feat: add challenge code

This commit is contained in:
jfmcarreira committed 2024-03-13 01:55:14 +00:00
commit 5634d1bb39
22 files changed
+925

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
#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;
}