File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1153,6 +1153,29 @@ public:
1153
1153
}
1154
1154
}
1155
1155
1156
+ /*
1157
+ * \brief Evaluate given string as math expression
1158
+ *
1159
+ * For unknown symbols, ParmParse database will be queried.
1160
+ */
1161
+ template <typename T, std::enable_if_t <std::is_same_v<T,int > ||
1162
+ std::is_same_v<T,long > ||
1163
+ std::is_same_v<T,long long > ||
1164
+ std::is_same_v<T,float > ||
1165
+ std::is_same_v<T,double >,int > = 0 >
1166
+ T eval (std::string const & expr) const
1167
+ {
1168
+ if constexpr (std::is_integral_v<T>) {
1169
+ auto const parser = this ->makeIParser (expr, {});
1170
+ auto const exe = parser.compileHost <0 >();
1171
+ return static_cast <T>(exe ()); // In the future, we might add safety check.
1172
+ } else {
1173
+ auto const parser = this ->makeParser (expr, {});
1174
+ auto const exe = parser.compileHost <0 >();
1175
+ return static_cast <T>(exe ());
1176
+ }
1177
+ }
1178
+
1156
1179
/*
1157
1180
* \brief Query two names.
1158
1181
*
You can’t perform that action at this time.
0 commit comments