I’m trying to figure out how I can switch between boost functions and c++11 functions depending on what the platform I’m compiling it on has available. I know that c++ doesn’t have template aliasing (pre-c++11) so I wrote the following, but I can’t understand the error message or why it’s not working:
#define FUNCTION_Boost
#if defined(FUNCTION_Boost)
#include <boost/function.hpp>
#elif defined(FUNCTION_STL)
#include <functional>
#endif
template<typename Res, typename... ArgTypes>
struct function {
#if defined(FUNCTION_Boost)
typedef boost::function<Res(ArgTypes...)> type;
#elif defined(FUNCTION_STL)
typedef std::function<Res(ArgTypes...)> type;
#endif
};
// In instantiation of ‘function<void()>’:
// error: function returning a function
void foo(function<void ()>::type f) {
f();
}
// this works fine
void bar(boost::function<void ()> f) {
f();
}
no need to define one more
function… everything could be done usingusing😉