Topic: N3686: Range (Traversable) constructors and r-value


Author: tomaszkam@gmail.com
Date: Wed, 9 Jul 2014 14:22:17 -0700 (PDT)
Raw View
------=_Part_458_3366628.1404940937344
Content-Type: text/plain; charset=UTF-8

The paper N3686
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3686.html> add
additional constructors for ST: containers in form:
template<typename Traversable> C(Traversable&& t)
And requires the container C to detect if Traversable owns elements (is
Container instead of Range) and it can move elements. This requires from
implementation of the std::vector
to be able to detect any user defined container type and will end up with
not supporting custom containers or having special trait like
(is_container).

But actually i think that the Traversable object should be responsible for
informing if it owns element and this can
be achieved bu defining r-value overloads for begin/end methods/free
functions.

In the example of vector, if we have following simple implementation of
Travesable constructor:
template<typename Traversable> C(Traversable&& t)
  : C{begin(std::forward<Traversable>(t)),
end(std::forward<Traversable>(t))} //just forward to two iterator version
{};

And have following additional members define:
typedef std::move_iterator<iterator> move_iterator;
move_iterator begin() &&;
move_iterator end() &&;

Then the following code:
std::vector<unique_pointer<Derived>> f();
std::vector<unique_pointer<Base>> v(f());
Will actaully work and move constructs unique_pointer<Base> from
unique_pointer<Derived> element by element.

In addition the user-defined container must simply provide begin/end &&
overloads to be used by
such constructor. The non-owning range jak (irange) will simply not define
such members.

--

---
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 http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_458_3366628.1404940937344
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The paper&nbsp;<a href=3D"http://www.open-std.org/jtc1/sc2=
2/wg21/docs/papers/2013/n3686.html">N3686</a> add additional constructors f=
or ST: containers in form:<br>template&lt;typename Traversable&gt; C(Traver=
sable&amp;&amp; t)<br>And requires the container C to detect if Traversable=
 owns elements (is Container instead of Range) and it can move elements. Th=
is requires from implementation of the std::vector<br>to be able to detect =
any user defined container type and will end up with not supporting custom =
containers or having special trait like (is_container).<br><br>But actually=
 i think that the Traversable object should be responsible for informing if=
 it owns element and this can <br>be achieved bu defining r-value overloads=
 for begin/end methods/free functions.<br><br>In the example of vector, if =
we have following simple implementation of Travesable constructor:<br>templ=
ate&lt;typename Traversable&gt; C(Traversable&amp;&amp; t)<br>&nbsp; : C{be=
gin(std::forward&lt;Traversable&gt;(t)), end(std::forward&lt;Traversable&gt=
;(t))} //just forward to two iterator version<br>{};<br><br>And have follow=
ing additional members define:<br>typedef std::move_iterator&lt;iterator&gt=
; move_iterator;<br>move_iterator begin() &amp;&amp;;<br>move_iterator end(=
) &amp;&amp;;<br><br>Then the following code:<br>std::vector&lt;unique_poin=
ter&lt;Derived&gt;&gt; f();<br>std::vector&lt;unique_pointer&lt;Base&gt;&gt=
; v(f());<br>Will actaully work and move constructs unique_pointer&lt;Base&=
gt; from unique_pointer&lt;Derived&gt; element by element.<br><br>In additi=
on the user-defined container must simply provide begin/end &amp;&amp; over=
loads to be used by<br>such constructor. The non-owning range jak (irange) =
will simply not define such members.<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&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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_458_3366628.1404940937344--

.