Add dereference

This commit is contained in:
Peter Dimov 2021-06-27 05:26:55 +03:00
parent 882d13e6e4
commit b0bcfff124
3 changed files with 25 additions and 0 deletions

View File

@ -90,6 +90,7 @@ BOOST_LAMBDA2_BINARY_FN(<<, left_shift)
BOOST_LAMBDA2_BINARY_FN(>>, right_shift)
BOOST_LAMBDA2_PREFIX_FN(+, unary_plus)
BOOST_LAMBDA2_PREFIX_FN(*, dereference)
// operators
@ -151,6 +152,7 @@ BOOST_LAMBDA2_BINARY_LAMBDA(<<, lambda2_detail::left_shift)
BOOST_LAMBDA2_BINARY_LAMBDA(>>, lambda2_detail::right_shift)
BOOST_LAMBDA2_UNARY_LAMBDA(+, lambda2_detail::unary_plus)
BOOST_LAMBDA2_UNARY_LAMBDA(*, lambda2_detail::dereference)
} // namespace lambda2
} // namespace boost

View File

@ -19,3 +19,4 @@ run quick.cpp ;
run lambda2_test.cpp ;
run version.cpp ;
run lookup_problem.cpp ;
run dereference.cpp ;

22
test/dereference.cpp Normal file
View File

@ -0,0 +1,22 @@
// 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 x[] = { 1, 2, 3 };
BOOST_TEST_EQ( (*_1)(x+0), *(x+0) );
BOOST_TEST_EQ( (*_1)(x+1), *(x+1) );
BOOST_TEST_EQ( (*_1 + *_2)(x+0, x+1), *(x+0) + *(x+1) );
BOOST_TEST_EQ( (*_1 + *_2 + *_3)(x+0, x+1, x+2), *(x+0) + *(x+1) + *(x+2) );
BOOST_TEST_EQ( std::bind(_1 + _2 + _3, *_1, *_2, *_3)(x+0, x+1, x+2), *(x+0) + *(x+1) + *(x+2) );
return boost::report_errors();
}