|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-10-22 05:51:15
>Right, there's one trivial error (is_POD needs a const int
>specialization) and a more serious one where I try to get the value_type
>using iterator_traits (because int* const is not a valid iterator type).
Again there are sublties here: is_POD<const int> is deliberately false,
otherwise you may find yourself memcpy'ing over a const array of int's. In
this context we are saying that const int is not a POD because it is not
trivially assignable.
>Yes. :-) Why wouldn't it? You're explicitly telling the compiler to load
>the pointer whenever it has to access it and save it whenever it is
>modified. It seems to me that the compiler can do this easily enough with
>the element by element version and with the memcpy version.
I realised afterwards that copy was a bad example, consider:
extern const volatile int vi;
int a[3];
std::fill(a, a+3, vi);
Would you expect a[0] to have the same value as a[2]? If so you're likely
to be surprised (remember that volatile qualified types may be changed by
events outside your programs control).
Now imagine that fill was implemented using a block fill for integer types
(load value once and then "rep stosd [addr]"), in this case the effect will
be different from the "assign one at a time" version, and it's not clear
which if either of these is correct.
-John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk