I have this enum (class)
enum class conditional_operator
{
plus_op,
or_op,
not_op
}
And I’d like a std::map that represents these mappings:
std::map<conditional_operator, std::binary_function<bool,bool,bool>> conditional_map =
{ { conditional_operator::plus_op, std::logical_and<bool> },
{ conditional_operator::or_op, std::logical_or<bool>},
{ conditional_operator::not_op, std::binary_negate<bool>} // this seems fishy too, binary_negate is not really what I want :(
Apart from the fact that this doesn’t compile:
error: expected primary-expression before ‘}’ token
error: expected primary-expression before ‘}’ token
error: expected primary-expression before ‘}’ token
for each of the three lines, how should I do this? I think a logical_not with a second dummy argument would work, once I get this to compile of course…
EDIT: Could I use lambda’s for this?
You really want
std::function<bool(bool, bool)>, notstd::binary_function<bool, bool, bool>. That only exists for typedefs and stuff in C++03. Secondly, I’d just use a lambda- they’re short enough and much clearer. Thestd::logical_andand stuff only exists for C++03 function object creation, and I’d use a lambda over them any day.Wait- what exact operator are you referring to with not? Because that’s unary, as far as I know.