From 2ce3e6496ae608e663bb3e7a188c63f4676e00e3 Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 18 Feb 2017 15:23:57 +0100 Subject: [PATCH] clean up range tests --- ostd/range.hh | 54 +++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/ostd/range.hh b/ostd/range.hh index 2063121..cb16425 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -82,20 +82,6 @@ using range_reference_t = typename range_traits::reference; template using range_difference_t = typename range_traits::difference_type; -namespace detail { - template - static char is_range_test_f( - typename U::range_category *, typename U::size_type *, - typename U::difference_type *, typename U::value_type *, - std::remove_reference_t * - ); - template - static int is_range_test_f(...); - - template constexpr bool is_range_test = - (sizeof(is_range_test_f(0, 0, 0, 0, 0)) == sizeof(char)); -} - // is input range namespace detail { @@ -103,7 +89,7 @@ namespace detail { constexpr bool is_input_range_core = std::is_convertible_v, input_range_tag>; - template> + template> constexpr bool is_input_range_base = false; template @@ -120,7 +106,7 @@ namespace detail { constexpr bool is_forward_range_core = std::is_convertible_v, forward_range_tag>; - template> + template> constexpr bool is_forward_range_base = false; template @@ -137,7 +123,7 @@ namespace detail { constexpr bool is_bidirectional_range_core = std::is_convertible_v, bidirectional_range_tag>; - template> + template> constexpr bool is_bidirectional_range_base = false; template @@ -155,7 +141,7 @@ namespace detail { constexpr bool is_random_access_range_core = std::is_convertible_v, random_access_range_tag>; - template> + template> constexpr bool is_random_access_range_base = false; template @@ -173,7 +159,7 @@ namespace detail { constexpr bool is_finite_random_access_range_core = std::is_convertible_v, finite_random_access_range_tag>; - template> + template> constexpr bool is_finite_random_access_range_base = false; template @@ -196,7 +182,7 @@ namespace detail { constexpr bool is_contiguous_range_core = std::is_convertible_v, contiguous_range_tag>; - template> + template> constexpr bool is_contiguous_range_base = false; template @@ -210,28 +196,28 @@ template constexpr bool is_contiguous_range = // is output range namespace detail { - template - struct output_range_test { - template - struct test_t {}; - template - static char test(test_t *); - template - static int test(...); - static constexpr bool value = (sizeof(test(0)) == sizeof(char)); - }; + template + static std::true_type test_outrange(typename std::is_same< + decltype(std::declval().put(std::declval())), bool + >::type *); + + template + static std::false_type test_outrange(...); + + template + constexpr bool output_range_test = decltype(test_outrange())::value; template constexpr bool is_output_range_core = std::is_convertible_v, output_range_tag> || ( is_input_range && ( - detail::output_range_test const &>::value || - detail::output_range_test &&>::value || - detail::output_range_test >::value + output_range_test const &> || + output_range_test &&> || + output_range_test > ) ); - template> + template> constexpr bool is_output_range_base = false; template