Skip to content

Commit

Permalink
Merge a33ea58 into 2b5b84b
Browse files Browse the repository at this point in the history
  • Loading branch information
Minoru committed May 28, 2022
2 parents 2b5b84b + a33ea58 commit 0182dd2
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions 3rd-party/expected.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This version targets C++11 and later.
//
// Copyright (C) 2016-2018 Martin Moene.
// Copyright (C) 2016-2020 Martin Moene.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -66,16 +66,25 @@
# define nsel_P0323R 7
#endif

// Control presence of exception handling (try and auto discover):
// Control presence of C++ exception handling (try and auto discover):

#ifndef nsel_CONFIG_NO_EXCEPTIONS
# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
# if defined(_MSC_VER)
# include <cstddef> // for _HAS_EXCEPTIONS
# endif
# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS)
# define nsel_CONFIG_NO_EXCEPTIONS 0
# else
# define nsel_CONFIG_NO_EXCEPTIONS 1
# endif
#endif

// at default use SEH with MSVC for no C++ exceptions

#ifndef nsel_CONFIG_NO_EXCEPTIONS_SEH
# define nsel_CONFIG_NO_EXCEPTIONS_SEH ( nsel_CONFIG_NO_EXCEPTIONS && _MSC_VER )
#endif

// C++ language version detection (C++20 is speculative):
// Note: VC14.0/1900 (VS2015) lacks too much from C++14.

Expand All @@ -92,10 +101,11 @@
#define nsel_CPP14_OR_GREATER ( nsel_CPLUSPLUS >= 201402L )
#define nsel_CPP17_OR_GREATER ( nsel_CPLUSPLUS >= 201703L )
#define nsel_CPP20_OR_GREATER ( nsel_CPLUSPLUS >= 202000L )
#define nsel_CPP23_OR_GREATER ( nsel_CPLUSPLUS >= 202300L )

// Use C++20 std::expected if available and requested:
// Use C++23 std::expected if available and requested:

#if nsel_CPP20_OR_GREATER && defined(__has_include )
#if nsel_CPP23_OR_GREATER && defined(__has_include )
# if __has_include( <expected> )
# define nsel_HAVE_STD_EXPECTED 1
# else
Expand Down Expand Up @@ -224,7 +234,11 @@ namespace nonstd {
// additional includes:

#if nsel_CONFIG_NO_EXCEPTIONS
# if nsel_CONFIG_NO_EXCEPTIONS_SEH
# include <windows.h> // for ExceptionCodes
# else
// already included: <cassert>
# endif
#else
# include <stdexcept>
#endif
Expand Down Expand Up @@ -1260,7 +1274,11 @@ struct error_traits
{
static void rethrow( Error const & /*e*/ )
{
#if nsel_CONFIG_NO_EXCEPTIONS_SEH
RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL );
#else
assert( false && detail::text("throw bad_expected_access<Error>{ e };") );
#endif
}
};

Expand All @@ -1269,7 +1287,11 @@ struct error_traits< std::exception_ptr >
{
static void rethrow( std::exception_ptr const & /*e*/ )
{
#if nsel_CONFIG_NO_EXCEPTIONS_SEH
RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL );
#else
assert( false && detail::text("throw bad_expected_access<std::exception_ptr>{ e };") );
#endif
}
};

Expand All @@ -1278,7 +1300,11 @@ struct error_traits< std::error_code >
{
static void rethrow( std::error_code const & /*e*/ )
{
#if nsel_CONFIG_NO_EXCEPTIONS_SEH
RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL );
#else
assert( false && detail::text("throw std::system_error( e );") );
#endif
}
};

Expand Down Expand Up @@ -1639,10 +1665,11 @@ class expected
return *this;
}

template< typename G
template< typename G = E
nsel_REQUIRES_T(
std::is_copy_constructible<E>::value // TODO: std::is_nothrow_copy_constructible<E>
&& std::is_copy_assignable<E>::value
std::is_constructible<E, G const&>::value &&
std::is_copy_constructible<G>::value // TODO: std::is_nothrow_copy_constructible<G>
&& std::is_copy_assignable<G>::value
)
>
expected & operator=( nonstd::unexpected_type<G> const & error )
Expand All @@ -1651,10 +1678,11 @@ class expected
return *this;
}

template< typename G
template< typename G = E
nsel_REQUIRES_T(
std::is_move_constructible<E>::value // TODO: std::is_nothrow_move_constructible<E>
&& std::is_move_assignable<E>::value
std::is_constructible<E, G&&>::value &&
std::is_move_constructible<G>::value // TODO: std::is_nothrow_move_constructible<G>
&& std::is_move_assignable<G>::value
)
>
expected & operator=( nonstd::unexpected_type<G> && error )
Expand Down Expand Up @@ -1742,12 +1770,12 @@ class expected

constexpr value_type const && operator *() const &&
{
return assert( has_value() ), std::move( contained.value() );
return std::move( ( assert( has_value() ), contained.value() ) );
}

nsel_constexpr14 value_type && operator *() &&
{
return assert( has_value() ), std::move( contained.value() );
return std::move( ( assert( has_value() ), contained.value() ) );
}

#endif
Expand Down Expand Up @@ -1808,12 +1836,12 @@ class expected

constexpr error_type const && error() const &&
{
return assert( ! has_value() ), std::move( contained.error() );
return std::move( ( assert( ! has_value() ), contained.error() ) );
}

error_type && error() &&
{
return assert( ! has_value() ), std::move( contained.error() );
return std::move( ( assert( ! has_value() ), contained.error() ) );
}

#endif
Expand Down Expand Up @@ -2080,12 +2108,12 @@ class expected<void, E>

constexpr error_type const && error() const &&
{
return assert( ! has_value() ), std::move( contained.error() );
return std::move( ( assert( ! has_value() ), contained.error() ) );
}

error_type && error() &&
{
return assert( ! has_value() ), std::move( contained.error() );
return std::move( ( assert( ! has_value() ), contained.error() ) );
}

#endif
Expand Down

0 comments on commit 0182dd2

Please sign in to comment.