From e09f9c439e6c2de1ba7003ebedb9f1ba436c58c9 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 3 Nov 2021 21:35:05 +0100 Subject: [PATCH] bump: Upgrade to optional-lite 3.5.0 --- LICENSE.adoc | 4 +-- src/third_party/nonstd/optional.hpp | 40 +++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/LICENSE.adoc b/LICENSE.adoc index e340fdd50..0ff2ca976 100644 --- a/LICENSE.adoc +++ b/LICENSE.adoc @@ -612,11 +612,11 @@ DEALINGS IN THE SOFTWARE. === src/third_party/nonstd/optional.hpp This is the single header version of -https://github.com/martinmoene/optional-lite[optional-lite] 3.4.0 with the +https://github.com/martinmoene/optional-lite[optional-lite] 3.5.0 with the following license: ---- -Copyright (c) 2014-2018 Martin Moene +Copyright (c) 2014-2021 Martin Moene Boost Software License - Version 1.0 - August 17th, 2003 diff --git a/src/third_party/nonstd/optional.hpp b/src/third_party/nonstd/optional.hpp index 8b371e5a8..2c9f12242 100644 --- a/src/third_party/nonstd/optional.hpp +++ b/src/third_party/nonstd/optional.hpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2014-2018 Martin Moene +// Copyright (c) 2014-2021 Martin Moene // // https://github.com/martinmoene/optional-lite // @@ -12,7 +12,7 @@ #define NONSTD_OPTIONAL_LITE_HPP #define optional_lite_MAJOR 3 -#define optional_lite_MINOR 4 +#define optional_lite_MINOR 5 #define optional_lite_PATCH 0 #define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH) @@ -47,7 +47,7 @@ // Control presence of exception handling (try and auto discover): #ifndef optional_CONFIG_NO_EXCEPTIONS -# if _MSC_VER +# if defined(_MSC_VER) # include // for _HAS_EXCEPTIONS # endif # if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) @@ -313,11 +313,11 @@ namespace nonstd { #define optional_CPP14_000 (optional_CPP14_OR_GREATER) #define optional_CPP17_000 (optional_CPP17_OR_GREATER) -// gcc >= 4.9, msvc >= vc14.1 (vs17): -#define optional_CPP11_140_G490 ((optional_CPP11_OR_GREATER_ && optional_COMPILER_GNUC_VERSION >= 490) || (optional_COMPILER_MSVC_VER >= 1910)) +// clang >= 2.9, gcc >= 4.9, msvc >= vc14.0/1900 (vs15): +#define optional_CPP11_140_C290_G490 ((optional_CPP11_OR_GREATER_ && (optional_COMPILER_CLANG_VERSION >= 290 || optional_COMPILER_GNUC_VERSION >= 490)) || (optional_COMPILER_MSVC_VER >= 1900)) // clang >= 3.5, msvc >= vc11 (vs12): -#define optional_CPP11_110_C350 ( optional_CPP11_110 && !optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) ) +#define optional_CPP11_110_C350 ( optional_CPP11_110 && !optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) ) // clang >= 3.5, gcc >= 5.0, msvc >= vc11 (vs12): #define optional_CPP11_110_C350_G500 \ @@ -331,7 +331,8 @@ namespace nonstd { #define optional_HAVE_IS_DEFAULT optional_CPP11_140 #define optional_HAVE_NOEXCEPT optional_CPP11_140 #define optional_HAVE_NULLPTR optional_CPP11_100 -#define optional_HAVE_REF_QUALIFIER optional_CPP11_140_G490 +#define optional_HAVE_REF_QUALIFIER optional_CPP11_140_C290_G490 +#define optional_HAVE_STATIC_ASSERT optional_CPP11_110 #define optional_HAVE_INITIALIZER_LIST optional_CPP11_140 // Presence of C++14 language features: @@ -405,6 +406,12 @@ namespace nonstd { # define optional_refref_qual /*&&*/ #endif +#if optional_HAVE( STATIC_ASSERT ) +# define optional_static_assert(expr, text) static_assert(expr, text); +#else +# define optional_static_assert(expr, text) /*static_assert(expr, text);*/ +#endif + // additional includes: #if optional_CONFIG_NO_EXCEPTIONS @@ -917,6 +924,15 @@ public: template< typename T> class optional { + optional_static_assert(( !std::is_same::type, nullopt_t>::value ), + "T in optional must not be of type 'nullopt_t'.") + + optional_static_assert(( !std::is_same::type, in_place_t>::value ), + "T in optional must not be of type 'in_place_t'.") + + optional_static_assert(( std::is_object::value && std::is_destructible::value && !std::is_array::value ), + "T in optional must meet the Cpp17Destructible requirements.") + private: template< typename > friend class optional; @@ -925,7 +941,7 @@ private: public: typedef T value_type; - // x.x.3.1, constructors + // x.x.3.1, constructors // 1a - default construct optional_constexpr optional() optional_noexcept @@ -1090,7 +1106,7 @@ public: > optional_constexpr explicit optional( nonstd_lite_in_place_t(T), Args&&... args ) : has_value_( true ) - , contained( T( std::forward(args)...) ) + , contained( in_place, std::forward(args)... ) {} // 7 (C++11) - in-place construct, initializer-list @@ -1443,7 +1459,7 @@ public: #endif -#if optional_CPP11_OR_GREATER +#if optional_HAVE( REF_QUALIFIER ) template< typename U > optional_constexpr value_type value_or( U && v ) const optional_ref_qual @@ -1454,7 +1470,11 @@ public: template< typename U > optional_constexpr14 value_type value_or( U && v ) optional_refref_qual { +#if optional_COMPILER_CLANG_VERSION + return has_value() ? /*std::move*/( contained.value() ) : static_cast(std::forward( v ) ); +#else return has_value() ? std::move( contained.value() ) : static_cast(std::forward( v ) ); +#endif } #else -- 2.47.2