mirror of
https://github.com/boostorg/lambda2.git
synced 2026-01-24 05:52:17 +00:00
Compare commits
5 Commits
feature/op
...
feature/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ff3fef3d1 | ||
|
|
0572e42219 | ||
|
|
7c39436198 | ||
|
|
f8b3099259 | ||
|
|
a666ac4fb6 |
@@ -9,6 +9,7 @@ Peter Dimov
|
|||||||
:toc: left
|
:toc: left
|
||||||
:toclevels: 4
|
:toclevels: 4
|
||||||
:idprefix:
|
:idprefix:
|
||||||
|
:listing-caption: Code Example
|
||||||
:docinfo: private-footer
|
:docinfo: private-footer
|
||||||
|
|
||||||
:leveloffset: +1
|
:leveloffset: +1
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ https://www.boost.org/LICENSE_1_0.txt
|
|||||||
|
|
||||||
* Added special cases in `operator<<` and `operator>>` when
|
* Added special cases in `operator<<` and `operator>>` when
|
||||||
the first argument is a stream, to allow `std::cout << _1`.
|
the first argument is a stream, to allow `std::cout << _1`.
|
||||||
|
* Added `operator\->*`.
|
||||||
|
* Added `first`, `second`.
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ namespace lambda2 {
|
|||||||
template<int I> struct lambda2_arg;
|
template<int I> struct lambda2_arg;
|
||||||
|
|
||||||
inline constexpr lambda2_arg<1> _1{};
|
inline constexpr lambda2_arg<1> _1{};
|
||||||
inline constexpr lambda2_arg<1> _2{};
|
inline constexpr lambda2_arg<2> _2{};
|
||||||
inline constexpr lambda2_arg<1> _3{};
|
inline constexpr lambda2_arg<3> _3{};
|
||||||
inline constexpr lambda2_arg<1> _4{};
|
inline constexpr lambda2_arg<4> _4{};
|
||||||
inline constexpr lambda2_arg<1> _5{};
|
inline constexpr lambda2_arg<5> _5{};
|
||||||
inline constexpr lambda2_arg<1> _6{};
|
inline constexpr lambda2_arg<6> _6{};
|
||||||
inline constexpr lambda2_arg<1> _7{};
|
inline constexpr lambda2_arg<7> _7{};
|
||||||
inline constexpr lambda2_arg<1> _8{};
|
inline constexpr lambda2_arg<8> _8{};
|
||||||
inline constexpr lambda2_arg<1> _9{};
|
inline constexpr lambda2_arg<9> _9{};
|
||||||
|
|
||||||
// arithmetic operators
|
// arithmetic operators
|
||||||
|
|
||||||
@@ -90,6 +90,11 @@ 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 );
|
||||||
|
|
||||||
|
// projections
|
||||||
|
|
||||||
|
inline constexpr /unspecified/ first{};
|
||||||
|
inline constexpr /unspecified/ second{};
|
||||||
|
|
||||||
} // namespace lambda2
|
} // namespace lambda2
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
```
|
```
|
||||||
@@ -405,3 +410,26 @@ Returns: :: `std::bind( std::forward<B>(b), std::forward<A>(a) );`
|
|||||||
Notes: :: This operator is intended to be used with "projection" function
|
Notes: :: This operator is intended to be used with "projection" function
|
||||||
objects such as member pointers or member functions taking zero arguments,
|
objects such as member pointers or member functions taking zero arguments,
|
||||||
as in `_1\->*&X::m` or `_1\->*&X::f`.
|
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<int, std::string> const & m )
|
||||||
|
{
|
||||||
|
using namespace boost::lambda2;
|
||||||
|
std::for_each( m.begin(), m.end(), std::cout << _1->*first << ": " << _1->*second << '\n' );
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -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
|
} // namespace lambda2_detail
|
||||||
|
|
||||||
// placeholders
|
// 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<8> _8{};
|
||||||
BOOST_LAMBDA2_INLINE_VAR constexpr lambda2_arg<9> _9{};
|
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
|
#undef BOOST_LAMBDA2_INLINE_VAR
|
||||||
|
|
||||||
} // namespace lambda2
|
} // namespace lambda2
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST_EQ( (_1->*&std::pair<int, int>::first)( x ), 1 );
|
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->*&std::pair<int, int>::second)( x ), 2 );
|
||||||
|
|
||||||
|
#if defined(_LIBCPP_VERSION)
|
||||||
|
|
||||||
|
// https://bugs.llvm.org/show_bug.cgi?id=51753
|
||||||
|
using std::placeholders::_1;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( (_1->*first)( x ), 1 );
|
||||||
|
BOOST_TEST_EQ( (_1->*second)( x ), 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
|
|||||||
Reference in New Issue
Block a user