@@ -253,8 +253,7 @@ class te_string_less
253
253
{
254
254
public:
255
255
[[nodiscard]]
256
- bool
257
- operator ()(const std::string& lhv, const std::string& rhv) const
256
+ bool operator ()(const std::string& lhv, const std::string& rhv) const
258
257
{
259
258
const auto minStrLen = std::min (lhv.length (), rhv.length ());
260
259
for (size_t i = 0 ; i < minStrLen; ++i)
@@ -293,7 +292,8 @@ class te_expr
293
292
explicit te_expr (const te_variable_flags type) noexcept : m_type(type) {}
294
293
295
294
// / @private
296
- te_expr () noexcept {};
295
+ te_expr () noexcept {}
296
+
297
297
// / @private
298
298
te_expr (const te_expr&) = delete ;
299
299
// / @private
@@ -319,8 +319,7 @@ class te_variable
319
319
320
320
// / @private
321
321
[[nodiscard]]
322
- bool
323
- operator <(const te_variable& that) const
322
+ bool operator <(const te_variable& that) const
324
323
{
325
324
return te_string_less{}(m_name, that.m_name );
326
325
}
@@ -350,8 +349,23 @@ class te_parser
350
349
: m_customFuncsAndVars(that.m_customFuncsAndVars),
351
350
m_unknownSymbolResolve (that.m_unknownSymbolResolve),
352
351
m_keepResolvedVariables(that.m_keepResolvedVariables),
353
- m_decimalSeparator(that.m_decimalSeparator), m_listSeparator(that.m_listSeparator)
352
+ m_decimalSeparator(that.m_decimalSeparator), m_listSeparator(that.m_listSeparator),
353
+ m_expression(that.m_expression)
354
354
{
355
+ try
356
+ {
357
+ if (!m_expression.empty ())
358
+ {
359
+ [[maybe_unused]]
360
+ const auto retVal = evaluate (m_expression);
361
+ }
362
+ }
363
+ catch (const std::exception& expt)
364
+ {
365
+ m_parseSuccess = false ;
366
+ m_result = te_nan;
367
+ m_lastErrorMessage = expt.what ();
368
+ }
355
369
}
356
370
357
371
// / @private
@@ -362,9 +376,26 @@ class te_parser
362
376
m_keepResolvedVariables = that.m_keepResolvedVariables ;
363
377
m_decimalSeparator = that.m_decimalSeparator ;
364
378
m_listSeparator = that.m_listSeparator ;
379
+ m_expression = that.m_expression ;
365
380
381
+ // re-run the expression that was copied over
366
382
reset_state ();
367
383
384
+ try
385
+ {
386
+ if (!m_expression.empty ())
387
+ {
388
+ [[maybe_unused]]
389
+ const auto retVal = evaluate (m_expression);
390
+ }
391
+ }
392
+ catch (const std::exception& expt)
393
+ {
394
+ m_parseSuccess = false ;
395
+ m_result = te_nan;
396
+ m_lastErrorMessage = expt.what ();
397
+ }
398
+
368
399
return *this ;
369
400
}
370
401
@@ -914,11 +945,13 @@ class te_parser
914
945
}
915
946
916
947
#define TE_DEF_FUNCTION (n ) \
917
- [[nodiscard]] constexpr static bool is_function##n(const te_variant_type& var) noexcept \
948
+ [[nodiscard]] \
949
+ constexpr static bool is_function##n(const te_variant_type& var) noexcept \
918
950
{ \
919
951
return std::holds_alternative<te_fun##n>(var); \
920
952
} \
921
- [[nodiscard]] constexpr static te_fun##n get_function##n(const te_variant_type& var) \
953
+ [[nodiscard]] \
954
+ constexpr static te_fun##n get_function##n(const te_variant_type& var) \
922
955
{ \
923
956
assert (std::holds_alternative<te_fun##n>(var)); \
924
957
return std::get<te_fun##n>(var); \
@@ -941,11 +974,13 @@ class te_parser
941
974
}
942
975
943
976
#define TE_DEF_CLOSURE (n ) \
944
- [[nodiscard]] constexpr static bool is_closure##n(const te_variant_type& var) noexcept \
977
+ [[nodiscard]] \
978
+ constexpr static bool is_closure##n(const te_variant_type& var) noexcept \
945
979
{ \
946
980
return std::holds_alternative<te_confun##n>(var); \
947
981
} \
948
- [[nodiscard]] constexpr static te_confun##n get_closure##n(const te_variant_type& var) \
982
+ [[nodiscard]] \
983
+ constexpr static te_confun##n get_closure##n(const te_variant_type& var) \
949
984
{ \
950
985
assert (std::holds_alternative<te_confun##n>(var)); \
951
986
return std::get<te_confun##n>(var); \
0 commit comments