[variant] make_recursive_variant containing a variant ?

Hi,
i am trying to build a recursive variant containing another variant, as
described in the following source code:
#include <cstdlib>
#include <vector>
#include <string>
#include

AMDG Alban Linard wrote:
Hi,
i am trying to build a recursive variant containing another variant, as described in the following source code:
#include <cstdlib> #include <vector> #include <string> #include
typedef ::boost::variant < int , bool > first_variant;
typedef ::boost::make_recursive_variant < first_variant , ::std::string , ::std::vector< ::boost::recursive_variant_ > >::type second_variant;
int main() { first_variant f(true); second_variant s(f); return EXIT_SUCCESS; }
It does not compile (g++-4.0 and g++-4.3). It seems that the "first_variant" part of second_variant is not used. Why this behavior ? Is there a workaround ?
This is a bug in boost::variant. You can fix it by changing line 101 of boost/variant/recursive_variant.hpp from typedef ::boost::variant< types > type; to typedef ::boost::variant< over_sequence<types> > type; In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Alban Linard wrote:
Hi,
i am trying to build a recursive variant containing another variant, as described in the following source code:
#include <cstdlib> #include <vector> #include <string> #include
typedef ::boost::variant < int , bool > first_variant;
typedef ::boost::make_recursive_variant < first_variant , ::std::string , ::std::vector< ::boost::recursive_variant_ > >::type second_variant;
int main() { first_variant f(true); second_variant s(f); return EXIT_SUCCESS; }
It does not compile (g++-4.0 and g++-4.3). It seems that the "first_variant" part of second_variant is not used. Why this behavior ? Is there a workaround ?
This is a bug in boost::variant. You can fix it by changing line 101 of boost/variant/recursive_variant.hpp from typedef ::boost::variant< types > type; to typedef ::boost::variant< over_sequence<types> > type;
In Christ, Steven Watanabe
Thank you very much!
Next step, i would like to store a container of first_variant instead of
a single one.
#include <cstdlib>
#include <vector>
#include

AMDG Alban Linard wrote:
Thank you very much!
Next step, i would like to store a container of first_variant instead of a single one.
#include <cstdlib> #include <vector> #include
typedef ::boost::variant < int , bool > first_variant;
typedef ::boost::make_recursive_variant < ::std::vector< first_variant > , ::std::vector< ::boost::recursive_variant_ > >::type second_variant;
int main() { ::std::vector< first_variant > f; second_variant s(f); return EXIT_SUCCESS; }
This crashes, too. Again, did i use it wrong or is it another problem ?
It's a part of the same problem. The fix I gave wasn't quite right. Try applying the patch I attached to http://svn.boost.org/trac/boost/ticket/1654 In Christ, Steven Watanabe

Steven Watanabe a écrit :
AMDG
Alban Linard wrote:
Thank you very much!
Next step, i would like to store a container of first_variant instead of a single one.
#include <cstdlib> #include <vector> #include
typedef ::boost::variant < int , bool > first_variant;
typedef ::boost::make_recursive_variant < ::std::vector< first_variant > , ::std::vector< ::boost::recursive_variant_ > >::type second_variant;
int main() { ::std::vector< first_variant > f; second_variant s(f); return EXIT_SUCCESS; }
This crashes, too. Again, did i use it wrong or is it another problem ?
It's a part of the same problem. The fix I gave wasn't quite right. Try applying the patch I attached to http://svn.boost.org/trac/boost/ticket/1654
In Christ, Steven Watanabe
Your patch solved the second problem too. Again, thank you very much. Alban Linard

AMDG Alban Linard wrote:
Hi,
i am trying to build a recursive variant containing another variant, as described in the following source code: <snip>
It does not compile (g++-4.0 and g++-4.3). It seems that the "first_variant" part of second_variant is not used. Why this behavior ? Is there a workaround ?
I've submitted a bug report: http://svn.boost.org/trac/boost/ticket/1654 In Christ, Steven Watanabe
participants (2)
-
Alban Linard
-
Steven Watanabe