diff options
-rw-r--r-- | config_host/config_global.h.in | 3 | ||||
-rw-r--r-- | configure.ac | 16 | ||||
-rw-r--r-- | include/o3tl/span.hxx | 14 | ||||
-rw-r--r-- | o3tl/qa/test-span.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 3 |
5 files changed, 33 insertions, 10 deletions
diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in index adb36c39ab8b..5b04594c12f5 100644 --- a/config_host/config_global.h.in +++ b/config_host/config_global.h.in @@ -29,6 +29,9 @@ Any change in this header will cause a rebuild of almost everything. // constexpr", and <https://wg21.link/P1143R2> "Adding the constinit keyword": #define HAVE_CPP_CONSTINIT_SORTED_VECTOR 0 +// Useable C++2a <span>: +#define HAVE_CPP_SPAN 0 + /* GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87150> "move ctor wrongly chosen in return stmt (derived vs. base)": */ #define HAVE_GCC_BUG_87150 0 diff --git a/configure.ac b/configure.ac index 651e9d60c2d4..194a3cc80fa5 100644 --- a/configure.ac +++ b/configure.ac @@ -6701,6 +6701,22 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([ CXXFLAGS=$save_CXXFLAGS AC_LANG_POP([C++]) +AC_MSG_CHECKING([whether $CXX_BASE supports C++2a <span> with unsigned size_type]) +AC_LANG_PUSH([C++]) +save_CXXFLAGS=$CXXFLAGS +CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11" +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include <span> + #include <type_traits> + // Don't check size_type directly, as it was called index_type before P1872R0: + void f(std::span<int> s) { static_assert(std::is_unsigned_v<decltype(s.size())>); }; + ])], [ + AC_DEFINE([HAVE_CPP_SPAN],[1]) + AC_MSG_RESULT([yes]) + ], [AC_MSG_RESULT([no])]) +CXXFLAGS=$save_CXXFLAGS +AC_LANG_POP([C++]) + AC_MSG_CHECKING([whether $CXX_BASE has GCC bug 87150]) AC_LANG_PUSH([C++]) save_CXXFLAGS=$CXXFLAGS 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 diff --git a/o3tl/qa/test-span.cxx b/o3tl/qa/test-span.cxx index 7ec67fa7fd91..3cb78ace1db2 100644 --- a/o3tl/qa/test-span.cxx +++ b/o3tl/qa/test-span.cxx @@ -9,6 +9,7 @@ #include <sal/config.h> +#include <cstddef> #include <utility> #include <cppunit/TestAssert.h> @@ -42,7 +43,7 @@ private: CPPUNIT_ASSERT_EQUAL(3, *v.crbegin()); CPPUNIT_ASSERT_EQUAL( o3tl::span<int>::difference_type(3), v.crend() - v.crbegin()); - CPPUNIT_ASSERT_EQUAL(o3tl::span<int>::index_type(3), v.size()); + CPPUNIT_ASSERT_EQUAL(std::size_t(3), v.size()); CPPUNIT_ASSERT(!v.empty()); CPPUNIT_ASSERT_EQUAL(2, v[1]); CPPUNIT_ASSERT_EQUAL(1, *v.data()); @@ -52,8 +53,8 @@ private: o3tl::span<int const> v1( d1 ); o3tl::span<int const> v2( d2 ); std::swap(v1, v2); - CPPUNIT_ASSERT_EQUAL(o3tl::span<int>::index_type(4), v1.size()); - CPPUNIT_ASSERT_EQUAL(o3tl::span<int>::index_type(2), v2.size()); + CPPUNIT_ASSERT_EQUAL(std::size_t(4), v1.size()); + CPPUNIT_ASSERT_EQUAL(std::size_t(2), v2.size()); } } }; diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 9edf43c4ecd6..9b6519ca1814 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -20,6 +20,7 @@ #include <config_feature_desktop.h> #include <algorithm> +#include <cstddef> #include <deque> #include <vector> @@ -1453,7 +1454,7 @@ void SfxDispatcher::SetSlotFilter(SfxSlotFilterState nEnable, { #ifdef DBG_UTIL // Check Array - for ( o3tl::span<sal_uInt16 const>::index_type n = 1; n < pSIDs.size(); ++n ) + for ( std::size_t n = 1; n < pSIDs.size(); ++n ) DBG_ASSERT( pSIDs[n] > pSIDs[n-1], "SetSlotFilter: SIDs not sorted" ); #endif |