I'm creating an expression with exprtk using variables which change constantly.
Do I have to reset and recompile the exprtk::expression
using an updated exprtk::symbol_table
everytime I change the value of a variable?
Or are the updated values evaluated directly by the existing, compiled expression?
#include <iostream>
#include <string>
#include "exprtk.hpp"
int main() {
std::string expression_string = "y := x + 1";
int x = 1;
exprtk::symbol_table<int> symbol_table;
symbol_table.add_variable("x", x);
exprtk::expression<int> expression;
expression.register_symbol_table(symbol_table);
exprtk::parser<int> parser;
if (!parser.compile(expression_string, expression))
{
std::cout << "Compilation error." << std::endl;
return 1;
}
expression.value(); // 1 + 1
x = 2;
// Do I have to create a new symbol_table, expression and parse again?
// Or does the expression evaluate the new value directly?
expression.value(); // 2 + 1?
return 0;
}