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
Post a Comment