equivariant functions
Steven Schveighoffer
schveiguy at yahoo.com
Wed Oct 15 12:44:14 PDT 2008
"Andrei Alexandrescu" wrote
> KennyTM~ wrote:
>> Andrei Alexandrescu wrote:
>>> Bill Baxter wrote:
>>>> Hmmm, looking at this:
>>>>
>>>> class Owner
>>>> {
>>>> const?(A) a() const?{...}
>>>> const?(B) b() const?{...}
>>>> const?(C) c() const?{...}
>>>> const?(D) d() const?{...}
>>>> const?(E) e() const?{...}
>>>> const?(F) f() const?{...}
>>>> const?(G) g() const?{...}
>>>> const?(H) h() const?{...}
>>>> const?(I) i() const?{...}
>>>> const?(J) j() const?{...}
>>>> }
>>>>
>>>> makes me think if we go with that syntax, Andrei is sooner or later
>>>> going to complain about his D code asking him too many questions. :-)
>>>> Eh, I guess he can edit the emacs mode to display const? as
>>>> smiley-faces or something. :-) :-)
>>>
>>> At this point Walter will intervene with:
>>>
>>> class Owner
>>> {
>>> const?
>>> {
>>> A a() {...}
>>> B b() {...}
>>> C c() {...}
>>> D d() {...}
>>> E e() {...}
>>> F f() {...}
>>> G g() {...}
>>> H h() {...}
>>> I i() {...}
>>> J j() {...}
>>> }
>>> }
>>>
>>> which isn't half bad.
>>>
>>>
>>> Andrei
>>
>> Huh? But
>>
>> class Owner {
>> const // without the "?"
>> {
>> A a() {...}
>> B b() {...}
>> C c() {...}
>> D d() {...}
>> E e() {...}
>> F f() {...}
>> G g() {...}
>> H h() {...}
>> I i() {...}
>> J j() {...}
>> }
>> }
>>
>> only apply const on the function, but not their return type (i.e. they
>> become
>>
>> A a() const { ... }
>> // etc.
>>
>> but not
>>
>> const(A) a() const { ... }
>> // etc.
>>
>> )
>
> Yah, but it does not make sense to not apply const? to the return value.
compromise:
>>> class Owner
>>> {
>>> const?
>>> {
>>> const?(A) a() {...}
>>> const?(B) b() {...}
>>> const?(C) c() {...}
>>> const?(D) d() {...}
>>> const?(E) e() {...}
>>> const?(F) f() {...}
>>> const?(G) g() {...}
>>> const?(H) h() {...}
>>> const?(I) i() {...}
>>> const?(J) j() {...}
>>> }
>>> }
Also still not terrible. Whatever we come up with should be consistent with
the other type modifiers.
Otherwise, you get into sticky situations like this:
const?
{
A a(X x)
}
Should this translate to:
const?(A) a(const?(X) x) const?
Sidenote: seeing that const? at the end really looks weird. Not sure I like
this so much any more. I think I'd rather see a new keyword...
-Steve
More information about the Digitalmars-d
mailing list