For an std::map<std::string, std::string> variables, I’d like to do this:
BOOST_CHECK_EQUAL(variables['a'], 'b');
The only problem is, in this context variables is const, so operator[] won’t work 🙁
Now, there are several workarounds to this; casting away the const, using variables.count('a') ? variables.find('a')->second : std::string() or even making a function wrapping that. None of these seem to me to be as nice as operator[]. What should I do? Is there a standard way of doing this (beautifully)?
Edit: Just to state the answer that none of you want to give: No, there is no convenient, beautiful, standard way of doing this in C++. I will have to implement a support function.
Improved implementation based on comments: