detail: update bundled copies of {optional,scope,span}-lite
optional-lite commit 5e4b7760aac85ea73a5b9b91c726fc36cbd4149b
scope-lite commit 8987f3f94121ce15e19a9b65e0078dc3cd6272d6
span-lite commit 0248244006ad3cf31b2430b6c93bd87277e46c03
Change-Id: Ib7b2570201d56847d92db178071431323bbac467
diff --git a/ndn-cxx/detail/nonstd/optional-lite.hpp b/ndn-cxx/detail/nonstd/optional-lite.hpp
index 2c9f122..cc30bf5 100644
--- a/ndn-cxx/detail/nonstd/optional-lite.hpp
+++ b/ndn-cxx/detail/nonstd/optional-lite.hpp
@@ -44,20 +44,26 @@
# define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD )
#endif
+// Control presence of extensions:
+
+#ifndef optional_CONFIG_NO_EXTENSIONS
+#define optional_CONFIG_NO_EXTENSIONS 0
+#endif
+
// Control presence of exception handling (try and auto discover):
#ifndef optional_CONFIG_NO_EXCEPTIONS
# if defined(_MSC_VER)
# include <cstddef> // for _HAS_EXCEPTIONS
# endif
-# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS)
+# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS))
# define optional_CONFIG_NO_EXCEPTIONS 0
# else
# define optional_CONFIG_NO_EXCEPTIONS 1
# endif
#endif
-// C++ language version detection (C++20 is speculative):
+// C++ language version detection (C++23 is speculative):
// Note: VC14.0/1900 (VS2015) lacks too much from C++14.
#ifndef optional_CPLUSPLUS
@@ -73,7 +79,8 @@
#define optional_CPP11_OR_GREATER_ ( optional_CPLUSPLUS >= 201103L )
#define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L )
#define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L )
-#define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202000L )
+#define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202002L )
+#define optional_CPP23_OR_GREATER ( optional_CPLUSPLUS >= 202300L )
// C++ language version (represent 98 as 3):
@@ -1485,7 +1492,40 @@
return has_value() ? contained.value() : static_cast<value_type>( v );
}
-#endif // optional_CPP11_OR_GREATER
+#endif // optional_HAVE( REF_QUALIFIER )
+
+#if !optional_CONFIG_NO_EXTENSIONS
+#if optional_HAVE( REF_QUALIFIER )
+
+ template< typename F >
+ optional_constexpr value_type value_or_eval( F f ) const &
+ {
+ return has_value() ? contained.value() : f();
+ }
+
+ template< typename F >
+ optional_constexpr14 value_type value_or_eval( F f ) &&
+ {
+ if ( has_value() )
+ {
+ return std::move( contained.value() );
+ }
+ else
+ {
+ return f();
+ }
+ }
+
+#else
+
+ template< typename F >
+ optional_constexpr value_type value_or_eval( F f ) const
+ {
+ return has_value() ? contained.value() : f();
+ }
+
+#endif // optional_HAVE( REF_QUALIFIER )
+#endif // !optional_CONFIG_NO_EXTENSIONS
// x.x.3.6, modifiers
@@ -1530,37 +1570,37 @@
// Relational operators
template< typename T, typename U >
-inline optional_constexpr bool operator==( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator==( optional<T> const & x, optional<U> const & y )
{
return bool(x) != bool(y) ? false : !bool( x ) ? true : *x == *y;
}
template< typename T, typename U >
-inline optional_constexpr bool operator!=( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator!=( optional<T> const & x, optional<U> const & y )
{
return !(x == y);
}
template< typename T, typename U >
-inline optional_constexpr bool operator<( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator<( optional<T> const & x, optional<U> const & y )
{
return (!y) ? false : (!x) ? true : *x < *y;
}
template< typename T, typename U >
-inline optional_constexpr bool operator>( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator>( optional<T> const & x, optional<U> const & y )
{
return (y < x);
}
template< typename T, typename U >
-inline optional_constexpr bool operator<=( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator<=( optional<T> const & x, optional<U> const & y )
{
return !(y < x);
}
template< typename T, typename U >
-inline optional_constexpr bool operator>=( optional<T> const & x, optional<U> const & y )
+optional_nodiscard optional_constexpr bool operator>=( optional<T> const & x, optional<U> const & y )
{
return !(x < y);
}
@@ -1568,73 +1608,73 @@
// Comparison with nullopt
template< typename T >
-inline optional_constexpr bool operator==( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator==( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
{
return (!x);
}
template< typename T >
-inline optional_constexpr bool operator==( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator==( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
{
return (!x);
}
template< typename T >
-inline optional_constexpr bool operator!=( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator!=( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
{
return bool(x);
}
template< typename T >
-inline optional_constexpr bool operator!=( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator!=( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
{
return bool(x);
}
template< typename T >
-inline optional_constexpr bool operator<( optional<T> const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator<( optional<T> const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept
{
return false;
}
template< typename T >
-inline optional_constexpr bool operator<( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator<( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
{
return bool(x);
}
template< typename T >
-inline optional_constexpr bool operator<=( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator<=( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
{
return (!x);
}
template< typename T >
-inline optional_constexpr bool operator<=( nullopt_t /*unused*/, optional<T> const & /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator<=( nullopt_t /*unused*/, optional<T> const & /*unused*/ ) optional_noexcept
{
return true;
}
template< typename T >
-inline optional_constexpr bool operator>( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator>( optional<T> const & x, nullopt_t /*unused*/ ) optional_noexcept
{
return bool(x);
}
template< typename T >
-inline optional_constexpr bool operator>( nullopt_t /*unused*/, optional<T> const & /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator>( nullopt_t /*unused*/, optional<T> const & /*unused*/ ) optional_noexcept
{
return false;
}
template< typename T >
-inline optional_constexpr bool operator>=( optional<T> const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator>=( optional<T> const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept
{
return true;
}
template< typename T >
-inline optional_constexpr bool operator>=( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
+optional_nodiscard optional_constexpr bool operator>=( nullopt_t /*unused*/, optional<T> const & x ) optional_noexcept
{
return (!x);
}
@@ -1642,73 +1682,73 @@
// Comparison with T
template< typename T, typename U >
-inline optional_constexpr bool operator==( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator==( optional<T> const & x, U const & v )
{
return bool(x) ? *x == v : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator==( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator==( U const & v, optional<T> const & x )
{
return bool(x) ? v == *x : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator!=( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator!=( optional<T> const & x, U const & v )
{
return bool(x) ? *x != v : true;
}
template< typename T, typename U >
-inline optional_constexpr bool operator!=( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator!=( U const & v, optional<T> const & x )
{
return bool(x) ? v != *x : true;
}
template< typename T, typename U >
-inline optional_constexpr bool operator<( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator<( optional<T> const & x, U const & v )
{
return bool(x) ? *x < v : true;
}
template< typename T, typename U >
-inline optional_constexpr bool operator<( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator<( U const & v, optional<T> const & x )
{
return bool(x) ? v < *x : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator<=( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator<=( optional<T> const & x, U const & v )
{
return bool(x) ? *x <= v : true;
}
template< typename T, typename U >
-inline optional_constexpr bool operator<=( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator<=( U const & v, optional<T> const & x )
{
return bool(x) ? v <= *x : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator>( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator>( optional<T> const & x, U const & v )
{
return bool(x) ? *x > v : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator>( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator>( U const & v, optional<T> const & x )
{
return bool(x) ? v > *x : true;
}
template< typename T, typename U >
-inline optional_constexpr bool operator>=( optional<T> const & x, U const & v )
+optional_nodiscard optional_constexpr bool operator>=( optional<T> const & x, U const & v )
{
return bool(x) ? *x >= v : false;
}
template< typename T, typename U >
-inline optional_constexpr bool operator>=( U const & v, optional<T> const & x )
+optional_nodiscard optional_constexpr bool operator>=( U const & v, optional<T> const & x )
{
return bool(x) ? v >= *x : true;
}
diff --git a/ndn-cxx/detail/nonstd/scope-lite.hpp b/ndn-cxx/detail/nonstd/scope-lite.hpp
index aa8ce4c..0badcb9 100644
--- a/ndn-cxx/detail/nonstd/scope-lite.hpp
+++ b/ndn-cxx/detail/nonstd/scope-lite.hpp
@@ -45,11 +45,15 @@
# define scope_CONFIG_SELECT_SCOPE ( scope_HAVE_STD_SCOPE ? scope_SCOPE_STD : scope_SCOPE_NONSTD )
#endif
-// #if !defined( scope_CONFIG_STRICT )
-// # define scope_CONFIG_STRICT 0
-// #endif
+#if !defined( scope_CONFIG_NO_EXTENSIONS )
+# define scope_CONFIG_NO_EXTENSIONS 0
+#endif
-// C++ language version detection (C++20 is speculative):
+#if !defined( scope_CONFIG_NO_CONSTEXPR )
+# define scope_CONFIG_NO_CONSTEXPR (scope_CONFIG_NO_EXTENSIONS || !scope_CPP20_OR_GREATER)
+#endif
+
+// C++ language version detection (C++23 is speculative):
// Note: VC14.0/1900 (VS2015) lacks too much from C++14.
#ifndef scope_CPLUSPLUS
@@ -64,12 +68,16 @@
#define scope_CPP11_OR_GREATER ( scope_CPLUSPLUS >= 201103L )
#define scope_CPP14_OR_GREATER ( scope_CPLUSPLUS >= 201402L )
#define scope_CPP17_OR_GREATER ( scope_CPLUSPLUS >= 201703L )
-#define scope_CPP20_OR_GREATER ( scope_CPLUSPLUS >= 202000L )
+#define scope_CPP20_OR_GREATER ( scope_CPLUSPLUS >= 202002L )
+#define scope_CPP23_OR_GREATER ( scope_CPLUSPLUS >= 202300L )
// Use C++yy <scope> if available and requested:
+// Note: __cpp_lib_experimental_scope: a value of at least 201902 indicates that the scope guard are supported
#if scope_CPP20_OR_GREATER && defined(__has_include )
-# if __has_include( <scope> )
+# if __has_include( <scope> )
+# define scope_HAVE_STD_SCOPE 1
+# elif __has_include( <experimental/scope> )
# define scope_HAVE_STD_SCOPE 1
# else
# define scope_HAVE_STD_SCOPE 0
@@ -83,6 +91,10 @@
//
// Using std <scope>:
//
+// ToDo:
+// - choose <scope> or <experimental/scope>.
+// - use correct namespace in using below.
+//
#if scope_USES_STD_SCOPE
@@ -259,6 +271,12 @@
# define scope_constexpr14 /*constexpr*/
#endif
+#if !scope_CONFIG_NO_CONSTEXPR
+#define scope_constexpr_ext constexpr
+#else
+# define scope_constexpr_ext /*constexpr*/
+#endif
+
#if scope_HAVE( IS_DELETE )
# define scope_is_delete = delete
# define scope_is_delete_access public
@@ -558,6 +576,28 @@
} // namepsace std20
+namespace detail {
+
+#if scope_CONFIG_NO_CONSTEXPR
+
+using std17::uncaught_exceptions;
+
+#else
+constexpr int uncaught_exceptions() noexcept
+{
+ if ( std::is_constant_evaluated() )
+ {
+ return 0;
+ }
+ else
+ {
+ return std17::uncaught_exceptions();
+ }
+}
+#endif
+
+} // namespace detail
+
//
// For reference:
//
@@ -646,7 +686,7 @@
&& std11::is_constructible<EF, Fn>::value
))
>
- explicit scope_exit( Fn&& fn )
+ scope_constexpr_ext explicit scope_exit( Fn&& fn )
scope_noexcept_op
((
std11::is_nothrow_constructible<EF, Fn>::value
@@ -659,7 +699,7 @@
, execute_on_destruction( true )
{}
- scope_exit( scope_exit && other )
+ scope_constexpr_ext scope_exit( scope_exit && other )
scope_noexcept_op
((
std11::is_nothrow_move_constructible<EF>::value
@@ -671,22 +711,22 @@
other.release();
}
- ~scope_exit() scope_noexcept
+ scope_constexpr_ext ~scope_exit() scope_noexcept
{
if ( execute_on_destruction )
exit_function();
}
- void release() scope_noexcept
+ scope_constexpr_ext void release() scope_noexcept
{
execute_on_destruction = false;
}
scope_is_delete_access:
- scope_exit( scope_exit const & ) scope_is_delete;
+ scope_constexpr_ext scope_exit( scope_exit const & ) scope_is_delete;
- scope_exit & operator=( scope_exit const & ) scope_is_delete;
- scope_exit & operator=( scope_exit && ) scope_is_delete;
+ scope_constexpr_ext scope_exit & operator=( scope_exit const & ) scope_is_delete;
+ scope_constexpr_ext scope_exit & operator=( scope_exit && ) scope_is_delete;
private:
EF exit_function;
@@ -705,7 +745,7 @@
&& std11::is_constructible<EF, Fn>::value
))
>
- explicit scope_fail( Fn&& fn )
+ scope_constexpr_ext explicit scope_fail( Fn&& fn )
scope_noexcept_op
((
std11::is_nothrow_constructible<EF, Fn>::value
@@ -714,10 +754,10 @@
: exit_function(
conditional_forward<Fn>( std::forward<Fn>(fn)
, std11::bool_constant< std11::is_nothrow_constructible<EF, Fn>::value >() ) )
- , uncaught_on_creation( std17::uncaught_exceptions() )
+ , uncaught_on_creation( detail::uncaught_exceptions() )
{}
- scope_fail( scope_fail && other )
+ scope_constexpr_ext scope_fail( scope_fail && other )
scope_noexcept_op
((
std11::is_nothrow_move_constructible<EF>::value
@@ -729,26 +769,26 @@
other.release();
}
- ~scope_fail() scope_noexcept
+ scope_constexpr_ext ~scope_fail() scope_noexcept
{
- if ( uncaught_on_creation < std17::uncaught_exceptions() )
+ if ( uncaught_on_creation < detail::uncaught_exceptions() )
exit_function();
}
- void release() scope_noexcept
+ scope_constexpr_ext void release() scope_noexcept
{
uncaught_on_creation = std::numeric_limits<int>::max();
}
scope_is_delete_access:
- scope_fail( scope_fail const & ) scope_is_delete;
+ scope_constexpr_ext scope_fail( scope_fail const & ) scope_is_delete;
- scope_fail & operator=( scope_fail const & ) scope_is_delete;
- scope_fail & operator=( scope_fail && ) scope_is_delete;
+ scope_constexpr_ext scope_fail & operator=( scope_fail const & ) scope_is_delete;
+ scope_constexpr_ext scope_fail & operator=( scope_fail && ) scope_is_delete;
private:
EF exit_function;
- int uncaught_on_creation; // { std17::uncaught_exceptions() };
+ int uncaught_on_creation; // { detail::uncaught_exceptions() };
};
// scope_success:
@@ -763,7 +803,7 @@
&& std11::is_constructible<EF, Fn>::value
))
>
- explicit scope_success( Fn&& fn )
+ scope_constexpr_ext explicit scope_success( Fn&& fn )
scope_noexcept_op
((
std11::is_nothrow_constructible<EF, Fn>::value
@@ -772,10 +812,10 @@
: exit_function(
conditional_forward<Fn>( std::forward<Fn>(fn)
, std11::bool_constant< std11::is_nothrow_constructible<EF, Fn>::value >() ) )
- , uncaught_on_creation( std17::uncaught_exceptions() )
+ , uncaught_on_creation( detail::uncaught_exceptions() )
{}
- scope_success( scope_success && other )
+ scope_constexpr_ext scope_success( scope_success && other )
scope_noexcept_op
((
std11::is_nothrow_move_constructible<EF>::value
@@ -787,26 +827,26 @@
other.release();
}
- ~scope_success() scope_noexcept
+ scope_constexpr_ext ~scope_success() scope_noexcept
{
- if ( uncaught_on_creation >= std17::uncaught_exceptions() )
+ if ( uncaught_on_creation >= detail::uncaught_exceptions() )
exit_function();
}
- void release() scope_noexcept
+ scope_constexpr_ext void release() scope_noexcept
{
uncaught_on_creation = -1;
}
scope_is_delete_access:
- scope_success( scope_success const & ) scope_is_delete;
+ scope_constexpr_ext scope_success( scope_success const & ) scope_is_delete;
- scope_success & operator=( scope_success const & ) scope_is_delete;
- scope_success & operator=( scope_success && ) scope_is_delete;
+ scope_constexpr_ext scope_success & operator=( scope_success const & ) scope_is_delete;
+ scope_constexpr_ext scope_success & operator=( scope_success && ) scope_is_delete;
private:
EF exit_function;
- int uncaught_on_creation; // { std17::uncaught_exceptions() };
+ int uncaught_on_creation; // { detail::uncaught_exceptions() };
};
#if scope_HAVE( DEDUCTION_GUIDES )
@@ -818,6 +858,7 @@
// optional factory functions (should at least be present for LFTS3):
template< class EF >
+scope_constexpr_ext
scope_exit<typename std11::decay<EF>::type>
make_scope_exit( EF && exit_function )
{
@@ -825,6 +866,7 @@
}
template< class EF >
+scope_constexpr_ext
scope_fail<typename std11::decay<EF>::type>
make_scope_fail( EF && exit_function )
{
@@ -832,6 +874,7 @@
}
template< class EF >
+scope_constexpr_ext
scope_success<typename std11::decay<EF>::type>
make_scope_success( EF && exit_function )
{
@@ -1196,7 +1239,7 @@
mutable int ucount_;
on_fail_policy()
- : ucount_( std17::uncaught_exceptions() )
+ : ucount_( detail::uncaught_exceptions() )
{}
on_fail_policy( on_fail_policy const & other )
@@ -1212,7 +1255,7 @@
bool perform()
{
- return ucount_ < std17::uncaught_exceptions();
+ return ucount_ < detail::uncaught_exceptions();
}
};
@@ -1221,7 +1264,7 @@
mutable int ucount_;
on_success_policy()
- : ucount_( std17::uncaught_exceptions() )
+ : ucount_( detail::uncaught_exceptions() )
{}
on_success_policy( on_success_policy const & other )
@@ -1237,7 +1280,7 @@
bool perform()
{
- return ucount_ >= std17::uncaught_exceptions();
+ return ucount_ >= detail::uncaught_exceptions();
}
};
diff --git a/ndn-cxx/detail/nonstd/span-lite.hpp b/ndn-cxx/detail/nonstd/span-lite.hpp
index 4382f99..a2d0c5d 100644
--- a/ndn-cxx/detail/nonstd/span-lite.hpp
+++ b/ndn-cxx/detail/nonstd/span-lite.hpp
@@ -175,7 +175,7 @@
# error Please define none or one of span_CONFIG_CONTRACT_VIOLATION_THROWS and span_CONFIG_CONTRACT_VIOLATION_TERMINATES to 1, but not both.
#endif
-// C++ language version detection (C++20 is speculative):
+// C++ language version detection (C++23 is speculative):
// Note: VC14.0/1900 (VS2015) lacks too much from C++14.
#ifndef span_CPLUSPLUS
@@ -190,7 +190,8 @@
#define span_CPP11_OR_GREATER ( span_CPLUSPLUS >= 201103L )
#define span_CPP14_OR_GREATER ( span_CPLUSPLUS >= 201402L )
#define span_CPP17_OR_GREATER ( span_CPLUSPLUS >= 201703L )
-#define span_CPP20_OR_GREATER ( span_CPLUSPLUS >= 202000L )
+#define span_CPP20_OR_GREATER ( span_CPLUSPLUS >= 202002L )
+#define span_CPP23_OR_GREATER ( span_CPLUSPLUS >= 202300L )
// C++ language version (represent 98 as 3):
diff --git a/ndn-cxx/util/optional.hpp b/ndn-cxx/util/optional.hpp
index ab3d88c..9113ead 100644
--- a/ndn-cxx/util/optional.hpp
+++ b/ndn-cxx/util/optional.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,6 +23,7 @@
#define NDN_CXX_UTIL_OPTIONAL_HPP
#define optional_CONFIG_SELECT_OPTIONAL optional_OPTIONAL_NONSTD
+#define optional_CONFIG_NO_EXTENSIONS 1
#include "ndn-cxx/detail/nonstd/optional-lite.hpp"
namespace ndn {