|
Boost : |
From: Joe Gottman (jgottman_at_[hidden])
Date: 2005-05-31 19:40:22
"AlisdairM" <alisdair.meredith_at_[hidden]> wrote in message
news:d7itb3$6mk$1_at_sea.gmane.org...
>
> Aggregate initialization is an important part of the array concept,
> allowing it to act largely as a plug-in replacement for language
> arrays, with the bonus it can be passed by value as well as by
> reference. The main drawback here is that we cannot deduce the size of
> a boost::array, as you can with a language array.
I know this is looking ahead quite a bit, but the next version of C++ is
going to have a new meaning for the "auto" keyword. The code
auto x = foo();
will declare x as a variable whose type is deduced from the return type of
foo() (See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1794.pdf
for details).
It should be possible to use this to create a function that creates an array
of the correct size:
template <class T>
array<T, 1> make_array(const T &t1);
template <class T>
array<T, 2> make_array(const T &t1, const T &t2);
template <class T>
array<T, 3> make_array(const T &t1, const T &t2, const T &t3);
etc.
Then we would be able to write code like
auto my_array = make_array(1,2, 3); // The type of my_array is array<int,
3>
Joe Gottman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk