mirror of
https://git.suyu.dev/suyu/ext-boost.git
synced 2025-12-24 08:14:46 +01:00
externals: Update boost to 1.72 and add Boost Context
This commit is contained in:
parent
5e8300b76a
commit
77abe07b3b
618 changed files with 96299 additions and 14263 deletions
245
boost/core/alloc_construct.hpp
Normal file
245
boost/core/alloc_construct.hpp
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_ALLOC_CONSTRUCT_HPP
|
||||
#define BOOST_CORE_ALLOC_CONSTRUCT_HPP
|
||||
|
||||
#include <boost/core/noinit_adaptor.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy(A& a, T* p)
|
||||
{
|
||||
std::allocator_traits<A>::destroy(a, p);
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
while (n > 0) {
|
||||
std::allocator_traits<A>::destroy(a, p + --n);
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy(A&, T* p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy_n(A&, T* p, std::size_t n)
|
||||
{
|
||||
while (n > 0) {
|
||||
p[--n].~T();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<class A, class T>
|
||||
class alloc_destroyer {
|
||||
public:
|
||||
alloc_destroyer(A& a, T* p) BOOST_NOEXCEPT
|
||||
: a_(a),
|
||||
p_(p),
|
||||
n_(0) { }
|
||||
|
||||
~alloc_destroyer() {
|
||||
boost::alloc_destroy_n(a_, p_, n_);
|
||||
}
|
||||
|
||||
std::size_t& size() BOOST_NOEXCEPT {
|
||||
return n_;
|
||||
}
|
||||
|
||||
private:
|
||||
alloc_destroyer(const alloc_destroyer&);
|
||||
alloc_destroyer& operator=(const alloc_destroyer&);
|
||||
|
||||
A& a_;
|
||||
T* p_;
|
||||
std::size_t n_;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class A, class T, class U, class... V>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p, U&& u, V&&... v)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p, std::forward<U>(u),
|
||||
std::forward<V>(v)...);
|
||||
}
|
||||
#else
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p, U&& u)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p, std::forward<U>(u));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p, const U& u)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p, u);
|
||||
}
|
||||
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p, U& u)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p, u);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
std::allocator_traits<A>::construct(a, p + i);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
std::allocator_traits<A>::construct(a, p + i, l[i % m]);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T, class I>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, I b)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; void(++i), void(++b)) {
|
||||
std::allocator_traits<A>::construct(a, p + i, *b);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
#else
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct(A&, T* p)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T();
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct(noinit_adaptor<A>&, T* p)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class A, class T, class U, class... V>
|
||||
inline void
|
||||
alloc_construct(A&, T* p, U&& u, V&&... v)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T(std::forward<U>(u), std::forward<V>(v)...);
|
||||
}
|
||||
#else
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p, U&& u)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T(std::forward<U>(u));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A&, T* p, const U& u)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T(u);
|
||||
}
|
||||
|
||||
template<class A, class T, class U>
|
||||
inline void
|
||||
alloc_construct(A&, T* p, U& u)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T(u);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
::new(static_cast<void*>(p + i)) T();
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(noinit_adaptor<A>& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<noinit_adaptor<A>, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
::new(static_cast<void*>(p + i)) T;
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
::new(static_cast<void*>(p + i)) T(l[i % m]);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T, class I>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, I b)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; void(++i), void(++b)) {
|
||||
::new(static_cast<void*>(p + i)) T(*b);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
158
boost/core/default_allocator.hpp
Normal file
158
boost/core/default_allocator.hpp
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_DEFAULT_ALLOCATOR_HPP
|
||||
#define BOOST_CORE_DEFAULT_ALLOCATOR_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <new>
|
||||
#include <climits>
|
||||
|
||||
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000
|
||||
#define BOOST_CORE_NO_CXX11_ALLOCATOR
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
#if defined(BOOST_NO_EXCEPTIONS)
|
||||
BOOST_NORETURN void throw_exception(const std::exception&);
|
||||
#endif
|
||||
|
||||
namespace default_ {
|
||||
|
||||
struct true_type {
|
||||
typedef bool value_type;
|
||||
typedef true_type type;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
|
||||
BOOST_CONSTEXPR operator bool() const BOOST_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR bool operator()() const BOOST_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct add_reference {
|
||||
typedef T& type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_reference<void> {
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct add_reference<const void> {
|
||||
typedef const void type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct default_allocator {
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef typename add_reference<T>::type reference;
|
||||
typedef typename add_reference<const T>::type const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef true_type propagate_on_container_move_assignment;
|
||||
typedef true_type is_always_equal;
|
||||
|
||||
template<class U>
|
||||
struct rebind {
|
||||
typedef default_allocator<U> other;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
|
||||
default_allocator() = default;
|
||||
#else
|
||||
BOOST_CONSTEXPR default_allocator() BOOST_NOEXCEPT { }
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
BOOST_CONSTEXPR default_allocator(const default_allocator<U>&)
|
||||
BOOST_NOEXCEPT { }
|
||||
|
||||
#if defined(PTRDIFF_MAX) && defined(SIZE_MAX)
|
||||
BOOST_CONSTEXPR std::size_t max_size() const BOOST_NOEXCEPT {
|
||||
return PTRDIFF_MAX < SIZE_MAX / sizeof(T)
|
||||
? PTRDIFF_MAX : SIZE_MAX / sizeof(T);
|
||||
}
|
||||
#else
|
||||
BOOST_CONSTEXPR std::size_t max_size() const BOOST_NOEXCEPT {
|
||||
return ~static_cast<std::size_t>(0) / sizeof(T);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > max_size()) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return static_cast<T*>(::operator new(sizeof(T) * n));
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t) {
|
||||
::operator delete(p);
|
||||
}
|
||||
#else
|
||||
T* allocate(std::size_t n) {
|
||||
if (n > max_size()) {
|
||||
boost::throw_exception(std::bad_alloc());
|
||||
}
|
||||
void* p = ::operator new(sizeof(T) * n, std::nothrow);
|
||||
if (!p) {
|
||||
boost::throw_exception(std::bad_alloc());
|
||||
}
|
||||
return static_cast<T*>(p);
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t) {
|
||||
::operator delete(p, std::nothrow);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR) || defined(BOOST_CORE_NO_CXX11_ALLOCATOR)
|
||||
template<class U, class V>
|
||||
void construct(U* p, const V& v) {
|
||||
::new(p) U(v);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void destroy(U* p) {
|
||||
p->~U();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
BOOST_CONSTEXPR inline bool
|
||||
operator==(const default_allocator<T>&,
|
||||
const default_allocator<U>&) BOOST_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
BOOST_CONSTEXPR inline bool
|
||||
operator!=(const default_allocator<T>&,
|
||||
const default_allocator<U>&) BOOST_NOEXCEPT
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} /* default_ */
|
||||
|
||||
using default_::default_allocator;
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
45
boost/core/first_scalar.hpp
Normal file
45
boost/core/first_scalar.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_FIRST_SCALAR_HPP
|
||||
#define BOOST_CORE_FIRST_SCALAR_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct make_scalar {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
struct make_scalar<T[N]> {
|
||||
typedef typename make_scalar<T>::type type;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class T>
|
||||
BOOST_CONSTEXPR inline T*
|
||||
first_scalar(T* p) BOOST_NOEXCEPT
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
BOOST_CONSTEXPR inline typename detail::make_scalar<T>::type*
|
||||
first_scalar(T (*p)[N]) BOOST_NOEXCEPT
|
||||
{
|
||||
return boost::first_scalar(&(*p)[0]);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
70
boost/core/ignore_unused.hpp
Normal file
70
boost/core/ignore_unused.hpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
//
|
||||
// Use, modification and distribution is subject to 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_CORE_IGNORE_UNUSED_HPP
|
||||
#define BOOST_CORE_IGNORE_UNUSED_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
|
||||
template <typename... Ts>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(Ts const& ...)
|
||||
{}
|
||||
|
||||
template <typename... Ts>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
#else
|
||||
|
||||
template <typename T1>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const&)
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const&, T2 const&)
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const&, T2 const&, T3 const&)
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const&, T2 const&, T3 const&, T4 const&)
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const&, T2 const&, T3 const&, T4 const&, T5 const&)
|
||||
{}
|
||||
|
||||
template <typename T1>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
|
||||
{}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_CORE_IGNORE_UNUSED_HPP
|
||||
112
boost/core/noinit_adaptor.hpp
Normal file
112
boost/core/noinit_adaptor.hpp
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_NOINIT_ADAPTOR_HPP
|
||||
#define BOOST_CORE_NOINIT_ADAPTOR_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#endif
|
||||
#include <new>
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class A>
|
||||
struct noinit_adaptor
|
||||
: A {
|
||||
template<class U>
|
||||
struct rebind {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
typedef noinit_adaptor<typename std::allocator_traits<A>::template
|
||||
rebind_alloc<U> > other;
|
||||
#else
|
||||
typedef noinit_adaptor<typename A::template rebind<U>::other> other;
|
||||
#endif
|
||||
};
|
||||
|
||||
noinit_adaptor()
|
||||
: A() { }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
template<class U>
|
||||
noinit_adaptor(U&& u) BOOST_NOEXCEPT
|
||||
: A(std::forward<U>(u)) { }
|
||||
#else
|
||||
template<class U>
|
||||
noinit_adaptor(const U& u) BOOST_NOEXCEPT
|
||||
: A(u) { }
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT
|
||||
: A(static_cast<const U&>(u)) { }
|
||||
|
||||
template<class U>
|
||||
void construct(U* p) {
|
||||
::new((void*)p) U;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class U, class V, class... Args>
|
||||
void construct(U* p, V&& v, Args&&... args) {
|
||||
::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
template<class U, class V>
|
||||
void construct(U* p, V&& v) {
|
||||
::new((void*)p) U(std::forward<V>(v));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
template<class U, class V>
|
||||
void construct(U* p, const V& v) {
|
||||
::new((void*)p) U(v);
|
||||
}
|
||||
|
||||
template<class U, class V>
|
||||
void construct(U* p, V& v) {
|
||||
::new((void*)p) U(v);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class U>
|
||||
void destroy(U* p) {
|
||||
p->~U();
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator==(const noinit_adaptor<T>& lhs,
|
||||
const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<const T&>(lhs) == static_cast<const U&>(rhs);
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
inline bool
|
||||
operator!=(const noinit_adaptor<T>& lhs,
|
||||
const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
inline noinit_adaptor<A>
|
||||
noinit_adapt(const A& a) BOOST_NOEXCEPT
|
||||
{
|
||||
return noinit_adaptor<A>(a);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
194
boost/core/scoped_enum.hpp
Normal file
194
boost/core/scoped_enum.hpp
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
// scoped_enum.hpp ---------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes, 2009
|
||||
// Copyright (C) 2011-2012 Vicente J. Botet Escriba
|
||||
// Copyright (C) 2012 Anthony Williams
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_CORE_SCOPED_ENUM_HPP
|
||||
#define BOOST_CORE_SCOPED_ENUM_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#ifdef BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
/**
|
||||
* Meta-function to get the native enum type associated to an enum class or its emulation.
|
||||
*/
|
||||
template <typename EnumType>
|
||||
struct native_type
|
||||
{
|
||||
/**
|
||||
* The member typedef type names the native enum type associated to the scoped enum,
|
||||
* which is it self if the compiler supports scoped enums or EnumType::enum_type if it is an emulated scoped enum.
|
||||
*/
|
||||
typedef typename EnumType::enum_type type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Casts a scoped enum to its underlying type.
|
||||
*
|
||||
* This function is useful when working with scoped enum classes, which doens't implicitly convert to the underlying type.
|
||||
* @param v A scoped enum.
|
||||
* @returns The underlying type.
|
||||
* @throws No-throws.
|
||||
*/
|
||||
template <typename UnderlyingType, typename EnumType>
|
||||
inline
|
||||
BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
|
||||
{
|
||||
return v.get_underlying_value_();
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a scoped enum to its native enum type.
|
||||
*
|
||||
* This function is useful to make programs portable when the scoped enum emulation can not be use where native enums can.
|
||||
*
|
||||
* EnumType the scoped enum type
|
||||
*
|
||||
* @param v A scoped enum.
|
||||
* @returns The native enum value.
|
||||
* @throws No-throws.
|
||||
*/
|
||||
template <typename EnumType>
|
||||
inline
|
||||
BOOST_CONSTEXPR typename EnumType::enum_type native_value(EnumType e) BOOST_NOEXCEPT
|
||||
{
|
||||
return e.get_native_value_();
|
||||
}
|
||||
|
||||
#else // BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
template <typename EnumType>
|
||||
struct native_type
|
||||
{
|
||||
typedef EnumType type;
|
||||
};
|
||||
|
||||
template <typename UnderlyingType, typename EnumType>
|
||||
inline
|
||||
BOOST_CONSTEXPR UnderlyingType underlying_cast(EnumType v) BOOST_NOEXCEPT
|
||||
{
|
||||
return static_cast<UnderlyingType>(v);
|
||||
}
|
||||
|
||||
template <typename EnumType>
|
||||
inline
|
||||
BOOST_CONSTEXPR EnumType native_value(EnumType e) BOOST_NOEXCEPT
|
||||
{
|
||||
return e;
|
||||
}
|
||||
|
||||
#endif // BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
}
|
||||
|
||||
|
||||
#ifdef BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||
explicit BOOST_CONSTEXPR operator underlying_type() const BOOST_NOEXCEPT { return get_underlying_value_(); }
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start a declaration of a scoped enum.
|
||||
*
|
||||
* @param EnumType The new scoped enum.
|
||||
* @param UnderlyingType The underlying type.
|
||||
*/
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType, UnderlyingType) \
|
||||
struct EnumType { \
|
||||
typedef void is_boost_scoped_enum_tag; \
|
||||
typedef UnderlyingType underlying_type; \
|
||||
EnumType() BOOST_NOEXCEPT {} \
|
||||
explicit BOOST_CONSTEXPR EnumType(underlying_type v) BOOST_NOEXCEPT : v_(v) {} \
|
||||
BOOST_CONSTEXPR underlying_type get_underlying_value_() const BOOST_NOEXCEPT { return v_; } \
|
||||
BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||
private: \
|
||||
underlying_type v_; \
|
||||
typedef EnumType self_type; \
|
||||
public: \
|
||||
enum enum_type
|
||||
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END2() \
|
||||
BOOST_CONSTEXPR enum_type get_native_value_() const BOOST_NOEXCEPT { return enum_type(v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator ==(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator ==(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)==rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator ==(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs==enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator !=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator !=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)!=rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator !=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs!=enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator <(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator <(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator <(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator <=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator <=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)<=rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator <=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs<=enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator >(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator >(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator >(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator >=(self_type lhs, self_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=enum_type(rhs.v_); } \
|
||||
friend BOOST_CONSTEXPR bool operator >=(self_type lhs, enum_type rhs) BOOST_NOEXCEPT { return enum_type(lhs.v_)>=rhs; } \
|
||||
friend BOOST_CONSTEXPR bool operator >=(enum_type lhs, self_type rhs) BOOST_NOEXCEPT { return lhs>=enum_type(rhs.v_); } \
|
||||
};
|
||||
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) \
|
||||
; \
|
||||
BOOST_CONSTEXPR EnumType(enum_type v) BOOST_NOEXCEPT : v_(v) {} \
|
||||
BOOST_SCOPED_ENUM_DECLARE_END2()
|
||||
|
||||
/**
|
||||
* Starts a declaration of a scoped enum with the default int underlying type.
|
||||
*
|
||||
* @param EnumType The new scoped enum.
|
||||
*/
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(EnumType) \
|
||||
BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType,int)
|
||||
|
||||
/**
|
||||
* Name of the native enum type.
|
||||
*
|
||||
* @param EnumType The new scoped enum.
|
||||
*/
|
||||
#define BOOST_SCOPED_ENUM_NATIVE(EnumType) EnumType::enum_type
|
||||
/**
|
||||
* Forward declares an scoped enum.
|
||||
*
|
||||
* @param EnumType The scoped enum.
|
||||
*/
|
||||
#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(EnumType) struct EnumType
|
||||
|
||||
#else // BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(EnumType,UnderlyingType) enum class EnumType : UnderlyingType
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(EnumType) enum class EnumType
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END2()
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END(EnumType) ;
|
||||
|
||||
#define BOOST_SCOPED_ENUM_NATIVE(EnumType) EnumType
|
||||
#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(EnumType) enum class EnumType
|
||||
|
||||
#endif // BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
// Deprecated macros
|
||||
#define BOOST_SCOPED_ENUM_START(name) BOOST_SCOPED_ENUM_DECLARE_BEGIN(name)
|
||||
#define BOOST_SCOPED_ENUM_END BOOST_SCOPED_ENUM_DECLARE_END2()
|
||||
#define BOOST_SCOPED_ENUM(name) BOOST_SCOPED_ENUM_NATIVE(name)
|
||||
|
||||
#endif // BOOST_CORE_SCOPED_ENUM_HPP
|
||||
Loading…
Add table
Add a link
Reference in a new issue