Boost logo

Boost Users :

From: Ares Lagae (ares.lagae_at_[hidden])
Date: 2007-05-30 02:54:49


my closest attempt is this:

#include <iostream>
#include <tr1/functional>

template <typename T>
void callback_1(T value)
{
  std::cout << __PRETTY_FUNCTION__ << std::endl;
}

template <typename T>
void callback_2(T value)
{
  std::cout << __PRETTY_FUNCTION__ << std::endl;
}

template <typename T, void (*FunctionPointer) (T)>
struct function_template_wrapper
{
  typedef void (*FunctionPointerType) (T);
  static FunctionPointerType function_pointer;
  static std::tr1::function<void (T)> function() { return
std::tr1::function<void (T)>(FunctionPointer); }
};
template <typename T, void (*FunctionPointer) (T)>
typename function_template_wrapper<T, FunctionPointer>::FunctionPointerType
function_template_wrapper<T, FunctionPointer>::function_pointer =
FunctionPointer;

template <typename T> struct callback_1_wrapper : public
function_template_wrapper<T, callback_1<T> > {};

template <typename T> struct callback_2_wrapper : public
function_template_wrapper<T, callback_2<T> > {};

template <template <typename> class function_template_wrapper>
void set_callback()
{
  function_template_wrapper<int>::function()(int());
  function_template_wrapper<double>::function()(int());
  function_template_wrapper<float>::function()(int());
}

int main(int argc, char* argv[])
{
  set_callback<callback_1_wrapper>();
  set_callback<callback_2_wrapper>();
}

-- 
Ares Lagae
Computer Graphics Research Group, Katholieke Universiteit Leuven
http://www.cs.kuleuven.be/~ares/

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