mirror of
https://github.com/boostorg/lambda2.git
synced 2026-01-20 16:42:16 +00:00
Compare commits
6 Commits
boost-1.77
...
boost-1.77
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e2e0a31b3 | ||
|
|
93c67a57c8 | ||
|
|
3bf3ce3a9e | ||
|
|
51b9448ae7 | ||
|
|
a064c3ae83 | ||
|
|
a329989b1e |
1
doc/.gitignore
vendored
1
doc/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/pdf/
|
||||
/html/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,5 +8,5 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Copyright and License
|
||||
:idprefix:
|
||||
|
||||
This documentation is copyright 2020 Peter Dimov and is distributed under
|
||||
This documentation is copyright 2020, 2021 Peter Dimov and is distributed under
|
||||
the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].
|
||||
|
||||
@@ -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
|
||||
////
|
||||
@@ -12,16 +12,18 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
This is a simple, but functional, {cpp}14 lambda library. It takes
|
||||
advantage of the fact that the standard `<functional>` header already
|
||||
provides placeholders `_1`, `_2`, `_3`, and so on, for use with
|
||||
`std::bind`, and function objects such as `std::plus`, `std::greater`,
|
||||
`std::logical_not`, and `std::bit_xor`, corresponding to arithmetic,
|
||||
relational, logical and bitwise operators.
|
||||
provides `std::bind` customization points (`is_placeholder`,
|
||||
`is_bind_expression`), and function objects such as `std::plus`,
|
||||
`std::greater`, `std::logical_not`, and `std::bit_xor`, corresponding
|
||||
to arithmetic, relational, logical and bitwise operators.
|
||||
|
||||
This allows the library to provide a minimal implementation that
|
||||
still lets expressions such as `_1 + 5`, `_1 % 2 == 0`, `_1 > _2`,
|
||||
or `_1 == ' ' || _1 == '\t'` to be composed and used as function
|
||||
objects.
|
||||
|
||||
For example, `_1 + 5` is implemented as `std::bind(std::plus<>, _1, 5)`.
|
||||
|
||||
These "lambda" expressions can also be freely combined with `std::bind`.
|
||||
For example, `std::bind( f, _1 ) == std::bind( g, _1 )` and
|
||||
`std::bind( f, _1 + _2 )` both work and have the expected behavior.
|
||||
@@ -67,5 +69,5 @@ None. A single, self-contained header.
|
||||
* Clang 3.5 or later with `-std=c++14` or above
|
||||
* Visual Studio 2015, 2017, 2019
|
||||
|
||||
Tested on https://travis-ci.org/github/pdimov/lambda2[Travis] and
|
||||
Tested on https://github.com/boostorg/lambda2/actions[Github Actions] and
|
||||
https://ci.appveyor.com/project/pdimov/lambda2[Appveyor].
|
||||
|
||||
@@ -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<int I> 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<class A, class B> auto operator+( A && a, B && b );
|
||||
template<class A, class B> auto operator-( A && a, B && b );
|
||||
template<class A, class B> auto operator*( A && a, B && b );
|
||||
@@ -23,6 +39,8 @@ template<class A, class B> auto operator/( A && a, B && b );
|
||||
template<class A, class B> auto operator%( A && a, B && b );
|
||||
template<class A> auto operator-( A && a );
|
||||
|
||||
// relational operators
|
||||
|
||||
template<class A, class B> auto operator==( A && a, B && b );
|
||||
template<class A, class B> auto operator!=( A && a, B && b );
|
||||
template<class A, class B> auto operator>( A && a, B && b );
|
||||
@@ -30,19 +48,84 @@ template<class A, class B> auto operator<( A && a, B && b );
|
||||
template<class A, class B> auto operator>=( A && a, B && b );
|
||||
template<class A, class B> auto operator<=( A && a, B && b );
|
||||
|
||||
// logical operators
|
||||
|
||||
template<class A, class B> auto operator&&( A && a, B && b );
|
||||
template<class A, class B> auto operator||( A && a, B && b );
|
||||
template<class A> auto operator!( A && a );
|
||||
|
||||
// bitwise operators
|
||||
|
||||
template<class A, class B> auto operator&( A && a, B && b );
|
||||
template<class A, class B> auto operator|( A && a, B && b );
|
||||
template<class A, class B> auto operator^( A && a, B && b );
|
||||
template<class A> auto operator~( A && a );
|
||||
|
||||
template<class A, class B> auto operator<<( A && a, B && b );
|
||||
template<class A, class B> auto operator>>( A && a, B && b );
|
||||
|
||||
// additional unary operators
|
||||
|
||||
template<class A> auto operator+( A && a );
|
||||
template<class A> auto operator*( A && a );
|
||||
template<class A> auto operator++( A && a );
|
||||
template<class A> auto operator--( A && a );
|
||||
template<class A> auto operator++( A && a, int );
|
||||
template<class A> auto operator--( A && a, int );
|
||||
|
||||
// compound assignment operators
|
||||
|
||||
template<class A, class B> auto operator+=( A && a, B && b );
|
||||
template<class A, class B> auto operator-=( A && a, B && b );
|
||||
template<class A, class B> auto operator*=( A && a, B && b );
|
||||
template<class A, class B> auto operator/=( A && a, B && b );
|
||||
template<class A, class B> auto operator%=( A && a, B && b );
|
||||
template<class A, class B> auto operator&=( A && a, B && b );
|
||||
template<class A, class B> auto operator|=( A && a, B && b );
|
||||
template<class A, class B> auto operator^=( A && a, B && b );
|
||||
template<class A, class B> auto operator<<=( A && a, B && b );
|
||||
template<class A, class B> auto operator>>=( A && a, B && b );
|
||||
|
||||
} // namespace lambda2
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
### Placeholders
|
||||
|
||||
```
|
||||
template<int I> struct lambda2_arg
|
||||
{
|
||||
template<class... A> decltype(auto) operator()( A&&... a ) const noexcept;
|
||||
template<class T> auto operator[]( T&& t ) const;
|
||||
};
|
||||
```
|
||||
|
||||
`lambda2_arg<I>` 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<class... A> decltype(auto) operator()( A&&... a ) const noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `std::get<std::size_t{I-1}>( std::tuple<A&&...>( std::forward<A>(a)... ) );`
|
||||
|
||||
```
|
||||
template<class T> auto operator[]( T&& t ) const;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `std::bind( fn, *this, std::forward<T>(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<class A> auto operator~( A && a );
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( std::bit_not<>(), std::forward<A>(a) );`
|
||||
|
||||
```
|
||||
template<class A, class B> auto operator<<( A && a, B && b );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `std::bind( fn, std::forward<A>(a), std::forward<B>(b) );`,
|
||||
where `fn` is a function object such that `fn(x, y)` returns `x << y`.
|
||||
|
||||
```
|
||||
template<class A, class B> auto operator>>( A && a, B && b );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `std::bind( fn, std::forward<A>(a), std::forward<B>(b) );`,
|
||||
where `fn` is a function object such that `fn(x, y)` returns `x >> y`.
|
||||
|
||||
### Additional Unary Operators
|
||||
|
||||
```
|
||||
template<class A> auto operator+( A && a );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `+x`.
|
||||
|
||||
```
|
||||
template<class A> auto operator*( A && a );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `*x`.
|
||||
|
||||
```
|
||||
template<class A> auto operator++( A && a );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `++x`.
|
||||
|
||||
```
|
||||
template<class A> auto operator--( A && a );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `--x`.
|
||||
|
||||
```
|
||||
template<class A> auto operator++( A && a, int );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `x++`.
|
||||
|
||||
```
|
||||
template<class A> auto operator--( A && a, int );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: ::
|
||||
`std::bind( fn, std::forward<A>(a) );`, where `fn` is a function object
|
||||
such that `fn(x)` returns `x--`.
|
||||
|
||||
### Compound Assignment Operators
|
||||
|
||||
```
|
||||
template<class A, class B> auto operator@=( A && a, B && b );
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Returns: :: `std::bind( fn, std::forward<A>(a), std::forward<B>(b) );`,
|
||||
where `fn` is a function object such that `fn(x, y)` returns `x @= y`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef BOOST_LAMBDA2_LAMBDA2_HPP_INCLUDED
|
||||
#define BOOST_LAMBDA2_LAMBDA2_HPP_INCLUDED
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user