Re: std::copy implementation standard conforming?
In article <1182276861.155331.76080@q75g2000hsh.googlegroups.com>,
Mathias Gaunard <loufoque@gmail.com> wrote:
On Jun 19, 5:57 pm, Ben <gro...@theyoungfamily.co.uk> wrote:
Now the array binds to the new copy version, and the check_iterator
gives an error during the copy as it thinks the array is only one byte
long.
It's not that it thinks it is one byte long. It is one byte long.
Accessing an array past the end is undefined behaviour.
The question is, is this std::copy overload allowed by the standard?
Yes.
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);
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]