SFML community forums

General => Feature requests => Topic started by: Conduit on September 28, 2014, 10:14:25 pm

Title: const version of sf::Transform::combine
Post by: Conduit on September 28, 2014, 10:14:25 pm
Presently the 'sf::Transform::combine()' member function alters the 'sf::Transform' instance directly, thus disallowing its use on const instances of the class. A const version of the function would force us to copy-construct our return value, but it might be worth adding... use code similar to the following is currently disallowed:

TransformableClass foo();
sf::Transform otherTransform(...);
transformableClass.getTransform().combine( otherTransform );
//                 ^^^^^^^^^^^^^^^^^^^^^^
//can't do that! getTransform() returns a const sf::Transform&

We can create a non-const copy of foo and work from there, but this is kludgy looking, harder to read, and probably requires a comment to explain the motivation behind the copy (at least on multi-person projects). Addition of a const version of 'sf::Transform::combine()' would solve these issues by hiding the copy within the function body. Thoughts?
Title: Re: const version of sf::Transform::combine
Post by: Nexus on September 28, 2014, 10:38:30 pm
It's never good if the const overload has different semantics (return copy instead of in-place modification), additionally "combine" would then be a misleading name.

Anyway, use operator* :)
Title: Re: const version of sf::Transform::combine
Post by: Conduit on September 28, 2014, 10:57:13 pm
Oh, man, not sure how I missed that... Never mind, then - thanks, Nexus!