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

Author Topic: Add constexpr to appropriate data types  (Read 3521 times)

0 Members and 1 Guest are viewing this topic.

Hydrogen

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Add constexpr to appropriate data types
« on: February 25, 2017, 03:00:59 am »
Many of the simple containers (such as vectors and rectangles) out to have constexpr constructors and arithmetic operators. This is both a matter of efficiency and convenience.

Example 1:
auto vector_sum = sf::Vector2f{1, 2} + sf::Vector2f{3, 4}; // Optimization: compute vector_sum at compile-time if operator + is constexpr.

Example 2:
struct Foo {
    static constexpr sf::Vector2f vector_constant{5, 6}; // Only possible if ctor is constexpr.
    ...
}


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Hydrogen

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Add constexpr to appropriate data types
« Reply #2 on: February 26, 2017, 04:14:27 am »
That's odd; I specifically searched for "constexpr" using the search tool before I posted. Nothing showed up.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Add constexpr to appropriate data types
« Reply #3 on: February 26, 2017, 08:46:01 am »
It's not specifically about constexpr, but rather about supporting new C++ standards, so yes you may not find it by searching a specific language keyword.
Laurent Gomila - SFML developer

 

anything