Skip to content

Commit

Permalink
GUI2/Typed Formula: made use of std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jan 26, 2021
1 parent 3757f2c commit 26426ea
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/gui/auxiliary/typed_formula.hpp
Expand Up @@ -25,6 +25,7 @@
#include "tstring.hpp"

#include <cassert>
#include <optional>

namespace gui2
{
Expand Down Expand Up @@ -93,7 +94,7 @@ class typed_formula
/** Determine whether the class contains a formula. */
bool has_formula() const
{
return !formula_.empty();
return formula_.has_value();
}

private:
Expand Down Expand Up @@ -123,9 +124,9 @@ class typed_formula
/**
* Contains the formula for the variable.
*
* If the string is empty, there's no formula.
* If without value, there's no formula.
*/
std::string formula_;
std::optional<std::string> formula_;

/** If there's no formula it contains the value. */
T value_;
Expand Down Expand Up @@ -154,10 +155,10 @@ operator()(const wfl::map_formula_callable& variables, wfl::function_symbol_tabl
return value_;
}

wfl::variant v = wfl::formula(formula_, functions).evaluate(variables);
wfl::variant v = wfl::formula(*formula_, functions).evaluate(variables);
const T& result = execute(v);

LOG_GUI_D << "Formula: execute '" << formula_ << "' result '" << result << "'.\n";
LOG_GUI_D << "Formula: execute '" << *formula_ << "' result '" << result << "'.\n";

return result;
}
Expand Down

0 comments on commit 26426ea

Please sign in to comment.