Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2004-03-21 18:33:24


On 03/21/2004 04:48 PM, Paul Mensonides wrote:
[snip]
> The Boost pp-lib cannot do the delay required to make this work properly.
> However, there are other methods of overloading an interface. Will something
> like this work instead?
[proposed code snipped]
> Regards,
> Paul Mensonides
Yes! Thanks very much. With source:
<-----------------cut here-----------------------------
using namespace boost::mpl;
struct target
{
     target
       ( int
       )
     {
         std::cout<<"target(int)\n";
     }

     target
       ( int
       , float
       )
     {
         std::cout<<"target(int,float)\n";
     }

     target
       ( int
       , float
       , target const&
       )
     {
         std::cout<<"target(int,float,target const&)\n";
     }

     target
       ( target const&
       )
     {
         std::cout<<"target(target const&)\n";
     }
};

struct member_target
{

BOOST_PP_REPEAT(
     2,
     PP_CTOR_FORWARDER_OVERLOAD,
     (member_target)(my_target)
)

   target my_target;

};

struct super_auto_ptr_target
: public std::auto_ptr<target>
{

BOOST_PP_REPEAT(
     2,
     PP_CTOR_FORWARDER_OVERLOAD,
     (super_auto_ptr_target)(new target)(std::auto_ptr<target>)
)

};

int main(void)
{
     typedef vector<int,float> int_float_typelist;
     at_c<int_float_typelist,0l>::type i=0;
     ++i;
     std::cout<<"mt0\n";
     member_target mt0(int_float_typelist(),0);
     std::cout<<"mt1\n";
     member_target mt1(int_float_typelist(),0,2.5);
     std::cout<<"sapt0\n";
     super_auto_ptr_target sapt0(int_float_typelist(),0);
     std::cout<<"sapt1\n";
     super_auto_ptr_target sapt1(int_float_typelist(),0,2.5);
     return 0;
}
>-----------------------cut here---------------------------------
intel gets output:

/opt/intel_cc_80/bin/icc -g -o pp_ctor_forwarder.exe pp_ctor_forwarder.o
running pp_ctor_forwarder
./pp_ctor_forwarder.exe
mt0
target(int)
mt1
target(int,float)
sapt0
target(int)
sapt1
target(int,float)

however, g++ complains:

/usr/local/gcc-3.4-20040225/bin/g++ -ggdb -c -Wall -MMD -O0 -ggdb
-I/home/evansl/prog_dev/boost-root.ln/boost_dev
-I/home/evansl/prog_dev/boost-root.ln -o pp_ctor_forwarder.o
pp_ctor_forwarder.cpp
pp_ctor_forwarder.cpp:49: error: `struct boost::mpl::at_c<VecOfTypes,
0l>::type' is not a type
pp_ctor_forwarder.cpp:49: error: ISO C++ forbids declaration of `a0'
with no type
pp_ctor_forwarder.cpp:49: error: `struct boost::mpl::at_c<VecOfTypes,
0l>::type' is not a type
pp_ctor_forwarder.cpp:49: error: `struct boost::mpl::at_c<VecOfTypes,
1l>::type' is not a type
pp_ctor_forwarder.cpp:49: error: ISO C++ forbids declaration of `a0'
with no type
pp_ctor_forwarder.cpp:49: error: ISO C++ forbids declaration of `a1'
with no type
pp_ctor_forwarder.cpp:63: error: `struct boost::mpl::at_c<VecOfTypes,
0l>::type' is not a type
pp_ctor_forwarder.cpp:63: error: ISO C++ forbids declaration of `a0'
with no type
pp_ctor_forwarder.cpp:63: error: `struct boost::mpl::at_c<VecOfTypes,
0l>::type' is not a type
pp_ctor_forwarder.cpp:63: error: `struct boost::mpl::at_c<VecOfTypes,
1l>::type' is not a type
pp_ctor_forwarder.cpp:63: error: ISO C++ forbids declaration of `a0'
with no type
pp_ctor_forwarder.cpp:63: error: ISO C++ forbids declaration of `a1'
with no type
pp_ctor_forwarder.cpp: In function `int main()':
pp_ctor_forwarder.cpp:80: warning: passing `double' for converting 3 of
`member_target::member_target(const VecOfTypes&, int, int) [with
VecOfTypes = main()::int_float_typelist]'
pp_ctor_forwarder.cpp:84: warning: passing `double' for converting 3 of
`super_auto_ptr_target::super_auto_ptr_target(const VecOfTypes&, int,
int) [with VecOfTypes = main()::int_float_typelist]'
make: *** [pp_ctor_forwarder.o] Error 1

Again, thanks very much!


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