From 93c67a57c8769e45d77b333c5fa876f31175de04 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 11 Jul 2021 16:51:40 +0300 Subject: [PATCH] Update reference --- doc/lambda2/reference.adoc | 176 ++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/doc/lambda2/reference.adoc b/doc/lambda2/reference.adoc index a9338b1..fc0c24b 100644 --- a/doc/lambda2/reference.adoc +++ b/doc/lambda2/reference.adoc @@ -1,5 +1,5 @@ //// -Copyright 2020 Peter Dimov +Copyright 2020, 2021 Peter Dimov Distributed under the Boost Software License, Version 1.0. https://www.boost.org/LICENSE_1_0.txt //// @@ -16,6 +16,22 @@ https://www.boost.org/LICENSE_1_0.txt namespace boost { namespace lambda2 { +// placeholders + +template struct lambda2_arg; + +inline constexpr lambda2_arg<1> _1{}; +inline constexpr lambda2_arg<1> _2{}; +inline constexpr lambda2_arg<1> _3{}; +inline constexpr lambda2_arg<1> _4{}; +inline constexpr lambda2_arg<1> _5{}; +inline constexpr lambda2_arg<1> _6{}; +inline constexpr lambda2_arg<1> _7{}; +inline constexpr lambda2_arg<1> _8{}; +inline constexpr lambda2_arg<1> _9{}; + +// arithmetic operators + template auto operator+( A && a, B && b ); template auto operator-( A && a, B && b ); template auto operator*( A && a, B && b ); @@ -23,6 +39,8 @@ 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 ); @@ -30,19 +48,84 @@ 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 ); + } // 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 @@ -214,3 +297,94 @@ template auto operator~( A && a ); + 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`.