c++ - boost::variant recursive trouble -
is there way make work? hope you'll idea, i'm trying create list means of recursive pairs
#include <boost/variant.hpp> #include <utility> struct nil {}; typedef boost::make_recursive_variant<nil, std::pair<int, boost::recursive_variant_ >>::type list_t; int main() { list_t list = { 1, (list_t){ 2, (list_t){ 3, nil() } } }; return 0; }
no. point of boost::variant has fixed size, , not dynamic allocation. in way it's similar union. recursive boost::variant have have infinite size in order contain largest possible value - impossible.
you could, however, passing through pointer. example:
struct nil { }; typedef boost::make_recursive_variant<nil, std::pair<int, boost::scoped_ptr<boost::recursive_variant_> > > variant_list_int;
Comments
Post a Comment