From eb13bd9991ceef34cacb0913df90045b08726f81 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 17:31:29 +0200 Subject: concepts: replace is_*_output_streamable* --- source/lib/include/newtype/concepts.hpp | 15 ++++++++++ .../newtype/impl/type_traits_extensions.hpp | 33 ---------------------- source/lib/include/newtype/newtype.hpp | 10 ++++--- source/tests/src/io_operators.cpp | 2 +- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/source/lib/include/newtype/concepts.hpp b/source/lib/include/newtype/concepts.hpp index c053612..c9ef951 100644 --- a/source/lib/include/newtype/concepts.hpp +++ b/source/lib/include/newtype/concepts.hpp @@ -54,6 +54,21 @@ namespace nt::concepts } 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) { { diff --git a/source/lib/include/newtype/impl/type_traits_extensions.hpp b/source/lib/include/newtype/impl/type_traits_extensions.hpp index 7db8e66..22834f2 100644 --- a/source/lib/include/newtype/impl/type_traits_extensions.hpp +++ b/source/lib/include/newtype/impl/type_traits_extensions.hpp @@ -124,39 +124,6 @@ namespace nt::impl auto constexpr is_nothrow_greater_than_equal_to_comparable_v = is_nothrow_greater_than_equal_to_comparable::value; } // namespace relationally_comparable - inline namespace iostreamable - { - - template - struct is_output_streamable : std::false_type - { - }; - - template - struct is_output_streamable() << std::declval())>> - : std::true_type - { - }; - - template - auto constexpr is_output_streamable_v = is_output_streamable::value; - - template - struct is_nothrow_output_streamable : std::false_type - { - }; - - template - struct is_nothrow_output_streamable() << std::declval())>> - : std::bool_constant() << std::declval())> - { - }; - - template - auto constexpr is_nothrow_output_streamable_v = is_nothrow_output_streamable::value; - - } // namespace iostreamable - inline namespace arithmetic { diff --git a/source/lib/include/newtype/newtype.hpp b/source/lib/include/newtype/newtype.hpp index acfd2f9..e40097d 100644 --- a/source/lib/include/newtype/newtype.hpp +++ b/source/lib/include/newtype/newtype.hpp @@ -335,11 +335,13 @@ namespace nt return lhs.decay() >= rhs.decay(); } - template + template BaseType, + typename TagType, + nt::contains auto DerivationClause> auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( - impl::is_nothrow_output_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_ostream> & + nt::concepts::nothrow_output_streamable) -> std::basic_ostream & { return output << source.decay(); } diff --git a/source/tests/src/io_operators.cpp b/source/tests/src/io_operators.cpp index 23be171..2be41eb 100644 --- a/source/tests/src/io_operators.cpp +++ b/source/tests/src/io_operators.cpp @@ -83,7 +83,7 @@ SCENARIO("Stream Output") using type_alias = nt::new_type; static_assert(has_stream_output_v); - THEN("it has the stream input operator") + THEN("it has the stream output operator") { STATIC_REQUIRE(has_stream_output_v); } -- cgit v1.2.3