C++ Mathematical Expression Toolkit (ExprTk)
release
Toggle main menu visibility
Loading...
Searching...
No Matches
exprtk
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-2025) *
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
26
template
<
typename
T>
27
struct
myfunc
final :
public
exprtk::ifunction
<T>
28
{
29
using
exprtk::ifunction<T>::operator();
30
31
myfunc
()
32
:
exprtk
::
ifunction
<T>(2)
33
{
exprtk::disable_has_side_effects
(*
this
); }
34
35
inline
T
operator()
(
const
T& v1,
const
T& v2)
override
36
{
37
return
T(1) + (v1 * v2) / T(3);
38
}
39
};
40
41
template
<
typename
T>
42
inline
T
myotherfunc
(T v0, T v1, T v2)
43
{
44
return
std::abs(v0 - v1) * v2;
45
}
46
47
template
<
typename
T>
48
void
symbol_table_function_names
()
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
68
int
main
()
69
{
70
symbol_table_function_names<double>
();
71
return
0;
72
}
exprtk::ifunction
Definition
exprtk.hpp:19861
exprtk::ifunction::ifunction
ifunction(const std::size_t &pc)
Definition
exprtk.hpp:19864
exprtk::symbol_table
Definition
exprtk.hpp:20090
exprtk.hpp
myotherfunc
T myotherfunc(T v0, T v1, T v2)
Definition
exprtk_simple_example_05.cpp:42
symbol_table_function_names
void symbol_table_function_names()
Definition
exprtk_symtab_functions.cpp:48
myotherfunc
T myotherfunc(T v0, T v1, T v2)
Definition
exprtk_symtab_functions.cpp:42
main
int main()
Definition
exprtk_symtab_functions.cpp:68
exprtk
Definition
exprtk.hpp:60
exprtk::disable_has_side_effects
void disable_has_side_effects(FunctionType &func)
Definition
exprtk.hpp:19839
myfunc
Definition
exprtk_mpfr_test.cpp:3717
myfunc::operator()
T operator()(const T &v1, const T &v2) override
Definition
exprtk_symtab_functions.cpp:35
myfunc::myfunc
myfunc()
Definition
exprtk_symtab_functions.cpp:31
Generated by
1.17.0