diff options
Diffstat (limited to 'include/ocl')
| -rw-r--r-- | include/ocl/is_same.hpp | 29 | ||||
| -rw-r--r-- | include/ocl/option.hpp | 52 |
2 files changed, 44 insertions, 37 deletions
diff --git a/include/ocl/is_same.hpp b/include/ocl/is_same.hpp index 57d372b..519a87b 100644 --- a/include/ocl/is_same.hpp +++ b/include/ocl/is_same.hpp @@ -19,8 +19,8 @@ namespace ocl using result_type = typename T::result_type; using type = T; - /// @brief hash from T's result_type. - static result_type hash() + // AMLALE: If it throws, we can't compute the hash correctly. + static constexpr result_type hash() noexcept { return T{}.hash(); } @@ -61,10 +61,7 @@ namespace ocl { using result_type = bool; - constexpr result_type hash() - { - return sizeof(T) == 1; - } + static constexpr auto value = sizeof(T) == 1; }; template <typename T> @@ -72,10 +69,7 @@ namespace ocl { using result_type = bool; - constexpr result_type hash() - { - return sizeof(T) > 1; - } + static constexpr auto value = sizeof(T) > 1; }; template <typename T> @@ -83,10 +77,7 @@ namespace ocl { using result_type = bool; - constexpr result_type hash() - { - return sizeof(T) >= 4; - } + static constexpr auto value = sizeof(T) >= 4; }; template <typename L, typename R> @@ -96,10 +87,7 @@ namespace ocl using left_type = L; using right_type = R; - constexpr result_type hash() - { - return false; - } + static constexpr auto value = false; }; template <typename L> @@ -109,10 +97,7 @@ namespace ocl using left_type = L; using right_type = L; - constexpr result_type hash() - { - return true; - } + static constexpr auto value = true; }; } // namespace ocl diff --git a/include/ocl/option.hpp b/include/ocl/option.hpp index d84e935..73af0ae 100644 --- a/include/ocl/option.hpp +++ b/include/ocl/option.hpp @@ -27,6 +27,7 @@ namespace ocl explicit option(const return_type& return_type) : ret_(return_type) { + assert(ret_ != return_type::invalid); } ~option() = default; @@ -36,6 +37,8 @@ namespace ocl option& expect(const char* input) { + assert(ret_ != return_type::invalid); + if (ret_ == return_type::err) { throw std::runtime_error(input ? input : "option::error"); @@ -47,8 +50,11 @@ namespace ocl template <typename ErrorHandler> option& expect_or_handle(const char* input) { + assert(ret_ != return_type::invalid); + if (ret_ == return_type::err) { + // AMLALE: Shall it be a functor or container here? ErrorHandler{}(input ? input : "option::error"); } @@ -59,56 +65,72 @@ namespace ocl return_type ret_{return_type::invalid}; }; - template <typename Teller, typename... Lst> - inline return_type eval(Teller tell, Lst&&... arg) - { - return tell(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; - } - namespace detail { - struct int_eq_teller final + // AMLALE: They (operator()) were marked `noexcept` as failing conditions within an evaluation (say a overloads operator==) proves that the + // predictate is wrong. + + struct teller + { + explicit teller() = default; + virtual ~teller() = default; + + template <class ObjFirst, class ObjLast> + bool operator()(ObjFirst a, ObjLast b) noexcept + { + return false; + } + }; + + struct int_eq_teller final : teller { template <class ObjFirst, class ObjLast> - bool operator()(ObjFirst a, ObjLast b) + bool operator()(ObjFirst a, ObjLast b) noexcept { return (a == b); } }; - struct int_greater_than_teller final + struct int_greater_than_teller final : teller { template <class ObjFirst, class ObjLast> - bool operator()(ObjFirst a, ObjLast b) + bool operator()(ObjFirst a, ObjLast b) noexcept { return (a > b); } }; - struct int_less_than_teller final + struct int_less_than_teller final : teller { template <class ObjFirst, class ObjLast> - bool operator()(ObjFirst a, ObjLast b) + bool operator()(ObjFirst a, ObjLast b) noexcept { return (a < b); } }; } // namespace detail + template <typename Teller, typename... Lst> + inline return_type eval(const Teller& tell, Lst&&... arg) + { + static_assert(std::is_base_of_v<detail::teller, Teller>, "Teller is not evalueable."); + return tell(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; + } + template <typename... Lst> - inline return_type eval_less_than(Lst&&... arg) + inline return_type eval_less_than(Lst&&... arg) noexcept { return detail::int_less_than_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; } template <typename... Lst> - inline return_type eval_eq(Lst&&... arg) + inline return_type eval_eq(Lst&&... arg) noexcept { return detail::int_eq_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; } template <typename... Lst> - inline return_type eval_greater_than(Lst&&... arg) + inline return_type eval_greater_than(Lst&&... arg) noexcept { return detail::int_greater_than_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; } |
