This is a simple, but functional, C++14 lambda library. It takes
advantage of the fact that the standard <functional> header already
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.
#include <boost/lambda2.hpp>
#include <algorithm>
using namespace boost::lambda2;
int count_even( int const * first, int const * last )
{
return std::count_if( first, last, _1 % 2 == 0 );
}-
GCC 5 or later with
-std=c++14or above -
Clang 3.9 or later with
-std=c++14or above -
Visual Studio 2015, 2017, 2019
Tested on Github Actions and Appveyor.