Interest in a 'Boost.property' library?
Is there any interest of "C# property" like library?
struct vec2 {
float get_x() const{...}
float set_x() const{...}
...
property_rw
On Sunday 07 July 2013 17:04:14 Metodi Todorov wrote:
Is there any interest of "C# property" like library?
struct vec2 { float get_x() const{...} float set_x() const{...} ... property_rw
x; vec2() : y(this) {} }; vec2 v; v.x = 15.0f; cout << v.x << endl;
Example: http://sourceforge.net/projects/cproperty/?source=dlp
I must say I'm not sure I see the point of x. You already had to define set_x/get_x, so you already concealed the nature of the property x (which is why properties exist, right?). One additional downside I see is that you have to store this inside the property, which adds to the vec2 object size and also affects its copyability/movability (i.e. you can't just have a default implementation of these functions). And you're bound to the particular signatures of the set/get functions.
07.07.2013 21:40, Andrey Semashev:
I must say I'm not sure I see the point of x. You already had to define set_x/get_x, so you already concealed the nature of the property x (which is why properties exist, right?).
I think properties exists for following reasons: 1) setter/getter have access to enveloping object internals 2) usual access syntax to field (i.e. "=") at user side 3) setter and getter are "tied" by syntax 4) virtual getter/setter, i.e. behaviour should be overridable by derived classes. (though, I may be wrong - I never use them)
One additional downside I see is that you have to store this inside the property, which adds to the vec2 object size
Maybe property-wrapper can be constructed on-demand, not affecting object size, like: widget.prop() = x; cout << widget.prop(); It only affects 2) from list above. Though it can be critical, and maybe in that case rollback to member functions is preferred: widget.prop(x); cout << widget.prop(); -- Evgeny Panasyuk
07.07.2013 18:04, Metodi Todorov:
Example: http://sourceforge.net/projects/cproperty/?source=dlp
1. Your property_rw, property_ro, property_wo have implicitly declared copy constructor and copy assignment operator, which have wrong semantic - they copy "this", while it must be tied to enveloping object. 2. FYI: I saw somewhere (maybe at stackoverflow) following C++11 approach for properties: http://coliru.stacked-crooked.com/view?id=1e7d98d17a1f945c3bd4bb3c8d69b204-f... class Widget { int value_; public: PROPERTY ( int, value, (cout << "getter" << endl; return value_;), (cout << "setter" << endl; value_ = x;) ); };
Is there any interest of "C# property" like library?
Personally, I don't remember if I ever need properties. Though, it is possible that there are some application domains where they are needed. I think such kind of property library should be mature and provide convenient interface, in order to be accepted into Boost. -- Evgeny Panasyuk
Is there any interest of "C# property" like library?
You might find this of interest as well: http://www.thradams.com/codeblog/properties.htm Regards, Nate
participants (5)
-
Andrey Semashev
-
Daniela Engert
-
Evgeny Panasyuk
-
Metodi Todorov
-
Nathan Ridge