Add operator() to placeholders

This commit is contained in:
Peter Dimov 2021-06-27 12:16:17 +03:00
parent bfc742d854
commit 07c965a088
2 changed files with 25 additions and 0 deletions

View File

@ -8,6 +8,8 @@
#include <functional> #include <functional>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <tuple>
#include <cstddef>
// Same format as BOOST_VERSION: // Same format as BOOST_VERSION:
// major * 100000 + minor * 100 + patch // major * 100000 + minor * 100 + patch
@ -22,6 +24,10 @@ namespace lambda2
template<int I> struct lambda2_arg template<int I> struct lambda2_arg
{ {
template<class... A> decltype(auto) operator()( A&&... a ) const noexcept
{
return std::get<std::size_t{I-1}>( std::tuple<A&&...>( std::forward<A>(a)... ) );
}
}; };
#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L #if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L

View File

@ -25,5 +25,24 @@ int main()
BOOST_TEST_EQ( std::bind(f, _8)( 1, 2, 3, 4, 5, 6, 7, 8 ), 8 ); BOOST_TEST_EQ( std::bind(f, _8)( 1, 2, 3, 4, 5, 6, 7, 8 ), 8 );
BOOST_TEST_EQ( std::bind(f, _9)( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 9 ); BOOST_TEST_EQ( std::bind(f, _9)( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 9 );
BOOST_TEST_EQ( _1( 1 ), 1 );
BOOST_TEST_EQ( _2( 1, 2 ), 2 );
BOOST_TEST_EQ( _3( 1, 2, 3 ), 3 );
BOOST_TEST_EQ( _4( 1, 2, 3, 4 ), 4 );
BOOST_TEST_EQ( _5( 1, 2, 3, 4, 5 ), 5 );
BOOST_TEST_EQ( _6( 1, 2, 3, 4, 5, 6 ), 6 );
BOOST_TEST_EQ( _7( 1, 2, 3, 4, 5, 6, 7 ), 7 );
BOOST_TEST_EQ( _8( 1, 2, 3, 4, 5, 6, 7, 8 ), 8 );
BOOST_TEST_EQ( _9( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 9 );
BOOST_TEST_EQ( _1( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1 );
BOOST_TEST_EQ( _2( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 2 );
BOOST_TEST_EQ( _3( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 3 );
BOOST_TEST_EQ( _4( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 4 );
BOOST_TEST_EQ( _5( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 5 );
BOOST_TEST_EQ( _6( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 6 );
BOOST_TEST_EQ( _7( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 7 );
BOOST_TEST_EQ( _8( 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 8 );
return boost::report_errors(); return boost::report_errors();
} }