*
* auto args = std::make_tuple(1, false);
* int res = apply(foo, args);
- * @encode
+ * @endcode
**/
template <class F, class Tuple>
constexpr auto apply(F&& f, Tuple&& t)
struct whatever {};
// Union used for storage:
+#if 0
typedef typename std::aligned_union<0,
void*,
std::pair<void(*)(),void*>,
std::pair<void(whatever::*)(), whatever*>
>::type TaskUnion;
+#else
+ union TaskUnion {
+ void* ptr;
+ std::pair<void(*)(),void*> funcptr;
+ std::pair<void(whatever::*)(), whatever*> memberptr;
+ char any1[sizeof(std::pair<void(*)(),void*>)];
+ char any2[sizeof(std::pair<void(whatever::*)(), whatever*>)];
+ TaskUnion() {}
+ ~TaskUnion() {}
+ };
+#endif
// Is F suitable for small buffer optimization?
template<class F>
[](TaskUnion& buffer, Args... args) -> R {
// Delete F when we go out of scope:
std::unique_ptr<F> code(*reinterpret_cast<F**>(&buffer));
- (*code)(std::forward<Args>(args)...);
+ return (*code)(std::forward<Args>(args)...);
},
// Destroy:
[](TaskUnion& buffer) {