Add first, second function objects. Fixes #5.

This commit is contained in:
Peter Dimov 2021-10-18 20:57:25 +03:00
parent f8b3099259
commit 7c39436198
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,14 @@ struct subscript
}
};
template<int I> struct get
{
template<class T> decltype(auto) operator()( T&& t ) const
{
return std::get<I>( std::forward<T>(t) );
}
};
} // namespace lambda2_detail
// placeholders
@ -65,6 +73,11 @@ BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_arg<7> _7{};
BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_arg<8> _8{};
BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_arg<9> _9{};
// first, second
BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_detail::get<0> first{};
BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_detail::get<1> second{};
#undef BOOST_LAMBDA2_INLINE_VAR
} // namespace lambda2

View File

@ -63,6 +63,9 @@ int main()
BOOST_TEST_EQ( (_1->*&std::pair<int, int>::first)( x ), 1 );
BOOST_TEST_EQ( (_1->*&std::pair<int, int>::second)( x ), 2 );
BOOST_TEST_EQ( (_1->*first)( x ), 1 );
BOOST_TEST_EQ( (_1->*second)( x ), 2 );
}
return boost::report_errors();