Files
calculator-challenge/BinaryOperatorFactory.tcc
T
2024-03-13 01:55:14 +00:00

21 lines
744 B
C++

#include "BinaryOperatorFactory.hpp"
#include "utils.hpp"
template<typename T>
BinaryOperatorFactory<T>::BinaryOperatorFactory() noexcept
{
_binary_operations["+"] = [](auto lhs, auto rhs) { return lhs + rhs; };
_binary_operations["-"] = [](auto lhs, auto rhs) { return lhs - rhs; };
_binary_operations["*"] = [](auto lhs, auto rhs) { return lhs * rhs; };
_binary_operations["/"] = [](auto lhs, auto rhs) { return lhs / rhs; };
}
template<typename T>
auto BinaryOperatorFactory<T>::make(std::string_view text) noexcept -> std::optional<Operator>
{
auto found_op = _binary_operations.find(std::string{sanitize_text(text)});
if (found_op == _binary_operations.end()) return std::nullopt;
return found_op->second;
}