Topic: Usability extensions to offsetof
Author: Myriachan <myriachan@gmail.com>
Date: Tue, 2 Sep 2014 21:37:53 -0700 (PDT)
Raw View
------=_Part_5899_1473812941.1409719073552
Content-Type: text/plain; charset=UTF-8
As a generalization of std::is_standard_layout, how about an
std::is_offsetof_compatible? Requiring standard-layout in order to use
offsetof is too restrictive; almost all implementations could support
offsetof in more situations than the Standard's "standard-layout"
definition allows.
Standard-layout makes stricter guarantees than are needed for offsetof
itself to work. Given certain caveats, and most implementations, offsetof
can work with any class that does not use virtual inheritance. An
implementation that isn't compatible wouldn't have to allow it, though
standard-layout would be the minimum support. The boundary conditions
would be either implementation choices (such as using offsets of a base
class on derived classes is defined when the base is the first base class)
or entirely undefined (using offsets on virtually-derived classes).
Note that merely reordering elements, such as to coalesce all private
members together, isn't enough to say that offsetof isn't compatible.
Whether element order matches memory order is orthogonal to the ability to
reference elements using offsets into a char array.
With this, there could also be member_pointer_to_offset and
offset_to_member_pointer library functions that work with compatible
classes.
Melissa
--
---
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_5899_1473812941.1409719073552
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">As a generalization of <span style=3D"font-family: courier=
new,monospace;">std::is_standard_layout</span>, how about an <span style=
=3D"font-family: courier new,monospace;">std::is_offsetof_compatible</span>=
? Requiring standard-layout in order to use <span style=3D"font-famil=
y: courier new,monospace;">offsetof</span> is too restrictive; almost all i=
mplementations could support <span style=3D"font-family: courier new,monosp=
ace;">offsetof</span> in more situations than the Standard's "standard-layo=
ut" definition allows.<br><br>Standard-layout makes stricter guarantees tha=
n are needed for <span style=3D"font-family: courier new,monospace;">offset=
of</span> itself to work. Given certain caveats, and most implementat=
ions, <span style=3D"font-family: courier new,monospace;">offsetof</span> c=
an work with any class that does not use virtual inheritance. An impl=
ementation that isn't compatible wouldn't have to allow it, though standard=
-layout would be the minimum support. The boundary conditions would b=
e either implementation choices (such as using offsets of a base class on d=
erived classes is defined when the base is the first base class) or entirel=
y undefined (using offsets on virtually-derived classes).<br><br>Note that =
merely reordering elements, such as to coalesce all private members togethe=
r, isn't enough to say that <span style=3D"font-family: courier new,monospa=
ce;">offsetof</span> isn't compatible. Whether element order matches =
memory order is orthogonal to the ability to reference elements using offse=
ts into a <span style=3D"font-family: courier new,monospace;">char</span> a=
rray.<br><br>With this, there could also be <span style=3D"font-family: cou=
rier new,monospace;">member_pointer_to_offset</span> and <span style=3D"fon=
t-family: courier new,monospace;">offset_to_member_pointer</span> library f=
unctions that work with compatible classes.<br><br>Melissa<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" 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_5899_1473812941.1409719073552--
.
Author: David Krauss <potswa@gmail.com>
Date: Wed, 3 Sep 2014 12:46:39 +0800
Raw View
--Apple-Mail=_7A7F992C-532A-4032-8EF8-97F739D2CC24
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
On 2014-09-03, at 12:37 PM, Myriachan <myriachan@gmail.com> wrote:
> As a generalization of std::is_standard_layout, how about an std::is_offs=
etof_compatible? Requiring standard-layout in order to use offsetof is too=
restrictive; almost all implementations could support offsetof in more sit=
uations than the Standard's "standard-layout" definition allows.
offsetof is a vestige of C compatibility, and standard layout is specifical=
ly tailored to C ABI compatibility. So the restriction is probably exactly =
what its designers intended.
Where would you prefer to use offsetof, instead of a pointer-to-member?
> With this, there could also be member_pointer_to_offset and offset_to_mem=
ber_pointer library functions that work with compatible classes.
There always could have been, but why?
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_7A7F992C-532A-4032-8EF8-97F739D2CC24
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;09–03, at 12:37 PM, Myriachan <<a href=3D"mailto:myriachan@g=
mail.com">myriachan@gmail.com</a>> wrote:</div><br class=3D"Apple-interc=
hange-newline"><blockquote type=3D"cite"><div dir=3D"ltr">As a generalizati=
on of <span style=3D"font-family: courier new,monospace;">std::is_standard_=
layout</span>, how about an <span style=3D"font-family: courier new,monospa=
ce;">std::is_offsetof_compatible</span>? Requiring standard-layout in=
order to use <span style=3D"font-family: courier new,monospace;">offsetof<=
/span> is too restrictive; almost all implementations could support <span s=
tyle=3D"font-family: courier new,monospace;">offsetof</span> in more situat=
ions than the Standard's "standard-layout" definition allows.<br></div></bl=
ockquote><div><br></div><div><font face=3D"Courier">offsetof</font> is a ve=
stige of C compatibility, and standard layout is specifically tailored to C=
ABI compatibility. So the restriction is probably exactly what its designe=
rs intended.</div><div><br></div><div>Where would you prefer to use <font f=
ace=3D"Courier">offsetof</font>, instead of a pointer-to-member?</div><br><=
blockquote type=3D"cite"><div dir=3D"ltr">With this, there could also be <s=
pan style=3D"font-family: 'courier new', monospace;">member_pointer_to_offs=
et</span> and <span style=3D"font-family: 'courier new', monospace;">offset=
_to_member_pointer</span> library functions that work with compatible class=
es.</div></blockquote><br></div><div>There always could have been, but why?=
</div><div><br></div></body></html>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--Apple-Mail=_7A7F992C-532A-4032-8EF8-97F739D2CC24--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 03 Sep 2014 09:03:01 -0700
Raw View
On Wednesday 03 September 2014 12:46:39 David Krauss wrote:
> Where would you prefer to use offsetof, instead of a pointer-to-member?
In the calculation of the reverse: from member to top-of-object.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 4 Sep 2014 12:19:38 -0700 (PDT)
Raw View
------=_Part_3810_1726609344.1409858378802
Content-Type: text/plain; charset=UTF-8
On Wednesday, September 3, 2014 9:03:07 AM UTC-7, Thiago Macieira wrote:
>
> On Wednesday 03 September 2014 12:46:39 David Krauss wrote:
> > Where would you prefer to use offsetof, instead of a pointer-to-member?
>
> In the calculation of the reverse: from member to top-of-object.
>
This has been my experience as well: most of the time, the reason I want
such functionality is because I want to return to the beginning of the
object, to "undo" a member pointer. In other words, Microsoft's
CONTAINING_RECORD macro, but with member pointers. It actually wasn't what
prompted the idea *this* time, though.
template <class Source, class Member>
Source *containing_instance(Member *member, Member Source::*member_pointer)
{
static_assert(is_object<Source>::value, "source class must be of object
type");
typedef typename conditional<is_const<Source>::value, const char, char
>::type c_char;
typedef typename conditional<is_volatile<Source>::value, volatile c_char
, c_char>::type cv_char;
ptrdiff_t offset = reinterpret_cast<cv_char *>(&(reinterpret_cast<Source
*>(1)->*member_pointer)) -
reinterpret_cast<cv_char *>(1);
// I don't see how to do this without breaking aliasing rules...
return reinterpret_cast<Source *>(reinterpret_cast<cv_char *>(member) -
offset);
}
There isn't a Standard way of determining whether a class has virtual
inheritance, however. is_offsetof_compatible would help with this, and
would be useful in more cases than merely standard-layout. Although,
actually, *are* there cases in which virtual inheritance breaks offsetof?
Member pointers also have a limitation in that you can't use them without a
known base type. If you have highly-generic code that can't be templated
on the type, you'd need to have a base class in order to use member
pointers. Adding a base class means that you can no longer use
aggregate-initialization of arrays of that class. I ran into this exact
problem last week at work, and it forcing me to use offsetof and lose all
type safety prompted me to make this proposal. (Conversion to an offset
loses type safety, of course, but prior to that conversion, you have type
safety. Some is better than none, I figure.)
On Tuesday, September 2, 2014 9:46:44 PM UTC-7, David Krauss wrote:
>
> offsetof is a vestige of C compatibility, and standard layout is
> specifically tailored to C ABI compatibility. So the restriction is
> probably exactly what its designers intended.
>
>
Standard-layout exists for compatibility with other languages' in-memory
structures, yes, but offsetof is useful under looser requirements.
Standard-layout guarantees things like that the in-memory order matches the
order of members, and that the offset of the first element is zero. These
need not be true to make use of offsetof in many cases.
However, even in the worst case, with virtual functions and virtual
inheritance, it's always true that a class C's instance C *c occupies a
"fixed" location starting at a char *p = reinterpret_cast<char *>(c) and
ends right before p + sizeof(C). Applied recursively, this means that for
each data member M C::m there exists an offset o such that &c->m ==
reinterpret_cast<M *>(p + o).
Where would you prefer to use offsetof, instead of a pointer-to-member?
>
>
Whenever a template won't work or is inconvenient - whenever you need to
access a member of a class using a char *. It can avoid code bloat, too,
by avoiding a zillion copies of assembly code with tiny changes. The
purpose of such a feature would primarily be for libraries. Users of such
a library would specify an element using a member pointer, then the library
itself would internally use offsets. (Such a library could not exist as a
DLL, because it is not possible in current C++ to use a member pointer with void
*. Instead, you have to use callback functions.)
Melissa
--
---
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_3810_1726609344.1409858378802
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, September 3, 2014 9:03:07 AM UTC-7, Thiago M=
acieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Wednesday 03 =
September 2014 12:46:39 David Krauss wrote:
<br>> Where would you prefer to use offsetof, instead of a pointer-to-me=
mber?
<br>
<br>In the calculation of the reverse: from member to top-of-object.
<br></blockquote><br>This has been my experience as well: most of the time,=
the reason I want such functionality is because I want to return to the be=
ginning of the object, to "undo" a member pointer. In other words, Mi=
crosoft's <span style=3D"font-family: courier new,monospace;">CONTAINING_RE=
CORD</span> macro, but with member pointers. It actually wasn't what =
prompted the idea <i>this</i> time, though.<br><br><div class=3D"prettyprin=
t" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 18=
7, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Source</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Member</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Source</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">containing_instance</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Member</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">member<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Member</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Source</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">::*</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">member_pointer</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">static_assert</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">is_object</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">S=
ource</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>:=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">value</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #080;" class=3D"styled-by-prettify">"source class must be of object =
type"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> =
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypedef</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> conditional</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">is_const</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Source</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">>::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">value</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">char</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">char</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">type c_char</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: #008;" class=3D"styled-by-prettify">typedef</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> conditional</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">is_volatile</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Source</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">>::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">value</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">volatil=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> c_char</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> c_char</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">type cv_char</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br> ptrdiff_t off=
set </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">cv_char </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">*>(&(</span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span=
style=3D"color: #606;" class=3D"styled-by-prettify">Source</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">*>(</span><span style=3D"color: =
#066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)->*</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">member_pointer</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">))</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </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: #008;" class=
=3D"styled-by-prettify">reinterpret_cast</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">cv_char </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*>(</span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br> </span><span style=3D"color: #800;" class=3D"style=
d-by-prettify">// I don't see how to do this without breaking aliasing rule=
s...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret=
_cast</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">Source</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">*>(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">cv_char </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*>(</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">member</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">-</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> offset</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</sp=
an></div></code></div><br><br>There isn't a Standard way of determining whe=
ther a class has virtual inheritance, however. <span style=3D"font-fa=
mily: courier new,monospace;">is_offsetof_compatible</span> would help with=
this, and would be useful in more cases than merely standard-layout. =
Although, actually, <i>are</i> there cases in which virtual inheritance br=
eaks <span style=3D"font-family: courier new,monospace;">offsetof</span>?<b=
r><br>Member pointers also have a limitation in that you can't use them=20
without a known base type. If you have highly-generic code that can't=
=20
be templated on the type, you'd need to have a base class in order to=20
use member pointers. Adding a base class means that you can no longer=
=20
use aggregate-initialization of arrays of that class. I ran into this=
=20
exact problem last week at work, and it forcing me to use <span style=3D"fo=
nt-family: courier new,monospace;">offsetof</span>
and lose all type safety prompted me to make this proposal. =20
(Conversion to an offset loses type safety, of course, but prior to that
conversion, you have type safety. Some is better than none, I figure=
..)<br><br><br>On Tuesday, September 2, 2014 9:46:44 PM UTC-7, David Krauss =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:=
break-word"><div><div><font face=3D"Courier">offsetof</font>
is a vestige of C compatibility, and standard layout is specifically=20
tailored to C ABI compatibility. So the restriction is probably exactly=20
what its designers intended.</div><div><br></div></div></div></blockquote><=
div><br>Standard-layout exists for compatibility with other languages' in-m=
emory structures, yes, but <span style=3D"font-family: courier new,monospac=
e;">offsetof</span> is useful under looser requirements. Standard-lay=
out guarantees things like that the in-memory order matches the order of me=
mbers, and that the offset of the first element is zero. These need n=
ot be true to make use of <span style=3D"font-family: courier new,monospace=
;">offsetof</span> in many cases.<br><br>However, even in the worst case, w=
ith virtual functions and virtual inheritance, it's always true that a clas=
s <span style=3D"font-family: courier new,monospace;">C</span>'s instance <=
span style=3D"font-family: courier new,monospace;">C *c</span> occupies a "=
fixed" location starting at a <span style=3D"font-family: courier new,monos=
pace;">char *p =3D reinterpret_cast<char *>(c)</span> and ends right =
before <span style=3D"font-family: courier new,monospace;">p + sizeof(C)</s=
pan>. Applied recursively, this means that for each data member <span=
style=3D"font-family: courier new,monospace;">M C::m</span> there exists a=
n offset <span style=3D"font-family: courier new,monospace;">o</span> such =
that <span style=3D"font-family: courier new,monospace;">&c->m =3D=
=3D reinterpret_cast<M *>(p + o)</span>.<br><br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-word"><div><div=
></div><div>Where would you prefer to use <font face=3D"Courier">offsetof</=
font>, instead of a pointer-to-member?</div> </div></div></blockquote>=
<br>Whenever a template won't work or is inconvenient - whenever you need t=
o access a member of a class using a <span style=3D"font-family: courier ne=
w,monospace;">char *</span>. It can avoid code bloat, too, by avoidin=
g a zillion copies of assembly code with tiny changes. The purpose of=
such a feature would primarily be for libraries. Users of such a lib=
rary would specify an element using a member pointer, then the library itse=
lf would internally use offsets. (Such a library could not exist as a=
DLL, because it is not possible in current C++ to use a member pointer wit=
h <span style=3D"font-family: courier new,monospace;">void *</span>. =
Instead, you have to use callback functions.)<br><br>Melissa<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" 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_3810_1726609344.1409858378802--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 04 Sep 2014 13:04:21 -0700
Raw View
On Thursday 04 September 2014 12:19:38 Myriachan wrote:
> There isn't a Standard way of determining whether a class has virtual=20
> inheritance, however. is_offsetof_compatible would help with this, and=
=20
> would be useful in more cases than merely standard-layout. Although,=20
> actually, *are* there cases in which virtual inheritance breaks offsetof?
All of them. Any member in the virtual base has a non-fixed position in the=
=20
derived class.
struct Base { int i; };
struct VirtualBase { int j; };
struct Derived : public Base, public virtual VirtualBase {};
struct Derived2 : public Derived { int k; };
The VirtualBase sub-object is allocated in different positions in Derived a=
nd=20
in Derived2.
Which is why you can't write this:
int Derived:: ptr() { return &Derived::j; }
Clang:
error: conversion from pointer to member of class 'VirtualBase' to pointer =
to=20
member of class 'Derived' via virtual base 'VirtualBase' is not allowed
GCC:
pointer to member conversion via virtual base =E2=80=98VirtualBase=E2=80=99
ICC:
error: cannot convert pointer to member of base class "VirtualBase" to poin=
ter=20
to member of derived class "Derived" -- base class is virtual
The point is that Derived is not standard-layout, so you can't use offsetof=
in=20
it.
The following classes are not standard layout either:
struct S1
{
int i;
protected:
int j;
};
struct S2
{
int i;
virtual ~S2();
};
Though on most ABIs their layout is well-defined: it's actually "what you'd=
=20
expect" for S1 and for S2 there's an extra pointer somewhere in the struct.
Though I'm going to say that a PMF is a superior solution to offsetof since=
it=20
works on both cases and is a language construct. If we're given the ability=
to=20
go back to the containing object, I don't think I'll ever need offsetof aga=
in.
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu, 4 Sep 2014 14:51:47 -0700
Raw View
--001a113312a6fabc380502445b4b
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Sep 4, 2014 at 1:04 PM, Thiago Macieira <thiago@macieira.org> wrote=
:
> On Thursday 04 September 2014 12:19:38 Myriachan wrote:
> > There isn't a Standard way of determining whether a class has virtual
> > inheritance, however. is_offsetof_compatible would help with this, and
> > would be useful in more cases than merely standard-layout. Although,
> > actually, *are* there cases in which virtual inheritance breaks offseto=
f?
>
> All of them. Any member in the virtual base has a non-fixed position in t=
he
> derived class.
>
> struct Base { int i; };
> struct VirtualBase { int j; };
> struct Derived : public Base, public virtual VirtualBase {};
> struct Derived2 : public Derived { int k; };
>
> The VirtualBase sub-object is allocated in different positions in Derived
> and
> in Derived2.
>
> Which is why you can't write this:
>
> int Derived:: ptr() { return &Derived::j; }
>
> Clang:
> error: conversion from pointer to member of class 'VirtualBase' to pointe=
r
> to
> member of class 'Derived' via virtual base 'VirtualBase' is not allowed
>
> GCC:
> pointer to member conversion via virtual base =E2=80=98VirtualBase=E2=80=
=99
>
> ICC:
> error: cannot convert pointer to member of base class "VirtualBase" to
> pointer
> to member of derived class "Derived" -- base class is virtual
>
>
> The point is that Derived is not standard-layout, so you can't use
> offsetof in
> it.
>
> The following classes are not standard layout either:
> struct S1
> {
> int i;
> protected:
> int j;
> };
>
> struct S2
> {
> int i;
> virtual ~S2();
> };
>
> Though on most ABIs their layout is well-defined: it's actually "what you=
'd
> expect" for S1 and for S2 there's an extra pointer somewhere in the struc=
t.
>
> Though I'm going to say that a PMF is a superior solution to offsetof
> since it
> works on both cases and is a language construct. If we're given the
> ability to
> go back to the containing object, I don't think I'll ever need offsetof
> again.
One of the C++ committee members has suggested solving this problem by
allowing pointers-to-members to be negated and added, and array indexed,
with semantics something like:
x .* -p .* p =3D=3D x
x .* (p .* q) =3D=3D (x .* p) .* q
x .* (p [ n ]) =3D=3D (p .* q) [ n ]
x .* (p . f) =3D=3D (x .* p) . f
[with X x, Y X::*p, Z Y::*q, size_t n, and f a member of Y]
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--001a113312a6fabc380502445b4b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Sep 4, 2014 at 1:04 PM, Thiago Macieira <span dir=3D"ltr"><<a href=
=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieira.org</a>&g=
t;</span> wrote:<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 class=3D"">On Thursday 04 September 2014 12:19:38 Myr=
iachan wrote:<br>
> There isn't a Standard way of determining whether a class has virt=
ual<br>
> inheritance, however.=C2=A0 is_offsetof_compatible would help with thi=
s, and<br>
> would be useful in more cases than merely standard-layout.=C2=A0 Altho=
ugh,<br>
</div>> actually, *are* there cases in which virtual inheritance breaks =
offsetof?<br>
<br>
All of them. Any member in the virtual base has a non-fixed position in the=
<br>
derived class.<br>
<br>
struct Base { int i; };<br>
struct VirtualBase { int j; };<br>
struct Derived : public Base, public virtual VirtualBase {};<br>
struct Derived2 : public Derived { int k; };<br>
<br>
The VirtualBase sub-object is allocated in different positions in Derived a=
nd<br>
in Derived2.<br>
<br>
Which is why you can't write this:<br>
<br>
int Derived:: ptr() { return &Derived::j; }<br>
<br>
Clang:<br>
error: conversion from pointer to member of class 'VirtualBase' to =
pointer to<br>
member of class 'Derived' via virtual base 'VirtualBase' is=
not allowed<br>
<br>
GCC:<br>
pointer to member conversion via virtual base =E2=80=98VirtualBase=E2=80=99=
<br>
<br>
ICC:<br>
error: cannot convert pointer to member of base class "VirtualBase&quo=
t; to pointer<br>
to member of derived class "Derived" -- base class is virtual<br>
<br>
<br>
The point is that Derived is not standard-layout, so you can't use offs=
etof in<br>
it.<br>
<br>
The following classes are not standard layout either:<br>
struct S1<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int i;<br>
protected:<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int j;<br>
};<br>
<br>
struct S2<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 virtual ~S2();<br>
};<br>
<br>
Though on most ABIs their layout is well-defined: it's actually "w=
hat you'd<br>
expect" for S1 and for S2 there's an extra pointer somewhere in th=
e struct.<br>
<br>
Though I'm going to say that a PMF is a superior solution to offsetof s=
ince it<br>
works on both cases and is a language construct. If we're given the abi=
lity to<br>
go back to the containing object, I don't think I'll ever need offs=
etof again.</blockquote><div><br></div><div>One of the C++ committee member=
s has suggested solving this problem by allowing pointers-to-members to be =
negated and added, and array indexed, with semantics something like:</div>
<div><br></div><div>x .* -p .* p =3D=3D x<br></div><div>x .* (p .* q) =3D=
=3D (x .* p) .* q</div><div>x .* (p [ n ]) =3D=3D (p .* q) [ n ]</div><div>=
x .* (p . f) =3D=3D (x .* p) . f</div><div><br></div><div>[with X x, Y X::*=
p, Z Y::*q, size_t n, and f a member of Y]<br>
</div></div></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" 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 />
--001a113312a6fabc380502445b4b--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 04 Sep 2014 15:52:07 -0700
Raw View
On Thursday 04 September 2014 14:51:47 Richard Smith wrote:
> One of the C++ committee members has suggested solving this problem by
> allowing pointers-to-members to be negated and added, and array indexed,
> with semantics something like:
>
> x .* -p .* p == x
> x .* (p .* q) == (x .* p) .* q
> x .* (p [ n ]) == (p .* q) [ n ]
> x .* (p . f) == (x .* p) . f
>
> [with X x, Y X::*p, Z Y::*q, size_t n, and f a member of Y]
Interesting.
x .* -p .* p is a weird construct. The use-case I expect is:
Y *y = &x.y;
y .* -p == x
and since
y = x .* p;
we have the compound statement
x .* p .* -p == x
But x .* -p makes no sense to me. A PMM Y X:: *p gets a Y from X, while its
negated version would get X from Y. But you can't apply p to a type Y, so I
don't expect one to be able to apply -p to X. If that expression can't appear
isolated, I wouldn't expect it to be allowed in a compound statement either.
Even if it's just offset additions like n[3] == *(n + 3) == 3[n]. That would be
more like saying n[k[3]] == k[n[3]], which isn't at all the same.
The same applies to p .* q. What would be its type? Sounds like Z Y::* X::*,
which is something altogether new, but could be useful.
p[n] makes sense. It's just p + n * sizeof(Y).
As for p.f, it would be a decltype(f) [e.g., for void f(int), it would be
void (X:: *)(int)]
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: Gabriel Dos Reis <gdr@axiomatics.org>
Date: Thu, 04 Sep 2014 16:09:41 -0700
Raw View
Thiago Macieira <thiago@macieira.org> writes:
| On Thursday 04 September 2014 14:51:47 Richard Smith wrote:
| > One of the C++ committee members has suggested solving this problem by
| > allowing pointers-to-members to be negated and added, and array indexed,
| > with semantics something like:
| >
| > x .* -p .* p == x
| > x .* (p .* q) == (x .* p) .* q
| > x .* (p [ n ]) == (p .* q) [ n ]
| > x .* (p . f) == (x .* p) . f
| >
| > [with X x, Y X::*p, Z Y::*q, size_t n, and f a member of Y]
|
| Interesting.
|
| x .* -p .* p is a weird construct.
I think we are missing "+", "*" and "%".
Half :-)
-- Gaby
--
---
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/.
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu, 4 Sep 2014 16:22:01 -0700
Raw View
--001a1135e2deae4eb20502459e62
Content-Type: text/plain; charset=UTF-8
On Thu, Sep 4, 2014 at 3:52 PM, Thiago Macieira <thiago@macieira.org> wrote:
> On Thursday 04 September 2014 14:51:47 Richard Smith wrote:
> > One of the C++ committee members has suggested solving this problem by
> > allowing pointers-to-members to be negated and added, and array indexed,
> > with semantics something like:
> >
> > x .* -p .* p == x
> > x .* (p .* q) == (x .* p) .* q
> > x .* (p [ n ]) == (p .* q) [ n ]
> > x .* (p . f) == (x .* p) . f
> >
> > [with X x, Y X::*p, Z Y::*q, size_t n, and f a member of Y]
>
> Interesting.
>
> x .* -p .* p is a weird construct. The use-case I expect is:
>
> Y *y = &x.y;
> y .* -p == x
>
> and since
> y = x .* p;
>
> we have the compound statement
>
> x .* p .* -p == x
>
> But x .* -p makes no sense to me. A PMM Y X:: *p gets a Y from X, while
> its
> negated version would get X from Y. But you can't apply p to a type Y, so I
> don't expect one to be able to apply -p to X.
Sorry, typo =) I meant "(x .* p) .* -p == x" of course.
If that expression can't appear
> isolated, I wouldn't expect it to be allowed in a compound statement
> either.
> Even if it's just offset additions like n[3] == *(n + 3) == 3[n]. That
> would be
> more like saying n[k[3]] == k[n[3]], which isn't at all the same.
>
> The same applies to p .* q. What would be its type?
It would be of type Z X::*.
Sounds like Z Y::* X::*,
> which is something altogether new, but could be useful.
>
> p[n] makes sense. It's just p + n * sizeof(Y).
>
> As for p.f, it would be a decltype(f) [e.g., for void f(int), it would be
> void (X:: *)(int)]
Right, and more generally for "T f", it would be "T X::*".
--
---
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/.
--001a1135e2deae4eb20502459e62
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Sep 4, 2014 at 3:52 PM, Thiago Macieira <span dir=3D"ltr"><<a href=
=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieira.org</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"">On Thurs=
day 04 September 2014 14:51:47 Richard Smith wrote:<br>
> One of the C++ committee members has suggested solving this problem by=
<br>
> allowing pointers-to-members to be negated and added, and array indexe=
d,<br>
> with semantics something like:<br>
><br>
> x .* -p .* p =3D=3D x<br>
> x .* (p .* q) =3D=3D (x .* p) .* q<br>
> x .* (p [ n ]) =3D=3D (p .* q) [ n ]<br>
> x .* (p . f) =3D=3D (x .* p) . f<br>
><br>
> [with X x, Y X::*p, Z Y::*q, size_t n, and f a member of Y]<br>
<br>
</div>Interesting.<br>
<br>
x .* -p .* p is a weird construct. The use-case I expect is:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Y *y =3D &x.y;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 y .* -p =3D=3D x<br>
<br>
and since<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 y =3D x .* p;<br>
<br>
we have the compound statement<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 x .* p .* -p =3D=3D x<br>
<br>
But x .* -p makes no sense to me. A PMM=C2=A0 Y X:: *p gets a Y from X, whi=
le its<br>
negated version would get X from Y. But you can't apply p to a type Y, =
so I<br>
don't expect one to be able to apply -p to X.</blockquote><div><br></di=
v><div>Sorry, typo =3D) I meant "(x .* p) .* -p =3D=3D x" of cour=
se.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If that expression c=
an't appear<br>
isolated, I wouldn't expect it to be allowed in a compound statement ei=
ther.<br>
Even if it's just offset additions like n[3] =3D=3D *(n + 3) =3D=3D 3[n=
]. That would be<br>
more like saying n[k[3]] =3D=3D k[n[3]], which isn't at all the same.<b=
r>
<br>
The same applies to p .* q. What would be its type?</blockquote><div><br></=
div><div>It would be of type Z X::*.</div><div><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">Sounds like Z Y::* X::*,<br>
which is something altogether new, but could be useful.<br>
<br>
p[n] makes sense. It's just p + n * sizeof(Y).<br>
<br>
As for p.f, it would be a decltype(f) [e.g., for void f(int), it would be<b=
r>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 void (X:: *)(int)]</blockquote><div><br></div><=
div>Right, and more generally for "T f", it would be "T X::*=
".<br></div></div></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" 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 />
--001a1135e2deae4eb20502459e62--
.
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 4 Sep 2014 20:49:52 -0700 (PDT)
Raw View
------=_Part_369_411316699.1409888992441
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thursday, September 4, 2014 1:04:27 PM UTC-7, Thiago Macieira wrote:
>
> On Thursday 04 September 2014 12:19:38 Myriachan wrote:=20
> > There isn't a Standard way of determining whether a class has virtual=
=20
> > inheritance, however. is_offsetof_compatible would help with this, and=
=20
> > would be useful in more cases than merely standard-layout. Although,=
=20
> > actually, *are* there cases in which virtual inheritance breaks=20
> offsetof?=20
>
> All of them. Any member in the virtual base has a non-fixed position in=
=20
> the=20
> derived class.=20
>
> struct Base { int i; };=20
> struct VirtualBase { int j; };=20
> struct Derived : public Base, public virtual VirtualBase {};=20
> struct Derived2 : public Derived { int k; };=20
>
> The VirtualBase sub-object is allocated in different positions in Derived=
=20
> and=20
> in Derived2.=20
>
> Which is why you can't write this:=20
>
> int Derived:: ptr() { return &Derived::j; }=20
>
> Clang:=20
> error: conversion from pointer to member of class 'VirtualBase' to pointe=
r=20
> to=20
> member of class 'Derived' via virtual base 'VirtualBase' is not allowed=
=20
>
> GCC:=20
> pointer to member conversion via virtual base =E2=80=98VirtualBase=E2=80=
=99=20
>
> ICC:=20
> error: cannot convert pointer to member of base class "VirtualBase" to=20
> pointer=20
> to member of derived class "Derived" -- base class is virtual=20
>
>
> The point is that Derived is not standard-layout, so you can't use=20
> offsetof in=20
> it. =20
offsetof *can* be meaningful in virtual-inheritance classes, so long as you=
=20
don't try to use it on anything but the exact same dynamic type. (I think=
=20
"dynamic type" is the right term.) That it's chosen not to be meaningful=
=20
is another story.
=20
>
> The following classes are not standard layout either:=20
> struct S1=20
> {=20
> int i;=20
> protected:=20
> int j;=20
> };=20
>
> struct S2=20
> {=20
> int i;=20
> virtual ~S2();=20
> };=20
>
> Though on most ABIs their layout is well-defined: it's actually "what=20
> you'd=20
> expect" for S1 and for S2 there's an extra pointer somewhere in the=20
> struct.=20
>
For the next part, I'm going to ignore inheritance, because offsets are not=
=20
directly usable with inheritance. Only standard-layout types guarantee=20
that the offset of a base class is zero, and there's no reason to object to=
=20
this.
In the case of S1, or rather, any trivially-copyable but=20
non-standard-layout type, it is formally provably only incompatible with=20
offsetof because the Standard says so. Although it does not work with=20
constexpr because "says so", you can use the pointer arithmetic behind=20
offsetof with class S1 and it will work in all implementations. The fact=
=20
that std::memmove works and is not a magic function - it can be=20
reimplemented in C++ itself outside the STL - implies this. Some unsigned=
=20
char * pointers formed during a simple for-loop memmove implementation will=
=20
eventually equal each of the members of a class, and static_cast<std::size_=
t>(current_dest=20
- start_dest) is equal to those offsets. Because std::memmove necessarily=
=20
works on the subobjects (because trivially-copyable is recursive), such=20
offsets must actually be usable.
This argument actually works with *any* type under certain reasonable=20
assumptions:
* Objects occupy contiguous regions of unsigned char * memory.
* All instances of the same "dynamic type" have the same memory layout. =
=20
That is, an implementation won't decide that when bit 3 of the address is=
=20
1, members x and y are swapped in memory.
The former is *sort of* guaranteed when using placement new; it can only=20
break if the implementation moves an object "somewhere else" for the=20
duration despite the placement new.
> Though I'm going to say that a PMF is a superior solution to offsetof=20
> since it=20
> works on both cases and is a language construct. If we're given the=20
> ability to=20
> go back to the containing object, I don't think I'll ever need offsetof=
=20
> again.=20
>
There are still things that member pointers don't allow and offsetof does,=
=20
even with standard-layout classes, such as member pointers to elements of=
=20
member arrays, and member pointers to subobjects of members. Also, member=
=20
pointers cannot be used with unsigned char * / void *, whereas offsetof can=
=20
be. Adding an empty base class to resolve the inability to use void * with=
=20
member pointers isn't always possible: you may be doing aggregate=20
initialization. (There's another proposal on relaxing that somewhere.)
Melissa
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_369_411316699.1409888992441
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, September 4, 2014 1:04:27 PM UTC-7, Thiago Ma=
cieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Thursday 04 Se=
ptember 2014 12:19:38 Myriachan wrote:
<br>> There isn't a Standard way of determining whether a class has virt=
ual=20
<br>> inheritance, however. is_offsetof_compatible would help with=
this, and=20
<br>> would be useful in more cases than merely standard-layout. A=
lthough,=20
<br>> actually, *are* there cases in which virtual inheritance breaks of=
fsetof?
<br>
<br>All of them. Any member in the virtual base has a non-fixed position in=
the=20
<br>derived class.
<br>
<br>struct Base { int i; };
<br>struct VirtualBase { int j; };
<br>struct Derived : public Base, public virtual VirtualBase {};
<br>struct Derived2 : public Derived { int k; };
<br>
<br>The VirtualBase sub-object is allocated in different positions in Deriv=
ed and=20
<br>in Derived2.
<br>
<br>Which is why you can't write this:
<br>
<br>int Derived:: ptr() { return &Derived::j; }
<br>
<br>Clang:
<br>error: conversion from pointer to member of class 'VirtualBase' to poin=
ter to=20
<br>member of class 'Derived' via virtual base 'VirtualBase' is not allowed
<br>
<br>GCC:
<br>pointer to member conversion via virtual base =E2=80=98VirtualBase=E2=
=80=99
<br>
<br>ICC:
<br>error: cannot convert pointer to member of base class "VirtualBase" to =
pointer=20
<br>to member of derived class "Derived" -- base class is virtual
<br>
<br>
<br>The point is that Derived is not standard-layout, so you can't use offs=
etof in=20
<br>it.
</blockquote><div><br>offsetof <i>can</i> be meaningful in virtual-in=
heritance classes, so long as you don't try to use it on anything but the e=
xact same dynamic type. (I think "dynamic type" is the right term.)&n=
bsp; That it's chosen not to be meaningful is another story.<br> </div=
><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;">
<br>The following classes are not standard layout either:
<br>struct S1
<br>{
<br> int i;
<br>protected:
<br> int j;
<br>};
<br>
<br>struct S2
<br>{
<br> int i;
<br> virtual ~S2();
<br>};
<br>
<br>Though on most ABIs their layout is well-defined: it's actually "what y=
ou'd=20
<br>expect" for S1 and for S2 there's an extra pointer somewhere in the str=
uct.
<br></blockquote><div><br>For the next part, I'm going to ignore inheritanc=
e, because offsets are not directly usable with inheritance. Only sta=
ndard-layout types guarantee that the offset of a base class is zero, and t=
here's no reason to object to this.<br><br>In the case of S1, or rather, an=
y trivially-copyable but non-standard-layout type, it is formally provably =
only incompatible with <span style=3D"font-family: courier new,monospace;">=
offsetof</span> because the Standard says so. Although it does not wo=
rk with <span style=3D"font-family: courier new,monospace;">constexpr</span=
> because "says so", you can use the pointer arithmetic behind <span style=
=3D"font-family: courier new,monospace;">offsetof</span> with class S1 and =
it will work in all implementations. The fact that <span style=3D"fon=
t-family: courier new,monospace;">std::memmove</span> works and is not a ma=
gic function - it can be reimplemented in C++ itself outside the STL - impl=
ies this. Some <span style=3D"font-family: courier new,monospace;">un=
signed char *</span> pointers formed during a simple <span style=3D"font-fa=
mily: courier new,monospace;">for</span>-loop <span style=3D"font-family: c=
ourier new,monospace;">memmove</span> implementation will eventually equal =
each of the members of a class, and <span style=3D"font-family: courier new=
,monospace;">static_cast<std::size_t>(current_dest - start_dest)</spa=
n> is equal to those offsets. Because <span style=3D"font-family: cou=
rier new,monospace;">std::memmove</span> necessarily works on the subobject=
s (because trivially-copyable is recursive), such offsets must actually be =
usable.<br><br>This argument actually works with <i>any</i> type under cert=
ain reasonable assumptions:<br> * Objects occupy contiguous regions of=
<span style=3D"font-family: courier new,monospace;">unsigned char *</span>=
memory.<br> * All instances of the same "dynamic type" have the same =
memory layout. That is, an implementation won't decide that when bit =
3 of the address is 1, members x and y are swapped in memory.<br><br>The fo=
rmer is <i>sort of</i> guaranteed when using placement <span style=3D"font-=
family: courier new,monospace;">new</span>; it can only break if the implem=
entation moves an object "somewhere else" for the duration despite the plac=
ement <span style=3D"font-family: courier new,monospace;">new</span>.<br><b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>Though I'm going to say that a PMF is a superior solution to offsetof s=
ince it=20
<br>works on both cases and is a language construct. If we're given the abi=
lity to=20
<br>go back to the containing object, I don't think I'll ever need offsetof=
again.
<br></blockquote><div><br>There are still things that member pointers don't=
allow and offsetof does, even with standard-layout classes, such as member=
pointers to elements of member arrays, and member pointers to subobjects o=
f members. Also, member pointers cannot be used with unsigned char * =
/ void *, whereas offsetof can be. Adding an empty base class to reso=
lve the inability to use void * with member pointers isn't always possible:=
you may be doing aggregate initialization. (There's another proposal=
on relaxing that somewhere.)<br><br>Melissa<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" 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_369_411316699.1409888992441--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Sat, 6 Sep 2014 01:13:46 -0700 (PDT)
Raw View
------=_Part_7335_513162167.1409991226650
Content-Type: text/plain; charset=UTF-8
To me it seems that the logical extension would be to allow casting of a
data member pointer to int to reveal the offset it represents. Isn't this
what we're trying to accomplish anyway? Or is the task at hand to get the
offset of a member in class A as it would be if refferred to via a pointer
to class B where virtual and multiple inheritance complicates matters?
I still think that the unary minus on a PMV is wierd as it can't be used
"for real" only in offset calculations.
If the target for all this is the CONTAINING_RECORD use case, (which Itoo
have used at times to save an unnecessary indirection level), wouldn't it
be more appropriate to revisit the inner classes discussion, maybe starting
out with this particular use case. I see some parallels with lambda
capture, an inner class being a little to its outer class as a lambda is to
its containing function.
--
---
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_7335_513162167.1409991226650
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">To me it seems that the logical extension would be to allo=
w casting of a data member pointer to int to reveal the offset it represent=
s. Isn't this what we're trying to accomplish anyway? Or is the task at han=
d to get the offset of a member in class A as it would be if refferred to v=
ia a pointer to class B where virtual and multiple inheritance complicates =
matters?<div><br></div><div>I still think that the unary minus on a PMV is =
wierd as it can't be used "for real" only in offset calculations.</div><div=
><br></div><div>If the target for all this is the <span style=3D"font-=
size: 13px; font-family: 'courier new', monospace;">CONTAINING_RECORD</span=
><span style=3D"font-size: 13px;"> use case, (which Itoo have us=
ed at times to save an unnecessary indirection level), wouldn't it be more =
appropriate to revisit the inner classes discussion, maybe starting out wit=
h this particular use case. I see some parallels with lambda capture, an in=
ner class being a little to its outer class as a lambda is to its containin=
g function.</span></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" 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_7335_513162167.1409991226650--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 6 Sep 2014 16:28:28 +0800
Raw View
--Apple-Mail=_4737AA58-5C2C-4ABE-BDE6-4E07F9D2126A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
On 2014-09-05, at 5:51 AM, Richard Smith <richard@metafoo.co.uk> wrote:
> One of the C++ committee members has suggested solving this problem by al=
lowing pointers-to-members to be negated and added, and array indexed, with=
semantics something like:
What was the reaction at the time? It's not much of a breaking change, alth=
ough it does introduce pointers to "members" of scalar types. Some subset o=
f those operations can be adopted. The only thing needed to solve the issue=
in this thread is the negation operator.
The whole list there makes it look like either a theoretical exposition abo=
ut the nature of PTMs, or just tongue-in-cheek. The idea is obscure, yes, b=
ut it's nothing a user can't handle if they're already attempting to hack a=
round it using offsetof.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_4737AA58-5C2C-4ABE-BDE6-4E07F9D2126A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;09–05, at 5:51 AM, Richard Smith <<a href=3D"mailto:richard@=
metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:</div><br class=3D"Apple=
-interchange-newline"><blockquote type=3D"cite"><div dir=3D"ltr"><div class=
=3D"gmail_extra"><div class=3D"gmail_quote"><div>One of the C++ committee m=
embers has suggested solving this problem by allowing pointers-to-members t=
o be negated and added, and array indexed, with semantics something like:</=
div></div></div></div></blockquote><div><br></div><div>What was the reactio=
n at the time? It’s not much of a breaking change, although it does i=
ntroduce pointers to “members” of scalar types. Some subset of =
those operations can be adopted. The only thing needed to solve the issue i=
n this thread is the negation operator.</div><div><br></div><div>The whole =
list there makes it look like either a theoretical exposition about the nat=
ure of PTMs, or just tongue-in-cheek. The idea is obscure, yes, but it&rsqu=
o;s nothing a user can’t handle if they’re already attempting t=
o hack around it using <font face=3D"Courier">offsetof</font>.</div></div><=
br></body></html>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--Apple-Mail=_4737AA58-5C2C-4ABE-BDE6-4E07F9D2126A--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Sat, 6 Sep 2014 15:59:41 -0700
Raw View
--047d7b3431ee83a0e705026d8ad1
Content-Type: text/plain; charset=UTF-8
On 6 Sep 2014 01:13, "Bengt Gustafsson" <bengt.gustafsson@beamways.com>
wrote:
>
> To me it seems that the logical extension would be to allow casting of a
data member pointer to int to reveal the offset it represents. Isn't this
what we're trying to accomplish anyway?
I think we're trying to capture a higher level notion than that.
> Or is the task at hand to get the offset of a member in class A as it
would be if refferred to via a pointer to class B where virtual and
multiple inheritance complicates matters?
>
> I still think that the unary minus on a PMV is wierd as it can't be used
"for real" only in offset calculations.
What do you mean by "for real"? You would be able to do this:
struct A {
int n;
} a;
int *p = &a.n;
A *pa = p->* -&A::n; // pa == &a
.... which is as "for real" as any existing use of member pointers, as far
as I can see.
> If the target for all this is the CONTAINING_RECORD use case, (which Itoo
have used at times to save an unnecessary indirection level), wouldn't it
be more appropriate to revisit the inner classes discussion, maybe starting
out with this particular use case. I see some parallels with lambda
capture, an inner class being a little to its outer class as a lambda is to
its containing function.
I don't think that inner classes are relevant here; they're about having an
independent object at an independent address that intrinsically has an
implicit reference to its parent. This is about having a nested object that
is extrinsically known to be at a fixed offset within its parent and being
able to navigate between the two in either direction.
> 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/.
--047d7b3431ee83a0e705026d8ad1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">On 6 Sep 2014 01:13, "Bengt Gustafsson" <<a hre=
f=3D"mailto:bengt.gustafsson@beamways.com">bengt.gustafsson@beamways.com</a=
>> wrote:<br>
><br>
> To me it seems that the logical extension would be to allow casting of=
a data member pointer to int to reveal the offset it represents. Isn't=
this what we're trying to accomplish anyway?</p>
<p dir=3D"ltr">I think we're trying to capture a higher level notion th=
an that.</p>
<p dir=3D"ltr">> Or is the task at hand to get the offset of a member in=
class A as it would be if refferred to via a pointer to class B where virt=
ual and multiple inheritance complicates matters?<br>
><br>
> I still think that the unary minus on a PMV is wierd as it can't b=
e used "for real" only in offset calculations.</p>
<p dir=3D"ltr">What do you mean by "for real"? You would be able =
to do this:</p>
<p dir=3D"ltr">struct A {<br>
=C2=A0 int n;<br>
} a;<br>
int *p =3D &a.n;<br>
A *pa =3D p->* -&A::n; // pa =3D=3D &a</p>
<p dir=3D"ltr">... which is as "for real" as any existing use of =
member pointers, as far as I can see.</p>
<p dir=3D"ltr">> If the target for all this is the=C2=A0CONTAINING_RECOR=
D=C2=A0use case, (which Itoo =C2=A0have used at times to save an unnecessar=
y indirection level), wouldn't it be more appropriate to revisit the in=
ner classes discussion, maybe starting out with this particular use case. I=
see some parallels with lambda capture, an inner class being a little to i=
ts outer class as a lambda is to its containing function.</p>
<p dir=3D"ltr">I don't think that inner classes are relevant here; they=
're about having an independent object at an independent address that i=
ntrinsically has an implicit reference to its parent. This is about having =
a nested object that is extrinsically known to be at a fixed offset within =
its parent and being able to navigate between the two in either direction.<=
/p>
<p dir=3D"ltr">> You received this message because you are subscribed to=
the Google Groups "ISO C++ Standard - Future Proposals" group.<b=
r>
> To unsubscribe from this group and stop receiving emails from it, send=
an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
> To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
> Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/g=
roup/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-propos=
als/</a>.<br>
</p>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--047d7b3431ee83a0e705026d8ad1--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Sat, 6 Sep 2014 16:00:49 -0700
Raw View
--001a11c1d2cc8636a705026d8ee3
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On 6 Sep 2014 07:14, "David Krauss" <potswa@gmail.com> wrote:
>
>
> On 2014=E2=80=9309=E2=80=9305, at 5:51 AM, Richard Smith <richard@metafoo=
..co.uk> wrote:
>
>> One of the C++ committee members has suggested solving this problem by
allowing pointers-to-members to be negated and added, and array indexed,
with semantics something like:
>
>
> What was the reaction at the time? It=E2=80=99s not much of a breaking ch=
ange,
although it does introduce pointers to =E2=80=9Cmembers=E2=80=9D of scalar =
types. Some
subset of those operations can be adopted. The only thing needed to solve
the issue in this thread is the negation operator.
It's not got as far as a formal proposal yet, to the best of my knowledge.
> The whole list there makes it look like either a theoretical exposition
about the nature of PTMs, or just tongue-in-cheek. The idea is obscure,
yes, but it=E2=80=99s nothing a user can=E2=80=99t handle if they=E2=80=99r=
e already attempting to
hack around it using offsetof.
>
> --
>
> ---
> 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/.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--001a11c1d2cc8636a705026d8ee3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">On 6 Sep 2014 07:14, "David Krauss" <<a href=3D=
"mailto:potswa@gmail.com">potswa@gmail.com</a>> wrote:<br>
><br>
><br>
> On 2014=E2=80=9309=E2=80=9305, at 5:51 AM, Richard Smith <<a href=
=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
><br>
>> One of the C++ committee members has suggested solving this proble=
m by allowing pointers-to-members to be negated and added, and array indexe=
d, with semantics something like:<br>
><br>
><br>
> What was the reaction at the time? It=E2=80=99s not much of a breaking=
change, although it does introduce pointers to =E2=80=9Cmembers=E2=80=9D o=
f scalar types. Some subset of those operations can be adopted. The only th=
ing needed to solve the issue in this thread is the negation operator.</p>
<p dir=3D"ltr">It's not got as far as a formal proposal yet, to the bes=
t of my knowledge.</p>
<p dir=3D"ltr">> The whole list there makes it look like either a theore=
tical exposition about the nature of PTMs, or just tongue-in-cheek. The ide=
a is obscure, yes, but it=E2=80=99s nothing a user can=E2=80=99t handle if =
they=E2=80=99re already attempting to hack around it using offsetof.<br>
><br>
> -- <br>
><br>
> --- <br>
> You received this message because you are subscribed to the Google Gro=
ups "ISO C++ Standard - Future Proposals" group.<br>
> To unsubscribe from this group and stop receiving emails from it, send=
an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
> To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
> Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/g=
roup/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-propos=
als/</a>.<br>
</p>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--001a11c1d2cc8636a705026d8ee3--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Sat, 6 Sep 2014 16:02:40 -0700
Raw View
--e0cb4e887c092d1f0d05026d959a
Content-Type: text/plain; charset=UTF-8
On 6 Sep 2014 15:59, "Richard Smith" <richard@metafoo.co.uk> wrote:
>
> On 6 Sep 2014 01:13, "Bengt Gustafsson" <bengt.gustafsson@beamways.com>
wrote:
> >
> > To me it seems that the logical extension would be to allow casting of
a data member pointer to int to reveal the offset it represents. Isn't this
what we're trying to accomplish anyway?
>
> I think we're trying to capture a higher level notion than that.
>
> > Or is the task at hand to get the offset of a member in class A as it
would be if refferred to via a pointer to class B where virtual and
multiple inheritance complicates matters?
> >
> > I still think that the unary minus on a PMV is wierd as it can't be
used "for real" only in offset calculations.
>
> What do you mean by "for real"? You would be able to do this:
>
> struct A {
> int n;
> } a;
> int *p = &a.n;
> A *pa = p->* -&A::n; // pa == &a
Err, A *pa = &p->*-&A::n;
> ... which is as "for real" as any existing use of member pointers, as far
as I can see.
>
> > If the target for all this is the CONTAINING_RECORD use case, (which
Itoo have used at times to save an unnecessary indirection level),
wouldn't it be more appropriate to revisit the inner classes discussion,
maybe starting out with this particular use case. I see some parallels with
lambda capture, an inner class being a little to its outer class as a
lambda is to its containing function.
>
> I don't think that inner classes are relevant here; they're about having
an independent object at an independent address that intrinsically has an
implicit reference to its parent. This is about having a nested object that
is extrinsically known to be at a fixed offset within its parent and being
able to navigate between the two in either direction.
>
> > 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/.
--e0cb4e887c092d1f0d05026d959a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">On 6 Sep 2014 15:59, "Richard Smith" <<a href=
=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
><br>
> On 6 Sep 2014 01:13, "Bengt Gustafsson" <<a href=3D"mailt=
o:bengt.gustafsson@beamways.com">bengt.gustafsson@beamways.com</a>> wrot=
e:<br>
> ><br>
> > To me it seems that the logical extension would be to allow casti=
ng of a data member pointer to int to reveal the offset it represents. Isn&=
#39;t this what we're trying to accomplish anyway?<br>
><br>
> I think we're trying to capture a higher level notion than that.<b=
r>
><br>
> > Or is the task at hand to get the offset of a member in class A a=
s it would be if refferred to via a pointer to class B where virtual and mu=
ltiple inheritance complicates matters?<br>
> ><br>
> > I still think that the unary minus on a PMV is wierd as it can=
9;t be used "for real" only in offset calculations.<br>
><br>
> What do you mean by "for real"? You would be able to do this=
:<br>
><br>
> struct A {<br>
> =C2=A0 int n;<br>
> } a;<br>
> int *p =3D &a.n;<br>
> A *pa =3D p->* -&A::n; // pa =3D=3D &a</p>
<p dir=3D"ltr">Err, A *pa =3D &p->*-&A::n;</p>
<p dir=3D"ltr">> ... which is as "for real" as any existing us=
e of member pointers, as far as I can see.<br>
><br>
> > If the target for all this is the=C2=A0CONTAINING_RECORD=C2=A0use=
case, (which Itoo =C2=A0have used at times to save an unnecessary indirect=
ion level), wouldn't it be more appropriate to revisit the inner classe=
s discussion, maybe starting out with this particular use case. I see some =
parallels with lambda capture, an inner class being a little to its outer c=
lass as a lambda is to its containing function.<br>
><br>
> I don't think that inner classes are relevant here; they're ab=
out having an independent object at an independent address that intrinsical=
ly has an implicit reference to its parent. This is about having a nested o=
bject that is extrinsically known to be at a fixed offset within its parent=
and being able to navigate between the two in either direction.<br>
><br>
> > You received this message because you are subscribed to the Googl=
e Groups "ISO C++ Standard - Future Proposals" group.<br>
> > To unsubscribe from this group and stop receiving emails from it,=
send an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org"=
>std-proposals+unsubscribe@isocpp.org</a>.<br>
> > To post to this group, send email to <a href=3D"mailto:std-propos=
als@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-p=
roposals/</a>.<br>
</p>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--e0cb4e887c092d1f0d05026d959a--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Sun, 7 Sep 2014 15:57:26 -0700 (PDT)
Raw View
------=_Part_518_1169443003.1410130646690
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Inner classes: If the only instance of the inner class is by value in its=
=20
outer class then we could accomplish accessing the outer class's members=20
without any coding:
class Outer {
int x;
class Inner {
void f() {
int y =3D x; // This is assigning from Outer's x.
}
} m_inner;
};
This is why I ment by "starting out with this particular case", i.e. that=
=20
it would be nice if this worked. Of course, once you start creating=20
instances of Inner that are not by value you'd have to
handle the hidden pointer issues, which is the sticky part, I assume. It=20
would be possible to state in the standard that "nested classes can access=
=20
outer class' members if the only instances are by value in the outer=20
class." which would make code above legal.
I understand that this is creating another special case so it would be of=
=20
course even better if full inner class functionality was implemented as it=
=20
has a wider spectrum of uses. Even this limited possibility would be very=
=20
useful though as it is one of the more common patterns and furthermore
the only pattern where the inner class would perform better than a=20
non-inner class with an explicit "outer" pointer sent to the constructor.=
=20
This performance gain is what CONTAINING_RECORD, offsetof and -PMV is=20
trying to reach at, resulting in rather ugly code in all cases.
One problem would be that the compiler would have to check that no illegal=
=20
instances are created. One simple trick would be to mandate that such=20
classes are private but I think that it should be possible to do the check=
=20
while parsing the class head. Well, if the code bodies were in a cpp file=
=20
this would not be possible, so a naive
implementation would only get a link error (providing the use of x creates=
=20
a name mangling change). This indicates that a "inner" keyword is necessary=
=20
(I hoped to get away without one). This may be just as well if an extension=
=20
to full inner classes is on the longer term agenda.
Den s=C3=B6ndagen den 7:e september 2014 kl. 01:02:42 UTC+2 skrev Richard S=
mith:
>
> On 6 Sep 2014 15:59, "Richard Smith" <ric...@metafoo.co.uk <javascript:>>=
=20
> wrote:
> >
> > On 6 Sep 2014 01:13, "Bengt Gustafsson" <bengt.gu...@beamways.com=20
> <javascript:>> wrote:
> > >
> > > To me it seems that the logical extension would be to allow casting o=
f=20
> a data member pointer to int to reveal the offset it represents. Isn't th=
is=20
> what we're trying to accomplish anyway?
> >
> > I think we're trying to capture a higher level notion than that.
> >
> > > Or is the task at hand to get the offset of a member in class A as it=
=20
> would be if refferred to via a pointer to class B where virtual and=20
> multiple inheritance complicates matters?
> > >
> > > I still think that the unary minus on a PMV is wierd as it can't be=
=20
> used "for real" only in offset calculations.
> >
> > What do you mean by "for real"? You would be able to do this:
> >
> > struct A {
> > int n;
> > } a;
> > int *p =3D &a.n;
> > A *pa =3D p->* -&A::n; // pa =3D=3D &a
>
> Err, A *pa =3D &p->*-&A::n;
>
> > ... which is as "for real" as any existing use of member pointers, as=
=20
> far as I can see.
> >
> > > If the target for all this is the CONTAINING_RECORD use case, (which=
=20
> Itoo have used at times to save an unnecessary indirection level),=20
> wouldn't it be more appropriate to revisit the inner classes discussion,=
=20
> maybe starting out with this particular use case. I see some parallels wi=
th=20
> lambda capture, an inner class being a little to its outer class as a=20
> lambda is to its containing function.
> >
> > I don't think that inner classes are relevant here; they're about havin=
g=20
> an independent object at an independent address that intrinsically has an=
=20
> implicit reference to its parent. This is about having a nested object th=
at=20
> is extrinsically known to be at a fixed offset within its parent and bein=
g=20
> able to navigate between the two in either direction.
> >
> > > You received this message because you are subscribed to the Google=20
> Groups "ISO C++ Standard - Future Proposals" group.
> > > To unsubscribe from this group and stop receiving emails from it, sen=
d=20
> an email to std-proposal...@isocpp.org <javascript:>.
> > > To post to this group, send email to std-pr...@isocpp.org=20
> <javascript:>.
> > > Visit this group at=20
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
> =20
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_518_1169443003.1410130646690
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Inner classes: If the only instance of the inner class is =
by value in its outer class then we could accomplish accessing the outer cl=
ass's members without any coding:<div><br></div><div>class Outer {</div><di=
v> int x;</div><div><br></div><div> class Inner {=
</div><div> void f() {</div><div> &=
nbsp; int y =3D x; // This is assigning from Outer's x=
..</div><div> }</div><div> } m_inner=
;</div><div><div>};</div><div><br></div><div>This is why I ment by "startin=
g out with this particular case", i.e. that it would be nice if this worked=
.. Of course, once you start creating instances of Inner that are not by val=
ue you'd have to</div><div>handle the hidden pointer issues, which is the s=
ticky part, I assume. It would be possible to state in the standard that "n=
ested classes can access outer class' members if the only instances are by =
value in the outer class." which would make code above legal.</div><div><br=
></div><div>I understand that this is creating another special case so it w=
ould be of course even better if full inner class functionality was impleme=
nted as it has a wider spectrum of uses. Even this limited possibility woul=
d be very useful though as it is one of the more common patterns and furthe=
rmore</div><div>the only pattern where the inner class would perform better=
than a non-inner class with an explicit "outer" pointer sent to the constr=
uctor. This performance gain is what <span style=3D"color: rgb(80, 0, =
80); font-size: 13px;"> CONTAINING_RECORD, offsetof and -PMV is trying=
to reach at, resulting in rather ugly code in all cases.</span></div><div>=
<br></div><div>One problem would be that the compiler would have to check t=
hat no illegal instances are created. One simple trick would be to mandate =
that such classes are private but I think that it should be possible to do =
the check while parsing the class head. Well, if the code bodies were in a =
cpp file this would not be possible, so a naive</div><div>implementation wo=
uld only get a link error (providing the use of x creates a name mangling c=
hange). This indicates that a "inner" keyword is necessary (I hoped to get =
away without one). This may be just as well if an extension to full inner c=
lasses is on the longer term agenda.</div><div><br><br>Den s=C3=B6ndagen de=
n 7:e september 2014 kl. 01:02:42 UTC+2 skrev Richard Smith:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><p dir=3D"ltr">On 6 Sep 2014 15:59, "Richard =
Smith" <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=
=3D"Ofv-yAogMFYJ" onmousedown=3D"this.href=3D'javascript:';return true;" on=
click=3D"this.href=3D'javascript:';return true;">ric...@metafoo.co.uk</a>&g=
t; wrote:<br>
><br>
> On 6 Sep 2014 01:13, "Bengt Gustafsson" <<a href=3D"javascript:" ta=
rget=3D"_blank" gdf-obfuscated-mailto=3D"Ofv-yAogMFYJ" onmousedown=3D"this.=
href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';ret=
urn true;">bengt.gu...@beamways.com</a><wbr>> wrote:<br>
> ><br>
> > To me it seems that the logical extension would be to allow casti=
ng of a data member pointer to int to reveal the offset it represents. Isn'=
t this what we're trying to accomplish anyway?<br>
><br>
> I think we're trying to capture a higher level notion than that.<br>
><br>
> > Or is the task at hand to get the offset of a member in class A a=
s it would be if refferred to via a pointer to class B where virtual and mu=
ltiple inheritance complicates matters?<br>
> ><br>
> > I still think that the unary minus on a PMV is wierd as it can't =
be used "for real" only in offset calculations.<br>
><br>
> What do you mean by "for real"? You would be able to do this:<br>
><br>
> struct A {<br>
> int n;<br>
> } a;<br>
> int *p =3D &a.n;<br>
> A *pa =3D p->* -&A::n; // pa =3D=3D &a</p>
<p dir=3D"ltr">Err, A *pa =3D &p->*-&A::n;</p>
<p dir=3D"ltr">> ... which is as "for real" as any existing use of membe=
r pointers, as far as I can see.<br>
><br>
> > If the target for all this is the CONTAINING_RECORD use=
case, (which Itoo have used at times to save an unnecessary indirect=
ion level), wouldn't it be more appropriate to revisit the inner classes di=
scussion, maybe starting out with this particular use case. I see some para=
llels with lambda capture, an inner class being a little to its outer class=
as a lambda is to its containing function.<br>
><br>
> I don't think that inner classes are relevant here; they're about havi=
ng an independent object at an independent address that intrinsically has a=
n implicit reference to its parent. This is about having a nested object th=
at is extrinsically known to be at a fixed offset within its parent and bei=
ng able to navigate between the two in either direction.<br>
><br>
> > You received this message because you are subscribed to the Googl=
e Groups "ISO C++ Standard - Future Proposals" group.<br>
> > To unsubscribe from this group and stop receiving emails from it,=
send an email to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"Ofv-yAogMFYJ" onmousedown=3D"this.href=3D'javascript:';return tru=
e;" onclick=3D"this.href=3D'javascript:';return true;">std-proposal...@<wbr=
>isocpp.org</a>.<br>
> > To post to this group, send email to <a href=3D"javascript:" targ=
et=3D"_blank" gdf-obfuscated-mailto=3D"Ofv-yAogMFYJ" onmousedown=3D"this.hr=
ef=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';retur=
n true;">std-pr...@isocpp.org</a>.<br>
> > Visit this group at <a href=3D"http://groups.google.com/a/isocpp.=
org/group/std-proposals/" target=3D"_blank" onmousedown=3D"this.href=3D'htt=
p://groups.google.com/a/isocpp.org/group/std-proposals/';return true;" oncl=
ick=3D"this.href=3D'http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/';return true;">http://groups.google.com/a/<wbr>isocpp.org/group/std-<wb=
r>proposals/</a>.<br>
</p>
</blockquote></div></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" 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_518_1169443003.1410130646690--
.
Author: Jean-Marc Bourguet <jm.bourguet@gmail.com>
Date: Mon, 8 Sep 2014 00:30:07 -0700 (PDT)
Raw View
------=_Part_6640_304909126.1410161407172
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Le samedi 6 septembre 2014 10:13:46 UTC+2, Bengt Gustafsson a =C3=A9crit :
>
> To me it seems that the logical extension would be to allow casting of a=
=20
> data member pointer to int to reveal the offset it represents. Isn't this=
=20
> what we're trying to accomplish anyway?
>
I'm not sure there is one offset to get when considering virtual=20
inheritance (you may have to apply dynamically determined offset to get to=
=20
the virtual base origin).
Yours,
--=20
Jean-Marc
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_6640_304909126.1410161407172
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>Le samedi 6 septembre 2014 10:13:46 UTC+2, Bengt Gusta=
fsson a =C3=A9crit :<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">To me it seems that the logical extension would be to allow cas=
ting of a data member pointer to int to reveal the offset it represents. Is=
n't this what we're trying to accomplish anyway?</div></blockquote><div><br=
></div><div>I'm not sure there is one offset to get when considering virtua=
l inheritance (you may have to apply dynamically determined offset to get t=
o the virtual base origin).</div><div><br></div><div>Yours,</div><div>--&nb=
sp;</div><div>Jean-Marc</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" 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_6640_304909126.1410161407172--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 08 Sep 2014 01:18:48 -0700
Raw View
On Monday 08 September 2014 00:30:07 Jean-Marc Bourguet wrote:
> Le samedi 6 septembre 2014 10:13:46 UTC+2, Bengt Gustafsson a =E9crit :
> > To me it seems that the logical extension would be to allow casting of =
a
> > data member pointer to int to reveal the offset it represents. Isn't th=
is
> > what we're trying to accomplish anyway?
>=20
> I'm not sure there is one offset to get when considering virtual
> inheritance (you may have to apply dynamically determined offset to get t=
o
> the virtual base origin).
You can't get a pointer-to-member across virtual inheritance.
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: =?ISO-8859-1?Q?Ion_Gazta=F1aga?= <igaztanaga@gmail.com>
Date: Mon, 08 Sep 2014 15:18:43 +0200
Raw View
El 08/09/2014 10:18, Thiago Macieira escribi=F3:
> On Monday 08 September 2014 00:30:07 Jean-Marc Bourguet wrote:
>> Le samedi 6 septembre 2014 10:13:46 UTC+2, Bengt Gustafsson a =E9crit :
>>> To me it seems that the logical extension would be to allow casting of =
a
>>> data member pointer to int to reveal the offset it represents. Isn't th=
is
>>> what we're trying to accomplish anyway?
>>
>> I'm not sure there is one offset to get when considering virtual
>> inheritance (you may have to apply dynamically determined offset to get =
to
>> the virtual base origin).
>
> You can't get a pointer-to-member across virtual inheritance.
Correct. I would like to point out that the inverse operation of a=20
pointer to member is very useful. Boost.Intrusive uses it to avoid=20
inheritance when creating intrusive containers. Currently=20
Boost.Intrusive uses get_parent_from_member:
http://www.boost.org/doc/libs/1_56_0/doc/html/boost/intrusive/get_parent_fr=
o_idp64544448.html
For most compilers, the pointer to member is an offset into the class=20
(+/- 1 depending on how you represent the null value). This only works=20
if you don't cross the virtual base boundary. The major portability=20
problem happens in MSVC where pointer to members can have multiple=20
sizes. In a class with a virtual base, a pointer to member has two or=20
three fields (mdisp, pdisp, vdisp) and even if the pointer to member=20
does not point to a member that lives beyond the virtual base boundary,=20
the vbtable is used to fix the this pointer before adding the offset.=20
This makes get_parent_from_pointer currently very hard to implement (*)=20
with classes with virtual bases in MSVC.
Ion
(*) Unless you gain access to RTTI information exporting it with a DLL=20
or using a specific assembler for each class + the linker to access=20
vftable addresses.
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 8 Sep 2014 11:05:31 -0700 (PDT)
Raw View
------=_Part_556_866220740.1410199531900
Content-Type: text/plain; charset=UTF-8
On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson wrote:
>
> Inner classes: If the only instance of the inner class is by value in its
> outer class then we could accomplish accessing the outer class's members
> without any coding:
>
> class Outer {
> int x;
>
> class Inner {
> void f() {
> int y = x; // This is assigning from Outer's x.
> }
> } m_inner;
> };
>
>
I think this should require some extra syntax to enforce that Inner is only
allowed to be instantiated in one place and only as a value data member of
Outer.
Something like:
class Outer {
int x;
static class Inner {
void f() { int y = x; }
} _inner1; //<-OK
Inner _inner2; //<- ERROR: cannot create multiple instances of a static
nested class
static class AnotherInner {}; //<-ERROR: cannot define a static nested
class without also instantiating a value data member
};
--
---
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_556_866220740.1410199531900
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, September 7, 2014 6:57:26 PM UTC-4, Ben=
gt Gustafsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">Inner classes: If the only instance of the inner class is by value=
in its outer class then we could accomplish accessing the outer class's me=
mbers without any coding:<div><br></div><div>class Outer {</div><div> =
int x;</div><div><br></div><div> class Inner {</div><d=
iv> void f() {</div><div> &n=
bsp; int y =3D x; // This is assigning from Outer's x.</div><=
div> }</div><div> } m_inner;</div><=
div><div>};</div><br></div></div></blockquote><div><br>I think this should =
require some extra syntax to enforce that Inner is only allowed to be insta=
ntiated in one place and only as a value data member of Outer.<br><br>Somet=
hing like:<br><br>class Outer {<br> int x;<br> static class Inn=
er {<br> void f() { int y =3D x; }<br> } _inner1; //<=
-OK<br> Inner _inner2; //<- ERROR: cannot create multiple instance=
s of a static nested class<br> static class AnotherInner {}; //<-E=
RROR: cannot define a static nested class without also instantiating a valu=
e data member<br>}; <br><br><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" 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_556_866220740.1410199531900--
.
Author: Miro Knejp <miro.knejp@gmail.com>
Date: Mon, 08 Sep 2014 20:26:16 +0200
Raw View
This is a multi-part message in MIME format.
--------------060901070007020801010302
Content-Type: text/plain; charset=UTF-8; format=flowed
I often wiched anonymous nested types could access the outer one. Before
C++11 there was no way of instantiating anonymous types, but now there
is decltype() making it more complicated to prevent instantiation
outside the enclosing class.
This discussion reminds me of how I once wondered whether it would make
sense to define namespaces inside classes (but member access with .
instead of :: ).
Am 08.09.2014 um 20:05 schrieb Matthew Fioravante:
>
>
> On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson wrote:
>
> Inner classes: If the only instance of the inner class is by value
> in its outer class then we could accomplish accessing the outer
> class's members without any coding:
>
> class Outer {
> int x;
>
> class Inner {
> void f() {
> int y = x; // This is assigning from Outer's x.
> }
> } m_inner;
> };
>
>
> I think this should require some extra syntax to enforce that Inner is
> only allowed to be instantiated in one place and only as a value data
> member of Outer.
>
> Something like:
>
> class Outer {
> int x;
> static class Inner {
> void f() { int y = x; }
> } _inner1; //<-OK
> Inner _inner2; //<- ERROR: cannot create multiple instances of a
> static nested class
> static class AnotherInner {}; //<-ERROR: cannot define a static
> nested class without also instantiating a value data member
> };
>
>
> --
>
> ---
> 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
> <mailto:std-proposals+unsubscribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org
> <mailto: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/.
--------------060901070007020801010302
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
I often wiched anonymous nested types could access the outer one.
Before C++11 there was no way of instantiating anonymous types, but
now there is decltype() making it more complicated to prevent
instantiation outside the enclosing class.<br>
<br>
This discussion reminds me of how I once wondered whether it would
make sense to define namespaces inside classes (but member access
with . instead of :: ).<br>
<br>
<div class=3D"moz-cite-prefix">Am 08.09.2014 um 20:05 schrieb Matthew
Fioravante:<br>
</div>
<blockquote
cite=3D"mid:2285060d-e475-48f8-a9cc-389487ee681f@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
<br>
On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson
wrote:
<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">Inner classes: If the only instance of the
inner class is by value in its outer class then we could
accomplish accessing the outer class's members without any
coding:
<div><br>
</div>
<div>class Outer {</div>
<div>=C2=A0 =C2=A0 int x;</div>
<div><br>
</div>
<div>=C2=A0 =C2=A0 class Inner {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 void f() {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int y =3D x; // =
This is assigning from
Outer's x.</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div>
<div>=C2=A0 =C2=A0 } m_inner;</div>
<div>
<div>};</div>
<br>
</div>
</div>
</blockquote>
<div><br>
I think this should require some extra syntax to enforce that
Inner is only allowed to be instantiated in one place and only
as a value data member of Outer.<br>
<br>
Something like:<br>
<br>
class Outer {<br>
=C2=A0 int x;<br>
=C2=A0 static class Inner {<br>
=C2=A0 =C2=A0 void f() { int y =3D x; }<br>
=C2=A0 } _inner1; //<-OK<br>
=C2=A0 Inner _inner2; //<- ERROR: cannot create multiple
instances of a static nested class<br>
=C2=A0 static class AnotherInner {}; //<-ERROR: cannot define =
a
static nested class without also instantiating a value data
member<br>
}; <br>
<br>
<br>
</div>
</div>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google
Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it,
send an email to <a moz-do-not-send=3D"true"
href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+=
unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a moz-do-not-send=3D"true"
href=3D"mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</=
a>.<br>
Visit this group at <a moz-do-not-send=3D"true"
href=3D"http://groups.google.com/a/isocpp.org/group/std-proposals/"=
>http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br>
</blockquote>
<br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--------------060901070007020801010302--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Mon, 8 Sep 2014 17:56:58 -0700
Raw View
--001a11c2bb1ea020a105029769ef
Content-Type: text/plain; charset=UTF-8
On Mon, Sep 8, 2014 at 11:05 AM, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
>
> On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson wrote:
>>
>> Inner classes: If the only instance of the inner class is by value in its
>> outer class then we could accomplish accessing the outer class's members
>> without any coding:
>>
>
This is not what "inner class" means, at least in Java (I'm not sure what
other languages have established a definition for the term yet) -- you can
have any number of instances of the inner class created by a given instance
of an outer class. What you're describing here seems to more akin to the
"anonymous struct members" feature already supported by several compilers.
class Outer {
>> int x;
>>
>> class Inner {
>> void f() {
>> int y = x; // This is assigning from Outer's x.
>> }
>> } m_inner;
>> };
>>
>>
> I think this should require some extra syntax to enforce that Inner is
> only allowed to be instantiated in one place and only as a value data
> member of Outer.
>
> Something like:
>
> class Outer {
> int x;
> static class Inner {
> void f() { int y = x; }
> } _inner1; //<-OK
>
That's OK even in C++98; this declares a static data member. But syntax
aside, sure, this is feasible. But if you don't want a static inner class
(or whatever you want to call that thing), you'd need to do something
morally like rewriting:
struct X { Y y; };
extern Y *p;
X *x = &p->*-&X::y
as:
struct X {
your_keyword_here struct MyY : Y {
X &x_from_this() { return outer_this; }; // or however you'd write
that...
} y;
};
extern Y *p;
X *x = &static_cast<X::MyY*>(p)->x_from_this();
.... which seems unfortunate.
--
---
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/.
--001a11c2bb1ea020a105029769ef
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Sep 8, 2014 at 11:05 AM, Matthew Fioravante <span dir=3D"ltr"><<a hr=
ef=3D"mailto:fmatthew5876@gmail.com" target=3D"_blank">fmatthew5876@gmail.c=
om</a>></span> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><sp=
an class=3D"">On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafss=
on wrote:<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">Inner cla=
sses: If the only instance of the inner class is by value in its outer clas=
s then we could accomplish accessing the outer class's members without =
any coding:</div></blockquote></span></div></blockquote><div><br></div><div=
>This is not what "inner class" means, at least in Java (I'm =
not sure what other languages have established a definition for the term ye=
t) -- you can have any number of instances of the inner class created by a =
given instance of an outer class. What you're describing here seems to =
more akin to the "anonymous struct members" feature already suppo=
rted by several compilers.</div><div><br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><span class=3D""><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><div>class Outer {</div><div>=C2=A0 =C2=A0 int x;</div><=
div><br></div><div>=C2=A0 =C2=A0 class Inner {</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 void f() {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 i=
nt y =3D x; // This is assigning from Outer's x.</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 } m_inner;</div><div><div>};</d=
iv><br></div></div></blockquote></span><div><br>I think this should require=
some extra syntax to enforce that Inner is only allowed to be instantiated=
in one place and only as a value data member of Outer.<br><br>Something li=
ke:<br><br>class Outer {<br>=C2=A0 int x;<br>=C2=A0 static class Inner {<sp=
an class=3D""><br>=C2=A0 =C2=A0 void f() { int y =3D x; }<br></span>=C2=A0 =
} _inner1; //<-OK</div></div></blockquote><div>=C2=A0</div><div>That'=
;s OK even in C++98; this declares a static data member. But syntax aside, =
sure, this is feasible. But if you don't want a static inner class (or =
whatever you want to call that thing), you'd need to do something moral=
ly like rewriting:</div><div><br></div><div>=C2=A0 struct X { Y y; };</div>=
<div>=C2=A0 extern Y *p;</div><div>=C2=A0 X *x =3D &p->*-&X::y</=
div><div><br></div><div>as:</div><div><br></div><div>=C2=A0 struct X {</div=
><div>=C2=A0 =C2=A0 your_keyword_here struct MyY : Y {</div><div>=C2=A0 =C2=
=A0 =C2=A0 X &x_from_this() { return outer_this; }; // or however you&#=
39;d write that...</div><div>=C2=A0 =C2=A0 } y;</div><div>=C2=A0 };</div><d=
iv><br></div><div>=C2=A0 extern Y *p;</div><div>=C2=A0 X *x =3D &static=
_cast<X::MyY*>(p)->x_from_this();</div><div><br></div><div>... whi=
ch seems unfortunate.</div></div></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" 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 />
--001a11c2bb1ea020a105029769ef--
.
Author: inkwizytoryankes@gmail.com
Date: Tue, 9 Sep 2014 10:04:14 -0700 (PDT)
Raw View
------=_Part_522_1478277945.1410282254594
Content-Type: text/plain; charset=UTF-8
I think better would be use `inline` keyword there. Another thing is to
allow separate class definition with field definition. This will allow
template types and easy way to implement properties:
class Outer
{
template<typename A, Getter G, Setter S>
inline class Inner
{
};
Inner<int, &Outer::g1, &Outer::s1> a;
Inner<int, &Outer::g2, &Outer::s2> b; //two different types
//Inner<int, &Outer::g2, &Outer::s2> c; //error
}
On Monday, September 8, 2014 8:05:32 PM UTC+2, Matthew Fioravante wrote:
>
>
>
> On Sunday, September 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson wrote:
>>
>> Inner classes: If the only instance of the inner class is by value in its
>> outer class then we could accomplish accessing the outer class's members
>> without any coding:
>>
>> class Outer {
>> int x;
>>
>> class Inner {
>> void f() {
>> int y = x; // This is assigning from Outer's x.
>> }
>> } m_inner;
>> };
>>
>>
> I think this should require some extra syntax to enforce that Inner is
> only allowed to be instantiated in one place and only as a value data
> member of Outer.
>
> Something like:
>
> class Outer {
> int x;
> static class Inner {
> void f() { int y = x; }
> } _inner1; //<-OK
> Inner _inner2; //<- ERROR: cannot create multiple instances of a static
> nested class
> static class AnotherInner {}; //<-ERROR: cannot define a static nested
> class without also instantiating a value data member
> };
>
>
>
--
---
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_522_1478277945.1410282254594
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think better would be use `inline` keyword there. Anothe=
r thing is to allow separate class definition with field definition. This w=
ill allow template types and easy way to implement properties:<br><div clas=
s=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-col=
or: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: =
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Outer</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></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: #008;" c=
lass=3D"styled-by-prettify">template</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"st=
yled-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"=
> </span><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">Getter</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> G</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Setter</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> S</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">inline</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inner</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &n=
bsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inner<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&</span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Outer</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">g1</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><code class=3D"prettyprint"><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Oute=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::s1</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"></span></code>></span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Inner</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"></span><code class=3D"prettyprint"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&</span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Outer</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">g2</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><code class=3D"prettyprint"><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Oute=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::s</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"></span></code></span></cod=
e><span style=3D"color: #660;" class=3D"styled-by-prettify">2></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">//two different types</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br> </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">//Inner<int, &Outer:=
:g2, &Outer::s2> c; //error</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span></div></code></div><br><br><br><br><br>On Monday,=
September 8, 2014 8:05:32 PM UTC+2, Matthew Fioravante wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
#ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Sunday, Septemb=
er 7, 2014 6:57:26 PM UTC-4, Bengt Gustafsson wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">Inner classes: If the only instance of th=
e inner class is by value in its outer class then we could accomplish acces=
sing the outer class's members without any coding:<div><br></div><div>class=
Outer {</div><div> int x;</div><div><br></div><div> &nb=
sp; class Inner {</div><div> void f() {</div><di=
v> int y =3D x; // This is assigni=
ng from Outer's x.</div><div> }</div><div> =
} m_inner;</div><div><div>};</div><br></div></div></blockquote><div=
><br>I think this should require some extra syntax to enforce that Inner is=
only allowed to be instantiated in one place and only as a value data memb=
er of Outer.<br><br>Something like:<br><br>class Outer {<br> int x;<b=
r> static class Inner {<br> void f() { int y =3D x; }<br=
> } _inner1; //<-OK<br> Inner _inner2; //<- ERROR: cannot=
create multiple instances of a static nested class<br> static class =
AnotherInner {}; //<-ERROR: cannot define a static nested class without =
also instantiating a value data member<br>}; <br><br><br></div></div></bloc=
kquote></div>
<p></p>
-- <br />
<br />
--- <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 />
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_522_1478277945.1410282254594--
.
Author: Myriachan <myriachan@gmail.com>
Date: Tue, 9 Sep 2014 12:23:28 -0700 (PDT)
Raw View
------=_Part_1306_828064393.1410290608156
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 9, 2014 10:04:14 AM UTC-7, inkwizyt...@gmail.com
wrote:
>
> I think better would be use `inline` keyword there. Another thing is to
> allow separate class definition with field definition. This will allow
> template types and easy way to implement properties:
> class Outer
> {
> template<typename A, Getter G, Setter S>
> inline class Inner
> {
> };
> Inner<int, &Outer::g1, &Outer::s1> a;
> Inner<int, &Outer::g2, &Outer::s2> b; //two different types
> //Inner<int, &Outer::g2, &Outer::s2> c; //error
> }
>
>
That syntax idea is somewhat dangerous. It is legal to *declare* a class
as part of the return type on a function in current C++, though it is not
legal to *define* a class in a function declaration. That means that the
above is unambiguous with current C++, as the two don't *technically*
conflict, but it does look dangerously confusing with current legal code:
#include <cstdio>
class Outer
{
public:
inline class NotReallyInner Function();
};
class NotReallyInner { };
inline NotReallyInner Outer::Function()
{
std::printf("Meow there!\n");
return NotReallyInner();
}
int main()
{
Outer outer;
outer.Function();
return 0;
}
NotReallyInner in this case is not one of these inner classes with a
backlink with Outer, it's not even an inner class at all!
Melissa
--
---
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_1306_828064393.1410290608156
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, September 9, 2014 10:04:14 AM UTC-7, inkwizyt.=
...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">I think better would be use `inline` keyword there. Another thing is =
to allow separate class definition with field definition. This will allow t=
emplate types and easy way to implement properties:<br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#0=
08">class</span><span style=3D"color:#000"> </span><span style=3D"color:#60=
6">Outer</span><span style=3D"color:#000"><br></span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br> </span><span styl=
e=3D"color:#008">template</span><span style=3D"color:#660"><</span><span=
style=3D"color:#008">typename</span><span style=3D"color:#000"> A</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#000"></span><span style=3D"color:#606">Getter</span><span st=
yle=3D"color:#000"> G</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Setter</span><span style=
=3D"color:#000"> S</span><span style=3D"color:#660">></span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#008">inline<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">class</=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">Inner</s=
pan><span style=3D"color:#000"><br> </span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#000"><br> </span><span s=
tyle=3D"color:#660">};</span><span style=3D"color:#000"><br> <=
/span><span style=3D"color:#606">Inner</span><span style=3D"color:#660"><=
;</span><span style=3D"color:#008">int</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">&</s=
pan><span style=3D"color:#606">Outer</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">g1</span><span style=3D"color:#660"><code><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">&</span><span style=3D"color:#606">Outer</span><spa=
n style=3D"color:#660">::s1</span><span style=3D"color:#000"></span><span s=
tyle=3D"color:#660"></span></code>></span><span style=3D"color:#000"> a<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nb=
sp; </span><span style=3D"color:#606">Inner</span><span style=3D"col=
or:#660"><</span><span style=3D"color:#008">int</span><span style=3D"col=
or:#660">,</span><span style=3D"color:#000"></span><code><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">&</span><span style=3D"colo=
r:#606">Outer</span><span style=3D"color:#660">::</span><span style=3D"colo=
r:#000">g2</span><span style=3D"color:#660"><code><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&am=
p;</span><span style=3D"color:#606">Outer</span><span style=3D"color:#660">=
::s</span><span style=3D"color:#000"></span><span style=3D"color:#660"></sp=
an></code></span></code><span style=3D"color:#660">2></span><span style=
=3D"color:#000"> b</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"> </span><span style=3D"color:#800">//two different types</span>=
<span style=3D"color:#000"><br> </span><span style=3D"color:#8=
00">//Inner<int, &Outer::g2, &Outer::s2> c; //error</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div=
></code></div><div dir=3D"ltr"><div><br></div></div></div></blockquote><div=
><br>That syntax idea is somewhat dangerous. It is legal to <i>declar=
e</i> a class as part of the return type on a function in current C++, thou=
gh it is not legal to <i>define</i> a class in a function declaration. =
; That means that the above is unambiguous with current C++, as the two don=
't <i>technically</i> conflict, but it does look dangerously confusing with=
current legal code:<br><br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"=
styled-by-prettify">#include</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-p=
rettify"><cstdio></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Out=
er</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><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: #008;" class=3D"styled-by-prettify">public</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">inline</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">NotReallyInner</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Function</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">();</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><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">NotReallyInner</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">inline</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>NotReallyInner</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Oute=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">Function</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> std</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">printf</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"Meow there!\n"</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: #008;" =
class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">NotReallyInner</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-pre=
ttify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">int<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> main</span=
><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><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Outer</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> outer</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br> outer</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Function</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: #008=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">0</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">}</sp=
an></div></code></div><br><br><span style=3D"font-family: courier new,monos=
pace;">NotReallyInner</span> in this case is not one of these inner classes=
with a backlink with <span style=3D"font-family: courier new,monospace;">O=
uter</span>, it's not even an inner class at all!<br><br>Melissa<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" 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_1306_828064393.1410290608156--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 9 Sep 2014 12:48:08 -0700 (PDT)
Raw View
------=_Part_1076_468095694.1410292088514
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 9, 2014 3:23:28 PM UTC-4, Myriachan wrote:
>
>
> NotReallyInner in this case is not one of these inner classes with a
> backlink with Outer, it's not even an inner class at all!
>
That doesn't look confusing to me. All you did was forward declare a class
named NotReallyInner.
For this new feature, you shouldn't need to have the inline keyword for a
forward declaration of an inner class because forward declarations only
allow for pointers and references, which are perfectly safe for inner
classes. inline on a class forward declaration could be even made to be an
error, since its confusing with your example.
struct Outer {
struct Inner;
int x;
inline struct Inner {
int y;
void foo() { y += x; }
};
Inner a;
};
Another possible use for this feature, function local classes which want to
access local variables. This is kind of like a lambda, except now you have
an object with state and operations other than just a single function call
operator. It doesn't need to contain additional pointers / references to
the outside objects.
Here is one somewhat silly use case:
void foo(const char* path) {
FILE* fp = fopen(path, "r");
inline struct ScopeGuard {
~ScopeGuard() { fclose(fp); }
};
ScopeGuard sg;
}
Another option is to put the inline keyword either after the class, or
after the name like the final keyword.
class Foo {} inline;
class inline Bar {};
The reason being that if we were to use the inline keyword as is, then
inline would not be able to be used in front of variable declarations for
some hypothetical new feature later.
inline class A {}; //An inner class definition
inline int a; //Cool new feature, inline variable int a
inline class B {} b; //Is this an inline class or an inline variable?
This also resolve's Meliss'a dilemna.
--
---
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_1076_468095694.1410292088514
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, September 9, 2014 3:23:28 PM UTC-4, My=
riachan wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><br><div><span style=3D"font-family:courier new,monospace">NotReallyInner<=
/span> in this case is not one of these inner classes with a backlink with =
<span style=3D"font-family:courier new,monospace">Outer</span>, it's not ev=
en an inner class at all!<br></div></div></blockquote><div><br>That doesn't=
look confusing to me. All you did was forward declare a class named NotRea=
llyInner.<br><br>For this new feature, you shouldn't need to have the inlin=
e keyword for a forward declaration of an inner class because forward decla=
rations only allow for pointers and references, which are perfectly safe fo=
r inner classes. inline on a class forward declaration could be even made t=
o be an error, since its confusing with your example.<br><br><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: r=
gb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break=
-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=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">Outer</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">Inner</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">inline</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Inner</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> =
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">v=
oid</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> y </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">+=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </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">};</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inner</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br></span></div></code></div><br>Another po=
ssible use for this feature, function local classes which want to access lo=
cal variables. This is kind of like a lambda, except now you have an object=
with state and operations other than just a single function call operator.=
It doesn't need to contain additional pointers / references to the outside=
objects.<br><br>Here is one somewhat silly use case:<br><br><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: r=
gb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break=
-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">char</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
path</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> FILE</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> fp </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> fopen</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">path</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"r"</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">inline</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">ScopeGuard</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">~</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">ScopeGuard</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> fclose</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">fp</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">ScopeGuard</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> sg</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div><=
/code></div><br>Another option is to put the inline keyword either after th=
e class, or after the name like the final keyword.<br><br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{}</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">inline</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">inline</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></div></code></div><br>The reason being that if=
we were to use the inline keyword as is, then inline would not be able to =
be used in front of variable declarations for some hypothetical new feature=
later.<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(25=
0, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border=
-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">inl=
ine</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">class</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"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">//An inner class definition</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">inline</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
Cool new feature, inline variable int a</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> B </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">//Is this an inline class or an inl=
ine variable?</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span></div></code></div><br>This also resolve's Meliss'a dilem=
na.<br><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" 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_1076_468095694.1410292088514--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 9 Sep 2014 12:56:48 -0700 (PDT)
Raw View
------=_Part_671_376473722.1410292608929
Content-Type: text/plain; charset=UTF-8
Among my various typos, I meant this:
class Foo inline {};
class inline Bar {};
Probably the first one is better, as it matches that final already does.
On Tuesday, September 9, 2014 3:48:08 PM UTC-4, Matthew Fioravante wrote:
>
>
>
> On Tuesday, September 9, 2014 3:23:28 PM UTC-4, Myriachan wrote:
>>
>>
>> NotReallyInner in this case is not one of these inner classes with a
>> backlink with Outer, it's not even an inner class at all!
>>
>
> That doesn't look confusing to me. All you did was forward declare a class
> named NotReallyInner.
>
> For this new feature, you shouldn't need to have the inline keyword for a
> forward declaration of an inner class because forward declarations only
> allow for pointers and references, which are perfectly safe for inner
> classes. inline on a class forward declaration could be even made to be an
> error, since its confusing with your example.
>
> struct Outer {
> struct Inner;
>
> int x;
>
> inline struct Inner {
> int y;
>
> void foo() { y += x; }
> };
>
> Inner a;
> };
>
>
> Another possible use for this feature, function local classes which want
> to access local variables. This is kind of like a lambda, except now you
> have an object with state and operations other than just a single function
> call operator. It doesn't need to contain additional pointers / references
> to the outside objects.
>
> Here is one somewhat silly use case:
>
> void foo(const char* path) {
> FILE* fp = fopen(path, "r");
>
> inline struct ScopeGuard {
> ~ScopeGuard() { fclose(fp); }
> };
> ScopeGuard sg;
>
> }
>
> Another option is to put the inline keyword either after the class, or
> after the name like the final keyword.
>
> class Foo {} inline;
> class inline Bar {};
>
> The reason being that if we were to use the inline keyword as is, then
> inline would not be able to be used in front of variable declarations for
> some hypothetical new feature later.
>
>
> inline class A {}; //An inner class definition
> inline int a; //Cool new feature, inline variable int a
> inline class B {} b; //Is this an inline class or an inline variable?
>
>
> This also resolve's Meliss'a dilemna.
>
>
--
---
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_671_376473722.1410292608929
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Among my various typos, I meant this:<br><br><br><div styl=
e=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border=
-style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#008">class</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">Foo</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">inline {}</span><span style=3D"color:#000"></span><span style=
=3D"color:#008"></span><span style=3D"color:#660">;</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#008">class</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">inline</span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">Bar</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{};</span><span style=3D"color:=
#000"><br></span></div></code></div><br>Probably the first one is better, a=
s it matches that final already does.<br><br><br>On Tuesday, September 9, 2=
014 3:48:08 PM UTC-4, Matthew Fioravante wrote:<blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;"><div dir=3D"ltr"><br><br>On Tuesday, September 9, 2014 3:2=
3:28 PM UTC-4, Myriachan wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr"><br><div><span style=3D"font-family:courier new,monospace">Not=
ReallyInner</span> in this case is not one of these inner classes with a ba=
cklink with <span style=3D"font-family:courier new,monospace">Outer</span>,=
it's not even an inner class at all!<br></div></div></blockquote><div><br>=
That doesn't look confusing to me. All you did was forward declare a class =
named NotReallyInner.<br><br>For this new feature, you shouldn't need to ha=
ve the inline keyword for a forward declaration of an inner class because f=
orward declarations only allow for pointers and references, which are perfe=
ctly safe for inner classes. inline on a class forward declaration could be=
even made to be an error, since its confusing with your example.<br><br><d=
iv style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187)=
;border-style:solid;border-width:1px;word-wrap:break-word"><code><div><span=
style=3D"color:#008">struct</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">Outer</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"><br> </span><=
span style=3D"color:#008">struct</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">Inner</span><span style=3D"color:#660">;</span><s=
pan style=3D"color:#000"><br><br> </span><span style=3D"color:#008">i=
nt</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">;</=
span><span style=3D"color:#000"><br><br> </span><span style=3D"color:=
#008">inline</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">struct</span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">Inner</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br> </span><span styl=
e=3D"color:#008">int</span><span style=3D"color:#000"> y</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br><br> </=
span><span style=3D"color:#008">void</span><span style=3D"color:#000"> foo<=
/span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"> y </span><=
span style=3D"color:#660">+=3D</span><span style=3D"color:#000"> x</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">}</span><span style=3D"color:#000"><br> </span><s=
pan style=3D"color:#660">};</span><span style=3D"color:#000"><br><br> =
</span><span style=3D"color:#606">Inner</span><span style=3D"color:#000"> =
a</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br><b=
r></span></div></code></div><br>Another possible use for this feature, func=
tion local classes which want to access local variables. This is kind of li=
ke a lambda, except now you have an object with state and operations other =
than just a single function call operator. It doesn't need to contain addit=
ional pointers / references to the outside objects.<br><br>Here is one some=
what silly use case:<br><br><div style=3D"background-color:rgb(250,250,250)=
;border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wra=
p:break-word"><code><div><span style=3D"color:#008">void</span><span style=
=3D"color:#000"> foo</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">const</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">char</span><span style=3D"color:#660">*</span><span style=
=3D"color:#000"> path</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br> FILE</span><span style=3D"color:#660">*</span><span s=
tyle=3D"color:#000"> fp </span><span style=3D"color:#660">=3D</span><span s=
tyle=3D"color:#000"> fopen</span><span style=3D"color:#660">(</span><span s=
tyle=3D"color:#000">path</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"r"</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"><br><br> </span><=
span style=3D"color:#008">inline</span><span style=3D"color:#000"> </span><=
span style=3D"color:#008">struct</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">ScopeGuard</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#660">~</span><span style=3D"color:#606=
">ScopeGuard</span><span style=3D"color:#660">()</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"> fclose</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">fp</span><span style=3D"color:#660">);</span><span style=3D"color:#000">=
</span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>&=
nbsp; </span><span style=3D"color:#660">};</span><span style=3D"color:#000"=
><br> </span><span style=3D"color:#606">ScopeGuard</span><span style=
=3D"color:#000"> sg</span><span style=3D"color:#660">;</span><span style=3D=
"color:#000"><br><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br></span></div></code></div><br>Another option is to put =
the inline keyword either after the class, or after the name like the=
final keyword.<br><br><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code><div><span style=3D"color:#008">class</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#606">Foo</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">{}</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">inline</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008=
">class</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>inline</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Bar</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{}=
;</span><span style=3D"color:#000"><br></span></div></code></div><br>The re=
ason being that if we were to use the inline keyword as is, then inline wou=
ld not be able to be used in front of variable declarations for some hypoth=
etical new feature later.<br><br><div style=3D"background-color:rgb(250,250=
,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;wor=
d-wrap:break-word"><code><div><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#008">inline</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">class</span><span style=3D"color:#000"> A </span><span =
style=3D"color:#660">{};</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#800">//An inner class definition</span><span style=3D"color:#0=
00"><br></span><span style=3D"color:#008">inline</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">int</span><span style=3D"color:#0=
00"> a</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
</span><span style=3D"color:#800">//Cool new feature, inline variable int =
a</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">in=
line</span><span style=3D"color:#000"> </span><span style=3D"color:#008">cl=
ass</span><span style=3D"color:#000"> B </span><span style=3D"color:#660">{=
}</span><span style=3D"color:#000"> b</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#800">//Is this=
an inline class or an inline variable?</span><span style=3D"color:#000"><b=
r><br></span></div></code></div><br>This also resolve's Meliss'a dilemna.<b=
r><br></div></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <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 />
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_671_376473722.1410292608929--
.
Author: Myriachan <myriachan@gmail.com>
Date: Tue, 9 Sep 2014 13:07:59 -0700 (PDT)
Raw View
------=_Part_1308_250739408.1410293279240
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 9, 2014 12:56:49 PM UTC-7, Matthew Fioravante wrote:
>
> Another option is to put the inline keyword either after the class, or
> after the name like the final keyword.
>
>>
>> class Foo inline {};
>> class inline Bar {};
>>
>> The reason being that if we were to use the inline keyword as is, then
>> inline would not be able to be used in front of variable declarations for
>> some hypothetical new feature later.
>>
>>
>> inline class A {}; //An inner class definition
>> inline int a; //Cool new feature, inline variable int a
>> inline class B {} b; //Is this an inline class or an inline variable?
>>
>>
>> This also resolve's Melissa's dilemma.
>>
>>
Yes, this works much better. C and C++ have always had keywords before
class/struct/union refer to the variable/function/typedef afterward rather
than the class being declared.
How would the special member functions work, especially across outer
instances? For example, what would happen if you did:
struct Outer
{
struct Inner inline
{
//...
};
void CopyOuter(Inner &dest, const Inner &src) const
{
dest = src;
}
Inner m_inner;
};
int main()
{
Outer outer1, outer2;
outer1.CopyInner(outer1.m_inner, outer2.m_inner);
return 0;
}
Melissa
--
---
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_1308_250739408.1410293279240
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, September 9, 2014 12:56:49 PM UTC-7, Matthew F=
ioravante wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">Another option is to put the inline keyword either after the class=
, or after the name like the final keyword.<br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddin=
g-left:1ex"><div dir=3D"ltr"><div><br><div style=3D"background-color:rgb(25=
0,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1p=
x;word-wrap:break-word"><code><div><span style=3D"color:#008">class</span><=
span style=3D"color:#000"> </span><span style=3D"color:#606">Foo</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">inline {}</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#008">class</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">inline</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">Bar</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{};</span><span style=3D"color:#000"><br></span></div><=
/code></div><br>The reason being that if we were to use the inline keyword =
as is, then inline would not be able to be used in front of variable declar=
ations for some hypothetical new feature later.<br><br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#0=
00"><br></span><span style=3D"color:#008">inline</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">class</span><span style=3D"color:=
#000"> A </span><span style=3D"color:#660">{};</span><span style=3D"color:#=
000"> </span><span style=3D"color:#800">//An inner class definition</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">inline</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">int</span><=
span style=3D"color:#000"> a</span><span style=3D"color:#660">;</span><span=
style=3D"color:#000"> </span><span style=3D"color:#800">//Cool new feature=
, inline variable int a</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#008">inline</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">class</span><span style=3D"color:#000"> B </span><span =
style=3D"color:#660">{}</span><span style=3D"color:#000"> b</span><span sty=
le=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=3D=
"color:#800">//Is this an inline class or an inline variable?</span><span s=
tyle=3D"color:#000"><br><br></span></div></code></div><br>This also resolve=
's Melissa's dilemma.<br><br></div></div></blockquote></div></blockquote><d=
iv><br>Yes, this works much better. C and C++ have always had keyword=
s before <span style=3D"font-family: courier new,monospace;">class</span>/<=
span style=3D"font-family: courier new,monospace;">struct</span>/<span styl=
e=3D"font-family: courier new,monospace;">union</span> refer to the variabl=
e/function/<span style=3D"font-family: courier new,monospace;">typedef</spa=
n> afterward rather than the class being declared.<br><br>How would the spe=
cial member functions work, especially across outer instances? For ex=
ample, what would happen if you did:<br><br><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Outer</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inner<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">inline</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><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">//.=
...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">CopyOuter</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">Inner</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">dest</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inn=
er</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">src</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> dest </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> src</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">}</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br><br> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Inner</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> m_inner</span><span style=3D"color: #66=
0;" 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"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> main</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">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Outer</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> outer1</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> outer2</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br> outer1</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">CopyInner</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">outer1</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">m_inner</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
outer2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">m_inner</span=
><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: #008;" class=3D"styled-by-prettify">return</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">0</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">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div><br><br>Melissa<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" 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_1308_250739408.1410293279240--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 9 Sep 2014 13:30:38 -0700 (PDT)
Raw View
------=_Part_500_1042988436.1410294638951
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 9, 2014 4:07:59 PM UTC-4, Myriachan wrote:
>
>
> How would the special member functions work, especially across outer
> instances? For example, what would happen if you did:
>
> struct Outer
> {
> struct Inner inline
> {
> //...
> };
>
> void CopyOuter(Inner &dest, const Inner &src) const
> {
> dest = src;
> }
>
> Inner m_inner;
> };
>
> int main()
> {
> Outer outer1, outer2;
> outer1.CopyInner(outer1.m_inner, outer2.m_inner);
> return 0;
> }
>
>
That seems perfectly fine to me. You don't even need all of that
obfuscation to make the point:
struct Outer {
struct Inner A { /* stuff */ };
A a;
};
void foo() {
Outer o1, o2;
o1.a = o2.a;
}
The notion needs to be defined more precisely, but I believe the
restriction should be that you can create only one instance of an inner
class as a value data member of its container (outer class or function
scope). You can't create additional data members, temporaries, local
variables, or any other instantiation of the type. The restriction is that
an inner class's physical position in memory must be fixed relative to its
outer container (offset as a data member or position on the stack frame as
a local variable).
Inner classes can be copyable and movable, as you copy and move their outer
containers. Moving and copying instances of Inner classes in function scope
doesn't make sense, as there will only ever be one instance.
How about global scope?
Only one instance.. Another use case. Singletons? This might be hijacking
the feature for a totally different unintended purpose. There's really no
such thing as a inner glass in global scope as by definition everything
already has access to global scoped objects.
//foo.hh in global scope
class Singleton inline {};
extern Singleton x;
//foo.cc, in global scope
Singleton x;
Singleton y; //ERROR: Multiple instances of inline class Singleton
This creates problems with multiple translation units.
//foo.hh
class Foo inline {};
//a.cc
Foo a;
//b.cc
Foo b;
The compiler cannot catch this, but maybe its ok?
--
---
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_500_1042988436.1410294638951
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, September 9, 2014 4:07:59 PM UTC-4, My=
riachan wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><br><div>How would the special member functions work, especially across ou=
ter instances? For example, what would happen if you did:<br><br><div=
style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);b=
order-style:solid;border-width:1px;word-wrap:break-word"><code><div><span s=
tyle=3D"color:#008">struct</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#606">Outer</span><span style=3D"color:#000"><br></span><span=
style=3D"color:#660">{</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Inner</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">inline</span><span style=3D"color:#000"><b=
r> </span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br> </span><span style=3D"color:#800"=
>//...</span><span style=3D"color:#000"><br> </span><span styl=
e=3D"color:#660">};</span><span style=3D"color:#000"><br><br> =
</span><span style=3D"color:#008">void</span><span style=3D"color:#000"> </=
span><span style=3D"color:#606">CopyOuter</span><span style=3D"color:#660">=
(</span><span style=3D"color:#606">Inner</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">&</span><span style=3D"color:#000">de=
st</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#008">const</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">Inner</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">&</span><span style=3D"color:#000">src</sp=
an><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">const</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"=
><br> dest </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> src</span><span style=3D"color:#660">;</=
span><span style=3D"color:#000"><br> </span><span style=3D"col=
or:#660">}</span><span style=3D"color:#000"><br><br> </span><s=
pan style=3D"color:#606">Inner</span><span style=3D"color:#000"> m_inner</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br></=
span><span style=3D"color:#008">int</span><span style=3D"color:#000"> main<=
/span><span style=3D"color:#660">()</span><span style=3D"color:#000"><br></=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbs=
p; </span><span style=3D"color:#606">Outer</span><span style=3D"colo=
r:#000"> outer1</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> outer2</span><span style=3D"color:#660">;</span><span style=3D"co=
lor:#000"><br> outer1</span><span style=3D"color:#660">.</span=
><span style=3D"color:#606">CopyInner</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">outer1</span><span style=3D"color:#660">.</s=
pan><span style=3D"color:#000">m_<wbr>inner</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> outer2</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">m_inner</span><span style=3D"color:#6=
60">);</span><span style=3D"color:#000"><br> </span><span styl=
e=3D"color:#008">return</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"co=
lor:#000"><br></span></div></code></div><br></div></div></blockquote><div><=
br>That seems perfectly fine to me. You don't even need all of that obfusca=
tion to make the point:<br><br><div class=3D"prettyprint" style=3D"backgrou=
nd-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-styl=
e: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyp=
rint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Outer</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </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: #008;" class=3D"styled-by-prettify">struct</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Inner</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> A </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"sty=
led-by-prettify">/* stuff */</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br> A a</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> </span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Outer</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> o1</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> o2=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> o1</=
span><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">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> o2</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></div></code></div><br><br><br>The notion needs to be defined more precis=
ely, but I believe the restriction should be that you can create only one i=
nstance of an inner class as a value data member of its container (outer cl=
ass or function scope). You can't create additional data members, temporari=
es, local variables, or any other instantiation of the type. The restrictio=
n is that an inner class's physical position in memory must be fixed relati=
ve to its outer container (offset as a data member or position on the stack=
frame as a local variable).<br><br>Inner classes can be copyable and movab=
le, as you copy and move their outer containers. Moving and copying instanc=
es of Inner classes in function scope doesn't make sense, as there will onl=
y ever be one instance.<br><br>How about global scope?<br><br>Only one inst=
ance.. Another use case. Singletons? This might be hijacking the feature fo=
r a totally different unintended purpose. There's really no such thing as a=
inner glass in global scope as by definition everything already has access=
to global scoped objects.<br><br><div class=3D"prettyprint" style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=
=3D"styled-by-prettify">//foo.hh in global scope</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Singleton</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">inline</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">extern<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">Singleton</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">//foo.cc, in global scope</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Singleton</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Singleton</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
ERROR: Multiple instances of inline class Singleton</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>=
This creates problems with multiple translation units.<br><br><div class=3D=
"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: =
rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: brea=
k-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">//foo.hh</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">inline</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//a.c=
c</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">//b.cc</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span></div></code></div><br>The compiler cannot catch this, b=
ut maybe its ok?<br> </div><div> </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" 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_500_1042988436.1410294638951--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 9 Sep 2014 13:52:59 -0700 (PDT)
Raw View
------=_Part_711_163131469.1410295979237
Content-Type: text/plain; charset=UTF-8
One more possibility, which would need a lot of work to be fleshed out and
made precise.
Intrusive data structures using inline template classes.
template <typename T>
class ListNode inline {
public:
T& getObject() { return *T::this; }
ListNode<T>* prev() { return _prev; }
ListNode<T>* next() { return _next; }
private:
ListNode<T>* _prev;
ListNode<T>* _next;
};
struct Foo {
int x;
int y;
ListNode<Foo> node;
};
Here the first template argument would be designated as the outer class and
thus ListNode<Foo> would have to be instantiated as a data member of foo.
This would be an error:
struct Bar {};
ListNode<Bar> b;
This feature might be useful more generically for other purposes:
template <typename T>
class DoStuffWithX inline {
void addX(int y) { T::x += y; }
};
class Outer1 {
int x;
DoStuffWithX d;
};
class Outer2 {
int z;
DoStuffWithX<Outer2> d; //ERROR: Outer2 has no member named x! Outer2::x
does not compile
};
That seems more compelling than the singleton case. In general the rule for
a template could be that its outer scope is not defined until you
instantiate it. So that you can reuse it in different scopes which satisfy
the concepts it requires.
--
---
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_711_163131469.1410295979237
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">One more possibility, which would need a lot of work to be=
fleshed out and made precise.<br><br>Intrusive data structures using inlin=
e template classes.<br><br><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">template</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ty=
pename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</=
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 s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">ListNode</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">public</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <br>&=
nbsp; T</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
getObject</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
this</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br> </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">ListNode</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">>*</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> prev</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> _prev</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </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:=
#606;" class=3D"styled-by-prettify">ListNode</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">>*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">next</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> _next</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">private</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">ListNode</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">>*</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> _prev</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 s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">ListNode</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">>*</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> _next</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </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"colo=
r: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> y</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">ListNod=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> node</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br><br></span></div></code></div><br>Here the first=
template argument would be designated as the outer class and thus ListNode=
<Foo> would have to be instantiated as a data member of foo.<br><br>T=
his would be an error:<br><div class=3D"prettyprint" style=3D"background-co=
lor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: so=
lid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><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"=
>Bar</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">ListNode</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">></span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> <br></span></div></code></div><br>This feature might be use=
ful more generically for other purposes:<br><br><div class=3D"prettyprint" =
style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, =
187); border-style: solid; border-width: 1px; word-wrap: break-word;"><code=
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: =
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">cla=
ss</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">DoStuffWithX</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">inline</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </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: #008;"=
class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> addX</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">x </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">+=3D</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> y</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> <br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Outer1</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </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: #008;" class=3D"styled-by-prettif=
y">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">DoStuffWithX</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> d</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Outer2</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </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: #008;" class=3D"styled-by-prettify">int</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br> </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">DoStuffWithX</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color:=
#606;" class=3D"styled-by-prettify">Outer2</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> d</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>//ERROR: Outer2 has no member named x! Outer2::x does not compile</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br><br></span></div></code><=
/div><br>That seems more compelling than the singleton case. In general the=
rule for a template could be that its outer scope is not defined until you=
instantiate it. So that you can reuse it in different scopes which satisfy=
the concepts it requires.<br><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" 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_711_163131469.1410295979237--
.