From 556321f18dfdbb6d0684b4fbc23ad7eab23a3d93 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 23 Oct 2020 19:03:37 -0700 Subject: Some cleanup in alspan.h --- common/alspan.h | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/common/alspan.h b/common/alspan.h index 7be07354..c1ad6f9e 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -10,11 +10,11 @@ namespace al { template -constexpr auto size(T &cont) -> decltype(cont.size()) +constexpr auto size(T &cont) noexcept(noexcept(cont.size())) -> decltype(cont.size()) { return cont.size(); } template -constexpr auto size(const T &cont) -> decltype(cont.size()) +constexpr auto size(const T &cont) noexcept(noexcept(cont.size())) -> decltype(cont.size()) { return cont.size(); } template @@ -27,11 +27,11 @@ constexpr size_t size(std::initializer_list list) noexcept template -constexpr auto data(T &cont) -> decltype(cont.data()) +constexpr auto data(T &cont) noexcept(noexcept(cont.data())) -> decltype(cont.data()) { return cont.data(); } template -constexpr auto data(const T &cont) -> decltype(cont.data()) +constexpr auto data(const T &cont) noexcept(noexcept(cont.data())) -> decltype(cont.data()) { return cont.data(); } template @@ -43,7 +43,9 @@ constexpr const T* data(std::initializer_list list) noexcept { return list.begin(); } -template(-1)> +constexpr size_t dynamic_extent{static_cast(-1)}; + +template class span; namespace detail_ { @@ -82,8 +84,6 @@ namespace detail_ { template class span { - static constexpr size_t dynamic_extent{static_cast(-1)}; - public: using element_type = T; using value_type = std::remove_cv_t; @@ -109,12 +109,15 @@ public: constexpr span(element_type (&arr)[E]) noexcept : span{al::data(arr), al::size(arr)} { } constexpr span(std::array &arr) noexcept : span{al::data(arr), al::size(arr)} { } template::value)> - constexpr span(const std::array &arr) noexcept : span{al::data(arr), al::size(arr)} { } + constexpr span(const std::array &arr) noexcept + : span{al::data(arr), al::size(arr)} + { } template constexpr span(U &cont) : span{al::data(cont), al::size(cont)} { } template constexpr span(const U &cont) : span{al::data(cont), al::size(cont)} { } - template::value && std::is_convertible::value)> + template::value + && std::is_convertible::value)> constexpr span(const span &span_) noexcept : span{al::data(span_), al::size(span_)} { } constexpr span(const span&) noexcept = default; @@ -136,8 +139,10 @@ public: constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; } constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; } - constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator{cend()}; } - constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator{cbegin()}; } + constexpr const_reverse_iterator crbegin() const noexcept + { return const_reverse_iterator{cend()}; } + constexpr const_reverse_iterator crend() const noexcept + { return const_reverse_iterator{cbegin()}; } template constexpr span first() const @@ -167,16 +172,15 @@ public: */ constexpr span first(size_t count) const; constexpr span last(size_t count) const; - constexpr span subspan(size_t offset, size_t count=dynamic_extent) const; + constexpr span subspan(size_t offset, + size_t count=dynamic_extent) const; private: pointer mData{nullptr}; }; template -class span(-1)> { - static constexpr size_t dynamic_extent{static_cast(-1)}; - +class span { public: using element_type = T; using value_type = std::remove_cv_t; @@ -193,7 +197,7 @@ public: using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - static constexpr size_t extent{static_cast(-1)}; + static constexpr size_t extent{dynamic_extent}; constexpr span() noexcept = default; constexpr span(pointer ptr, index_type count) : mData{ptr}, mDataEnd{ptr+count} { } @@ -203,12 +207,15 @@ public: template constexpr span(std::array &arr) noexcept : span{al::data(arr), al::size(arr)} { } template::value)> - constexpr span(const std::array &arr) noexcept : span{al::data(arr), al::size(arr)} { } + constexpr span(const std::array &arr) noexcept + : span{al::data(arr), al::size(arr)} + { } template constexpr span(U &cont) : span{al::data(cont), al::size(cont)} { } template constexpr span(const U &cont) : span{al::data(cont), al::size(cont)} { } - template::value || extent != N) && std::is_convertible::value)> + template::value || extent != N) + && std::is_convertible::value)> constexpr span(const span &span_) noexcept : span{al::data(span_), al::size(span_)} { } constexpr span(const span&) noexcept = default; @@ -231,8 +238,10 @@ public: constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; } constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; } - constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator{cend()}; } - constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator{cbegin()}; } + constexpr const_reverse_iterator crbegin() const noexcept + { return const_reverse_iterator{cend()}; } + constexpr const_reverse_iterator crend() const noexcept + { return const_reverse_iterator{cbegin()}; } template constexpr span first() const @@ -279,7 +288,8 @@ constexpr inline auto span::last(size_t count) const -> span -constexpr inline auto span::subspan(size_t offset, size_t count) const -> span +constexpr inline auto span::subspan(size_t offset, size_t count) const + -> span { return (offset > size()) ? span{} : (count >= size()-offset) ? span{mData+offset, mData+extent} : -- cgit v1.2.3