//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" template < class Pointee > boost::forward_adapter< new_fwdee > new_ ( void ) { typedef Pointee base; typedef new_fwdee new_fwdee_base_type; new_fwdee new_fwdee_base_value; boost::forward_adapter< new_fwdee_base_type > new_base(new_fwdee_base_value); return new_base; } int main(void) { typedef std::auto_ptr result_type; result_type f_void(new_()()); result_type f_int(new_()(99)); float const pi=3.14; result_type f_float_int(new_()(pi,99)); return boost::report_errors(); }