byKey and byValue: properties or methods?

Alvaro alvaroDotSegura at gmail.com
Fri Jan 20 06:13:51 PST 2012


El 20/01/2012 10:15, Jonathan M Davis escribió:
> On Friday, January 20, 2012 09:58:42 Marco Leise wrote:
>> Ah, I meant to say that getters should not modify their object. When I see
>> "a = abc.x[i]" I would be a little surprised to find that it changes the
>> observable state of abc. The same goes for "a = b.length()". Now it is
>> clearer, isn't is? :p
> The one major place where you essentially have a getter being able to modifer
> the original through its return value in C++ that I'm aware of is the
> subscript operator, and it has to in order to function like the built-in
> substript operator, so that's a special case.
>
> - Jonathan M Davis

Well, there is the case of std::map and its [] operator which adds an 
element if it does not exist. Even if in the right hand side:

a = map[x]; // modifies map if x was not found in it

Maybe Marco is talking about something like that.


More information about the Digitalmars-d mailing list