5 ms·
Example: x = {'foo':34,'bar':[1,2,3],'baz':'quux'} The headers alone for STL maps are hundreds of LOC.
by Borogove 12y ago
Example:
x = {'foo':34,'bar':[1,2,3],'baz':'quux'}
The headers alone for STL maps are hundreds of LOC.
- GFK_of_xmaspast 12y agoI agree with the upstream comment about expressiveness, but this isn't a fair example.
- zmmmmm 12y agoCounting headers is rather unfair. C++11: map<int, char> x = {{1, 'a'}, {3, 'b'}, {5, 'c'}, {7, 'd'}}; Any not-ancient C++ using boost Assign: map<int, char> x = map_list_of (1, 'a') (3, 'b') (5, 'c') (7, 'd'); Shamelessly stolen from here: http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c http://stackoverflow.com/questions/138600/initializing-a-sta...
- nly 12y agoThat's tricky, because C++ is statically typed and you've selected a varying value type, but here's the closest thing in real terms. #include <map> #include <vector> #include <string> #include <boost/any.hpp> using boost::any; using std::map; using std::string; using std::vector; int main() { map<string,any> x = {{"foo", 34}, {"bar", vector<int>{1,2,3}}, {"bar", "quux"}}; } Syntax overhead amortizes to constant factor ;)