Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-05-29 12:55:00


Hi!

do you mean this?

#include <iostream>

template<class T>
void function_template(T value)
{
        std::cout << value << std::endl;
}

struct function_template_wrapper
{
        template<class T, void(*Fct)(T)>
        static inline void call(T value)
        {
                Fct(value);
        }
};

int main(int argc, char* argv[])
{

        function_template_wrapper::call<int, function_template<int> >(10);

        return 0;
}

May be you will take a look at boost::function library.

Best Regards,
Ovanes

On Tue, May 29, 2007 17:57, Ares Lagae wrote:
> consider the following program:
>
> template <typename T>
> void function_template(T value)
> {
> std::cout << __PRETTY_FUNCTION__ << std::endl;
> }
>
> struct function_template_wrapper
> {
> template <typename T> static void call(T value)
> {
> function_template<T>(value);
> }
> };
>
> int main(int argc, char* argv[])
> {
> int i;
> function_template_wrapper::call<int>(i);
> }
>
> Is it possible to somehow parameterize the struct function_template_wrapper
> such that I can pass function_template as a parameter?
>
> E.g. function_template_wrapper<function_template>::call<int>(i); would call
> function_template<int>(i), and
> function_template_wrapper<other_function_template>::call<int>(i); would
> call other_function_template<int>(i)
>
> Underlying problem: I want to somehow pass a name of a function template to
> a class, that will instantiate the function template for a number of types
> (known at compile time), and store these instantiations in function
> objects, for later use.
>
> Best regards,
>
> --
> Ares Lagae
> Computer Graphics Research Group, Katholieke Universiteit Leuven
> http://www.cs.kuleuven.be/~ares/
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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