Prevent constructing sf::Text
with a temporary sf::Font
By deleting this constructor overload, it fails to compile if you pass a temporary font to this parameter slot. That includes code like sf::Text text("", sf::Font()); but more importantly it prohibits code like this sf::Font getFont() { sf::Font font; // load a font... return font; } sf::Text text("", getFont()); The same idea can be applied to setFont() to prevent setting fonts from a temporary. Credit to Jonny for the idea Co-authored-by: JonnyPtn <jonathan.r.paton@googlemail.com>
This commit is contained in:
parent
718195bf25
commit
3f4bb1ae12
@ -88,6 +88,12 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Disallow construction from a temporary font
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
Text(const String& string, Font&& font, unsigned int characterSize = 30) = delete;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
@ -150,6 +156,12 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setFont(const Font& font);
|
void setFont(const Font& font);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Disallow setting from a temporary font
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void setFont(Font&& font) = delete;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the character size
|
/// \brief Set the character size
|
||||||
///
|
///
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
static_assert(!std::is_constructible_v<sf::Text, sf::String, sf::Font&&, unsigned int>);
|
||||||
static_assert(std::is_copy_constructible_v<sf::Text>);
|
static_assert(std::is_copy_constructible_v<sf::Text>);
|
||||||
static_assert(std::is_copy_assignable_v<sf::Text>);
|
static_assert(std::is_copy_assignable_v<sf::Text>);
|
||||||
static_assert(std::is_nothrow_move_constructible_v<sf::Text>);
|
static_assert(std::is_nothrow_move_constructible_v<sf::Text>);
|
||||||
|
Loading…
Reference in New Issue
Block a user