Topic: Properties


Author: adi.hodos@gmail.com
Date: Tue, 27 Nov 2012 03:37:22 -0800 (PST)
Raw View
------=_Part_818_19792976.1354016242893
Content-Type: text/plain; charset=ISO-8859-1

It's really a shame that C++ does not have properties. They would improve
readability, reduce verbosity and increase encapsulation. I know of one
compiler that supports them as an extension :
http://msdn.microsoft.com/en-us/library/yhfk0thd%28v=vs.110%29.aspx .
Besides this document, isn't there any effort towards getting them into the
language ?

On Monday, November 5, 2012 4:46:15 PM UTC+2, Olaf van der Spek wrote:
>
> Does a proposal exist to add properties to C++? C# (and others) have them
> and they seem very useful. The access syntax is as simple as possible and
> cleaner than get and set functions. Migrating from public members to
> properties is simple as they share the same syntax.
> Implementation seems simple, but I can't remember seeing a proposal for it.
>

--




------=_Part_818_19792976.1354016242893
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

It's really a shame that C++ does not have properties. They would improve r=
eadability, reduce verbosity and increase encapsulation. I know of one comp=
iler that supports them as an extension : http://msdn.microsoft.com/en-us/l=
ibrary/yhfk0thd%28v=3Dvs.110%29.aspx . Besides this document, isn't there a=
ny effort towards getting them into the language ?<br><br>On Monday, Novemb=
er 5, 2012 4:46:15 PM UTC+2, Olaf van der Spek wrote:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;">Does a proposal exist to add properties to C++? C# (=
and others) have them and they seem very useful. The access syntax is as si=
mple as possible and cleaner than get and set functions. Migrating from pub=
lic members to properties is simple as they share the same syntax.<div>Impl=
ementation seems simple, but I can't remember seeing a proposal for it.</di=
v></blockquote>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_818_19792976.1354016242893--

.


Author: Sebastian Gesemann <s.gesemann@gmail.com>
Date: Tue, 27 Nov 2012 14:27:04 +0100
Raw View
On Tue, Nov 27, 2012 at 12:37 PM,  <adi.hodos@gmail.com> wrote:
> It's really a shame that C++ does not have properties. They would improve
> readability, reduce verbosity and increase encapsulation. I know of one
> compiler that supports them as an extension :
> http://msdn.microsoft.com/en-us/library/yhfk0thd%28v=vs.110%29.aspx .
> Besides this document, isn't there any effort towards getting them into the
> language ?

Is there really that much bang for the buck? The only nice thing about
such a feature is that one can later alter a class and turn a public
data member into a property without having to change all the data
member accesses. But is this really a problem? I mean, does this
situation come up often enough that it warrants this feature?

Also, how does it interact with template argument deduction and
references? For example, I can imagine that this won't work:

  SomeClass object;
  object.prop1 = 17;
  object.prop2 = 29;
  std::swap(object.prop1, object.prop2);
  auto mptr = &SomeClass::prop1;
  (object.*mptr) = 99;

I'm not sure about whether introducing a new kind of "pseudo
expression" is really worth the hassle.

Cheers!
SG

--




.


Author: adi.hodos@gmail.com
Date: Tue, 27 Nov 2012 07:51:28 -0800 (PST)
Raw View
------=_Part_968_5697954.1354031488860
Content-Type: text/plain; charset=ISO-8859-1

Yes, they would certainly enhance readability. More important, they would
lessen the verbosity of the client code (something that C++ has plenty,
unfortunately).

Since a property is only "a view" into some part of class, the code you
posted does not make any sense.
A property may or may not be backed by a data member (it could simply be a
function call that computes a result based on the values of data members in
the class).

This is largely based on code that I'm writing :

//
// How we do it now
class vector3FNP {
private :
    float x;
    float y;
    float z;

public :

    void set_x(float val) { x = val; }

    float get_x() const { return x; }

    void set_y(float val) { y = val; }

    float get_y() const { return y; }

    void set_z(float val) { z = val; }

    float get_z() const { return z; }
};



Say we have a 3rd party library and all of its functions need the
individual components of vectors to do computations on them :
float compute_distance(float x0, float y0, float z0, float x1, float y1,
float z1

Then our client code looks like this :

vector3FNP v0;
vector3FNP v1;

compute_distance(v0.get_x(), v0.get_y(), v0.get_z(), v1.get_x(), v1.get_y(),v1
..get_z());


Now let's pretend we have a compiler that supports properties. The class
definition, is a bit more verbose :

class vector3FWP {
private :
    float x;
    float y;
    float z;

private :

    void set_x(float val) { x = val; }

    float get_x() const { return x; }

    void set_y(float val) { y = val; }

    float get_y() const { return y; }

    void set_z(float val) { z = val; }

    float get_z() const { return z; }

public :

    property X { get = get_x, set = set_x };

    property Y { get = get_y, set = set_y };

    property Z { get = get_z, set = set_z };
};

but the client code looks much better :

vector3FWP v0;
vector3FWP v1;

compute_distance(v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z);

I would certainly prefer the second version any time, even if the
definition of the class is a bit more verbose.
I prefer to type more now, if it means to type less later.

On Tuesday, November 27, 2012 3:27:07 PM UTC+2, Sebastian Gesemann wrote:
>
> On Tue, Nov 27, 2012 at 12:37 PM,  <adi....@gmail.com <javascript:>>
> wrote:
> > It's really a shame that C++ does not have properties. They would
> improve
> > readability, reduce verbosity and increase encapsulation. I know of one
> > compiler that supports them as an extension :
> > http://msdn.microsoft.com/en-us/library/yhfk0thd%28v=vs.110%29.aspx .
> > Besides this document, isn't there any effort towards getting them into
> the
> > language ?
>
> Is there really that much bang for the buck? The only nice thing about
> such a feature is that one can later alter a class and turn a public
> data member into a property without having to change all the data
> member accesses. But is this really a problem? I mean, does this
> situation come up often enough that it warrants this feature?
>
> Also, how does it interact with template argument deduction and
> references? For example, I can imagine that this won't work:
>
>   SomeClass object;
>   object.prop1 = 17;
>   object.prop2 = 29;
>   std::swap(object.prop1, object.prop2);
>   auto mptr = &SomeClass::prop1;
>   (object.*mptr) = 99;
>
> I'm not sure about whether introducing a new kind of "pseudo
> expression" is really worth the hassle.
>
> Cheers!
> SG
>

--




------=_Part_968_5697954.1354031488860
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Yes, they would certainly enhance readability. More important, they would l=
essen the verbosity of the client code (something that C++ has plenty, unfo=
rtunately).<br><br>Since a property is only "a view" into some part of clas=
s, the code you posted does not make any sense.<br>A property may or may no=
t be backed by a data member (it could simply be a function call that compu=
tes a result based on the values of data members in the class).<br><br>This=
 is largely based on code that I'm writing :<br><br><div class=3D"prettypri=
nt" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 1=
87, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">//</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">// How we do it now</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"> vector3FNP </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: #008;" class=3D"styled-by=
-prettify">private</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">fl=
oat</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">float</span><spa=
n 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"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">public</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>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> set_x</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">float=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> val</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> x </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> val</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><br>&nbsp; =
&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">flo=
at</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> get_x</=
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: #008;" class=3D"styled-by-prettify">const</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: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> set_y</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> val</span><span style=3D"color: #66=
0;" 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"> y </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> val</s=
pan><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 style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> get_y</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"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"> y</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: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> set_z</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">float</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> val</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: #660;" class=3D"styled-by-prettify">{</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> z </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> val</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: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">float</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> get_z</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: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an 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">return</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </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">};</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br></s=
pan></div></code></div><br>Say we have a 3rd party library and all of its f=
unctions need the individual components of vectors to do computations on th=
em :<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"sub=
prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">floa=
t</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> compute_=
distance</span><span style=3D"color: #660;" 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"> x0</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: #0=
08;" class=3D"styled-by-prettify">float</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> y0</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">float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> z0</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">float</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x1</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: #008;" class=
=3D"styled-by-prettify">float</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> y1</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: #008;" class=3D"styled-by-prettify">float<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z1<br></sp=
an></div></code></div><br>Then our client code looks like this :<br><br><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er-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-prettify">vector3FNP v0</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>vector3FNP v1</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>compute_distanc=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">v0</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">get_x</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> v0</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">get_y</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(),</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 v0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">get_z</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(),</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> v1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">get_x</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> v1</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">get_y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> v1</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">get_z</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">());</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span></div></code></div>=
<br>Now let's pretend we have a compiler that supports properties. The clas=
s definition, is a bit more verbose :<br><br><div class=3D"prettyprint" sty=
le=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187=
); border-style: solid; border-width: 1px; word-wrap: break-word;"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> vector3FWP </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"style=
d-by-prettify">private</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </=
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 st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> z</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><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">private</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><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> set_x</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">f=
loat</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> val</=
span><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"> x </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> val</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&=
nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> g=
et_x</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: #008;" class=3D"styled-by-prettify">const</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: #008;" class=3D"=
styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</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>&nbsp; &nbs=
p; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> set_y</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> val</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 style=3D"color: #000;" class=3D"styled-by=
-prettify"> y </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> va=
l</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> get_y</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;" cla=
ss=3D"styled-by-prettify">const</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"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</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 styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> set_z</span><span style=3D"color: #660=
;" 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"s=
tyled-by-prettify"> val</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> z </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> val</span><span style=3D"co=
lor: #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><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">float</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> get_z</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: #008;" class=3D"styled-by-prettif=
y">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/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: #008;" class=3D"styled-by-prettify">return</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> z</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: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">public</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>&nbsp; &=
nbsp; property X </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">get</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> get_x</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">set</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> set=
_x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; =
&nbsp; property Y </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">get</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> get_y</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">set</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> se=
t_y </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp;=
 &nbsp; property Z </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: #008;" class=3D"styled-by-prettify">get</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> get_z</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: #008;" class=3D=
"styled-by-prettify">set</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
et_z </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></div></co=
de></div><br>but the client code looks much better :<br><br><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">vector3FWP v0</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>vector3FWP v1</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>compute_distance</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">v0</span><span style=3D"colo=
r: #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">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> v0</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">Y</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> v0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">Z</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> v1</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">X</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> v1</span><spa=
n 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"> v1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">Z</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></div></code></div><br>I would certainly prefer the second version=
 any time, even if the definition of the class is a bit more verbose.<br>I =
prefer to type more now, if it means to type less later.<br><br>On Tuesday,=
 November 27, 2012 3:27:07 PM UTC+2, Sebastian Gesemann wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
 #ccc solid;padding-left: 1ex;">On Tue, Nov 27, 2012 at 12:37 PM, &nbsp;&lt=
;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"UDl3R6t=
3cWMJ">adi....@gmail.com</a>&gt; wrote:
<br>&gt; It's really a shame that C++ does not have properties. They would =
improve
<br>&gt; readability, reduce verbosity and increase encapsulation. I know o=
f one
<br>&gt; compiler that supports them as an extension :
<br>&gt; <a href=3D"http://msdn.microsoft.com/en-us/library/yhfk0thd%28v=3D=
vs.110%29.aspx" target=3D"_blank">http://msdn.microsoft.com/en-<wbr>us/libr=
ary/yhfk0thd%28v=3Dvs.<wbr>110%29.aspx</a> .
<br>&gt; Besides this document, isn't there any effort towards getting them=
 into the
<br>&gt; language ?
<br>
<br>Is there really that much bang for the buck? The only nice thing about
<br>such a feature is that one can later alter a class and turn a public
<br>data member into a property without having to change all the data
<br>member accesses. But is this really a problem? I mean, does this
<br>situation come up often enough that it warrants this feature?
<br>
<br>Also, how does it interact with template argument deduction and
<br>references? For example, I can imagine that this won't work:
<br>
<br>&nbsp; SomeClass object;
<br>&nbsp; object.prop1 =3D 17;
<br>&nbsp; object.prop2 =3D 29;
<br>&nbsp; std::swap(object.prop1, object.prop2);
<br>&nbsp; auto mptr =3D &amp;SomeClass::prop1;
<br>&nbsp; (object.*mptr) =3D 99;
<br>
<br>I'm not sure about whether introducing a new kind of "pseudo
<br>expression" is really worth the hassle.
<br>
<br>Cheers!
<br>SG
<br></blockquote>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_968_5697954.1354031488860--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 27 Nov 2012 18:06:51 +0200
Raw View
On 27 November 2012 17:51,  <adi.hodos@gmail.com> wrote:
> but the client code looks much better :
> vector3FWP v0;
> vector3FWP v1;
> compute_distance(v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z);
> I would certainly prefer the second version any time, even if the definition
> of the class is a bit more verbose.
> I prefer to type more now, if it means to type less later.

I can get the same effect with public data members. And if I want to
hook some functionality
into the member accesses, I can use a wrapper type that does so. I
believe we need a more
convincing example.

Also keep in mind that reflection may bring forth functionality that
can realize properties,
we want to be in sync with that work, although we don't want to put
our every egg in the
reflection basket either.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Tue, 27 Nov 2012 17:18:09 +0100
Raw View
On Tue, Nov 27, 2012 at 5:06 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> I can get the same effect with public data members. And if I want to
> hook some functionality
> into the member accesses, I can use a wrapper type that does so. I

What wrapper type? C++ (and Boost) don't provide one AFAIK.

> believe we need a more
> convincing example.

True, the example should probably have public data members.
But often you want public const private mutable data members and
properties allow you to have them.

> Also keep in mind that reflection may bring forth functionality that
> can realize properties,
> we want to be in sync with that work, although we don't want to put
> our every egg in the
> reflection basket either.

How are properties related to reflection?

--
Olaf

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 27 Nov 2012 19:06:09 +0200
Raw View
On 27 November 2012 18:18, Olaf van der Spek <olafvdspek@gmail.com> wrote:
> On Tue, Nov 27, 2012 at 5:06 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>> I can get the same effect with public data members. And if I want to
>> hook some functionality
>> into the member accesses, I can use a wrapper type that does so. I
> What wrapper type? C++ (and Boost) don't provide one AFAIK.

Currently I write them myself. It's rather custom functionality to decide
what to do, for properties not backed by members, for properties
doing some kind of processing etc., so it's a bit hard to generalize.
What I can do is write a generic skeleton property that has conversion
operations readily declared.

> How are properties related to reflection?

They seem to try and solve similar problems. Compile-time reflection is
expected to provide access to members by name, and to allow programmers
to customize how a given member gets accessed, or to allow accessing
names not backed by actual members. Or, well, that's on my wishlist,
and some people I've discussed reflection with seem to agree.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Tue, 27 Nov 2012 18:21:21 +0100
Raw View
On Tue, Nov 27, 2012 at 6:06 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 27 November 2012 18:18, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>> On Tue, Nov 27, 2012 at 5:06 PM, Ville Voutilainen
>> <ville.voutilainen@gmail.com> wrote:
>>> I can get the same effect with public data members. And if I want to
>>> hook some functionality
>>> into the member accesses, I can use a wrapper type that does so. I
>> What wrapper type? C++ (and Boost) don't provide one AFAIK.
>
> Currently I write them myself. It's rather custom functionality to decide
> what to do, for properties not backed by members, for properties
> doing some kind of processing etc., so it's a bit hard to generalize.

Isn't that an argument for proper properties support?

> What I can do is write a generic skeleton property that has conversion
> operations readily declared.
>
>> How are properties related to reflection?
>
> They seem to try and solve similar problems. Compile-time reflection is
> expected to provide access to members by name, and to allow programmers
> to customize how a given member gets accessed, or to allow accessing
> names not backed by actual members. Or, well, that's on my wishlist,
> and some people I've discussed reflection with seem to agree.

Properties and reflection might have some overlap, but it's not clear
to me how they're similar problems.


--
Olaf

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 27 Nov 2012 19:30:30 +0200
Raw View
On 27 November 2012 19:21, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>> What wrapper type? C++ (and Boost) don't provide one AFAIK.
>> Currently I write them myself. It's rather custom functionality to decide
> Isn't that an argument for proper properties support?

Sure. The question is how often you really need such wrapper types, and how much
properties really help.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Tue, 27 Nov 2012 18:41:26 +0100
Raw View
On Tue, Nov 27, 2012 at 6:30 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 27 November 2012 19:21, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>> What wrapper type? C++ (and Boost) don't provide one AFAIK.
>>> Currently I write them myself. It's rather custom functionality to decide
>> Isn't that an argument for proper properties support?
>
> Sure. The question is how often you really need such wrapper types,

Very often

> and how much
> properties really help.

Eh, what do you mean? The advantages of properties are clear, aren't they?
The only question is how to best implement them.

Take containers for example. "if (s.size >= 8)" looks a bit cleaner
than "if (s.size() >= 8)".

--
Olaf

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 27 Nov 2012 19:51:18 +0200
Raw View
On 27 November 2012 19:41, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>>>> What wrapper type? C++ (and Boost) don't provide one AFAIK.
>>>> Currently I write them myself. It's rather custom functionality to decide
>>> Isn't that an argument for proper properties support?
>> Sure. The question is how often you really need such wrapper types,
> Very often

I'm not sure I share that experience. I'd say "surprisingly rarely". :)

>> and how much
>> properties really help.
> Eh, what do you mean? The advantages of properties are clear, aren't they?
> The only question is how to best implement them.
> Take containers for example. "if (s.size >= 8)" looks a bit cleaner
> than "if (s.size() >= 8)".

I don't find that difference significant. And regarding the advantages, when I
consider writing a normal member function vs. writing a property function (if I
need more complex processing than just accessing a member), it's even less
clear to me.

I'm very interested in seeing a proposal for properties, but I'm not
sure I'm convinced
they are a big improvement, overall. If some reflection facilities can
assist people
who want properties, the more the merrier. If properties are added as
a stand-alone
facility, I have my doubts.

--




.


Author: adi.hodos@gmail.com
Date: Tue, 27 Nov 2012 11:26:31 -0800 (PST)
Raw View
------=_Part_3_9047604.1354044391771
Content-Type: text/plain; charset=ISO-8859-1

Why should the members be public ? What if our vector is implemented like
this, to support SSE :


#include <cstdio>

class vector3F {
private :
    float vecdata_[4];

public :

} __attribute__((align(16)));


Now what ? Should I make use of the ugly structure plus array in a union
trick ? I'm now exposing the guts of the class to the user, and opening the
door to misuse. Not to mention the potential confusion of new users when
faced with something like this :

class vector3F {
private :
    union {
        float vecdata_[4]; // Why 4 elements ? Should I use the array or X,
Y, Z ??
        struct {
            float W; // What's this doing in a vector3 ??
            float Z;
            float Y;
            float X;
        };
    };

public :

} __attribute__((align(16)));



Olaf, you can implement properties via templates plus some macros. It's
described in Matthew Wilson's Imperfect C++, section 35 if I remember
exactly. My approach is mostly based on code in that book. But it's not
pretty.

--




------=_Part_3_9047604.1354044391771
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Why should the members be public ? What if our vector is implemented like t=
his, to support SSE :<br><br><br><div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D=
"styled-by-prettify">#include</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">&lt;cstdio&gt;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> vector3F </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></span><span style=3D"color: #008;" class=3D"styled-by-prettify">private<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> vecdata_</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"col=
or: #066;" class=3D"styled-by-prettify">4</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">public</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: #660;" class=3D"styled-by-prettify">=
}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __attrib=
ute__</span><span style=3D"color: #660;" class=3D"styled-by-prettify">((</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">align</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">16</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)));</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br></span></div></code></div><br>Now=
 what ? Should I make use of the ugly structure plus array in a union trick=
 ? I'm now exposing the guts of the class to the user, and opening the door=
 to misuse. Not to mention the potential confusion of new users when faced =
with something like this :<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: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> vector3F </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">private</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>&nbsp; &nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">union</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>&nbsp; &nbsp; &nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">float</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> vecdata_</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span st=
yle=3D"color: #066;" class=3D"styled-by-prettify">4</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">];</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// Why 4 elements ? Should I use the array or X, Y,=
 Z ??</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">struct</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>&=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">float</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> W</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
// What's this doing in a vector3 ??</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">float</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>&nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; </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">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">float</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"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">public</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><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> __attribute__</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">((</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">align</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">16</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)));</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span></div></code></div><br><br>Olaf, you can impl=
ement properties via templates plus some macros. It's described in Matthew =
Wilson's Imperfect C++, section 35 if I remember exactly. My approach is mo=
stly based on code in that book. But it's not pretty.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_3_9047604.1354044391771--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 27 Nov 2012 21:33:01 +0200
Raw View
On 27 November 2012 21:26,  <adi.hodos@gmail.com> wrote:
> Why should the members be public ? What if our vector is implemented like
> this, to support SSE :
> #include <cstdio>
> class vector3F {
> private :
>     float vecdata_[4];
>
> public :
>
> } __attribute__((align(16)));
> Now what ? Should I make use of the ugly structure plus array in a union

Let's assume you have properties. Now what? What does the property
look like? What will
it return?

> trick ? I'm now exposing the guts of the class to the user, and opening the
> door to misuse. Not to mention the potential confusion of new users when

What misuse? Can you please explain how vecdata can be misused?

--




.


Author: adi.hodos@gmail.com
Date: Tue, 27 Nov 2012 12:33:06 -0800 (PST)
Raw View
------=_Part_278_750102.1354048386460
Content-Type: text/plain; charset=ISO-8859-1


It would return the value of the component. What else could it return (in
this case) ?

class vector3F {
private :
    union {
        float vecdata_[4];
    };

    float get_x() const {
        return x_;
    }

    void set_x(float val) {
        vecdata_[0] = val;
    }

public :

    property X { get = get_x, set = set_x };

} __attribute__((align(16)));


It's just syntactic sugar, allowing the client to simply write v.X instead
of v.get_x() . Much more readable. and concise.
The misuse part : the class is exposing to the client its internals. The
fact that there's an array of four floats is an implementation detail. It
is needed because of that way SSE instructions work. For a three component
vector, the W/vecdata_[3] member must always be set to zero, since it has
no meaning. But since it's available in the public interface, its all too
easy to write v.W = 2.0f without even thinking.
So one must choose between :
- the ugliness and verbosity of get_xxx()/set_xx() but you get
safety/encapsulation
- public members that break encapsulation and are open to abuse but then
you get ease of use and readability.
Why can't I have both ?

--




------=_Part_278_750102.1354048386460
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br>It would return the value of the component. What else could it return (=
in this case) ? <br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> vector3F </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></span><span style=3D"color: #008;" class=3D"styled-by-prettify">private<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">union</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> vecdata_</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">4</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: #660=
;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> get_x</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;" cla=
ss=3D"styled-by-prettify">const</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>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</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"styled-by-prett=
ify"><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> set_x</span><span style=3D"color: #660;" 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-pret=
tify"> val</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"><br>&nbsp; &nbsp; &nbsp; &n=
bsp; vecdata_</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">]</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> val</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: #660;" c=
lass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">public</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>&=
nbsp; &nbsp; <br>&nbsp; &nbsp; property X </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"style=
d-by-prettify">get</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> get_x<=
/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: #008;" class=3D"styled-by-prettify">set</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> set_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: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> __attribute__</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">((</span><span style=3D"color: #000;" class=3D"styled-by-prettify">al=
ign</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">16</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)));</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br></span></div></c=
ode></div>It's just syntactic sugar, allowing the client to simply write v.=
X instead of v.get_x() . Much more readable. and concise.<br>The misuse par=
t : the class is exposing to the client its internals. The fact that there'=
s an array of four floats is an implementation detail. It is needed because=
 of that way SSE instructions work. For a three component vector, the W/vec=
data_[3] member must always be set to zero, since it has no meaning. But si=
nce it's available in the public interface, its all too easy to write v.W =
=3D 2.0f without even thinking.<br>So one must choose between :<br>- the ug=
liness and verbosity of get_xxx()/set_xx() but you get safety/encapsulation=
<br>- public members that break encapsulation and are open to abuse but the=
n you get ease of use and readability.<br>Why can't I have both ?<br><br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_278_750102.1354048386460--

.


Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Tue, 27 Nov 2012 21:39:52 +0100
Raw View
--f46d042f9d0e83606f04cf800ecc
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Nov 27, 2012 at 9:33 PM, <adi.hodos@gmail.com> wrote:

> So one must choose between :
> - the ugliness and verbosity of get_xxx()/set_xx() but you get
> safety/encapsulation
>
>
Except this one is on the eye of the beholder. Personally, I don't think
`xxx()` is much more verbose than `xxx`.

Martinho

--




--f46d042f9d0e83606f04cf800ecc
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><div class=3D"gmail_quote">On Tue, Nov 27, 2012 at 9:33 PM,  <span dir=
=3D"ltr">&lt;<a href=3D"mailto:adi.hodos@gmail.com" target=3D"_blank">adi.h=
odos@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

So one must choose between :<br>- the ugliness and verbosity of get_xxx()/s=
et_xx() but you get safety/encapsulation<br><span class=3D"HOEnZb"><font co=
lor=3D"#888888"><br></font></span></blockquote><div><br>Except this one is =
on the eye of the beholder. Personally, I don&#39;t think `xxx()` is much m=
ore verbose than `xxx`.<br>

</div></div><br clear=3D"all">Martinho<br>
<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--f46d042f9d0e83606f04cf800ecc--

.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 13:21:17 -0800 (PST)
Raw View
------=_Part_111_19409953.1354051277646
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 3:39:52 PM UTC-5, R. Martinho Fernandes wrote:
>
> Except this one is on the eye of the beholder. Personally, I don't think
> `xxx()` is much more verbose than `xxx`.
>

It doesn't get significantly more verbose until you have a setter and a
getter in a pair. Let's say you have a class like this:

class TrackedVector
{
  public:
    float get_x() const { return x; }
    float get_y() const { return y; }
    float get_z() const { return z; }

    void set_x(float f); { x = f; dirty = true; }
    void set_y(float f); { x = f; dirty = true; }
    void set_z(float f); { x = f; dirty = true; }

    bool is_dirty() const { return dirty; }
    void mark_clean() { dirty = false; }

  private:
    float x, y, z;
    bool dirty;
};

Now, in C++, to find the magnitude of a vector, you have to write:

magnitude = sqrt(v.get_x()*v.get_x() + v.get_y()*v.get_y() +
v.get_z()*v.get_z());

Whereas in a language with properties, you can simply write:

magnitude = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);

That's not only significantly less verbose, but significantly easier to
read.

Now, an argument that always comes up is "But how will I know I'm calling a
function!" Of course, we've all heard this argument before with regard to
overloaded operators, or really any new abstraction, so it's worth taking
with a grain of salt. And the secret is, C++ *can* support the simpler
syntax, at a price:

class TrackedVector
{
  public:
    TrackedVector() : x(*this), y(*this), z(*this) {}

    class Property
    {
      public:
        float operator=(float val) { this->val = val; parent.dirty = true; }
        operator float() const { return val; }

        // Comparison operators, etc...

      private:
        float val;
        TrackedVector& parent;

        Property(TrackedVector& parent) : parent(parent) {}
        friend class TrackedVector;
    } x, y, z;

    bool is_dirty() const { return dirty; }
    void mark_clean() { dirty = false; }

  private:
    bool dirty;

    friend class Property;
};

So, it's already possible to have hidden function calls, but it adds a lot
of boilerplate, and nearly doubles the memory requirements -- triples them
on 64-bit machines.

--




------=_Part_111_19409953.1354051277646
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 3:39:52 PM UTC-5, R. Martinho Fernandes wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div>Except this one is on th=
e eye of the beholder. Personally, I don't think `xxx()` is much more verbo=
se than `xxx`.<br></div></blockquote><div><br>It doesn't get significantly =
more verbose until you have a setter and a getter in a pair. Let's say you =
have a class like this:<br><br><span style=3D"font-family: courier new,mono=
space;">class TrackedVector<br>{<br>&nbsp; public:<br>&nbsp;&nbsp;&nbsp; fl=
oat get_x() const { return x; }<br>&nbsp;&nbsp;&nbsp; float get_y() const {=
 return y; }<br>&nbsp;&nbsp;&nbsp; float get_z() const { return z; }<br><br=
>&nbsp;&nbsp;&nbsp; void set_x(float f); { x =3D f; dirty =3D true; }<br>&n=
bsp;&nbsp;&nbsp; void set_y(float f); { x =3D f; dirty =3D true; }<br>&nbsp=
;&nbsp;&nbsp; void set_z(float f); { x =3D f; dirty =3D true; }<br><br>&nbs=
p;&nbsp;&nbsp; bool is_dirty() const { return dirty; }<br>&nbsp;&nbsp;&nbsp=
; void mark_clean() { dirty =3D false; }<br><br>&nbsp; private:<br>&nbsp;&n=
bsp;&nbsp; float x, y, z;<br>&nbsp;&nbsp;&nbsp; bool dirty;<br>};</span><br=
><br>Now, in C++, to find the magnitude of a vector, you have to write:<br>=
<br><span style=3D"font-family: courier new,monospace;">magnitude =3D sqrt(=
v.get_x()*v.get_x() + v.get_y()*v.get_y() + v.get_z()*v.get_z());</span><br=
><br>Whereas in a language with properties, you can simply write:<br><br><s=
pan style=3D"font-family: courier new,monospace;">magnitude =3D sqrt(v.x*v.=
x + v.y*v.y + v.z*v.z);</span><br><br>That's not only significantly less ve=
rbose, but significantly easier to read.<br><br>Now, an argument that alway=
s comes up is "But how will I know I'm calling a function!" Of course, we'v=
e all heard this argument before with regard to overloaded operators, or re=
ally any new abstraction, so it's worth taking with a grain of salt. And th=
e secret is, C++ <i>can</i> support the simpler syntax, at a price:<br><br>=
<span style=3D"font-family: courier new,monospace;">class TrackedVector<br>=
{<br>&nbsp; public:<br>&nbsp;&nbsp;&nbsp; TrackedVector() : x(*this), y(*th=
is), z(*this) {}<br><br>&nbsp;&nbsp;&nbsp; class Property<br>&nbsp;&nbsp;&n=
bsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public:<br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; float operator=3D(float val) { this-&gt;val =3D val; pa=
rent.dirty =3D true; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operat=
or float() const { return val; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; // Comparison operators, etc...<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; private:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float val;<br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TrackedVector&amp; parent;<br><br>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property(TrackedVector&amp; paren=
t) : parent(parent) {}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; friend=
 class TrackedVector;<br>&nbsp;&nbsp;&nbsp; } x, y, z;<br><br>&nbsp;&nbsp;&=
nbsp; bool is_dirty() const { return dirty; }<br>&nbsp;&nbsp;&nbsp; void ma=
rk_clean() { dirty =3D false; }<br><br>&nbsp; private:<br>&nbsp;&nbsp;&nbsp=
; bool dirty;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; friend class Pro=
perty;<br>};</span><br><br>So, it's already possible to have hidden functio=
n calls, but it adds a lot of boilerplate, and nearly doubles the memory re=
quirements -- triples them on 64-bit machines.<br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_111_19409953.1354051277646--

.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Tue, 27 Nov 2012 22:28:21 +0100
Raw View
On Tue, Nov 27, 2012 at 10:21 PM,  <rick@longbowgames.com> wrote:
> magnitude = sqrt(v.get_x()*v.get_x() + v.get_y()*v.get_y() +
> v.get_z()*v.get_z());
>
> Whereas in a language with properties, you can simply write:
>
> magnitude = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);

I'm not sure that's entirely fair.
You could use x() instead of get_x().
For setters I'd still use set_x().

> So, it's already possible to have hidden function calls, but it adds a lot
> of boilerplate, and nearly doubles the memory requirements -- triples them
> on 64-bit machines.

What's the dirty flag for?

Don't forget the other advantage of properties: being able to move
from public data members to properties without changing client syntax.



--
Olaf

--




.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 13:53:46 -0800 (PST)
Raw View
------=_Part_336_14383853.1354053226665
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 4:28:21 PM UTC-5, Olaf van der Spek wrote:
>
> I'm not sure that's entirely fair.
> You could use x() instead of get_x().
> For setters I'd still use set_x().
>

That's true, but people tend not to do that because programmers hate
asymmetry :)

What's the dirty flag for?
>

Just to check if the object has changed since the last time you checked it.
I work in the game industry, and it's a fairly common pattern to step
through a list of objects once per frame to see if anything has triggered
an update. This is obviously a very simplified example.

Don't forget the other advantage of properties: being able to move
> from public data members to properties without changing client syntax.
>

 Very true! In the example I gave before, it's very likely that the class
would have evolved from a traditional vector with nothing but three public
floats.

--




------=_Part_336_14383853.1354053226665
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 4:28:21 PM UTC-5, Olaf van der Spek wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;">I'm not sure that's entirely fair=
..
<br>You could use x() instead of get_x().
<br>For setters I'd still use set_x().
<br></blockquote><div><br>That's true, but people tend not to do that becau=
se programmers hate asymmetry :) <br><br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;">What's the dirty flag for?
<br></blockquote><div><br>Just to check if the object has changed since the=
 last time you checked it. I work in the game industry, and it's a fairly c=
ommon pattern to step through a list of objects once per frame to see if an=
ything has triggered an update. This is obviously a very simplified example=
.. <br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Don't forget t=
he other advantage of properties: being able to move
<br>from public data members to properties without changing client syntax.
<br></blockquote><div><br>&nbsp;Very true! In the example I gave before, it=
's very likely that the class would have evolved from a traditional vector =
with nothing but three public floats.<br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_336_14383853.1354053226665--

.


Author: masse.nicolas@gmail.com
Date: Tue, 27 Nov 2012 14:43:43 -0800 (PST)
Raw View
------=_Part_209_6016766.1354056223807
Content-Type: text/plain; charset=ISO-8859-1

In fact, with C++11, you could already do better.
Here a quick exemple I've just written :

#include <iostream>
#include <functional>

template<typename T>
struct property
{
   typedef std::function<T(void)> getter;
   typedef std::function<void(const T&)> setter;
   getter m_getter;
   setter m_setter;

   operator T () { return m_getter(); }
   void operator= (const T& value) { m_setter(value); }
};

class Price
{
   float m_unitPrice;
   float m_vat;
public:
   property<float> UnitPrice;
   property<float> VAT;
   property<float> PriceTTC;

Price()
{
   UnitPrice = {
      [&]() { return m_unitPrice; },
      [&](float value) { m_unitPrice = value; },
   };
   VAT = {
      [&]() { return m_vat; },
      [&](float value) { m_vat = value; },
   };
   PriceTTC = {
      [&]() { return (1+ m_vat/100) * m_unitPrice; }
   };
}
};

int main()
{
   Price X;
   X.UnitPrice = 5.0;
   X.VAT = 5.0;
   std::cout << X.PriceTTC;
   return 0;
}

It does work, and once the property class have been declared, rest of the
code is easy to wrote.
But as you already pointed out, such an approach will consume a lot of
memory (3 more member, with 2 std::func each in my example, not speaking
about the lambda funcs), so I'm still looking for a better solution, and I
think i would require a change to the language, but I'm not 100% sure of
that yet.


On Tuesday, November 27, 2012 10:21:17 PM UTC+1, ri...@longbowgames.com
wrote:
>
> class TrackedVector
> {
>   public:
>     TrackedVector() : x(*this), y(*this), z(*this) {}
>
>     class Property
>     {
>       public:
>         float operator=(float val) { this->val = val; parent.dirty = true;
> }
>         operator float() const { return val; }
>
>         // Comparison operators, etc...
>
>       private:
>         float val;
>         TrackedVector& parent;
>
>         Property(TrackedVector& parent) : parent(parent) {}
>         friend class TrackedVector;
>     } x, y, z;
>
>     bool is_dirty() const { return dirty; }
>     void mark_clean() { dirty = false; }
>
>   private:
>     bool dirty;
>
>     friend class Property;
> };
>
> So, it's already possible to have hidden function calls, but it adds a lot
> of boilerplate, and nearly doubles the memory requirements -- triples them
> on 64-bit machines.
>

--




------=_Part_209_6016766.1354056223807
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>In fact, with C++11, you could already do better.<br></div><div>Here a=
 quick exemple I've just written :</div><div><br></div><div>#include &lt;io=
stream&gt;<br>#include &lt;functional&gt;<br><br>template&lt;typename T&gt;=
<br>struct property<br>{<br>&nbsp; &nbsp;typedef std::function&lt;T(void)&g=
t; getter;<br> &nbsp; &nbsp;typedef std::function&lt;void(const T&amp;)&gt;=
 setter;<br> &nbsp; &nbsp;getter m_getter;<br> &nbsp; &nbsp;setter m_setter=
;<br> <br> &nbsp; &nbsp;operator T () { return m_getter(); }<br> &nbsp; &nb=
sp;void operator=3D (const T&amp; value) { m_setter(value); }<br>};<br><br>=
class Price<br>{<br> &nbsp; &nbsp;float m_unitPrice;<br> &nbsp; &nbsp;float=
 m_vat;<br> public:<br> &nbsp; &nbsp;property&lt;float&gt; UnitPrice;<br> &=
nbsp; &nbsp;property&lt;float&gt; VAT;<br> &nbsp; &nbsp;property&lt;float&g=
t; PriceTTC; <br> <br> Price() <br> { <br>  &nbsp; &nbsp;UnitPrice =3D {<br=
>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_unitPrice; },<br>   &nbs=
p; &nbsp;&nbsp; &nbsp;[&amp;](float value) {  m_unitPrice =3D value; },<br>=
  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;VAT =3D {<br>   &nbsp; &nbsp;&nbsp; &nb=
sp;[&amp;]() { return m_vat; },<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](flo=
at value) { m_vat =3D value; },<br>  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;Pric=
eTTC =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return (1+ m_vat/100=
) * m_unitPrice; }<br>  &nbsp; &nbsp;};<br> }<br>};<br><br>int main()<br>{<=
br> &nbsp; &nbsp;Price X;<br> &nbsp; &nbsp;X.UnitPrice =3D 5.0;<br> &nbsp; =
&nbsp;X.VAT =3D 5.0;<br> &nbsp; &nbsp;std::cout &lt;&lt; X.PriceTTC;<br> &n=
bsp; &nbsp;return 0;<br>}</div><div><br></div><div>It does work, and once t=
he property class have been declared, rest of the code is easy to wrote.</d=
iv><div>But as you already pointed out, such an approach will consume a lot=
 of memory (3 more member, with 2 std::func each in my example, not speakin=
g about the lambda funcs), so I'm still looking for a better solution, and =
I think i would require a change to the language, but I'm not 100% sure of =
that yet.</div><div><br></div><br>On Tuesday, November 27, 2012 10:21:17 PM=
 UTC+1, ri...@longbowgames.com wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
 1ex;"><span style=3D"font-family:courier new,monospace">class TrackedVecto=
r<br>{<br>&nbsp; public:<br>&nbsp;&nbsp;&nbsp; TrackedVector() : x(*this), =
y(*this), z(*this) {}<br><br>&nbsp;&nbsp;&nbsp; class Property<br>&nbsp;&nb=
sp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public:<br>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; float operator=3D(float val) { this-&gt;val =3D va=
l; parent.dirty =3D true; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o=
perator float() const { return val; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp; // Comparison operators, etc...<br><br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; private:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float val;<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TrackedVector&amp; parent;<br>=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property(TrackedVector&amp; =
parent) : parent(parent) {}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f=
riend class TrackedVector;<br>&nbsp;&nbsp;&nbsp; } x, y, z;<br><br>&nbsp;&n=
bsp;&nbsp; bool is_dirty() const { return dirty; }<br>&nbsp;&nbsp;&nbsp; vo=
id mark_clean() { dirty =3D false; }<br><br>&nbsp; private:<br>&nbsp;&nbsp;=
&nbsp; bool dirty;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; friend clas=
s Property;<br>};</span><br><br>So, it's already possible to have hidden fu=
nction calls, but it adds a lot of boilerplate, and nearly doubles the memo=
ry requirements -- triples them on 64-bit machines.<br></blockquote>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_209_6016766.1354056223807--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 27 Nov 2012 23:53:28 +0100
Raw View
Le 27/11/12 22:28, Olaf van der Spek a =E9crit :
> On Tue, Nov 27, 2012 at 10:21 PM,  <rick@longbowgames.com> wrote:
>> magnitude =3D sqrt(v.get_x()*v.get_x() + v.get_y()*v.get_y() +
>> v.get_z()*v.get_z());
>>
>> Whereas in a language with properties, you can simply write:
>>
>> magnitude =3D sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
> I'm not sure that's entirely fair.
> You could use x() instead of get_x().
>
+1
> Don't forget the other advantage of properties: being able to move=20
> from public data members to properties without changing client syntax.=20
This is in general not exactly true as showed at the beginning of this=20
thread

Also, how does it interact with template argument deduction and
references? For example, I can imagine that this won't work:

   SomeClass object;
   object.prop1 =3D 17;
   object.prop2 =3D 29;
   std::swap(object.prop1, object.prop2);
   auto mptr =3D &SomeClass::prop1;
   (object.*mptr) =3D 99;


-- Vicente

--=20




.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 28 Nov 2012 00:02:08 +0100
Raw View
Le 27/11/12 17:18, Olaf van der Spek a =E9crit :
> On Tue, Nov 27, 2012 at 5:06 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
> True, the example should probably have public data members.
> But often you want public const private mutable data members and
> properties allow you to have them.

property_type property() const;

responds to quite well to the needs.

-- Vicente

--=20




.


Author: Andrew Sandoval <sandoval@netwaysglobal.com>
Date: Tue, 27 Nov 2012 15:22:53 -0800 (PST)
Raw View
------=_Part_1383_15162359.1354058573516
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 4:43:43 PM UTC-6, masse....@gmail.com wrote:
>
> In fact, with C++11, you could already do better.
> Here a quick exemple I've just written :
>
> #include <iostream>
> #include <functional>
>
> template<typename T>
> struct property
> {
>    typedef std::function<T(void)> getter;
>    typedef std::function<void(const T&)> setter;
>    getter m_getter;
>    setter m_setter;
>
>    operator T () { return m_getter(); }
>    void operator= (const T& value) { m_setter(value); }
> };
>
> class Price
> {
>    float m_unitPrice;
>    float m_vat;
> public:
>    property<float> UnitPrice;
>    property<float> VAT;
>    property<float> PriceTTC;
>
> Price()
> {
>    UnitPrice = {
>       [&]() { return m_unitPrice; },
>       [&](float value) { m_unitPrice = value; },
>    };
>    VAT = {
>       [&]() { return m_vat; },
>       [&](float value) { m_vat = value; },
>    };
>    PriceTTC = {
>       [&]() { return (1+ m_vat/100) * m_unitPrice; }
>    };
> }
> };
>
> int main()
> {
>    Price X;
>    X.UnitPrice = 5.0;
>    X.VAT = 5.0;
>    std::cout << X.PriceTTC;
>    return 0;
> }
>
> It does work, and once the property class have been declared, rest of the
> code is easy to wrote.
> But as you already pointed out, such an approach will consume a lot of
> memory (3 more member, with 2 std::func each in my example, not speaking
> about the lambda funcs), so I'm still looking for a better solution, and I
> think i would require a change to the language, but I'm not 100% sure of
> that yet.
>
>
> Why not simplify this down...  The following solution doesn't handle your
PriceTTC case, but that can probably be done cleverly another way -- or
better just as a function.  I don't follow other languages closely, but I
don't think their properties do that kind of thing either...  So, this
should be very light-weight w/regards to your memory (etc.) concerns, in
fact I suspect it almost entirely is optimized away in release builds:

#include <iostream>

template <typename T>
class property
{
private:
    T& m_ref;
    property();
public:
    property(T& r) : m_ref(r)
    {
    }

    const T get() const
    {
        return m_ref;
    }

    const T& operator=(const T& v)
    {
        m_ref = v;
        return m_ref;
    }

    operator T () const
    {
        return m_ref;
    }
};

class Price
{
private:
   float m_unitPrice;
   float m_vat;
public:
   property<float> UnitPrice;
   property<float> VAT;

   Price(float fup, float fvat) : m_unitPrice(fup), m_vat(fvat),
       UnitPrice(m_unitPrice),
       VAT(m_vat)
   {
   }
};

int wmain(int argc, wchar_t* argv[])
{
    Price cost(1.2f, .065f);
    std::cout << "Unit Price: " << cost.UnitPrice << std::endl;
    std::cout << "VAT: " << cost.VAT << std::endl;

    cost.UnitPrice = 2.40f;        // Inflation
    std::cout << "Unit Price" << cost.UnitPrice << std::endl;

    return 0;
}



-Andrew Sandoval

--




------=_Part_1383_15162359.1354058573516
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 4:43:43 PM UTC-6, masse....@gmail.com wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div>In fact, with C++11, you c=
ould already do better.<br></div><div>Here a quick exemple I've just writte=
n :</div><div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;func=
tional&gt;<br><br>template&lt;typename T&gt;<br>struct property<br>{<br>&nb=
sp; &nbsp;typedef std::function&lt;T(void)&gt; getter;<br> &nbsp; &nbsp;typ=
edef std::function&lt;void(const T&amp;)&gt; setter;<br> &nbsp; &nbsp;gette=
r m_getter;<br> &nbsp; &nbsp;setter m_setter;<br> <br> &nbsp; &nbsp;operato=
r T () { return m_getter(); }<br> &nbsp; &nbsp;void operator=3D (const T&am=
p; value) { m_setter(value); }<br>};<br><br>class Price<br>{<br> &nbsp; &nb=
sp;float m_unitPrice;<br> &nbsp; &nbsp;float m_vat;<br> public:<br> &nbsp; =
&nbsp;property&lt;float&gt; UnitPrice;<br> &nbsp; &nbsp;property&lt;float&g=
t; VAT;<br> &nbsp; &nbsp;property&lt;float&gt; PriceTTC; <br> <br> Price() =
<br> { <br>  &nbsp; &nbsp;UnitPrice =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[=
&amp;]() { return m_unitPrice; },<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](f=
loat value) {  m_unitPrice =3D value; },<br>  &nbsp; &nbsp;};<br>  &nbsp; &=
nbsp;VAT =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_vat; },=
<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](float value) { m_vat =3D value; },=
<br>  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;PriceTTC =3D {<br>   &nbsp; &nbsp;&=
nbsp; &nbsp;[&amp;]() { return (1+ m_vat/100) * m_unitPrice; }<br>  &nbsp; =
&nbsp;};<br> }<br>};<br><br>int main()<br>{<br> &nbsp; &nbsp;Price X;<br> &=
nbsp; &nbsp;X.UnitPrice =3D 5.0;<br> &nbsp; &nbsp;X.VAT =3D 5.0;<br> &nbsp;=
 &nbsp;std::cout &lt;&lt; X.PriceTTC;<br> &nbsp; &nbsp;return 0;<br>}</div>=
<div><br></div><div>It does work, and once the property class have been dec=
lared, rest of the code is easy to wrote.</div><div>But as you already poin=
ted out, such an approach will consume a lot of memory (3 more member, with=
 2 std::func each in my example, not speaking about the lambda funcs), so I=
'm still looking for a better solution, and I think i would require a chang=
e to the language, but I'm not 100% sure of that yet.</div><div><br></div><=
br></blockquote><div>Why not simplify this down...&nbsp; The following solu=
tion doesn't handle your PriceTTC case, but that can probably be done cleve=
rly another way -- or better just as a function.&nbsp; I don't follow other=
 languages closely, but I don't think their properties do that kind of thin=
g either...&nbsp; So, this should be very light-weight w/regards to your me=
mory (etc.) concerns, in fact I suspect it almost entirely is optimized awa=
y in release builds:<br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">#include</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;i=
ostream&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
emplate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
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><sp=
an 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"co=
lor: #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"> property<br></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: #008;" class=3D"st=
yled-by-prettify">private</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>&nbsp; &nbsp; T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> m_ref</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; &nbsp; property</span><span style=3D"color: #660;" class=3D"styled-=
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-prettify">=
public</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; property</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> r</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 style=3D"color: #000;" class=3D"=
styled-by-prettify"> m_ref</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">r</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: #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: #660;" class=3D"styled-by-prettify">}</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp=
; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
onst</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">get</span><sp=
an 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: #00=
0;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> m_ref</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: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D(</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 v</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: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; =
&nbsp; &nbsp; m_ref </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> m_ref</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: #660;" class=3D"styled-by-prettify">}=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&n=
bsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">operator</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"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_ref</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #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">Price</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-by-prettify">pr=
ivate</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">float</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_unitPrice=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">float</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> m_vat</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"co=
lor: #008;" class=3D"styled-by-prettify">public</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>&nbsp; &nbsp;property</span><span style=3D"=
color: #080;" class=3D"styled-by-prettify">&lt;float&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">UnitPrice</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>&nbsp; &nbsp;property</span><span style=3D"=
color: #080;" class=3D"styled-by-prettify">&lt;float&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> VAT</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp;</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Price</span><span style=3D"color=
: #660;" 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"> fup</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fvat=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><s=
pan 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"> m_unitPrice</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">fup</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> m_vat</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">fvat</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; &nbsp; &nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">UnitPrice</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
m_unitPrice</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; &nbsp;VAT</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">m_vat</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; &nbsp;</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; &nbsp;</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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> wmain</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: #000;" class=
=3D"styled-by-prettify"> argc</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"=
>wchar_t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> argv</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>&nbsp; &nbsp; </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Price</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> cost</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">1.2f</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: #660;" class=3D"styled-by-pret=
tify">.</span><span style=3D"color: #066;" class=3D"styled-by-prettify">065=
f</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;=
 std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">"Unit Price: "</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> cost</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">UnitPrice</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
endl</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbs=
p; std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">"VAT: "</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> cost</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">VAT </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">end=
l</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nb=
sp; cost</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.<=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">UnitPrice</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n 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;" class=3D"styled-by-prettify">2.40f</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">// Inflation</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">"Unit Price"</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> cost</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">UnitPrice</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><s=
pan 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: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span></div></code></div><br><br>-Andrew Sandoval <br></=
div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1383_15162359.1354058573516--

.


Author: adi.hodos@gmail.com
Date: Tue, 27 Nov 2012 15:32:35 -0800 (PST)
Raw View
------=_Part_2185_31073638.1354059155127
Content-Type: text/plain; charset=ISO-8859-1

This is what I'm using atm, based on code from Imperfect C++ :


template
<
    typename T,
    typename get_ret_type,
    typename set_arg_type,
    get_ret_type (T::*get_fn)() const,
    void (T::*set_fn)(set_arg_type),
    ptrdiff_t (*get_offset_fn)()
>
class external_property_get_set {
    typedef external_property_get_set
    <
        T,
        get_ret_type,
        set_arg_type,
        get_fn,
        set_fn,
        get_offset_fn
    >                                                             class_type
;

public :
    operator get_ret_type() const {
        const T* obj = (const T*) ((char*) this - get_offset_fn());
        return (obj->*get_fn)();
    }

    class_type& operator=(set_arg_type val) {
        T* obj = (T*) ((char*) this - get_offset_fn());
        (obj->*set_fn)(val);
        return *this;
    }
};

#define MK_PROP_OFFSET(class_name, prop_name) \
    static ptrdiff_t get_prop_offset_ ## prop_name() {   \
        return offsetof(class_name, prop_name);         \
    }

#define EXTERNAL_PROPERTY_GET_SET(  \
    class_name,                     \
    get_return_type,                \
    set_argument_type,              \
    get_function,                   \
    set_function,                   \
    property_name)                  \
    friend class external_property_get_set \
    < \
        class_name,  \
        get_return_type, \
        set_argument_type, \
        &class_name::get_function, \
        &class_name::set_function, \
        &class_name::get_prop_offset_ ## property_name \
    >; \
    external_property_get_set \
    < \
        class_name,  \
        get_return_type, \
        set_argument_type, \
        &class_name::get_function, \
        &class_name::set_function, \
        &class_name::get_prop_offset_ ## property_name \
    > property_name; \

class vector3F {
private :
    float vecdata_[4];

    float get_x() const {
        return vecdata_[0];
    }

    void set_x(float val) {
        vecdata_[0] = val;
    }

    float get_y() const {
        return vecdata_[1];
    }

    void set_y(float val) {
        vecdata_[1] = val;
    }

    float get_z() const {
        return vecdata_[2];
    }

    void set_z(float val) {
        vecdata_[2] = val;
    }

    MK_PROP_OFFSET(vector3F, X);
    MK_PROP_OFFSET(vector3F, Y);
    MK_PROP_OFFSET(vector3F, Z);

public :
    vector3F() {}

    vector3F(float x, float y, float z) {
        vecdata_[0] = x;
        vecdata_[1] = y;
        vecdata_[2] = z;
    }


    union {
        EXTERNAL_PROPERTY_GET_SET(vector3F, float, float, get_x, set_x, X);
        EXTERNAL_PROPERTY_GET_SET(vector3F, float, float, get_y, set_y, Y);
        EXTERNAL_PROPERTY_GET_SET(vector3F, float, float, get_z, set_z, Z);
    }; // Use a union so there's only a small space penalty (usually only 1
byte)
};

int main(int, char**) {
    vector3F v0(3.4f, 1.0f, -2.0f);

    v0.X = -12.48f;
    v0.Y = 43.44f;
    v0.Z = +128.5f;

    printf("\n%3.3f, %3.3f, %3.3f", (float) v0.X, (float) v0.Y, (float) v0.Z
);

    return 0;
};

But God, it's ugly. Plus, it uses the offsetof macro. It works, but it's an
ugly hack.

--




------=_Part_2185_31073638.1354059155127
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<code>This is what I'm using atm, based on code from Imperfect C++ :<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; w=
ord-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">template</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">&lt;</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">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"><br>&nbsp; &nbsp; </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> get_ret_type</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>&nbsp; &nbsp; </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> set_arg_type</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>&nbsp; &nbsp; get_ret_type </span><spa=
n 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"styled-by-prettify">get_fn</span><span style=3D"color: #660;" cl=
ass=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: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan 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"col=
or: #000;" class=3D"styled-by-prettify">set_fn</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">set_arg_type</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; ptrdiff_t </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(*</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">get_offset_fn</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">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> external_property_get_set </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typedef</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> external_property_get_set<br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &=
nbsp; T</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; &nbsp; &nbsp; get_ret_type</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; set_arg_type</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>&nbsp; &nbsp; &nbsp; &nbsp; get=
_fn</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=
; &nbsp; &nbsp; set_fn</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>&nbsp; &nbsp; &nbsp; &nbsp; get_offset_fn<br>&nbsp; &nbsp; </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; class_type</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br></span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">public</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"> &nbsp; &nbsp;<br>&nbsp; &nbsp; </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> get_ret_type</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: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-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>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</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-prettify=
"> obj </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #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;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">((</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">char</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">this</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"> get_offset_fn</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">());</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">return</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">obj</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">-&gt;*</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">get_fn</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)();</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; </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>&nbsp; &nbsp; <br>&nbsp; &nbsp; class_type</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">=3D(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">set_arg_type val</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> obj </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</spa=
n><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 style=3D"color: #=
008;" class=3D"styled-by-prettify">char</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-b=
y-prettify">this</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"> get_offset_=
fn</span><span style=3D"color: #660;" class=3D"styled-by-prettify">());</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">o=
bj</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;*</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">set_fn</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">)(</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">val</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; &nbsp; &nbsp; </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">return</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=
: #008;" class=3D"styled-by-prettify">this</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: #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"st=
yled-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-pr=
ettify">#define</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> MK_PROP_OFFSET</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>class_name</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> prop_na=
me</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: #660;" class=3D"styled-by-prettify">\</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">static</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> ptrdiff_t get_prop_offset_ </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">## prop_name(=
) { &nbsp; \</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> offsetof</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">class_name</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> prop_name</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp;=
 &nbsp; &nbsp; &nbsp; </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>&nbsp; &nbsp; </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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; <br></span><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">#define</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> EXTERNAL_PROPERTY_GET_SET</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> &nbsp;</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; class_name</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">\</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; &nbsp; get_return_type</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">\</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; set_argume=
nt_type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">\</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; get_function</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">\</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; set_function</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">\</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; pr=
operty_name</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</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">friend</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> external_property_get_set </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: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #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>&nbsp; &nbsp; &nbsp; &nbsp; class_name</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp;</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; &nbsp; &nbsp; get_retu=
rn_type</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: #660;" class=3D"styled-by-prettify">\</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nb=
sp; set_argument_type</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 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp=
; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>class_name</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">get_fun=
ction</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>&nbsp; &nbsp; &nbsp; &nbsp; =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">class_name</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">set_function</span><spa=
n 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>&nbsp; &nbsp; &nbsp; &nbsp; </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">class_name</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">get_prop_offset_ </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">## property_name \</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </=
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 sty=
le=3D"color: #660;" class=3D"styled-by-prettify">\</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; external_property=
_get_set </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: #660;" class=3D"styled-by-prettify">&l=
t;</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"><br>&nbsp; &nbsp; &nbsp; &=
nbsp; class_name</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &n=
bsp;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">\</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbs=
p; &nbsp; &nbsp; get_return_type</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: #660;" class=3D"styled-by-pret=
tify">\</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; &nbsp; &nbsp; &nbsp; set_argument_type</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">\</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">class_name</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">get_function</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 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">class_name</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">set_function</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">\</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp=
; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">class_=
name</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">get_prop_offse=
t_ </span><span style=3D"color: #800;" class=3D"styled-by-prettify">## prop=
erty_name \</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> property_name</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: #660;" class=3D"styled-by-prettify">\</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> vector3F </=
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><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">private</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>&nbsp; &nbsp; </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> vecdata_</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">4</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">];</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">float</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> get_x</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">const</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>&nbsp; &nbsp=
; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> vecdata_</span><span style=3D"color: #660;" 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 st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbs=
p; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> set_x=
</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"> val</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 style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; vecdata_</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"co=
lor: #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"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> val</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; </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; &nbsp; <br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">float</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> get_y</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: #008;" class=3D"styled-by-prettify">const</s=
pan><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>&nbsp; &nbsp; &nbsp; &nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> vecdata_</sp=
an><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-prettify"><br>&nbsp; &nbsp; </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> set_y</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> val</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-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; &nbsp; &nbsp; vecdata_</span><span style=3D"color: #66=
0;" 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"style=
d-by-prettify">]</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> val</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbs=
p; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> get_=
z</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: #008;" class=3D"styled-by-prettify">const</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"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> vecdata_</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">];</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp; &nbsp; </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; <br>&nbsp; &nbsp; </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> set_z</span><span style=3D"color: #660=
;" 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"s=
tyled-by-prettify"> val</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; &nbsp; &nbsp; vecdata_</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> val</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>&nbsp; &nbsp; </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; MK_PROP=
_OFFSET</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector3F</sp=
an><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">);</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; MK_PROP_OFFSET</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">vector3F</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><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; MK_PROP_OFFSET</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">vector3F</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> Z</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>&nbsp; &nbsp; <br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">public</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>&nbsp; &nbsp; vector3F</span><span style=3D"color: #660;" class=3D"st=
yled-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>&nb=
sp; &nbsp; <br>&nbsp; &nbsp; vector3F</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">float</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> x</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: #008;" class=3D"styled-by-prettify">float</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> y</span><span sty=
le=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: #008;=
" class=3D"styled-by-prettify">float</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> z</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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; &nbsp; &nbsp; vecdata_</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</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"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; vecda=
ta_</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 st=
yle=3D"color: #660;" class=3D"styled-by-prettify">]</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> y</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; &nbsp; &nbsp; vecdata_</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">2</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=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&=
nbsp; &nbsp; <br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">union</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; &nbsp; &nbsp; EXTERNAL_PROPERTY_GET_SET</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">vector3F</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">float</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">float=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> get_x</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> set_x</span><span style=3D"colo=
r: #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">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; EXTERNAL_PROPERTY_GET_SET</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">vector3F</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: #0=
08;" class=3D"styled-by-prettify">float</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">float</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ge=
t_y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> set_y</span><sp=
an 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"colo=
r: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; EXTERNAL_PRO=
PERTY_GET_SET</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector=
3F</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: #008;" class=3D"styled-by-prettify">float</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;" cla=
ss=3D"styled-by-prettify">float</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> get_z</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
set_z</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> Z</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><sp=
an 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">// Use a union so there's only a smal=
l space penalty (usually only 1 byte)</span><span style=3D"color: #000;" cl=
ass=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: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> main</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 sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">char</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">**)</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; &nbsp; vector3F v0</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">3.4f</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">1.0f<=
/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: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">2.0f</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; v0</span><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"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">-</span><span style=3D"color: #066;" class=3D"styled-by-prettify">12.4=
8f</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;=
 v0</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 s=
tyle=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;" class=3D"styled-by-prettify">43.44f</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; v0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">Z </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</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: #066;" class=3D"styled-by-prettify">128.5f</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br=
>&nbsp; &nbsp; printf</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #080;" class=3D"styled-by-prettify=
">"\n%3.3f, %3.3f, %3.3f"</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</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: #008;" class=3D"styled-by-prettify">float</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> v0</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #00=
0;" 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"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">flo=
at</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> v0</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">Y</span><span style=3D"color: #66=
0;" 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: #008;" class=3D"styled-by-pret=
tify">float</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> v0</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">Z</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><s=
pan 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></div></code></div><br>But God, it's ugly.=
 Plus, it uses the offsetof macro. It works, but it's an ugly hack.<br></co=
de>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2185_31073638.1354059155127--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 28 Nov 2012 00:34:02 +0100
Raw View
Le 27/11/12 18:41, Olaf van der Spek a =E9crit :
> On Tue, Nov 27, 2012 at 6:30 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>> On 27 November 2012 19:21, Olaf van der Spek <olafvdspek@gmail.com> wrot=
e:
>>>>> What wrapper type? C++ (and Boost) don't provide one AFAIK.
>>>> Currently I write them myself. It's rather custom functionality to dec=
ide
>>> Isn't that an argument for proper properties support?
>> Sure. The question is how often you really need such wrapper types,
> Very often
>
>> and how much
>> properties really help.
> Eh, what do you mean? The advantages of properties are clear, aren't they=
?
> The only question is how to best implement them.

Before implementing, the problem is how to define and integrate them in=20
an already complex language. Adding a new kind of member implies seen=20
how this new member and the rest of the language interact. I don't know=20
if some of the posters is ready to start a proposal that describes all=20
these interactions, but be sure the list is longuer than you could expect.

>
> Take containers for example. "if (s.size >=3D 8)" looks a bit cleaner
> than "if (s.size() >=3D 8)".
>
I agree and I would like to see well defined properties already in C++,=20
but they are not in, and define them will need to respond to questions like

* what &s.size mean?
* can we store property members?
* could a property be used as a 'function'? would it be a getter or a=20
setter? do we need std::mem_property? std::bind_property? ...
* could rw properties be swapped?
* could properties be indexed?
* could properties be returned by functions?
* could properties be used as function parameters?
* could properties be used as template parameters?
* ...

In summary, are properties 1st class citizen entities?

Whether it is worth doing it or not is an open question. Any one=20
voluntering?

-- Vicente

--=20




.


Author: Nevin Liber <nliber@gmail.com>
Date: Tue, 27 Nov 2012 17:35:22 -0600
Raw View
On Nov 27, 2012, at 4:43 PM, "masse.nicolas@gmail.com"
<masse.nicolas@gmail.com> wrote:

> template<typename T>
> struct property
> {
>    typedef std::function<T(void)> getter;
>    typedef std::function<void(const T&)> setter;
>    getter m_getter;
>    setter m_setter;
>
>    operator T () { return m_getter(); }
>    void operator= (const T& value) { m_setter(value); }
> };
>
> class Price
> {
>    float m_unitPrice;
>    float m_vat;
> public:
>    property<float> UnitPrice;
>    property<float> VAT;
>    property<float> PriceTTC;
>
> Price()
> {
>    UnitPrice = {
>       [&]() { return m_unitPrice; },
>       [&](float value) { m_unitPrice = value; },
>    };
>    VAT = {
>       [&]() { return m_vat; },
>       [&](float value) { m_vat = value; },
>    };
>    PriceTTC = {
>       [&]() { return (1+ m_vat/100) * m_unitPrice; }
>    };
> }
> };
>
> It does work, and once the property class have been declared, rest of the code is easy to wrote.

Except copying Price is now broken. Once you introduce reference
semantics, everything gets vastly more complicated.  Presumably a real
property would have value semantics when the underlying object has
value semantics.
>

--




.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 15:37:05 -0800 (PST)
Raw View
------=_Part_1253_27533036.1354059425945
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 6:22:53 PM UTC-5, Andrew Sandoval wrote:
>
> Why not simplify this down...  The following solution doesn't handle your
> PriceTTC case, but that can probably be done cleverly another way -- or
> better just as a function.  I don't follow other languages closely, but I
> don't think their properties do that kind of thing either...  So, this
> should be very light-weight w/regards to your memory (etc.) concerns, in
> fact I suspect it almost entirely is optimized away in release builds:
>

I would be very pleasantly surprised if that was optimized away. I suspect
the compiler wouldn't even stand a chance unless you defined your
properties in the header.

Also, your properties only work on one value. In practice, they need some
sort of access to their parent object.

Even if there was a way to get it to optimize everything away, the
programmer has to do a lot of work to double-check that it's really doing
that. Properties really should just be syntactic sugar for getters and
setters. Although that syntactic sugar lets you do really elegant things
like this:

v.x = v.y = v.z = 0;

On Tuesday, November 27, 2012 5:53:28 PM UTC-5, viboes wrote:
>
> Also, how does it interact with template argument deduction and
> references? For example, I can imagine that this won't work:
>
>    SomeClass object;
>    object.prop1 = 17;
>    object.prop2 = 29;
>    std::swap(object.prop1, object.prop2);
>    auto mptr = &SomeClass::prop1;
>    (object.*mptr) = 99;
>

I can't speak for other languages, but in C#, I'm pretty sure taking a
reference to a property is a compile-time error. But at least it's reduced
your refactoring time from a day down to half an hour.

--




------=_Part_1253_27533036.1354059425945
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 6:22:53 PM UTC-5, Andrew Sandoval wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;">Why not simplify this down...&nbsp;=
 The following solution doesn't handle your PriceTTC case, but that can pro=
bably be done cleverly another way -- or better just as a function.&nbsp; I=
 don't follow other languages closely, but I don't think their properties d=
o that kind of thing either...&nbsp; So, this should be very light-weight w=
/regards to your memory (etc.) concerns, in fact I suspect it almost entire=
ly is optimized away in release builds:<br></blockquote><div><br>I would be=
 very pleasantly surprised if that was optimized away. I suspect the compil=
er wouldn't even stand a chance unless you defined your properties in the h=
eader.<br><br>Also, your properties only work on one value. In practice, th=
ey need some sort of access to their parent object.<br><br>Even if there wa=
s a way to get it to optimize everything away, the programmer has to do a l=
ot of work to double-check that it's really doing that. Properties really s=
hould just be syntactic sugar for getters and setters. Although that syntac=
tic sugar lets you do really elegant things like this:<br><br><span style=
=3D"font-family: courier new,monospace;">v.x =3D v.y =3D v.z =3D 0;</span><=
br><br>On Tuesday, November 27, 2012 5:53:28 PM UTC-5, viboes wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;">Also, how does it interact with templ=
ate argument deduction and
<br>references? For example, I can imagine that this won't work:
<br>
<br>&nbsp; &nbsp;SomeClass object;
<br>&nbsp; &nbsp;object.prop1 =3D 17;
<br>&nbsp; &nbsp;object.prop2 =3D 29;
<br>&nbsp; &nbsp;std::swap(object.prop1, object.prop2);
<br>&nbsp; &nbsp;auto mptr =3D &amp;SomeClass::prop1;
<br>&nbsp; &nbsp;(object.*mptr) =3D 99;
<br></blockquote><br>I can't speak for other languages, but in C#, I'm pret=
ty sure taking a reference to a property is a compile-time error. But at le=
ast it's reduced your refactoring time from a day down to half an hour.<br>=
</div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1253_27533036.1354059425945--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 27 Nov 2012 15:42:02 -0800 (PST)
Raw View
------=_Part_35_23522211.1354059722487
Content-Type: text/plain; charset=ISO-8859-1



On Tuesday, November 27, 2012 3:22:53 PM UTC-8, Andrew Sandoval wrote:
>
> On Tuesday, November 27, 2012 4:43:43 PM UTC-6, masse....@gmail.com wrote:
>>
>> In fact, with C++11, you could already do better.
>> Here a quick exemple I've just written :
>>
>> #include <iostream>
>> #include <functional>
>>
>> template<typename T>
>> struct property
>> {
>>    typedef std::function<T(void)> getter;
>>    typedef std::function<void(const T&)> setter;
>>    getter m_getter;
>>    setter m_setter;
>>
>>    operator T () { return m_getter(); }
>>    void operator= (const T& value) { m_setter(value); }
>> };
>>
>> class Price
>> {
>>    float m_unitPrice;
>>    float m_vat;
>> public:
>>    property<float> UnitPrice;
>>    property<float> VAT;
>>    property<float> PriceTTC;
>>
>> Price()
>> {
>>    UnitPrice = {
>>       [&]() { return m_unitPrice; },
>>       [&](float value) { m_unitPrice = value; },
>>    };
>>    VAT = {
>>       [&]() { return m_vat; },
>>       [&](float value) { m_vat = value; },
>>    };
>>    PriceTTC = {
>>       [&]() { return (1+ m_vat/100) * m_unitPrice; }
>>    };
>> }
>> };
>>
>> int main()
>> {
>>    Price X;
>>    X.UnitPrice = 5.0;
>>    X.VAT = 5.0;
>>    std::cout << X.PriceTTC;
>>    return 0;
>> }
>>
>> It does work, and once the property class have been declared, rest of the
>> code is easy to wrote.
>> But as you already pointed out, such an approach will consume a lot of
>> memory (3 more member, with 2 std::func each in my example, not speaking
>> about the lambda funcs), so I'm still looking for a better solution, and I
>> think i would require a change to the language, but I'm not 100% sure of
>> that yet.
>>
>>
>> Why not simplify this down...  The following solution doesn't handle your
> PriceTTC case, but that can probably be done cleverly another way -- or
> better just as a function.  I don't follow other languages closely, but I
> don't think their properties do that kind of thing either...  So, this
> should be very light-weight w/regards to your memory (etc.) concerns, in
> fact I suspect it almost entirely is optimized away in release builds:
>
> #include <iostream>
>
> template <typename T>
> class property
> {
> private:
>     T& m_ref;
>     property();
> public:
>     property(T& r) : m_ref(r)
>     {
>     }
>
>     const T get() const
>     {
>         return m_ref;
>     }
>
>     const T& operator=(const T& v)
>     {
>         m_ref = v;
>         return m_ref;
>     }
>
>     operator T () const
>     {
>         return m_ref;
>     }
> };
>
> class Price
> {
> private:
>    float m_unitPrice;
>    float m_vat;
> public:
>    property<float> UnitPrice;
>    property<float> VAT;
>
>    Price(float fup, float fvat) : m_unitPrice(fup), m_vat(fvat),
>        UnitPrice(m_unitPrice),
>        VAT(m_vat)
>    {
>    }
> };
>
> int wmain(int argc, wchar_t* argv[])
> {
>     Price cost(1.2f, .065f);
>     std::cout << "Unit Price: " << cost.UnitPrice << std::endl;
>     std::cout << "VAT: " << cost.VAT << std::endl;
>
>     cost.UnitPrice = 2.40f;        // Inflation
>     std::cout << "Unit Price" << cost.UnitPrice << std::endl;
>
>     return 0;
> }
>
>
>
> -Andrew Sandoval
>

A library solution is a terrible idea. Ignoring the deficiencies in your
particular implementation (copy-assignment, copy-construction, only works
with single member variables, instead of arbitrary code, etc), it has
other, more fundamental, flaws to this whole style of approach.

For example, any class that uses it instantly stops being standard layout
and trivial. Why? There's no reason for that; I shouldn't have to give up
these class features just because I want to provide a (theoretically)
better user interface.

Look, I personally am not a fan of properties. But if the decision is made
to add them to C++, then they need to be added *properly* as a first-class
language feature. Not as some obvious library hack like this. That's why
they're adding real polymorphic lambda functions to C++, rather than trying
to add hacks like Boost.Phoenix and so forth.

If it's going to be done, then do it for real. Just because you might be
able to do it via the library doesn't mean you *should.*

--




------=_Part_35_23522211.1354059722487
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Tuesday, November 27, 2012 3:22:53 PM UTC-8, Andrew Sandoval wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday, November 27, 20=
12 4:43:43 PM UTC-6, <a>masse....@gmail.com</a> wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div>In fact, with C++11, you could already do better.<b=
r></div><div>Here a quick exemple I've just written :</div><div><br></div><=
div>#include &lt;iostream&gt;<br>#include &lt;functional&gt;<br><br>templat=
e&lt;typename T&gt;<br>struct property<br>{<br>&nbsp; &nbsp;typedef std::fu=
nction&lt;T(void)&gt; getter;<br> &nbsp; &nbsp;typedef std::function&lt;voi=
d(const T&amp;)&gt; setter;<br> &nbsp; &nbsp;getter m_getter;<br> &nbsp; &n=
bsp;setter m_setter;<br> <br> &nbsp; &nbsp;operator T () { return m_getter(=
); }<br> &nbsp; &nbsp;void operator=3D (const T&amp; value) { m_setter(valu=
e); }<br>};<br><br>class Price<br>{<br> &nbsp; &nbsp;float m_unitPrice;<br>=
 &nbsp; &nbsp;float m_vat;<br> public:<br> &nbsp; &nbsp;property&lt;float&g=
t; UnitPrice;<br> &nbsp; &nbsp;property&lt;float&gt; VAT;<br> &nbsp; &nbsp;=
property&lt;float&gt; PriceTTC; <br> <br> Price() <br> { <br>  &nbsp; &nbsp=
;UnitPrice =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_unitP=
rice; },<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](float value) {  m_unitPric=
e =3D value; },<br>  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;VAT =3D {<br>   &nbs=
p; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_vat; },<br>   &nbsp; &nbsp;&nbsp=
; &nbsp;[&amp;](float value) { m_vat =3D value; },<br>  &nbsp; &nbsp;};<br>=
  &nbsp; &nbsp;PriceTTC =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { r=
eturn (1+ m_vat/100) * m_unitPrice; }<br>  &nbsp; &nbsp;};<br> }<br>};<br><=
br>int main()<br>{<br> &nbsp; &nbsp;Price X;<br> &nbsp; &nbsp;X.UnitPrice =
=3D 5.0;<br> &nbsp; &nbsp;X.VAT =3D 5.0;<br> &nbsp; &nbsp;std::cout &lt;&lt=
; X.PriceTTC;<br> &nbsp; &nbsp;return 0;<br>}</div><div><br></div><div>It d=
oes work, and once the property class have been declared, rest of the code =
is easy to wrote.</div><div>But
 as you already pointed out, such an approach will consume a lot of=20
memory (3 more member, with 2 std::func each in my example, not speaking
 about the lambda funcs), so I'm still looking for a better solution,=20
and I think i would require a change to the language, but I'm not 100%=20
sure of that yet.</div><div><br></div><br></blockquote><div>Why not=20
simplify this down...&nbsp; The following solution doesn't handle your=20
PriceTTC case, but that can probably be done cleverly another way -- or=20
better just as a function.&nbsp; I don't follow other languages closely, bu=
t I
 don't think their properties do that kind of thing either...&nbsp; So, thi=
s=20
should be very light-weight w/regards to your memory (etc.) concerns, in
 fact I suspect it almost entirely is optimized away in release builds:<br>=
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#800">#include</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#080">&lt;iostrea=
m&gt;</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#008">template</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#008">typename</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> property<br></span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#008">private</span>=
<span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &n=
bsp; T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#0=
00"> m_ref</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br>&nbsp; &nbsp; property</span><span style=3D"color:#660">();</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">public</spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; =
&nbsp; property</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">T</span><span style=3D"color:#660">&amp;</span><span style=3D"colo=
r:#000"> r</span><span style=3D"color:#660">)</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">:</span><span style=3D"color:#000"> =
m_ref</span><span style=3D"color:#660">(</span><span style=3D"color:#000">r=
</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">c=
onst</span><span style=3D"color:#000"> T </span><span style=3D"color:#008">=
get</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color:#008">=
return</span><span style=3D"color:#000"> m_ref</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"> T<=
/span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">operator</span><span style=3D"color:#660">=
=3D(</span><span style=3D"color:#008">const</span><span style=3D"color:#000=
"> T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000=
"> v</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><b=
r>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; m_ref </span><span style=3D"color=
:#660">=3D</span><span style=3D"color:#000"> v</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">operator</s=
pan><span style=3D"color:#000"> T </span><span style=3D"color:#660">()</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">const</span=
><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"color=
:#000"><br><br></span><span style=3D"color:#008">class</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">Price</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#008">private</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span>=
<span style=3D"color:#008">float</span><span style=3D"color:#000"> m_unitPr=
ice</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp;</span><span style=3D"color:#008">float</span><span style=3D"=
color:#000"> m_vat</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">public</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;propert=
y</span><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">UnitPrice</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp;property</spa=
n><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color:#000"=
> VAT</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br><br>&nbsp; &nbsp;</span><span style=3D"color:#606">Price</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#008">float</span><span styl=
e=3D"color:#000"> fup</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">float</span><span style=
=3D"color:#000"> fvat</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"> m_unitPrice</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">fup</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"> m_vat</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">fvat</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:=
#606">UnitPrice</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">m_unitPrice</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;VAT</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">m_vat</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</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:#000"><br><br></s=
pan><span style=3D"color:#008">int</span><span style=3D"color:#000"> wmain<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#000"> argc</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">wchar_t</sp=
an><span style=3D"color:#660">*</span><span style=3D"color:#000"> argv</spa=
n><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>&nbsp; =
&nbsp; </span><span style=3D"color:#606">Price</span><span style=3D"color:#=
000"> cost</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
66">1.2f</span><span style=3D"color:#660">,</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">.</span><span style=3D"color:#066">065=
f</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price: "</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span=
><span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span>=
<span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"VAT: "</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><span sty=
le=3D"color:#000">VAT </span><span style=3D"color:#660">&lt;&lt;</span><spa=
n style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span=
 style=3D"color:#000">endl</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br><br>&nbsp; &nbsp; cost</span><span style=3D"color:#=
660">.</span><span style=3D"color:#606">UnitPrice</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2.40f</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"> &nbsp; &nbsp; &nbsp; &nbsp;</span><=
span style=3D"color:#800">// Inflation</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D=
"color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span>=
<span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><=
span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> std=
</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br=
>&nbsp; &nbsp; </span><span style=3D"color:#008">return</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=3D"c=
olor:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#660">}</span><span style=3D"color:#000"><br><br></span></div></code></d=
iv><br><br>-Andrew Sandoval <br></div></blockquote><div><br>A
 library solution is a terrible idea. Ignoring the deficiencies in your=20
particular implementation (copy-assignment, copy-construction, only works w=
ith single member variables, instead of arbitrary code, etc), it has other,=
 more fundamental, flaws to this whole style of approach.<br><br>For exampl=
e, any class that uses it instantly stops being standard layout and trivial=
.. Why? There's no reason for that; I shouldn't have to give up these class =
features just because I want to provide a (theoretically) better user inter=
face.<br><br>Look, I personally am not a fan of properties. But if the deci=
sion is made to add them to C++, then they need to be added <i>properly</i>=
 as a first-class language feature. Not as some obvious library hack like t=
his. That's why they're adding real polymorphic lambda functions to C++, ra=
ther than trying to add hacks like Boost.Phoenix and so forth.<br><br>If it=
's going to be done, then do it for real. Just because you might be able to=
 do it via the library doesn't mean you <i>should.</i><br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_35_23522211.1354059722487--

.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 15:46:13 -0800 (PST)
Raw View
------=_Part_188_16506323.1354059973637
Content-Type: text/plain; charset=ISO-8859-1

I think the point of these implementations is to show that people are
already going to great lengths to implement property semantics, even if
it's in a terrible way.

--




------=_Part_188_16506323.1354059973637
Content-Type: text/html; charset=ISO-8859-1

I think the point of these implementations is to show that people are already going to great lengths to implement property semantics, even if it's in a terrible way.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_188_16506323.1354059973637--

.


Author: Andrew Sandoval <sandoval@netwaysglobal.com>
Date: Tue, 27 Nov 2012 16:39:04 -0800 (PST)
Raw View
------=_Part_1403_15998708.1354063145013
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 5:42:02 PM UTC-6, Nicol Bolas wrote:
>
> On Tuesday, November 27, 2012 3:22:53 PM UTC-8, Andrew Sandoval wrote:
>>
>> On Tuesday, November 27, 2012 4:43:43 PM UTC-6, masse....@gmail.comwrote:
>>>
>>> In fact, with C++11, you could already do better.
>>> Here a quick exemple I've just written :
>>>
>>> #include <iostream>
>>> #include <functional>
>>>
>>> template<typename T>
>>> struct property
>>> {
>>>    typedef std::function<T(void)> getter;
>>>    typedef std::function<void(const T&)> setter;
>>>    getter m_getter;
>>>    setter m_setter;
>>>
>>>    operator T () { return m_getter(); }
>>>    void operator= (const T& value) { m_setter(value); }
>>> };
>>>
>>> class Price
>>> {
>>>    float m_unitPrice;
>>>    float m_vat;
>>> public:
>>>    property<float> UnitPrice;
>>>    property<float> VAT;
>>>    property<float> PriceTTC;
>>>
>>> Price()
>>> {
>>>    UnitPrice = {
>>>       [&]() { return m_unitPrice; },
>>>       [&](float value) { m_unitPrice = value; },
>>>    };
>>>    VAT = {
>>>       [&]() { return m_vat; },
>>>       [&](float value) { m_vat = value; },
>>>    };
>>>    PriceTTC = {
>>>       [&]() { return (1+ m_vat/100) * m_unitPrice; }
>>>    };
>>> }
>>> };
>>>
>>> int main()
>>> {
>>>    Price X;
>>>    X.UnitPrice = 5.0;
>>>    X.VAT = 5.0;
>>>    std::cout << X.PriceTTC;
>>>    return 0;
>>> }
>>>
>>> It does work, and once the property class have been declared, rest of
>>> the code is easy to wrote.
>>> But as you already pointed out, such an approach will consume a lot of
>>> memory (3 more member, with 2 std::func each in my example, not speaking
>>> about the lambda funcs), so I'm still looking for a better solution, and I
>>> think i would require a change to the language, but I'm not 100% sure of
>>> that yet.
>>>
>>>
>>> Why not simplify this down...  The following solution doesn't handle
>> your PriceTTC case, but that can probably be done cleverly another way --
>> or better just as a function.  I don't follow other languages closely, but
>> I don't think their properties do that kind of thing either...  So, this
>> should be very light-weight w/regards to your memory (etc.) concerns, in
>> fact I suspect it almost entirely is optimized away in release builds:
>>
>> #include <iostream>
>>
>> template <typename T>
>> class property
>> {
>> private:
>>     T& m_ref;
>>     property();
>> public:
>>     property(T& r) : m_ref(r)
>>     {
>>     }
>>
>>     const T get() const
>>     {
>>         return m_ref;
>>     }
>>
>>     const T& operator=(const T& v)
>>     {
>>         m_ref = v;
>>         return m_ref;
>>     }
>>
>>     operator T () const
>>     {
>>         return m_ref;
>>     }
>> };
>>
>> class Price
>> {
>> private:
>>    float m_unitPrice;
>>    float m_vat;
>> public:
>>    property<float> UnitPrice;
>>    property<float> VAT;
>>
>>    Price(float fup, float fvat) : m_unitPrice(fup), m_vat(fvat),
>>        UnitPrice(m_unitPrice),
>>        VAT(m_vat)
>>    {
>>    }
>> };
>>
>> int wmain(int argc, wchar_t* argv[])
>> {
>>     Price cost(1.2f, .065f);
>>     std::cout << "Unit Price: " << cost.UnitPrice << std::endl;
>>     std::cout << "VAT: " << cost.VAT << std::endl;
>>
>>     cost.UnitPrice = 2.40f;        // Inflation
>>     std::cout << "Unit Price" << cost.UnitPrice << std::endl;
>>
>>     return 0;
>> }
>>
>>
>>
>> -Andrew Sandoval
>>
>
> A library solution is a terrible idea. Ignoring the deficiencies in your
> particular implementation (copy-assignment, copy-construction, only works
> with single member variables, instead of arbitrary code, etc), it has
> other, more fundamental, flaws to this whole style of approach.
>
> For example, any class that uses it instantly stops being standard layout
> and trivial. Why? There's no reason for that; I shouldn't have to give up
> these class features just because I want to provide a (theoretically)
> better user interface.
>
> Look, I personally am not a fan of properties. But if the decision is made
> to add them to C++, then they need to be added *properly* as a
> first-class language feature. Not as some obvious library hack like this.
> That's why they're adding real polymorphic lambda functions to C++, rather
> than trying to add hacks like Boost.Phoenix and so forth.
>
> If it's going to be done, then do it for real. Just because you might be
> able to do it via the library doesn't mean you *should.*
>

I'd argue just the opposite.  I'm not a fan of properties either, but if it
needs to be there I'd rather see it in the standard library than to see the
language implement something that hides functionality (potentially).

Also, someone could easily add copy assignment, copy constructor, etc. to
this, but it works pretty close to the way properties work where ever I've
seen them used...  And if you really need multiple values, etc. another
class can do it, like the computed_property below.

The ugliest part of this is that you can't use a lambda in a typedef, so
putting something like this in a class is ugly still.  Or, like
computed_property below it requires using a function pointer...

Just remember that anything that goes into the Standard Library can
potentially be in production within a year or two.  Any core language
changes are 2014 at the soonest.

#include <iostream>
#include <tuple>
#include <algorithm>

template <typename T, typename TSeq, typename TC>
class computed_property
{
private:
    TSeq m_fields;
    TC m_computation;
public:
    computed_property(TSeq &&fields, TC &&computation) : m_fields(std::move(
fields)), m_computation(std::move(computation))
    {
    }

    computed_property(TSeq &fields, TC &computation) : m_fields(fields),m_computation
(computation)
    {
    }

    const T get() const
    {
        return m_computation(m_fields);
    }

    operator T () const
    {
        return get();
    }
};

template <typename T>
class property
{
private:
    T& m_ref;
    property();
public:
    property(T& r) : m_ref(r)
    {
    }

    const T get() const
    {
        return m_ref;
    }

    const T& operator=(const T& v)
    {
        m_ref = v;
        return m_ref;
    }

    operator T () const
    {
        return m_ref;
    }
};

class Price
{
private:
   float m_unitPrice;
   float m_vat;
   float m_discount;
public:
   property<float> UnitPrice;
   property<float> VAT;
   property<float> Discount;
   computed_property<float, std::tuple<const float &, const float &>, float
(*)(const std::tuple<const float&, const float&> &) > PriceTTC;
   computed_property<float, std::tuple<const float &, const float &, const
float &>, float (*)(const std::tuple<const float&, const float&, const float
&> &) > DiscountedTotal;

   Price() :
       UnitPrice(m_unitPrice),
       VAT(m_vat),
       Discount(m_discount),
       PriceTTC(std::tie(m_unitPrice, m_vat), [](const std::tuple<const
float &, const float &> &values) ->float
       {
           return (1 + std::get<1>(values) / 100) * std::get<0>(values);
       }),
       DiscountedTotal(std::tie(m_unitPrice, m_vat, m_discount), [](conststd
::tuple<const float &, const float &, const float &> &values) ->float
       {
           return ((1 + std::get<1>(values) / 100) * std::get<0>(values)) -
(std::get<0>(values) * (std::get<2>(values) / 100));
       })
   {
   }
};

int wmain(int argc, wchar_t* argv[])
{
    Price cost;

    cost.UnitPrice = 200.0f;
    cost.VAT = 6.5f;
    cost.Discount = 10.0f;

    Price secondCost = cost;

    std::cout << "Unit Price: " << secondCost.UnitPrice << std::endl;
    std::cout << "VAT: " << secondCost.VAT << "%" << std::endl;
    std::cout << "Discount: " << secondCost.Discount << "%" << std::endl;

    std::cout << "Price TTC: " << secondCost.PriceTTC << std::endl;
    std::cout << "Price Discounted: " << secondCost.DiscountedTotal << std::
endl;

    return 0;
}


I'll be the first to admit that computed_property isn't pretty, but I'd
still argue it's better than the solution using offsetof, etc.

-Andrew Sandoval


--




------=_Part_1403_15998708.1354063145013
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 5:42:02 PM UTC-6, Nicol Bolas wrote:<blockquo=
te class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left:=
 1px #ccc solid;padding-left: 1ex;">On Tuesday, November 27, 2012 3:22:53 P=
M UTC-8, Andrew Sandoval wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">On T=
uesday, November 27, 2012 4:43:43 PM UTC-6, <a>masse....@gmail.com</a> wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bor=
der-left:1px #ccc solid;padding-left:1ex"><div>In fact, with C++11, you cou=
ld already do better.<br></div><div>Here a quick exemple I've just written =
:</div><div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;functi=
onal&gt;<br><br>template&lt;typename T&gt;<br>struct property<br>{<br>&nbsp=
; &nbsp;typedef std::function&lt;T(void)&gt; getter;<br> &nbsp; &nbsp;typed=
ef std::function&lt;void(const T&amp;)&gt; setter;<br> &nbsp; &nbsp;getter =
m_getter;<br> &nbsp; &nbsp;setter m_setter;<br> <br> &nbsp; &nbsp;operator =
T () { return m_getter(); }<br> &nbsp; &nbsp;void operator=3D (const T&amp;=
 value) { m_setter(value); }<br>};<br><br>class Price<br>{<br> &nbsp; &nbsp=
;float m_unitPrice;<br> &nbsp; &nbsp;float m_vat;<br> public:<br> &nbsp; &n=
bsp;property&lt;float&gt; UnitPrice;<br> &nbsp; &nbsp;property&lt;float&gt;=
 VAT;<br> &nbsp; &nbsp;property&lt;float&gt; PriceTTC; <br> <br> Price() <b=
r> { <br>  &nbsp; &nbsp;UnitPrice =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&a=
mp;]() { return m_unitPrice; },<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](flo=
at value) {  m_unitPrice =3D value; },<br>  &nbsp; &nbsp;};<br>  &nbsp; &nb=
sp;VAT =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_vat; },<b=
r>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](float value) { m_vat =3D value; },<b=
r>  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;PriceTTC =3D {<br>   &nbsp; &nbsp;&nb=
sp; &nbsp;[&amp;]() { return (1+ m_vat/100) * m_unitPrice; }<br>  &nbsp; &n=
bsp;};<br> }<br>};<br><br>int main()<br>{<br> &nbsp; &nbsp;Price X;<br> &nb=
sp; &nbsp;X.UnitPrice =3D 5.0;<br> &nbsp; &nbsp;X.VAT =3D 5.0;<br> &nbsp; &=
nbsp;std::cout &lt;&lt; X.PriceTTC;<br> &nbsp; &nbsp;return 0;<br>}</div><d=
iv><br></div><div>It does work, and once the property class have been decla=
red, rest of the code is easy to wrote.</div><div>But
 as you already pointed out, such an approach will consume a lot of=20
memory (3 more member, with 2 std::func each in my example, not speaking
 about the lambda funcs), so I'm still looking for a better solution,=20
and I think i would require a change to the language, but I'm not 100%=20
sure of that yet.</div><div><br></div><br></blockquote><div>Why not=20
simplify this down...&nbsp; The following solution doesn't handle your=20
PriceTTC case, but that can probably be done cleverly another way -- or=20
better just as a function.&nbsp; I don't follow other languages closely, bu=
t I
 don't think their properties do that kind of thing either...&nbsp; So, thi=
s=20
should be very light-weight w/regards to your memory (etc.) concerns, in
 fact I suspect it almost entirely is optimized away in release builds:<br>=
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#800">#include</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#080">&lt;iostrea=
m&gt;</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#008">template</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#008">typename</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> property<br></span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#008">private</span>=
<span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &n=
bsp; T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#0=
00"> m_ref</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br>&nbsp; &nbsp; property</span><span style=3D"color:#660">();</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">public</spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; =
&nbsp; property</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">T</span><span style=3D"color:#660">&amp;</span><span style=3D"colo=
r:#000"> r</span><span style=3D"color:#660">)</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">:</span><span style=3D"color:#000"> =
m_ref</span><span style=3D"color:#660">(</span><span style=3D"color:#000">r=
</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">c=
onst</span><span style=3D"color:#000"> T </span><span style=3D"color:#008">=
get</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color:#008">=
return</span><span style=3D"color:#000"> m_ref</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"> T<=
/span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">operator</span><span style=3D"color:#660">=
=3D(</span><span style=3D"color:#008">const</span><span style=3D"color:#000=
"> T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000=
"> v</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><b=
r>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; m_ref </span><span style=3D"color=
:#660">=3D</span><span style=3D"color:#000"> v</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">operator</s=
pan><span style=3D"color:#000"> T </span><span style=3D"color:#660">()</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">const</span=
><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"color=
:#000"><br><br></span><span style=3D"color:#008">class</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">Price</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#008">private</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span>=
<span style=3D"color:#008">float</span><span style=3D"color:#000"> m_unitPr=
ice</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp;</span><span style=3D"color:#008">float</span><span style=3D"=
color:#000"> m_vat</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">public</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;propert=
y</span><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">UnitPrice</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp;property</spa=
n><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color:#000"=
> VAT</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br><br>&nbsp; &nbsp;</span><span style=3D"color:#606">Price</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#008">float</span><span styl=
e=3D"color:#000"> fup</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">float</span><span style=
=3D"color:#000"> fvat</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"> m_unitPrice</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">fup</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"> m_vat</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">fvat</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:=
#606">UnitPrice</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">m_unitPrice</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;VAT</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">m_vat</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</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:#000"><br><br></s=
pan><span style=3D"color:#008">int</span><span style=3D"color:#000"> wmain<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#000"> argc</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">wchar_t</sp=
an><span style=3D"color:#660">*</span><span style=3D"color:#000"> argv</spa=
n><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>&nbsp; =
&nbsp; </span><span style=3D"color:#606">Price</span><span style=3D"color:#=
000"> cost</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
66">1.2f</span><span style=3D"color:#660">,</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">.</span><span style=3D"color:#066">065=
f</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price: "</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span=
><span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span>=
<span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"VAT: "</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><span sty=
le=3D"color:#000">VAT </span><span style=3D"color:#660">&lt;&lt;</span><spa=
n style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span=
 style=3D"color:#000">endl</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br><br>&nbsp; &nbsp; cost</span><span style=3D"color:#=
660">.</span><span style=3D"color:#606">UnitPrice</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2.40f</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"> &nbsp; &nbsp; &nbsp; &nbsp;</span><=
span style=3D"color:#800">// Inflation</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D=
"color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span>=
<span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><=
span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> std=
</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br=
>&nbsp; &nbsp; </span><span style=3D"color:#008">return</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=3D"c=
olor:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#660">}</span><span style=3D"color:#000"><br><br></span></div></code></d=
iv><br><br>-Andrew Sandoval <br></div></blockquote><div><br>A
 library solution is a terrible idea. Ignoring the deficiencies in your=20
particular implementation (copy-assignment, copy-construction, only works w=
ith single member variables, instead of arbitrary code, etc), it has other,=
 more fundamental, flaws to this whole style of approach.<br><br>For exampl=
e, any class that uses it instantly stops being standard layout and trivial=
.. Why? There's no reason for that; I shouldn't have to give up these class =
features just because I want to provide a (theoretically) better user inter=
face.<br><br>Look, I personally am not a fan of properties. But if the deci=
sion is made to add them to C++, then they need to be added <i>properly</i>=
 as a first-class language feature. Not as some obvious library hack like t=
his. That's why they're adding real polymorphic lambda functions to C++, ra=
ther than trying to add hacks like Boost.Phoenix and so forth.<br><br>If it=
's going to be done, then do it for real. Just because you might be able to=
 do it via the library doesn't mean you <i>should.</i><br></div></blockquot=
e><div><br>I'd argue just the opposite.&nbsp; I'm not a fan of properties e=
ither, but if it needs to be there I'd rather see it in the standard librar=
y than to see the language implement something that hides functionality (po=
tentially).<br><br>Also, someone could easily add copy assignment, copy con=
structor, etc. to this, but it works pretty close to the way properties wor=
k where ever I've seen them used...&nbsp; And if you really need multiple v=
alues, etc. another class can do it, like the computed_property below.<br><=
br>The ugliest part of this is that you can't use a lambda in a typedef, so=
 putting something like this in a class is ugly still.&nbsp; Or, like compu=
ted_property below it requires using a function pointer...<br><br>Just reme=
mber that anything that goes into the Standard Library can potentially be i=
n production within a year or two.&nbsp; Any core language changes are 2014=
 at the soonest.<br><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; b=
order-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">#include</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;iostr=
eam&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #800;" class=3D"styled-by-prettify">#include<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #080;" class=3D"styled-by-prettify">&lt;tuple&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">#include</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #080;" class=3D"styled-by-prettify">&lt;algorithm&gt;</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">template</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </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"> 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">typename</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">TSeq<=
/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: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> TC</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> computed_property<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></span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">private</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">TSeq</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> m_fields</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; TC m_computation</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: #008;" class=3D"styled-by-=
prettify">public</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; &nbsp; computed_property</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">TSeq</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
fields</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> TC </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">computation</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: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> m_fields</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=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-prett=
ify">move</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">fields</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">)),</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> m_computation</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">move</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">computation</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">))</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; &nbsp; </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: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br>&nbsp; &nbsp; computed_property</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">TSeq</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">fields</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> TC=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">computation</s=
pan><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 style=3D"color: #=
000;" class=3D"styled-by-prettify"> m_fields</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">fields</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> m_computation</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">computation</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; </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>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> T </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ge=
t</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: #008;" class=3D"styled-by-prettify">const</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </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; &nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_computation=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">m_fields</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> T </span><span st=
yle=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">const</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span sty=
le=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">get</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: #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"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">template</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </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"> T</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span st=
yle=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"colo=
r: #000;" class=3D"styled-by-prettify"> property<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></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">private</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; &nbsp; T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> m_ref</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>&nbsp; &nbsp; property</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><span style=3D"color: #008;" class=3D"styled-by=
-prettify">public</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; property</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> r</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: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> m_ref</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">r</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; </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>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> T </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ge=
t</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: #008;" class=3D"styled-by-prettify">const</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </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; &nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_ref</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: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D(</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> v</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: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; =
&nbsp; &nbsp; &nbsp; m_ref </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> v</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> m_ref</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; </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">operator</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> T </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>&nbsp; &nbsp; </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp=
; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">r=
eturn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_re=
f</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: #660;" class=3D"styled-by-prettify">}</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></span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Price</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></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-prettify">=
private</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">float=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_unitPri=
ce</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">float</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_vat</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> m_discount</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: #=
008;" class=3D"styled-by-prettify">public</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;property</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;float&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">UnitPrice</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;property</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;float&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> VAT</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; &nbsp;property</span><span style=3D"c=
olor: #080;" class=3D"styled-by-prettify">&lt;float&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Discount</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; &nbsp;computed_property</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">tuple</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">float<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&amp;,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">float</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;&gt;,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">float</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(*)(</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">tuple</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">float</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&amp;,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
onst</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">float</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&gt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&amp;)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">PriceTTC</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;computed_property</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">float</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">tu=
ple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&amp;,</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"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">float</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&amp;&gt;,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">float</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">co=
nst</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">tuple</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">const</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: #660;" class=
=3D"styled-by-prettify">&amp;,</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: #008;" class=3D"styled-by-prettify">flo=
at</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&amp;)</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Dis=
countedTotal</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
>&nbsp; &nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">Price</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"> <br>&nbsp; &nbsp; &nbsp; &=
nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">UnitP=
rice</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">m_unitPrice</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbs=
p; &nbsp;VAT</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">m_vat</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &n=
bsp; &nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Discount</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">m_discount=
</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; =
&nbsp; &nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">PriceTTC</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">tie</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">m_unitPrice</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> m_vat</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">),</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: #008;" class=3D"styled-by-prettify=
">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">tuple</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</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: #00=
8;" class=3D"styled-by-prettify">float</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"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">float</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&gt;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">values</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">-&gt;</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">float</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">return</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: #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"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">get</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">values</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 style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">100</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"> std</span><span style=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">&lt;</span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">values</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; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}),</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">DiscountedTotal</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">tie</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">m_unitP=
rice</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_vat</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> m_discount</span><span styl=
e=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: #660;=
" 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"s=
tyled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&amp;,</span><span style=3D"color:=
 #000;" 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">float</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&amp;,</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"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">values</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: #660;" class=3D"styled-by-prettify">-&=
gt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">float</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp; &nbsp; &nbsp;</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</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: #066;" class=3D"styl=
ed-by-prettify">1</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">+<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">get</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color:=
 #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">values</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 style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">100</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: #6=
60;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">get</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">values</span><sp=
an 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"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">get<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">values</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"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">2</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">values</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">/</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">100</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">));</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp;=
 &nbsp;</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: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp;</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><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> wmain</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> argc</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">wch=
ar_t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> argv</span><sp=
an 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>&nbsp; &nbsp; </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Price</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> cost</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; cost</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #606;=
" class=3D"styled-by-prettify">UnitPrice</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </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;" class=3D"styled-by-prett=
ify">200.0f</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; &nbsp; cost</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">VAT <=
/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">6.5f</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>&nbsp; &nbsp; cost</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Discount</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">10.0f</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">Price</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> secondCost </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
cost</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; =
&nbsp; std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #080;" class=3D"styled-by-prettify">"Unit Price: "</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> secondCost</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">UnitPrice</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" cl=
ass=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">endl</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; std</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>cout </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #080;" class=3D"styled-by-prettify">"VAT: "</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> secondCost</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">VAT </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"%"</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">"Discount: "</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> secondCost</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">.</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Discount</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pretti=
fy">"%"</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
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"> std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">endl</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"Price TTC: "</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> secondCost</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">.</span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">PriceTTC</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt=
;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">endl</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>&nbsp; &nbsp; std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" c=
lass=3D"styled-by-prettify">"Price Discounted: "</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> secondCost</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">.</span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">DiscountedTotal</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">e=
ndl</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &=
nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">retu=
rn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #066;" class=3D"styled-by-prettify">0</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;" clas=
s=3D"styled-by-prettify"><br><br></span></div></code></div><br>I'll be the =
first to admit that computed_property isn't pretty, but I'd still argue it'=
s better than the solution using offsetof, etc.<br><br>-Andrew Sandoval<br>=
&nbsp;<br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1403_15998708.1354063145013--

.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 16:46:50 -0800 (PST)
Raw View
------=_Part_1437_564622.1354063610495
Content-Type: text/plain; charset=ISO-8859-1

Personally, I would never support a library solution. It would be an
embarrassment if C++ had properties that came with a performance penalty.

And if you're worried about functionality being hidden and paying for
something you didn't expect, all these examples show that this is *already
happening*, and the price you're paying is *even worse* than if C++
supported properties natively.

--




------=_Part_1437_564622.1354063610495
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Personally, I would never support a library solution. It would be an embarr=
assment if C++ had properties that came with a performance penalty.<br><br>=
And if you're worried about functionality being hidden and paying for somet=
hing you didn't expect, all these examples show that this is <i>already hap=
pening</i>, and the price you're paying is <i>even worse</i> than if C++ su=
pported properties natively.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1437_564622.1354063610495--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Tue, 27 Nov 2012 19:03:46 -0600
Raw View
--0015175cd1e2c7fac104cf83d061
Content-Type: text/plain; charset=ISO-8859-1

On 27 November 2012 18:39, Andrew Sandoval <sandoval@netwaysglobal.com>wrote:

> Also, someone could easily add copy assignment, copy constructor, etc. to
> this,
>

Then please do so and show us the code.  My initial thought on it is making
property non-copyable, thus forcing Price to write an explicit copy
constructor.  But that doesn't exactly seem like something that is "easily"
done, as it is very intrusive, tedious and error prone.  Then add move
semantics.


> Just remember that anything that goes into the Standard Library can
> potentially be in production within a year or two.
>

Unlikely given there is no existing implementation, let alone field
experience.

I'll be the first to admit that computed_property isn't pretty, but I'd
> still argue it's better than the solution using offsetof, etc.
>

While I haven't looked at Matt Wilson's implementation in quite a while,
I'm pretty sure the offsetof stuff and macros are there to solve the
reference semantics problem.
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404

--




--0015175cd1e2c7fac104cf83d061
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 27 November 2012 18:39, Andrew Sandoval <span dir=3D"ltr">&lt;<a href=3D=
"mailto:sandoval@netwaysglobal.com" target=3D"_blank">sandoval@netwaysgloba=
l.com</a>&gt;</span> wrote:<br><div class=3D"gmail_quote"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">

<div class=3D"HOEnZb"><div class=3D"h5">Also, someone could easily add copy=
 assignment, copy constructor, etc. to this,</div></div></blockquote><div><=
br></div><div>Then please do so and show us the code. =A0My initial thought=
 on it is making property non-copyable, thus forcing Price to write an expl=
icit copy constructor. =A0But that doesn&#39;t exactly seem like something =
that is &quot;easily&quot; done, as it is very intrusive, tedious and error=
 prone. =A0Then add move semantics.</div>

<div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div class=3D"HOEnZb"><div cla=
ss=3D"h5">Just remember that anything that goes into the Standard Library c=
an potentially be in production within a year or two.=A0</div>

</div></blockquote><div><br></div><div>Unlikely given there is no existing =
implementation, let alone field experience.</div><div><br></div><blockquote=
 class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">

<div>I&#39;ll be the first to admit that computed_property isn&#39;t pretty=
, but I&#39;d still argue it&#39;s better than the solution using offsetof,=
 etc.</div></blockquote><div><br></div><div>While I haven&#39;t looked at M=
att Wilson&#39;s implementation in quite a while, I&#39;m pretty sure the o=
ffsetof stuff and macros are there to solve the reference semantics problem=
..</div>

</div>-- <br>=A0Nevin &quot;:-)&quot; Liber=A0 &lt;mailto:<a href=3D"mailto=
:nevin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>&gt;=
=A0 (847) 691-1404<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--0015175cd1e2c7fac104cf83d061--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 27 Nov 2012 17:15:34 -0800 (PST)
Raw View
------=_Part_133_23268635.1354065334226
Content-Type: text/plain; charset=ISO-8859-1



On Tuesday, November 27, 2012 4:39:04 PM UTC-8, Andrew Sandoval wrote:
>
> On Tuesday, November 27, 2012 5:42:02 PM UTC-6, Nicol Bolas wrote:
>>
>> On Tuesday, November 27, 2012 3:22:53 PM UTC-8, Andrew Sandoval wrote:
>>>
>>> On Tuesday, November 27, 2012 4:43:43 PM UTC-6, masse....@gmail.comwrote:
>>>>
>>>> In fact, with C++11, you could already do better.
>>>> Here a quick exemple I've just written :
>>>>
>>>> #include <iostream>
>>>> #include <functional>
>>>>
>>>> template<typename T>
>>>> struct property
>>>> {
>>>>    typedef std::function<T(void)> getter;
>>>>    typedef std::function<void(const T&)> setter;
>>>>    getter m_getter;
>>>>    setter m_setter;
>>>>
>>>>    operator T () { return m_getter(); }
>>>>    void operator= (const T& value) { m_setter(value); }
>>>> };
>>>>
>>>> class Price
>>>> {
>>>>    float m_unitPrice;
>>>>    float m_vat;
>>>> public:
>>>>    property<float> UnitPrice;
>>>>    property<float> VAT;
>>>>    property<float> PriceTTC;
>>>>
>>>> Price()
>>>> {
>>>>    UnitPrice = {
>>>>       [&]() { return m_unitPrice; },
>>>>       [&](float value) { m_unitPrice = value; },
>>>>    };
>>>>    VAT = {
>>>>       [&]() { return m_vat; },
>>>>       [&](float value) { m_vat = value; },
>>>>    };
>>>>    PriceTTC = {
>>>>       [&]() { return (1+ m_vat/100) * m_unitPrice; }
>>>>    };
>>>> }
>>>> };
>>>>
>>>> int main()
>>>> {
>>>>    Price X;
>>>>    X.UnitPrice = 5.0;
>>>>    X.VAT = 5.0;
>>>>    std::cout << X.PriceTTC;
>>>>    return 0;
>>>> }
>>>>
>>>> It does work, and once the property class have been declared, rest of
>>>> the code is easy to wrote.
>>>> But as you already pointed out, such an approach will consume a lot of
>>>> memory (3 more member, with 2 std::func each in my example, not speaking
>>>> about the lambda funcs), so I'm still looking for a better solution, and I
>>>> think i would require a change to the language, but I'm not 100% sure of
>>>> that yet.
>>>>
>>>>
>>>> Why not simplify this down...  The following solution doesn't handle
>>> your PriceTTC case, but that can probably be done cleverly another way --
>>> or better just as a function.  I don't follow other languages closely, but
>>> I don't think their properties do that kind of thing either...  So, this
>>> should be very light-weight w/regards to your memory (etc.) concerns, in
>>> fact I suspect it almost entirely is optimized away in release builds:
>>>
>>> #include <iostream>
>>>
>>> template <typename T>
>>> class property
>>> {
>>> private:
>>>     T& m_ref;
>>>     property();
>>> public:
>>>     property(T& r) : m_ref(r)
>>>     {
>>>     }
>>>
>>>     const T get() const
>>>     {
>>>         return m_ref;
>>>     }
>>>
>>>     const T& operator=(const T& v)
>>>     {
>>>         m_ref = v;
>>>         return m_ref;
>>>     }
>>>
>>>     operator T () const
>>>     {
>>>         return m_ref;
>>>     }
>>> };
>>>
>>> class Price
>>> {
>>> private:
>>>    float m_unitPrice;
>>>    float m_vat;
>>> public:
>>>    property<float> UnitPrice;
>>>    property<float> VAT;
>>>
>>>    Price(float fup, float fvat) : m_unitPrice(fup), m_vat(fvat),
>>>        UnitPrice(m_unitPrice),
>>>        VAT(m_vat)
>>>    {
>>>    }
>>> };
>>>
>>> int wmain(int argc, wchar_t* argv[])
>>> {
>>>     Price cost(1.2f, .065f);
>>>     std::cout << "Unit Price: " << cost.UnitPrice << std::endl;
>>>     std::cout << "VAT: " << cost.VAT << std::endl;
>>>
>>>     cost.UnitPrice = 2.40f;        // Inflation
>>>     std::cout << "Unit Price" << cost.UnitPrice << std::endl;
>>>
>>>     return 0;
>>> }
>>>
>>>
>>>
>>> -Andrew Sandoval
>>>
>>
>> A library solution is a terrible idea. Ignoring the deficiencies in your
>> particular implementation (copy-assignment, copy-construction, only works
>> with single member variables, instead of arbitrary code, etc), it has
>> other, more fundamental, flaws to this whole style of approach.
>>
>> For example, any class that uses it instantly stops being standard layout
>> and trivial. Why? There's no reason for that; I shouldn't have to give up
>> these class features just because I want to provide a (theoretically)
>> better user interface.
>>
>> Look, I personally am not a fan of properties. But if the decision is
>> made to add them to C++, then they need to be added *properly* as a
>> first-class language feature. Not as some obvious library hack like this.
>> That's why they're adding real polymorphic lambda functions to C++, rather
>> than trying to add hacks like Boost.Phoenix and so forth.
>>
>> If it's going to be done, then do it for real. Just because you might be
>> able to do it via the library doesn't mean you *should.*
>>
>
> I'd argue just the opposite.  I'm not a fan of properties either, but if
> it needs to be there I'd rather see it in the standard library than to see
> the language implement something that hides functionality (potentially).
>

How would a proper language feature hide *functionality*, of all things?


>
> Also, someone could easily add copy assignment, copy constructor, etc. to
> this, but it works pretty close to the way properties work where ever I've
> seen them used...  And if you really need multiple values, etc. another
> class can do it, like the computed_property below.
>
> The ugliest part of this is that you can't use a lambda in a typedef, so
> putting something like this in a class is ugly still.  Or, like
> computed_property below it requires using a function pointer...
>
> Just remember that anything that goes into the Standard Library can
> potentially be in production within a year or two.  Any core language
> changes are 2014 at the soonest.
>

Better done correctly later than done poorly now. Remember: we're talking
about something that exists *solely* for the convenience of the programmer.
It can wait.

--




------=_Part_133_23268635.1354065334226
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Tuesday, November 27, 2012 4:39:04 PM UTC-8, Andrew Sandoval wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday, November 27, 20=
12 5:42:02 PM UTC-6, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex">On Tuesday, November 27, 2012 3:22:53 PM UTC-8, Andrew Sandoval wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;padding-left:1ex">On Tuesday, November 27, 2012 4:43:4=
3 PM UTC-6, <a>masse....@gmail.com</a> wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div>In fact, with C++11, you could already do better.<br></div><=
div>Here a quick exemple I've just written :</div><div><br></div><div>#incl=
ude &lt;iostream&gt;<br>#include &lt;functional&gt;<br><br>template&lt;type=
name T&gt;<br>struct property<br>{<br>&nbsp; &nbsp;typedef std::function&lt=
;T(void)&gt; getter;<br> &nbsp; &nbsp;typedef std::function&lt;void(const T=
&amp;)&gt; setter;<br> &nbsp; &nbsp;getter m_getter;<br> &nbsp; &nbsp;sette=
r m_setter;<br> <br> &nbsp; &nbsp;operator T () { return m_getter(); }<br> =
&nbsp; &nbsp;void operator=3D (const T&amp; value) { m_setter(value); }<br>=
};<br><br>class Price<br>{<br> &nbsp; &nbsp;float m_unitPrice;<br> &nbsp; &=
nbsp;float m_vat;<br> public:<br> &nbsp; &nbsp;property&lt;float&gt; UnitPr=
ice;<br> &nbsp; &nbsp;property&lt;float&gt; VAT;<br> &nbsp; &nbsp;property&=
lt;float&gt; PriceTTC; <br> <br> Price() <br> { <br>  &nbsp; &nbsp;UnitPric=
e =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return m_unitPrice; },<=
br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;](float value) {  m_unitPrice =3D val=
ue; },<br>  &nbsp; &nbsp;};<br>  &nbsp; &nbsp;VAT =3D {<br>   &nbsp; &nbsp;=
&nbsp; &nbsp;[&amp;]() { return m_vat; },<br>   &nbsp; &nbsp;&nbsp; &nbsp;[=
&amp;](float value) { m_vat =3D value; },<br>  &nbsp; &nbsp;};<br>  &nbsp; =
&nbsp;PriceTTC =3D {<br>   &nbsp; &nbsp;&nbsp; &nbsp;[&amp;]() { return (1+=
 m_vat/100) * m_unitPrice; }<br>  &nbsp; &nbsp;};<br> }<br>};<br><br>int ma=
in()<br>{<br> &nbsp; &nbsp;Price X;<br> &nbsp; &nbsp;X.UnitPrice =3D 5.0;<b=
r> &nbsp; &nbsp;X.VAT =3D 5.0;<br> &nbsp; &nbsp;std::cout &lt;&lt; X.PriceT=
TC;<br> &nbsp; &nbsp;return 0;<br>}</div><div><br></div><div>It does work, =
and once the property class have been declared, rest of the code is easy to=
 wrote.</div><div>But
 as you already pointed out, such an approach will consume a lot of=20
memory (3 more member, with 2 std::func each in my example, not speaking
 about the lambda funcs), so I'm still looking for a better solution,=20
and I think i would require a change to the language, but I'm not 100%=20
sure of that yet.</div><div><br></div><br></blockquote><div>Why not=20
simplify this down...&nbsp; The following solution doesn't handle your=20
PriceTTC case, but that can probably be done cleverly another way -- or=20
better just as a function.&nbsp; I don't follow other languages closely, bu=
t I
 don't think their properties do that kind of thing either...&nbsp; So, thi=
s=20
should be very light-weight w/regards to your memory (etc.) concerns, in
 fact I suspect it almost entirely is optimized away in release builds:<br>=
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#800">#include</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#080">&lt;iostrea=
m&gt;</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#008">template</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#008">typename</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> property<br></span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#008">private</span>=
<span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &n=
bsp; T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#0=
00"> m_ref</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br>&nbsp; &nbsp; property</span><span style=3D"color:#660">();</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">public</spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; =
&nbsp; property</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">T</span><span style=3D"color:#660">&amp;</span><span style=3D"colo=
r:#000"> r</span><span style=3D"color:#660">)</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">:</span><span style=3D"color:#000"> =
m_ref</span><span style=3D"color:#660">(</span><span style=3D"color:#000">r=
</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">c=
onst</span><span style=3D"color:#000"> T </span><span style=3D"color:#008">=
get</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color:#008">=
return</span><span style=3D"color:#000"> m_ref</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#000"> T<=
/span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">operator</span><span style=3D"color:#660">=
=3D(</span><span style=3D"color:#008">const</span><span style=3D"color:#000=
"> T</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000=
"> v</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><b=
r>&nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; m_ref </span><span style=3D"color=
:#660">=3D</span><span style=3D"color:#000"> v</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#008">operator</s=
pan><span style=3D"color:#000"> T </span><span style=3D"color:#660">()</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">const</span=
><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> m_r=
ef</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"color=
:#000"><br><br></span><span style=3D"color:#008">class</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">Price</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#008">private</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span>=
<span style=3D"color:#008">float</span><span style=3D"color:#000"> m_unitPr=
ice</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp;</span><span style=3D"color:#008">float</span><span style=3D"=
color:#000"> m_vat</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">public</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp;propert=
y</span><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">UnitPrice</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp;property</spa=
n><span style=3D"color:#080">&lt;float&gt;</span><span style=3D"color:#000"=
> VAT</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br><br>&nbsp; &nbsp;</span><span style=3D"color:#606">Price</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#008">float</span><span styl=
e=3D"color:#000"> fup</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">float</span><span style=
=3D"color:#000"> fvat</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"> m_unitPrice</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">fup</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"> m_vat</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">fvat</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:=
#606">UnitPrice</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">m_unitPrice</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;VAT</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">m_vat</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp;</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:#000"><br><br></s=
pan><span style=3D"color:#008">int</span><span style=3D"color:#000"> wmain<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#000"> argc</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">wchar_t</sp=
an><span style=3D"color:#660">*</span><span style=3D"color:#000"> argv</spa=
n><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>&nbsp; =
&nbsp; </span><span style=3D"color:#606">Price</span><span style=3D"color:#=
000"> cost</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
66">1.2f</span><span style=3D"color:#660">,</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">.</span><span style=3D"color:#066">065=
f</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price: "</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span=
><span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span>=
<span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"VAT: "</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><span sty=
le=3D"color:#000">VAT </span><span style=3D"color:#660">&lt;&lt;</span><spa=
n style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span=
 style=3D"color:#000">endl</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br><br>&nbsp; &nbsp; cost</span><span style=3D"color:#=
660">.</span><span style=3D"color:#606">UnitPrice</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2.40f</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"> &nbsp; &nbsp; &nbsp; &nbsp;</span><=
span style=3D"color:#800">// Inflation</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D=
"color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#080">"Unit Price"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&lt;</span>=
<span style=3D"color:#000"> cost</span><span style=3D"color:#660">.</span><=
span style=3D"color:#606">UnitPrice</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> std=
</span><span style=3D"color:#660">::</span><span style=3D"color:#000">endl<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br=
>&nbsp; &nbsp; </span><span style=3D"color:#008">return</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=3D"c=
olor:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#660">}</span><span style=3D"color:#000"><br><br></span></div></code></d=
iv><br><br>-Andrew Sandoval <br></div></blockquote><div><br>A
 library solution is a terrible idea. Ignoring the deficiencies in your=20
particular implementation (copy-assignment, copy-construction, only works w=
ith single member variables, instead of arbitrary code, etc), it has other,=
 more fundamental, flaws to this whole style of approach.<br><br>For exampl=
e, any class that uses it instantly stops being standard layout and trivial=
.. Why? There's no reason for that; I shouldn't have to give up these class =
features just because I want to provide a (theoretically) better user inter=
face.<br><br>Look, I personally am not a fan of properties. But if the deci=
sion is made to add them to C++, then they need to be added <i>properly</i>=
 as a first-class language feature. Not as some obvious library hack like t=
his. That's why they're adding real polymorphic lambda functions to C++, ra=
ther than trying to add hacks like Boost.Phoenix and so forth.<br><br>If it=
's going to be done, then do it for real. Just because you might be able to=
 do it via the library doesn't mean you <i>should.</i><br></div></blockquot=
e><div><br>I'd argue just the opposite.&nbsp; I'm not a fan of properties e=
ither, but if it needs to be there I'd rather see it in the standard librar=
y than to see the language implement something that hides functionality (po=
tentially).<br></div></blockquote><div><br>How would a proper language feat=
ure hide <i>functionality</i>, of all things?<br>&nbsp;</div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><div><br>Also, someone could easily add copy=
 assignment, copy constructor, etc. to this, but it works pretty close to t=
he way properties work where ever I've seen them used...&nbsp; And if you r=
eally need multiple values, etc. another class can do it, like the computed=
_property below.<br><br>The ugliest part of this is that you can't use a la=
mbda in a typedef, so putting something like this in a class is ugly still.=
&nbsp; Or, like computed_property below it requires using a function pointe=
r...<br><br>Just remember that anything that goes into the Standard Library=
 can potentially be in production within a year or two.&nbsp; Any core lang=
uage changes are 2014 at the soonest.<br></div></blockquote><br>Better done=
 correctly later than done poorly now. Remember: we're talking about someth=
ing that exists <i>solely</i> for the convenience of the programmer. It can=
 wait.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_133_23268635.1354065334226--

.


Author: rick@longbowgames.com
Date: Tue, 27 Nov 2012 17:50:58 -0800 (PST)
Raw View
------=_Part_1313_16889440.1354067458955
Content-Type: text/plain; charset=ISO-8859-1

I forgot that way back in 2004, there was a proposal for Implicitly
Callable Functions<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1611.pdf>that had some support for properties, although they were still awkward and
had a (smaller) performance penalty. The prime motivation was to define
constants, which is particularly weak now that constexpr exists.

For reference, Microsoft implemented properties using __declspec(property)<http://msdn.microsoft.com/en-us/library/yhfk0thd.aspx>,
and clang supports the same syntax in order to parse Microsoft files.

--




------=_Part_1313_16889440.1354067458955
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I forgot that way back in 2004, there was a proposal for <a href=3D"http://=
www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1611.pdf">Implicitly Call=
able Functions</a> that had some support for properties, although they were=
 still awkward and had a (smaller) performance penalty. The prime motivatio=
n was to define constants, which is particularly weak now that constexpr ex=
ists.<br><br>For reference, Microsoft implemented properties using <a href=
=3D"http://msdn.microsoft.com/en-us/library/yhfk0thd.aspx">__declspec(prope=
rty)</a>, and clang supports the same syntax in order to parse Microsoft fi=
les.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1313_16889440.1354067458955--

.


Author: Andrew Sandoval <sandoval@netwaysglobal.com>
Date: Tue, 27 Nov 2012 19:58:01 -0800 (PST)
Raw View
------=_Part_2209_21562107.1354075081116
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, November 27, 2012 7:03:46 PM UTC-6, Nevin ":-)" Liber wrote:
>
> On 27 November 2012 18:39, Andrew Sandoval <sand...@netwaysglobal.com<javascript:>
> > wrote:
>
>> Also, someone could easily add copy assignment, copy constructor, etc. to
>> this,
>>
>
> Then please do so and show us the code.  My initial thought on it is
> making property non-copyable, thus forcing Price to write an explicit copy
> constructor.  But that doesn't exactly seem like something that is "easily"
> done, as it is very intrusive, tedious and error prone.  Then add move
> semantics.
>
>
>> Just remember that anything that goes into the Standard Library can
>> potentially be in production within a year or two.
>>
>
> Unlikely given there is no existing implementation, let alone field
> experience.
>
> I'll be the first to admit that computed_property isn't pretty, but I'd
>> still argue it's better than the solution using offsetof, etc.
>>
>
> While I haven't looked at Matt Wilson's implementation in quite a while,
> I'm pretty sure the offsetof stuff and macros are there to solve the
> reference semantics problem.
> --
>  Nevin ":-)" Liber  <mailto:ne...@eviloverlord.com <javascript:>>  (847)
> 691-1404
>

No, you (and others) are right.  I wasn't counting the cost of initializing
the references.  I was only considering the cost of using the property
objects, which *is* optimized away by my compiler.  It would be cool if you
could do something like:

template <typename T, T& tref)
class property
{
    // operator=, operator T () const, etc. here..., returning tref, etc.,
e.g.
    operator T () const { return tref; }
};

class Price
{
private:
    float m_fUnitPrice;
public:
    property<float, m_fUnitPrice> UnitPrice;
....
};

But, obviously that will not work with classes.

And I'll admit that I glossed over the other implementation as soon as I
saw more than one macro.

So, I'm not going to argue for or (more accurately) against this any more.
I can see that it has some value, even if I am not accustomed to using
properties.

-Andrew Sandoval

--




------=_Part_2209_21562107.1354075081116
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 27, 2012 7:03:46 PM UTC-6, Nevin ":-)" Liber wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;">On 27 November 2012 18:39, Andrew=
 Sandoval <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" g=
df-obfuscated-mailto=3D"kk4n94q2IjIJ">sand...@netwaysglobal.com</a>&gt;</sp=
an> wrote:<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>Also, someone could easily add copy assignment, copy constructor,=
 etc. to this,</div></div></blockquote><div><br></div><div>Then please do s=
o and show us the code. &nbsp;My initial thought on it is making property n=
on-copyable, thus forcing Price to write an explicit copy constructor. &nbs=
p;But that doesn't exactly seem like something that is "easily" done, as it=
 is very intrusive, tedious and error prone. &nbsp;Then add move semantics.=
</div>

<div>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Just remember tha=
t anything that goes into the Standard Library can potentially be in produc=
tion within a year or two.&nbsp;</div>

</div></blockquote><div><br></div><div>Unlikely given there is no existing =
implementation, let alone field experience.</div><div><br></div><blockquote=
 class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">

<div>I'll be the first to admit that computed_property isn't pretty, but I'=
d still argue it's better than the solution using offsetof, etc.</div></blo=
ckquote><div><br></div><div>While I haven't looked at Matt Wilson's impleme=
ntation in quite a while, I'm pretty sure the offsetof stuff and macros are=
 there to solve the reference semantics problem.</div>

</div>-- <br>&nbsp;Nevin ":-)" Liber&nbsp; &lt;mailto:<a href=3D"javascript=
:" target=3D"_blank" gdf-obfuscated-mailto=3D"kk4n94q2IjIJ">ne...@eviloverl=
ord.com</a><wbr>&gt;&nbsp; (847) 691-1404<br></blockquote><div><br>No, you =
(and others) are right.&nbsp; I wasn't counting the cost of initializing th=
e references.&nbsp; I was only considering the cost of using the property o=
bjects, which <i>is</i> optimized away by my compiler.&nbsp; It would be co=
ol if you could do something like:<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 clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">template</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </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-b=
y-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> tref</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">class</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> property<br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">// operator=3D, operator T () const, etc.=
 here..., returning tref, etc., e.g.</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">operator</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> T </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">const</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"> tref</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"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
lass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Price</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></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: #0=
08;" class=3D"styled-by-prettify">private</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">float</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> m_fUnitPrice</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"style=
d-by-prettify">public</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; property</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">float</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m=
_fUnitPrice</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">UnitPrice</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">...</span><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></span></div></code></div><br>But, obviously =
that will not work with classes.<br><br>And I'll admit that I glossed over =
the other implementation as soon as I saw more than one macro.<br><br>So, I=
'm not going to argue for or (more accurately) against this any more.&nbsp;=
 I can see that it has some value, even if I am not accustomed to using pro=
perties.<br><br>-Andrew Sandoval<br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2209_21562107.1354075081116--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 08:23:09 +0200
Raw View
On 27 November 2012 22:33,  <adi.hodos@gmail.com> wrote:
> It would return the value of the component. What else could it return (in
> this case) ?
> class vector3F {
> private :
>     union {
>         float vecdata_[4];
>
>     };
>     float get_x() const {
>         return x_;
>     }
>     void set_x(float val) {
>         vecdata_[0] = val;
>
>     }
> public :
>     property X { get = get_x, set = set_x };
> } __attribute__((align(16)));
> It's just syntactic sugar, allowing the client to simply write v.X instead
> of v.get_x() . Much more readable. and concise.

If I have to write such getters/setters anyway, I'll name them both x().
For a property solution, I'd expect having default getter/setter generated,
but again, for cases where I have to write the functions anyway, properties
buy me *very* little.

> The misuse part : the class is exposing to the client its internals. The
> fact that there's an array of four floats is an implementation detail. It is
> needed because of that way SSE instructions work. For a three component
> vector, the W/vecdata_[3] member must always be set to zero, since it has no
> meaning. But since it's available in the public interface, its all too easy
> to write v.W = 2.0f without even thinking.

The repercussions of writing v.W = 2.0f seem rather small to me, but I see
your point about exposing the internals.

--




.


Author: Fabio Fracassi <f.fracassi@gmx.net>
Date: Wed, 28 Nov 2012 08:59:53 +0100
Raw View
On 11/27/12 6:21 PM, Olaf van der Spek wrote:
> On Tue, Nov 27, 2012 at 6:06 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>> On 27 November 2012 18:18, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>
>> They seem to try and solve similar problems. Compile-time reflection is
>> expected to provide access to members by name, and to allow programmers
>> to customize how a given member gets accessed, or to allow accessing
>> names not backed by actual members. Or, well, that's on my wishlist,
>> and some people I've discussed reflection with seem to agree.
> Properties and reflection might have some overlap, but it's not clear
> to me how they're similar problems.
>
>
If you have sufficiently comprehensive static reflection facilities,
properties can be implemented as a library.
It might still make sense to have them as a "first-class" language
feature, for better syntax, or faster compile speed, though.

regards

Fabio

--




.


Author: adi.hodos@gmail.com
Date: Wed, 28 Nov 2012 01:54:45 -0800 (PST)
Raw View
------=_Part_1468_7183985.1354096485876
Content-Type: text/plain; charset=ISO-8859-1


IMHO it does not make any sense to copy/copy construct/take the address
address/initialize a reference to a property, so those operations should be
compile errors (can you call swap for operator+= with two objects that
implement it ?).
A property is just a shortcut for a call to the get/set function, just like
an overloaded operator.
A property may be backed by a data member :

//
// NOT VALID C++, just a concept

class Window {
private :
  vector2<int> dimensions_;

  int get_height() const { return dimensions_.X; }
  void set_height(int x) { dimensions_.X = x; }

public :
 property Height { get =  ()  { return dimensions_.X; }, set = (int x) {dimensions_
..X = x } }
};


Or, it could simply be a computation that gives a certain characteristic of
the object :

//
// Not valid C++, just a concept
class vector3 {
private :
  float data_[3];

public :
  property LengthSquared { get = ()  { return data_[0] * data_[0] + data_[1]
* data_[1] + data_[2] * data_[2]; } }
};



So code like this :

vector3 v0;
vector3 v1;
std::swap(v0.LengthSquared, v1.LengthSquared)


does not make any sense and would be a compile error.

--




------=_Part_1468_7183985.1354096485876
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br>IMHO it does not make any sense to copy/copy construct/take the address=
 address/initialize a reference to a property, so those operations should b=
e compile errors (can you call swap for operator+=3D with two objects that =
implement it ?).<br>A property is just a shortcut for a call to the get/set=
 function, just like an overloaded operator.<br>A property may be backed by=
 a data member :<br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-b=
y-prettify">//</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
 NOT VALID C++, just a concept</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">Window</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 s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">private</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; vector2</span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> dimensions_</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>&nbsp; </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> get_height</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"style=
d-by-prettify">const</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: #008;" class=3D"styled-by-prettify">return</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> dimensions_</span><s=
pan 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">;</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>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> set_height</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">in=
t</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 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"> dimensions_</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"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> x</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"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>&nbsp;property </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Height</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"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">get</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp;</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> &nbsp;</span><span style=3D"co=
lor: #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">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> dimensions_</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">X</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: #660;" class=3D"styled-by-prettify">},</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">set</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </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: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">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"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> dimensions_</span><span style=3D"co=
lor: #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"color: #000;" class=3D"sty=
led-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"=
> </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></div></code></d=
iv><br>Or, it could simply be a computation that gives a certain characteri=
stic of the object :<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"prettyprin=
t"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">//</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// Not valid C++, just a concept</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> vector3 </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">pri=
vate</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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">float</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> data_</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">3</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">];</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">public</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>&nb=
sp; property </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">LengthSquared</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"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </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: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> &nbsp;</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">retur=
n</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> data_</s=
pan><span style=3D"color: #660;" 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"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> data_</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">0</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"> data_</span><span style=3D"colo=
r: #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-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> data_=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><s=
pan 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-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">+</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> data_</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> data_</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">];</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</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></span></div></code></div=
><br><br>So code like this :<br><br><div class=3D"prettyprint" style=3D"bac=
kground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border=
-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">vector3 v0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>vector3 v1</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>std</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">s=
wap</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">v0</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">LengthSquared</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> v1</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">.</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">LengthSquared</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br></span></div></code></div><br>does not make any s=
ense and would be a compile error.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1468_7183985.1354096485876--

.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 12:12:58 +0100
Raw View
On Tue, Nov 27, 2012 at 6:51 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
>> Eh, what do you mean? The advantages of properties are clear, aren't they?
>> The only question is how to best implement them.
>> Take containers for example. "if (s.size >= 8)" looks a bit cleaner
>> than "if (s.size() >= 8)".
>
> I don't find that difference significant.

But you agree it's cleaner?

> And regarding the advantages, when I
> consider writing a normal member function vs. writing a property function (if I
> need more complex processing than just accessing a member), it's even less
> clear to me.

True, but you can't go from public data member to member function
without affecting clients.


On Tue, Nov 27, 2012 at 8:26 PM,  <adi.hodos@gmail.com> wrote:
> Olaf, you can implement properties via templates plus some macros. It's
> described in Matthew Wilson's Imperfect C++, section 35 if I remember
> exactly. My approach is mostly based on code in that book. But it's not
> pretty.

I know, I know, but this is about finding a good (perfect?) solution.


On Tue, Nov 27, 2012 at 9:39 PM, Martinho Fernandes
<martinho.fernandes@gmail.com> wrote:
> Except this one is on the eye of the beholder. Personally, I don't think
> `xxx()` is much more verbose than `xxx`.

So you agree it's more verbose?
The difference is bigger with v.set_name("Olaf") vs v.name = "Olaf";
v.name("Olaf") is shorter but less clear.


On Tue, Nov 27, 2012 at 11:53 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
>> Don't forget the other advantage of properties: being able to move from
>> public data members to properties without changing client syntax.
>
> This is in general not exactly true as showed at the beginning of this
> thread

Where exactly? I'm sure lots of people would be very happy if you've
got a solution that's not worse in memory/performance than a data
member / member function. Bonus points if the definition syntax is
clean too.

> Also, how does it interact with template argument deduction and
> references? For example, I can imagine that this won't work:
>
>   SomeClass object;
>   object.prop1 = 17;
>   object.prop2 = 29;
>   std::swap(object.prop1, object.prop2);

If get returns non-const& it'd work, otherwise it wouldn't.

>   auto mptr = &SomeClass::prop1;
>   (object.*mptr) = 99;

This might still work, although mptr would not be a regular member ptr.


On Wed, Nov 28, 2012 at 12:34 AM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
>> Eh, what do you mean? The advantages of properties are clear, aren't they?
>> The only question is how to best implement them.
>
>
> Before implementing, the problem is how to define and integrate them in an
> already complex language. Adding a new kind of member implies seen how this
> new member and the rest of the language interact. I don't know if some of
> the posters is ready to start a proposal that describes all these
> interactions, but be sure the list is longuer than you could expect.

That's the how question. So we do agree that if possible, properties
would be good to have?

> I agree and I would like to see well defined properties already in C++, but
> they are not in, and define them will need to respond to questions like

Let's try

> * what &s.size mean?

If get returns a non-const&, it'd be the pointer as usual.
Otherwise, it'd be a member pointer to the property.

> * can we store property members?

What do you mean?

> * could a property be used as a 'function'? would it be a getter or a
> setter? do we need std::mem_property? std::bind_property? ...

Probably not.

> * could rw properties be swapped?

If a non-const& is available

> * could properties be indexed?

Probably

> * could properties be returned by functions?
> * could properties be used as function parameters?
> * could properties be used as template parameters?

Probably not, to all three.

> In summary, are properties 1st class citizen entities?
>
> Whether it is worth doing it or not is an open question. Any one
> voluntering?

I think the question is when (and by who), not if.

On Wed, Nov 28, 2012 at 1:39 AM, Andrew Sandoval
<sandoval@netwaysglobal.com> wrote:
> Just remember that anything that goes into the Standard Library can
> potentially be in production within a year or two.  Any core language
> changes are 2014 at the soonest.

That's not how we decide between language and library.


--
Olaf

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 13:28:40 +0200
Raw View
On 28 November 2012 13:12, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>> Take containers for example. "if (s.size >= 8)" looks a bit cleaner
>>> than "if (s.size() >= 8)".
>> I don't find that difference significant.
> But you agree it's cleaner?

No, I don't. If I did agree, I'd say that it's significant. ;)

>> And regarding the advantages, when I
>> consider writing a normal member function vs. writing a property function (if I
>> need more complex processing than just accessing a member), it's even less
>> clear to me.
> True, but you can't go from public data member to member function
> without affecting clients.

If I expect the internal representation to change over time, I will
write a function.
If I make a design mistake and have to change from data member to
member function,
I consider that my problem, not the standard's problem.

>> Except this one is on the eye of the beholder. Personally, I don't think
>> `xxx()` is much more verbose than `xxx`.
> So you agree it's more verbose?
> The difference is bigger with v.set_name("Olaf") vs v.name = "Olaf";
> v.name("Olaf") is shorter but less clear.

It's v.name() = "Olaf" if your accessing function returns a reference.

I'd say I'm lukewarm towards properties. I used to want them badly,
but as years have gone
by, I've found fewer and fewer needs for properties.

--




.


Author: =?ISO-8859-1?Q?Mikael_Kilpel=E4inen?=
Date: Wed, 28 Nov 2012 12:43:16 +0100
Raw View
> If get returns non-const&  it'd work, otherwise it wouldn't.
>
>
Doesn't this defeat half of the purpose, if you expose internals via
reference?

Anyhow, for me properties just seem like one more incarnation of being
able to make perfect proxy types.


Mikael

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 12:47:30 +0100
Raw View
On Wed, Nov 28, 2012 at 12:28 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 28 November 2012 13:12, Olaf van der Spek <olafvdspek@gmail.com> wrote=
:
>>>> Take containers for example. "if (s.size >=3D 8)" looks a bit cleaner
>>>> than "if (s.size() >=3D 8)".
>>> I don't find that difference significant.
>> But you agree it's cleaner?
>
> No, I don't. If I did agree, I'd say that it's significant. ;)

Can't it be insignificantly cleaner?

>> True, but you can't go from public data member to member function
>> without affecting clients.
>
> If I expect the internal representation to change over time, I will
> write a function.

It's not just about internal representation. What if you wanted to add chec=
ks?

With properties you wouldn't have to make that decision.

> If I make a design mistake and have to change from data member to
> member function,
> I consider that my problem, not the standard's problem.

Sure, but again, properties would avoid that problem altogether.

>>> Except this one is on the eye of the beholder. Personally, I don't thin=
k
>>> `xxx()` is much more verbose than `xxx`.
>> So you agree it's more verbose?
>> The difference is bigger with v.set_name("Olaf") vs v.name =3D "Olaf";
>> v.name("Olaf") is shorter but less clear.
>
> It's v.name() =3D "Olaf" if your accessing function returns a reference.

A non-const reference? That's not your typical get/set function, is it?

On Wed, Nov 28, 2012 at 12:43 PM, Mikael Kilpel=E4inen
<mikael.kilpelainen@gmail.com> wrote:
>> If get returns non-const&  it'd work, otherwise it wouldn't.
>>
>>
> Doesn't this defeat half of the purpose, if you expose internals via
> reference?

That's a per-property decision a developer has to make. For some
properties a non-const reference makes sense, for others it doesn't.
--=20
Olaf

--=20




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 13:52:01 +0200
Raw View
On 28 November 2012 13:47, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>> No, I don't. If I did agree, I'd say that it's significant. ;)
> Can't it be insignificantly cleaner?

I find it questionable whether it's cleaner. It's shorter. That's not
the same thing.

>> If I expect the internal representation to change over time, I will
>> write a function.
> It's not just about internal representation. What if you wanted to add checks?
> With properties you wouldn't have to make that decision.

I know it's not just about internal representation. If I expect to have to cope
with a changing representation *or* I expect to add checks or whatever, I'll
write a function. It's barely different from deciding to use a property instead
of member access.

>> If I make a design mistake and have to change from data member to
>> member function,
>> I consider that my problem, not the standard's problem.
> Sure, but again, properties would avoid that problem altogether.

Do they? I expect clients to have to rebuild anyway, although they don't need
to be changed. If I design correctly from the get-go, I don't need subsequent
client recompiles when the implementation of the accessing functions change
but the signatures of them doesn't, and the representation doesn't.

>> It's v.name() = "Olaf" if your accessing function returns a reference.
> A non-const reference? That's not your typical get/set function, is it?

Oh, it's very typical, vector and map have operator[] that is exactly that kind
of a getter.

--




.


Author: =?ISO-8859-1?Q?Mikael_Kilpel=E4inen?=
Date: Wed, 28 Nov 2012 12:57:11 +0100
Raw View
> That's a per-property decision a developer has to make. For some
> properties a non-const reference makes sense, for others it doesn't.
I don't quite see how that makes sense, if you expose the reference you
can effective by pass the properties 'set'.
This means the 'set' has to be trivial in that sense for it not to be
surprising .. which in other hand implies that the 'get' is
trivial as well.. so why not just have public member variable then? Or
was there some other use case?


Mikael

--




.


Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Wed, 28 Nov 2012 12:59:24 +0100
Raw View
--f46d042f9d0efbbaf004cf8ce673
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Nov 28, 2012 at 12:47 PM, Olaf van der Spek <olafvdspek@gmail.com>wrote:

> It's not just about internal representation. What if you wanted to add
> checks?
>
>
If you add checks, you are changing the preconditions. That is a breaking
change. I don't like it when my breaking changes compile silently.

Martinho

--




--f46d042f9d0efbbaf004cf8ce673
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div class=3D"gmail_quote">On Wed, Nov 28, 2012 at 12:47 PM, Olaf van der S=
pek <span dir=3D"ltr">&lt;<a href=3D"mailto:olafvdspek@gmail.com" target=3D=
"_blank">olafvdspek@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex">

It&#39;s not just about internal representation. What if you wanted to add =
checks?<br>
<br></blockquote><div><br clear=3D"all">If you add checks, you are changing=
 the preconditions. That is a breaking change. I don&#39;t like it when my =
breaking changes compile silently.<br><br>Martinho<br>
<br>=A0</div></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--f46d042f9d0efbbaf004cf8ce673--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 14:04:52 +0200
Raw View
On 28 November 2012 13:59, Martinho Fernandes
<martinho.fernandes@gmail.com> wrote:
>> It's not just about internal representation. What if you wanted to add
>> checks?
> If you add checks, you are changing the preconditions. That is a breaking
> change. I don't like it when my breaking changes compile silently.

To be fair, that's not a property-specific problem.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 13:06:16 +0100
Raw View
On Wed, Nov 28, 2012 at 12:52 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> I know it's not just about internal representation. If I expect to have to cope
> with a changing representation *or* I expect to add checks or whatever, I'll
> write a function. It's barely different from deciding to use a property instead
> of member access.

Is it? You can go from data member to property without changing clients.

>>> If I make a design mistake and have to change from data member to
>>> member function,
>>> I consider that my problem, not the standard's problem.
>> Sure, but again, properties would avoid that problem altogether.
>
> Do they? I expect clients to have to rebuild anyway, although they don't need

Rebuilding is not a problem IMO.

> to be changed. If I design correctly from the get-go, I don't need subsequent

But not everything is (or even can be) designed right from the get-go.

> client recompiles when the implementation of the accessing functions change
> but the signatures of them doesn't, and the representation doesn't.
>
>>> It's v.name() = "Olaf" if your accessing function returns a reference.
>> A non-const reference? That's not your typical get/set function, is it?
>
> Oh, it's very typical, vector and map have operator[] that is exactly that kind
> of a getter.

It's a typical function, but it's not a getter IMO.
You're also ignoring the case when that kind of access function isn't usable.


--
Olaf

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 13:09:42 +0100
Raw View
On Wed, Nov 28, 2012 at 12:57 PM, Mikael Kilpel=E4inen
<mikael.kilpelainen@gmail.com> wrote:
>> That's a per-property decision a developer has to make. For some
>> properties a non-const reference makes sense, for others it doesn't.
>
> I don't quite see how that makes sense, if you expose the reference you c=
an
> effective by pass the properties 'set'.
> This means the 'set' has to be trivial in that sense for it not to be
> surprising .. which in other hand implies that the 'get' is
> trivial as well.. so why not just have public member variable then? Or wa=
s
> there some other use case?

Look at the vector example. It allows you to provide an alias, for
example x for v[0], y for v[1], etc.
Or length for size.


On Wed, Nov 28, 2012 at 12:59 PM, Martinho Fernandes
<martinho.fernandes@gmail.com> wrote:
> If you add checks, you are changing the preconditions.

Maybe, maybe not. Maybe you're adding a check for an existing precondition.

Olaf

--=20




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 14:10:04 +0200
Raw View
On 28 November 2012 14:06, Olaf van der Spek <olafvdspek@gmail.com> wrote:
> On Wed, Nov 28, 2012 at 12:52 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>> I know it's not just about internal representation. If I expect to have to cope
>> with a changing representation *or* I expect to add checks or whatever, I'll
>> write a function. It's barely different from deciding to use a property instead
>> of member access.
> Is it? You can go from data member to property without changing clients.
>> Do they? I expect clients to have to rebuild anyway, although they don't need
> Rebuilding is not a problem IMO.

Having to change client code and having to rebuild client code are different
problems, but neither of them is insignificant. I didn't mean to imply that it's
not costly to change a client, but I'd also like to point out that
it's not without
cost to have to rebuild a client.

>> to be changed. If I design correctly from the get-go, I don't need subsequent
> But not everything is (or even can be) designed right from the get-go.

We agree there.

>> Oh, it's very typical, vector and map have operator[] that is exactly that kind
>> of a getter.
> It's a typical function, but it's not a getter IMO.

Let's not split hairs about what is or is not a getter. Such functions
are in wide-spread
use, and if you write a name() that acts like that it's not going to
be a huge surprise
to everybody.

> You're also ignoring the case when that kind of access function isn't usable.

I don't quite know what I'm ignoring, can you explain? :)

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 13:14:57 +0100
Raw View
On Wed, Nov 28, 2012 at 1:10 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> Having to change client code and having to rebuild client code are different
> problems, but neither of them is insignificant. I didn't mean to imply that it's
> not costly to change a client, but I'd also like to point out that
> it's not without
> cost to have to rebuild a client.

True, but updating code is significantly more expensive than
rebuilding, isn't it?
If rebuilding is a problem (in your case) you could use properties
from the get-go.

>>> Oh, it's very typical, vector and map have operator[] that is exactly that kind
>>> of a getter.
>> It's a typical function, but it's not a getter IMO.
>
> Let's not split hairs about what is or is not a getter. Such functions
> are in wide-spread
> use, and if you write a name() that acts like that it's not going to
> be a huge surprise
> to everybody.
>
>> You're also ignoring the case when that kind of access function isn't usable.
>
> I don't quite know what I'm ignoring, can you explain? :)

Suppose I want to set dirty_ to true when name is set.
If name() returns a string&, I can't do that, can I?

--
Olaf

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 14:20:23 +0200
Raw View
On 28 November 2012 14:14, Olaf van der Spek <olafvdspek@gmail.com> wrote:
> True, but updating code is significantly more expensive than
> rebuilding, isn't it?
> If rebuilding is a problem (in your case) you could use properties
> from the get-go.

Or I can use functions from the get-go. ;)

>>> You're also ignoring the case when that kind of access function isn't usable.
>> I don't quite know what I'm ignoring, can you explain? :)
> Suppose I want to set dirty_ to true when name is set.
> If name() returns a string&, I can't do that, can I?

Same applies if a property getter returns a string&, as Mikael said,
because I can
then bypass the property setter. I can also return a proxy object reference, and
handle the dirty_ setting in that proxy. That _is_ a work-around, I admit that.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 13:24:20 +0100
Raw View
On Wed, Nov 28, 2012 at 1:20 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 28 November 2012 14:14, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>> True, but updating code is significantly more expensive than
>> rebuilding, isn't it?
>> If rebuilding is a problem (in your case) you could use properties
>> from the get-go.
>
> Or I can use functions from the get-go. ;)

Sigh, sure, *in your case*
But there are more cases than yours. Cases where rebuilding is not a problem.

>>>> You're also ignoring the case when that kind of access function isn't usable.
>>> I don't quite know what I'm ignoring, can you explain? :)
>> Suppose I want to set dirty_ to true when name is set.
>> If name() returns a string&, I can't do that, can I?
>
> Same applies if a property getter returns a string&, as Mikael said,
> because I can
> then bypass the property setter.

True, so don't return a non-const& (again *that* case)

> I can also return a proxy object reference, and
> handle the dirty_ setting in that proxy. That _is_ a work-around, I admit that.

Good, because I almost thought we were going around in circles.

--
Olaf

--




.


Author: =?ISO-8859-1?Q?Mikael_Kilpel=E4inen?=
Date: Wed, 28 Nov 2012 13:33:43 +0100
Raw View
> Look at the vector example. It allows you to provide an alias, for
> example x for v[0], y for v[1], etc.
> Or length for size.
>
>
Okey, so you can provide alias without space overhead.. but that doesn't
really convince me.
Properties can be useful though but I think they should not expose the
internals then.


Mikael

--




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 14:35:53 +0200
Raw View
On 28 November 2012 14:24, Olaf van der Spek <olafvdspek@gmail.com> wrote:
>>> If rebuilding is a problem (in your case) you could use properties
>>> from the get-go.
>> Or I can use functions from the get-go. ;)
> Sigh, sure, *in your case*
> But there are more cases than yours. Cases where rebuilding is not a problem.

I fail to see what the point of that is. Of course there are cases
where rebuilding
isn't a problem, and there are cases where it is a problem. This seems
like a red
herring, a problem which properties don't (and probably shouldn't be claimed to)
solve.

In order to try and avoid going in circles, I recommend someone (maybe you)
writes a proposal for properties. It should take into account the
previous proposals,
and especially find out why those proposals weren't accepted. What I've tried to
point out is limitations of properties; I'm not trying to dismiss
properties, I'm trying
to remind everybody that the applicability and benefit of properties
_may_ end up
not being worth their cost. That's a design issue that _any_ proposal,
especially
a language facility proposal needs to take into account in its rationale.

--




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 13:36:24 +0100
Raw View
On Wed, Nov 28, 2012 at 1:33 PM, Mikael Kilpel=E4inen
<mikael.kilpelainen@gmail.com> wrote:
>> Look at the vector example. It allows you to provide an alias, for
>> example x for v[0], y for v[1], etc.
>> Or length for size.
>>
>>
> Okey, so you can provide alias without space overhead.. but that doesn't
> really convince me.
> Properties can be useful though but I think they should not expose the
> internals then.

Shouldn't that be up to the person using them?
In some cases exposed internals (and thus a pointer or reference to
them) makes sense. In other cases it doesn't.
Should we prevent one of the use cases?


--=20
Olaf

--=20




.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 28 Nov 2012 14:37:11 +0200
Raw View
On 28 November 2012 14:33, Mikael Kilpel=E4inen
<mikael.kilpelainen@gmail.com> wrote:
>> Look at the vector example. It allows you to provide an alias, for
>> example x for v[0], y for v[1], etc.
>> Or length for size.
> Okey, so you can provide alias without space overhead.. but that doesn't
> really convince me.
> Properties can be useful though but I think they should not expose the
> internals then.

To be fair, that's more a style than a technique issue to me, and I
don't think we should
try and limit properties to disallow such exposure, if the user
chooses to expose members
that way even through properties.

--=20




.


Author: =?ISO-8859-1?Q?Mikael_Kilpel=E4inen?=
Date: Wed, 28 Nov 2012 13:42:15 +0100
Raw View
> To be fair, that's more a style than a technique issue to me, and I
> don't think we should
> try and limit properties to disallow such exposure, if the user
> chooses to expose members
> that way even through properties.
>

Sorry, my wording was bad, what I tried to say is that the
implementation shouldn't force it but
from my point of view that usage gives no extra value for properties as
I find it missguided.

But in general, like I said, properties can be useful. I do totally
agree on Ville's point though; I am not sure it is worth it.


Mikael

--




.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 28 Nov 2012 13:50:59 +0100
Raw View
Le 28/11/12 12:12, Olaf van der Spek a =E9crit :
> On Tue, Nov 27, 2012 at 11:53 PM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr> wrote:
>>> Don't forget the other advantage of properties: being able to move from
>>> public data members to properties without changing client syntax.
>> This is in general not exactly true as showed at the beginning of this
>> thread
> Where exactly?
The text that followed was posted by    Sebastian Gesemann 27/11/2012 14h27

> I'm sure lots of people would be very happy if you've
> got a solution that's not worse in memory/performance than a data
> member / member function. Bonus points if the definition syntax is
> clean too.
You loss me here.
>
>> Also, how does it interact with template argument deduction and
>> references? For example, I can imagine that this won't work:
>>
>>    SomeClass object;
>>    object.prop1 =3D 17;
>>    object.prop2 =3D 29;
>>    std::swap(object.prop1, object.prop2);
> If get returns non-const& it'd work, otherwise it wouldn't.
If get returns non-const& it can not be used with printf for example.
>
>>    auto mptr =3D &SomeClass::prop1;
>>    (object.*mptr) =3D 99;
> This might still work, although mptr would not be a regular member ptr.
So we need to add something else to the language, isn't it?
>
>
> On Wed, Nov 28, 2012 at 12:34 AM, Vicente J. Botet Escriba
> <vicente.botet@wanadoo.fr> wrote:
>>> Eh, what do you mean? The advantages of properties are clear, aren't th=
ey?
>>> The only question is how to best implement them.
>>
>> Before implementing, the problem is how to define and integrate them in =
an
>> already complex language. Adding a new kind of member implies seen how t=
his
>> new member and the rest of the language interact. I don't know if some o=
f
>> the posters is ready to start a proposal that describes all these
>> interactions, but be sure the list is longuer than you could expect.
> That's the how question. So we do agree that if possible, properties
> would be good to have?
Only if we have a good and integrated definition.
>
>> I agree and I would like to see well defined properties already in C++, =
but
>> they are not in, and define them will need to respond to questions like
> Let's try
>
>> * what &s.size mean?
> If get returns a non-const&, it'd be the pointer as usual.
> Otherwise, it'd be a member pointer to the property.
See my comments above.
>
>> * can we store property members?
> What do you mean?
I was thinking to the data function members counterpart.
>
>> * could a property be used as a 'function'? would it be a getter or a
>> setter? do we need std::mem_property? std::bind_property? ...
> Probably not.
Hrrr, I have a concept that abstracts two functions and I can not use it=20
as a function?
>
>> * could rw properties be swapped?
> If a non-const& is available
>
>> * could properties be indexed?
> Probably
>
>> * could properties be returned by functions?
>> * could properties be used as function parameters?
>> * could properties be used as template parameters?
> Probably not, to all three.
I believe I will vote (if I have the opportunity) against the=20
introduction of something that can not be used in these cases.
>
>> In summary, are properties 1st class citizen entities?
You have not replayed to this important question.
>>
>> Whether it is worth doing it or not is an open question. Any one
>> voluntering?
> I think the question is when (and by who), not if.
>
>
I will be happy to review a concrete proposal if some one consider it is=20
worth doing it, but IMHO properties should be 1st citizen class entities=20
or not be.

-- Vicente

--=20




.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 14:15:45 +0100
Raw View
On Wed, Nov 28, 2012 at 1:50 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
>>>> Don't forget the other advantage of properties: being able to move from
>>>> public data members to properties without changing client syntax.
>>>
>>> This is in general not exactly true as showed at the beginning of this
>>> thread
>>
>> Where exactly?
>
> The text that followed was posted by    Sebastian Gesemann 27/11/2012 14h27

Ah, like that. You're right, it might not be true in some cases.

> If get returns non-const& it can not be used with printf for example.

Why not?

>>
>>>    auto mptr = &SomeClass::prop1;
>>>    (object.*mptr) = 99;
>>
>> This might still work, although mptr would not be a regular member ptr.
>
> So we need to add something else to the language, isn't it?

Maybe, maybe not. Some technical details are complex.
You'd basically like to store a member pointer to a property?

>>> * can we store property members?
>>
>> What do you mean?
>
> I was thinking to the data function members counterpart.

Conceptually you should be able to.
You'd have to store a pointer to the class and the type info would
have enough info to use it.

>>
>>> * could a property be used as a 'function'? would it be a getter or a
>>> setter? do we need std::mem_property? std::bind_property? ...
>>
>> Probably not.
>
> Hrrr, I have a concept that abstracts two functions and I can not use it as
> a function?

Scrap that, I think you should be able to.

>>> * could properties be returned by functions?
>>> * could properties be used as function parameters?
>>> * could properties be used as template parameters?
>>
>> Probably not, to all three.
>
> I believe I will vote (if I have the opportunity) against the introduction
> of something that can not be used in these cases.

Why?
What exactly would it mean to return a property? Do you mean a
(member) property pointer instead?

>>
>>> In summary, are properties 1st class citizen entities?
>
> You have not replayed to this important question.

I'm not sure what exactly you mean.

If conceptually a certain use/feature (related to properties) makes
sense, I think it should be supported.


--
Olaf

--




.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 28 Nov 2012 18:45:55 +0100
Raw View
This is a multi-part message in MIME format.
--------------090504010109040609010507
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 28/11/12 14:15, Olaf van der Spek a =E9crit :
> On Wed, Nov 28, 2012 at 1:50 PM, Vicente J. Botet Escriba
> <vicente.botet@wanadoo.fr> wrote:
>> If get returns non-const& it can not be used with printf for example.
> Why not?
My bad. I was thinking to another case.
>
>>>>     auto mptr =3D &SomeClass::prop1;
>>>>     (object.*mptr) =3D 99;
>>> This might still work, although mptr would not be a regular member ptr.
>> So we need to add something else to the language, isn't it?
> Maybe, maybe not. Some technical details are complex.
> You'd basically like to store a member pointer to a property?
Yes. This means that a specific syntax for pointer to member properties=20
is needed.
>
>>>> * can we store property members?
>>> What do you mean?
>> I was thinking to the data function members counterpart.
> Conceptually you should be able to.
> You'd have to store a pointer to the class and the type info would
> have enough info to use it.
>
>>>> * could a property be used as a 'function'? would it be a getter or a
>>>> setter? do we need std::mem_property? std::bind_property? ...
>>> Probably not.
>> Hrrr, I have a concept that abstracts two functions and I can not use it=
 as
>> a function?
> Scrap that, I think you should be able to.
So this will need some library additions.
>>>> * could properties be returned by functions?
>>>> * could properties be used as function parameters?
>>>> * could properties be used as template parameters?
>>> Probably not, to all three.
>> I believe I will vote (if I have the opportunity) against the introducti=
on
>> of something that can not be used in these cases.
> Why?
> What exactly would it mean to return a property? Do you mean a
> (member) property pointer instead?
Yes.

Should properties support the following use case?

  void f(int& v)  {
    v=3D1;
  }

  struct X {

    property int a;

  };

   X x;

   f(x.a);

If 'a' were a data member, this will be correct.

So I would say yes, properties should support it. But I don't see how=20
the property setter will be used inside 'f'.
If this is not accepted, this is show-stopper example showing that=20
moving from a data member to a property is not transparent.

The user will need to use an intermediary variable to get the desired=20
behavior

   X x;  int i;
   f(i);
   x.a=3Di;

Are properties cleaner? transparent?

-- Vicente

--=20




--------------090504010109040609010507
Content-Type: text/html; charset=ISO-8859-1

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 28/11/12 14:15, Olaf van der Spek a
      &eacute;crit&nbsp;:<br>
    </div>
    <blockquote
cite="mid:CAA7U3HP7rWFZYCOyNHvVWPmyYBd-4uNDcuKHiStHCgnTDSoC5Q@mail.gmail.com"
      type="cite">
      <pre wrap="">On Wed, Nov 28, 2012 at 1:50 PM, Vicente J. Botet Escriba
<a class="moz-txt-link-rfc2396E" href="mailto:vicente.botet@wanadoo.fr">&lt;vicente.botet@wanadoo.fr&gt;</a> wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">If get returns non-const&amp; it can not be used with printf for example.
</pre>
      </blockquote>
      <pre wrap="">
Why not?</pre>
    </blockquote>
    My bad. I was thinking to another case.<br>
    <blockquote
cite="mid:CAA7U3HP7rWFZYCOyNHvVWPmyYBd-4uNDcuKHiStHCgnTDSoC5Q@mail.gmail.com"
      type="cite">
      <pre wrap="">

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <pre wrap="">
</pre>
          <blockquote type="cite">
            <pre wrap="">   auto mptr = &amp;SomeClass::prop1;
   (object.*mptr) = 99;
</pre>
          </blockquote>
          <pre wrap="">
This might still work, although mptr would not be a regular member ptr.
</pre>
        </blockquote>
        <pre wrap="">
So we need to add something else to the language, isn't it?
</pre>
      </blockquote>
      <pre wrap="">
Maybe, maybe not. Some technical details are complex.
You'd basically like to store a member pointer to a property?</pre>
    </blockquote>
    Yes. This means that a specific syntax for pointer to member
    properties is needed.<br>
    <blockquote
cite="mid:CAA7U3HP7rWFZYCOyNHvVWPmyYBd-4uNDcuKHiStHCgnTDSoC5Q@mail.gmail.com"
      type="cite">
      <pre wrap="">

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <blockquote type="cite">
            <pre wrap="">* can we store property members?
</pre>
          </blockquote>
          <pre wrap="">
What do you mean?
</pre>
        </blockquote>
        <pre wrap="">
I was thinking to the data function members counterpart.
</pre>
      </blockquote>
      <pre wrap="">
Conceptually you should be able to.
You'd have to store a pointer to the class and the type info would
have enough info to use it.

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <pre wrap="">
</pre>
          <blockquote type="cite">
            <pre wrap="">* could a property be used as a 'function'? would it be a getter or a
setter? do we need std::mem_property? std::bind_property? ...
</pre>
          </blockquote>
          <pre wrap="">
Probably not.
</pre>
        </blockquote>
        <pre wrap="">
Hrrr, I have a concept that abstracts two functions and I can not use it as
a function?
</pre>
      </blockquote>
      <pre wrap="">
Scrap that, I think you should be able to.
</pre>
    </blockquote>
    So this will need some library additions.<br>
    <blockquote
cite="mid:CAA7U3HP7rWFZYCOyNHvVWPmyYBd-4uNDcuKHiStHCgnTDSoC5Q@mail.gmail.com"
      type="cite">
      <pre wrap="">
</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <blockquote type="cite">
            <pre wrap="">* could properties be returned by functions?
* could properties be used as function parameters?
* could properties be used as template parameters?
</pre>
          </blockquote>
          <pre wrap="">
Probably not, to all three.
</pre>
        </blockquote>
        <pre wrap="">
I believe I will vote (if I have the opportunity) against the introduction
of something that can not be used in these cases.
</pre>
      </blockquote>
      <pre wrap="">
Why?
What exactly would it mean to return a property? Do you mean a
(member) property pointer instead?</pre>
    </blockquote>
    Yes.<br>
    <br>
    Should properties support the following use case?<br>
    <br>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp;void f(int&amp; v)&nbsp; { <br>
        &nbsp;&nbsp; v=1;<br>
        &nbsp;}&nbsp;<o:p></o:p></span></p>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp;struct X {<o:p></o:p></span></p>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp;&nbsp; property int a;<o:p></o:p></span></p>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp;};<o:p></o:p></span></p>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp; X x;<o:p></o:p></span></p>
    <span style="font-size:11.0pt;font-family:&quot;Trebuchet
      MS&quot;,&quot;sans-serif&quot;;
      color:#1F497D" lang="EN-US">&nbsp; f(x.a); </span><br>
    <br>
    If 'a' were a data member, this will be correct. <br>
    <br>
    So I would say yes, properties should support it. But I don't see
    how the property setter will be used inside 'f'.<br>
    If this is not accepted, this is show-stopper example showing that
    moving from a data member to a property is not transparent. <br>
    <br>
    The user will need to use an intermediary variable to get the
    desired behavior<br>
    <p class="MsoNormal"><span
        style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US">&nbsp; X x;</span>&nbsp; int i;<br>
      &nbsp; f(i);<span style="font-size:11.0pt;font-family:&quot;Trebuchet
        MS&quot;,&quot;sans-serif&quot;;
        color:#1F497D" lang="EN-US"><span
          style="font-size:11.0pt;font-family:&quot;Trebuchet
          MS&quot;,&quot;sans-serif&quot;;
          color:#1F497D" lang="EN-US"><br>
          &nbsp; x.a=i;</span> </span><br>
    </p>
    Are properties cleaner? transparent?<br>
    <br>
    -- Vicente<br>
  </body>
</html>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--------------090504010109040609010507--

.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Wed, 28 Nov 2012 18:57:15 +0100
Raw View
On Wed, Nov 28, 2012 at 6:45 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
> Should properties support the following use case?
>
>  void f(int& v)  {
>    v=1;
>  }
>
>  struct X {
>
>    property int a;
>
>  };
>
>   X x;
>
>   f(x.a);
>
> If 'a' were a data member, this will be correct.
>
> So I would say yes, properties should support it. But I don't see how the
> property setter will be used inside 'f'.
> If this is not accepted, this is show-stopper example showing that moving
> from a data member to a property is not transparent.

Public data members and properties with non-trivial set functions are
not equivalent.
You just can't get an int& from such a property.
It's the same with a set_a(int) function, isn't it?

> The user will need to use an intermediary variable to get the desired
> behavior
>
>   X x;  int i;

Don't forget int i = x.a;

>   f(i);
>   x.a=i;
>
> Are properties cleaner?

Yes

> transparent?

What exactly do you mean?
No, they're not equivalent.

--
Olaf

--




.


Author: DeadMG <wolfeinstein@gmail.com>
Date: Wed, 28 Nov 2012 10:15:38 -0800 (PST)
Raw View
------=_Part_21_11766826.1354126539157
Content-Type: text/plain; charset=ISO-8859-1

If this<https://groups.google.com/a/isocpp.org/d/topic/std-proposals/fgCw1xFGZLM/discussion> were
to be accepted and slightly altered, it could be used for properties.
Copyable is required if the property is backed by an actual variable,
though.

template<typename T> class property {
    // get and set implementation
    struct proxy {
        property* prop;
        T t;
        proxy(property& p) : t(p.get()) { prop = &p; }
        T& operator auto() && { return t; }
        ~proxy() { prop->set(std::move(t)); }
    };
    proxy operator auto() & { return proxy(*this); }
};

This may provide answers to many of your questions.

Can properties be swapped? Yes.
Can properties be treated as lvalues in some respects (not all)? Yes. For
example, property<std::string> would work fine when, say, += is invoked.
You would also be able to use auto x = f.prop; But auto&& would not
function, as you'd have a reference to an expiring value. Perhaps the
automatic type overriding proposal could be altered somehow to support this
use case, for example, supporting separate overloads for auto, auto&,
auto&&.
Member function pointers? No.
Can properties be returned from functions? Yes- if you exposed
property<T>::proxy, there is no reason it could not be returned, although
this may be rather ugly. Passing a property as an lvalue is far more
feasible.
Can properties be passed as functions? No. Fundamentally, this cannot
happen, as it would interfere with operator() on the proxied object.
Can properties be passed in templates? I doubt it.

Properties will never be able to replicate the exact interface of lvalues,
because, well, they're not really lvalues. This, I think, should not reduce
their adoption, because they are fundamentally rather helpful.

--




------=_Part_21_11766826.1354126539157
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

If&nbsp;<a href=3D"https://groups.google.com/a/isocpp.org/d/topic/std-propo=
sals/fgCw1xFGZLM/discussion">this</a>&nbsp;were to be accepted and slightly=
 altered, it could be used for properties. Copyable is required if the prop=
erty is backed by an actual variable, though.<div><br></div><div>template&l=
t;typename T&gt; class property {</div><div>&nbsp; &nbsp; // get and set im=
plementation</div><div>&nbsp; &nbsp; struct proxy {</div><div>&nbsp; &nbsp;=
 &nbsp; &nbsp; property* prop;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; T t;</=
div><div>&nbsp; &nbsp; &nbsp; &nbsp; proxy(property&amp; p) : t(p.get()) { =
prop =3D &amp;p; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; T&amp; operator au=
to() &amp;&amp; { return t; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ~proxy(=
) { prop-&gt;set(std::move(t)); }</div><div>&nbsp; &nbsp; };</div><div>&nbs=
p; &nbsp; proxy operator auto() &amp; { return proxy(*this); }</div><div>};=
</div><div><br></div><div>This may provide answers to many of your question=
s.</div><div><br></div><div>Can properties be swapped? Yes.</div><div>Can p=
roperties be treated as lvalues in some respects (not all)? Yes. For exampl=
e, property&lt;std::string&gt; would work fine when, say, +=3D is invoked. =
You would also be able to use auto x =3D f.prop; But auto&amp;&amp; would n=
ot function, as you'd have a reference to an expiring value. Perhaps the au=
tomatic type overriding proposal could be altered somehow to support this u=
se case, for example, supporting separate overloads for auto, auto&amp;, au=
to&amp;&amp;.</div><div>Member function pointers? No.</div><div>Can propert=
ies be returned from functions? Yes- if you exposed property&lt;T&gt;::prox=
y, there is no reason it could not be returned, although this may be rather=
 ugly. Passing a property as an lvalue is far more feasible.</div><div>Can =
properties be passed as functions? No. Fundamentally, this cannot happen, a=
s it would interfere with operator() on the proxied object.</div><div>Can p=
roperties be passed in templates? I doubt it.</div><div><br></div><div>Prop=
erties will never be able to replicate the exact interface of lvalues, beca=
use, well, they're not really lvalues. This, I think, should not reduce the=
ir adoption, because they are fundamentally rather helpful.</div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_21_11766826.1354126539157--

.


Author: rick@longbowgames.com
Date: Wed, 28 Nov 2012 10:44:08 -0800 (PST)
Raw View
------=_Part_6_11321068.1354128248187
Content-Type: text/plain; charset=ISO-8859-1

On Wednesday, November 28, 2012 1:15:38 PM UTC-5, DeadMG wrote:
>
> If this<https://groups.google.com/a/isocpp.org/d/topic/std-proposals/fgCw1xFGZLM/discussion> were
> to be accepted and slightly altered, it could be used for properties.
> Copyable is required if the property is backed by an actual variable,
> though.


That's a little cleaner, but doesn't offer much more than current
library-based solutions, and carries the same expense. Actually, it carries
more expense, since it's additionally creating a temporary value.

--




------=_Part_6_11321068.1354128248187
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Wednesday, November 28, 2012 1:15:38 PM UTC-5, DeadMG wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1p=
x #ccc solid;padding-left: 1ex;">If&nbsp;<a href=3D"https://groups.google.c=
om/a/isocpp.org/d/topic/std-proposals/fgCw1xFGZLM/discussion" target=3D"_bl=
ank">this</a>&nbsp;were to be accepted and slightly altered, it could be us=
ed for properties. Copyable is required if the property is backed by an act=
ual variable, though.</blockquote><div><br>That's a little cleaner, but doe=
sn't offer much more than current library-based solutions, and carries the =
same expense. Actually, it carries more expense, since it's additionally cr=
eating a temporary value. <br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_6_11321068.1354128248187--

.


Author: Fabio Fracassi <f.fracassi@gmx.net>
Date: Wed, 28 Nov 2012 21:52:38 +0100
Raw View
On 11/28/12 1:06 PM, Olaf van der Spek wrote:
> On Wed, Nov 28, 2012 at 12:52 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>> I know it's not just about internal representation. If I expect to have to cope
>> with a changing representation *or* I expect to add checks or whatever, I'll
>> write a function. It's barely different from deciding to use a property instead
>> of member access.
> Is it? You can go from data member to property without changing clients.
>
>>>> If I make a design mistake and have to change from data member to
>>>> member function,
>>>> I consider that my problem, not the standard's problem.
>>> Sure, but again, properties would avoid that problem altogether.
>> Do they? I expect clients to have to rebuild anyway, although they don't need
> Rebuilding is not a problem IMO.
>
>> to be changed. If I design correctly from the get-go, I don't need subsequent
> But not everything is (or even can be) designed right from the get-go.
>
>> client recompiles when the implementation of the accessing functions change
>> but the signatures of them doesn't, and the representation doesn't.
>>
>>
Which (i.e. not having to change clients) means you can use it in
generic code like:

template<typename P, typename F>
P do_something(P& rhs, P& lhs) {
     P res;
     res.x = F(rhs.x, lhs.x);
     //...
     return res;
}

And it will work with both

struct SimplePoint { double x,y; };

and

struct SelfawarePoint {
     property x(get: x() set: set_x(double))
     // ...
   private:
     void set_x(double x) { x_ = x; changed_ = true; }
     // ...

     double x_;
     // ...
     bool changed_;
};

Quite a huge benefit, IMVHO.

regards

Fabio




--




.


Author: DeadMG <wolfeinstein@gmail.com>
Date: Wed, 28 Nov 2012 14:33:09 -0800 (PST)
Raw View
------=_Part_253_4786317.1354141989379
Content-Type: text/plain; charset=ISO-8859-1

On Wednesday, November 28, 2012 6:44:08 PM UTC, ri...@longbowgames.com
wrote:

> On Wednesday, November 28, 2012 1:15:38 PM UTC-5, DeadMG wrote:
>>
>> If this<https://groups.google.com/a/isocpp.org/d/topic/std-proposals/fgCw1xFGZLM/discussion> were
>> to be accepted and slightly altered, it could be used for properties.
>> Copyable is required if the property is backed by an actual variable,
>> though.
>
>
> That's a little cleaner, but doesn't offer much more than current
> library-based solutions, and carries the same expense. Actually, it carries
> more expense, since it's additionally creating a temporary value.
>

Not really, it's just caching the return value of get().

--




------=_Part_253_4786317.1354141989379
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Wednesday, November 28, 2012 6:44:08 PM UTC, ri...@longbowgames.com wrot=
e:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Wednesday, November 2=
8, 2012 1:15:38 PM UTC-5, DeadMG wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex">If&nbsp;<a href=3D"https://groups.google.com/a/isocpp.org/d/topic/std-p=
roposals/fgCw1xFGZLM/discussion" target=3D"_blank">this</a>&nbsp;were to be=
 accepted and slightly altered, it could be used for properties. Copyable i=
s required if the property is backed by an actual variable, though.</blockq=
uote><div><br>That's a little cleaner, but doesn't offer much more than cur=
rent library-based solutions, and carries the same expense. Actually, it ca=
rries more expense, since it's additionally creating a temporary value. <br=
></div></blockquote><div><br></div><div>Not really, it's just caching the r=
eturn value of get().&nbsp;</div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_253_4786317.1354141989379--

.


Author: nicolas.jinchereau@gmail.com
Date: Mon, 26 Aug 2013 13:58:40 -0700 (PDT)
Raw View
------=_Part_3916_11950219.1377550720554
Content-Type: text/plain; charset=ISO-8859-1

Has anyone considered the following syntax for properties?

This approach is similar to that of the D programming language, except that
the keyword "property" is already in use in Objective-C++ and CLI, so
instead, the auto keyword is used.

class Test
{
int _number;
public:
int number() = auto;
int number(int number) = auto;
};

int Test::number()
{
return _number;
}

int Test::number(int number)
{
return _number = number;
}


Test test;

test.number = 5;
//same as:  test.number(5);

int a = test.number;
// same as:  int a = test.number();

test.number += 5;
// same as:  int tmp = test.number(); tmp +=- 5; test.number(tmp);

int a = 1 + test.number + 3;
// same as:  int a = 1 + test.number() + 3;

--

---
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_3916_11950219.1377550720554
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Has anyone considered the following syntax for properties?=
<br><br><div>This approach is similar to that of the D programming language=
, except that the keyword "property" is already in use in Objective-C++ and=
 CLI, so instead, the auto keyword is used.<div><br><div><div>class Test</d=
iv><div>{</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre=
"> </span>int _number;</div><div>public:</div><div><span class=3D"Apple-tab=
-span" style=3D"white-space:pre"> </span>int number() =3D auto;</div><div><=
span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>int number(=
int number) =3D auto;</div><div>};</div><div><br></div><div>int Test::numbe=
r()</div><div>{</div><div><span class=3D"Apple-tab-span" style=3D"white-spa=
ce:pre"> </span>return _number;</div><div>}</div><div><br></div><div>int Te=
st::number(int number)</div><div>{</div><div><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre"> </span>return _number =3D number;</div><div>}</=
div><div><br></div><div><br></div><div>Test test;</div><div><br></div><div>=
test.number =3D 5;</div><div>//same as: &nbsp;test.number(5);</div><div><br=
></div><div>int a =3D test.number;</div><div>// same as: &nbsp;int a =3D te=
st.number();</div><div><br></div><div>test.number +=3D 5;</div><div>// same=
 as: &nbsp;int tmp =3D test.number(); tmp +=3D- 5; test.number(tmp);</div><=
div><br></div><div>int a =3D 1 + test.number + 3;</div><div>// same as: &nb=
sp;int a =3D 1 + test.number() + 3;</div></div><div><br></div></div></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_3916_11950219.1377550720554--

.