From 8f9e88a9c5d83ea043be341a2b8663130e85f5eb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 17:34:00 +0200 Subject: concepts: group in namespaces --- source/lib/include/newtype/concepts.hpp | 147 ++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/source/lib/include/newtype/concepts.hpp b/source/lib/include/newtype/concepts.hpp index c9ef951..8f94a42 100644 --- a/source/lib/include/newtype/concepts.hpp +++ b/source/lib/include/newtype/concepts.hpp @@ -9,72 +9,87 @@ namespace nt::concepts { - template - concept equality_comparable = requires(SubjectType lhs, SubjectType rhs) { - { - lhs == rhs - } -> std::convertible_to; - }; - - template - concept nothrow_equality_comparable = requires(SubjectType lhs, SubjectType rhs) { - requires equality_comparable; - { - lhs == rhs - } noexcept; - }; - - template - concept inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { - { - lhs != rhs - } -> std::convertible_to; - }; - - template - concept nothrow_inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { - requires inequality_comparable; - { - lhs != rhs - } noexcept; - }; - - template - concept input_streamable = requires(SubjectType subject) { - { - std::declval &>() >> subject - } -> std::same_as &>; - }; - - template - concept nothrow_input_streamable = requires(SubjectType subject) { - requires input_streamable; - { - std::declval &>() >> subject - } noexcept; - }; - - template - concept output_streamable = requires(SubjectType subject) { - { - std::declval &>() << subject - } -> std::same_as &>; - }; - - template - concept nothrow_output_streamable = requires(SubjectType subject) { - requires output_streamable; - { - std::declval &>() << subject - } noexcept; - }; - - template - concept hashable = requires(SubjectType subject) { - { - std::hash{}(subject) - } -> std::convertible_to; - }; + inline namespace comparability + { + + template + concept equality_comparable = requires(SubjectType lhs, SubjectType rhs) { + { + lhs == rhs + } -> std::convertible_to; + }; + + template + concept nothrow_equality_comparable = requires(SubjectType lhs, SubjectType rhs) { + requires equality_comparable; + { + lhs == rhs + } noexcept; + }; + + template + concept inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { + { + lhs != rhs + } -> std::convertible_to; + }; + + template + concept nothrow_inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { + requires inequality_comparable; + { + lhs != rhs + } noexcept; + }; + + } // namespace comparability + + inline namespace iostreamable + { + + template + concept input_streamable = requires(SubjectType subject) { + { + std::declval &>() >> subject + } -> std::same_as &>; + }; + + template + concept nothrow_input_streamable = requires(SubjectType subject) { + requires input_streamable; + { + std::declval &>() >> subject + } noexcept; + }; + + template + concept output_streamable = requires(SubjectType subject) { + { + std::declval &>() << subject + } -> std::same_as &>; + }; + + template + concept nothrow_output_streamable = requires(SubjectType subject) { + requires output_streamable; + { + std::declval &>() << subject + } noexcept; + }; + + } // namespace iostreamable + + inline namespace standard_extensions + { + + template + concept hashable = requires(SubjectType subject) { + { + std::hash{}(subject) + } -> std::convertible_to; + }; + + } } // namespace nt::concepts -- cgit v1.2.3