
On 5/4/2015 9:50 PM, Thijs (M.A.) van den Berg wrote:
I would actually prefer not to use type erasure: make a strong-typed and efficient heterogenous container. Something like this... ?
template
struct tuple_vector : std::tuple< std::vector<Args>... > { typename std::tuple type; template <typename T> void push_back(const T& value) { std::get< std::vector<T> >(*this).push_back(value); }
template <typename T> void push_back( T&& value) { std::get< std::vector<T> >(*this).push_back(value); } };
struct Point { double x; double y; }; struct Line { double x; double y; double a; double l; }; struct Rectangle { double x; double y; double a; double w; double h; }; struct Circle { double x; double y; double r; };
tuple_vector
shapes; shapes.push_back(Point{1.0, 1.0} ); shapes.push_back(Point{1.0, 1.0} ); shapes.push_back(Circle{1.0, 1.0, .3} ); shapes.push_back(Rectangle{0.0, 0.0, 0.0, 1.0, 1.0} );
This is neat, but it' not quite the same thing. Unlike std::vectorboost::any, your tuple_vector does not organize objects into strictly linear arrangement. Using your example, there is no way to draw shapes in the order they were inserted into container.