// file : odb/details/function-wrapper.txx // copyright : Copyright (c) 2009-2014 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #include // std::swap, std::move namespace odb { namespace details { #ifdef ODB_CXX11 template struct caller_impl; #ifdef ODB_CXX11_VARIADIC_TEMPLATE template struct caller_impl { static R function (const void* f, A... a) { return (*static_cast*> (f)) (a...); } }; #else template struct caller_impl { static R function (const void* f, A1 a1) { return (*static_cast*> (f)) (a1); } }; template struct caller_impl { static R function (const void* f, A1 a1, A2 a2) { return (*static_cast*> (f)) (a1, a2); } }; #endif template void deleter_impl (const void* f) { delete static_cast*> (f); } template template function_wrapper:: function_wrapper ( F1 f, typename std::enable_if::value>::type*) { std_function_type sf (std::move (f)); if (F* const* const f = sf.template target ()) { function = *f; deleter = 0; std_function = 0; } else { function = reinterpret_cast (&caller_impl::function); deleter = &deleter_impl; std_function = new std_function_type (std::move (sf)); } } #endif template void function_wrapper:: swap (function_wrapper& x) { std::swap (function, x.function); std::swap (deleter, x.deleter); std::swap (std_function, x.std_function); } } }