So I have a basic class like this:
class SpriteBounds {
private:
Sint16 _x, _y;
Uint16 _w, _h;
constexpr SpriteBounds(Sint16 x, Sint16 y, Uint16 w, Uint16 h) : _x(x), _y(y), _w(w), _h(h) { }
public:
SpriteBounds(const BattleItem& battleItem);
SpriteBounds(const RuleItem& ruleItem);
constexpr SpriteBounds RelativeToInventory(const RuleInventory &inventory);
constexpr SpriteBounds RelativeToSlot(const RuleSlot &slot);
constexpr SpriteBounds Centered(const SDL_Rect& bounds);
constexpr SpriteBounds Offset(const int x, const int y);
constexpr SpriteBounds OffsetX(const int x) { return { _x + x, _y, _w, _h, }; }
constexpr SpriteBounds OffsetY(const int y) { return { _x, _y + y, _w, _h, }; }
}```
All the member functions just do basic translations and then return a new instance of the class via the private ctor. Now while I don't expect this class can be fully inlined (because it has to be constructed from my dynamic items) my hope is that by making it constexpr the compiler can be smart enough and inline all the translations?
That is when called like this:
```C++
const auto bounds = SpriteBounds(battleItem).RelativeToInventory(inventory).RelativeToSlot(slot).OffsetX(15);
The compiler can be smart enough that instead of creating a bunch of objects it can just perform all the translations "inline" as it were.
Is this a foolish hope? Does it even matter for so small a struct? Should I just mutate instead? Is there a better way?