//// Copyright 2020, 2021 Peter Dimov Distributed under the Boost Software License, Version 1.0. https://www.boost.org/LICENSE_1_0.txt //// [#reference] # Reference :idprefix: ref_ ## ### Synopsis ``` namespace boost { namespace lambda2 { // placeholders template struct lambda2_arg; inline constexpr lambda2_arg<1> _1{}; inline constexpr lambda2_arg<2> _2{}; inline constexpr lambda2_arg<3> _3{}; inline constexpr lambda2_arg<4> _4{}; inline constexpr lambda2_arg<5> _5{}; inline constexpr lambda2_arg<6> _6{}; inline constexpr lambda2_arg<7> _7{}; inline constexpr lambda2_arg<8> _8{}; inline constexpr lambda2_arg<9> _9{}; // arithmetic operators template auto operator+( A && a, B && b ); template auto operator-( A && a, B && b ); template auto operator*( A && a, B && b ); template auto operator/( A && a, B && b ); template auto operator%( A && a, B && b ); template auto operator-( A && a ); // relational operators template auto operator==( A && a, B && b ); template auto operator!=( A && a, B && b ); template auto operator>( A && a, B && b ); template auto operator<( A && a, B && b ); template auto operator>=( A && a, B && b ); template auto operator<=( A && a, B && b ); // logical operators template auto operator&&( A && a, B && b ); template auto operator||( A && a, B && b ); template auto operator!( A && a ); // bitwise operators template auto operator&( A && a, B && b ); template auto operator|( A && a, B && b ); template auto operator^( A && a, B && b ); template auto operator~( A && a ); template auto operator<<( A && a, B && b ); template auto operator>>( A && a, B && b ); // additional unary operators template auto operator+( A && a ); template auto operator*( A && a ); template auto operator++( A && a ); template auto operator--( A && a ); template auto operator++( A && a, int ); template auto operator--( A && a, int ); // compound assignment operators template auto operator+=( A && a, B && b ); template auto operator-=( A && a, B && b ); template auto operator*=( A && a, B && b ); template auto operator/=( A && a, B && b ); template auto operator%=( A && a, B && b ); template auto operator&=( A && a, B && b ); template auto operator|=( A && a, B && b ); template auto operator^=( A && a, B && b ); template auto operator<<=( A && a, B && b ); template auto operator>>=( A && a, B && b ); // additional binary operators template auto operator->*( A && a, B && b ); // projections inline constexpr /unspecified/ first{}; inline constexpr /unspecified/ second{}; } // namespace lambda2 } // namespace boost ``` ### Placeholders ``` template struct lambda2_arg { template decltype(auto) operator()( A&&... a ) const noexcept; template auto operator[]( T&& t ) const; }; ``` `lambda2_arg` is the type of the library-provided placeholders `_I`. The standard customization point `std::is_placeholder` is specialized for it, enabling the use of Lambda2's placeholders with `std::bind`. The placeholders define `operator()`, which permits their direct use as function objects. E.g. `_1(x, y)` returns `x`. `operator[]` is also defined to allow expressions like `_1[x]` or `_1[_2]`. ``` template decltype(auto) operator()( A&&... a ) const noexcept; ``` [none] * {blank} + Returns: :: `std::get( std::tuple( std::forward(a)... ) );` ``` template auto operator[]( T&& t ) const; ``` [none] * {blank} + Returns: :: `std::bind( fn, *this, std::forward(t) );`, where `fn` is a function object such that `fn(x, y)` returns `x[y]`. ### Common Requirements All operators defined in the subsequent sections only participate in overload resolution if at least one of their operands is such that for its unqualified type `T`, the expression `std::is_placeholder::value || std::is_bind_expression::value` is `true`. ### Arithmetic Operators ``` template auto operator+( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::plus<>(), std::forward(a), std::forward(b) );` ``` template auto operator-( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::minus<>(), std::forward(a), std::forward(b) );` ``` template auto operator*( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::multiplies<>(), std::forward(a), std::forward(b) );` ``` template auto operator/( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::divides<>(), std::forward(a), std::forward(b) );` ``` template auto operator%( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::modulus<>(), std::forward(a), std::forward(b) );` ``` template auto operator-( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( std::negate<>(), std::forward(a) );` ### Relational Operators ``` template auto operator==( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::equal_to<>(), std::forward(a), std::forward(b) );` ``` template auto operator!=( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::not_equal_to<>(), std::forward(a), std::forward(b) );` ``` template auto operator>( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::greater<>(), std::forward(a), std::forward(b) );` ``` template auto operator<( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::less<>(), std::forward(a), std::forward(b) );` ``` template auto operator>=( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::greater_equal<>(), std::forward(a), std::forward(b) );` ``` template auto operator<=( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::less_equal<>(), std::forward(a), std::forward(b) );` ### Logical Operators ``` template auto operator&&( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::logical_and<>(), std::forward(a), std::forward(b) );` ``` template auto operator||( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::logical_or<>(), std::forward(a), std::forward(b) );` ``` template auto operator!( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( std::logical_not<>(), std::forward(a) );` ### Bitwise Operators ``` template auto operator&( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::bit_and<>(), std::forward(a), std::forward(b) );` ``` template auto operator|( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::bit_or<>(), std::forward(a), std::forward(b) );` ``` template auto operator^( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( std::bit_xor<>(), std::forward(a), std::forward(b) );` ``` template auto operator~( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( std::bit_not<>(), std::forward(a) );` ``` template auto operator<<( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a), std::forward(b) );`, where `fn` is a function object such that `fn(x, y)` returns `x << y`. ``` template auto operator>>( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a), std::forward(b) );`, where `fn` is a function object such that `fn(x, y)` returns `x >> y`. ### Additional Unary Operators ``` template auto operator+( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `+x`. ``` template auto operator*( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `*x`. ``` template auto operator++( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `++x`. ``` template auto operator--( A && a ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `--x`. ``` template auto operator++( A && a, int ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `x++`. ``` template auto operator--( A && a, int ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a) );`, where `fn` is a function object such that `fn(x)` returns `x--`. ### Compound Assignment Operators ``` template auto operator@=( A && a, B && b ); ``` [none] * {blank} + Returns: :: `std::bind( fn, std::forward(a), std::forward(b) );`, where `fn` is a function object such that `fn(x, y)` returns `x @= y`. ### Additional Binary Operators ``` template auto operator->*( A && a, B && b ); ``` [none] * {blank} + 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' ); } ```