Files
2024-03-13 01:55:14 +00:00

35 lines
746 B
C++

#ifndef CALCULATOR_CHALLENGE_OPERAND_HPP
#define CALCULATOR_CHALLENGE_OPERAND_HPP
#include <functional>
#include <string>
#include <variant>
template<typename T>
using BinaryOperatorType = std::function<T(T, T)>;
using Operator = BinaryOperatorType<double>;
class IntegerOperand
{
public:
explicit IntegerOperand(double value) noexcept : _value{value} {}
auto get() const noexcept -> double { return _value; };
private:
double _value{0};
};
class VariableOperand
{
public:
explicit VariableOperand(std::string name) noexcept : _name{std::move(name)} {}
auto get() const noexcept -> std::string { return _name; };
private:
std::string _name;
};
using Operand = std::variant<IntegerOperand, VariableOperand>;
#endif