diff --git a/include/boost/lambda2/lambda2.hpp b/include/boost/lambda2/lambda2.hpp index ba72493..77eee9a 100644 --- a/include/boost/lambda2/lambda2.hpp +++ b/include/boost/lambda2/lambda2.hpp @@ -18,6 +18,8 @@ namespace boost namespace lambda2 { +// placeholders + template struct lambda2_arg { }; @@ -55,6 +57,40 @@ namespace lambda2 namespace lambda2_detail { +// additional function objects + +#define BOOST_LAMBDA2_PREFIX_FN(op, fn) \ + struct fn \ + { \ + template decltype(auto) operator()(T&& t) const \ + { \ + return op std::forward(t); \ + } \ + }; + +#define BOOST_LAMBDA2_POSTFIX_FN(op, fn) \ + struct fn \ + { \ + template decltype(auto) operator()(T&& t) const \ + { \ + return std::forward(t) op; \ + } \ + }; + +#define BOOST_LAMBDA2_BINARY_FN(op, fn) \ + struct fn \ + { \ + template decltype(auto) operator()(T1&& t1, T2&& t2) const \ + { \ + return std::forward(t1) op std::forward(t2); \ + } \ + }; + +BOOST_LAMBDA2_BINARY_FN(<<, left_shift) +BOOST_LAMBDA2_BINARY_FN(>>, right_shift) + +// operators + template using remove_cvref_t = std::remove_cv_t>; template> using is_lambda_expression = @@ -82,6 +118,8 @@ template using enable_binary_lambda = return std::bind( fn(), std::forward(a), std::forward(b) ); \ } +// standard + BOOST_LAMBDA2_BINARY_LAMBDA(+, std::plus<>) BOOST_LAMBDA2_BINARY_LAMBDA(-, std::minus<>) BOOST_LAMBDA2_BINARY_LAMBDA(*, std::multiplies<>) @@ -105,6 +143,11 @@ BOOST_LAMBDA2_BINARY_LAMBDA(|, std::bit_or<>) BOOST_LAMBDA2_BINARY_LAMBDA(^, std::bit_xor<>) BOOST_LAMBDA2_UNARY_LAMBDA(~, std::bit_not<>) +// additional + +BOOST_LAMBDA2_BINARY_LAMBDA(<<, lambda2_detail::left_shift) +BOOST_LAMBDA2_BINARY_LAMBDA(>>, lambda2_detail::right_shift) + } // namespace lambda2 } // namespace boost diff --git a/test/lambda2_test.cpp b/test/lambda2_test.cpp index c3c85f4..b4e4e73 100644 --- a/test/lambda2_test.cpp +++ b/test/lambda2_test.cpp @@ -2,6 +2,10 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) && _MSC_VER == 1900 +# pragma warning(disable: 4552) // '<<': operator has no effect; expected operator with side-effect +#endif + #include #include @@ -56,5 +60,8 @@ int main() #endif + TEST_BINARY(<<) + TEST_BINARY(>>) + return boost::report_errors(); }