From 0bdefd25d7043a222330e229a66bcd956c759046 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 26 Jun 2022 15:50:01 -0600 Subject: [PATCH] Use in-class member initializers See C++ Core Guidelines item C.45 for more information. https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c45-dont-define-a-default-constructor-that-only-initializes-data-members-use-in-class-member-initializers-instead --- include/SFML/System/Angle.hpp | 2 +- include/SFML/System/Angle.inl | 4 +--- include/SFML/System/Clock.hpp | 2 +- include/SFML/System/MemoryInputStream.hpp | 6 +++--- include/SFML/System/String.hpp | 3 ++- include/SFML/System/Time.hpp | 2 +- include/SFML/System/Time.inl | 4 +--- include/SFML/System/Vector2.hpp | 4 ++-- include/SFML/System/Vector2.inl | 4 +--- include/SFML/System/Vector3.hpp | 6 +++--- include/SFML/System/Vector3.inl | 4 +--- src/SFML/System/Clock.cpp | 4 +--- src/SFML/System/MemoryInputStream.cpp | 4 +--- src/SFML/System/String.cpp | 8 +------- 14 files changed, 20 insertions(+), 37 deletions(-) diff --git a/include/SFML/System/Angle.hpp b/include/SFML/System/Angle.hpp index 8cfcf4fd0..affcc2b32 100644 --- a/include/SFML/System/Angle.hpp +++ b/include/SFML/System/Angle.hpp @@ -160,7 +160,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - float m_degrees; //!< Angle value stored as degrees + float m_degrees{0}; //!< Angle value stored as degrees }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Angle.inl b/include/SFML/System/Angle.inl index 74a22acbc..d8b4e9b03 100644 --- a/include/SFML/System/Angle.inl +++ b/include/SFML/System/Angle.inl @@ -39,9 +39,7 @@ constexpr float positiveRemainder(float a, float b) //////////////////////////////////////////////////////////// -constexpr Angle::Angle() : m_degrees(0.0f) -{ -} +constexpr Angle::Angle() = default; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Clock.hpp b/include/SFML/System/Clock.hpp index a99f849a6..18b8b5794 100644 --- a/include/SFML/System/Clock.hpp +++ b/include/SFML/System/Clock.hpp @@ -140,7 +140,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - ClockImpl::time_point m_startTime; //!< Time of last reset + ClockImpl::time_point m_startTime{ClockImpl::now()}; //!< Time of last reset }; } // namespace sf diff --git a/include/SFML/System/MemoryInputStream.hpp b/include/SFML/System/MemoryInputStream.hpp index 3112f66ee..58b4224cf 100644 --- a/include/SFML/System/MemoryInputStream.hpp +++ b/include/SFML/System/MemoryInputStream.hpp @@ -105,9 +105,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - const char* m_data; //!< Pointer to the data in memory - std::int64_t m_size; //!< Total size of the data - std::int64_t m_offset; //!< Current reading position + const char* m_data{nullptr}; //!< Pointer to the data in memory + std::int64_t m_size{0}; //!< Total size of the data + std::int64_t m_offset{0}; //!< Current reading position }; } // namespace sf diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index cb3b4623f..06faf905f 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -56,7 +56,8 @@ public: //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// - static const std::size_t InvalidPos; //!< Represents an invalid position in the string + /// Represents an invalid position in the string + static inline const std::size_t InvalidPos{std::basic_string::npos}; //////////////////////////////////////////////////////////// /// \brief Default constructor diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 02afe267e..bd4b57084 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -119,7 +119,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::chrono::microseconds m_microseconds; //!< Time value stored as microseconds + std::chrono::microseconds m_microseconds{0}; //!< Time value stored as microseconds }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Time.inl b/include/SFML/System/Time.inl index 9dbc25a31..501040487 100644 --- a/include/SFML/System/Time.inl +++ b/include/SFML/System/Time.inl @@ -24,9 +24,7 @@ //////////////////////////////////////////////////////////// -constexpr Time::Time() : m_microseconds(0) -{ -} +constexpr Time::Time() = default; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Vector2.hpp b/include/SFML/System/Vector2.hpp index b12bdb143..8ca34a63b 100644 --- a/include/SFML/System/Vector2.hpp +++ b/include/SFML/System/Vector2.hpp @@ -210,8 +210,8 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - T x; //!< X coordinate of the vector - T y; //!< Y coordinate of the vector + T x{0}; //!< X coordinate of the vector + T y{0}; //!< Y coordinate of the vector //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Vector2.inl b/include/SFML/System/Vector2.inl index 637380f0e..32555d73a 100644 --- a/include/SFML/System/Vector2.inl +++ b/include/SFML/System/Vector2.inl @@ -25,9 +25,7 @@ //////////////////////////////////////////////////////////// template -constexpr Vector2::Vector2() : x(0), y(0) -{ -} +constexpr Vector2::Vector2() = default; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Vector3.hpp b/include/SFML/System/Vector3.hpp index b01719ecc..9304c00b3 100644 --- a/include/SFML/System/Vector3.hpp +++ b/include/SFML/System/Vector3.hpp @@ -134,9 +134,9 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - T x; //!< X coordinate of the vector - T y; //!< Y coordinate of the vector - T z; //!< Z coordinate of the vector + T x{0}; //!< X coordinate of the vector + T y{0}; //!< Y coordinate of the vector + T z{0}; //!< Z coordinate of the vector }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Vector3.inl b/include/SFML/System/Vector3.inl index a23265eaf..1a5391ec2 100644 --- a/include/SFML/System/Vector3.inl +++ b/include/SFML/System/Vector3.inl @@ -25,9 +25,7 @@ //////////////////////////////////////////////////////////// template -constexpr Vector3::Vector3() : x(0), y(0), z(0) -{ -} +constexpr Vector3::Vector3() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index 0f56c8b10..8e0a107ee 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -32,9 +32,7 @@ namespace sf { //////////////////////////////////////////////////////////// -Clock::Clock() : m_startTime(ClockImpl::now()) -{ -} +Clock::Clock() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/MemoryInputStream.cpp b/src/SFML/System/MemoryInputStream.cpp index 2c7299ab3..eb092cef7 100644 --- a/src/SFML/System/MemoryInputStream.cpp +++ b/src/SFML/System/MemoryInputStream.cpp @@ -33,9 +33,7 @@ namespace sf { //////////////////////////////////////////////////////////// -MemoryInputStream::MemoryInputStream() : m_data(nullptr), m_size(0), m_offset(0) -{ -} +MemoryInputStream::MemoryInputStream() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index 02dd023f3..a074369a6 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -35,13 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// -const std::size_t String::InvalidPos = std::basic_string::npos; - - -//////////////////////////////////////////////////////////// -String::String() -{ -} +String::String() = default; ////////////////////////////////////////////////////////////