$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: François Duranleau (duranlef_at_[hidden])
Date: 2007-10-02 14:29:12
On Mon, 1 Oct 2007, David Abrahams wrote:
[...]
> See
> http://boost.org/libs/parameter/doc/html/index.html#adding-type-requirements
I tried this simple example:
//---------------------------------------------
#include <boost/parameter/name.hpp>
#include <boost/parameter/preprocessor.hpp>
BOOST_PARAMETER_NAME( (arg1 , kw) arg1 )
BOOST_PARAMETER_FUNCTION(
     (arg1_type) ,
     the_function ,
     kw ,
     (required (arg1 , *))
)
{
     return arg1;
}
int
main()
{
     int i = the_function( 1 ) ;
     return 0 ;
}
//---------------------------------------------
but it won't compile either (gcc-4.0.2). Actually, if we look at the 
preprocessed output, it's not surprising. Here is the part of interest 
(formatted for readability):
//---------------------------------------------
namespace kw {
struct arg1
{
     static char const* keyword_name()
     {
         return "arg1";
     }
     typedef boost::parameter::value_type< boost::mpl::_2,
                                           arg1,
                                           boost::parameter::void_ > _;
     typedef boost::parameter::value_type< boost::mpl::_2,
                                           arg1,
                                           boost::parameter::void_ > _1;
};
}
namespace {
::boost::parameter::keyword<kw:: arg1>& arg1 = 
::boost::parameter::keyword<kw:: arg1>::get();
}
template <class Args>
struct boost_param_result_11the_function
{
     typedef typename boost::parameter::aux::unaryfunptr_arg_type<
         void(*)(arg1_type)
     >::type type;
};
template <class BoostParameterDummy>
struct boost_param_params_11the_function
     : boost::parameter::parameters<
           boost::parameter::required<
               kw::arg1 ,
               typename boost::parameter::aux::unwrap_predicate<
                   void *
               >::type
           >
       >
{
};
typedef boost_param_params_11the_function<int> 
boost_param_parameters_11the_function;
template <class Args>
typename boost_param_result_11the_function< Args >::type
boost_param_implthe_function(Args const& args);
template< class ParameterArgumentType0>
inline
typename boost_param_result_11the_function< typename 
boost::parameter::aux::argument_pack<
     boost_param_parameters_11the_function ,
     const ParameterArgumentType0 >::type
>::type
the_function ( const ParameterArgumentType0& a0 ,
                typename boost::parameter::aux::match<
                    boost_param_parameters_11the_function,
                    ParameterArgumentType0
                >::type boost_parameter_enabler_argument =
                    boost_param_parameters_11the_function() )
{
     return boost_param_implthe_function(
         boost_param_parameters_11the_function()( a0 )
     );
}
template < class ResultType ,
            class Args ,
            class arg1_type >
ResultType
boost_param_default_11the_function( ResultType(*)() ,
                                     Args const& args ,
                                     int ,
                                     arg1_type& arg1 ) ;
template <class Args>
typename boost_param_result_11the_function<Args>::type
boost_param_implthe_function(Args const& args)
{
     return boost_param_default_11the_function(
         (typename boost_param_result_11the_function<Args>::type(*)())0 ,
         args ,
         0L ,
         boost::parameter::aux::cast<void *>::remove_const(
             boost::parameter::aux::cast<void *>::execute(
                 args[ boost::parameter::keyword<kw::arg1 >::get() ]
             )
         )
     );
}
template < class ResultType ,
            class Args ,
            class arg1_type >
ResultType
boost_param_default_11the_function( ResultType(*)() ,
                                     Args const& args ,
                                     int ,
                                     arg1_type& arg1 )
{
     return arg1;
}
int
main()
{
     int i = the_function( 1 ) ;
     return 0 ;
}
//---------------------------------------------
Notice where 'boost_param_result_11the_function' is defined: nowhere at 
that point is arg1_type defined. Same about 
'boost_param_params_11the_function' if we want to make other parameters' 
type dependant on, e.g., arg1_type. Seems like the only place it is 
defined is at 'boost_param_default_11the_function'.
I looked for examples in Boost.Parameter's test programs, alas, it seems 
there are no tests written for this feature.
-- Francois Duranleau