Afficher un message
Vieux 08/12/2007, 12h43   #5
Pete Becker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: std::list of C-style arrays

On 2007-12-07 21:59:30 -0500, Juha Nieminen <nospam@thanks.invalid> said:

> Kai-Uwe Bux wrote:
>> Built-in arrays do not satisfy the Assignable and CopyConstructible concepts
>> required for types used in standard sequence containers.

>
> Is there any technical or rational reason for this? After all, they
> *are* copied and assigned if they are members of a struct/class. Why
> can't it be so also when they are bare?


The simplest answer is that that's the way it is in C. A more complex
answer is that you end up in a tangle, because the name of an array
decays to a pointer to its first element in many contexts, and when
you're down to a pointer you no longer know the size. Yes, C++ could
have added a bunch of rules about when you can and when you can't copy
them, but that would not be productive. If you need copyable arrays,
use std::tr1::array. For more details, see chapter 4 of my book, "The
Standard C++ Library Extensions."

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

  Réponse avec citation
 
Page generated in 0,04579 seconds with 9 queries