G
Glen Low
This naming convention is also consistent with the IDL/C++ language
C++ iostreams uses the int xyz(); void xyz(int) convention as well.
What is so evil about accessors/mutators, if they are not "just"
returning the underlying data member? (They could be calculating it,
caching it or passing it on to another object for example.)
Here's a suggestion to make the accessor/mutator pair into a first
class object, akin (but better in the long run) to VB/C# property,
your thots please.
We define a property class (with appropriate templating) to declare:
property& operator= (T);
operator T() const;
The signature is the same or similar to the proxy objects that often
crop up in delayed dereferencing scenarios.
The class contains a reference to the underlying object, and two PMFs
(either as template non-type params or constructor params) to the
[private] accessor/mutators in the object.
The object can either expose the property as a public data member (I'm
going to get into trouble for this one...), or through a member
function.
The former allows you to do this:
a.xyz = 12; std::cout << a.xyz;
The latter is slightly clunkier:
a.xyz() = 12; std::cout << a.xyz();
If the latter, a compiler would probably just optimize away the
property temporary anyway. (The latter also allows indexing
scenarios.)
What else does this buy you? The property can now be used as an
object, a substitute for a reference e.g.
template <typename U> void mul (U& z, const U& x, const U& y) { z = x
* y; }
Now mul could only take U = int before. But it can now take a property
and it will do the right thing. A bit similar to how an STL iterator
is an extension of the pointer, the property is like an extension to
reference. mul would not work with the pair of accessor/mutator
unwrapped.
Any comments, caveats, thoughts on this?
Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com
binding, and I wanted to seek your opinion regarding this.
C++ iostreams uses the int xyz(); void xyz(int) convention as well.
What is so evil about accessors/mutators, if they are not "just"
returning the underlying data member? (They could be calculating it,
caching it or passing it on to another object for example.)
Here's a suggestion to make the accessor/mutator pair into a first
class object, akin (but better in the long run) to VB/C# property,
your thots please.
We define a property class (with appropriate templating) to declare:
property& operator= (T);
operator T() const;
The signature is the same or similar to the proxy objects that often
crop up in delayed dereferencing scenarios.
The class contains a reference to the underlying object, and two PMFs
(either as template non-type params or constructor params) to the
[private] accessor/mutators in the object.
The object can either expose the property as a public data member (I'm
going to get into trouble for this one...), or through a member
function.
The former allows you to do this:
a.xyz = 12; std::cout << a.xyz;
The latter is slightly clunkier:
a.xyz() = 12; std::cout << a.xyz();
If the latter, a compiler would probably just optimize away the
property temporary anyway. (The latter also allows indexing
scenarios.)
What else does this buy you? The property can now be used as an
object, a substitute for a reference e.g.
template <typename U> void mul (U& z, const U& x, const U& y) { z = x
* y; }
Now mul could only take U = int before. But it can now take a property
and it will do the right thing. A bit similar to how an STL iterator
is an extension of the pointer, the property is like an extension to
reference. mul would not work with the pair of accessor/mutator
unwrapped.
Any comments, caveats, thoughts on this?
Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com