aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/lib/include/newtype/concepts.hpp147
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