@@ -253,8 +253,7 @@ class te_string_less
253253 {
254254 public:
255255 [[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
258257 {
259258 const auto minStrLen = std::min (lhv.length (), rhv.length ());
260259 for (size_t i = 0 ; i < minStrLen; ++i)
@@ -293,7 +292,8 @@ class te_expr
293292 explicit te_expr (const te_variable_flags type) noexcept : m_type(type) {}
294293
295294 // / @private
296- te_expr () noexcept {};
295+ te_expr () noexcept {}
296+
297297 // / @private
298298 te_expr (const te_expr&) = delete ;
299299 // / @private
@@ -319,8 +319,7 @@ class te_variable
319319
320320 // / @private
321321 [[nodiscard]]
322- bool
323- operator <(const te_variable& that) const
322+ bool operator <(const te_variable& that) const
324323 {
325324 return te_string_less{}(m_name, that.m_name );
326325 }
@@ -350,8 +349,23 @@ class te_parser
350349 : m_customFuncsAndVars(that.m_customFuncsAndVars),
351350 m_unknownSymbolResolve (that.m_unknownSymbolResolve),
352351 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)
354354 {
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+ }
355369 }
356370
357371 // / @private
@@ -362,9 +376,26 @@ class te_parser
362376 m_keepResolvedVariables = that.m_keepResolvedVariables ;
363377 m_decimalSeparator = that.m_decimalSeparator ;
364378 m_listSeparator = that.m_listSeparator ;
379+ m_expression = that.m_expression ;
365380
381+ // re-run the expression that was copied over
366382 reset_state ();
367383
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+
368399 return *this ;
369400 }
370401
@@ -914,11 +945,13 @@ class te_parser
914945 }
915946
916947#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 \
918950 { \
919951 return std::holds_alternative<te_fun##n>(var); \
920952 } \
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) \
922955 { \
923956 assert (std::holds_alternative<te_fun##n>(var)); \
924957 return std::get<te_fun##n>(var); \
@@ -941,11 +974,13 @@ class te_parser
941974 }
942975
943976#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 \
945979 { \
946980 return std::holds_alternative<te_confun##n>(var); \
947981 } \
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) \
949984 { \
950985 assert (std::holds_alternative<te_confun##n>(var)); \
951986 return std::get<te_confun##n>(var); \
0 commit comments