mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
Merge topic 'constexpr_cxxNew_more'
b9842a846dSource: mark some optional methods as constexpr7fd73de51aSource: make some cmValue methods constexprae180314b6Source: come cmFileTime methods are constexpr for C++14 Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !12680
This commit is contained in:
commit
4aa3dec6c5
3 files changed
+32
-29
No files matched your search
+6
-4
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cm/bits/constexpr.hxx>
|
||||
|
||||
/** \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) {
|
||||
|
||||
+5
-2
@@ -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
|
||||
|
||||
+21
-23
@@ -17,6 +17,7 @@
|
||||
# endif
|
||||
# include <memory>
|
||||
|
||||
# include <cm/bits/constexpr.hxx>
|
||||
# include <cm/utility>
|
||||
#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<T> make_optional(Args&&... args)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
optional<T>::optional(nullopt_t) noexcept
|
||||
constexpr optional<T>::optional(nullopt_t) noexcept
|
||||
: optional()
|
||||
{
|
||||
}
|
||||
@@ -454,25 +455,25 @@ bool operator>=(T const& value, optional<U> const& opt)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const* optional<T>::operator->() const
|
||||
constexpr T const* optional<T>::operator->() const
|
||||
{
|
||||
return &**this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* optional<T>::operator->()
|
||||
CONSTEXPR_CXX14 T* optional<T>::operator->()
|
||||
{
|
||||
return &**this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const& optional<T>::operator*() const&
|
||||
constexpr T const& optional<T>::operator*() const&
|
||||
{
|
||||
return this->_mem.value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& optional<T>::operator*() &
|
||||
CONSTEXPR_CXX14 T& optional<T>::operator*() &
|
||||
{
|
||||
return this->_mem.value;
|
||||
}
|
||||
@@ -490,19 +491,19 @@ T&& optional<T>::operator*() &&
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool optional<T>::has_value() const noexcept
|
||||
constexpr bool optional<T>::has_value() const noexcept
|
||||
{
|
||||
return this->_has_value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
optional<T>::operator bool() const noexcept
|
||||
constexpr optional<T>::operator bool() const noexcept
|
||||
{
|
||||
return this->has_value();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& optional<T>::value() &
|
||||
CONSTEXPR_CXX14 T& optional<T>::value() &
|
||||
{
|
||||
if (!this->has_value()) {
|
||||
throw cm::bad_optional_access{};
|
||||
@@ -511,12 +512,9 @@ T& optional<T>::value() &
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const& optional<T>::value() const&
|
||||
constexpr T const& optional<T>::value() const&
|
||||
{
|
||||
if (!this->has_value()) {
|
||||
throw cm::bad_optional_access{};
|
||||
}
|
||||
return **this;
|
||||
return **(this->has_value() ? this : throw cm::bad_optional_access{});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in new issue
Block a user