Yes and no. No, there is no one specifically designed to provide exactly the same functionality. But yes, you can do the same in several ways. If you expect to access the data in the first place in the entered order, then the obvious way to go is a simple vector of pairs:
std::vector<std::string, std::string> food_colors; food_colors.push_back({"banana", "yellow"}); food_colors.push_back({"apple", "green"}); food_colors.push_back({"lemon", "yellow"}); for (auto const &f : food_colors) std::cout << f.first << ": " << f.second << "\n";
This keeps order, just keeping items in order. If you need to access them by key, you can use std::find to linearly search for a specific element. This minimizes the use of additional memory due to slow key access if you receive a lot of items.
If you need faster key access with more elements, you can use Boost MultiIndex. If you really want to avoid this, you can easily create your own index. To do this, start by entering your elements in std::unordered_map (or perhaps std::map ). This gives quick access by key, but without access in the input order. However, it returns an iterator for each element as it is inserted into the map. You can simply save these iterators to a vector to access in insertion order. Although the principle of this is quite simple, the code is a bit on the clumsy side, so that is nice:
std::map<std::string, std::string> fruit; std::vector<std::map<std::string, std::string>::iterator> in_order; in_order.push_back(fruit.insert(std::make_pair("banana", "yellow")).first); in_order.push_back(fruit.insert(std::make_pair("apple", "green")).first); in_order.push_back(fruit.insert(std::make_pair("lemon", "yellow")).first);
This allows you to access either by key:
// ripen the apple: fruit["apple"] = "red";
... or in the order of entry:
for (auto i : in_order) std::cout << i->first << ": " << i->second << "\n";
At the moment, I have shown the basic mechanism for this - if you want to use it a lot, you probably want to wrap it in a class to hide some ugliness and keep things pretty and clean under normal use.