Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-01-26 00:07:00


The attached code attempts to use CRTP (Curiously Recurring Template
Pattern) to see if recursive_variant can be avoided; however,
I'm getting 2 variant's produced instead of 1 and the which gives
the wrong result.

The output is:
<-- cut here --
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/build/gcc4_1/lje/libs/variant/test/crtp_test.exe
set_of_objects_tracked+
===>Enter:int_list_1 scope
   object_tracked+:id=1:default
   ===>Enter:variant()
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1176:id=1
   ===>Exit:variant()
   object_tracked+:id=2:default
   ===>Enter:template<typename T>variant(T& operand)
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1360:id=2
     ===>Enter:template<typename T>convert_construct(T& operand,int,false)
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1268
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/initializer.hpp:95:index=1
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1280:after
initialize:which=1
     ===>Exit:template<typename T>convert_construct(T& operand,int,false)
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1362:after_convert_construct:which=1
   ===>Exit:template<typename T>variant(T& operand)
   ===>Enter:template<class T>vlist(T)
     id=1
     T.first=1
     this->which=0
   ===>Exit:template<class T>vlist(T)
   int_list_1.which()=0
   object_tracked-:id=2:am_i_live=1
   object_tracked-:id=1:am_i_live=1
===>Exit:int_list_1 scope
set_of_objects_tracked-
>-- cut here --
The output produced from just the attached includes:

     this->which=0

but I expected which=1 since the CTOR arg is the 2nd bounded type:
(pair<int,list_type*>). The other output's are produced by
making object_tracked a super of variant and also putting
debug prints in various CTOR's. The output:

   ===>Enter:variant()
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/lje/libs/variant/test/variant.hpp:1176:id=1
   ===>Exit:variant()

indicates a variant produced with the default CTOR has id=1 which is
the id of the vlist produced with the pair CTOR arg.

Does anyone have any clue why this is happening, IOW why which=0 instead
of 1.

I tried using the debugger, but it was not more help.

TIA.

-regards,
Larry




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk