|
Boost : |
Subject: Re: [boost] Proposal: boost::make_array()
From: Yves Bailly (yves.bailly_at_[hidden])
Date: 2013-01-12 20:43:27
Greetings Kyle,
On 01/12/2013 05:45 PM, Kyle Lutz wrote:
> I'd like to propose a new function for the Boost Array library named
> make_array(). The function constructs a fixed size array given N arguments
> and is similar to the make_pair() and make_tuple() functions.
> [...]
> The code is available on github at https://github.com/kylelutz/make_array
Sorry if it's a genuine question... But in the case of C++11, wouldn't it be
simpler to use an expansion instead of the "push_array" function? Something
like this:
#include <array>
template<typename Head, typename... Args>
struct get_first
{
typedef Head type;
};
template<typename... Args>
std::array<typename get_first<Args...>::type, sizeof...(Args)> make_array(Args&&... args)
{
return std::array<typename get_first<Args...>::type, sizeof...(Args)> { { args... } };
}
Usage:
auto my_array = make_array(1, 2, 3);
static_assert(std::is_same<std::array<int, 3>, decltype(arr)>::value, "Error");
for(int v: arr)
{
std::cout << v << " ";
}
Tested with G++ 4.7.2, the "static_assert" does not fail.
But maybe I'm missing something obvious...
-- (o< | Yves Bailly | -o) //\ | Linux Dijon : http://www.coagul.org | //\ \_/ | | \_/`
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk