Topic: Simple std::copy, std::move
Author: Myriachan <myriachan@gmail.com>
Date: Tue, 22 Dec 2015 12:26:52 -0800 (PST)
Raw View
------=_Part_7936_1049723035.1450816012124
Content-Type: multipart/alternative;
boundary="----=_Part_7937_1373181867.1450816012124"
------=_Part_7937_1373181867.1450816012124
Content-Type: text/plain; charset=UTF-8
Is there a reason that there is no std::copy or std::move that just copies
one thing to the other? It would be convenient for arrays, since they
don't have an operator =.
template <typename T, typename U>
T ©(T &dest, const U &src);
template <typename T, typename U, size_t S>
T (©(T (&dest)[S], const U (&src)[S]))[S];
template <typename T, typename U>
T &move(T &dest, U &&src);
template <typename T, typename U, size_t S>
T (&move(T (&dest)[S], U (&src)[S]))[S];
I don't know whether it should be src, dest or dest, src. Also, allowing T
and U to be different is questionable.
I assume undefined behavior if std::addressof(dest) == std::addressof(src).
Or if you play games with reinterpret_cast to make overlapping array
references.
Example implementation:
template <typename T, typename U>
T ©(T &dest, const U &src)
{
dest = src;
return dest;
}
template <typename T, typename U, size_t S>
std::enable_if_t<std::is_trivially_copyable<T>::value && std::is_same<T,
U>::value, T (&)[S]> copy(T (&dest)[S], const U (&src)[S])
{
std::memcpy(dest, src, sizeof(dest));
return dest;
}
template <typename T, typename U, size_t S>
std::enable_if_t<!(std::is_trivially_copyable<T>::value && std::is_same<T,
U>::value), T (&)[S]> copy(T (&dest)[S], const U (&src)[S])
{
for (std::size_t x = 0; x < S; ++x)
dest[x] = src[x];
return dest;
}
Melissa
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7937_1373181867.1450816012124
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Is there a reason that there is no std::copy or std::move =
that just copies one thing to the other?=C2=A0 It would be convenient for a=
rrays, since they don't have an operator =3D.<br><br><span style=3D"fon=
t-family: courier new,monospace;">template <typename T, typename U><b=
r>T &copy(T &dest, const U &src);<br>template <typename T, t=
ypename U, size_t S><br>T (&copy(T (&dest)[S], const U (&src=
)[S]))[S];<br><br>template <typename T, typename U><br>T &move(T =
&dest, U &&src);<br>template <typename T, typename U, size_t=
S><br>T (&move(T (&dest)[S], U (&src)[S]))[S];<br><br></spa=
n>I don't know whether it should be <span style=3D"font-family: courier=
new,monospace;">src, dest</span> or <span style=3D"font-family: courier ne=
w,monospace;">dest, src</span>.=C2=A0 Also, allowing T and U to be differen=
t is questionable.<br><br>I assume undefined behavior if <span style=3D"fon=
t-family: courier new,monospace;">std::addressof(dest) =3D=3D std::addresso=
f(src)</span>.=C2=A0 Or if you play games with <span style=3D"font-family: =
courier new,monospace;">reinterpret_cast</span> to make overlapping array r=
eferences.<br><br>Example implementation:<br><br><span style=3D"font-family=
: courier new,monospace;">template <typename T, typename U><br>T &=
;copy(T &dest, const U &src)<br>{<br>=C2=A0=C2=A0=C2=A0 dest =3D sr=
c;<br>=C2=A0=C2=A0=C2=A0 return dest;<br>}<br><br>template <typename T, =
typename U, size_t S><br>std::enable_if_t<std::is_trivially_copyable&=
lt;T>::value && std::is_same<T, U>::value, T (&)[S]>=
; copy(T (&dest)[S], const U (&src)[S])<br>{<br>=C2=A0=C2=A0=C2=A0 =
std::memcpy(dest, src, sizeof(dest));<br>=C2=A0=C2=A0=C2=A0 return dest;<br=
>}<br><br>template <typename T, typename U, size_t S><br>std::enable_=
if_t<!(std::is_trivially_copyable<T>::value
&& std::is_same<T, U>::value), T (&)[S]> copy(T=20
(&dest)[S], const U (&src)[S])<br>{<br>=C2=A0=C2=A0=C2=A0 for (std:=
:size_t x =3D 0; x < S; ++x)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 dest[x] =3D src[x];<br>=C2=A0=C2=A0=C2=A0 return dest;<br>}</span><br><=
br>Melissa<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_7937_1373181867.1450816012124--
------=_Part_7936_1049723035.1450816012124--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 22 Dec 2015 14:54:31 -0600
Raw View
On Tue, Dec 22, 2015 at 2:26 PM, Myriachan <myriachan@gmail.com> wrote:
> Is there a reason that there is no std::copy or std::move that just copies
> one thing to the other? It would be convenient for arrays, since they don't
> have an operator =.
That is why you need std::array. I don't think we should change
value semantics' syntax.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 22 Dec 2015 13:18:24 -0800 (PST)
Raw View
------=_Part_2360_1241324149.1450819104912
Content-Type: multipart/alternative;
boundary="----=_Part_2361_62091630.1450819104912"
------=_Part_2361_62091630.1450819104912
Content-Type: text/plain; charset=UTF-8
Would this not simply be the range copy/move? What you're talking about is
effectively contingent on ranges, which is ongoing work at present.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2361_62091630.1450819104912
Content-Type: text/html; charset=UTF-8
<div dir="ltr">Would this not simply be the range copy/move? What you're talking about is effectively contingent on ranges, which is ongoing work at present.<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="https://groups.google.com/a/isocpp.org/group/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
------=_Part_2361_62091630.1450819104912--
------=_Part_2360_1241324149.1450819104912--
.