Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/is_callable.h @ 11634

Last change on this file since 11634 was 11519, checked in by kohlia, 7 years ago

See previous

File size: 926 bytes
Line 
1#ifndef IS_CALLABLE_H
2#define IS_CALLABLE_H
3
4#include <type_traits>
5
6// See https://stackoverflow.com/a/15396757/7421666
7template<typename T>
8struct IsCallableImpl
9{
10private:
11    typedef char(&yes)[1];
12    typedef char(&no)[2];
13
14    struct Fallback { void operator()(); };
15    struct Derived : T, Fallback { };
16
17    template<typename U, U> struct Check;
18
19    template<typename>
20    static yes test(...);
21
22    template<typename C>
23    static no test(Check<void (Fallback::*)(), &C::operator()>*);
24
25public:
26    static const bool value = sizeof(test<Derived>(0)) == sizeof(yes);
27};
28
29// Checks if a type is callable (has an 'operator()'). This will not work for
30// normal functions without modifications, but we don't need that case anyway.
31template<typename T>
32struct IsCallable
33    : std::conditional<
34        std::is_class<T>::value,
35        IsCallableImpl<T>,
36        std::false_type
37    >::type
38{ };
39
40#endif // IS_CALLABLE_H
Note: See TracBrowser for help on using the repository browser.