forked from boostorg/bind
Compare commits
4 Commits
feature/st
...
boost-1.76
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12e2ca325d | ||
|
|
1e3efb361b | ||
|
|
bb50844171 | ||
|
|
ee25007a9f |
@@ -11,6 +11,8 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -18,6 +20,15 @@ template<class R> struct apply
|
|||||||
{
|
{
|
||||||
typedef R result_type;
|
typedef R result_type;
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||||
|
|
||||||
|
template<class F, class... A> result_type operator()( F&& f, A&&... a ) const
|
||||||
|
{
|
||||||
|
return static_cast<F&&>( f )( static_cast<A&&>( a )... );
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
template<class F> result_type operator()(F & f) const
|
template<class F> result_type operator()(F & f) const
|
||||||
{
|
{
|
||||||
return f();
|
return f();
|
||||||
@@ -67,6 +78,8 @@ template<class R> struct apply
|
|||||||
{
|
{
|
||||||
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|||||||
@@ -79,3 +79,7 @@ run protect_test2.cpp ;
|
|||||||
run protect_cpp20_test.cpp ;
|
run protect_cpp20_test.cpp ;
|
||||||
run bind_noexcept_mf2_test.cpp ;
|
run bind_noexcept_mf2_test.cpp ;
|
||||||
run std_placeholders_test.cpp ;
|
run std_placeholders_test.cpp ;
|
||||||
|
run apply_test.cpp ;
|
||||||
|
run apply_test2.cpp ;
|
||||||
|
run apply_rv_test.cpp ;
|
||||||
|
run apply_rv_test2.cpp ;
|
||||||
|
|||||||
77
test/apply_rv_test.cpp
Normal file
77
test/apply_rv_test.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2021 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include<boost/bind/apply.hpp>
|
||||||
|
#include<boost/bind/bind.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/config/pragma_message.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
struct F
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
int operator()( int & x ) const
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int operator()( int && x ) const
|
||||||
|
{
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int& get_lvalue_arg()
|
||||||
|
{
|
||||||
|
static int a = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_prvalue_arg()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
F& get_lvalue_f()
|
||||||
|
{
|
||||||
|
static F f;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
F get_prvalue_f()
|
||||||
|
{
|
||||||
|
return F();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using namespace boost::placeholders;
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_lvalue_arg))(), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_prvalue_arg))(), -2 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_lvalue_arg))(), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_prvalue_arg))(), -2 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int&>(), _2))(get_lvalue_f, get_lvalue_arg), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int>(), _2))(get_lvalue_f, get_prvalue_arg), -2 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int&>(), _2))(get_prvalue_f, get_lvalue_arg), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int>(), _2))(get_prvalue_f, get_prvalue_arg), -2 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
92
test/apply_rv_test2.cpp
Normal file
92
test/apply_rv_test2.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
// Copyright 2021 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include<boost/bind/apply.hpp>
|
||||||
|
#include<boost/bind/bind.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/config/pragma_message.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#elif defined(BOOST_NO_CXX11_REF_QUALIFIERS)
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_REF_QUALIFIERS is defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
struct F
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
int operator()( int & x ) &
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int operator()( int && x ) &
|
||||||
|
{
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int operator()( int & x ) &&
|
||||||
|
{
|
||||||
|
return x + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int operator()( int && x ) &&
|
||||||
|
{
|
||||||
|
return -x - 10;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int& get_lvalue_arg()
|
||||||
|
{
|
||||||
|
static int a = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_prvalue_arg()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
F& get_lvalue_f()
|
||||||
|
{
|
||||||
|
static F f;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
F get_prvalue_f()
|
||||||
|
{
|
||||||
|
return F();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using namespace boost::placeholders;
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_lvalue_arg))(), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_lvalue_f), boost::bind(get_prvalue_arg))(), -2 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_lvalue_arg))(), 11 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(get_prvalue_f), boost::bind(get_prvalue_arg))(), -12 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int&>(), _2))(get_lvalue_f, get_lvalue_arg), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F&>(), _1), boost::bind(boost::apply<int>(), _2))(get_lvalue_f, get_prvalue_arg), -2 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int&>(), _2))(get_prvalue_f, get_lvalue_arg), 11 );
|
||||||
|
BOOST_TEST_EQ( boost::bind(boost::apply<int>(), boost::bind(boost::apply<F>(), _1), boost::bind(boost::apply<int>(), _2))(get_prvalue_f, get_prvalue_arg), -12 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
29
test/apply_test.cpp
Normal file
29
test/apply_test.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2021 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/bind/apply.hpp>
|
||||||
|
#include <boost/bind/protect.hpp>
|
||||||
|
#include <boost/bind/bind.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
using namespace boost::placeholders;
|
||||||
|
|
||||||
|
int f( int x )
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _1 ) ), 1 )(), 1 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _2 ) ), 1, 2 )(), 2 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _3 ) ), 1, 2, 3 )(), 3 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _4 ) ), 1, 2, 3, 4 )(), 4 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _5 ) ), 1, 2, 3, 4, 5 )(), 5 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _6 ) ), 1, 2, 3, 4, 5, 6 )(), 6 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _7 ) ), 1, 2, 3, 4, 5, 6, 7 )(), 7 );
|
||||||
|
BOOST_TEST_EQ( boost::bind( boost::apply<int>(), boost::protect( boost::bind( f, _8 ) ), 1, 2, 3, 4, 5, 6, 7, 8 )(), 8 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
15
test/apply_test2.cpp
Normal file
15
test/apply_test2.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2021 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/bind/apply.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <boost/core/is_same.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void, boost::apply<void>::result_type>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int&, boost::apply<int&>::result_type>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user