|
Boost : |
Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-10-20 16:30:29
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;
some of the problems your syntax introduces have already been mentioned.
another one is that the getters and setters can not be virtual. C# and
C++/CLI allow overriding setters and getters, and pure virtual properties,
but I don't think that can be achieved with the same syntax in C++, since
setters/getters are functions of seperate nested classes.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk