diff --git a/Source/cmFileTime.h b/Source/cmFileTime.h index 8cf477fd47..1fb62b17d0 100644 --- a/Source/cmFileTime.h +++ b/Source/cmFileTime.h @@ -6,6 +6,8 @@ #include +#include + /** \class cmFileTime * \brief Abstract file modification time with support for comparison with * other file modification times. @@ -62,7 +64,7 @@ public: * @brief Compare file modification times. * @return -1, 0, +1 for this older, same, or newer than ftm. */ - int Compare(cmFileTime ftm) const + CONSTEXPR_CXX14 int Compare(cmFileTime ftm) const { TimeType const diff = this->Time - ftm.Time; if (diff == 0) { @@ -92,7 +94,7 @@ public: /** * @brief Return true if this is within the same second as ftm */ - bool EqualS(cmFileTime ftm) const + CONSTEXPR_CXX14 bool EqualS(cmFileTime ftm) const { TimeType diff = this->Time - ftm.Time; if (diff < 0) { @@ -104,7 +106,7 @@ public: /** * @brief Return true if this is older or newer than ftm by at least a second */ - bool DifferS(cmFileTime ftm) const + CONSTEXPR_CXX14 bool DifferS(cmFileTime ftm) const { TimeType diff = this->Time - ftm.Time; if (diff < 0) { @@ -118,7 +120,7 @@ public: * @return -1: this at least a second older, 0: this within the same second * as ftm, +1: this at least a second newer than ftm. */ - int CompareS(cmFileTime ftm) const + CONSTEXPR_CXX14 int CompareS(cmFileTime ftm) const { TimeType const diff = this->Time - ftm.Time; if (diff <= -cmFileTime::UtPerS) { diff --git a/Source/cmValue.h b/Source/cmValue.h index 58edd54b31..9820d37db9 100644 --- a/Source/cmValue.h +++ b/Source/cmValue.h @@ -136,11 +136,14 @@ public: } static bool IsNOTFOUND(cm::string_view) noexcept; - static bool IsEmpty(char const* value) noexcept + static constexpr bool IsEmpty(char const* value) noexcept { return !value || *value == '\0'; } - static bool IsEmpty(cm::string_view value) noexcept { return value.empty(); } + static constexpr bool IsEmpty(cm::string_view value) noexcept + { + return value.empty(); + } /** * Does a string indicates that CMake/CPack/CTest internally diff --git a/Utilities/std/cm/optional b/Utilities/std/cm/optional index 6a03a6c062..3ceb29e24a 100644 --- a/Utilities/std/cm/optional +++ b/Utilities/std/cm/optional @@ -17,6 +17,7 @@ # endif # include +# include # include #endif @@ -50,8 +51,8 @@ class optional public: using value_type = T; - optional() noexcept = default; - optional(nullopt_t) noexcept; + constexpr optional() noexcept = default; + constexpr optional(nullopt_t) noexcept; optional(optional const& other); optional(optional&& other) noexcept; @@ -88,18 +89,18 @@ public: optional&>::type operator=(U&& v); - T const* operator->() const; - T* operator->(); - T const& operator*() const&; - T& operator*() &; + constexpr T const* operator->() const; + CONSTEXPR_CXX14 T* operator->(); + constexpr T const& operator*() const&; + CONSTEXPR_CXX14 T& operator*() &; T const&& operator*() const&&; T&& operator*() &&; - explicit operator bool() const noexcept; - bool has_value() const noexcept; + constexpr explicit operator bool() const noexcept; + constexpr bool has_value() const noexcept; - T& value() &; - T const& value() const&; + CONSTEXPR_CXX14 T& value() &; + constexpr T const& value() const&; T&& value() &&; T const&& value() const&&; @@ -148,7 +149,7 @@ optional make_optional(Args&&... args) } template -optional::optional(nullopt_t) noexcept +constexpr optional::optional(nullopt_t) noexcept : optional() { } @@ -454,25 +455,25 @@ bool operator>=(T const& value, optional const& opt) } template -T const* optional::operator->() const +constexpr T const* optional::operator->() const { return &**this; } template -T* optional::operator->() +CONSTEXPR_CXX14 T* optional::operator->() { return &**this; } template -T const& optional::operator*() const& +constexpr T const& optional::operator*() const& { return this->_mem.value; } template -T& optional::operator*() & +CONSTEXPR_CXX14 T& optional::operator*() & { return this->_mem.value; } @@ -490,19 +491,19 @@ T&& optional::operator*() && } template -bool optional::has_value() const noexcept +constexpr bool optional::has_value() const noexcept { return this->_has_value; } template -optional::operator bool() const noexcept +constexpr optional::operator bool() const noexcept { return this->has_value(); } template -T& optional::value() & +CONSTEXPR_CXX14 T& optional::value() & { if (!this->has_value()) { throw cm::bad_optional_access{}; @@ -511,12 +512,9 @@ T& optional::value() & } template -T const& optional::value() const& +constexpr T const& optional::value() const& { - if (!this->has_value()) { - throw cm::bad_optional_access{}; - } - return **this; + return **(this->has_value() ? this : throw cm::bad_optional_access{}); } template