feat():initial version

This commit is contained in:
2026-06-09 20:16:47 +08:00
commit 85fbb3188c
14809 changed files with 3044607 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#ifndef BOOST_LEAF_HPP_INCLUDED
#define BOOST_LEAF_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/leaf/capture.hpp>
#include <boost/leaf/common.hpp>
#include <boost/leaf/context.hpp>
#include <boost/leaf/error.hpp>
#include <boost/leaf/exception.hpp>
#include <boost/leaf/handle_errors.hpp>
#include <boost/leaf/on_error.hpp>
#include <boost/leaf/pred.hpp>
#include <boost/leaf/result.hpp>
#endif

View File

@@ -0,0 +1,187 @@
#ifndef BOOST_LEAF_CONFIG_HPP_INCLUDED
#define BOOST_LEAF_CONFIG_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// The following is based on Boost Config.
// (C) Copyright John Maddock 2001 - 2003.
// (C) Copyright Martin Wille 2003.
// (C) Copyright Guillaume Melquiond 2003.
#ifndef BOOST_LEAF_ENABLE_WARNINGS
# if defined(__clang__)
# pragma clang system_header
# elif (__GNUC__*100+__GNUC_MINOR__>301)
# pragma GCC system_header
# elif defined(_MSC_VER)
# pragma warning(push,1)
# endif
#endif
////////////////////////////////////////
// Configure BOOST_LEAF_NO_EXCEPTIONS, unless already #defined
#ifndef BOOST_LEAF_NO_EXCEPTIONS
# if defined(__clang__) && !defined(__ibmxl__)
// Clang C++ emulates GCC, so it has to appear early.
# if !__has_feature(cxx_exceptions)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__DMC__)
// Digital Mars C++
# if !defined(_CPPUNWIND)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__GNUC__) && !defined(__ibmxl__)
// GNU C++:
# if !defined(__EXCEPTIONS)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__KCC)
// Kai C++
# if !defined(_EXCEPTIONS)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__CODEGEARC__)
// CodeGear - must be checked for before Borland
# if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__BORLANDC__)
// Borland
# if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__MWERKS__)
// Metrowerks CodeWarrior
# if !__option(exceptions)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__IBMCPP__) && defined(__COMPILER_VER__) && defined(__MVS__)
// IBM z/OS XL C/C++
# if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(__ibmxl__)
// IBM XL C/C++ for Linux (Little Endian)
# if !__has_feature(cxx_exceptions)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# elif defined(_MSC_VER)
// Microsoft Visual C++
//
// Must remain the last #elif since some other vendors (Metrowerks, for
// example) also #define _MSC_VER
# if !defined(_CPPUNWIND)
# define BOOST_LEAF_NO_EXCEPTIONS
# endif
# endif
#endif
#ifdef BOOST_NORETURN
# define BOOST_LEAF_NORETURN BOOST_NORETURN
#else
# if defined(_MSC_VER)
# define BOOST_LEAF_NORETURN __declspec(noreturn)
# elif defined(__GNUC__)
# define BOOST_LEAF_NORETURN __attribute__ ((__noreturn__))
# elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130)
# if __has_attribute(noreturn)
# define BOOST_LEAF_NORETURN [[noreturn]]
# endif
# elif defined(__has_cpp_attribute)
# if __has_cpp_attribute(noreturn)
# define BOOST_LEAF_NORETURN [[noreturn]]
# endif
# endif
#endif
#if !defined(BOOST_LEAF_NORETURN)
# define BOOST_LEAF_NORETURN
#endif
////////////////////////////////////////
#ifndef BOOST_LEAF_DIAGNOSTICS
# define BOOST_LEAF_DIAGNOSTICS 1
#endif
#if BOOST_LEAF_DIAGNOSTICS!=0 && BOOST_LEAF_DIAGNOSTICS!=1
# error BOOST_LEAF_DIAGNOSTICS must be 0 or 1.
#endif
////////////////////////////////////////
#ifdef _MSC_VER
# define BOOST_LEAF_ALWAYS_INLINE __forceinline
#else
# define BOOST_LEAF_ALWAYS_INLINE __attribute__((always_inline)) inline
#endif
////////////////////////////////////////
#ifndef BOOST_LEAF_NODISCARD
# if __cplusplus >= 201703L
# define BOOST_LEAF_NODISCARD [[nodiscard]]
# else
# define BOOST_LEAF_NODISCARD
# endif
#endif
////////////////////////////////////////
#ifndef BOOST_LEAF_CONSTEXPR
# if __cplusplus > 201402L
# define BOOST_LEAF_CONSTEXPR constexpr
# else
# define BOOST_LEAF_CONSTEXPR
# endif
#endif
////////////////////////////////////////
#ifndef BOOST_LEAF_ASSERT
# ifdef BOOST_ASSERT
# define BOOST_LEAF_ASSERT BOOST_ASSERT
# else
# include <cassert>
# define BOOST_LEAF_ASSERT assert
# endif
#endif
////////////////////////////////////////
#ifndef BOOST_LEAF_NO_EXCEPTIONS
# include <exception>
# if (defined(__cpp_lib_uncaught_exceptions) && __cpp_lib_uncaught_exceptions >= 201411L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
# define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 1
# else
# define BOOST_LEAF_STD_UNCAUGHT_EXCEPTIONS 0
# endif
#endif
#endif

View File

@@ -0,0 +1,128 @@
#ifndef BOOST_LEAF_DETAIL_DEMANGLE_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_DEMANGLE_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// core::demangle
//
// Copyright 2014 Peter Dimov
// Copyright 2014 Andrey Semashev
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_LEAF_ENABLE_WARNINGS
# if defined(__clang__)
# pragma clang system_header
# elif (__GNUC__*100+__GNUC_MINOR__>301)
# pragma GCC system_header
# elif defined(_MSC_VER)
# pragma warning(push,1)
# endif
#endif
#if !defined(_MSC_VER)
# if defined(__has_include) && __has_include(<cxxabi.h>)
# define BOOST_LEAF_HAS_CXXABI_H
# endif
#endif
#if defined( BOOST_LEAF_HAS_CXXABI_H )
# include <cxxabi.h>
// For some architectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library
// (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement
// abi::__cxa_demangle(). We detect this implementation by checking the include guard here.
# if defined( __GABIXX_CXXABI_H__ )
# undef BOOST_LEAF_HAS_CXXABI_H
# else
# include <cstddef>
# endif
#endif
namespace boost { namespace leaf {
namespace leaf_detail
{
inline char const * demangle_alloc( char const * name ) noexcept;
inline void demangle_free( char const * name ) noexcept;
class scoped_demangled_name
{
private:
char const * m_p;
public:
explicit scoped_demangled_name( char const * name ) noexcept :
m_p( demangle_alloc( name ) )
{
}
~scoped_demangled_name() noexcept
{
demangle_free( m_p );
}
char const * get() const noexcept
{
return m_p;
}
scoped_demangled_name( scoped_demangled_name const& ) = delete;
scoped_demangled_name& operator= ( scoped_demangled_name const& ) = delete;
};
#if defined( BOOST_LEAF_HAS_CXXABI_H )
inline char const * demangle_alloc( char const * name ) noexcept
{
int status = 0;
std::size_t size = 0;
return abi::__cxa_demangle( name, NULL, &size, &status );
}
inline void demangle_free( char const * name ) noexcept
{
std::free( const_cast< char* >( name ) );
}
inline char const * demangle( char const * name )
{
scoped_demangled_name demangled_name( name );
char const * p = demangled_name.get();
if( !p )
p = name;
return p;
}
#else
inline char const * demangle_alloc( char const * name ) noexcept
{
return name;
}
inline void demangle_free( char const * ) noexcept
{
}
inline char const * demangle( char const * name )
{
return name;
}
#endif
}
} }
#ifdef BOOST_LEAF_HAS_CXXABI_H
# undef BOOST_LEAF_HAS_CXXABI_H
#endif
#endif

View File

@@ -0,0 +1,100 @@
#ifndef BOOST_LEAF_DETAIL_FUNCTION_TRAITS_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_FUNCTION_TRAITS_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEAF_ENABLE_WARNINGS
# if defined(__clang__)
# pragma clang system_header
# elif (__GNUC__*100+__GNUC_MINOR__>301)
# pragma GCC system_header
# elif defined(_MSC_VER)
# pragma warning(push,1)
# endif
#endif
#include <boost/leaf/detail/mp11.hpp>
#include <tuple>
namespace boost { namespace leaf {
namespace leaf_detail
{
template<class...>
struct gcc49_workaround //Thanks Glen Fernandes
{
using type = void;
};
template<class... T>
using void_t = typename gcc49_workaround<T...>::type;
template<class F,class V=void>
struct function_traits
{
constexpr static int arity = -1;
};
template<class F>
struct function_traits<F, void_t<decltype(&F::operator())>>
{
private:
using tr = function_traits<decltype(&F::operator())>;
public:
using return_type = typename tr::return_type;
static constexpr int arity = tr::arity - 1;
using mp_args = typename leaf_detail_mp11::mp_rest<typename tr::mp_args>;
template <int I>
struct arg:
tr::template arg<I+1>
{
};
};
template<class R, class... A>
struct function_traits<R(A...)>
{
using return_type = R;
static constexpr int arity = sizeof...(A);
using mp_args = leaf_detail_mp11::mp_list<A...>;
template <int I>
struct arg
{
static_assert(I < arity, "I out of range");
using type = typename std::tuple_element<I,std::tuple<A...>>::type;
};
};
template<class F> struct function_traits<F&> : function_traits<F> { };
template<class F> struct function_traits<F&&> : function_traits<F> { };
template<class R, class... A> struct function_traits<R(*)(A...)> : function_traits<R(A...)> { };
template<class R, class... A> struct function_traits<R(* &)(A...)> : function_traits<R(A...)> { };
template<class R, class... A> struct function_traits<R(* const &)(A...)> : function_traits<R(A...)> { };
template<class C, class R, class... A> struct function_traits<R(C::*)(A...)> : function_traits<R(C&,A...)> { };
template<class C, class R, class... A> struct function_traits<R(C::*)(A...) const> : function_traits<R(C const &,A...)> { };
template<class C, class R> struct function_traits<R(C::*)> : function_traits<R(C&)> { };
template <class F>
using fn_return_type = typename function_traits<F>::return_type;
template <class F, int I>
using fn_arg_type = typename function_traits<F>::template arg<I>::type;
template <class F>
using fn_mp_args = typename function_traits<F>::mp_args;
}
} }
#endif

View File

@@ -0,0 +1,303 @@
#ifndef BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_MP11_HPP_INCLUDED
// Copyright 2015-2017 Peter Dimov.
// Copyright 2019 Emil Dotchevski.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <type_traits>
#include <cstddef>
namespace boost { namespace leaf { namespace leaf_detail_mp11 {
// mp_list<T...>
template<class... T> struct mp_list
{
};
// mp_identity
template<class T> struct mp_identity
{
using type = T;
};
// mp_inherit
template<class... T> struct mp_inherit: T... {};
// mp_if, mp_if_c
namespace detail
{
template<bool C, class T, class... E> struct mp_if_c_impl
{
};
template<class T, class... E> struct mp_if_c_impl<true, T, E...>
{
using type = T;
};
template<class T, class E> struct mp_if_c_impl<false, T, E>
{
using type = E;
};
} // namespace detail
template<bool C, class T, class... E> using mp_if_c = typename detail::mp_if_c_impl<C, T, E...>::type;
template<class C, class T, class... E> using mp_if = typename detail::mp_if_c_impl<static_cast<bool>(C::value), T, E...>::type;
// mp_bool
template<bool B> using mp_bool = std::integral_constant<bool, B>;
using mp_true = mp_bool<true>;
using mp_false = mp_bool<false>;
// mp_to_bool
template<class T> using mp_to_bool = mp_bool<static_cast<bool>( T::value )>;
// mp_not<T>
template<class T> using mp_not = mp_bool< !T::value >;
// mp_int
template<int I> using mp_int = std::integral_constant<int, I>;
// mp_size_t
template<std::size_t N> using mp_size_t = std::integral_constant<std::size_t, N>;
// mp_set_contains<S, V>
namespace detail
{
template<class S, class V> struct mp_set_contains_impl;
template<template<class...> class L, class... T, class V> struct mp_set_contains_impl<L<T...>, V>
{
using type = mp_to_bool<std::is_base_of<mp_identity<V>, mp_inherit<mp_identity<T>...> > >;
};
} // namespace detail
template<class S, class V> using mp_set_contains = typename detail::mp_set_contains_impl<S, V>::type;
// mp_set_push_back<S, T...>
namespace detail
{
template<class S, class... T> struct mp_set_push_back_impl;
template<template<class...> class L, class... U> struct mp_set_push_back_impl<L<U...>>
{
using type = L<U...>;
};
template<template<class...> class L, class... U, class T1, class... T> struct mp_set_push_back_impl<L<U...>, T1, T...>
{
using S = mp_if<mp_set_contains<L<U...>, T1>, L<U...>, L<U..., T1>>;
using type = typename mp_set_push_back_impl<S, T...>::type;
};
} // namespace detail
template<class S, class... T> using mp_set_push_back = typename detail::mp_set_push_back_impl<S, T...>::type;
// mp_unique<L>
namespace detail
{
template<class L> struct mp_unique_impl;
template<template<class...> class L, class... T> struct mp_unique_impl<L<T...>>
{
using type = mp_set_push_back<L<>, T...>;
};
} // namespace detail
template<class L> using mp_unique = typename detail::mp_unique_impl<L>::type;
// mp_append<L...>
namespace detail
{
template<class... L> struct mp_append_impl;
template<> struct mp_append_impl<>
{
using type = mp_list<>;
};
template<template<class...> class L, class... T> struct mp_append_impl<L<T...>>
{
using type = L<T...>;
};
template<template<class...> class L1, class... T1, template<class...> class L2, class... T2, class... Lr> struct mp_append_impl<L1<T1...>, L2<T2...>, Lr...>
{
using type = typename mp_append_impl<L1<T1..., T2...>, Lr...>::type;
};
}
template<class... L> using mp_append = typename detail::mp_append_impl<L...>::type;
// mp_front<L>
namespace detail
{
template<class L> struct mp_front_impl
{
// An error "no type named 'type'" here means that the argument to mp_front
// is either not a list, or is an empty list
};
template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
{
using type = T1;
};
} // namespace detail
template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
// mp_pop_front<L>
namespace detail
{
template<class L> struct mp_pop_front_impl
{
// An error "no type named 'type'" here means that the argument to mp_pop_front
// is either not a list, or is an empty list
};
template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
{
using type = L<T...>;
};
} // namespace detail
template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
// mp_first<L>
template<class L> using mp_first = mp_front<L>;
// mp_rest<L>
template<class L> using mp_rest = mp_pop_front<L>;
// mp_remove_if<L, P>
namespace detail
{
template<class L, template<class...> class P> struct mp_remove_if_impl;
template<template<class...> class L, class... T, template<class...> class P> struct mp_remove_if_impl<L<T...>, P>
{
template<class U> using _f = mp_if<P<U>, mp_list<>, mp_list<U>>;
using type = mp_append<L<>, _f<T>...>;
};
} // namespace detail
template<class L, template<class...> class P> using mp_remove_if = typename detail::mp_remove_if_impl<L, P>::type;
// integer_sequence
template<class T, T... I> struct integer_sequence
{
};
// detail::make_integer_sequence_impl
namespace detail
{
// iseq_if_c
template<bool C, class T, class E> struct iseq_if_c_impl;
template<class T, class E> struct iseq_if_c_impl<true, T, E>
{
using type = T;
};
template<class T, class E> struct iseq_if_c_impl<false, T, E>
{
using type = E;
};
template<bool C, class T, class E> using iseq_if_c = typename iseq_if_c_impl<C, T, E>::type;
// iseq_identity
template<class T> struct iseq_identity
{
using type = T;
};
template<class S1, class S2> struct append_integer_sequence;
template<class T, T... I, T... J> struct append_integer_sequence<integer_sequence<T, I...>, integer_sequence<T, J...>>
{
using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >;
};
template<class T, T N> struct make_integer_sequence_impl;
template<class T, T N> struct make_integer_sequence_impl_
{
private:
static_assert( N >= 0, "make_integer_sequence<T, N>: N must not be negative" );
static T const M = N / 2;
static T const R = N % 2;
using S1 = typename make_integer_sequence_impl<T, M>::type;
using S2 = typename append_integer_sequence<S1, S1>::type;
using S3 = typename make_integer_sequence_impl<T, R>::type;
using S4 = typename append_integer_sequence<S2, S3>::type;
public:
using type = S4;
};
template<class T, T N> struct make_integer_sequence_impl: iseq_if_c<N == 0, iseq_identity<integer_sequence<T>>, iseq_if_c<N == 1, iseq_identity<integer_sequence<T, 0>>, make_integer_sequence_impl_<T, N> > >
{
};
} // namespace detail
// make_integer_sequence
template<class T, T N> using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;
// index_sequence
template<std::size_t... I> using index_sequence = integer_sequence<std::size_t, I...>;
// make_index_sequence
template<std::size_t N> using make_index_sequence = make_integer_sequence<std::size_t, N>;
// index_sequence_for
template<class... T> using index_sequence_for = make_integer_sequence<std::size_t, sizeof...(T)>;
// implementation by Bruno Dutra (by the name is_evaluable)
namespace detail
{
template<template<class...> class F, class... T> struct mp_valid_impl
{
template<template<class...> class G, class = G<T...>> static mp_true check(int);
template<template<class...> class> static mp_false check(...);
using type = decltype(check<F>(0));
};
} // namespace detail
template<template<class...> class F, class... T> using mp_valid = typename detail::mp_valid_impl<F, T...>::type;
} } }
#endif

View File

@@ -0,0 +1,180 @@
#ifndef BOOST_LEAF_DETAIL_OPTIONAL_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_OPTIONAL_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEAF_ENABLE_WARNINGS
# if defined(__clang__)
# pragma clang system_header
# elif (__GNUC__*100+__GNUC_MINOR__>301)
# pragma GCC system_header
# elif defined(_MSC_VER)
# pragma warning(push,1)
# endif
#endif
#include <boost/leaf/detail/config.hpp>
#include <utility>
#include <new>
namespace boost { namespace leaf {
namespace leaf_detail
{
template <class T>
class optional
{
int key_;
union { T value_; };
public:
typedef T value_type;
BOOST_LEAF_CONSTEXPR optional() noexcept:
key_(0)
{
}
BOOST_LEAF_CONSTEXPR optional( optional const & x ):
key_(x.key_)
{
if( x.key_ )
(void) new (&value_) T( x.value_ );
}
BOOST_LEAF_CONSTEXPR optional( optional && x ) noexcept:
key_(x.key_)
{
if( x.key_ )
{
(void) new (&value_) T( std::move(x.value_) );
x.reset();
}
}
BOOST_LEAF_CONSTEXPR optional( int key, T const & v ):
key_(key),
value_(v)
{
BOOST_LEAF_ASSERT(!empty());
}
BOOST_LEAF_CONSTEXPR optional( int key, T && v ) noexcept:
key_(key),
value_(std::move(v))
{
BOOST_LEAF_ASSERT(!empty());
}
BOOST_LEAF_CONSTEXPR optional & operator=( optional const & x )
{
reset();
if( int key = x.key() )
{
put(key, x.value_);
key_ = key;
}
return *this;
}
BOOST_LEAF_CONSTEXPR optional & operator=( optional && x ) noexcept
{
reset();
if( int key = x.key() )
{
put(key, std::move(x.value_));
x.reset();
}
return *this;
}
~optional() noexcept
{
reset();
}
BOOST_LEAF_CONSTEXPR bool empty() const noexcept
{
return key_==0;
}
BOOST_LEAF_CONSTEXPR int key() const noexcept
{
return key_;
}
BOOST_LEAF_CONSTEXPR void reset() noexcept
{
if( key_ )
{
value_.~T();
key_=0;
}
}
BOOST_LEAF_CONSTEXPR T & put( int key, T const & v )
{
BOOST_LEAF_ASSERT(key);
reset();
(void) new(&value_) T(v);
key_=key;
return value_;
}
BOOST_LEAF_CONSTEXPR T & put( int key, T && v ) noexcept
{
BOOST_LEAF_ASSERT(key);
reset();
(void) new(&value_) T(std::move(v));
key_=key;
return value_;
}
BOOST_LEAF_CONSTEXPR T const * has_value(int key) const noexcept
{
BOOST_LEAF_ASSERT(key);
return key_==key ? &value_ : 0;
}
BOOST_LEAF_CONSTEXPR T * has_value(int key) noexcept
{
BOOST_LEAF_ASSERT(key);
return key_==key ? &value_ : 0;
}
BOOST_LEAF_CONSTEXPR T const & value(int key) const & noexcept
{
BOOST_LEAF_ASSERT(has_value(key) != 0);
return value_;
}
BOOST_LEAF_CONSTEXPR T & value(int key) & noexcept
{
BOOST_LEAF_ASSERT(has_value(key) != 0);
return value_;
}
BOOST_LEAF_CONSTEXPR T const && value(int key) const && noexcept
{
BOOST_LEAF_ASSERT(has_value(key) != 0);
return value_;
}
BOOST_LEAF_CONSTEXPR T value(int key) && noexcept
{
BOOST_LEAF_ASSERT(has_value(key) != 0);
T tmp(std::move(value_));
reset();
return tmp;
}
};
}
} }
#endif

View File

@@ -0,0 +1,134 @@
#ifndef BOOST_LEAF_DETAIL_PRINT_HPP_INCLUDED
#define BOOST_LEAF_DETAIL_PRINT_HPP_INCLUDED
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEAF_ENABLE_WARNINGS
# if defined(__clang__)
# pragma clang system_header
# elif (__GNUC__*100+__GNUC_MINOR__>301)
# pragma GCC system_header
# elif defined(_MSC_VER)
# pragma warning(push,1)
# endif
#endif
#include <boost/leaf/detail/optional.hpp>
#include <iosfwd>
#include <cstring>
namespace boost { namespace leaf {
namespace leaf_detail
{
template <int N>
BOOST_LEAF_CONSTEXPR inline char const * check_prefix( char const * t, char const (&prefix)[N] )
{
return std::strncmp(t,prefix,sizeof(prefix)-1)==0 ? t+sizeof(prefix)-1 : t;
}
}
template <class Name>
inline char const * type()
{
using leaf_detail::check_prefix;
char const * t =
#ifdef __FUNCSIG__
__FUNCSIG__;
#else
__PRETTY_FUNCTION__;
#endif
#if defined(__clang__)
BOOST_LEAF_ASSERT(check_prefix(t,"const char *boost::leaf::type() ")==t+32);
return t+32;
#elif defined(__GNUC__)
BOOST_LEAF_ASSERT(check_prefix(t,"const char* boost::leaf::type() ")==t+32);
return t+32;
#else
char const * clang_style = check_prefix(t,"const char *boost::leaf::type() ");
if( clang_style!=t )
return clang_style;
char const * gcc_style = check_prefix(t,"const char* boost::leaf::type() ");
if( gcc_style!=t )
return gcc_style;
#endif
return t;
}
namespace leaf_detail
{
template <class T, class E = void>
struct is_printable: std::false_type
{
};
template <class T>
struct is_printable<T, decltype(std::declval<std::ostream&>()<<std::declval<T const &>(), void())>: std::true_type
{
};
////////////////////////////////////////
template <class T, class E = void>
struct has_printable_member_value: std::false_type
{
};
template <class T>
struct has_printable_member_value<T, decltype(std::declval<std::ostream&>()<<std::declval<T const &>().value, void())>: std::true_type
{
};
////////////////////////////////////////
template <class Wrapper, bool WrapperPrintable=is_printable<Wrapper>::value, bool ValuePrintable=has_printable_member_value<Wrapper>::value>
struct diagnostic;
template <class Wrapper, bool ValuePrintable>
struct diagnostic<Wrapper, true, ValuePrintable>
{
static constexpr bool is_invisible = false;
static void print( std::ostream & os, Wrapper const & x )
{
os << x;
}
};
template <class Wrapper>
struct diagnostic<Wrapper, false, true>
{
static constexpr bool is_invisible = false;
static void print( std::ostream & os, Wrapper const & x )
{
os << type<Wrapper>() << ": " << x.value;
}
};
template <class Wrapper>
struct diagnostic<Wrapper, false, false>
{
static constexpr bool is_invisible = false;
static void print( std::ostream & os, Wrapper const & )
{
os << type<Wrapper>() << ": {Non-Printable}";
}
};
#ifndef BOOST_LEAF_NO_EXCEPTIONS
template <>
struct diagnostic<std::exception_ptr, false, false>
{
static constexpr bool is_invisible = true;
BOOST_LEAF_CONSTEXPR static void print( std::ostream &, std::exception_ptr const & )
{
}
};
#endif
}
} }
#endif