Topic: N3686: Range (Traversable) constructors and


Author: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Date: Sat, 12 Jul 2014 11:23:45 +0200
Raw View
--001a11337e429610d604fdfb9e95
Content-Type: text/plain; charset=UTF-8

This is a great suggestion.

In general, containers should be allowed to provide begin() && and end() &&
overloads. Their result type should be convertible to container::iterator.

  begin() const and end() const return container::const_iterator.
  begin() and end() return container::iterator, which is convertible to
container::const_iterator.
  begin() && and end() && return an unspecified type, which is convertible
to container::iterator.

This is a relaxation of the current requirements, so all existing
containers are compliant. It would be nice to have
container::rvalue_iterator or container::move_iterator instead of the
unspecified type, but we can't require it type because the existing
containers don't provide it.

Roman Perepelitsa.

2014-07-09 23:22 GMT+02:00 <tomaszkam@gmail.com>:

> 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/.
>

--

---
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/.

--001a11337e429610d604fdfb9e95
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra">This is a great suggestion.</di=
v><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">In genera=
l, containers should be allowed to provide <font face=3D"courier new, monos=
pace">begin() &amp;&amp;</font> and <font face=3D"courier new, monospace">e=
nd() &amp;&amp;</font> overloads. Their result type should be convertible t=
o <font face=3D"courier new, monospace">container::iterator</font>.</div>

<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">=C2=A0 <fon=
t face=3D"courier new, monospace">begin() const</font> and <font face=3D"co=
urier new, monospace">end() const</font> return <font face=3D"courier new, =
monospace">container::const_iterator</font>.</div>

<div class=3D"gmail_extra">=C2=A0 <font face=3D"courier new, monospace">beg=
in()</font> and <font face=3D"courier new, monospace">end()</font> return <=
font face=3D"courier new, monospace">container::iterator</font>, which is c=
onvertible to <font face=3D"courier new, monospace">container::const_iterat=
or</font>.</div>

<div class=3D"gmail_extra">=C2=A0 <font face=3D"courier new, monospace">beg=
in() &amp;&amp;</font> and <font face=3D"courier new, monospace">end() &amp=
;&amp;</font> return an unspecified type, which is convertible to <font fac=
e=3D"courier new, monospace">container::iterator</font>.</div>

<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">This is a r=
elaxation of the current requirements, so all existing containers are compl=
iant. It would be nice to have <font face=3D"courier new, monospace">contai=
ner::rvalue_iterator</font>=C2=A0or <font face=3D"courier new, monospace">c=
ontainer::move_iterator</font> instead of the unspecified type, but we can&=
#39;t require it type because the existing containers don&#39;t provide it.=
</div>

<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Roman Perep=
elitsa.</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">2014=
-07-09 23:22 GMT+02:00  <span dir=3D"ltr">&lt;<a href=3D"mailto:tomaszkam@g=
mail.com" target=3D"_blank">tomaszkam@gmail.com</a>&gt;</span>:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr">The paper=C2=A0<a href=3D"http://www.open=
-std.org/jtc1/sc22/wg21/docs/papers/2013/n3686.html" target=3D"_blank">N368=
6</a> add additional constructors for ST: containers in form:<br>

template&lt;typename Traversable&gt; C(Traversable&amp;&amp; t)<br>And requ=
ires the container C to detect if Traversable owns elements (is Container i=
nstead of Range) and it can move elements. This requires from implementatio=
n of the std::vector<br>

to be able to detect any user defined container type and will end up with n=
ot supporting custom containers or having special trait like (is_container)=
..<br><br>But actually i think that the Traversable object should be respons=
ible for informing if it owns element and this can <br>

be achieved bu defining r-value overloads for begin/end methods/free functi=
ons.<br><br>In the example of vector, if we have following simple implement=
ation of Travesable constructor:<br>template&lt;typename Traversable&gt; C(=
Traversable&amp;&amp; t)<br>

=C2=A0 : C{begin(std::forward&lt;Traversable&gt;(t)), end(std::forward&lt;T=
raversable&gt;(t))} //just forward to two iterator version<br>{};<br><br>An=
d have following additional members define:<br>typedef std::move_iterator&l=
t;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_pointer&lt;Derived&gt;&g=
t; f();<br>std::vector&lt;unique_pointer&lt;Base&gt;&gt; v(f());<br>Will ac=
taully work and move constructs unique_pointer&lt;Base&gt; from unique_poin=
ter&lt;Derived&gt; element by element.<br>

<br>In addition the user-defined container must simply provide begin/end &a=
mp;&amp; overloads to be used by<br>such constructor. The non-owning range =
jak (irange) will simply not define such members.<span class=3D""><font col=
or=3D"#888888"><br>

</font></span></div><span class=3D""><font color=3D"#888888">

<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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></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 />

--001a11337e429610d604fdfb9e95--

.