|
Boost : |
Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-10-23 09:40:44
Olaf van der Spek wrote:
> On Fri, Oct 23, 2009 at 1:30 AM, Edward Diener <eldiener_at_[hidden]> wrote:
>> Of course you can support reference properties along with value properties.
>> It is just very hard, if not impossible, to support both kinds using the
>> same template class. So really one would not a separate template class to
>> support reference properties.
>
> Maybe I should've said class reference. Take std::string for example.
> I'd be very interested if you've got code that supports for example
> name.size() where name is your reference property class. name->size()
> is no problem, but I'd like to have name.size().
I understand your point, and you are right, and this is a notational
weakness as compared with accessing the data directly.
I don't believe that one can define a dot ( '.' ) operator in C++ but
maybe there is a metaprogramming way to hijack the dot operator. If
there is I would be glad to use it.
Actually I have rejected defining the -> operator for my reference
properties, because -> implies a pointer in standard C++ terminology and
I do not think of reference properties "pointing" to their type object.
Instead my reference properties have currently no built-in forwarder
operator to the actual type object. One could currently use the more
laborious form of:
propertyReference<std::string> name;
std::string & avar = name; // read/write property reference getter
avar.size() = 10; // or
std::string::size_type sz(avar.size());
or one could use my getter member function so one could write:
propertyReference<std::string> name;
name.getReference.size() = 10; // or
std::string::size_type sz(name.getReference.size());
Using a member function rather than an operator in this case is just a
little more inconvenient.
My member function is actually currently called "getValue" for my
reference property but I have decided that it is a confusing name since
one is really getting a reference, and have changed it to "getReference".
-----------------------------------------------------------------------
"So really one would not a separate template class to
support reference properties."
This was originally mistyped by me and should have been:
"So really one would need a separate template class to
support reference properties."
But I think you read through my error anyway without any problems.
-----------------------------------------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk