|I would change std::function<void(T &, T const &)> _setterFunction; to std::function<void(T const &)> _setterFunction;|
I suppose you're suggesting the method
std::function<T(T const &)>
.I've considered your idea, using my way you have also the old/current values. Maybe I can consider a method like
std::function<T(T const &,T const &)>
, passing old and new values as parameters, I need to consider implicit copy/move constructors (for instance, when I want to maintain old value, or modify the old object in order to release some resource).
Good point about oranges and apples. Maybe it would be cleaner to force the user to indicate getter/setter during declaration,like
, where funcGetter and funcSetter are two functions/functor. Another way would be
, but the user would have now the opportunity to change getter and setter simply by reinitializing the variable.
Why I've written this library, other than play a bit with templates and other C++ features?
Well, in java I've found setter/getter useful, but I've hated the associated boilerplate. Then I've loved Lombok's annotations.
- debug/tracing: you want to track when some variable is read/written/overwritten (maybe the variable is an object, referencing other resources)
- refactoring: in your code, you're exposing some variable to other class. Now you want to enforce some constrain on assignment, without change all references to what variable (which has to become a method).
- lazy initialization.