diff --git a/include/boost/core/detail/assert.hpp b/include/boost/core/detail/assert.hpp deleted file mode 100644 index d677e2e0..00000000 --- a/include/boost/core/detail/assert.hpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2025 Glen Joseph Fernandes -(glenjofe@gmail.com) - -Distributed under the Boost Software License, Version 1.0. -(http://www.boost.org/LICENSE_1_0.txt) -*/ -#undef BOOST_CORE_DETAIL_ASSERT - -#if !defined(__clang__) && \ - !defined(__INTEL_COMPILER) && \ - defined(__GNUC__) && \ - (__GNUC__ < 5) -#define BOOST_CORE_DETAIL_ASSERT(expr) void(0) -#else -#include -#define BOOST_CORE_DETAIL_ASSERT(expr) BOOST_ASSERT(expr) -#endif diff --git a/include/boost/core/span.hpp b/include/boost/core/span.hpp index 3a602c25..1039d674 100644 --- a/include/boost/core/span.hpp +++ b/include/boost/core/span.hpp @@ -8,12 +8,20 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_CORE_SPAN_HPP #define BOOST_CORE_SPAN_HPP -#include #include +#include +#include +#include #include #include #include +#if BOOST_WORKAROUND(BOOST_GCC, < 50000) +# define BOOST_CORE_SPAN_CONSTEXPR +#else +# define BOOST_CORE_SPAN_CONSTEXPR constexpr +#endif + namespace boost { constexpr std::size_t dynamic_extent = static_cast(-1); @@ -274,19 +282,19 @@ class span { return span(s_.p + O, C); } - constexpr span first(size_type c) const { - return BOOST_CORE_DETAIL_ASSERT(c <= size()), + BOOST_CORE_SPAN_CONSTEXPR span first(size_type c) const { + return BOOST_ASSERT(c <= size()), span(s_.p, c); } - constexpr span last(size_type c) const { - return BOOST_CORE_DETAIL_ASSERT(c <= size()), + BOOST_CORE_SPAN_CONSTEXPR span last(size_type c) const { + return BOOST_ASSERT(c <= size()), span(s_.p + (s_.n - c), c); } - constexpr span subspan(size_type o, + BOOST_CORE_SPAN_CONSTEXPR span subspan(size_type o, size_type c = dynamic_extent) const { - return BOOST_CORE_DETAIL_ASSERT(o <= size() && + return BOOST_ASSERT(o <= size() && (c == dynamic_extent || c + o <= size())), span(s_.p + o, c == dynamic_extent ? s_.n - o : c); @@ -304,16 +312,16 @@ class span { return s_.n == 0; } - constexpr reference operator[](size_type i) const { - return BOOST_CORE_DETAIL_ASSERT(i < size()), s_.p[i]; + BOOST_CORE_SPAN_CONSTEXPR reference operator[](size_type i) const { + return BOOST_ASSERT(i < size()), s_.p[i]; } - constexpr reference front() const { - return BOOST_CORE_DETAIL_ASSERT(!empty()), *s_.p; + BOOST_CORE_SPAN_CONSTEXPR reference front() const { + return BOOST_ASSERT(!empty()), *s_.p; } - constexpr reference back() const { - return BOOST_CORE_DETAIL_ASSERT(!empty()), s_.p[s_.n - 1]; + BOOST_CORE_SPAN_CONSTEXPR reference back() const { + return BOOST_ASSERT(!empty()), s_.p[s_.n - 1]; } constexpr pointer data() const noexcept { @@ -403,4 +411,6 @@ as_writable_bytes(span s) noexcept } /* boost */ +#undef BOOST_CORE_SPAN_CONSTEXPR + #endif diff --git a/test/span_constexpr_test.cpp b/test/span_constexpr_test.cpp index c24751b8..043fec92 100644 --- a/test/span_constexpr_test.cpp +++ b/test/span_constexpr_test.cpp @@ -6,7 +6,8 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#if !defined(BOOST_NO_CXX11_CONSTEXPR) +#include +#if !defined(BOOST_NO_CXX11_CONSTEXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 50000) #include #include