I'm using such code:
std::unordered_map<int64_t /*id_ord*/, LimitOrder> futOrders;
LimitOrder& newOrder = futOrders[orderId];
newOrder.Operation = side;
newOrder.InstrumentId = instrumentId;
newOrder.Lots = lots;
newOrder.Price = price;
newOrder.State = Active;
newOrder.Id = orderId;
Here I know that futOrders
doesn't contain orderId, so []
works this way: the function inserts a new element with that key and returns a reference to it's mapped value.
Ideally I want this behavior: "Just add to collection, otherwise somehow indicate that element is already exist. Exception is preffered." I want this to make it clear in code that it's assumed that element is new, and probably for better performance. Can you recomend something or what I have is the best?