Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: const version of sf::Transform::combine  (Read 2760 times)

0 Members and 1 Guest are viewing this topic.

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
const version of sf::Transform::combine
« 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?
« Last Edit: September 28, 2014, 10:22:59 pm by Conduit »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: const version of sf::Transform::combine
« Reply #1 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* :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: const version of sf::Transform::combine
« Reply #2 on: September 28, 2014, 10:57:13 pm »
Oh, man, not sure how I missed that... Never mind, then - thanks, Nexus!

 

anything