2
0
mirror of https://github.com/boostorg/compat.git synced 2026-01-20 04:22:24 +00:00

20 Commits

Author SHA1 Message Date
Peter Dimov
30242af2c2 Add constexpr tests for bind_back 2024-03-29 21:43:34 +02:00
Peter Dimov
9a58caf918 Add bind_back 2024-03-29 21:20:49 +02:00
Peter Dimov
28e71552eb Add integer_sequence_test 2024-03-28 21:37:43 +02:00
Peter Dimov
10ad6ab592 Add boost/compat/integer_sequence.hpp 2024-03-28 21:28:20 +02:00
Peter Dimov
39ddb40a47 Update test/quick.cpp 2024-03-28 21:13:31 +02:00
Peter Dimov
928f2d7255 Add bind_front_md_constexpr_test 2024-03-28 21:12:46 +02:00
Peter Dimov
5a5db4a74f Add bind_front_mfn_constexpr_test 2024-03-28 21:12:46 +02:00
Peter Dimov
acd8c12e91 Add bind_front_obj_constexpr_test 2024-03-28 21:12:46 +02:00
Peter Dimov
710ea6a904 Add bind_front_fn_constexpr_test 2024-03-28 21:12:46 +02:00
Peter Dimov
a09b9b2c5a Add bind_front_md_test 2024-03-28 21:12:46 +02:00
Peter Dimov
758b0c2ef9 Add bind_front_mfn_test 2024-03-28 21:12:46 +02:00
Peter Dimov
4ea967b756 Avoid bind_front_obj_test failure on GCC 4.8 2024-03-28 21:12:46 +02:00
Peter Dimov
d745abe3a3 Disable invoke_mfn_constexpr_test, invoke_md_constexpr_test for GCC 4.9 as well 2024-03-28 21:12:46 +02:00
Peter Dimov
fa9180b234 Add GCC 4.9 to GHA 2024-03-28 21:12:46 +02:00
Peter Dimov
abcc654046 Add bind_front_obj_test 2024-03-28 21:12:46 +02:00
Peter Dimov
b6deff5638 Update bind_front_fn_test 2024-03-28 21:12:46 +02:00
Peter Dimov
90e76cb4f4 Add bind_front 2024-03-28 21:12:45 +02:00
Peter Dimov
c290c03ea3 Merge branch 'master' into develop 2024-03-28 21:12:12 +02:00
Peter Dimov
bba8d5f101 Update CMakeLists.txt 2024-03-28 20:32:41 +02:00
Peter Dimov
56b776fc29 Update test/quick.cpp 2024-03-28 20:31:36 +02:00
25 changed files with 2293 additions and 3 deletions

View File

@@ -22,6 +22,11 @@ jobs:
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8
- toolset: gcc-4.9
cxxstd: "03,11"
os: ubuntu-latest
container: ubuntu:16.04
install: g++-4.9
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-latest
@@ -194,7 +199,7 @@ jobs:
mkdir -p libs/$LIBRARY
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
python3 tools/boostdep/depinst/depinst.py $LIBRARY
./bootstrap.sh
./b2 -d0 headers

View File

@@ -15,6 +15,8 @@ target_include_directories(boost_compat INTERFACE include)
target_link_libraries(boost_compat
INTERFACE
Boost::assert
Boost::config
Boost::throw_exception
)
target_compile_features(boost_compat INTERFACE cxx_std_11)

View File

@@ -0,0 +1,72 @@
#ifndef BOOST_COMPAT_BIND_BACK_HPP_INCLUDED
#define BOOST_COMPAT_BIND_BACK_HPP_INCLUDED
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/invoke.hpp>
#include <boost/compat/type_traits.hpp>
#include <boost/compat/integer_sequence.hpp>
#include <boost/compat/detail/returns.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <tuple>
#include <utility>
namespace boost {
namespace compat {
namespace detail {
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
# pragma warning(push)
# pragma warning(disable: 4100) // 'a': unreferenced formal parameter
#endif
template<class F, class A, class... B, std::size_t... I>
static constexpr auto invoke_bind_back_( F&& f, A&& a, index_sequence<I...>, B&&... b )
BOOST_COMPAT_RETURNS( compat::invoke( std::forward<F>(f), std::forward<B>(b)..., std::get<I>( std::forward<A>(a) )... ) )
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
# pragma warning(pop)
#endif
template<class F, class... A> class bind_back_
{
private:
F f_;
std::tuple<A...> a_;
public:
template<class F2, class... A2>
constexpr bind_back_( F2&& f2, A2&&... a2 ): f_( std::forward<F2>(f2) ), a_( std::forward<A2>(a2)... ) {}
public:
template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &
BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> constexpr auto operator()( B&&... b ) const &
BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &&
BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> constexpr auto operator()( B&&... b ) const &&
BOOST_COMPAT_RETURNS( detail::invoke_bind_back_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
};
} // namespace detail
template<class F, class... A> constexpr auto bind_back( F&& f, A&&... a ) -> detail::bind_back_< decay_t<F>, decay_t<A>... >
{
return { std::forward<F>(f), std::forward<A>(a)... };
}
} // namespace compat
} // namespace boost
#endif // BOOST_COMPAT_BIND_BACK_HPP_INCLUDED

View File

@@ -0,0 +1,72 @@
#ifndef BOOST_COMPAT_BIND_FRONT_HPP_INCLUDED
#define BOOST_COMPAT_BIND_FRONT_HPP_INCLUDED
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/invoke.hpp>
#include <boost/compat/type_traits.hpp>
#include <boost/compat/integer_sequence.hpp>
#include <boost/compat/detail/returns.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <tuple>
#include <utility>
namespace boost {
namespace compat {
namespace detail {
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
# pragma warning(push)
# pragma warning(disable: 4100) // 'a': unreferenced formal parameter
#endif
template<class F, class A, class... B, std::size_t... I>
static constexpr auto invoke_bind_front_( F&& f, A&& a, index_sequence<I...>, B&&... b )
BOOST_COMPAT_RETURNS( compat::invoke( std::forward<F>(f), std::get<I>( std::forward<A>(a) )..., std::forward<B>(b)... ) )
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
# pragma warning(pop)
#endif
template<class F, class... A> class bind_front_
{
private:
F f_;
std::tuple<A...> a_;
public:
template<class F2, class... A2>
constexpr bind_front_( F2&& f2, A2&&... a2 ): f_( std::forward<F2>(f2) ), a_( std::forward<A2>(a2)... ) {}
public:
template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &
BOOST_COMPAT_RETURNS( detail::invoke_bind_front_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> constexpr auto operator()( B&&... b ) const &
BOOST_COMPAT_RETURNS( detail::invoke_bind_front_( f_, a_, make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> BOOST_CXX14_CONSTEXPR auto operator()( B&&... b ) &&
BOOST_COMPAT_RETURNS( detail::invoke_bind_front_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
template<class... B> constexpr auto operator()( B&&... b ) const &&
BOOST_COMPAT_RETURNS( detail::invoke_bind_front_( std::move(f_), std::move(a_), make_index_sequence<sizeof...(A)>(), std::forward<B>(b)... ) )
};
} // namespace detail
template<class F, class... A> constexpr auto bind_front( F&& f, A&&... a ) -> detail::bind_front_< decay_t<F>, decay_t<A>... >
{
return { std::forward<F>(f), std::forward<A>(a)... };
}
} // namespace compat
} // namespace boost
#endif // BOOST_COMPAT_BIND_FRONT_HPP_INCLUDED

View File

@@ -0,0 +1,120 @@
#ifndef BOOST_COMPAT_INTEGER_SEQUENCE_HPP_INCLUDED
#define BOOST_COMPAT_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(_MSC_VER) || defined(__GNUC__)
# pragma push_macro( "I" )
# undef I
#endif
#if defined(__has_builtin)
# if __has_builtin(__make_integer_seq)
# define BOOST_COMPAT_HAS_MAKE_INTEGER_SEQ
# endif
#endif
namespace boost
{
namespace compat
{
// integer_sequence
template<class T, T... I> struct integer_sequence
{
};
#if defined(BOOST_COMPAT_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_COMPAT_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 compat
} // namespace boost
#if defined(_MSC_VER) || defined(__GNUC__)
# pragma pop_macro( "I" )
#endif
#endif // #ifndef BOOST_COMPAT_INTEGER_SEQUENCE_HPP_INCLUDED

View File

@@ -15,6 +15,8 @@ template<class T> using remove_cv_t = typename std::remove_cv<T>::type;
template<class T> using remove_reference_t = typename std::remove_reference<T>::type;
template<class T> using remove_cvref_t = remove_cv_t< remove_reference_t<T> >;
template<class T> using decay_t = typename std::decay<T>::type;
template<bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type;
template<bool B, class T, class F> using conditional_t = typename std::conditional<B, T, F>::type;

View File

@@ -45,10 +45,32 @@ run invoke_md_noexcept_test.cpp ;
compile invoke_fn_constexpr_test.cpp ;
compile invoke_obj_constexpr_test.cpp ;
compile invoke_mfn_constexpr_test.cpp
: <toolset>gcc-4.8:<build>no ;
: <toolset>gcc-4.8:<build>no <toolset>gcc-4.9:<build>no ;
compile invoke_md_constexpr_test.cpp
: <toolset>gcc-4.8:<build>no ;
: <toolset>gcc-4.8:<build>no <toolset>gcc-4.9:<build>no ;
run invoke_result_test.cpp ;
run is_invocable_test.cpp ;
run is_nothrow_invocable_test.cpp ;
run bind_front_fn_test.cpp ;
run bind_front_obj_test.cpp ;
run bind_front_mfn_test.cpp ;
run bind_front_md_test.cpp ;
compile bind_front_fn_constexpr_test.cpp ;
compile bind_front_obj_constexpr_test.cpp ;
compile bind_front_mfn_constexpr_test.cpp ;
compile bind_front_md_constexpr_test.cpp ;
run integer_sequence_test.cpp ;
run bind_back_fn_test.cpp ;
run bind_back_obj_test.cpp ;
run bind_back_mfn_test.cpp ;
run bind_back_md_test.cpp ;
compile bind_back_fn_constexpr_test.cpp ;
compile bind_back_obj_constexpr_test.cpp ;
compile bind_back_mfn_constexpr_test.cpp ;
compile bind_back_md_constexpr_test.cpp ;

View File

@@ -0,0 +1,60 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_back.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
constexpr int f0()
{
return -1;
}
constexpr int f1( int x1 ) noexcept
{
return x1;
}
constexpr int f2( int x1, int x2 )
{
return 10*x1+x2;
}
constexpr int f3( int x1, int x2, int x3 ) noexcept
{
return 100*x1 + 10*x2 + x3;
}
int main()
{
BOOST_TEST_EQ( boost::compat::bind_back( f0 )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( f1 )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( f2 )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( f3 )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( f1, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( f2, 1 )( 2 ), 21 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1 )( 2, 3 ), 231 );
BOOST_TEST_EQ( boost::compat::bind_back( f2, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1, 2 )( 3 ), 312 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1, 2, 3 )(), 123 );
}
#endif

View File

@@ -0,0 +1,57 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_back.hpp>
#include <boost/core/lightweight_test.hpp>
#include <memory>
int f0()
{
return -1;
}
int f1( int x1 ) noexcept
{
return x1;
}
int f2( int x1, int x2 )
{
return 10*x1+x2;
}
int f3( int x1, int x2, int x3 ) noexcept
{
return 100*x1 + 10*x2 + x3;
}
int g( std::unique_ptr<int> p, std::unique_ptr<int> q )
{
return 10 * *p + *q;
}
int main()
{
BOOST_TEST_EQ( boost::compat::bind_back( f0 )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( f1 )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( f2 )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( f3 )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( f1, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( f2, 1 )( 2 ), 21 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1 )( 2, 3 ), 231 );
BOOST_TEST_EQ( boost::compat::bind_back( f2, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1, 2 )( 3 ), 312 );
BOOST_TEST_EQ( boost::compat::bind_back( f3, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( g, std::unique_ptr<int>( new int(1) ) )( std::unique_ptr<int>( new int(2) ) ), 21 );
return boost::report_errors();
}

View File

@@ -0,0 +1,58 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_back.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct X
{
int m = -1;
};
struct Y: public X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, X() )(), -1 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &x )(), -1 );
}
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, Y() )(), -1 );
}
{
constexpr Y y = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &y )(), -1 );
}
#endif
}
#endif

101
test/bind_back_md_test.cpp Normal file
View File

@@ -0,0 +1,101 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_back.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
struct X
{
int m = -1;
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, X() )(), -1 );
}
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, Y() )(), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, x )(), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &x )(), -1 );
boost::compat::bind_back( &X::m, &x )() = +1;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &x )(), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(x) )(), -1 );
boost::compat::bind_back( &X::m, std::ref(x) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(x) )(), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::cref(x) )(), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, y )(), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &y )(), -1 );
boost::compat::bind_back( &X::m, &y )() = +1;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &y )(), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(y) )(), -1 );
boost::compat::bind_back( &X::m, std::ref(y) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(y) )(), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::cref(y) )(), -1 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(x) )(), -1 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, std::ref(y) )(), -1 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,137 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_back.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct X
{
constexpr int f0()
{
return -1;
}
constexpr int f1( int x1 ) noexcept
{
return x1;
}
constexpr int f2( int x1, int x2 ) const
{
return 10*x1+x2;
}
constexpr int f3( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct Y: public X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( X() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( X(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, X(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, X(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, X(), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( X() ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( X() ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( X() ), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( Y() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( Y(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( Y(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( Y(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, Y(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, Y(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, Y(), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( Y() ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( Y() ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( Y() ), 123 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
constexpr Y x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
{
constexpr Y x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
}
#endif

308
test/bind_back_mfn_test.cpp Normal file
View File

@@ -0,0 +1,308 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_back.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
#include <memory>
struct X
{
int f0()
{
return -1;
}
int f1( int x1 ) noexcept
{
return x1;
}
int f2( int x1, int x2 ) const
{
return 10*x1+x2;
}
int f3( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( X() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( X(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, X(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, X(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, X(), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( X() ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( X() ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( X() ), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( Y() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( Y(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( Y(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( Y(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, Y(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, Y(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, Y(), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( Y() ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( Y() ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( Y() ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( x ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( x ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, &x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( &x ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, &x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( &x ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, std::ref(x), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( std::ref(x) ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::ref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::ref(x) ), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f0 )( std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1 )( std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, std::ref(x), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f1, 1 )( std::ref(x) ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::ref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::ref(x) ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::cref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::cref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::cref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::cref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::cref(x) ), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::cref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::cref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::cref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::cref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::cref(x) ), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( x ), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, &x, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( &x ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( &x ), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::ref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::ref(x) ), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f2, 1, 2 )( std::ref(x) ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::ref(x) ), 123 );
}
{
std::unique_ptr<X> px( new X );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::move(px) ), 123 );
}
{
std::unique_ptr<Y> px( new Y );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, 1, 2, 3 )( std::move(px) ), 123 );
}
{
std::unique_ptr<X> px( new X );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::move(px), 1, 2, 3 )(), 123 );
}
{
std::unique_ptr<Y> px( new Y );
BOOST_TEST_EQ( boost::compat::bind_back( &X::f3, std::move(px), 1, 2, 3 )(), 123 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,96 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_back.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct F1
{
constexpr int operator()()
{
return -1;
}
constexpr int operator()( int x1 ) noexcept
{
return x1;
}
constexpr int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
constexpr int operator()( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct F2
{
constexpr int operator()( int x1, int x2 ) &
{
return 100*x1 + 10*x2 + 1;
}
constexpr int operator()( int x1, int x2 ) const &
{
return 100*x1 + 10*x2 + 2;
}
constexpr int operator()( int x1, int x2 ) &&
{
return 100*x1 + 10*x2 + 3;
}
constexpr int operator()( int x1, int x2 ) const &&
{
return 100*x1 + 10*x2 + 4;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( F1() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )( 2 ), 21 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )( 2, 3 ), 231 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2 )( 3 ), 312 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_back( F2(), 9 )( 8 ), 893 );
}
{
constexpr auto fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 892 );
}
{
constexpr auto fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 894 );
}
}
#endif

101
test/bind_back_obj_test.cpp Normal file
View File

@@ -0,0 +1,101 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_back.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
struct F1
{
int operator()()
{
return -1;
}
int operator()( int x1 ) noexcept
{
return x1;
}
int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
int operator()( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct F2
{
int operator()( int x1, int x2 ) &
{
return 100*x1 + 10*x2 + 1;
}
int operator()( int x1, int x2 ) const &
{
return 100*x1 + 10*x2 + 2;
}
int operator()( int x1, int x2 ) &&
{
return 100*x1 + 10*x2 + 3;
}
int operator()( int x1, int x2 ) const &&
{
return 100*x1 + 10*x2 + 4;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_back( F1() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( F1() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )( 2 ), 21 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1 )( 2, 3 ), 231 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2 )( 3 ), 312 );
BOOST_TEST_EQ( boost::compat::bind_back( F1(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_back( F2(), 9 )( 8 ), 893 );
}
{
auto fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 891 );
}
{
auto const fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 892 );
}
{
auto fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 893 );
}
#if !BOOST_WORKAROUND(BOOST_GCC, < 40900)
{
auto const fn = boost::compat::bind_back( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 894 );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,60 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_front.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
constexpr int f0()
{
return -1;
}
constexpr int f1( int x1 ) noexcept
{
return x1;
}
constexpr int f2( int x1, int x2 )
{
return 10*x1+x2;
}
constexpr int f3( int x1, int x2, int x3 ) noexcept
{
return 100*x1 + 10*x2 + x3;
}
int main()
{
BOOST_TEST_EQ( boost::compat::bind_front( f0 )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( f1 )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( f2 )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3 )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f1, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( f2, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f2, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1, 2, 3 )(), 123 );
}
#endif

View File

@@ -0,0 +1,57 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_front.hpp>
#include <boost/core/lightweight_test.hpp>
#include <memory>
int f0()
{
return -1;
}
int f1( int x1 ) noexcept
{
return x1;
}
int f2( int x1, int x2 )
{
return 10*x1+x2;
}
int f3( int x1, int x2, int x3 ) noexcept
{
return 100*x1 + 10*x2 + x3;
}
int g( std::unique_ptr<int> p, std::unique_ptr<int> q )
{
return 10 * *p + *q;
}
int main()
{
BOOST_TEST_EQ( boost::compat::bind_front( f0 )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( f1 )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( f2 )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3 )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f1, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( f2, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f2, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( f3, 1, 2, 3 )(), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( g, std::unique_ptr<int>( new int(1) ) )( std::unique_ptr<int>( new int(2) ) ), 12 );
return boost::report_errors();
}

View File

@@ -0,0 +1,58 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_front.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct X
{
int m = -1;
};
struct Y: public X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, X() )(), -1 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
}
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, Y() )(), -1 );
}
{
constexpr Y y = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), -1 );
}
#endif
}
#endif

101
test/bind_front_md_test.cpp Normal file
View File

@@ -0,0 +1,101 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_front.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
struct X
{
int m = -1;
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, X() )(), -1 );
}
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, Y() )(), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, x )(), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
boost::compat::bind_front( &X::m, &x )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), -1 );
boost::compat::bind_front( &X::m, std::ref(x) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::cref(x) )(), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, y )(), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), -1 );
boost::compat::bind_front( &X::m, &y )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), -1 );
boost::compat::bind_front( &X::m, std::ref(y) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::cref(y) )(), -1 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), -1 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), -1 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,167 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_front.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct X
{
constexpr int f0()
{
return -1;
}
constexpr int f1( int x1 ) noexcept
{
return x1;
}
constexpr int f2( int x1, int x2 ) const
{
return 10*x1+x2;
}
constexpr int f3( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct Y: public X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( X() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( X(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, X() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, X() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, X(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, Y() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, Y() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1, 2, 3 )(), 123 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
{
constexpr Y x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
constexpr Y x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
}
#endif

View File

@@ -0,0 +1,378 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 7
# pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif
#include <boost/compat/bind_front.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
#include <memory>
struct X
{
int f0()
{
return -1;
}
int f1( int x1 ) noexcept
{
return x1;
}
int f2( int x1, int x2 ) const
{
return 10*x1+x2;
}
int f3( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( X() ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( X(), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, X() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, X() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, X(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, X(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, X(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, Y() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, Y() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, Y(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, Y(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, Y(), 1, 2, 3 )(), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, x )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, &x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, &x )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, &x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, std::ref(x) )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, std::ref(x) )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, std::ref(x), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::cref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1, 2, 3 )(), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, x )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, &x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, &x )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, &x, 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0 )( std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1 )( std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f0, std::ref(x) )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, std::ref(x) )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f1, std::ref(x), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
}
{
Y x;
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::cref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::cref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::cref(x), 1, 2, 3 )(), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, x, 1, 2, 3 )(), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, &x, 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, &x, 1, 2, 3 )(), 123 );
}
{
Y const x = {};
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x) )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x) )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f2, std::ref(x), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::ref(x), 1, 2, 3 )(), 123 );
}
{
std::unique_ptr<X> px( new X );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::move(px), 1 )( 2, 3 ), 123 );
}
{
std::unique_ptr<Y> px( new Y );
BOOST_TEST_EQ( boost::compat::bind_front( &X::f3, std::move(px), 1 )( 2, 3 ), 123 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,96 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_front.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct F1
{
constexpr int operator()()
{
return -1;
}
constexpr int operator()( int x1 ) noexcept
{
return x1;
}
constexpr int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
constexpr int operator()( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct F2
{
constexpr int operator()( int x1, int x2 ) &
{
return 100*x1 + 10*x2 + 1;
}
constexpr int operator()( int x1, int x2 ) const &
{
return 100*x1 + 10*x2 + 2;
}
constexpr int operator()( int x1, int x2 ) &&
{
return 100*x1 + 10*x2 + 3;
}
constexpr int operator()( int x1, int x2 ) const &&
{
return 100*x1 + 10*x2 + 4;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( F1() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_front( F2(), 9 )( 8 ), 983 );
}
{
constexpr auto fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 982 );
}
{
constexpr auto fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 984 );
}
}
#endif

View File

@@ -0,0 +1,101 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/bind_front.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
struct F1
{
int operator()()
{
return -1;
}
int operator()( int x1 ) noexcept
{
return x1;
}
int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
int operator()( int x1, int x2, int x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct F2
{
int operator()( int x1, int x2 ) &
{
return 100*x1 + 10*x2 + 1;
}
int operator()( int x1, int x2 ) const &
{
return 100*x1 + 10*x2 + 2;
}
int operator()( int x1, int x2 ) &&
{
return 100*x1 + 10*x2 + 3;
}
int operator()( int x1, int x2 ) const &&
{
return 100*x1 + 10*x2 + 4;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( F1() )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1 ), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1() )( 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )(), 1 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )( 2 ), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1 )( 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2 )(), 12 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2 )( 3 ), 123 );
BOOST_TEST_EQ( boost::compat::bind_front( F1(), 1, 2, 3 )(), 123 );
}
{
BOOST_TEST_EQ( boost::compat::bind_front( F2(), 9 )( 8 ), 983 );
}
{
auto fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 981 );
}
{
auto const fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( fn( 8 ), 982 );
}
{
auto fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 983 );
}
#if !BOOST_WORKAROUND(BOOST_GCC, < 40900)
{
auto const fn = boost::compat::bind_front( F2(), 9 );
BOOST_TEST_EQ( std::move( fn )( 8 ), 984 );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
// Copyright 2015 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/integer_sequence.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <cstddef>
int main()
{
using boost::compat::integer_sequence;
using boost::compat::make_integer_sequence;
using boost::compat::index_sequence;
using boost::compat::make_index_sequence;
using boost::compat::index_sequence_for;
BOOST_TEST_TRAIT_SAME(make_integer_sequence<int, 0>, integer_sequence<int>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<int, 1>, integer_sequence<int, 0>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<int, 2>, integer_sequence<int, 0, 1>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<int, 3>, integer_sequence<int, 0, 1, 2>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<int, 4>, integer_sequence<int, 0, 1, 2, 3>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<char, 0>, integer_sequence<char>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<char, 1>, integer_sequence<char, 0>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<char, 2>, integer_sequence<char, 0, 1>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<char, 3>, integer_sequence<char, 0, 1, 2>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<char, 4>, integer_sequence<char, 0, 1, 2, 3>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<std::size_t, 0>, integer_sequence<std::size_t>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<std::size_t, 1>, integer_sequence<std::size_t, 0>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<std::size_t, 2>, integer_sequence<std::size_t, 0, 1>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<std::size_t, 3>, integer_sequence<std::size_t, 0, 1, 2>);
BOOST_TEST_TRAIT_SAME(make_integer_sequence<std::size_t, 4>, integer_sequence<std::size_t, 0, 1, 2, 3>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<0>, integer_sequence<std::size_t>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<1>, integer_sequence<std::size_t, 0>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<2>, integer_sequence<std::size_t, 0, 1>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<3>, integer_sequence<std::size_t, 0, 1, 2>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<4>, integer_sequence<std::size_t, 0, 1, 2, 3>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<0>, index_sequence<>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<1>, index_sequence<0>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<2>, index_sequence<0, 1>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<3>, index_sequence<0, 1, 2>);
BOOST_TEST_TRAIT_SAME(make_index_sequence<4>, index_sequence<0, 1, 2, 3>);
BOOST_TEST_TRAIT_SAME(index_sequence_for<>, index_sequence<>);
BOOST_TEST_TRAIT_SAME(index_sequence_for<void>, index_sequence<0>);
BOOST_TEST_TRAIT_SAME(index_sequence_for<void, void>, index_sequence<0, 1>);
BOOST_TEST_TRAIT_SAME(index_sequence_for<void, void, void>, index_sequence<0, 1, 2>);
BOOST_TEST_TRAIT_SAME(index_sequence_for<void, void, void, void>, index_sequence<0, 1, 2, 3>);
return boost::report_errors();
}

View File

@@ -3,6 +3,10 @@
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/latch.hpp>
#include <boost/compat/shared_lock.hpp>
#include <boost/compat/invoke.hpp>
#include <boost/compat/bind_front.hpp>
#include <boost/compat/bind_back.hpp>
int main()
{