summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-12-06 16:36:01 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-12-07 09:00:00 +0100
commit8e6865188242bccb3d8aa857ddc990d72a058d3d (patch)
tree31a19fba39c6c7f85e1561a8e73e25a6e71cb50f /include
parentc1fbdc8717fa68f4c432511ace8b58c97b1386ad (diff)
Adapt o3tl::span to P1872R0
..."span should have size_type, not index_type" (<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1872r0.pdf>), as implemented by libc++ since <https://github.com/llvm/llvm-project/commit/ 1466335cf4b2854a0be1defcf279fe50772bad6f> "[libc++][P1872] span should have size_type, not index_type." All uses of index_type had been added to mitigate the previous std::span change from signed (ptrdiff_t) to unsigned (size_t) index_type, see 6ef8420fdbf8dff16de13147c5ab833bc5e01121 "Adapt o3tl::span to updated C++2a std::span". There is no easy solution to transparently support all three std::span variants currently out there (signed index_type, unsigned index_type, unsigned size_type), without causing compilation failures due to CPPUNIT_ASSERT_EQUAL with arguments of different types, or compiler warnings about mixed signed/unsigned comparisons. So rule out the oldest std::span variant (signed index_type) in configure.ac (so that o3tl::span will use its own hand-rolled code in that case) and simplify the uses of index_type to std::size_t (as had already been mentioned in 6ef8420fdbf8dff16de13147c5ab833bc5e01121). Change-Id: I6ddf424ffb7941da3f69ad66fd29ecd35f09afae Reviewed-on: https://gerrit.libreoffice.org/84652 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/span.hxx14
1 files changed, 8 insertions, 6 deletions
diff --git a/include/o3tl/span.hxx b/include/o3tl/span.hxx
index 1618b86df897..b19d2d847ac7 100644
--- a/include/o3tl/span.hxx
+++ b/include/o3tl/span.hxx
@@ -12,7 +12,9 @@
#include <sal/config.h>
-#if __has_include(<span>)
+#include <config_global.h>
+
+#if HAVE_CPP_SPAN
#include <span>
@@ -40,7 +42,7 @@ public:
using iterator = pointer;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using reverse_iterator = std::reverse_iterator<iterator>;
- using index_type = std::size_t;
+ using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
constexpr span() noexcept : data_(nullptr), size_(0) {}
@@ -48,7 +50,7 @@ public:
template<std::size_t N>
constexpr span (T (&a)[N]) noexcept : data_(a), size_(N) {}
- constexpr span (T *a, index_type len) noexcept
+ constexpr span (T *a, size_type len) noexcept
: data_(a), size_(len)
{
// not terribly sure about this, might need to strengthen it
@@ -72,9 +74,9 @@ public:
{ return rbegin(); }
constexpr const_reverse_iterator crend() const noexcept { return rend(); }
- constexpr index_type size() const noexcept { return size_; }
+ constexpr size_type size() const noexcept { return size_; }
- constexpr reference operator [](index_type pos) const {
+ constexpr reference operator [](size_type pos) const {
assert(pos < size());
return data_[pos];
}
@@ -83,7 +85,7 @@ public:
private:
pointer data_;
- index_type size_;
+ size_type size_;
};
} // namespace o3tl