feat: add challenge code
This commit is contained in:
commit
5634d1bb39
22 files changed
+925
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user