Topic: A means to access the encapsulating object within
Author: mihailnajdenov@gmail.com
Date: Wed, 19 Oct 2016 02:43:59 -0700 (PDT)
Raw View
------=_Part_95_1850439157.1476870239878
Content-Type: multipart/alternative;
boundary="----=_Part_96_1969648807.1476870239878"
------=_Part_96_1969648807.1476870239878
Content-Type: text/plain; charset=UTF-8
But you can always store a pointer in the contained class to the containing
class
template <class T, class Obj, T (Obj::*G)() const, void (Obj::*S)(T)>
struct Property
{
Obj& operator=(const T &value) {
auto p = _that;
(p->*S)(value);
return *p; // we return the encapsulating object for intuitive
chaining
}
operator T () const {
auto p = _that;
return (p->*G)();
}
Obj* _that;
};
struct A {
public:
int getMember() const { return member_; } // imagine that these are
complex routines
void setMember(int v) { member_ = v; } // and we couldn't get the
same behavior by making member_ public
public:
Property<int, A, &A::getMember, &A::setMember> member{this};
private:
int member_;
};
This compiles and runs today.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c3476dd7-7b32-4135-b4f3-fbafae3608c1%40isocpp.org.
------=_Part_96_1969648807.1476870239878
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>But you can always store a pointer in the contained c=
lass to the containing class</div><div><br></div><div class=3D"prettyprint"=
style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; back=
ground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span class=3D"styled-by-prettify" style=3D"color: #606=
;"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: =
transparent;">template <class T, class Obj, T (Obj::*G)() const, void (O=
bj::*S)(T)><br>struct Property=C2=A0 <br>{<br>=C2=A0=C2=A0=C2=A0 Obj&=
; operator=3D(const T &value) {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 auto p =3D _that;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (p-&=
gt;*S)(value);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return *p; // =
we return the encapsulating object for intuitive chaining<br>=C2=A0=C2=A0=
=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 operator T () const {=
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto p =3D _that;<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return (p->*G)();<br>=C2=A0=C2=A0=
=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 Obj* _that;<br>};</fo=
nt></span></div><div><br></div><div class=3D"subprettyprint"><span class=3D=
"styled-by-prettify" style=3D"color: #606;"><font color=3D"rgb(34,34,34)" f=
ace=3D"Arial" style=3D"background-color: transparent;"><br>struct A {</font=
></span></div><div><br></div><div class=3D"subprettyprint"><span class=3D"s=
tyled-by-prettify" style=3D"color: #606;"><font color=3D"rgb(34,34,34)" fac=
e=3D"Arial" style=3D"background-color: transparent;">public:<br>=C2=A0=C2=
=A0=C2=A0 int getMember() const { return member_; } // imagine that these a=
re complex routines<br>=C2=A0=C2=A0=C2=A0 void setMember(int v) { member_ =
=3D v; }=C2=A0=C2=A0=C2=A0 // and we couldn't get the same behavior by =
making member_ public</font></span></div><div><br></div><div class=3D"subpr=
ettyprint"><span class=3D"styled-by-prettify" style=3D"color: #606;"><font =
color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transpare=
nt;">public:<br>=C2=A0=C2=A0=C2=A0 Property<int, A, &A::getMember, &=
amp;A::setMember> member{this};<br>=C2=A0=C2=A0=C2=A0 <br>private:<br>=
=C2=A0=C2=A0=C2=A0 int member_;<br>};</font></span><span class=3D"styled-by=
-prettify" style=3D"color: #660;"></span></div></code></div><div><br></div>=
<div><br></div><div>This compiles and runs today.</div><div><br></div></div=
>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c3476dd7-7b32-4135-b4f3-fbafae3608c1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c3476dd7-7b32-4135-b4f3-fbafae3608c1=
%40isocpp.org</a>.<br />
------=_Part_96_1969648807.1476870239878--
------=_Part_95_1850439157.1476870239878--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 19 Oct 2016 06:29:59 -0700 (PDT)
Raw View
------=_Part_194_1350717381.1476883799700
Content-Type: multipart/alternative;
boundary="----=_Part_195_982572844.1476883799700"
------=_Part_195_982572844.1476883799700
Content-Type: text/plain; charset=UTF-8
I had some ideas about inner classes in C++ that do this
<https://groups.google.com/a/isocpp.org/d/msg/std-proposals/HjGujSdKXX0/27WIWTc_EwAJ>
..
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/153735cc-65da-4061-a77c-57d59d97afc3%40isocpp.org.
------=_Part_195_982572844.1476883799700
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I had some ideas about <a href=3D"https://groups.google.co=
m/a/isocpp.org/d/msg/std-proposals/HjGujSdKXX0/27WIWTc_EwAJ">inner classes =
in C++ that do this</a>.<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/153735cc-65da-4061-a77c-57d59d97afc3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/153735cc-65da-4061-a77c-57d59d97afc3=
%40isocpp.org</a>.<br />
------=_Part_195_982572844.1476883799700--
------=_Part_194_1350717381.1476883799700--
.
Author: Evan Teran <evan.teran@gmail.com>
Date: Wed, 19 Oct 2016 08:02:07 -0700 (PDT)
Raw View
------=_Part_217_1514164744.1476889327493
Content-Type: multipart/alternative;
boundary="----=_Part_218_749706940.1476889327493"
------=_Part_218_749706940.1476889327493
Content-Type: text/plain; charset=UTF-8
yes, you can store it via a constructor explicitly, I hadn't thought about
using the in class version of the constructor which is nice.
On Wednesday, October 19, 2016 at 5:44:00 AM UTC-4, mihailn...@gmail.com
wrote:
>
> But you can always store a pointer in the contained class to the
> containing class
>
> template <class T, class Obj, T (Obj::*G)() const, void (Obj::*S)(T)>
> struct Property
> {
> Obj& operator=(const T &value) {
> auto p = _that;
> (p->*S)(value);
> return *p; // we return the encapsulating object for intuitive
> chaining
> }
>
> operator T () const {
> auto p = _that;
> return (p->*G)();
> }
>
> Obj* _that;
> };
>
>
> struct A {
>
> public:
> int getMember() const { return member_; } // imagine that these are
> complex routines
> void setMember(int v) { member_ = v; } // and we couldn't get the
> same behavior by making member_ public
>
> public:
> Property<int, A, &A::getMember, &A::setMember> member{this};
>
> private:
> int member_;
> };
>
>
> This compiles and runs today.
>
>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9%40isocpp.org.
------=_Part_218_749706940.1476889327493
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">yes, you can store it via a constructor explicitly, I hadn=
't thought about using the in class version of the constructor which is=
nice.<br><br>On Wednesday, October 19, 2016 at 5:44:00 AM UTC-4, mihailn..=
..@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div>But you can always store a pointer in the contained class to the =
containing class</div><div><br></div><div style=3D"border:1px solid rgb(187=
,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><di=
v><span style=3D"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" s=
tyle=3D"background-color:transparent">template <class T, class Obj, T (O=
bj::*G)() const, void (Obj::*S)(T)><br>struct Property=C2=A0 <br>{<br>=
=C2=A0=C2=A0=C2=A0 Obj& operator=3D(const T &value) {<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto p =3D _that;<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 (p->*S)(value);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 return *p; // we return the encapsulating object for intuit=
ive chaining<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=
=C2=A0 operator T () const {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
auto p =3D _that;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return (p-&=
gt;*G)();<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=
=A0 Obj* _that;<br>};</font></span></div><div><br></div><div><span style=3D=
"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"backgrou=
nd-color:transparent"><br>struct A {</font></span></div><div><br></div><div=
><span style=3D"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" st=
yle=3D"background-color:transparent">public:<br>=C2=A0=C2=A0=C2=A0 int getM=
ember() const { return member_; } // imagine that these are complex routine=
s<br>=C2=A0=C2=A0=C2=A0 void setMember(int v) { member_ =3D v; }=C2=A0=C2=
=A0=C2=A0 // and we couldn't get the same behavior by making member_ pu=
blic</font></span></div><div><br></div><div><span style=3D"color:#606"><fon=
t color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:transpar=
ent">public:<br>=C2=A0=C2=A0=C2=A0 Property<int, A, &A::getMember, &=
amp;A::setMember> member{this};<br>=C2=A0=C2=A0=C2=A0 <br>private:<br>=
=C2=A0=C2=A0=C2=A0 int member_;<br>};</font></span><span style=3D"color:#66=
0"></span></div></code></div><div><br></div><div><br></div><div>This compil=
es and runs today.</div><div><br></div></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9=
%40isocpp.org</a>.<br />
------=_Part_218_749706940.1476889327493--
------=_Part_217_1514164744.1476889327493--
.