c++ - Nested containers of different types -


i new stl , wanted know best way implement this: wanted nest containers elements of different types. idea set, elements either vectors or maps.

this way iterate through set applying common operations elements. @ same time, of operations on elements, dependant on vector or map type. however, assume elements must of same type.

would there alternative implement this?

you can't put 2 different kinds of objects standard container. have "wrap" container in object "knows" kind of object holding. boost::variant<t1, t2 ... > relatively standard way of doing it. if can't use boost library, may find works ok:

struct wrapper {      int type;  // or enum       union {          vector v;          map m;      } content; }; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -