Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-10-20 23:51:39


Stefan Strasser wrote:
> Am Tuesday 20 October 2009 22:07:28 schrieb Matthew Chambers:
>> Do you plan to have a macro for defining simple/trivial properties with
>> a single line?
>
> I think that this is the only thing that's missing from c++, and that it
> doesn't need a C# properties syntax.
>
> the C++ "properties" syntax is, for example (taken from tr1::unordered_map):
>
> float max_load_factor() const;
> void max_load_factor(float z);
>
> I wouldn't even consider your proposed properties syntax "syntactic sugar".
> it's just a different syntax, not a better one imho.
>
> so if there's anything missing from c++ it would be something like
>
> #define BOOST_TRIVIAL_PROPERTY(T,name) \
> T name() const{ return _name; } \
> void name(T __name){ _name=__name; } \
> T _name;

I don't believe a trivial property does very much. While a trivial style
property such as you mention above could be part of any C++ "property"
implementation, what is minimally needed beyond that is what the OP's
property implementation provides, which is the ability to have some sort
of backing function to set the property at the very least.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk