Boost logo

Boost Users :

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


Just a small addition to my example:

I was unsure if compiler will deduce the type of the function param without explicit template
specialization. At least MSVC 8 did it. Hope this is so by C++ standard. Here is the example:

include <iostream>

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

template<class T>
void other_function_template(T value)
{
        std::cout << value*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>(10);
        function_template_wrapper::call<int, other_function_template>(10);

        return 0;
}

With Kind Regards,

Ovanes


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