From 93e02a01568519344310897e8e9f4ee4f32ff75f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 15:42:41 +0200 Subject: concets: replace is_*_input_streamable* --- source/lib/include/newtype/concepts.hpp | 16 +++++++++++++ .../newtype/impl/type_traits_extensions.hpp | 27 ---------------------- source/lib/include/newtype/newtype.hpp | 20 +++++++++------- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/source/lib/include/newtype/concepts.hpp b/source/lib/include/newtype/concepts.hpp index 6db528c..c053612 100644 --- a/source/lib/include/newtype/concepts.hpp +++ b/source/lib/include/newtype/concepts.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace nt::concepts { @@ -38,6 +39,21 @@ namespace nt::concepts } 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 hashable = requires(SubjectType subject) { { diff --git a/source/lib/include/newtype/impl/type_traits_extensions.hpp b/source/lib/include/newtype/impl/type_traits_extensions.hpp index c4b9bee..7db8e66 100644 --- a/source/lib/include/newtype/impl/type_traits_extensions.hpp +++ b/source/lib/include/newtype/impl/type_traits_extensions.hpp @@ -155,33 +155,6 @@ namespace nt::impl template auto constexpr is_nothrow_output_streamable_v = is_nothrow_output_streamable::value; - template - struct is_input_streamable : std::false_type - { - }; - - template - struct is_input_streamable() >> std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_input_streamable_v = is_input_streamable::value; - - template - struct is_nothrow_input_streamable : std::false_type - { - }; - - template - struct is_nothrow_input_streamable() >> std::declval())>> - : std::bool_constant() >> std::declval())> - { - }; - - template - auto constexpr is_nothrow_input_streamable_v = is_nothrow_input_streamable::value; - } // namespace iostreamable inline namespace arithmetic diff --git a/source/lib/include/newtype/newtype.hpp b/source/lib/include/newtype/newtype.hpp index 33863ac..acfd2f9 100644 --- a/source/lib/include/newtype/newtype.hpp +++ b/source/lib/include/newtype/newtype.hpp @@ -25,11 +25,13 @@ namespace nt static_assert(!std::is_reference_v, "The base type must not be a reference type"); static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); - template + template BaseTypeT, + typename TagTypeT, + nt::contains auto DerivationClauseV> auto friend operator>>(std::basic_istream &, new_type &) noexcept( - impl::is_nothrow_input_streamable_v, BaseTypeT>) - -> std::enable_if_t, BaseTypeT>, - std::basic_istream> &; + nt::concepts::nothrow_input_streamable) -> std::basic_istream &; template auto constexpr friend @@ -342,11 +344,13 @@ namespace nt return output << source.decay(); } - template + template BaseType, + typename TagType, + nt::contains auto DerivationClause> auto operator>>(std::basic_istream & input, new_type & target) noexcept( - impl::is_nothrow_input_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_istream> & + nt::concepts::nothrow_input_streamable) -> std::basic_istream & { return input >> target.m_value; } -- cgit v1.2.3