Topic: container conversion algorithms
Author: Ricardo Fabiano de Andrade <ricardofabianodeandrade@gmail.com>
Date: Sat, 28 May 2016 23:14:03 -0500
Raw View
--001a113d50c6c4ae360533f35ec5
Content-Type: text/plain; charset=UTF-8
Is there any interest in having something like the following in the
standard:
``
template <template <typename ...> class C, class T, class U>
auto copy_to(T&& begin, U&& end) {
return C<typename T::value_type>(std::forward<T>(begin),
std::forward<U>(end));
}
template <template <typename ...> class C, class T, class U>
auto move_to(T&& begin, U&& end) {
return copy_to<C>(std::make_move_iterator(std::forward<T>(begin)),
std::make_move_iterator(std::forward<U>(end)));
}
std::string n;
auto cv = copy_to<std::vector>(n.begin(), n.end());
auto cs = copy_to<std::set>(n.begin(), n.end());
auto cu = copy_to<std::unordered_set>(n.begin(), n.end());
auto cl = copy_to<std::list>(n.begin(), n.end());
auto cd = copy_to<std::deque>(n.begin(), n.end());
auto cf = copy_to<std::forward_list>(n.begin(), n.end());
auto mv = move_to<std::vector>(n.begin(), n.end());
auto ms = move_to<std::set>(n.begin(), n.end());
auto mu = move_to<std::unordered_set>(n.begin(), n.end());
auto ml = move_to<std::list>(n.begin(), n.end());
auto md = move_to<std::deque>(n.begin(), n.end());
auto mf = move_to<std::forward_list>(n.begin(), n.end());
``
I'd include also some others to copy keys/values to/from std::map-like
containers.
Or should we wait for Eric Niebler's Ranges?
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbO%2BqTe_92eKTROxO7H7Py-ovzgJx3cVmVZ7e_HboRx6Aw%40mail.gmail.com.
--001a113d50c6c4ae360533f35ec5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Is there any interest in having something like the followi=
ng in the standard:<div><br></div><div>``</div><div><div>template <templ=
ate <typename ...> class C, class T, class U></div><div>auto copy_=
to(T&& begin, U&& end) {</div><div>=C2=A0 =C2=A0 return C&l=
t;typename T::value_type>(std::forward<T>(begin), std::forward<=
U>(end));</div><div>}</div><div><br></div><div>template <template <=
;typename ...> class C, class T, class U></div><div>auto move_to(T&am=
p;& begin, U&& end) {</div><div>=C2=A0 =C2=A0 return copy_to<=
;C>(std::make_move_iterator(std::forward<T>(begin)), std::make_mov=
e_iterator(std::forward<U>(end)));</div><div>}</div><div><br></div><d=
iv>std::string n;</div><div>auto cv =3D copy_to<std::vector>(n.begin(=
), n.end());</div><div>auto cs =3D copy_to<std::set>(n.begin(), n.end=
());</div><div>auto cu =3D copy_to<std::unordered_set>(n.begin(), n.e=
nd());</div><div>auto cl =3D copy_to<std::list>(n.begin(), n.end());<=
/div><div>auto cd =3D copy_to<std::deque>(n.begin(), n.end());</div><=
div>auto cf =3D copy_to<std::forward_list>(n.begin(), n.end());</div>=
<div><br></div><div>auto mv =3D move_to<std::vector>(n.begin(), n.end=
());</div><div>auto ms =3D move_to<std::set>(n.begin(), n.end());</di=
v><div>auto mu =3D move_to<std::unordered_set>(n.begin(), n.end());</=
div><div>auto ml =3D move_to<std::list>(n.begin(), n.end());</div><di=
v>auto md =3D move_to<std::deque>(n.begin(), n.end());</div><div>auto=
mf =3D move_to<std::forward_list>(n.begin(), n.end());</div></div><d=
iv>``</div><div><br></div><div>I'd include also some others to copy key=
s/values to/from std::map-like containers.</div><div><br></div><div>Or shou=
ld we wait for Eric Niebler's Ranges?</div><div><br></div><div><br></di=
v><div><br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbO%2BqTe_92eKTROxO7H7Py-ovzgJ=
x3cVmVZ7e_HboRx6Aw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbO%2B=
qTe_92eKTROxO7H7Py-ovzgJx3cVmVZ7e_HboRx6Aw%40mail.gmail.com</a>.<br />
--001a113d50c6c4ae360533f35ec5--
.
Author: Morwenn <morwenn29@gmail.com>
Date: Sun, 29 May 2016 03:04:02 -0700 (PDT)
Raw View
------=_Part_2255_1126192521.1464516243038
Content-Type: multipart/alternative;
boundary="----=_Part_2256_1964704081.1464516243039"
------=_Part_2256_1964704081.1464516243039
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I guess that there will be a second iteration of the Ranges TS to add=20
range-based overloads to standard container constructors.
I would wait for that one instead of providing copy_to and move_to=20
functions, even though it might take a bit of time.
Meanwhile, users can still use the iterator-based constructors, or write=20
copy_to and move_to by themselves if they really hate
the occasional boilerplate. They feel pretty trivial to implement, so there=
=20
is no need to standardize them.
Le dimanche 29 mai 2016 06:14:05 UTC+2, Ricardo Andrade a =C3=A9crit :
>
> Is there any interest in having something like the following in the=20
> standard:
>
> ``
> template <template <typename ...> class C, class T, class U>
> auto copy_to(T&& begin, U&& end) {
> return C<typename T::value_type>(std::forward<T>(begin),=20
> std::forward<U>(end));
> }
>
> template <template <typename ...> class C, class T, class U>
> auto move_to(T&& begin, U&& end) {
> return copy_to<C>(std::make_move_iterator(std::forward<T>(begin)),=20
> std::make_move_iterator(std::forward<U>(end)));
> }
>
> std::string n;
> auto cv =3D copy_to<std::vector>(n.begin(), n.end());
> auto cs =3D copy_to<std::set>(n.begin(), n.end());
> auto cu =3D copy_to<std::unordered_set>(n.begin(), n.end());
> auto cl =3D copy_to<std::list>(n.begin(), n.end());
> auto cd =3D copy_to<std::deque>(n.begin(), n.end());
> auto cf =3D copy_to<std::forward_list>(n.begin(), n.end());
>
> auto mv =3D move_to<std::vector>(n.begin(), n.end());
> auto ms =3D move_to<std::set>(n.begin(), n.end());
> auto mu =3D move_to<std::unordered_set>(n.begin(), n.end());
> auto ml =3D move_to<std::list>(n.begin(), n.end());
> auto md =3D move_to<std::deque>(n.begin(), n.end());
> auto mf =3D move_to<std::forward_list>(n.begin(), n.end());
> ``
>
> I'd include also some others to copy keys/values to/from std::map-like=20
> containers.
>
> Or should we wait for Eric Niebler's Ranges?
>
>
>
>
--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/90fe971b-3428-40e3-b524-ab8ec1ba9f4d%40isocpp.or=
g.
------=_Part_2256_1964704081.1464516243039
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I guess that there will be a second iteration of the Range=
s TS to add range-based overloads to standard container constructors.<br>I =
would wait for that one instead of providing <span style=3D"font-family: co=
urier new,monospace;">copy_to</span> and <span style=3D"font-family: courie=
r new,monospace;">move_to</span> functions, even though it might take a bit=
of time.<br><br>Meanwhile, users can still use the iterator-based construc=
tors, or write <span style=3D"font-family: courier new,monospace;">copy_to<=
/span> and <span style=3D"font-family: courier new,monospace;">move_to</spa=
n> by themselves if they really hate<br>the occasional boilerplate. They fe=
el pretty trivial to implement, so there is no need to standardize them.<br=
><br>Le dimanche 29 mai 2016 06:14:05 UTC+2, Ricardo Andrade a =C3=A9crit=
=C2=A0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Is the=
re any interest in having something like the following in the standard:<div=
><br></div><div>``</div><div><div>template <template <typename ...>=
; class C, class T, class U></div><div>auto copy_to(T&& begin, U=
&& end) {</div><div>=C2=A0 =C2=A0 return C<typename T::value_typ=
e>(std::forward<T><wbr>(begin), std::forward<U>(end));</div>=
<div>}</div><div><br></div><div>template <template <typename ...> =
class C, class T, class U></div><div>auto move_to(T&& begin, U&a=
mp;& end) {</div><div>=C2=A0 =C2=A0 return copy_to<C>(std::make_m=
ove_<wbr>iterator(std::forward<T>(<wbr>begin)), std::make_move_iterat=
or(std::<wbr>forward<U>(end)));</div><div>}</div><div><br></div><div>=
std::string n;</div><div>auto cv =3D copy_to<std::vector>(n.begin()<w=
br>, n.end());</div><div>auto cs =3D copy_to<std::set>(n.begin(), n.e=
nd());</div><div>auto cu =3D copy_to<std::unordered_set>(n.<wbr>begin=
(), n.end());</div><div>auto cl =3D copy_to<std::list>(n.begin(), n.e=
nd());</div><div>auto cd =3D copy_to<std::deque>(n.begin(), n.end());=
</div><div>auto cf =3D copy_to<std::forward_list>(n.<wbr>begin(), n.e=
nd());</div><div><br></div><div>auto mv =3D move_to<std::vector>(n.be=
gin()<wbr>, n.end());</div><div>auto ms =3D move_to<std::set>(n.begin=
(), n.end());</div><div>auto mu =3D move_to<std::unordered_set>(n.<wb=
r>begin(), n.end());</div><div>auto ml =3D move_to<std::list>(n.begin=
(), n.end());</div><div>auto md =3D move_to<std::deque>(n.begin(), n.=
end());</div><div>auto mf =3D move_to<std::forward_list>(n.<wbr>begin=
(), n.end());</div></div><div>``</div><div><br></div><div>I'd include a=
lso some others to copy keys/values to/from std::map-like containers.</div>=
<div><br></div><div>Or should we wait for Eric Niebler's Ranges?</div><=
div><br></div><div><br></div><div><br></div></div>
</blockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/90fe971b-3428-40e3-b524-ab8ec1ba9f4d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/90fe971b-3428-40e3-b524-ab8ec1ba9f4d=
%40isocpp.org</a>.<br />
------=_Part_2256_1964704081.1464516243039--
------=_Part_2255_1126192521.1464516243038--
.
Author: "T. C." <rs2740@gmail.com>
Date: Sun, 29 May 2016 07:17:00 -0700 (PDT)
Raw View
------=_Part_246_1586743825.1464531420663
Content-Type: multipart/alternative;
boundary="----=_Part_247_366245839.1464531420663"
------=_Part_247_366245839.1464531420663
Content-Type: text/plain; charset=UTF-8
On Sunday, May 29, 2016 at 12:14:05 AM UTC-4, Ricardo Andrade wrote:
>
> Is there any interest in having something like the following in the
> standard:
>
> ``
> template <template <typename ...> class C, class T, class U>
> auto copy_to(T&& begin, U&& end) {
> return C<typename T::value_type>(std::forward<T>(begin),
> std::forward<U>(end));
> }
>
> template <template <typename ...> class C, class T, class U>
> auto move_to(T&& begin, U&& end) {
> return copy_to<C>(std::make_move_iterator(std::forward<T>(begin)),
> std::make_move_iterator(std::forward<U>(end)));
> }
>
> std::string n;
> auto cv = copy_to<std::vector>(n.begin(), n.end());
> auto cs = copy_to<std::set>(n.begin(), n.end());
> auto cu = copy_to<std::unordered_set>(n.begin(), n.end());
> auto cl = copy_to<std::list>(n.begin(), n.end());
> auto cd = copy_to<std::deque>(n.begin(), n.end());
> auto cf = copy_to<std::forward_list>(n.begin(), n.end());
>
> auto mv = move_to<std::vector>(n.begin(), n.end());
> auto ms = move_to<std::set>(n.begin(), n.end());
> auto mu = move_to<std::unordered_set>(n.begin(), n.end());
> auto ml = move_to<std::list>(n.begin(), n.end());
> auto md = move_to<std::deque>(n.begin(), n.end());
> auto mf = move_to<std::forward_list>(n.begin(), n.end());
> ``
>
> I'd include also some others to copy keys/values to/from std::map-like
> containers.
>
> Or should we wait for Eric Niebler's Ranges?
>
>
>
>
Template argument deduction for constructors would make copy_to redundant
(you'd be able to just write std::vector(n.begin(), n.end())).
move_to is more interesting but feels too limited due to the inability to
specify the allocator/comparator etc.
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/568e19bc-a66a-4fbb-9328-a843f540672f%40isocpp.org.
------=_Part_247_366245839.1464531420663
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, May 29, 2016 at 12:14:05 AM UTC-4, Rica=
rdo Andrade wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr">Is there any interest in having something like the following in the st=
andard:<div><br></div><div>``</div><div><div>template <template <type=
name ...> class C, class T, class U></div><div>auto copy_to(T&&am=
p; begin, U&& end) {</div><div>=C2=A0 =C2=A0 return C<typename T=
::value_type>(std::forward<T><wbr>(begin), std::forward<U>(e=
nd));</div><div>}</div><div><br></div><div>template <template <typena=
me ...> class C, class T, class U></div><div>auto move_to(T&&=
begin, U&& end) {</div><div>=C2=A0 =C2=A0 return copy_to<C>(=
std::make_move_<wbr>iterator(std::forward<T>(<wbr>begin)), std::make_=
move_iterator(std::<wbr>forward<U>(end)));</div><div>}</div><div><br>=
</div><div>std::string n;</div><div>auto cv =3D copy_to<std::vector>(=
n.begin()<wbr>, n.end());</div><div>auto cs =3D copy_to<std::set>(n.b=
egin(), n.end());</div><div>auto cu =3D copy_to<std::unordered_set>(n=
..<wbr>begin(), n.end());</div><div>auto cl =3D copy_to<std::list>(n.b=
egin(), n.end());</div><div>auto cd =3D copy_to<std::deque>(n.begin()=
, n.end());</div><div>auto cf =3D copy_to<std::forward_list>(n.<wbr>b=
egin(), n.end());</div><div><br></div><div>auto mv =3D move_to<std::vect=
or>(n.begin()<wbr>, n.end());</div><div>auto ms =3D move_to<std::set&=
gt;(n.begin(), n.end());</div><div>auto mu =3D move_to<std::unordered_se=
t>(n.<wbr>begin(), n.end());</div><div>auto ml =3D move_to<std::list&=
gt;(n.begin(), n.end());</div><div>auto md =3D move_to<std::deque>(n.=
begin(), n.end());</div><div>auto mf =3D move_to<std::forward_list>(n=
..<wbr>begin(), n.end());</div></div><div>``</div><div><br></div><div>I'=
d include also some others to copy keys/values to/from std::map-like contai=
ners.</div><div><br></div><div>Or should we wait for Eric Niebler's Ran=
ges?</div><div><br></div><div><br></div><div><br></div></div></blockquote><=
div><br></div><div>Template argument deduction for constructors would make =
copy_to redundant (you'd be able to just write std::vector(n.begin(), n=
..end())).</div><div><br></div><div>move_to is more interesting but feels to=
o limited due to the inability to specify the allocator/comparator etc.</di=
v><div>=C2=A0</div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/568e19bc-a66a-4fbb-9328-a843f540672f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/568e19bc-a66a-4fbb-9328-a843f540672f=
%40isocpp.org</a>.<br />
------=_Part_247_366245839.1464531420663--
------=_Part_246_1586743825.1464531420663--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Sun, 29 May 2016 21:54:51 -0700 (PDT)
Raw View
------=_Part_1325_937597035.1464584091850
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, 29 May 2016 16:17:01 UTC+2, T. C. wrote:
> On Sunday, May 29, 2016 at 12:14:05 AM UTC-4, Ricardo Andrade wrote:
> Is there any interest in having something like the following in the stand=
ard:
>=20
>=20
> ``
>=20
> template <template <typename ...> class C, class T, class U>
> auto copy_to(T&& begin, U&& end) {
> =C2=A0 =C2=A0 return C<typename T::value_type>(std::forward<T>(begin), st=
d::forward<U>(end));
> }
>=20
>=20
> template <template <typename ...> class C, class T, class U>
> auto move_to(T&& begin, U&& end) {
> =C2=A0 =C2=A0 return copy_to<C>(std::make_move_iterator(std::forward<T>(b=
egin)), std::make_move_iterator(std::forward<U>(end)));
> }
>=20
>=20
> std::string n;
> auto cv =3D copy_to<std::vector>(n.begin(), n.end());
> auto cs =3D copy_to<std::set>(n.begin(), n.end());
> auto cu =3D copy_to<std::unordered_set>(n.begin(), n.end());
> auto cl =3D copy_to<std::list>(n.begin(), n.end());
> auto cd =3D copy_to<std::deque>(n.begin(), n.end());
> auto cf =3D copy_to<std::forward_list>(n.begin(), n.end());
>=20
>=20
> auto mv =3D move_to<std::vector>(n.begin(), n.end());
> auto ms =3D move_to<std::set>(n.begin(), n.end());
> auto mu =3D move_to<std::unordered_set>(n.begin(), n.end());
> auto ml =3D move_to<std::list>(n.begin(), n.end());
> auto md =3D move_to<std::deque>(n.begin(), n.end());
> auto mf =3D move_to<std::forward_list>(n.begin(), n.end());
> ``
>=20
>=20
> I'd include also some others to copy keys/values to/from std::map-like co=
ntainers.
>=20
>=20
> Or should we wait for Eric Niebler's Ranges?
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> Template argument deduction for constructors would make copy_to redundant=
(you'd be able to just write std::vector(n.begin(), n.end())).
>=20
>=20
> move_to is more interesting but feels too limited due to the inability to=
specify the allocator/comparator etc.
> =C2=A0
Repeating n is not feasible where it's the result of a range algorithm (tra=
nsform, slice etc.), especially where that may involve temporaries with ful=
l-expression bounded lifetime.=20
Insofar as Ranges TS is influenced by boost::range, this exists as boost::c=
opy_range<T>. I'd hope it makes it into Ranges TS, but it is easily overloo=
ked, unfortunately.
--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/9d7dcd52-75d4-4af7-813c-0dc6025631c6%40isocpp.or=
g.
------=_Part_1325_937597035.1464584091850--
.