Boost logo

Boost :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-07-09 17:41:12

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

Anyway, just my 2 cents for today,

Kind regards,

Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center

Boost list run by bdawes at, gregod at, cpdaniel at, john at