220 5956 <82e8d6bc-c6a3-441d-8079-d385cd4f1238@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nick <nicolas.jinchereau@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Properties Syntax
Date: Wed, 28 Aug 2013 15:30:18 -0700 (PDT)
Lines: 510
Approved: news@gmane.org
Message-ID: <82e8d6bc-c6a3-441d-8079-d385cd4f1238@isocpp.org>
References: <e18c3ee9-66f7-48e0-bd8b-04051c952de0@isocpp.org>
 <5e23a0e9-2bd9-4f62-aa83-47bea8144eae@isocpp.org>
 <CALQmNFjE1QX9CMt_7bo3XRLKv4rXsbiYAo9dqkUK5TCqLyyGEw@mail.gmail.com>
 <CAFk2RUagizA4UKrnb__8oJXB2ni96ZwYTzAp=HTgOdMZCDXwOA@mail.gmail.com>
 <1377717206.3009.5.camel@sara>
 <b2df9bd9-3f78-41b2-bfce-e4ac86f25847@isocpp.org>
 <CAOfiQqkkThJMVsn1mRkfxDGALn-HmVGTUvH=8HK4ynSDTBExvA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_819_7158214.1377729018440"
X-Trace: ger.gmane.org 1377729018 22564 80.91.229.3 (28 Aug 2013 22:30:18 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 28 Aug 2013 22:30:18 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC42HSUOVYGBB67T7GIAKGQEFF6VVQA@isocpp.org Thu Aug 29 00:30:21 2013
Return-path: <std-proposals+bncBC42HSUOVYGBB67T7GIAKGQEFF6VVQA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC42HSUOVYGBB67T7GIAKGQEFF6VVQA@isocpp.org>)
	id 1VEoFo-0007J8-I8
	for gclcip-std-proposals@m.gmane.org; Thu, 29 Aug 2013 00:30:21 +0200
Original-Received: by mail-ob0-f199.google.com with SMTP id dn14sf25669451obc.6
        for <gclcip-std-proposals@m.gmane.org>; Wed, 28 Aug 2013 15:30:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=tnjxbtQ8ZSoU/H27TObwds2tAnZDkxqfTbzRfBWqXUU=;
        b=y+dFJl9ZM62pVUPEOsxiE8HXBMstZwZ99b+w7XhQSqRtijasdSvTwSpmiexrw25HSo
         3siXMyPDna9xe3ykmZre8tWaB8G2BI2zSWcgEKND1f13dXfEyhEW7mk9wUPLEEOcLcfw
         zTuY9xWccAYmNq2muQHzwOIIBHDwIkHpmccJM6SaI0U3vjZUhkWDaO3VO6U+le/veyYV
         b329JNP5Zf5U5Fum0lkkK0Up7gPckqODciJ+AqNg2Sz4Y2Cv5c7wp2DWF+CinerEo8HL
         sL7xODbTYe3RoqN/5qOt1rCrt0BboFdjdBrqU/6gc5bicJSHhZdCcKuTLbsANLLpWpWp
         co/w==
X-Received: by 10.182.148.230 with SMTP id tv6mr22626obb.42.1377729019411;
        Wed, 28 Aug 2013 15:30:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.12.231 with SMTP id b7ls608673qec.68.gmail; Wed, 28 Aug
 2013 15:30:18 -0700 (PDT)
X-Received: by 10.49.94.39 with SMTP id cz7mr7472qeb.26.1377729018955;
        Wed, 28 Aug 2013 15:30:18 -0700 (PDT)
In-Reply-To: <CAOfiQqkkThJMVsn1mRkfxDGALn-HmVGTUvH=8HK4ynSDTBExvA@mail.gmail.com>
X-Original-Sender: nicolas.jinchereau@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5956
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5956>

------=_Part_819_7158214.1377729018440
Content-Type: text/plain; charset=ISO-8859-1

On Wednesday, 28 August 2013 17:24:44 UTC-4, Richard Smith wrote:

> On Wed, Aug 28, 2013 at 12:52 PM, Nick <nicolas.j...@gmail.com<javascript:>
> > wrote:
>
>> I have to disagree with this.
>>
>> With Richard's implementation, taking sizeof(property<int>) yields 48 
>> bytes.
>>
>> So if you had an object with 10 properties, you would have a half a 
>> kilobyte of extra data per instance.
>>
>> The function pointers can be done away with using some very convoluted 
>> template syntax, but the reference to the container must still exist, 
>> making the minimum possible size of a library based property 4 bytes, which 
>> is still not negligible.
>>
>
> Yes, the code I presented is not ideal, in a number of ways. The storage 
> overhead is one. Another is that "a.number = b.number" does not compile, 
> and classes containing such properties become non-copyable ("a.number = 
> b.number;" would need to do different things depending on whether it 
> happens in the surrounding class's copy-assignment operator).
>
> But... if we can find a set of language changes that suffice to make a 
> library implementation of properties work better, we are likely to improve 
> the language as a whole rather than adding a single point feature.
>
 


There are several more problems with library properties beside the storage 
overhead.

Let's consider that we used the following template implementation, which 
still takes 4 bytes per property:

template<typename T, class C, T(C::*get)(), void(C::*set)(T)>
struct property {
    C *object;
    property(C *object) : object(object){}

    operator T() { return (object->*get)(); }
    template<typename U> property &operator=(U &&u) { (object->*set)(std::
forward<U>(u)); return *this; }
}

1) But consider using it on a Point:

struct Point
{
    float x, y;
    Point(float x = 0, float y = 0) : x(x), y(y){}
};

How would you provide access to the members of Point with library 
properties?

struct Test {
    property<Point, ...> point;
};

Test test;
cout << test.point.x << endl;

Currently, the only option available is to override T* operator->()

const T* property::operator->() { return &(object->*get)(); }

but unless C::get() returns a reference, which it very likely won't, then 
this code will be returning a reference to a temporary. This may not cause 
problems, since that temporary is read only, but may will fail to compile 
or generate warnings on some compilers.

2) No function overloading could be done for the setter.

3) specific functionality of the property's type would be hidden:

Consider if Point had operator+=()

Point& operator+=(const Point &p) { x += p.x; y += p.y; return *this; }

The following code would not compile:

test.point += Point(5, 6);

Whereas, with a real property, the get and set methods of the property 
could be called to retrieve and store the value.

Now, a partial solution may be to include commonly used operators inside 
the property class:

template<typename U>
property &operator+=(U &&u) {
    T tmp = (object->*get)();
    tmp += u;
    (object->*set)(std::forward<U>(tmp));
    return *this; 
}

And since this is a template, I'm pretty sure(vs2012 and mingw tested) it 
should be ignored for classes that don't have an operator+= unless you 
actually try to use it, but that doesn't fix the problem that you still 
have to include every operator manually into your property class.

If you started to use a class that had a ToString() method, now you would 
need to incorporate that into your property too, and the list would go on 
endlessly.

4) Finally if something like offsetof() was standardized to work on non-POD 
types, there would be a way to get rid of that last 4 bytes per property, 
but currently, it is not. And I say "something like" because assuming that 
offsetof() did work, it would still require macros to get the job done. A 
real piece of builtin compiler magic would still be needed to get a pointer 
to the enclosing instance of an object.


Now, this is just the begining, but I'm sure I could go on for a few more 
hours at least.

-- 

--- 
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_819_7158214.1377729018440
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span style=3D"font-size: 13px;">On Wednesday, 28 August 2=
013 17:24:44 UTC-4, Richard Smith  wrote:</span><br><blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;"><div dir=3D"ltr">On Wed, Aug 28, 2013 at 12:52 PM, Ni=
ck <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfu=
scated-mailto=3D"4QacqHzBpXUJ">nicolas.j...@gmail.com</a>&gt;</span> wrote:=
<br><div><div class=3D"gmail_quote">
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><span style=3D"font-si=
ze:13px">I have to disagree with this.</span></div><div><span style=3D"font=
-size:13px"><br>
</span></div><div>With Richard's implementation, taking sizeof(property&lt;=
int&gt;) yields 48 bytes.</div><div><br></div><div>So if you had an object =
with 10 properties, you would have a half a kilobyte of extra data per inst=
ance.</div>
<div><br></div><div>The function pointers can be done away with using some =
very convoluted template syntax,&nbsp;<span style=3D"font-size:13px">but th=
e reference to the container must still exist, making the minimum possible =
size of a library based property 4 bytes, which is still not negligible.</s=
pan></div>
</div></blockquote><div><br></div><div>Yes, the code I presented is not ide=
al, in a number of ways. The storage overhead is one. Another is that "a.nu=
mber =3D b.number" does not compile, and classes containing such properties=
 become non-copyable ("a.number =3D b.number;" would need to do different t=
hings depending on whether it happens in the surrounding class's copy-assig=
nment operator).</div>
<div><br></div><div>But... if we can find a set of language changes that su=
ffice to make a library implementation of properties work better, we are li=
kely to improve the language as a whole rather than adding a single point f=
eature.</div></div></div></div></blockquote><div>&nbsp;</div><div><br></div=
><div><br></div><div>There are several more problems with library propertie=
s beside the storage overhead.</div><div><br></div><div>Let's consider that=
 we used the following template implementation, which still takes 4 bytes p=
er property:</div><div><br></div><div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); 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: #660;" class=3D"styled-by-prettify">&lt;</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T</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: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> C</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">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">C</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::*</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">get</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">void</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">C</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">set</sp=
an><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">)&gt;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> property </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>&nbsp; &nbsp; C </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">*</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">object</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>&nbsp; &nbsp; property</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">C </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ob=
ject</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"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">object</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">object</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">){}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">operator</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> T</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"> </span><span s=
tyle=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=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">object</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">-&gt;*</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">get</span><span style=3D"color: #660;" class=3D"styled=
-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>&nbsp;=
 &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> property </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">=3D(</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">U </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">u</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: #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: #008;" class=3D"styled-by-prettify">object</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-&gt;*</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">set</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">u</span><s=
pan 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"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">*</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">this</span><span style=3D"color: #660;" class=3D"styled-b=
y-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"><br></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><div><br></div><div>1)&nbsp;<span style=3D"font-size: 13px;">But consider=
 using it on a Point:</span></div><div><br></div><div><div class=3D"prettyp=
rint" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(=
187, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Point</=
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>&nbsp; &nbsp; </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">,</span><font color=3D"#000000">=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> y</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span></font><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><font color=3D"#=
000000"><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &n=
bsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Point=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> x </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">0</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: #008;" class=3D"styled-by-prettify"=
>float</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;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">0</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"> x</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">x</sp=
an><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">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">y</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">){}</span></font><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span></div></code></div></div><div><br></div><d=
iv>How would you provide access to the members of Point with library proper=
ties?</div><div><br></div><div class=3D"prettyprint" style=3D"background-co=
lor: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Test</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: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; &nbsp; property</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Point</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">...&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 point</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></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><br></span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Test</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> test</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>cout </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> test</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">point</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">x </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> endl</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div></cod=
e></div><div><br></div><div>Currently, the only option available is to over=
ride T* operator-&gt;()</div><div><br></div><div><div class=3D"prettyprint"=
 style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, =
187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> property</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-&gt;()</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;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&amp;(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
object</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt=
;*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">get</spa=
n><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></div></code></div><=
br>but unless C::get() returns a reference, which it very likely won't, the=
n this code will be returning a reference to a temporary. This may not caus=
e problems, since that temporary is read only, but may will fail to compile=
 or generate warnings on some compilers.</div><div><br></div><div>2)&nbsp;<=
span style=3D"font-size: 13px;">No function overloading could be done for t=
he setter.</span></div><div><span style=3D"font-size: 13px;"><br></span></d=
iv><div><span style=3D"font-size: 13px;">3) specific functionality of the p=
roperty's type would be hidden:</span></div><div><span style=3D"font-size: =
13px;"><br></span></div><div><span style=3D"font-size: 13px;">Consider if P=
oint had operator+=3D()</span></div><div><span style=3D"font-size: 13px;"><=
br></span></div><div><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font colo=
r=3D"#660066"><span style=3D"color: #606;" class=3D"styled-by-prettify">Poi=
nt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">+=3D(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Point</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">p</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"> x </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">+=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> p</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">x</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> y </span><span style=3D"color: #660;" class=3D"styled-by-prettify">+=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">y</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: #008;" class=
=3D"styled-by-prettify">return</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: #008;" class=3D"styled-by-prettify=
">this</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">}</span></font><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code>=
</div><div style=3D"font-size: 13px;"><br></div><div style=3D"font-size: 13=
px;">The following code would not compile:</div><div style=3D"font-size: 13=
px;"><br></div><div><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-w=
ord;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">test</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">point </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">+=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Point</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>5</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">6</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span></div></code></div><br>Whe=
reas, with a real property, the get and set methods of the property could b=
e called to retrieve and store the value.</div></div><div><br></div><div>No=
w, a partial solution may be to include commonly used operators inside the =
property class:</div><div><br></div><div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">templ=
ate</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</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"> U</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>property </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">+=3D(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">U </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">u</span><span style=3D"color: #660;" clas=
s=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"><b=
r>&nbsp; &nbsp; T tmp </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">object</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;*</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)();</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; tmp </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">+=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> u</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><font color=3D"#000000"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &nbsp; </span></font=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">object</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-&gt;*</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">set</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">forward</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">tmp</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><font color=
=3D"#000000"><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbs=
p; &nbsp; </span></font><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">return</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: #008;" class=3D"styled-by-prettify">this</span><spa=
n 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"c=
olor: #660;" class=3D"styled-by-prettify">}</span></div></code></div><div><=
br></div></div><div>And since this is a template, I'm pretty sure(vs2012 an=
d mingw tested) it should be ignored for classes that don't have an operato=
r+=3D unless you actually try to use it, but that doesn't fix the problem t=
hat you still have to include every operator manually into your property cl=
ass.</div><div><br></div><div>If you started to use a class that had a ToSt=
ring() method, now you would need to incorporate that into your property to=
o, and the list would go on endlessly.</div><div><br></div><div>4)&nbsp;<sp=
an style=3D"font-size: 13px;">Finally if something like offsetof() was stan=
dardized to work on non-POD types, there would be a way to get rid of that =
last 4 bytes per property, but currently, it is not. And I say "something l=
ike" because assuming that offsetof() did work, it would still require macr=
os to get the job done. A real piece of builtin compiler magic would still =
be needed to get a pointer to the enclosing instance of an object.</span></=
div><div><br></div><div><br></div><div>Now, this is just the begining, but =
I'm sure I could go on for a few more hours at least.</div><div><br></div><=
/div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_819_7158214.1377729018440--

.
