MCPcopy Create free account
hub / github.com/ArashPartow/exprtk / vector_overflow_example

Function vector_overflow_example

exprtk_simple_example_20.cpp:55–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54template <typename T>
55void vector_overflow_example()
56{
57 typedef exprtk::symbol_table<T> symbol_table_t;
58 typedef exprtk::expression<T> expression_t;
59 typedef exprtk::parser<T> parser_t;
60
61 const std::string expression_str =
62 " for (var i := 0; i < max(v0[],v1[]); i += 1) "
63 " { "
64 " v0[i] := (2 * v0[i]) + (v1[i] / 3); "
65 " } ";
66
67 T v0[5 ] = { 0, 1, 2, 3, 4 };
68 T v1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
69
70 vector_access_rtc vec_rtc;
71
72 vec_rtc.vector_map[v0] = "v0";
73 vec_rtc.vector_map[v1] = "v1";
74
75 symbol_table_t symbol_table;
76 expression_t expression;
77 parser_t parser;
78
79 symbol_table.add_vector("v0", v0);
80 symbol_table.add_vector("v1", v1);
81
82 expression.register_symbol_table(symbol_table);
83
84 parser.register_vector_access_runtime_check(vec_rtc);
85
86 try
87 {
88 if (!parser.compile(expression_str, expression))
89 {
90 printf("Error: %s\tExpression: %s\n",
91 parser.error().c_str(),
92 expression_str.c_str());
93
94 return;
95 }
96
97 expression.value();
98 }
99 catch(std::runtime_error& exception)
100 {
101 printf("Exception: %s\n",exception.what());
102 }
103}
104
105int main()
106{

Callers

nothing calls this directly

Calls 1

valueMethod · 0.45

Tested by

no test coverage detected