Emmanuel Hadoux Emmanuel Hadoux - 1 year ago 34
C++ Question

C++14 Functional logical_not on functions

I have a logical expression, let's say

!a & b
However, instead of evaluating this expression, I would like to build a functional tree and defer the evaluation to later.
The values of
are computed using a function
so we have:

auto value_of_a = std::bind(value, _1); //I need an additional argument
auto value_of_b = std::bind(value, _1);

I would like to use
instead of using my own lambdas. However, they call a direct operator on the argument (for instance
Therefore I cannot use something like:

auto v = std::bind(logical_not, value_of_a); //And we still need the first argument
//to call value_of_a

Can I bind the result (like some sort of Future) instead of the function?

I am trying to use as much already defined functions as possible for the sake of readability.
I am using C++14 but those are defined in C++11.

I am aware that using lambdas may be the easiest way, but I am trying to leverage as much as I can what already exists. However, I will fall back to them if the solution is not really better.

Thanks, hope it is clear enough.

Answer Source
              std::bind(std::logical_not<>{}, value_of_a),
              std::bind(value_of_b, std::placeholders::_2));

Provided that value_of_a is a bind expression, the above code is equivalent to:

( not value_of_a(#1) ) and ( value_of_b(#2) )