fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. struct OrderBook {
  6. std::string symbol;
  7. OrderBook(std::string symbol) : symbol(symbol) {}
  8. void addOrder(std::string received_order) {
  9. std::cout << "adding order '" << received_order << "' into symbol '" << symbol << "'";
  10. }
  11. };
  12.  
  13. int main() {
  14. std::map<std::string, OrderBook> buy_side_symbols;
  15. std::string symbol = "the symbol";
  16.  
  17. auto symbol_iter = buy_side_symbols.find(symbol);
  18.  
  19. if (symbol_iter == buy_side_symbols.end())
  20. symbol_iter = buy_side_symbols.emplace(symbol, symbol).first;
  21.  
  22. std::string received_order = "some book";
  23. symbol_iter->second.addOrder(received_order);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
adding order 'some book' into symbol 'the symbol'