
----- Original Message ----- From: "Yechezkel Mett" <ymett.on.boost@gmail.com> To: <boost@lists.boost.org> Sent: Wednesday, November 19, 2008 4:51 PM Subject: Re: [boost] task_array<n> and variadic templates
On Wed, Nov 19, 2008 at 5:32 PM, Yechezkel Mett <ymett.on.boost@gmail.com> wrote:
On Wed, Nov 19, 2008 at 5:08 PM, Vicente Botet <vicente.botet@wanadoo.fr> wrote:
On a current compiler:
template <std::size N> struct task_array { task arr_[N]; template <typename... F> task_array(F... f) { static_assert(sizeof...(T) == N, "Constructor must provide N parameters") boost::array<task, N> arr = { task(f)... }; std::copy(arr.begin(), arr.end(), arr_); } };
if you don't mind the multiple copies -- perhaps better to move rather than copy.
Recursion isn't too bad either:
namespace detail { template<typename T, typename Head, typename... Tail> void fill_array(T* arr, Head h, Tail... t) { *arr = T(h); fill_array(arr + 1, t...); }
template<typename T> void fill_array(T* arr) {} }
template <std::size N> struct task_array { task arr_[N]; template <typename... F> task_array(F... f) { static_assert(sizeof...(T) == N, "Constructor must provide N parameters") detail::fill_array(arr_, f...); } };
I will try both, changing the c array by boos::array Thanks, Vicente