Re: DR 851 - Simplified array construction.
Chris Fairles ha scritto:
The proposed make_array solution requires the type to be specified
explicitly (i.e. make_array<int>(1,2,3,4,5)) whereas every other
make_* doesn't (so far as I recall, correct if I'm wrong).
The following def'n however works w/o requiring the explicit type
param:
template<class T, class... Args>
std::array<T, sizeof...(Args)+1>
make_array(T&& t, Args&&... a)
{
return std::array<T,sizeof...(Args)
+1>{{std::forward<T>(t),std::forward<Args>(a)...}};
}
int main()
{
// this works with gcc 4.4.0 mainline (at least with rev. 140533).
auto a = make_array(1,2,3,4,5);
auto b = make_array(3.5);
}
This seems a little more useful perhaps. Any reason why it couldn't be
considered as another potential solution to DR 851?
The idea is nice, but it's a bit error prone, for example in this case:
auto a = make_array(1,2.1,3.2,4.3,5.4);
which silently produces an array of ints and not an array of doubles as
I would expect, simply because I have forgotten the ".0" in the first
argument.
Anyway, the issue is still in review status so there's room for improvement.
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]