- namespace internal
- {
- /**
- * @internal
- *
- * General template declaration of a class that is used to encapsulate
- * arguments to global and static member functions, make sure a new thread
- * is created and that function being run on that thread.
- *
- * Although this general template is not implemented at all, the default
- * template argument makes sure that whenever using the name of this
- * class, the last template argument will be computed correctly from the
- * previous arguments, and the correct specialization for this last
- * template argument be used, even though we need to specify it.
- */
- template <typename RT, typename ArgList, int length>
- class fun_encapsulator;
-
-
-// ----------- encapsulators for function objects
-
- /**
- * @internal
- *
- * Encapsulator class for functions with no arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 0>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() ()
- {
- return Thread<RT> (function);
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 1 argument.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 1>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 2 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 2>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 3 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 3>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 4 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 4>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 5 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 5>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4,
- typename std::tuple_element<4,ArgList>::type arg5)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4),
- internal::maybe_make_ref<typename std::tuple_element<4,ArgList>::type>::act(arg5)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 6 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 6>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4,
- typename std::tuple_element<4,ArgList>::type arg5,
- typename std::tuple_element<5,ArgList>::type arg6)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4),
- internal::maybe_make_ref<typename std::tuple_element<4,ArgList>::type>::act(arg5),
- internal::maybe_make_ref<typename std::tuple_element<5,ArgList>::type>::act(arg6)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 7 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 7>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4,
- typename std::tuple_element<4,ArgList>::type arg5,
- typename std::tuple_element<5,ArgList>::type arg6,
- typename std::tuple_element<6,ArgList>::type arg7)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4),
- internal::maybe_make_ref<typename std::tuple_element<4,ArgList>::type>::act(arg5),
- internal::maybe_make_ref<typename std::tuple_element<5,ArgList>::type>::act(arg6),
- internal::maybe_make_ref<typename std::tuple_element<6,ArgList>::type>::act(arg7)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 8 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 8>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4,
- typename std::tuple_element<4,ArgList>::type arg5,
- typename std::tuple_element<5,ArgList>::type arg6,
- typename std::tuple_element<6,ArgList>::type arg7,
- typename std::tuple_element<7,ArgList>::type arg8)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4),
- internal::maybe_make_ref<typename std::tuple_element<4,ArgList>::type>::act(arg5),
- internal::maybe_make_ref<typename std::tuple_element<5,ArgList>::type>::act(arg6),
- internal::maybe_make_ref<typename std::tuple_element<6,ArgList>::type>::act(arg7),
- internal::maybe_make_ref<typename std::tuple_element<7,ArgList>::type>::act(arg8)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
-
- /**
- * @internal
- *
- * Encapsulator class for functions with 9 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 9>
- {
- public:
- fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
- : function (*function)
- {}
-
- fun_encapsulator (const std::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
- : function (function)
- {}
-
- inline
- Thread<RT>
- operator() (typename std::tuple_element<0,ArgList>::type arg1,
- typename std::tuple_element<1,ArgList>::type arg2,
- typename std::tuple_element<2,ArgList>::type arg3,
- typename std::tuple_element<3,ArgList>::type arg4,
- typename std::tuple_element<4,ArgList>::type arg5,
- typename std::tuple_element<5,ArgList>::type arg6,
- typename std::tuple_element<6,ArgList>::type arg7,
- typename std::tuple_element<7,ArgList>::type arg8,
- typename std::tuple_element<8,ArgList>::type arg9)
- {
- return
- Thread<RT>
- (std::bind (function,
- internal::maybe_make_ref<typename std::tuple_element<0,ArgList>::type>::act(arg1),
- internal::maybe_make_ref<typename std::tuple_element<1,ArgList>::type>::act(arg2),
- internal::maybe_make_ref<typename std::tuple_element<2,ArgList>::type>::act(arg3),
- internal::maybe_make_ref<typename std::tuple_element<3,ArgList>::type>::act(arg4),
- internal::maybe_make_ref<typename std::tuple_element<4,ArgList>::type>::act(arg5),
- internal::maybe_make_ref<typename std::tuple_element<5,ArgList>::type>::act(arg6),
- internal::maybe_make_ref<typename std::tuple_element<6,ArgList>::type>::act(arg7),
- internal::maybe_make_ref<typename std::tuple_element<7,ArgList>::type>::act(arg8),
- internal::maybe_make_ref<typename std::tuple_element<8,ArgList>::type>::act(arg9)));
- }
-
- private:
- std::function<typename internal::fun_ptr<RT,ArgList>::type> function;
- };
- }
-
-
-
// ----------- thread starters for functions not taking any parameters
/**