Topic: Adding programmatic variables


Author: Xavi Gratal <gratal@gmail.com>
Date: Fri, 22 Nov 2013 12:39:34 -0800 (PST)
Raw View
------=_Part_44_15221032.1385152774945
Content-Type: text/plain; charset=ISO-8859-1

I'm sure this is a pretty bad title, so I'll try to explain what I mean.

One of my favorite features of C++ is that it's easy to create libraries
with constructs that behave like other builtin constructs, making it
possible to build really expressive user code, while controlling the
behavior behind the scenes. For example, it is possible to create objects
that are callable (behave like functions) and objects that are
subscriptable (behave like arrays) or types for which you can use operators
(like for builtin numeric types). All these features, while they are not
necessary since they could be all easily replaced by a single function
call, make C++ extremely powerful to build domain-specific languages.

However, I've always found that there is a construct that we can't emulate:
a struct. We can't create an object that behaves as if it had a member
variable x unless it actually has a member variable x. When building, for
example, a vector class for linear algebra, we can offer subscripting, so
that in that way it feels well integrated into the language, but we can't
offer variables x and y that access the two first elements if we are using
dynamic storage, or if we are trying to obtain the x and y of something
that is implemented as an expression template. Most matrix libraries, such
as eigen, implement x() and y() as functions, so that you can do things
such as cout << vec.x() or vec.x()=3. This feels unnatural and makes it
impossible to use such classes as a drop-in replacement for a simple struct
vec { double x,y; } with added functionality.

So my proposal is to add member functions that can be used as if they were
member variables, and compute a value that is returned every time the
variable is accessed.

Possible syntax for declaring these functions could be:

int x { return 3; }     //this could be disambiguated from
brace-initialization since it must have a return statement, but I guess it
could be hard on the parser
auto int x { return 3; }
int operator a() { return 3; }
int operator a { return 3; }
int operator .a() { return 3; }

I hope my proposal was more or less clear. Any idea if it has been proposed
before? If not, are there any very good reasons to not have something like
this?

Thanks in advance for your comments.

--

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

<div dir=3D"ltr">I'm sure this is a pretty bad title, so I'll try to explai=
n what I mean.<div><br></div><div>One of my favorite features of C++ is tha=
t it's easy to create libraries with constructs that behave like other buil=
tin constructs, making it possible to build really expressive user code, wh=
ile controlling the behavior behind the scenes. For example, it is possible=
 to create objects that are callable (behave like functions) and objects th=
at are subscriptable (behave like arrays) or types for which you can use op=
erators (like for builtin numeric types). All these features, while they ar=
e not necessary since they could be all easily replaced by a single functio=
n call, make C++ extremely powerful to build domain-specific languages.</di=
v><div><br></div><div>However, I've always found that there is a construct =
that we can't emulate: a struct. We can't create an object that behaves as =
if it had a member variable x unless it actually has a member variable x. W=
hen building, for example, a vector class for linear algebra, we can offer =
subscripting, so that in that way it feels well integrated into the languag=
e, but we can't offer variables x and y that access the two first elements =
if we are using dynamic storage, or if we are trying to obtain the x and y =
of something that is implemented as an expression template. Most matrix lib=
raries, such as eigen, implement x() and y() as functions, so that you can =
do things such as cout &lt;&lt; vec.x() or vec.x()=3D3. This feels unnatura=
l and makes it impossible to use such classes as a drop-in replacement for =
a simple struct vec { double x,y; } with added functionality.</div><div><br=
></div><div>So my proposal is to add member functions that can be used as i=
f they were member variables, and compute a value that is returned every ti=
me the variable is accessed.</div><div><br></div><div>Possible syntax for d=
eclaring these functions could be:</div><div><br></div><div>int x { return =
3; } &nbsp; &nbsp; //this could be disambiguated from brace-initialization =
since it must have a return statement, but I guess it could be hard on the =
parser</div><div>auto int x { return 3; }</div><div>int operator a() { retu=
rn 3; }</div><div>int operator a { return 3; }</div><div>int operator .a() =
{ return 3; }</div><div><br></div><div>I hope my proposal was more or less =
clear. Any idea if it has been proposed before? If not, are there any very =
good reasons to not have something like this?</div><div><br></div><div>Than=
ks in advance for your comments.</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_44_15221032.1385152774945--

.


Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Fri, 22 Nov 2013 22:46:12 +0100
Raw View
On Fri, 2013-11-22 at 12:39 -0800, Xavi Gratal wrote:
> I'm sure this is a pretty bad title, so I'll try to explain what I
> mean.
>
>
> One of my favorite features of C++ is that it's easy to create
> libraries with constructs that behave like other builtin constructs,
> making it possible to build really expressive user code, while
> controlling the behavior behind the scenes. For example, it is
> possible to create objects that are callable (behave like functions)
> and objects that are subscriptable (behave like arrays) or types for
> which you can use operators (like for builtin numeric types). All
> these features, while they are not necessary since they could be all
> easily replaced by a single function call, make C++ extremely powerful
> to build domain-specific languages.
>
>
> However, I've always found that there is a construct that we can't
> emulate: a struct. We can't create an object that behaves as if it had
> a member variable x unless it actually has a member variable x. When
> building, for example, a vector class for linear algebra, we can offer
> subscripting, so that in that way it feels well integrated into the
> language, but we can't offer variables x and y that access the two
> first elements if we are using dynamic storage, or if we are trying to
> obtain the x and y of something that is implemented as an expression
> template. Most matrix libraries, such as eigen, implement x() and y()
> as functions, so that you can do things such as cout << vec.x() or
> vec.x()=3. This feels unnatural and makes it impossible to use such
> classes as a drop-in replacement for a simple struct vec { double
> x,y; } with added functionality.
>
>
> So my proposal is to add member functions that can be used as if they
> were member variables, and compute a value that is returned every time
> the variable is accessed.
>


I think this sounds like yet another reinvention of properties.
That have been discussed to death repeatedly but I sadly lack any links
to previous discussions.

/MF


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Fri, 22 Nov 2013 13:53:27 -0800
Raw View
--047d7b6d91d45553b204ebcb0b7f
Content-Type: text/plain; charset=ISO-8859-1

Have you seen this:

http://www.youtube.com/watch?v=Gy9ITl1AWRY


On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <gratal@gmail.com> wrote:

> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>
> One of my favorite features of C++ is that it's easy to create libraries
> with constructs that behave like other builtin constructs, making it
> possible to build really expressive user code, while controlling the
> behavior behind the scenes. For example, it is possible to create objects
> that are callable (behave like functions) and objects that are
> subscriptable (behave like arrays) or types for which you can use operators
> (like for builtin numeric types). All these features, while they are not
> necessary since they could be all easily replaced by a single function
> call, make C++ extremely powerful to build domain-specific languages.
>
> However, I've always found that there is a construct that we can't
> emulate: a struct. We can't create an object that behaves as if it had a
> member variable x unless it actually has a member variable x. When
> building, for example, a vector class for linear algebra, we can offer
> subscripting, so that in that way it feels well integrated into the
> language, but we can't offer variables x and y that access the two first
> elements if we are using dynamic storage, or if we are trying to obtain the
> x and y of something that is implemented as an expression template. Most
> matrix libraries, such as eigen, implement x() and y() as functions, so
> that you can do things such as cout << vec.x() or vec.x()=3. This feels
> unnatural and makes it impossible to use such classes as a drop-in
> replacement for a simple struct vec { double x,y; } with added
> functionality.
>
> So my proposal is to add member functions that can be used as if they were
> member variables, and compute a value that is returned every time the
> variable is accessed.
>
> Possible syntax for declaring these functions could be:
>
> int x { return 3; }     //this could be disambiguated from
> brace-initialization since it must have a return statement, but I guess it
> could be hard on the parser
> auto int x { return 3; }
> int operator a() { return 3; }
> int operator a { return 3; }
> int operator .a() { return 3; }
>
> I hope my proposal was more or less clear. Any idea if it has been
> proposed before? If not, are there any very good reasons to not have
> something like this?
>
> Thanks in advance for your comments.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">Have you seen this:<div><br></div><div><a href=3D"http://w=
ww.youtube.com/watch?v=3DGy9ITl1AWRY">http://www.youtube.com/watch?v=3DGy9I=
Tl1AWRY</a><br></div></div><div class=3D"gmail_extra"><br><br><div class=3D=
"gmail_quote">
On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <span dir=3D"ltr">&lt;<a href=
=3D"mailto:gratal@gmail.com" target=3D"_blank">gratal@gmail.com</a>&gt;</sp=
an> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">I&#39;m sure this is a pretty bad title, so I&#39;ll try t=
o explain what I mean.<div><br></div><div>One of my favorite features of C+=
+ is that it&#39;s easy to create libraries with constructs that behave lik=
e other builtin constructs, making it possible to build really expressive u=
ser code, while controlling the behavior behind the scenes. For example, it=
 is possible to create objects that are callable (behave like functions) an=
d objects that are subscriptable (behave like arrays) or types for which yo=
u can use operators (like for builtin numeric types). All these features, w=
hile they are not necessary since they could be all easily replaced by a si=
ngle function call, make C++ extremely powerful to build domain-specific la=
nguages.</div>
<div><br></div><div>However, I&#39;ve always found that there is a construc=
t that we can&#39;t emulate: a struct. We can&#39;t create an object that b=
ehaves as if it had a member variable x unless it actually has a member var=
iable x. When building, for example, a vector class for linear algebra, we =
can offer subscripting, so that in that way it feels well integrated into t=
he language, but we can&#39;t offer variables x and y that access the two f=
irst elements if we are using dynamic storage, or if we are trying to obtai=
n the x and y of something that is implemented as an expression template. M=
ost matrix libraries, such as eigen, implement x() and y() as functions, so=
 that you can do things such as cout &lt;&lt; vec.x() or vec.x()=3D3. This =
feels unnatural and makes it impossible to use such classes as a drop-in re=
placement for a simple struct vec { double x,y; } with added functionality.=
</div>
<div><br></div><div>So my proposal is to add member functions that can be u=
sed as if they were member variables, and compute a value that is returned =
every time the variable is accessed.</div><div><br></div><div>Possible synt=
ax for declaring these functions could be:</div>
<div><br></div><div>int x { return 3; } =A0 =A0 //this could be disambiguat=
ed from brace-initialization since it must have a return statement, but I g=
uess it could be hard on the parser</div><div>auto int x { return 3; }</div=
>
<div>int operator a() { return 3; }</div><div>int operator a { return 3; }<=
/div><div>int operator .a() { return 3; }</div><div><br></div><div>I hope m=
y proposal was more or less clear. Any idea if it has been proposed before?=
 If not, are there any very good reasons to not have something like this?</=
div>
<div><br></div><div>Thanks in advance for your comments.</div></div><span c=
lass=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
=A0<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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></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 />

--047d7b6d91d45553b204ebcb0b7f--

.


Author: xavi <gratal@gmail.com>
Date: Fri, 22 Nov 2013 22:56:41 +0100
Raw View
--047d7bb03c6cdc6b0d04ebcb165f
Content-Type: text/plain; charset=ISO-8859-1

It certainly isn't a reinvention of something that exists in the language.
Even if you don't have any links, do you know which were the main arguments
against something that would allow what I propose?

Richard, thanks for the link. Looks promising.


2013/11/22 Richard Smith <richard@metafoo.co.uk>

> Have you seen this:
>
> http://www.youtube.com/watch?v=Gy9ITl1AWRY
>
>
> On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <gratal@gmail.com> wrote:
>
>> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>>
>> One of my favorite features of C++ is that it's easy to create libraries
>> with constructs that behave like other builtin constructs, making it
>> possible to build really expressive user code, while controlling the
>> behavior behind the scenes. For example, it is possible to create objects
>> that are callable (behave like functions) and objects that are
>> subscriptable (behave like arrays) or types for which you can use operators
>> (like for builtin numeric types). All these features, while they are not
>> necessary since they could be all easily replaced by a single function
>> call, make C++ extremely powerful to build domain-specific languages.
>>
>> However, I've always found that there is a construct that we can't
>> emulate: a struct. We can't create an object that behaves as if it had a
>> member variable x unless it actually has a member variable x. When
>> building, for example, a vector class for linear algebra, we can offer
>> subscripting, so that in that way it feels well integrated into the
>> language, but we can't offer variables x and y that access the two first
>> elements if we are using dynamic storage, or if we are trying to obtain the
>> x and y of something that is implemented as an expression template. Most
>> matrix libraries, such as eigen, implement x() and y() as functions, so
>> that you can do things such as cout << vec.x() or vec.x()=3. This feels
>> unnatural and makes it impossible to use such classes as a drop-in
>> replacement for a simple struct vec { double x,y; } with added
>> functionality.
>>
>> So my proposal is to add member functions that can be used as if they
>> were member variables, and compute a value that is returned every time the
>> variable is accessed.
>>
>> Possible syntax for declaring these functions could be:
>>
>> int x { return 3; }     //this could be disambiguated from
>> brace-initialization since it must have a return statement, but I guess it
>> could be hard on the parser
>> auto int x { return 3; }
>> int operator a() { return 3; }
>> int operator a { return 3; }
>> int operator .a() { return 3; }
>>
>> I hope my proposal was more or less clear. Any idea if it has been
>> proposed before? If not, are there any very good reasons to not have
>> something like this?
>>
>> Thanks in advance for your comments.
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
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/.

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

<div dir=3D"ltr">It certainly isn&#39;t a reinvention of something that exi=
sts in the language. Even if you don&#39;t have any links, do you know whic=
h were the main arguments against something that would allow what I propose=
?<div>
<br></div><div>Richard, thanks for the link. Looks promising.</div></div><d=
iv class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">2013/11/22 Rich=
ard Smith <span dir=3D"ltr">&lt;<a href=3D"mailto:richard@metafoo.co.uk" ta=
rget=3D"_blank">richard@metafoo.co.uk</a>&gt;</span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">Have you seen this:<div><br=
></div><div><a href=3D"http://www.youtube.com/watch?v=3DGy9ITl1AWRY" target=
=3D"_blank">http://www.youtube.com/watch?v=3DGy9ITl1AWRY</a><br>
</div></div><div class=3D"HOEnZb"><div class=3D"h5"><div class=3D"gmail_ext=
ra"><br><br><div class=3D"gmail_quote">
On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <span dir=3D"ltr">&lt;<a href=
=3D"mailto:gratal@gmail.com" target=3D"_blank">gratal@gmail.com</a>&gt;</sp=
an> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">

<div dir=3D"ltr">I&#39;m sure this is a pretty bad title, so I&#39;ll try t=
o explain what I mean.<div><br></div><div>One of my favorite features of C+=
+ is that it&#39;s easy to create libraries with constructs that behave lik=
e other builtin constructs, making it possible to build really expressive u=
ser code, while controlling the behavior behind the scenes. For example, it=
 is possible to create objects that are callable (behave like functions) an=
d objects that are subscriptable (behave like arrays) or types for which yo=
u can use operators (like for builtin numeric types). All these features, w=
hile they are not necessary since they could be all easily replaced by a si=
ngle function call, make C++ extremely powerful to build domain-specific la=
nguages.</div>

<div><br></div><div>However, I&#39;ve always found that there is a construc=
t that we can&#39;t emulate: a struct. We can&#39;t create an object that b=
ehaves as if it had a member variable x unless it actually has a member var=
iable x. When building, for example, a vector class for linear algebra, we =
can offer subscripting, so that in that way it feels well integrated into t=
he language, but we can&#39;t offer variables x and y that access the two f=
irst elements if we are using dynamic storage, or if we are trying to obtai=
n the x and y of something that is implemented as an expression template. M=
ost matrix libraries, such as eigen, implement x() and y() as functions, so=
 that you can do things such as cout &lt;&lt; vec.x() or vec.x()=3D3. This =
feels unnatural and makes it impossible to use such classes as a drop-in re=
placement for a simple struct vec { double x,y; } with added functionality.=
</div>

<div><br></div><div>So my proposal is to add member functions that can be u=
sed as if they were member variables, and compute a value that is returned =
every time the variable is accessed.</div><div><br></div><div>Possible synt=
ax for declaring these functions could be:</div>

<div><br></div><div>int x { return 3; } =A0 =A0 //this could be disambiguat=
ed from brace-initialization since it must have a return statement, but I g=
uess it could be hard on the parser</div><div>auto int x { return 3; }</div=
>

<div>int operator a() { return 3; }</div><div>int operator a { return 3; }<=
/div><div>int operator .a() { return 3; }</div><div><br></div><div>I hope m=
y proposal was more or less clear. Any idea if it has been proposed before?=
 If not, are there any very good reasons to not have something like this?</=
div>

<div><br></div><div>Thanks in advance for your comments.</div></div><span><=
font color=3D"#888888">

<p></p>

-- <br>
=A0<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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>

<p></p>

-- <br>
=A0<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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></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 />

--047d7bb03c6cdc6b0d04ebcb165f--

.


Author: hoothootlegs@gmail.com
Date: Fri, 22 Nov 2013 14:48:33 -0800 (PST)
Raw View
------=_Part_88_7926125.1385160513663
Content-Type: text/plain; charset=ISO-8859-1

 Yeah this isn't in C++, but it exists in other languages such as C# and D,
where it is called "properties".

 I agree that it would be nice to have


On Friday, November 22, 2013 2:56:41 PM UTC-7, Xavi Gratal wrote:

> It certainly isn't a reinvention of something that exists in the language.
> Even if you don't have any links, do you know which were the main arguments
> against something that would allow what I propose?
>
> Richard, thanks for the link. Looks promising.
>
>
> 2013/11/22 Richard Smith <ric...@metafoo.co.uk <javascript:>>
>
>> Have you seen this:
>>
>> http://www.youtube.com/watch?v=Gy9ITl1AWRY
>>
>>
>> On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <gra...@gmail.com<javascript:>
>> > wrote:
>>
>>> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>>>
>>> One of my favorite features of C++ is that it's easy to create libraries
>>> with constructs that behave like other builtin constructs, making it
>>> possible to build really expressive user code, while controlling the
>>> behavior behind the scenes. For example, it is possible to create objects
>>> that are callable (behave like functions) and objects that are
>>> subscriptable (behave like arrays) or types for which you can use operators
>>> (like for builtin numeric types). All these features, while they are not
>>> necessary since they could be all easily replaced by a single function
>>> call, make C++ extremely powerful to build domain-specific languages.
>>>
>>> However, I've always found that there is a construct that we can't
>>> emulate: a struct. We can't create an object that behaves as if it had a
>>> member variable x unless it actually has a member variable x. When
>>> building, for example, a vector class for linear algebra, we can offer
>>> subscripting, so that in that way it feels well integrated into the
>>> language, but we can't offer variables x and y that access the two first
>>> elements if we are using dynamic storage, or if we are trying to obtain the
>>> x and y of something that is implemented as an expression template. Most
>>> matrix libraries, such as eigen, implement x() and y() as functions, so
>>> that you can do things such as cout << vec.x() or vec.x()=3. This feels
>>> unnatural and makes it impossible to use such classes as a drop-in
>>> replacement for a simple struct vec { double x,y; } with added
>>> functionality.
>>>
>>> So my proposal is to add member functions that can be used as if they
>>> were member variables, and compute a value that is returned every time the
>>> variable is accessed.
>>>
>>> Possible syntax for declaring these functions could be:
>>>
>>> int x { return 3; }     //this could be disambiguated from
>>> brace-initialization since it must have a return statement, but I guess it
>>> could be hard on the parser
>>> auto int x { return 3; }
>>> int operator a() { return 3; }
>>> int operator a { return 3; }
>>> int operator .a() { return 3; }
>>>
>>> I hope my proposal was more or less clear. Any idea if it has been
>>> proposed before? If not, are there any very good reasons to not have
>>> something like this?
>>>
>>> Thanks in advance for your comments.
>>>
>>> --
>>>
>>> ---
>>> 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-proposal...@isocpp.org <javascript:>.
>>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>>> Visit this group at
>>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>>
>>
>>  --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr"><div>&nbsp;Yeah this isn't in C++, but it exists in other =
languages such as C# and D, where it is called "properties".&nbsp; </div><d=
iv>&nbsp;</div><div>&nbsp;I agree that it would be nice to have</div><div>&=
nbsp;</div><div><br>On Friday, November 22, 2013 2:56:41 PM UTC-7, Xavi Gra=
tal wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px =
0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border=
-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">It certainly =
isn't a reinvention of something that exists in the language. Even if you d=
on't have any links, do you know which were the main arguments against some=
thing that would allow what I propose?<div>
<br></div><div>Richard, thanks for the link. Looks promising.</div></div><d=
iv><br><br><div class=3D"gmail_quote">2013/11/22 Richard Smith <span dir=3D=
"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" _originalhref=3D"javasc=
ript:" gdf-obfuscated-mailto=3D"FsQYweoOlk0J">ric...@metafoo.co.uk</a>&gt;<=
/span><br>
<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; paddi=
ng-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px=
; border-left-style: solid;"><div dir=3D"ltr">Have you seen this:<div><br><=
/div><div><a href=3D"http://www.youtube.com/watch?v=3DGy9ITl1AWRY" target=
=3D"_blank" _originalhref=3D"http://www.youtube.com/watch?v=3DGy9ITl1AWRY">=
http://www.youtube.com/watch?<wbr>v=3DGy9ITl1AWRY</a><br>
</div></div><div><div><div><br><br><div class=3D"gmail_quote">
On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <span dir=3D"ltr">&lt;<a href=
=3D"javascript:" target=3D"_blank" _originalhref=3D"javascript:" gdf-obfusc=
ated-mailto=3D"FsQYweoOlk0J">gra...@gmail.com</a>&gt;</span> wrote:<br><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-l=
eft: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; bo=
rder-left-style: solid;">

<div dir=3D"ltr">I'm sure this is a pretty bad title, so I'll try to explai=
n what I mean.<div><br></div><div>One of my favorite features of C++ is tha=
t it's easy to create libraries with constructs that behave like other buil=
tin constructs, making it possible to build really expressive user code, wh=
ile controlling the behavior behind the scenes. For example, it is possible=
 to create objects that are callable (behave like functions) and objects th=
at are subscriptable (behave like arrays) or types for which you can use op=
erators (like for builtin numeric types). All these features, while they ar=
e not necessary since they could be all easily replaced by a single functio=
n call, make C++ extremely powerful to build domain-specific languages.</di=
v>

<div><br></div><div>However, I've always found that there is a construct th=
at we can't emulate: a struct. We can't create an object that behaves as if=
 it had a member variable x unless it actually has a member variable x. Whe=
n building, for example, a vector class for linear algebra, we can offer su=
bscripting, so that in that way it feels well integrated into the language,=
 but we can't offer variables x and y that access the two first elements if=
 we are using dynamic storage, or if we are trying to obtain the x and y of=
 something that is implemented as an expression template. Most matrix libra=
ries, such as eigen, implement x() and y() as functions, so that you can do=
 things such as cout &lt;&lt; vec.x() or vec.x()=3D3. This feels unnatural =
and makes it impossible to use such classes as a drop-in replacement for a =
simple struct vec { double x,y; } with added functionality.</div>

<div><br></div><div>So my proposal is to add member functions that can be u=
sed as if they were member variables, and compute a value that is returned =
every time the variable is accessed.</div><div><br></div><div>Possible synt=
ax for declaring these functions could be:</div>

<div><br></div><div>int x { return 3; } &nbsp; &nbsp; //this could be disam=
biguated from brace-initialization since it must have a return statement, b=
ut I guess it could be hard on the parser</div><div>auto int x { return 3; =
}</div>

<div>int operator a() { return 3; }</div><div>int operator a { return 3; }<=
/div><div>int operator .a() { return 3; }</div><div><br></div><div>I hope m=
y proposal was more or less clear. Any idea if it has been proposed before?=
 If not, are there any very good reasons to not have something like this?</=
div>

<div><br></div><div>Thanks in advance for your comments.</div></div><span><=
font color=3D"#888888">

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" _originalhref=3D"javascri=
pt:" gdf-obfuscated-mailto=3D"FsQYweoOlk0J">std-proposal...@<wbr>isocpp.org=
</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" _originalhref=3D"javascript:" gdf-obfuscated-mailto=3D"FsQYweoOlk0J">st=
d-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank" _originalhref=3D"http://groups.google.com=
/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/<wbr>isocpp.=
org/group/std-<wbr>proposals/</a>.<br>
</font></span></blockquote></div><br></div>

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" _originalhref=3D"javascri=
pt:" gdf-obfuscated-mailto=3D"FsQYweoOlk0J">std-proposal...@<wbr>isocpp.org=
</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" _originalhref=3D"javascript:" gdf-obfuscated-mailto=3D"FsQYweoOlk0J">st=
d-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank" _originalhref=3D"http://groups.google.com=
/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/<wbr>isocpp.=
org/group/std-<wbr>proposals/</a>.<br>
</div></div></blockquote></div><br></div>
</blockquote></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_88_7926125.1385160513663--

.


Author: xavi <gratal@gmail.com>
Date: Sat, 23 Nov 2013 00:16:04 +0100
Raw View
--089e0153867cc2677f04ebcc32a0
Content-Type: text/plain; charset=ISO-8859-1

I'm not familiar with D, but in C# and Python (when using the C library to
create new types), properties are usually implemented in terms of a getter
and a setter. Since C++ has references and the possibility to overload
operator=, the implementation would be much simpler. It would be much like
any other function, and 'set' functionality could be implementing by
returning either a reference or some proxy type with an operator=.
The only necessary change to the language would be to have some special
type of member function which takes no parameters and that can be called
omitting the (). It shouldn't be possible to call this function with the
normal function call syntax, otherwise there would be an ambiguity when the
returned type overloads operator().


2013/11/22 <hoothootlegs@gmail.com>

>  Yeah this isn't in C++, but it exists in other languages such as C# and
> D, where it is called "properties".
>
>  I agree that it would be nice to have
>
>
> On Friday, November 22, 2013 2:56:41 PM UTC-7, Xavi Gratal wrote:
>
>> It certainly isn't a reinvention of something that exists in the
>> language. Even if you don't have any links, do you know which were the main
>> arguments against something that would allow what I propose?
>>
>> Richard, thanks for the link. Looks promising.
>>
>>
>> 2013/11/22 Richard Smith <ric...@metafoo.co.uk>
>>
>>> Have you seen this:
>>>
>>> http://www.youtube.com/watch?v=Gy9ITl1AWRY
>>>
>>>
>>> On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <gra...@gmail.com> wrote:
>>>
>>>> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>>>>
>>>> One of my favorite features of C++ is that it's easy to create
>>>> libraries with constructs that behave like other builtin constructs, making
>>>> it possible to build really expressive user code, while controlling the
>>>> behavior behind the scenes. For example, it is possible to create objects
>>>> that are callable (behave like functions) and objects that are
>>>> subscriptable (behave like arrays) or types for which you can use operators
>>>> (like for builtin numeric types). All these features, while they are not
>>>> necessary since they could be all easily replaced by a single function
>>>> call, make C++ extremely powerful to build domain-specific languages.
>>>>
>>>> However, I've always found that there is a construct that we can't
>>>> emulate: a struct. We can't create an object that behaves as if it had a
>>>> member variable x unless it actually has a member variable x. When
>>>> building, for example, a vector class for linear algebra, we can offer
>>>> subscripting, so that in that way it feels well integrated into the
>>>> language, but we can't offer variables x and y that access the two first
>>>> elements if we are using dynamic storage, or if we are trying to obtain the
>>>> x and y of something that is implemented as an expression template. Most
>>>> matrix libraries, such as eigen, implement x() and y() as functions, so
>>>> that you can do things such as cout << vec.x() or vec.x()=3. This feels
>>>> unnatural and makes it impossible to use such classes as a drop-in
>>>> replacement for a simple struct vec { double x,y; } with added
>>>> functionality.
>>>>
>>>> So my proposal is to add member functions that can be used as if they
>>>> were member variables, and compute a value that is returned every time the
>>>> variable is accessed.
>>>>
>>>> Possible syntax for declaring these functions could be:
>>>>
>>>> int x { return 3; }     //this could be disambiguated from
>>>> brace-initialization since it must have a return statement, but I guess it
>>>> could be hard on the parser
>>>> auto int x { return 3; }
>>>> int operator a() { return 3; }
>>>> int operator a { return 3; }
>>>> int operator .a() { return 3; }
>>>>
>>>> I hope my proposal was more or less clear. Any idea if it has been
>>>> proposed before? If not, are there any very good reasons to not have
>>>> something like this?
>>>>
>>>> Thanks in advance for your comments.
>>>>
>>>> --
>>>>
>>>> ---
>>>> 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-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>
>>>> Visit this group at http://groups.google.com/a/isocpp.org/group/std-
>>>> proposals/.
>>>>
>>>
>>>  --
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "ISO C++ Standard - Future Proposals" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to std-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>>
>>> Visit this group at http://groups.google.com/a/isocpp.org/group/std-
>>> proposals/.
>>>
>>
>>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
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/.

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

<div dir=3D"ltr">I&#39;m not familiar with D, but in C# and Python (when us=
ing the C library to create new types), properties are usually implemented =
in terms of a getter and a setter. Since C++ has references and the possibi=
lity to overload operator=3D, the implementation would be much simpler. It =
would be much like any other function, and &#39;set&#39; functionality coul=
d be implementing by returning either a reference or some proxy type with a=
n operator=3D.<div>
The only necessary change to the language would be to have some special typ=
e of member function which takes no parameters and that can be called omitt=
ing the (). It shouldn&#39;t be possible to call this function with the nor=
mal function call syntax, otherwise there would be an ambiguity when the re=
turned type overloads operator().</div>
</div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">2013/11=
/22  <span dir=3D"ltr">&lt;<a href=3D"mailto:hoothootlegs@gmail.com" target=
=3D"_blank">hoothootlegs@gmail.com</a>&gt;</span><br><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">
<div dir=3D"ltr"><div>=A0Yeah this isn&#39;t in C++, but it exists in other=
 languages such as C# and D, where it is called &quot;properties&quot;.=A0 =
</div><div>=A0</div><div>=A0I agree that it would be nice to have</div><div=
 class=3D"im">
<div>=A0</div><div><br>On Friday, November 22, 2013 2:56:41 PM UTC-7, Xavi =
Gratal wrote:</div></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);borde=
r-left-width:1px;border-left-style:solid">
<div class=3D"im"><div dir=3D"ltr">It certainly isn&#39;t a reinvention of =
something that exists in the language. Even if you don&#39;t have any links=
, do you know which were the main arguments against something that would al=
low what I propose?<div>

<br></div><div>Richard, thanks for the link. Looks promising.</div></div></=
div><div><br><br><div class=3D"gmail_quote">2013/11/22 Richard Smith <span =
dir=3D"ltr">&lt;<a>ric...@metafoo.co.uk</a>&gt;</span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding=
-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-l=
eft-style:solid"><div class=3D"im"><div dir=3D"ltr">Have you seen this:<div=
><br>
</div><div><a href=3D"http://www.youtube.com/watch?v=3DGy9ITl1AWRY" target=
=3D"_blank">http://www.youtube.com/watch?<u></u>v=3DGy9ITl1AWRY</a><br>
</div></div></div><div><div><div><br><br><div class=3D"gmail_quote"><div cl=
ass=3D"im">
On Fri, Nov 22, 2013 at 12:39 PM, Xavi Gratal <span dir=3D"ltr">&lt;<a>gra.=
...@gmail.com</a>&gt;</span> wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb=
(204,204,204);border-left-width:1px;border-left-style:solid">
<div class=3D"im">

<div dir=3D"ltr">I&#39;m sure this is a pretty bad title, so I&#39;ll try t=
o explain what I mean.<div><br></div><div>One of my favorite features of C+=
+ is that it&#39;s easy to create libraries with constructs that behave lik=
e other builtin constructs, making it possible to build really expressive u=
ser code, while controlling the behavior behind the scenes. For example, it=
 is possible to create objects that are callable (behave like functions) an=
d objects that are subscriptable (behave like arrays) or types for which yo=
u can use operators (like for builtin numeric types). All these features, w=
hile they are not necessary since they could be all easily replaced by a si=
ngle function call, make C++ extremely powerful to build domain-specific la=
nguages.</div>


<div><br></div><div>However, I&#39;ve always found that there is a construc=
t that we can&#39;t emulate: a struct. We can&#39;t create an object that b=
ehaves as if it had a member variable x unless it actually has a member var=
iable x. When building, for example, a vector class for linear algebra, we =
can offer subscripting, so that in that way it feels well integrated into t=
he language, but we can&#39;t offer variables x and y that access the two f=
irst elements if we are using dynamic storage, or if we are trying to obtai=
n the x and y of something that is implemented as an expression template. M=
ost matrix libraries, such as eigen, implement x() and y() as functions, so=
 that you can do things such as cout &lt;&lt; vec.x() or vec.x()=3D3. This =
feels unnatural and makes it impossible to use such classes as a drop-in re=
placement for a simple struct vec { double x,y; } with added functionality.=
</div>


<div><br></div><div>So my proposal is to add member functions that can be u=
sed as if they were member variables, and compute a value that is returned =
every time the variable is accessed.</div><div><br></div><div>Possible synt=
ax for declaring these functions could be:</div>


<div><br></div><div>int x { return 3; } =A0 =A0 //this could be disambiguat=
ed from brace-initialization since it must have a return statement, but I g=
uess it could be hard on the parser</div><div>auto int x { return 3; }</div=
>


<div>int operator a() { return 3; }</div><div>int operator a { return 3; }<=
/div><div>int operator .a() { return 3; }</div><div><br></div><div>I hope m=
y proposal was more or less clear. Any idea if it has been proposed before?=
 If not, are there any very good reasons to not have something like this?</=
div>


<div><br></div><div>Thanks in advance for your comments.</div></div></div><=
span><font color=3D"#888888"><div class=3D"im">

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br></div>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a>std-proposal...@<u></u>isocpp.org</a>.<br>
To post to this group, send email to <a>std-pr...@isocpp.org</a>.<div class=
=3D"im"><br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<u></u>isocpp.=
org/group/std-<u></u>proposals/</a>.<br>
</div></font></span></blockquote></div><br></div><div class=3D"im">

<p></p>

-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br></div>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a>std-proposal...@<u></u>isocpp.org</a>.<br>
To post to this group, send email to <a>std-pr...@isocpp.org</a>.<div class=
=3D"im"><br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<u></u>isocpp.=
org/group/std-<u></u>proposals/</a>.<br>
</div></div></div></blockquote></div><br></div>
</blockquote></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
=A0<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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></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 />

--089e0153867cc2677f04ebcc32a0--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 23 Nov 2013 09:14:45 +0800
Raw View
On 11/23/13 4:39 AM, Xavi Gratal wrote:
> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>
> One of my favorite features of C++ is that it's easy to create libraries
> with constructs that behave like other builtin constructs, making it
> possible to build really expressive user code, while controlling the
> behavior behind the scenes.

Heh, I first read this as "expensive behavior." The downside is that
innocuous looking code can hide complex function calls.

An existing strategy for making "properties" is to use a member proxy
containing a link to the containing object. This carries overhead,
invalidates the implicit constructor definitions, and uses up the
user-defined conversion slot.

> However, I've always found that there is a construct that we can't emulate:
> a struct. We can't create an object that behaves as if it had a member
> variable x unless it actually has a member variable x.

Strictly speaking, member references are not objects and do not require
storage. I think a reference whose initializer is recomputed at each use
might be a good basis for the feature. Such would be useful in local
scopes as well. Think of it as an "expression alias."

int v[ 5 ], index;
explicit int & vi = v[ index ]; // "explicit" in the sense of "ya know
what I'm sayin'."
for ( index = 0; index != 5; ++ index ) {
     vi = index; // vi resolves to the elements in sequence
} // now v = { 0, 1, 2, 3, 4 }

The standard never specifies how reference lvalues are obtained upon
use, so this feature would be very easy to add. References already bind
to prvalues so you could use it to return data, not only to reference
preexisting objects.

The natural way to handle these in the ABI would be a hidden member
function, and no in-structure storage, but that would be an
implementation detail.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: xavi <gratal@gmail.com>
Date: Sat, 23 Nov 2013 02:58:10 +0100
Raw View
--089e0153867c76c0e804ebce7691
Content-Type: text/plain; charset=ISO-8859-1

2013/11/23 David Krauss <potswa@gmail.com>

> On 11/23/13 4:39 AM, Xavi Gratal wrote:
>
>> I'm sure this is a pretty bad title, so I'll try to explain what I mean.
>>
>> One of my favorite features of C++ is that it's easy to create libraries
>> with constructs that behave like other builtin constructs, making it
>> possible to build really expressive user code, while controlling the
>> behavior behind the scenes.
>>
>
> Heh, I first read this as "expensive behavior." The downside is that
> innocuous looking code can hide complex function calls.
>
> An existing strategy for making "properties" is to use a member proxy
> containing a link to the containing object. This carries overhead,
> invalidates the implicit constructor definitions, and uses up the
> user-defined conversion slot.
>
> There are already many ways to have hidden expensive behaviour. And code
that looks like might be expensive, because it's a function call (maybe
calling another function call, everything inlined) and it reduces to access
to a variable. The same way that operator[] should, in general, be used for
something that is more or less like indexing, and operator* should be used
for something that is more or less like dereferencing, this kind of
variables should be used for something that is more or less like directly
accessing a variable. It actually gives a way to show that this is a simple
operation, making innocuous code look innocuous. Of course, almost every
construct in C++ can be abused in really creative ways, but that's a fair
price to pay for all the flexibility.

And as you say, it's already possible having an object that holds a pointer
to the containing object, but it seems pretty silly to have an object full
of pointers to itself, and completely unacceptable for the vector example I
described.

>
>  However, I've always found that there is a construct that we can't
>> emulate:
>> a struct. We can't create an object that behaves as if it had a member
>> variable x unless it actually has a member variable x.
>>
>
> Strictly speaking, member references are not objects and do not require
> storage. I think a reference whose initializer is recomputed at each use
> might be a good basis for the feature. Such would be useful in local scopes
> as well. Think of it as an "expression alias."
>
> int v[ 5 ], index;
> explicit int & vi = v[ index ]; // "explicit" in the sense of "ya know
> what I'm sayin'."
> for ( index = 0; index != 5; ++ index ) {
>     vi = index; // vi resolves to the elements in sequence
> } // now v = { 0, 1, 2, 3, 4 }
>

If, when declared inside a class, has a "this" so that it can access member
variables and functions, and something like

explicit const int &x const y = this->x[0]+3;

works as expected so that it can be applied to rvalues and to const
objects, then this would allow exactly the same kind of interface as my
proposal.

>
> The standard never specifies how reference lvalues are obtained upon use,
> so this feature would be very easy to add. References already bind to
> prvalues so you could use it to return data, not only to reference
> preexisting objects.
>
> The natural way to handle these in the ABI would be a hidden member
> function, and no in-structure storage, but that would be an implementation
> detail.
>
> I still think that what I propose would be easier to implement, since it
only requires being able to declare a special kind of function which is
called without the empty (), but I'm no expert in compilers, so I might be
wrong. It would even be possible to add that for all member functions,
since unless I'm mistaken, if x is a member function of some class, and y
is an object of this class, then x.y without a parenthesis has absolutely
no meaning. I think this is the approach taken in objective-C. The problem
in C++, as I mentioned before, is that it would be impossible to return
objects that overload operator().

>
> --
>
> --- You received this message because you are subscribed to the Google
> Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at http://groups.google.com/a/isocpp.org/group/std-
> proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">2013/11/23 David Krauss <span dir=3D"ltr">&lt;<a href=3D"mailto:pot=
swa@gmail.com" target=3D"_blank">potswa@gmail.com</a>&gt;</span><br><blockq=
uote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc =
solid;padding-left:1ex">
<div class=3D"im">On 11/23/13 4:39 AM, Xavi Gratal wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
I&#39;m sure this is a pretty bad title, so I&#39;ll try to explain what I =
mean.<br>
<br>
One of my favorite features of C++ is that it&#39;s easy to create librarie=
s<br>
with constructs that behave like other builtin constructs, making it<br>
possible to build really expressive user code, while controlling the<br>
behavior behind the scenes.<br>
</blockquote>
<br></div>
Heh, I first read this as &quot;expensive behavior.&quot; The downside is t=
hat innocuous looking code can hide complex function calls.<br>
<br>
An existing strategy for making &quot;properties&quot; is to use a member p=
roxy containing a link to the containing object. This carries overhead, inv=
alidates the implicit constructor definitions, and uses up the user-defined=
 conversion slot.<div class=3D"im">
<br></div></blockquote><div>There are already many ways to have hidden expe=
nsive behaviour. And code that looks like might be expensive, because it&#3=
9;s a function call (maybe calling another function call, everything inline=
d) and it reduces to access to a variable. The same way that operator[] sho=
uld, in general, be used for something that is more or less like indexing, =
and operator* should be used for something that is more or less like derefe=
rencing, this kind of variables should be used for something that is more o=
r less like directly accessing a variable. It actually gives a way to show =
that this is a simple operation, making innocuous code look innocuous. Of c=
ourse, almost every construct in C++ can be abused in really creative ways,=
 but that&#39;s a fair price to pay for all the flexibility.=A0</div>
<div><br></div><div>And as you say, it&#39;s already possible having an obj=
ect that holds a pointer to the containing object, but it seems pretty sill=
y to have an object full of pointers to itself, and completely unacceptable=
 for the vector example I described.</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"im">
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
However, I&#39;ve always found that there is a construct that we can&#39;t =
emulate:<br>
a struct. We can&#39;t create an object that behaves as if it had a member<=
br>
variable x unless it actually has a member variable x.<br>
</blockquote>
<br></div>
Strictly speaking, member references are not objects and do not require sto=
rage. I think a reference whose initializer is recomputed at each use might=
 be a good basis for the feature. Such would be useful in local scopes as w=
ell. Think of it as an &quot;expression alias.&quot;<br>

<br>
int v[ 5 ], index;<br>
explicit int &amp; vi =3D v[ index ]; // &quot;explicit&quot; in the sense =
of &quot;ya know what I&#39;m sayin&#39;.&quot;<br>
for ( index =3D 0; index !=3D 5; ++ index ) {<br>
=A0 =A0 vi =3D index; // vi resolves to the elements in sequence<br>
} // now v =3D { 0, 1, 2, 3, 4 }<br></blockquote><div><br></div><div>If, wh=
en declared inside a class, has a &quot;this&quot; so that it can access me=
mber variables and functions, and something like</div><div><br></div><div>
explicit const int &amp;x const y =3D this-&gt;x[0]+3;</div><div><br></div>=
<div>works as expected so that it can be applied to rvalues and to const ob=
jects, then this would allow exactly the same kind of interface as my propo=
sal.</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
<br>
The standard never specifies how reference lvalues are obtained upon use, s=
o this feature would be very easy to add. References already bind to prvalu=
es so you could use it to return data, not only to reference preexisting ob=
jects.<br>

<br>
The natural way to handle these in the ABI would be a hidden member functio=
n, and no in-structure storage, but that would be an implementation detail.=
<div class=3D"HOEnZb"><div class=3D"h5"><br></div></div></blockquote><div>
I still think that what I propose would be easier to implement, since it on=
ly requires being able to declare a special kind of function which is calle=
d without the empty (), but I&#39;m no expert in compilers, so I might be w=
rong. It would even be possible to add that for all member functions, since=
 unless I&#39;m mistaken, if x is a member function of some class, and y is=
 an object of this class, then x.y without a parenthesis has absolutely no =
meaning. I think this is the approach taken in objective-C. The problem in =
C++, as I mentioned before, is that it would be impossible to return object=
s that overload operator(). =A0=A0</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"HOEnZb"><div class=3D"h5">
<br>
-- <br>
<br>
--- You received this message because you are subscribed to the Google Grou=
ps &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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@<u></u>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/<u></u>isocpp.=
org/group/std-<u></u>proposals/</a>.<br>
</div></div></blockquote></div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e0153867c76c0e804ebce7691--

.