
Daryle Walker wrote:
Arrays are badly-copyable because the C++ committee has never fixed them from their half-done status (unlike struct).
FWIW, it's quite easy to write a template function that can copy both built-in arrays (of any number of dimensions) and Assignable types: template <typename T> void copy(const T &source, T &dest) { dest = source; } template <typename T, std::size_t N> void copy(const T (&source)[N], T (&dest)[N]) { for (std::size_t i = 0; i < N; ++i) copy(source[i], dest[i]); } So arrays aren't /that/ uncopyable :-)
Maybe we should take the lead and make a special case for allowing array objects in an boost::any.
I certainly wouldn't mind having array support for boost::any... Ferdinand Prantl wrote:
I were not arguing the type of the expression. The thing was - is it possible to modify boost::any in some way to make it usable with C-string style constants without a cast?
Is it really so bad to have a cast? What about the following syntax? boost::any foo( cast_array_to_ptr("foo") ); Having cast_array_to_ptr as follows: template<typename T, std::size_t N> T * cast_array_to_ptr(T (&arg)[N]) { return arg; }
By the way, there is a problem with the proposal made in my previous e-mail. It would be virtually impossible to get the value from the object by a cast if the array was stored with its exact type.
It wouldn't be completely impossible, though. You can have a function that returns a char-pointer, implemented by trying to cast a boost::any to char[N], for N = 1 to some reasonably high maximum constant...
Storing the array as a full copy with its exact type brings more questions like handling multidimensional arrays, avoiding assignments when copying the array and how to get the array from the boost::any object by boost::any_cast.
I'm pretty sure we can solve those questions on handling multidimensional arrays, and avoiding assignments, as I mentioned at Boost Users http://article.gmane.org/gmane.comp.lib.boost.user/37430 Anyway, just my 2 cents for today, Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center