C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Classes | Functions
exprtk_simple_example_20.cpp File Reference
#include <cstdio>
#include <stdexcept>
#include <map>
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_simple_example_20.cpp:

Go to the source code of this file.

Classes

struct  vector_access_rtc
 

Functions

template<typename T >
void vector_overflow_example ()
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 105 of file exprtk_simple_example_20.cpp.

106{
107 vector_overflow_example<double>();
108 return 0;
109}

◆ vector_overflow_example()

template<typename T >
void vector_overflow_example ( )

Definition at line 55 of file exprtk_simple_example_20.cpp.

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}

References vector_access_rtc::vector_map.