4

I have c++ std::map object like

std::map<std::string, int> data = {{"a",1},{"b",2}};

And I have a string expression consists of the keys in this map:

"(a%2)+2*((b-2)%2)"

All I want to do is to calculate the value of this expression, and the return type should be int. Is there a way to do this? Maybe the boost package could be helpful.

spring cc
  • 867
  • 7
  • 17

1 Answers1

6

ExprTk seems to be what you are looking for, seems simple to use and only requires #include "exprtk.hpp".

This can be done using boost, as show in the answers to this question.

Mor A.
  • 3,045
  • 1
  • 14
  • 18