I can't seem to get a vector output from exprTk. I figure it should be relatively simple but in the manual I can only find how to input a vector and not how to output one.
What I currently have is the following:
typedef double T; // numeric type (float, double, mpfr etc...)
typedef exprtk::symbol_table<T> symbol_table_t;
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
std::string expression_string = "var z[2] := { x, y };";
T x = T(5.3);
T y = T(2.3);
std::vector<T> z;
symbol_table_t symbol_table;
symbol_table.add_variable("x", x);
symbol_table.add_variable("y", y);
symbol_table.add_vector("z", z);
expression_t expression;
expression.register_symbol_table(symbol_table);
//Check if expression is valid
parser_t parser;
if (!parser.compile(expression_string, expression))
{
printf("Compilation error...\n");
return;
}
T result = expression.value();
std::cout << result << std::endl; \\returns: 5.3 as expected the first element of vector z.
std::cout << z[0] << std::endl; \\Crashes the program
What I want as output is just the vector z. How do I do this, or what am I doing wrong?