How to use exprtk to evaluate an equasion as bool?
Asked Answered
D

1

6

I'm trying to run this code:

exprtk::parser<bool> parser;
exprtk::expression<bool> expression;
parser.compile("5 > 6", expression);
std::cout << expression.value() << "\n";

But I get this error:

'exprtk::expression<T>::operator T(void) const': member function already defined or declared

On VS 2019. This doesn't happen when I use other data types. Is this a bug or am I doing something wrong?

Darnall answered 23/6, 2021 at 16:47 Comment(0)
E
10

From the documentation:

exprtk::expression<NumericType>

Note: NumericType can be any floating point type. This includes but is not limited to: float, double, long double, MPFR or any custom type conforming to an interface compatible with the standard floating point type.

bool is not a floating-point type.

Educt answered 23/6, 2021 at 16:55 Comment(2)
I see, so the only way would be to see if the result is non-zero?Darnall
@GameBoss9000, 5 > 6 return 0, and 6 > 5 returns 1. I think the library converts true to 1, and false to 0.Hildahildagard

© 2022 - 2024 — McMap. All rights reserved.