diff options
author | Chris Robinson <[email protected]> | 2020-10-23 19:53:07 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-10-23 19:53:07 -0700 |
commit | 966c4498d4e8024f821cb35ceba934dba10a1922 (patch) | |
tree | c29a31ae013a9345eece0149e312ab5550d8ebdb /common/alspan.h | |
parent | 556321f18dfdbb6d0684b4fbc23ad7eab23a3d93 (diff) |
Don't use a template parameter as a variable
And try to silence an MSVC warning about a constant overflow.
Diffstat (limited to 'common/alspan.h')
-rw-r--r-- | common/alspan.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/common/alspan.h b/common/alspan.h index c1ad6f9e..f2c42b16 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -158,12 +158,19 @@ public: return span<element_type,C>{mData+(E-C), C}; } - template<size_t O, size_t C, size_t RealC=((C==dynamic_extent) ? E-O : C)> - constexpr span<element_type,RealC> subspan() const + template<size_t O, size_t C> + constexpr auto subspan() const -> std::enable_if_t<C!=dynamic_extent,span<element_type,C>> { static_assert(E >= O, "Offset exceeds extent"); - static_assert(E-O >= RealC, "New size exceeds original capacity"); - return span<element_type,RealC>{mData+O, RealC}; + static_assert(E-O >= C, "New size exceeds original capacity"); + return span<element_type,C>{mData+O, C}; + } + + template<size_t O, size_t C=dynamic_extent> + constexpr auto subspan() const -> std::enable_if_t<C==dynamic_extent,span<element_type,E-O>> + { + static_assert(E >= O, "Offset exceeds extent"); + return span<element_type,E-O>{mData+O, E-O}; } /* NOTE: Can't declare objects of a specialized template class prior to @@ -257,9 +264,13 @@ public: constexpr span last(size_t count) const { return (count >= size()) ? *this : span{mDataEnd-count, mDataEnd}; } + template<size_t O, size_t C> + constexpr auto subspan() const -> std::enable_if_t<C!=dynamic_extent,span<element_type,C>> + { return span<element_type,C>{mData+O, C}; } + template<size_t O, size_t C=dynamic_extent> - constexpr span<element_type,C> subspan() const - { return span<element_type,C>{mData+O, (C!=dynamic_extent) ? mData+O+C : mDataEnd}; } + constexpr auto subspan() const -> std::enable_if_t<C==dynamic_extent,span<element_type,C>> + { return span<element_type,C>{mData+O, mDataEnd}; } constexpr span subspan(size_t offset, size_t count=dynamic_extent) const { |