2
0
mirror of https://github.com/boostorg/compat.git synced 2026-01-19 16:12:15 +00:00

40 Commits

Author SHA1 Message Date
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
Peter Dimov
53c5bcf824 Disable is_nothrow_invocable under msvc-14.0 2024-03-22 19:15:09 +02:00
Peter Dimov
e270914326 Rephrase is_nothrow_invocable to not crash MSVC 2024-03-22 19:05:04 +02:00
Peter Dimov
5b6c4ffe95 Add is_nothrow_invocable 2024-03-22 18:38:10 +02:00
Peter Dimov
26e18fd796 Add is_invocable 2024-03-22 18:14:36 +02:00
Peter Dimov
571b48ca51 Add Boost::mp11 to test/CMakeLists.txt 2024-03-22 17:48:08 +02:00
Peter Dimov
b4b6cacb9d Add invoke_result_t 2024-03-22 17:34:42 +02:00
Peter Dimov
6b0825b893 Disable invoke_mfn_constexpr_test and invoke_md_constexpr_test for GCC 4.8 2024-03-22 05:09:13 +02:00
Peter Dimov
dca886ef30 Add constexpr tests for invoke 2024-03-22 05:02:43 +02:00
Peter Dimov
4710db471a Add noexcept tests for invoke 2024-03-22 02:35:29 +02:00
Peter Dimov
d83085a5d9 Add trailing return types to mem_fn for C++11 2024-03-21 21:37:10 +02:00
Peter Dimov
8633042b73 Add constexpr to mem_fn and invoke 2024-03-21 21:30:10 +02:00
Peter Dimov
eba152aa8e Reimplement mem_fn 2024-03-21 21:27:04 +02:00
Peter Dimov
efff37c7a3 Add mem_fn_mfn_test, mem_fn_md_test 2024-03-21 21:00:34 +02:00
Peter Dimov
d745a4cfba Disable -Wnoexcept-type under GCC 7 2024-03-21 20:43:25 +02:00
Peter Dimov
9743e1e03f Add invoke_md_test 2024-03-21 20:28:27 +02:00
Peter Dimov
3980572c34 Add invoke_mfn_test 2024-03-21 20:21:58 +02:00
Peter Dimov
9cad6fbca9 Add invoke_obj_test 2024-03-21 20:12:01 +02:00
Peter Dimov
31fe10bf54 Update invoke_fn_test.cpp 2024-03-21 20:04:47 +02:00
Peter Dimov
b6858273bd Add boost::compat::invoke 2024-03-21 19:57:32 +02:00
Peter Dimov
0220855d9c Update ci.yml 2024-03-21 19:51:58 +02:00
Peter Dimov
91c2054151 Merge pull request #7 from cmazakas/missing-copyright
Add missing copyright to shared_lock_test.cpp
2024-03-21 19:48:13 +02:00
Christian Mazakas
6153916abe Add missing copyright to shared_lock_test.cpp 2024-03-21 10:41:17 -07:00
38 changed files with 2970 additions and 13 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
@@ -116,24 +121,33 @@ jobs:
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
container: ubuntu:22.04
os: ubuntu-latest
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
container: ubuntu:22.04
os: ubuntu-latest
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
container: ubuntu:22.04
os: ubuntu-latest
install: clang-15
- toolset: clang
compiler: clang++-16
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
os: ubuntu-latest
install: clang-16
- toolset: clang
compiler: clang++-17
cxxstd: "03,11,14,17,20,2b"
container: ubuntu:23.10
os: ubuntu-latest
install: clang-17
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-11
@@ -185,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
@@ -228,7 +242,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
@@ -272,7 +286,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
@@ -321,7 +335,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
@@ -380,7 +394,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install packages
if: matrix.install
@@ -434,7 +448,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
@@ -483,7 +497,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd
@@ -550,7 +564,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Boost
shell: cmd

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_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,10 @@
#ifndef BOOST_COMPAT_DETAIL_RETURNS_HPP_INCLUDED
#define BOOST_COMPAT_DETAIL_RETURNS_HPP_INCLUDED
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#define BOOST_COMPAT_RETURNS(...) noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
#endif // BOOST_COMPAT_DETAIL_RETURNS_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

@@ -0,0 +1,67 @@
#ifndef BOOST_COMPAT_INVOKE_HPP_INCLUDED
#define BOOST_COMPAT_INVOKE_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/mem_fn.hpp>
#include <boost/compat/type_traits.hpp>
#include <boost/compat/detail/returns.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <utility>
namespace boost {
namespace compat {
// invoke
template<class F, class... A>
constexpr auto invoke( F&& f, A&&... a )
BOOST_COMPAT_RETURNS( std::forward<F>(f)(std::forward<A>(a)...) )
template<class M, class T, class... A>
constexpr auto invoke( M T::* pm, A&&... a )
BOOST_COMPAT_RETURNS( mem_fn(pm)(std::forward<A>(a)...) )
// invoke_result_t
template<class F, class... A> using invoke_result_t = decltype( compat::invoke( std::declval<F>(), std::declval<A>()... ) );
// is_invocable
namespace detail {
template<class, class F, class... A> struct is_invocable_: std::false_type {};
template<class F, class... A> struct is_invocable_< void_t<invoke_result_t<F, A...>>, F, A... >: std::true_type {};
} // namespace detail
template<class F, class... A> struct is_invocable: detail::is_invocable_<void, F, A...> {};
// is_nothrow_invocable
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
template<class F, class... A> struct is_nothrow_invocable: std::false_type {};
#else
namespace detail {
template<class F, class... A> struct is_nothrow_invocable_
{
using type = std::integral_constant<bool, noexcept( compat::invoke( std::declval<F>(), std::declval<A>()... ) )>;
};
} // namespace detail
template<class F, class... A> struct is_nothrow_invocable: conditional_t< is_invocable<F, A...>::value, detail::is_nothrow_invocable_<F, A...>, std::false_type >::type {};
#endif
} // namespace compat
} // namespace boost
#endif // BOOST_COMPAT_INVOKE_HPP_INCLUDED

View File

@@ -0,0 +1,78 @@
#ifndef BOOST_COMPAT_MEM_FN_HPP_INCLUDED
#define BOOST_COMPAT_MEM_FN_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/type_traits.hpp>
#include <boost/compat/detail/returns.hpp>
#include <functional>
namespace boost {
namespace compat {
namespace detail {
template<class T, class U, class Td = remove_cvref_t<T>, class Ud = remove_cvref_t<U>>
struct is_same_or_base: std::integral_constant<bool, std::is_same<Td, Ud>::value || std::is_base_of<Td, Ud>::value>
{
};
template<class T> struct is_reference_wrapper_: std::false_type {};
template<class T> struct is_reference_wrapper_< std::reference_wrapper<T> >: std::true_type {};
template<class T> struct is_reference_wrapper: is_reference_wrapper_< remove_cvref_t<T> > {};
template<class M, class T> struct _mfn
{
M T::* pm_;
template<class U, class... A, class En = enable_if_t<is_same_or_base<T, U>::value>>
constexpr auto operator()( U&& u, A&&... a ) const
BOOST_COMPAT_RETURNS( (std::forward<U>(u).*pm_)( std::forward<A>(a)... ) )
template<class U, class... A, class = void, class En = enable_if_t< !is_same_or_base<T, U>::value && is_reference_wrapper<U>::value>>
constexpr auto operator()( U&& u, A&&... a ) const
BOOST_COMPAT_RETURNS( (u.get().*pm_)( std::forward<A>(a)... ) )
template<class U, class... A, class = void, class = void, class En = enable_if_t< !is_same_or_base<T, U>::value && !is_reference_wrapper<U>::value>>
constexpr auto operator()( U&& u, A&&... a ) const
BOOST_COMPAT_RETURNS( ((*std::forward<U>(u)).*pm_)( std::forward<A>(a)... ) )
};
template<class M, class T> struct _md
{
M T::* pm_;
template<class U, class En = enable_if_t<is_same_or_base<T, U>::value>>
constexpr auto operator()( U&& u ) const
BOOST_COMPAT_RETURNS( std::forward<U>(u).*pm_ )
template<class U, class = void, class En = enable_if_t< !is_same_or_base<T, U>::value && is_reference_wrapper<U>::value>>
constexpr auto operator()( U&& u ) const
BOOST_COMPAT_RETURNS( u.get().*pm_ )
template<class U, class = void, class = void, class En = enable_if_t< !is_same_or_base<T, U>::value && !is_reference_wrapper<U>::value>>
constexpr auto operator()( U&& u ) const
BOOST_COMPAT_RETURNS( (*std::forward<U>(u)).*pm_ )
};
} // namespace detail
template<class M, class T, class En = enable_if_t< std::is_function<M>::value > >
constexpr auto mem_fn( M T::* pm ) noexcept -> detail::_mfn<M, T>
{
return detail::_mfn<M, T>{ pm };
}
template<class M, class T, class = void, class En = enable_if_t< !std::is_function<M>::value > >
constexpr auto mem_fn( M T::* pm ) noexcept -> detail::_md<M, T>
{
return detail::_md<M, T>{ pm };
}
} // namespace compat
} // namespace boost
#endif // BOOST_COMPAT_MEM_FN_HPP_INCLUDED

View File

@@ -0,0 +1,38 @@
#ifndef BOOST_COMPAT_TYPE_TRAITS_HPP_INCLUDED
#define BOOST_COMPAT_TYPE_TRAITS_HPP_INCLUDED
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <type_traits>
namespace boost {
namespace compat {
template<class T> using remove_const_t = typename std::remove_const<T>::type;
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;
namespace detail {
template<class...> struct make_void
{
using type = void;
};
} // namespace detail
template<class... T> using void_t = typename detail::make_void<T...>::type;
} // namespace compat
} // namespace boost
#endif // BOOST_COMPAT_TYPE_TRAITS_HPP_INCLUDED

View File

@@ -8,6 +8,7 @@ if(HAVE_BOOST_TEST)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::compat Boost::core Threads::Threads)
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::compat Boost::core Boost::mp11 Threads::Threads)
endif()

View File

@@ -25,5 +25,42 @@ project
run quick.cpp ;
run latch_test.cpp ;
run shared_lock_test.cpp ;
run shared_lock_test.cpp : : : <exception-handling>off : shared_lock_test_nx ;
run invoke_fn_test.cpp ;
run invoke_obj_test.cpp ;
run invoke_mfn_test.cpp ;
run invoke_md_test.cpp ;
run mem_fn_mfn_test.cpp ;
run mem_fn_md_test.cpp ;
run invoke_fn_noexcept_test.cpp ;
run invoke_obj_noexcept_test.cpp ;
run invoke_mfn_noexcept_test.cpp ;
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.9:<build>no ;
compile invoke_md_constexpr_test.cpp
: <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 ;

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

@@ -0,0 +1,40 @@
// 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/invoke.hpp>
#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::invoke( f0 ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( f1, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( f2, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( f3, 1, 2, 3 ), 123 );
}

View File

@@ -0,0 +1,47 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config/pragma_message.hpp>
#if !defined(__cpp_noexcept_function_type)
BOOST_PRAGMA_MESSAGE( "Test skipped, __cpp_noexcept_function_type is not defined" )
int main() {}
#else
#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
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 main()
{
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f0 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f1, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f2, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f3, 1, 2, 3 ) ), true );
return boost::report_errors();
}
#endif

40
test/invoke_fn_test.cpp Normal file
View File

@@ -0,0 +1,40 @@
// 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/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
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 main()
{
BOOST_TEST_EQ( boost::compat::invoke( f0 ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( f1, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( f2, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( f3, 1, 2, 3 ), 123 );
return boost::report_errors();
}

View File

@@ -0,0 +1,43 @@
// 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/config.hpp>
#include <boost/config/workaround.hpp>
#include <functional>
#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::invoke( &X::m, X() ), -1 );
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::m, x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &x ), -1 );
}
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
{
BOOST_TEST_EQ( boost::compat::invoke( &X::m, Y() ), -1 );
constexpr Y y = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::m, y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &y ), -1 );
}
#endif
}

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
#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
struct X
{
int m = -1;
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, X() ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, Y() ) ), true );
}
{
X x;
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, x ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, &x ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::ref(x) ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::cref(x) ) ), true );
}
{
Y y;
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, y ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, &y ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::ref(y) ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::cref(y) ) ), true );
}
{
X const x = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, x ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, &x ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::ref(x) ) ), true );
}
{
Y const y = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, y ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, &y ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::m, std::ref(y) ) ), true );
}
return boost::report_errors();
}

105
test/invoke_md_test.cpp Normal file
View File

@@ -0,0 +1,105 @@
// 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/core/lightweight_test.hpp>
#include <functional>
struct X
{
int m = -1;
};
struct Y: public virtual X
{
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::invoke( &X::m, X() ), -1 );
}
{
BOOST_TEST_EQ( boost::compat::invoke( &X::m, Y() ), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, x ), -1 );
boost::compat::invoke( &X::m, x ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, x ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &x ), -1 );
boost::compat::invoke( &X::m, &x ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &x ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(x) ), -1 );
boost::compat::invoke( &X::m, std::ref(x) ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(x) ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::cref(x) ), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, y ), -1 );
boost::compat::invoke( &X::m, y ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, y ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &y ), -1 );
boost::compat::invoke( &X::m, &y ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &y ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(y) ), -1 );
boost::compat::invoke( &X::m, std::ref(y) ) = +1;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(y) ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::cref(y) ), -1 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::m, x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(x) ), -1 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::m, y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::m, std::ref(y) ), -1 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,89 @@
// 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/invoke.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <functional>
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct X
{
constexpr int f0() const
{
return -1;
}
constexpr int f1( int x1 ) const 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::invoke( &X::f0, X() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, X(), 1, 2, 3 ), 123 );
}
{
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, Y() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, Y(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, Y(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, Y(), 1, 2, 3 ), 123 );
}
{
constexpr X x = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, &x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &x, 1, 2, 3 ), 123 );
}
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
{
constexpr Y y = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, &y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, &y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &y, 1, 2, 3 ), 123 );
}
#endif
}

View File

@@ -0,0 +1,134 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config/pragma_message.hpp>
#if !defined(__cpp_noexcept_function_type)
BOOST_PRAGMA_MESSAGE( "Test skipped, __cpp_noexcept_function_type is not defined" )
int main() {}
#else
#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
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( noexcept( boost::compat::invoke( &X::f0, X() ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, X(), 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, X(), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, X(), 1, 2, 3 ) ), true );
}
{
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, Y() ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, Y(), 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, Y(), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, Y(), 1, 2, 3 ) ), true );
}
{
X x;
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, x ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, x, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, x, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, x, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, &x ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, &x, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, &x, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, &x, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, std::ref(x) ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, std::ref(x), 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::ref(x), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::ref(x), 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::cref(x), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::cref(x), 1, 2, 3 ) ), true );
}
{
Y y;
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, y ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, y, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, y, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, y, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, &y ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, &y, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, &y, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, &y, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f0, std::ref(y) ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f1, std::ref(y), 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::ref(y), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::ref(y), 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::cref(y), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::cref(y), 1, 2, 3 ) ), true );
}
{
X const x = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, x, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, x, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, &x, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, &x, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::ref(x), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::ref(x), 1, 2, 3 ) ), true );
}
{
Y const y = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, y, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, y, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, &y, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, &y, 1, 2, 3 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f2, std::ref(y), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( &X::f3, std::ref(y), 1, 2, 3 ) ), true );
}
return boost::report_errors();
}
#endif

127
test/invoke_mfn_test.cpp Normal file
View File

@@ -0,0 +1,127 @@
// 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/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
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::invoke( &X::f0, X() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, X(), 1, 2, 3 ), 123 );
}
{
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, Y() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, Y(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, Y(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, Y(), 1, 2, 3 ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, &x ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::cref(x), 1, 2, 3 ), 123 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, &y ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, &y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f0, std::ref(y) ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f1, std::ref(y), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::ref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::ref(y), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::cref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::cref(y), 1, 2, 3 ), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::ref(x), 1, 2, 3 ), 123 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, &y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, &y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f2, std::ref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( &X::f3, std::ref(y), 1, 2, 3 ), 123 );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,50 @@
// 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>
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
#define BOOST_TEST_EQ(x, y) STATIC_ASSERT((x) == (y))
struct F
{
constexpr int operator()() const
{
return -1;
}
constexpr int operator()( int x1 ) const 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;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::invoke( F() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1, 2, 3 ), 123 );
}
{
constexpr F f = {};
BOOST_TEST_EQ( boost::compat::invoke( f ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2, 3 ), 123 );
}
}

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
#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
struct F
{
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;
}
};
int main()
{
{
BOOST_TEST_EQ( noexcept( boost::compat::invoke( F() ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( F(), 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( F(), 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( F(), 1, 2, 3 ) ), true );
}
{
F f = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f, 1 ) ), true );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f, 1, 2, 3 ) ), true );
}
{
F const f = {};
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f, 1, 2 ) ), false );
BOOST_TEST_EQ( noexcept( boost::compat::invoke( f, 1, 2, 3 ) ), true );
}
return boost::report_errors();
}

57
test/invoke_obj_test.cpp Normal file
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
#include <boost/compat/invoke.hpp>
#include <boost/core/lightweight_test.hpp>
struct F
{
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;
}
};
int main()
{
{
BOOST_TEST_EQ( boost::compat::invoke( F() ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( F(), 1, 2, 3 ), 123 );
}
{
F f;
BOOST_TEST_EQ( boost::compat::invoke( f ), -1 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2, 3 ), 123 );
}
{
F const f = {};
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::invoke( f, 1, 2, 3 ), 123 );
}
return boost::report_errors();
}

107
test/invoke_result_test.cpp Normal file
View File

@@ -0,0 +1,107 @@
// 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/utility.hpp>
struct F
{
void operator()()
{
}
char operator()( char x1 ) noexcept
{
return x1;
}
int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
double operator()( float x1, float x2, float x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct X
{
};
int main()
{
using boost::compat::invoke_result_t;
using boost::mp11::mp_valid;
// nonfunction
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int, int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int, int, int> ));
// function reference
BOOST_TEST_TRAIT_SAME( invoke_result_t<void(&)()>, void );
BOOST_TEST_TRAIT_SAME( invoke_result_t<char(&)(int), char>, char );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int(&)(int, int), int, int>, int );
BOOST_TEST_TRAIT_SAME( invoke_result_t<double(&)(double, double, double), float, float, float>, double );
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, void(&)(), int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(&)(int)> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(&)(int), int, int> ));
// function pointer
BOOST_TEST_TRAIT_SAME( invoke_result_t<void(*)()>, void );
BOOST_TEST_TRAIT_SAME( invoke_result_t<char(*)(int), char>, char );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int(*)(int, int), int, int>, int );
BOOST_TEST_TRAIT_SAME( invoke_result_t<double(*)(double, double, double), float, float, float>, double );
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, void(*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(*)(int), int, int> ));
// object
BOOST_TEST_TRAIT_SAME( invoke_result_t<F>, void );
BOOST_TEST_TRAIT_SAME( invoke_result_t<F, char>, char );
BOOST_TEST_TRAIT_SAME( invoke_result_t<F, int, int>, int );
BOOST_TEST_TRAIT_SAME( invoke_result_t<F, float, float, float>, double );
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, F, int, int, int, int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, F const> ));
// member function pointer
BOOST_TEST_TRAIT_SAME( invoke_result_t<void(X::*)(), X>, void );
BOOST_TEST_TRAIT_SAME( invoke_result_t<char(X::*)(int), X, char>, char );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int(X::*)(int, int), X, int, int>, int );
BOOST_TEST_TRAIT_SAME( invoke_result_t<double(X::*)(double, double, double), X, float, float, float>, double );
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, void(X::*)()> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, void(X::*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, void(X::*)(), X, int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(X::*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(X::*)(int), int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(X::*)(int), X> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, char(X::*)(int), X, int, int> ));
// member data pointer
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X>, int&& );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X const>, int const&& );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X&>, int& );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X const&>, int const& );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X*>, int& );
BOOST_TEST_TRAIT_SAME( invoke_result_t<int X::*, X const*>, int const& );
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int X::*> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int X::*, int> ));
BOOST_TEST_TRAIT_FALSE(( mp_valid<invoke_result_t, int X::*, X, int> ));
return boost::report_errors();
}

105
test/is_invocable_test.cpp Normal file
View File

@@ -0,0 +1,105 @@
// 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/core/lightweight_test_trait.hpp>
struct F
{
void operator()()
{
}
char operator()( char x1 ) noexcept
{
return x1;
}
int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
double operator()( float x1, float x2, float x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct X
{
};
int main()
{
using boost::compat::is_invocable;
// nonfunction
BOOST_TEST_TRAIT_FALSE(( is_invocable<int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<int, int, int> ));
// function reference
BOOST_TEST_TRAIT_TRUE(( is_invocable<void(&)()> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<char(&)(int), char> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int(&)(int, int), int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<double(&)(double, double, double), float, float, float> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<void(&)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(&)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(&)(int), int, int> ));
// function pointer
BOOST_TEST_TRAIT_TRUE(( is_invocable<void(*)()> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<char(*)(int), char> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int(*)(int, int), int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<double(*)(double, double, double), float, float, float> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<void(*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(*)(int), int, int> ));
// object
BOOST_TEST_TRAIT_TRUE(( is_invocable<F> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<F, char> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<F, int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<F, float, float, float> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<F, int, int, int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<F const> ));
// member function pointer
BOOST_TEST_TRAIT_TRUE(( is_invocable<void(X::*)(), X> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<char(X::*)(int), X, char> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int(X::*)(int, int), X, int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<double(X::*)(double, double, double), X, float, float, float> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<void(X::*)()> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<void(X::*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<void(X::*)(), X, int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(X::*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(X::*)(int), int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(X::*)(int), X> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<char(X::*)(int), X, int, int> ));
// member data pointer
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X const> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X&> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X const&> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X*> ));
BOOST_TEST_TRAIT_TRUE(( is_invocable<int X::*, X const*> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<int X::*> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<int X::*, int> ));
BOOST_TEST_TRAIT_FALSE(( is_invocable<int X::*, X, int> ));
return boost::report_errors();
}

View File

@@ -0,0 +1,143 @@
// 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/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
struct F
{
void operator()()
{
}
char operator()( char x1 ) noexcept
{
return x1;
}
int operator()( int x1, int x2 ) const
{
return 10*x1+x2;
}
double operator()( float x1, float x2, float x3 ) const noexcept
{
return 100*x1 + 10*x2 + x3;
}
};
struct X
{
};
int main()
{
using boost::compat::is_nothrow_invocable;
// nonfunction
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int, int, int> ));
// function reference
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(&)()> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(&)(int), char> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int(&)(int, int), int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<double(&)(double, double, double), float, float, float> ));
#if defined(__cpp_noexcept_function_type)
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<void(&)() noexcept> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<char(&)(int) noexcept, char> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int(&)(int, int) noexcept, int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<double(&)(double, double, double) noexcept, float, float, float> ));
#endif
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(&)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(&)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(&)(int), int, int> ));
// function pointer
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(*)()> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(*)(int), char> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int(*)(int, int), int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<double(*)(double, double, double), float, float, float> ));
#if defined(__cpp_noexcept_function_type)
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<void(*)() noexcept> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<char(*)(int) noexcept, char> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int(*)(int, int) noexcept, int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<double(*)(double, double, double) noexcept, float, float, float> ));
#endif
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(*)(int), int, int> ));
// object
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<F> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<F, int, int> ));
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<F, char> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<F, float, float, float> ));
#endif
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<F, int, int, int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<F const> ));
// member function pointer
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(X::*)(), X> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(X::*)(int), X, char> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int(X::*)(int, int), X, int, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<double(X::*)(double, double, double), X, float, float, float> ));
#if defined(__cpp_noexcept_function_type)
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<void(X::*)() noexcept, X> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<char(X::*)(int) noexcept, X, char> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int(X::*)(int, int) noexcept, X, int, int> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<double(X::*)(double, double, double) noexcept, X, float, float, float> ));
#endif
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(X::*)()> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(X::*)(), int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<void(X::*)(), X, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(X::*)(int)> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(X::*)(int), int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(X::*)(int), X> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<char(X::*)(int), X, int, int> ));
// member data pointer
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X const> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X&> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X const&> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X*> ));
BOOST_TEST_TRAIT_TRUE(( is_nothrow_invocable<int X::*, X const*> ));
#endif
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int X::*> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int X::*, int> ));
BOOST_TEST_TRAIT_FALSE(( is_nothrow_invocable<int X::*, X, int> ));
return boost::report_errors();
}

105
test/mem_fn_md_test.cpp Normal file
View File

@@ -0,0 +1,105 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/compat/mem_fn.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::mem_fn( &X::m )( X() ), -1 );
}
{
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( Y() ), -1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( x ), -1 );
boost::compat::mem_fn( &X::m )( x ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( x ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &x ), -1 );
boost::compat::mem_fn( &X::m )( &x ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &x ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(x) ), -1 );
boost::compat::mem_fn( &X::m )( std::ref(x) ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(x) ), +1 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::cref(x) ), -1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( y ), -1 );
boost::compat::mem_fn( &X::m )( y ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( y ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &y ), -1 );
boost::compat::mem_fn( &X::m )( &y ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &y ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(y) ), -1 );
boost::compat::mem_fn( &X::m )( std::ref(y) ) = +1;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(y) ), +1 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::cref(y) ), -1 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( x ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(x) ), -1 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( y ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( &y ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::m )( std::ref(y) ), -1 );
}
return boost::report_errors();
}

127
test/mem_fn_mfn_test.cpp Normal file
View File

@@ -0,0 +1,127 @@
// 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/mem_fn.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>
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::mem_fn( &X::f0 )( X() ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( X(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( X(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( X(), 1, 2, 3 ), 123 );
}
{
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( Y() ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( Y(), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( Y(), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( Y(), 1, 2, 3 ), 123 );
}
{
X x;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( x ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( &x ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( &x, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( std::ref(x) ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( std::ref(x), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::cref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::cref(x), 1, 2, 3 ), 123 );
}
{
Y y;
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( y ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( &y ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( &y, 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( &y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( &y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f0 )( std::ref(y) ), -1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f1 )( std::ref(y), 1 ), 1 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::ref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::ref(y), 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::cref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::cref(y), 1, 2, 3 ), 123 );
}
{
X const x = {};
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( &x, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( &x, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::ref(x), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::ref(x), 1, 2, 3 ), 123 );
}
{
Y const y = {};
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( &y, 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( &y, 1, 2, 3 ), 123 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f2 )( std::ref(y), 1, 2 ), 12 );
BOOST_TEST_EQ( boost::compat::mem_fn( &X::f3 )( std::ref(y), 1, 2, 3 ), 123 );
}
return boost::report_errors();
}

View File

@@ -3,6 +3,9 @@
// 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>
int main()
{

View File

@@ -1,3 +1,9 @@
// Copyright 2023 Peter Dimov.
// Copyright 2023 Christian Mazakas.
// Copyright 2023 Ed Catmur
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifdef _MSC_VER
#pragma warning(disable: 4530) // C++ exception handler used, but unwing semantics not enabled
#pragma warning(disable: 4577) // noexcept used with no exception handling mode specified