Remove dependency on Mp11 (fixes msvc-12.0 as a side effect)

This commit is contained in:
Peter Dimov
2024-01-06 01:29:50 +02:00
parent b523bc3042
commit ea7f38833f
3 changed files with 189 additions and 19 deletions

View File

@@ -20,17 +20,16 @@
// See http://www.boost.org/libs/bind for documentation. // See http://www.boost.org/libs/bind for documentation.
// //
#include <boost/bind/detail/result_traits.hpp>
#include <boost/bind/mem_fn.hpp> #include <boost/bind/mem_fn.hpp>
#include <boost/bind/arg.hpp> #include <boost/bind/arg.hpp>
#include <boost/bind/std_placeholders.hpp> #include <boost/bind/std_placeholders.hpp>
#include <boost/bind/detail/result_traits.hpp>
#include <boost/bind/detail/tuple_for_each.hpp>
#include <boost/bind/detail/integer_sequence.hpp>
#include <boost/visit_each.hpp> #include <boost/visit_each.hpp>
#include <boost/is_placeholder.hpp> #include <boost/is_placeholder.hpp>
#include <boost/type.hpp> #include <boost/type.hpp>
#include <boost/core/ref.hpp> #include <boost/core/ref.hpp>
#include <boost/mp11/integer_sequence.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/tuple.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/config/workaround.hpp> #include <boost/config/workaround.hpp>
#include <utility> #include <utility>
@@ -147,18 +146,15 @@ template<class V> struct accept_lambda
} }
}; };
template<class Tp> struct equal_lambda struct equal_lambda
{ {
Tp const& tp1_;
Tp const& tp2_;
bool result; bool result;
explicit equal_lambda( Tp const& tp1, Tp const& tp2 ): tp1_( tp1 ), tp2_( tp2 ), result( true ) {} equal_lambda(): result( true ) {}
template<class I> void operator()( I ) template<class A1, class A2> void operator()( A1& a1, A2& a2 )
{ {
result = result && ref_compare( std::get<I::value>( tp1_ ), std::get<I::value>( tp2_ ) ); result = result && ref_compare( a1, a2 );
} }
}; };
@@ -176,22 +172,22 @@ public:
list( A... a ): data_( a... ) {} list( A... a ): data_( a... ) {}
template<class R, class F, class A2, std::size_t... I> R call_impl( type<R>, F & f, A2 & a2, mp11::index_sequence<I...> ) template<class R, class F, class A2, std::size_t... I> R call_impl( type<R>, F & f, A2 & a2, _bi::index_sequence<I...> )
{ {
return unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... ); return unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... );
} }
template<class R, class F, class A2, std::size_t... I> R call_impl( type<R>, F & f, A2 & a2, mp11::index_sequence<I...> ) const template<class R, class F, class A2, std::size_t... I> R call_impl( type<R>, F & f, A2 & a2, _bi::index_sequence<I...> ) const
{ {
return unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... ); return unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... );
} }
template<class F, class A2, std::size_t... I> void call_impl( type<void>, F & f, A2 & a2, mp11::index_sequence<I...> ) template<class F, class A2, std::size_t... I> void call_impl( type<void>, F & f, A2 & a2, _bi::index_sequence<I...> )
{ {
unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... ); unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... );
} }
template<class F, class A2, std::size_t... I> void call_impl( type<void>, F & f, A2 & a2, mp11::index_sequence<I...> ) const template<class F, class A2, std::size_t... I> void call_impl( type<void>, F & f, A2 & a2, _bi::index_sequence<I...> ) const
{ {
unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... ); unwrapper<F>::unwrap( f, 0 )( a2[ std::get<I>( data_ ) ]... );
} }
@@ -200,12 +196,12 @@ public:
template<class R, class F, class A2> R operator()( type<R>, F & f, A2 & a2 ) template<class R, class F, class A2> R operator()( type<R>, F & f, A2 & a2 )
{ {
return call_impl( type<R>(), f, a2, mp11::index_sequence_for<A...>() ); return call_impl( type<R>(), f, a2, _bi::index_sequence_for<A...>() );
} }
template<class R, class F, class A2> R operator()( type<R>, F & f, A2 & a2 ) const template<class R, class F, class A2> R operator()( type<R>, F & f, A2 & a2 ) const
{ {
return call_impl( type<R>(), f, a2, mp11::index_sequence_for<A...>() ); return call_impl( type<R>(), f, a2, _bi::index_sequence_for<A...>() );
} }
// //
@@ -238,12 +234,12 @@ public:
template<class V> void accept( V & v ) const template<class V> void accept( V & v ) const
{ {
mp11::tuple_for_each( data_, accept_lambda<V>( v ) ); _bi::tuple_for_each( accept_lambda<V>( v ), data_ );
} }
bool operator==( list const & rhs ) const bool operator==( list const & rhs ) const
{ {
return mp11::mp_for_each< mp11::mp_iota_c< sizeof...(A) > >( equal_lambda<data_type>( data_, rhs.data_ ) ).result; return _bi::tuple_for_each( equal_lambda(), data_, rhs.data_ ).result;
} }
}; };

View File

@@ -0,0 +1,111 @@
#ifndef BOOST_BIND_DETAIL_INTEGER_SEQUENCE_HPP_INCLUDED
#define BOOST_BIND_DETAIL_INTEGER_SEQUENCE_HPP_INCLUDED
// Copyright 2015, 2017, 2019 Peter Dimov.
//
// 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 <cstddef>
#if defined(__has_builtin)
# if __has_builtin(__make_integer_seq)
# define BOOST_BIND_DETAIL_HAS_MAKE_INTEGER_SEQ
# endif
#endif
namespace boost
{
namespace _bi
{
// integer_sequence
template<class T, T... I> struct integer_sequence
{
};
#if defined(BOOST_BIND_DETAIL_HAS_MAKE_INTEGER_SEQ)
template<class T, T N> using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
#else
// 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;
#endif // defined(BOOST_BIND_DETAIL_HAS_MAKE_INTEGER_SEQ)
// 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)>;
} // namespace _bi
} // namespace boost
#endif // #ifndef BOOST_BIND_DETAIL_INTEGER_SEQUENCE_HPP_INCLUDED

View File

@@ -0,0 +1,63 @@
#ifndef BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED
#define BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED
// Copyright 2015-2020 Peter Dimov.
//
// 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/bind/detail/integer_sequence.hpp>
#include <utility>
#include <type_traits>
#include <cstddef>
#if BOOST_MP11_MSVC
# pragma warning( push )
# pragma warning( disable: 4100 ) // unreferenced formal parameter 'tp'
#endif
namespace boost
{
namespace _bi
{
// tuple_for_each( f, tp )
template<class F, class Tp, std::size_t... J> F tuple_for_each_impl( F&& f, Tp&& tp, integer_sequence<std::size_t, J...> )
{
using A = int[ 1 + sizeof...(J) ];
using std::get;
return (void)A{ 0, ((void)f(get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f);
}
template<class F, class Tp> F tuple_for_each( F&& f, Tp&& tp )
{
using seq = make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>;
return _bi::tuple_for_each_impl( std::forward<F>(f), std::forward<Tp>(tp), seq() );
}
// tuple_for_each( f, tp1, tp2 )
template<class F, class Tp1, class Tp2, std::size_t... J> F tuple_for_each_impl( F&& f, Tp1&& tp1, Tp2&& tp2, integer_sequence<std::size_t, J...> )
{
using A = int[ 1 + sizeof...(J) ];
using std::get;
return (void)A{ 0, ((void)f( get<J>(std::forward<Tp1>(tp1)), get<J>(std::forward<Tp2>(tp2)) ), 0)... }, std::forward<F>(f);
}
template<class F, class Tp1, class Tp2> F tuple_for_each( F&& f, Tp1&& tp1, Tp2&& tp2 )
{
using seq = make_index_sequence<std::tuple_size<typename std::remove_reference<Tp1>::type>::value>;
return _bi::tuple_for_each_impl( std::forward<F>(f), std::forward<Tp1>(tp1), std::forward<Tp2>(tp2), seq() );
}
} // namespace _bi
} // namespace boost
#if BOOST_MP11_MSVC
# pragma warning( pop )
#endif
#endif // #ifndef BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED