C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
exprtk_symtab_functions.cpp
Go to the documentation of this file.
1/*
2 **************************************************************
3 * C++ Mathematical Expression Toolkit Library *
4 * *
5 * ExprTk Symbol Table Function Names Example *
6 * Author: Arash Partow (1999-2024) *
7 * URL: https://www.partow.net/programming/exprtk/index.html *
8 * *
9 * Copyright notice: *
10 * Free use of the Mathematical Expression Toolkit Library is *
11 * permitted under the guidelines and in accordance with the *
12 * most current version of the MIT License. *
13 * https://www.opensource.org/licenses/MIT *
14 * SPDX-License-Identifier: MIT *
15 * *
16 **************************************************************
17*/
18
19
20#include <cstdio>
21#include <string>
22
23#include "exprtk.hpp"
24
25
26template <typename T>
27struct myfunc final : public exprtk::ifunction<T>
28{
29 using exprtk::ifunction<T>::operator();
30
34
35 inline T operator()(const T& v1, const T& v2) override
36 {
37 return T(1) + (v1 * v2) / T(3);
38 }
39};
40
41template <typename T>
42inline T myotherfunc(T v0, T v1, T v2)
43{
44 return std::abs(v0 - v1) * v2;
45}
46
47template <typename T>
49{
50 typedef exprtk::symbol_table<T> symbol_table_t;
51
52 symbol_table_t symbol_table;
53
54 myfunc<T> mf;
55
56 symbol_table.add_function("f1",[](T v0) -> T { return v0;});
57 symbol_table.add_function("f2",[](T v0, T v1) -> T{ return v0 / v1;});
58
59 symbol_table.add_function("myfunc" , mf );
60 symbol_table.add_function("otherfunc", myotherfunc);
61
62 for (const auto& func : symbol_table.get_function_list())
63 {
64 printf("function: %s\n",func.c_str());
65 }
66}
67
68int main()
69{
70 symbol_table_function_names<double>();
71 return 0;
72}
ifunction(const std::size_t &pc)
Definition exprtk.hpp:19545
void symbol_table_function_names()
T myotherfunc(T v0, T v1, T v2)
void disable_has_side_effects(FunctionType &func)
Definition exprtk.hpp:19520
T operator()(const T &v1, const T &v2) override