diff --git a/doc/lambda2.adoc b/doc/lambda2.adoc index d65c0e9..2ab0cba 100644 --- a/doc/lambda2.adoc +++ b/doc/lambda2.adoc @@ -9,6 +9,7 @@ Peter Dimov :toc: left :toclevels: 4 :idprefix: +:listing-caption: Code Example :docinfo: private-footer :leveloffset: +1 diff --git a/doc/lambda2/changelog.adoc b/doc/lambda2/changelog.adoc index 06e1f1d..2065156 100644 --- a/doc/lambda2/changelog.adoc +++ b/doc/lambda2/changelog.adoc @@ -13,3 +13,4 @@ https://www.boost.org/LICENSE_1_0.txt * Added special cases in `operator<<` and `operator>>` when the first argument is a stream, to allow `std::cout << _1`. * Added `operator\->*`. +* Added `first`, `second`. diff --git a/doc/lambda2/reference.adoc b/doc/lambda2/reference.adoc index d49a6f6..4d249f2 100644 --- a/doc/lambda2/reference.adoc +++ b/doc/lambda2/reference.adoc @@ -90,6 +90,11 @@ template auto operator>>=( A && a, B && b ); template auto operator->*( A && a, B && b ); +// projections + +inline constexpr /unspecified/ first{}; +inline constexpr /unspecified/ second{}; + } // namespace lambda2 } // namespace boost ``` @@ -405,3 +410,26 @@ Returns: :: `std::bind( std::forward(b), std::forward(a) );` Notes: :: This operator is intended to be used with "projection" function objects such as member pointers or member functions taking zero arguments, as in `_1\->*&X::m` or `_1\->*&X::f`. + +### Projections + +``` +inline constexpr /unspecified/ first{}; +``` + +A function object such that `first(x)` returns `std::get<0>(x)`. + +``` +inline constexpr /unspecified/ second{}; +``` + +A function object such that `second(x)` returns `std::get<1>(x)`. + +.Using first and second to print out a map +``` +void print( std::map const & m ) +{ + using namespace boost::lambda2; + std::for_each( m.begin(), m.end(), std::cout << _1->*first << ": " << _1->*second << '\n' ); +} +```