
From: Bronek Kozicki <brok@rubikon.pl>
#include <cassert> #include <cstdio> #include <utility>
// Copyright Bronislaw Kozicki 2003-2004. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See http://www.boost.org/LICENSE_1_0.txt )
#ifndef __COMO__ # if defined(_MSC_VER) && (_MSC_VER <= 1310) # define FAULTY # endif // _MSC_VER #endif // __COMO__
template <bool> struct static_assert; template <> struct static_assert<true> {};
class trampoline { private: typedef void(*_pf_t)(void *);
template <typename Functor> struct _lever_t;
template <typename Functor> struct _lever_t<Functor *> { static_assert<sizeof(Functor*) == sizeof(void *)> size;
union convert { Functor* f; void* p; };
What if a void * and a pmf are not the same size? You at least need a static assertion to that effect, right?
static void exec(void * p) { convert c; c.p = p; (*c.f)(); }
static std::pair<_pf_t, void *> init(Functor* f) { convert c; c.f = f; return std::pair<_pf_t, void *>(&exec, c.p);
^^^^^ &_lever_t::exec Unfortunately, the type of exec is void (_lever_t<Function *>::*)(void *) not void (*)(void *) as you've declared _pf_t. Thus, on any compiler that uses a different function pointer type for pointers to member functions and regular function pointers, will fail to compile this code. (I haven't tested to learn if there are any, but even if there aren't any today, there could be tomorrow.) -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;