diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 17:34:00 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 17:34:00 +0200 |
| commit | 8f9e88a9c5d83ea043be341a2b8663130e85f5eb (patch) | |
| tree | c5894804b90108a5fc019e09591f35463544f69e | |
| parent | eb13bd9991ceef34cacb0913df90045b08726f81 (diff) | |
| download | newtype-8f9e88a9c5d83ea043be341a2b8663130e85f5eb.tar.xz newtype-8f9e88a9c5d83ea043be341a2b8663130e85f5eb.zip | |
concepts: group in namespaces
| -rw-r--r-- | source/lib/include/newtype/concepts.hpp | 147 |
1 files 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<typename SubjectType> - concept equality_comparable = requires(SubjectType lhs, SubjectType rhs) { - { - lhs == rhs - } -> std::convertible_to<bool>; - }; - - template<typename SubjectType> - concept nothrow_equality_comparable = requires(SubjectType lhs, SubjectType rhs) { - requires equality_comparable<SubjectType>; - { - lhs == rhs - } noexcept; - }; - - template<typename SubjectType> - concept inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { - { - lhs != rhs - } -> std::convertible_to<bool>; - }; - - template<typename SubjectType> - concept nothrow_inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { - requires inequality_comparable<SubjectType>; - { - lhs != rhs - } noexcept; - }; - - template<typename SubjectType, typename CharType, typename StreamTraits> - concept input_streamable = requires(SubjectType subject) { - { - std::declval<std::basic_istream<CharType, StreamTraits> &>() >> subject - } -> std::same_as<std::basic_istream<CharType, StreamTraits> &>; - }; - - template<typename SubjectType, typename CharType, typename StreamTraits> - concept nothrow_input_streamable = requires(SubjectType subject) { - requires input_streamable<SubjectType, CharType, StreamTraits>; - { - std::declval<std::basic_istream<CharType, StreamTraits> &>() >> subject - } noexcept; - }; - - template<typename SubjectType, typename CharType, typename StreamTraits> - concept output_streamable = requires(SubjectType subject) { - { - std::declval<std::basic_ostream<CharType, StreamTraits> &>() << subject - } -> std::same_as<std::basic_ostream<CharType, StreamTraits> &>; - }; - - template<typename SubjectType, typename CharType, typename StreamTraits> - concept nothrow_output_streamable = requires(SubjectType subject) { - requires output_streamable<SubjectType, CharType, StreamTraits>; - { - std::declval<std::basic_ostream<CharType, StreamTraits> &>() << subject - } noexcept; - }; - - template<typename SubjectType> - concept hashable = requires(SubjectType subject) { - { - std::hash<SubjectType>{}(subject) - } -> std::convertible_to<std::size_t>; - }; + inline namespace comparability + { + + template<typename SubjectType> + concept equality_comparable = requires(SubjectType lhs, SubjectType rhs) { + { + lhs == rhs + } -> std::convertible_to<bool>; + }; + + template<typename SubjectType> + concept nothrow_equality_comparable = requires(SubjectType lhs, SubjectType rhs) { + requires equality_comparable<SubjectType>; + { + lhs == rhs + } noexcept; + }; + + template<typename SubjectType> + concept inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { + { + lhs != rhs + } -> std::convertible_to<bool>; + }; + + template<typename SubjectType> + concept nothrow_inequality_comparable = requires(SubjectType lhs, SubjectType rhs) { + requires inequality_comparable<SubjectType>; + { + lhs != rhs + } noexcept; + }; + + } // namespace comparability + + inline namespace iostreamable + { + + template<typename SubjectType, typename CharType, typename StreamTraits> + concept input_streamable = requires(SubjectType subject) { + { + std::declval<std::basic_istream<CharType, StreamTraits> &>() >> subject + } -> std::same_as<std::basic_istream<CharType, StreamTraits> &>; + }; + + template<typename SubjectType, typename CharType, typename StreamTraits> + concept nothrow_input_streamable = requires(SubjectType subject) { + requires input_streamable<SubjectType, CharType, StreamTraits>; + { + std::declval<std::basic_istream<CharType, StreamTraits> &>() >> subject + } noexcept; + }; + + template<typename SubjectType, typename CharType, typename StreamTraits> + concept output_streamable = requires(SubjectType subject) { + { + std::declval<std::basic_ostream<CharType, StreamTraits> &>() << subject + } -> std::same_as<std::basic_ostream<CharType, StreamTraits> &>; + }; + + template<typename SubjectType, typename CharType, typename StreamTraits> + concept nothrow_output_streamable = requires(SubjectType subject) { + requires output_streamable<SubjectType, CharType, StreamTraits>; + { + std::declval<std::basic_ostream<CharType, StreamTraits> &>() << subject + } noexcept; + }; + + } // namespace iostreamable + + inline namespace standard_extensions + { + + template<typename SubjectType> + concept hashable = requires(SubjectType subject) { + { + std::hash<SubjectType>{}(subject) + } -> std::convertible_to<std::size_t>; + }; + + } } // namespace nt::concepts |
