SFML community forums

General => Feature requests => Topic started by: Xeverous on May 15, 2017, 11:31:05 pm

Title: make sf::Vector2/3<T> classes have constexpr constructors and functions
Post by: Xeverous on May 15, 2017, 11:31:05 pm
Pretty much in the title

Currently such code does not compile:
constexpr sf::Vector2u tile_size{64, 64};

GCC 5.1 output: (-std=c++14)
In file included from ../src/Application.cpp:4:0:
../src/Global.h:25:40: error: the type 'const Vector2u {aka const sf::Vector2<unsigned int>}' of constexpr variable 'constants::tile_size' is not literal
 constexpr sf::Vector2u tile_size{64, 64};
                                        ^
In file included from D:\Files\C++\include/SFML/Graphics/Rect.hpp:31:0,
                 from D:\Files\C++\include/SFGUI/Widget.hpp:5,
                 from D:\Files\C++\include/SFGUI/Container.hpp:3,
                 from D:\Files\C++\include/SFGUI/Bin.hpp:3,
                 from D:\Files\C++\include/SFGUI/Alignment.hpp:3,
                 from D:\Files\C++\include/SFGUI/Widgets.hpp:7,
                 from ../src/UserInterface.h:5,
                 from ../src/Application.h:3,
                 from ../src/Application.cpp:3:
D:\Files\C++\include/SFML/System/Vector2.hpp:37:7: note: 'sf::Vector2<unsigned int>' is not literal because:
 class Vector2
       ^
D:\Files\C++\include/SFML/System/Vector2.hpp:37:7: note:   'sf::Vector2<unsigned int>' is not an aggregate, does not have a trivial default constructor, and has no constexpr constructor that is not a copy or move constructor

It would be a convenient feature, and it's probably easy to implement
Title: Re: make sf::Vector2/3<T> classes have constexpr constructors and functions
Post by: Hapax on May 16, 2017, 01:23:48 am
constexpr was introduced in C++11. SFML 2 is C++98.

That said, I'm sure this has been discussed before and there's a likelihood of it making SFML version 3 when it will take on board (at least) C++11.