Re: std::copy implementation standard conforming?
Roman.Perepelitsa@gmail.com wrote:
The problem is not undefined behavior but the fact that template
parameter deduction does not do conversions that is
void bar(T[1] x);//1
void bar(T *x);//2
template <class T> foo(T x) {bar (x);}
char x[1];
char *y = x;
foo(x) ;// calls bar(char[1]);
foo(y) ;// calls bar(char *);
data->data is a a one byte array not a byte *. Cast is the solution
or a named temp like
byte *out = data->data; // this does the conversion.
std::copy(array.begin(),array.end(),out);
Implementation of std::copy is standard conforming. When you have UB
in your program, compiler can do whatever he wants. Usually the best
it can do is to signal you somehow (assert, runtime error etc).
Previous implementation did nothing to detect UB while new
implementation of std::copy detects UB and signals about it.
I don't have a copy of the standard on me, but to the best of my
knowledge (and memory), as long as the struct is a POD and extra memory
was allocated properly for it, the struct hack is 100% legal in C++ and
has defined behavior.
Andrei
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]