Now's your chance to prove how big ya dick:
https://stackoverflow.com/questions/562 ... -detection
Who Likes Template Metaprogramming?
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Who Likes Template Metaprogramming?
Taking a stab in the dark here, too wrapped up and tired to test, but cppreference.com/is_invocable
Shouldn't you also have the parameter pack along with <F>?
The documentation seems to say that it checks if the function is callable with the parameters supplied to the parameter pack args..., so
example
Shouldn't you also have the parameter pack along with <F>?
The documentation seems to say that it checks if the function is callable with the parameters supplied to the parameter pack args..., so
Code: Select all
template<class F, class...Args>
void Register( F&& f, Args&&... args )
{
static_assert(std::is_invocable<F, args...>::value,"Handler must be invocable.");
// ...
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Who Likes Template Metaprogramming?
using call_type = function_traits<decltype(&F::type::operator())>;
If F is a lambda, where does the ::type come into play?
If F is a lambda, where does the ::type come into play?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Who Likes Template Metaprogramming?
Yeah, I found something nice to fix that secondary problem:
And this solved my lambda problem with function_traits
Code: Select all
template<typename T>
struct is_callable_impl
{
private:
typedef char( &yes )[1];
typedef char( &no )[2];
struct Fallback
{
void operator()();
};
struct Derived : T,Fallback
{};
template<typename U,U> struct Check;
template<typename>
static yes test( ... );
template<typename C>
static no test( Check<void (Fallback::*)(),&C::operator()>* );
public:
static const bool value = sizeof( test<Derived>( 0 ) ) == sizeof( yes );
};
template<typename T>
struct is_callable
: std::conditional<
std::is_class<T>::value,
is_callable_impl<T>,
std::false_type
>::type
{};
Code: Select all
template <typename T>
struct function_traits
: public function_traits<decltype(&T::operator())>
{};
// For generic types, directly use the result of the signature of its 'operator()'
template <typename ClassType,typename ReturnType,typename... Args>
struct function_traits<ReturnType( ClassType::* )(Args...) const>
// we specialize for pointers to member function
{
enum
{
arity = sizeof...(Args)
};
// arity is the number of arguments.
typedef ReturnType result_type;
template <size_t i>
struct arg
{
typedef typename std::tuple_element<i,std::tuple<Args...>>::type type;
// the i-th argument is equivalent to the i-th tuple element of a tuple
// composed of those arguments.
};
};
Chili