Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/scriptablecontroller/is_callable.h @ 12302

Last change on this file since 12302 was 11673, checked in by kohlia, 7 years ago

The ScriptableController should work now. A demo level called scriptableControllerTest exists as well.

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