//Purpose: // An *attempt* to emulate template new_ as found attached to following post: /* http://lists.boost.org/Archives/boost/2007/12/131251.php */ #include #include #include #include #include #include #include #define TEMPLATED_FUN_ARITY(IGNORE_0, ARITY, FUN_NAME_RESULT) \ template \ < BOOST_PP_ENUM_PARAMS(ARITY, class T ) \ > \ BOOST_PP_SEQ_ELEM(1,FUN_NAME_RESULT) \ BOOST_PP_SEQ_ELEM(0,FUN_NAME_RESULT) \ ( BOOST_PP_ENUM_BINARY_PARAMS(ARITY, T, & t ) \ ) const \ { \ return result_type \ ( new Pointee(BOOST_PP_ENUM_PARAMS(ARITY, t )) \ ); \ } \ /**/ //delimit_macro_test_code template struct new_fwdee { typedef std::auto_ptr result_type ; result_type operator() ( void ) const { return result_type ( new Pointee ); } BOOST_PP_REPEAT_FROM_TO(1,3,TEMPLATED_FUN_ARITY,(operator())(result_type)) }; #undef TEMPLATED_FUN_ARITY #include "base.hpp" int main(void) { typedef new_fwdee new_fwdee_base_type; typedef new_fwdee_base_type::result_type result_type; new_fwdee_base_type new_fwdee_base_value; boost::forward_adapter< new_fwdee_base_type > new_base(new_fwdee_base_value); //Problem: // Have to create new_fwdee_base_value first, and then new_base, before // actually using to new_base to create a result_type. This is in contrast // to just using new_(arg1,...,argN) as in Abraham's new_. // // NOTE: I'm just guessing that's what Abraham's new_ use look like. // I've been unable to compile it (lacking new.hpp). result_type f_void(new_base()); result_type f_int(new_base(99)); float const pi=3.14; result_type f_float_int(new_base(pi,99)); return boost::report_errors(); }