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 &lt;templ=
ate &lt;typename ...&gt; class C, class T, class U&gt;</div><div>auto copy_=
to(T&amp;&amp; begin, U&amp;&amp; end) {</div><div>=C2=A0 =C2=A0 return C&l=
t;typename T::value_type&gt;(std::forward&lt;T&gt;(begin), std::forward&lt;=
U&gt;(end));</div><div>}</div><div><br></div><div>template &lt;template &lt=
;typename ...&gt; class C, class T, class U&gt;</div><div>auto move_to(T&am=
p;&amp; begin, U&amp;&amp; end) {</div><div>=C2=A0 =C2=A0 return copy_to&lt=
;C&gt;(std::make_move_iterator(std::forward&lt;T&gt;(begin)), std::make_mov=
e_iterator(std::forward&lt;U&gt;(end)));</div><div>}</div><div><br></div><d=
iv>std::string n;</div><div>auto cv =3D copy_to&lt;std::vector&gt;(n.begin(=
), n.end());</div><div>auto cs =3D copy_to&lt;std::set&gt;(n.begin(), n.end=
());</div><div>auto cu =3D copy_to&lt;std::unordered_set&gt;(n.begin(), n.e=
nd());</div><div>auto cl =3D copy_to&lt;std::list&gt;(n.begin(), n.end());<=
/div><div>auto cd =3D copy_to&lt;std::deque&gt;(n.begin(), n.end());</div><=
div>auto cf =3D copy_to&lt;std::forward_list&gt;(n.begin(), n.end());</div>=
<div><br></div><div>auto mv =3D move_to&lt;std::vector&gt;(n.begin(), n.end=
());</div><div>auto ms =3D move_to&lt;std::set&gt;(n.begin(), n.end());</di=
v><div>auto mu =3D move_to&lt;std::unordered_set&gt;(n.begin(), n.end());</=
div><div>auto ml =3D move_to&lt;std::list&gt;(n.begin(), n.end());</div><di=
v>auto md =3D move_to&lt;std::deque&gt;(n.begin(), n.end());</div><div>auto=
 mf =3D move_to&lt;std::forward_list&gt;(n.begin(), n.end());</div></div><d=
iv>``</div><div><br></div><div>I&#39;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&#39;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&quot; 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 &lt;template &lt;typename ...&gt=
; class C, class T, class U&gt;</div><div>auto copy_to(T&amp;&amp; begin, U=
&amp;&amp; end) {</div><div>=C2=A0 =C2=A0 return C&lt;typename T::value_typ=
e&gt;(std::forward&lt;T&gt;<wbr>(begin), std::forward&lt;U&gt;(end));</div>=
<div>}</div><div><br></div><div>template &lt;template &lt;typename ...&gt; =
class C, class T, class U&gt;</div><div>auto move_to(T&amp;&amp; begin, U&a=
mp;&amp; end) {</div><div>=C2=A0 =C2=A0 return copy_to&lt;C&gt;(std::make_m=
ove_<wbr>iterator(std::forward&lt;T&gt;(<wbr>begin)), std::make_move_iterat=
or(std::<wbr>forward&lt;U&gt;(end)));</div><div>}</div><div><br></div><div>=
std::string n;</div><div>auto cv =3D copy_to&lt;std::vector&gt;(n.begin()<w=
br>, n.end());</div><div>auto cs =3D copy_to&lt;std::set&gt;(n.begin(), n.e=
nd());</div><div>auto cu =3D copy_to&lt;std::unordered_set&gt;(n.<wbr>begin=
(), n.end());</div><div>auto cl =3D copy_to&lt;std::list&gt;(n.begin(), n.e=
nd());</div><div>auto cd =3D copy_to&lt;std::deque&gt;(n.begin(), n.end());=
</div><div>auto cf =3D copy_to&lt;std::forward_list&gt;(n.<wbr>begin(), n.e=
nd());</div><div><br></div><div>auto mv =3D move_to&lt;std::vector&gt;(n.be=
gin()<wbr>, n.end());</div><div>auto ms =3D move_to&lt;std::set&gt;(n.begin=
(), n.end());</div><div>auto mu =3D move_to&lt;std::unordered_set&gt;(n.<wb=
r>begin(), n.end());</div><div>auto ml =3D move_to&lt;std::list&gt;(n.begin=
(), n.end());</div><div>auto md =3D move_to&lt;std::deque&gt;(n.begin(), n.=
end());</div><div>auto mf =3D move_to&lt;std::forward_list&gt;(n.<wbr>begin=
(), n.end());</div></div><div>``</div><div><br></div><div>I&#39;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&#39;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&quot; 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 &lt;template &lt;type=
name ...&gt; class C, class T, class U&gt;</div><div>auto copy_to(T&amp;&am=
p; begin, U&amp;&amp; end) {</div><div>=C2=A0 =C2=A0 return C&lt;typename T=
::value_type&gt;(std::forward&lt;T&gt;<wbr>(begin), std::forward&lt;U&gt;(e=
nd));</div><div>}</div><div><br></div><div>template &lt;template &lt;typena=
me ...&gt; class C, class T, class U&gt;</div><div>auto move_to(T&amp;&amp;=
 begin, U&amp;&amp; end) {</div><div>=C2=A0 =C2=A0 return copy_to&lt;C&gt;(=
std::make_move_<wbr>iterator(std::forward&lt;T&gt;(<wbr>begin)), std::make_=
move_iterator(std::<wbr>forward&lt;U&gt;(end)));</div><div>}</div><div><br>=
</div><div>std::string n;</div><div>auto cv =3D copy_to&lt;std::vector&gt;(=
n.begin()<wbr>, n.end());</div><div>auto cs =3D copy_to&lt;std::set&gt;(n.b=
egin(), n.end());</div><div>auto cu =3D copy_to&lt;std::unordered_set&gt;(n=
..<wbr>begin(), n.end());</div><div>auto cl =3D copy_to&lt;std::list&gt;(n.b=
egin(), n.end());</div><div>auto cd =3D copy_to&lt;std::deque&gt;(n.begin()=
, n.end());</div><div>auto cf =3D copy_to&lt;std::forward_list&gt;(n.<wbr>b=
egin(), n.end());</div><div><br></div><div>auto mv =3D move_to&lt;std::vect=
or&gt;(n.begin()<wbr>, n.end());</div><div>auto ms =3D move_to&lt;std::set&=
gt;(n.begin(), n.end());</div><div>auto mu =3D move_to&lt;std::unordered_se=
t&gt;(n.<wbr>begin(), n.end());</div><div>auto ml =3D move_to&lt;std::list&=
gt;(n.begin(), n.end());</div><div>auto md =3D move_to&lt;std::deque&gt;(n.=
begin(), n.end());</div><div>auto mf =3D move_to&lt;std::forward_list&gt;(n=
..<wbr>begin(), n.end());</div></div><div>``</div><div><br></div><div>I&#39;=
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&#39;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&#39;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&quot; 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--

.