Remove dependency on Boost.TypeTraits

This commit is contained in:
Peter Dimov
2024-05-11 21:26:24 +03:00
parent 28b88d07bb
commit 38a2ab7646
2 changed files with 52 additions and 65 deletions

View File

@ -15,17 +15,6 @@
#include <boost/function_equal.hpp> #include <boost/function_equal.hpp>
#include <boost/core/typeinfo.hpp> #include <boost/core/typeinfo.hpp>
#include <boost/core/ref.hpp> #include <boost/core/ref.hpp>
#include <boost/type_traits/has_trivial_copy.hpp>
#include <boost/type_traits/has_trivial_destructor.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/composite_traits.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/config/workaround.hpp> #include <boost/config/workaround.hpp>
@ -33,6 +22,7 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include <new> #include <new>
#include <type_traits>
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
# pragma warning( push ) # pragma warning( push )
@ -43,10 +33,8 @@
// retained because used in a test // retained because used in a test
#define BOOST_FUNCTION_TARGET_FIX(x) #define BOOST_FUNCTION_TARGET_FIX(x)
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \ #define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
typename ::boost::enable_if_< \ typename std::enable_if< !std::is_integral<Functor>::value, Type>::type
!(::boost::is_integral<Functor>::value), \
Type>::type
namespace boost { namespace boost {
namespace detail { namespace detail {
@ -131,15 +119,15 @@ namespace boost {
template<typename F> template<typename F>
class get_function_tag class get_function_tag
{ {
typedef typename conditional<(is_pointer<F>::value), typedef typename std::conditional<std::is_pointer<F>::value,
function_ptr_tag, function_ptr_tag,
function_obj_tag>::type ptr_or_obj_tag; function_obj_tag>::type ptr_or_obj_tag;
typedef typename conditional<(is_member_pointer<F>::value), typedef typename std::conditional<std::is_member_pointer<F>::value,
member_ptr_tag, member_ptr_tag,
ptr_or_obj_tag>::type ptr_or_obj_or_mem_tag; ptr_or_obj_tag>::type ptr_or_obj_or_mem_tag;
typedef typename conditional<(is_reference_wrapper<F>::value), typedef typename std::conditional<is_reference_wrapper<F>::value,
function_obj_ref_tag, function_obj_ref_tag,
ptr_or_obj_or_mem_tag>::type or_ref_tag; ptr_or_obj_or_mem_tag>::type or_ref_tag;
@ -204,8 +192,8 @@ namespace boost {
BOOST_STATIC_CONSTANT BOOST_STATIC_CONSTANT
(bool, (bool,
value = ((sizeof(F) <= sizeof(function_buffer) && value = ((sizeof(F) <= sizeof(function_buffer) &&
(alignment_of<function_buffer>::value (std::alignment_of<function_buffer>::value
% alignment_of<F>::value == 0)))); % std::alignment_of<F>::value == 0))));
}; };
template <typename F,typename A> template <typename F,typename A>
@ -306,7 +294,7 @@ namespace boost {
// Function objects that fit in the small-object buffer. // Function objects that fit in the small-object buffer.
static inline void static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer, manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, true_type) functor_manager_operation_type op, std::true_type)
{ {
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op); functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
} }
@ -314,7 +302,7 @@ namespace boost {
// Function objects that require heap allocation // Function objects that require heap allocation
static inline void static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer, manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, false_type) functor_manager_operation_type op, std::false_type)
{ {
if (op == clone_functor_tag) { if (op == clone_functor_tag) {
// Clone the functor // Clone the functor
@ -355,7 +343,7 @@ namespace boost {
functor_manager_operation_type op, function_obj_tag) functor_manager_operation_type op, function_obj_tag)
{ {
manager(in_buffer, out_buffer, op, manager(in_buffer, out_buffer, op,
integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>()); std::integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
} }
// For member pointers, we use the small-object optimization buffer. // For member pointers, we use the small-object optimization buffer.
@ -363,7 +351,7 @@ namespace boost {
manager(const function_buffer& in_buffer, function_buffer& out_buffer, manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, member_ptr_tag) functor_manager_operation_type op, member_ptr_tag)
{ {
manager(in_buffer, out_buffer, op, true_type()); manager(in_buffer, out_buffer, op, std::true_type());
} }
public: public:
@ -401,7 +389,7 @@ namespace boost {
// Function objects that fit in the small-object buffer. // Function objects that fit in the small-object buffer.
static inline void static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer, manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, true_type) functor_manager_operation_type op, std::true_type)
{ {
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op); functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
} }
@ -409,7 +397,7 @@ namespace boost {
// Function objects that require heap allocation // Function objects that require heap allocation
static inline void static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer, manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, false_type) functor_manager_operation_type op, std::false_type)
{ {
typedef functor_wrapper<Functor,Allocator> functor_wrapper_type; typedef functor_wrapper<Functor,Allocator> functor_wrapper_type;
@ -460,7 +448,7 @@ namespace boost {
functor_manager_operation_type op, function_obj_tag) functor_manager_operation_type op, function_obj_tag)
{ {
manager(in_buffer, out_buffer, op, manager(in_buffer, out_buffer, op,
integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>()); std::integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
} }
public: public:
@ -529,8 +517,8 @@ public:
detail::function::function_buffer type_result; detail::function::function_buffer type_result;
type_result.members.type.type = &BOOST_CORE_TYPEID(Functor); type_result.members.type.type = &BOOST_CORE_TYPEID(Functor);
type_result.members.type.const_qualified = is_const<Functor>::value; type_result.members.type.const_qualified = std::is_const<Functor>::value;
type_result.members.type.volatile_qualified = is_volatile<Functor>::value; type_result.members.type.volatile_qualified = std::is_volatile<Functor>::value;
get_vtable()->manager(functor, type_result, get_vtable()->manager(functor, type_result,
detail::function::check_functor_type_tag); detail::function::check_functor_type_tag);
return static_cast<Functor*>(type_result.members.obj_ptr); return static_cast<Functor*>(type_result.members.obj_ptr);
@ -544,7 +532,7 @@ public:
detail::function::function_buffer type_result; detail::function::function_buffer type_result;
type_result.members.type.type = &BOOST_CORE_TYPEID(Functor); type_result.members.type.type = &BOOST_CORE_TYPEID(Functor);
type_result.members.type.const_qualified = true; type_result.members.type.const_qualified = true;
type_result.members.type.volatile_qualified = is_volatile<Functor>::value; type_result.members.type.volatile_qualified = std::is_volatile<Functor>::value;
get_vtable()->manager(functor, type_result, get_vtable()->manager(functor, type_result,
detail::function::check_functor_type_tag); detail::function::check_functor_type_tag);
// GCC 2.95.3 gets the CV qualifiers wrong here, so we // GCC 2.95.3 gets the CV qualifiers wrong here, so we
@ -553,8 +541,8 @@ public:
} }
template<typename F> template<typename F>
typename boost::enable_if_< !boost::is_function<F>::value, bool >::type typename std::enable_if< !std::is_function<F>::value, bool >::type
contains(const F& f) const contains(const F& f) const
{ {
if (const F* fp = this->template target<F>()) if (const F* fp = this->template target<F>())
{ {
@ -565,8 +553,8 @@ public:
} }
template<typename Fn> template<typename Fn>
typename boost::enable_if_< boost::is_function<Fn>::value, bool >::type typename std::enable_if< std::is_function<Fn>::value, bool >::type
contains(Fn& f) const contains(Fn& f) const
{ {
typedef Fn* F; typedef Fn* F;
if (const F* fp = this->template target<F>()) if (const F* fp = this->template target<F>())

View File

@ -15,11 +15,10 @@
#include <boost/core/no_exceptions_support.hpp> #include <boost/core/no_exceptions_support.hpp>
#include <boost/mem_fn.hpp> #include <boost/mem_fn.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <type_traits>
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
# pragma warning( push ) # pragma warning( push )
@ -180,7 +179,7 @@ namespace boost {
> >
struct get_function_invoker struct get_function_invoker
{ {
typedef typename conditional<(is_void<R>::value), typedef typename std::conditional<std::is_void<R>::value,
void_function_invoker< void_function_invoker<
FunctionPtr, FunctionPtr,
R, R,
@ -201,7 +200,7 @@ namespace boost {
> >
struct get_function_obj_invoker struct get_function_obj_invoker
{ {
typedef typename conditional<(is_void<R>::value), typedef typename std::conditional<std::is_void<R>::value,
void_function_obj_invoker< void_function_obj_invoker<
FunctionObj, FunctionObj,
R, R,
@ -222,7 +221,7 @@ namespace boost {
> >
struct get_function_ref_invoker struct get_function_ref_invoker
{ {
typedef typename conditional<(is_void<R>::value), typedef typename std::conditional<std::is_void<R>::value,
void_function_ref_invoker< void_function_ref_invoker<
FunctionObj, FunctionObj,
R, R,
@ -244,7 +243,7 @@ namespace boost {
> >
struct get_member_invoker struct get_member_invoker
{ {
typedef typename conditional<(is_void<R>::value), typedef typename std::conditional<std::is_void<R>::value,
void_member_invoker< void_member_invoker<
MemberPtr, MemberPtr,
R, R,
@ -499,27 +498,27 @@ namespace boost {
// Assign to a function object using the small object optimization // Assign to a function object using the small object optimization
template<typename FunctionObj> template<typename FunctionObj>
void void
assign_functor(FunctionObj f, function_buffer& functor, true_type) const assign_functor(FunctionObj f, function_buffer& functor, std::true_type) const
{ {
new (reinterpret_cast<void*>(functor.data)) FunctionObj(std::move(f)); new (reinterpret_cast<void*>(functor.data)) FunctionObj(std::move(f));
} }
template<typename FunctionObj,typename Allocator> template<typename FunctionObj,typename Allocator>
void void
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, true_type) const assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, std::true_type) const
{ {
assign_functor(std::move(f),functor,true_type()); assign_functor(std::move(f),functor,std::true_type());
} }
// Assign to a function object allocated on the heap. // Assign to a function object allocated on the heap.
template<typename FunctionObj> template<typename FunctionObj>
void void
assign_functor(FunctionObj f, function_buffer& functor, false_type) const assign_functor(FunctionObj f, function_buffer& functor, std::false_type) const
{ {
functor.members.obj_ptr = new FunctionObj(std::move(f)); functor.members.obj_ptr = new FunctionObj(std::move(f));
} }
template<typename FunctionObj,typename Allocator> template<typename FunctionObj,typename Allocator>
void void
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, false_type) const assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, std::false_type) const
{ {
typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type; typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
@ -540,7 +539,7 @@ namespace boost {
{ {
if (!boost::detail::function::has_empty_target(boost::addressof(f))) { if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
assign_functor(std::move(f), functor, assign_functor(std::move(f), functor,
integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>()); std::integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
return true; return true;
} else { } else {
return false; return false;
@ -552,7 +551,7 @@ namespace boost {
{ {
if (!boost::detail::function::has_empty_target(boost::addressof(f))) { if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
assign_functor_a(std::move(f), functor, a, assign_functor_a(std::move(f), functor, a,
integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>()); std::integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
return true; return true;
} else { } else {
return false; return false;
@ -566,8 +565,8 @@ namespace boost {
function_buffer& functor, function_obj_ref_tag) const function_buffer& functor, function_obj_ref_tag) const
{ {
functor.members.obj_ref.obj_ptr = (void *)(f.get_pointer()); functor.members.obj_ref.obj_ptr = (void *)(f.get_pointer());
functor.members.obj_ref.is_const_qualified = is_const<FunctionObj>::value; functor.members.obj_ref.is_const_qualified = std::is_const<FunctionObj>::value;
functor.members.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value; functor.members.obj_ref.is_volatile_qualified = std::is_volatile<FunctionObj>::value;
return true; return true;
} }
template<typename FunctionObj,typename Allocator> template<typename FunctionObj,typename Allocator>
@ -643,8 +642,8 @@ namespace boost {
// one with a default parameter. // one with a default parameter.
template<typename Functor> template<typename Functor>
function_n(Functor f function_n(Functor f
,typename boost::enable_if_< ,typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
int>::type = 0 int>::type = 0
) : ) :
function_base() function_base()
@ -653,8 +652,8 @@ namespace boost {
} }
template<typename Functor,typename Allocator> template<typename Functor,typename Allocator>
function_n(Functor f, Allocator a function_n(Functor f, Allocator a
,typename boost::enable_if_< ,typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
int>::type = 0 int>::type = 0
) : ) :
function_base() function_base()
@ -691,8 +690,8 @@ namespace boost {
// handle function_n as the type of the temporary to // handle function_n as the type of the temporary to
// construct. // construct.
template<typename Functor> template<typename Functor>
typename boost::enable_if_< typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
function_n&>::type function_n&>::type
operator=(Functor f) operator=(Functor f)
{ {
@ -835,8 +834,8 @@ namespace boost {
if (stored_vtable.assign_to(std::move(f), functor)) { if (stored_vtable.assign_to(std::move(f), functor)) {
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base); std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
// coverity[pointless_expression]: suppress coverity warnings on apparant if(const). // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
if (boost::has_trivial_copy_constructor<Functor>::value && if (std::is_trivially_copy_constructible<Functor>::value &&
boost::has_trivial_destructor<Functor>::value && std::is_trivially_destructible<Functor>::value &&
boost::detail::function::function_allows_small_object_optimization<Functor>::value) boost::detail::function::function_allows_small_object_optimization<Functor>::value)
value |= static_cast<std::size_t>(0x01); value |= static_cast<std::size_t>(0x01);
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value); vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
@ -869,8 +868,8 @@ namespace boost {
if (stored_vtable.assign_to_a(std::move(f), functor, a)) { if (stored_vtable.assign_to_a(std::move(f), functor, a)) {
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base); std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
// coverity[pointless_expression]: suppress coverity warnings on apparant if(const). // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
if (boost::has_trivial_copy_constructor<Functor>::value && if (std::is_trivially_copy_constructible<Functor>::value &&
boost::has_trivial_destructor<Functor>::value && std::is_trivially_destructible<Functor>::value &&
boost::detail::function::function_allows_small_object_optimization<Functor>::value) boost::detail::function::function_allows_small_object_optimization<Functor>::value)
value |= static_cast<std::size_t>(0x01); value |= static_cast<std::size_t>(0x01);
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value); vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
@ -974,8 +973,8 @@ public:
template<typename Functor> template<typename Functor>
function(Functor f function(Functor f
,typename boost::enable_if_< ,typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
int>::type = 0 int>::type = 0
) : ) :
base_type(std::move(f)) base_type(std::move(f))
@ -983,8 +982,8 @@ public:
} }
template<typename Functor,typename Allocator> template<typename Functor,typename Allocator>
function(Functor f, Allocator a function(Functor f, Allocator a
,typename boost::enable_if_< ,typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
int>::type = 0 int>::type = 0
) : ) :
base_type(std::move(f),a) base_type(std::move(f),a)
@ -1014,8 +1013,8 @@ public:
} }
template<typename Functor> template<typename Functor>
typename boost::enable_if_< typename std::enable_if<
!(is_integral<Functor>::value), !std::is_integral<Functor>::value,
self_type&>::type self_type&>::type
operator=(Functor f) operator=(Functor f)
{ {