-namespace bits {
-
- // Something similar exist in C++14:
- template<class T>
- constexpr T max(T a, T b)
- {
- return (a > b) ? a : b;
- }
- template<class T, class... Args>
- constexpr T max(T a, Args... b)
- {
- return max(std::forward<T>(a), max(std::forward<Args>(b)...));
- }
-
- struct whatever {};
-
- // What we can store in a Task:
- typedef void* ptr_callback;
- struct funcptr_callback {
- // Placeholder for any function pointer:
- void(*callback)();
- void* data;
- };
- struct member_funcptr_callback {
- // Placeholder for any pointer to member function:
- void (whatever::* callback)();
- whatever* data;
- };
- typedef char any_callback[max(
- sizeof(ptr_callback),
- sizeof(funcptr_callback),
- sizeof(member_funcptr_callback)
- )];
-
- // Union of what we can store in a Task:
- union TaskErasure {
- ptr_callback ptr;
- funcptr_callback funcptr;
- member_funcptr_callback member_funcptr;
- any_callback any;
- };
-
- // Can we copy F in Task (or do we have to use the heap)?
- template<class F>
- constexpr bool isUsableDirectlyInTask()
- {
- // The only types we can portably store directly in the Task are the
- // trivially copyable ones (we can memcpy) which are small enough to fit:
- return std::is_trivially_copyable<F>::value &&
- sizeof(F) <= sizeof(bits::any_callback);
- }
-
-}
-