Topic: Allow containers and iterators of incomplete types
Author: stonewine.winestone@gmail.com
Date: Thu, 7 Jul 2016 00:51:30 -0700 (PDT)
Raw View
------=_Part_7099_1202720759.1467877890307
Content-Type: multipart/alternative;
boundary="----=_Part_7100_437200494.1467877890307"
------=_Part_7100_437200494.1467877890307
Content-Type: text/plain; charset=UTF-8
The idea is to allow STL containers, or a subset of them, to be able to
created (is instantiate the word?) with incomplete types and to be able to
create their iterators:
struct IncompleteType;
std::vector<IncompleteType> a;
std::vector<IncompleteType>::iterator a;
Some problems this can solve:
- In the definition of an object, it may wish to store a vector of
itself. This can be useful perhaps if you have nodes which can contain more
of itself, perhaps you are parsing JSON or something.
struct Node {
int data;
std::vector<Node> children;
};
- In the definition of an object, it wishes to store an iterator to
itself. This can be useful perhaps if you need to store where you are
within a container for whatever reason.
// Probably not the best example
struct Node {
int data;
std::vector<Node> children;
std::vector<Node>::iterator position_in_parent;
};
Alternatives to this:
- Using a pointer, Node*. Sometimes you might not want to store a vector
but instead a list, or some container without contiguous storage, of some
object. This is where iterators are more useful as they can abstract this
difference away and allow operator++ and such to remain functional. A
pointer can also lack the restrictions of a non-random access iterator and
is unable to model a reverse iterator.
- Using a size_t to store your index within the container. This has
limitations in terms of access speed if the container is a std::list or
similar. It also cannot be passed to STL algorithms and has to be turned
into an iterator first and this requires access to your container to do so.
Also boost containers support this
<http://www.boost.org/doc/libs/1_54_0/doc/html/container/containers_of_incomplete_types.html>,
though I'm not sure how much people care about this.
--
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/e99cdd27-5763-40b9-baf4-6b04afb3f85e%40isocpp.org.
------=_Part_7100_437200494.1467877890307
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div>The idea is to allow STL containers, or a subset =
of them, to be able to created (is instantiate the word?) with incomplete t=
ypes and to be able to create their iterators:<br><br></div><div class=3D"p=
rettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break=
-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">I=
ncompleteType</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r><br>std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">IncompleteType</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">></span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">vector</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">IncompleteType</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">iterator a</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span></div></code></div><div></div><div><br></div><d=
iv>Some problems this can solve:</div><div><ul><li>In the definition of an =
object, it may wish to store a vector of itself. This can be useful perhaps=
if you have nodes which can contain more of itself, perhaps you are parsin=
g JSON or something.<br><br><div class=3D"prettyprint" style=3D"border: 1px=
solid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250=
, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Node</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> data</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">vector</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">No=
de</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> children</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code></div>=
<br></li><li>In the definition of an object, it wishes to store an iterator=
to itself. This can be useful perhaps if you need to store where you are w=
ithin a container for whatever reason.<br><br><div class=3D"prettyprint" st=
yle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgro=
und-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
Probably not the best example</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Node</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> data</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">vector</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Node</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> children</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">vector</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">Node</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
;::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">iterato=
r position_in_parent</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</s=
pan></div></code></div><br>Alternatives to this:<br></li><ul><li>Using a po=
inter, Node*. Sometimes you might not want to store a vector but instead a =
list, or some container without contiguous storage, of some object. This is=
where iterators are more useful as they can abstract this difference away =
and allow operator++ and such to remain functional. A pointer can also lack=
the restrictions of a non-random access iterator and is unable to model a =
reverse iterator.<br></li><li>Using a size_t to store your index within the=
container. This has limitations in terms of access speed if the container =
is a std::list or similar. It also cannot be passed to STL algorithms and h=
as to be turned into an iterator first and this requires access to your con=
tainer to do so.</li></ul></ul><div><span style=3D"line-height: 17px;">Also=
=C2=A0<a href=3D"http://www.boost.org/doc/libs/1_54_0/doc/html/container/co=
ntainers_of_incomplete_types.html">boost containers support this</a>, thoug=
h I'm not sure how much people care about this.</span></div></div><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/e99cdd27-5763-40b9-baf4-6b04afb3f85e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e99cdd27-5763-40b9-baf4-6b04afb3f85e=
%40isocpp.org</a>.<br />
------=_Part_7100_437200494.1467877890307--
------=_Part_7099_1202720759.1467877890307--
.
Author: TONGARI J <tongari95@gmail.com>
Date: Thu, 7 Jul 2016 16:23:32 +0800
Raw View
--001a114e6e86d1e6e9053707668c
Content-Type: text/plain; charset=UTF-8
The last paper I can find is: wg21.link/n4510
The status shows that it's adopted, but I'm not sure if this goes into
c++17.
--
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/CANCwVhcMdebuJsLimiNeJR4RZ4KbwcMrFy7Bs0A5W%3D695fUzPQ%40mail.gmail.com.
--001a114e6e86d1e6e9053707668c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra">The last paper I can find is:=
=C2=A0wg21.link/n4510</div><div class=3D"gmail_extra">The status shows that=
it's adopted, but I'm not sure if this goes into c++17.</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/CANCwVhcMdebuJsLimiNeJR4RZ4KbwcMrFy7B=
s0A5W%3D695fUzPQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANCwVhcMdebuJs=
LimiNeJR4RZ4KbwcMrFy7Bs0A5W%3D695fUzPQ%40mail.gmail.com</a>.<br />
--001a114e6e86d1e6e9053707668c--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 7 Jul 2016 12:01:21 +0300
Raw View
On 7 July 2016 at 11:23, TONGARI J <tongari95@gmail.com> wrote:
> The last paper I can find is: wg21.link/n4510
> The status shows that it's adopted, but I'm not sure if this goes into
> c++17.
Yes, it's going into C++17.
--
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/CAFk2RUa%2BSAZa2WvbTVqxbG-%2BbZQPM%2BQPkyoSx3OxoK3apyh6uQ%40mail.gmail.com.
.
Author: stonewine.winestone@gmail.com
Date: Thu, 7 Jul 2016 02:23:42 -0700 (PDT)
Raw View
------=_Part_4800_104827414.1467883422266
Content-Type: multipart/alternative;
boundary="----=_Part_4801_1987486571.1467883422267"
------=_Part_4801_1987486571.1467883422267
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I found that but it says
>
> T shall be complete before any member of the resulting specialization=E2=
=80=A6 is=20
> referenced.
>
Does that mean you cannot reference std::vector<IncompleteType>::iterator?
On Thursday, July 7, 2016 at 6:23:34 PM UTC+10, TONGARI J wrote:
>
> The last paper I can find is: wg21.link/n4510
> The status shows that it's adopted, but I'm not sure if this goes into=20
> c++17.
>
--=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/01877a48-906f-44e4-8935-ed1ea65109a9%40isocpp.or=
g.
------=_Part_4801_1987486571.1467883422267
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I found that but it says<blockquote class=3D"gmail_quote" =
style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-sty=
le: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><code=
style=3D"white-space: pre-wrap; color: rgb(0, 0, 0);">T</code><span style=
=3D"color: rgb(0, 0, 0); font-family: "Times New Roman"; font-siz=
e: medium;">=C2=A0shall be complete before any member of the resulting spec=
ialization=E2=80=A6 is referenced.</span><br></blockquote><div>Does that me=
an you cannot reference std::vector<IncompleteType>::iterator?<br><br=
>On Thursday, July 7, 2016 at 6:23:34 PM UTC+10, TONGARI J wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>The last paper I c=
an find is:=C2=A0wg21.link/n4510</div><div>The status shows that it's a=
dopted, but I'm not sure if this goes into c++17.</div></div>
</blockquote></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/01877a48-906f-44e4-8935-ed1ea65109a9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/01877a48-906f-44e4-8935-ed1ea65109a9=
%40isocpp.org</a>.<br />
------=_Part_4801_1987486571.1467883422267--
------=_Part_4800_104827414.1467883422266--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 7 Jul 2016 13:28:10 +0300
Raw View
On 7 July 2016 at 12:23, <stonewine.winestone@gmail.com> wrote:
> I found that but it says
>>
>> T shall be complete before any member of the resulting specialization=E2=
=80=A6 is
>> referenced.
>
> Does that mean you cannot reference std::vector<IncompleteType>::iterator=
?
Yes. The paper is conservative. It's quite probable that the support
for incomplete types will be extended
over time, proposals welcome.
--=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/CAFk2RUaD4Q9g-8yqP3qLDJEmX%3DX2HTqzUeismm1dnTqzw=
CCGTA%40mail.gmail.com.
.