From 250713d93201204af077a671b4e4ab03526575c1 Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 16 Jul 2020 02:31:04 +0000 Subject: [PATCH] Use `if constexpr` to simplify xrange_extent::init_begin Switch from tag-based overload dispatching to use `if constexpr`. --- common/main/d_range.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/common/main/d_range.h b/common/main/d_range.h index 253ad1bf7..303e2d403 100644 --- a/common/main/d_range.h +++ b/common/main/d_range.h @@ -71,28 +71,24 @@ class xrange_extent : using begin_type = xrange_endpoint; using end_type = xrange_endpoint; using iterator = xrange_iterator; - static begin_type init_begin(B b, E e, std::true_type /* is_same */) + static begin_type init_begin(B b, E e) { - return ( + if constexpr (std::is_convertible::value) + { #ifdef DXX_CONSTANT_TRUE - /* Compile-time only check. Runtime handles (b > e) - * correctly, and it can happen in a correct program. If it - * is guaranteed to happen, then the range is always empty, - * which likely indicates a bug. - */ - (DXX_CONSTANT_TRUE(!(b < e)) && (DXX_ALWAYS_ERROR_FUNCTION(xrange_is_always_empty, "begin never less than end"), 0)), + (DXX_CONSTANT_TRUE(!(b < e)) && (DXX_ALWAYS_ERROR_FUNCTION(xrange_is_always_empty, "begin never less than end"), 0)); #endif - b < e ? std::move(b) : e - ); - } - static begin_type init_begin(B b, E, std::false_type /* is_same */) - { - return begin_type(b); + if (!(b < e)) + return e; + } + else + (void)e; + return b; } public: using range_owns_iterated_storage = std::false_type; xrange_extent(B b, E e) : - begin_type(init_begin(std::move(b), e, std::is_same())), end_type(std::move(e)) + begin_type(init_begin(std::move(b), e)), end_type(std::move(e)) { } iterator begin() const