mirror of
https://github.com/boostorg/lambda2.git
synced 2025-05-10 09:43:52 +00:00
Add operator++, operator--
This commit is contained in:
parent
a01d4473ab
commit
bfc742d854
@ -97,6 +97,12 @@ BOOST_LAMBDA2_BINARY_FN(>>, right_shift)
|
|||||||
BOOST_LAMBDA2_UNARY_FN(+, unary_plus)
|
BOOST_LAMBDA2_UNARY_FN(+, unary_plus)
|
||||||
BOOST_LAMBDA2_UNARY_FN(*, dereference)
|
BOOST_LAMBDA2_UNARY_FN(*, dereference)
|
||||||
|
|
||||||
|
BOOST_LAMBDA2_UNARY_FN(++, increment)
|
||||||
|
BOOST_LAMBDA2_UNARY_FN(--, decrement)
|
||||||
|
|
||||||
|
BOOST_LAMBDA2_POSTFIX_FN(++, postfix_increment)
|
||||||
|
BOOST_LAMBDA2_POSTFIX_FN(--, postfix_decrement)
|
||||||
|
|
||||||
// operators
|
// operators
|
||||||
|
|
||||||
template<class T> using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
|
template<class T> using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||||
@ -119,6 +125,13 @@ template<class A, class B> using enable_binary_lambda =
|
|||||||
return std::bind( fn(), std::forward<A>(a) ); \
|
return std::bind( fn(), std::forward<A>(a) ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BOOST_LAMBDA2_POSTFIX_LAMBDA(op, fn) \
|
||||||
|
template<class A, class = lambda2_detail::enable_unary_lambda<A>> \
|
||||||
|
auto operator op( A&& a, int ) \
|
||||||
|
{ \
|
||||||
|
return std::bind( fn(), std::forward<A>(a) ); \
|
||||||
|
}
|
||||||
|
|
||||||
#define BOOST_LAMBDA2_BINARY_LAMBDA(op, fn) \
|
#define BOOST_LAMBDA2_BINARY_LAMBDA(op, fn) \
|
||||||
template<class A, class B, class = lambda2_detail::enable_binary_lambda<A, B>> \
|
template<class A, class B, class = lambda2_detail::enable_binary_lambda<A, B>> \
|
||||||
auto operator op( A&& a, B&& b ) \
|
auto operator op( A&& a, B&& b ) \
|
||||||
@ -159,6 +172,12 @@ BOOST_LAMBDA2_BINARY_LAMBDA(>>, lambda2_detail::right_shift)
|
|||||||
BOOST_LAMBDA2_UNARY_LAMBDA(+, lambda2_detail::unary_plus)
|
BOOST_LAMBDA2_UNARY_LAMBDA(+, lambda2_detail::unary_plus)
|
||||||
BOOST_LAMBDA2_UNARY_LAMBDA(*, lambda2_detail::dereference)
|
BOOST_LAMBDA2_UNARY_LAMBDA(*, lambda2_detail::dereference)
|
||||||
|
|
||||||
|
BOOST_LAMBDA2_UNARY_LAMBDA(++, lambda2_detail::increment)
|
||||||
|
BOOST_LAMBDA2_UNARY_LAMBDA(--, lambda2_detail::decrement)
|
||||||
|
|
||||||
|
BOOST_LAMBDA2_POSTFIX_LAMBDA(++, lambda2_detail::postfix_increment)
|
||||||
|
BOOST_LAMBDA2_POSTFIX_LAMBDA(--, lambda2_detail::postfix_decrement)
|
||||||
|
|
||||||
} // namespace lambda2
|
} // namespace lambda2
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@ -21,3 +21,4 @@ run version.cpp ;
|
|||||||
run lookup_problem.cpp ;
|
run lookup_problem.cpp ;
|
||||||
run dereference.cpp ;
|
run dereference.cpp ;
|
||||||
run placeholders.cpp ;
|
run placeholders.cpp ;
|
||||||
|
run increment.cpp ;
|
||||||
|
34
test/increment.cpp
Normal file
34
test/increment.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2021 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/lambda2.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using namespace boost::lambda2;
|
||||||
|
|
||||||
|
int x1 = 1, x2 = 2, y1 = 1, y2 = 2;
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( (_1++)(x1), y1++ );
|
||||||
|
BOOST_TEST_EQ( (++_1)(x1), ++y1 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( (_1--)(x1), y1-- );
|
||||||
|
BOOST_TEST_EQ( (--_1)(x1), --y1 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( (_1++ + _2++)(x1, x2), y1++ + y2++ );
|
||||||
|
BOOST_TEST_EQ( (++_1 + ++_2)(x1, x2), ++y1 + ++y2 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( (_1-- + _2--)(x1, x2), y1-- + y2-- );
|
||||||
|
BOOST_TEST_EQ( (--_1 + --_2)(x1, x2), --y1 + --y2 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( std::bind(_1 + _2, _1++, _2++)(x1, x2), y1++ + y2++ );
|
||||||
|
BOOST_TEST_EQ( std::bind(_1 + _2, ++_1, ++_2)(x1, x2), ++y1 + ++y2 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( std::bind(_1 + _2, _1--, _2--)(x1, x2), y1-- + y2-- );
|
||||||
|
BOOST_TEST_EQ( std::bind(_1 + _2, --_1, --_2)(x1, x2), --y1 + --y2 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user