Boost logo

Boost Users :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-05-30 03:22:24


Ares Lagae wrote:
> Ovanes Markarian wrote:
>
>> Hi!
>>
>> do you mean this?
>>
>>
>> function_template_wrapper::call<int, function_template<int> >(10);
>>
>
> Thanks for the reply, but it's not really what I want.

So you're looking for something like template template parameters for
function templates? As you probably know, there is no such language feature.

However, it's common practice to use function objects for the use case
you describe:

     // A Function Object
     struct my_func
     {
         template<typename T>
         void operator()(T const &) const
         {
             // [...]
         }

         typedef void result_type;

         // It's also possible to use a result type that
         // depends on T. Further reading:
         // http://www.boost.org/libs/utility/utility.htm#result_of
     };

Now you can pass objects of that type to another function template, or
just pass the type 'my_func' to a class template as template argument
(for generic components it's usually a good idea to provide a way to
initialize the object - maybe a default argument in the ctor, otherwise
valid types are restricted to be DefaultConstructible and users can't
set an initial state).

You can also stuff such an object into a Boost.Function, hard-wiring it
towards a certain signature in order to call it from anywhere (such as
another translation unit where the type of the function object is unknown).

Regards,
Tobias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net