-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Set() setter property method chaining #13
Comments
I tried it, here is what I found: Attempt 1#define GETTERSETTER(type, method, name)
GETTER(type, method, name)
auto Set##method(type value) {
name = value;
return *this;
}
#endif Works for simple classes, but not classes like Also, for classes where there is a user-provided Another note, I get the warnings: Attempt 2#define GETTERSETTER(base, type, method, name)
GETTER(type, method, name)
base&& Set##method(type value) && {
name = value;
return std::move(*this);
}
#endif Works well, but needs refactoring to pass the base type to the utility macro. Maybe we could define a special macro for classes with deleted copy constructor / user-defined P.S. Referenced stackoverflow Attempt 3#define GETTERSETTER(type, method, name) \
GETTER(type, method, name) \
/** Sets the name value for the object. @param value The value of which to set name to. */ \
auto& Set##method(type value) & { \
name = value; \
return *this; \
} \
auto&& Set##method(type value) && { \
name = value; \
return std::move(*this); \
}
#endif This works, but needs |
Here is example test with the Attempt 3: raylib::Vector2 chained = raylib::Vector2(1, 2).SetX(2).SetY(4);
AssertEqual(chained.x, 2);
AssertEqual(chained.y, 4); |
Could use
auto
, or hardcode thereturn *this
in the property utility.The text was updated successfully, but these errors were encountered: