1
0
forked from boostorg/core

Compare commits

..

16 Commits

Author SHA1 Message Date
Peter Dimov
d92a7b0498 Disable span_constexpr_test under GCC 4.x 2025-02-23 19:19:23 +02:00
Peter Dimov
5f6bb283fb Disable constexpr under GCC 4.x when there's BOOST_ASSERT 2025-02-23 18:55:04 +02:00
Peter Dimov
6b1d7a91e6 Use BOOST_ASSERT instead of BOOST_CORE_DETAIL_ASSERT 2025-02-23 18:55:04 +02:00
Peter Dimov
1e1ccb491e Fix GCC 4.8 Drone job to actually use 4.8 2025-02-23 18:37:43 +02:00
Glen Fernandes
787b03ea9c Use BOOST_ASSERT but disable assertions on older GCC 2025-01-18 17:14:03 -05:00
Glen Fernandes
b9a2221b3b Rename detail assert macro since it isn't a public facility 2025-01-18 14:14:24 -05:00
Glen Fernandes
cb603c9c6b Undef assert macro and remove guards 2025-01-18 00:53:35 -05:00
Glen Fernandes
24a8174ef1 Add asserts to span 2025-01-18 00:52:31 -05:00
Peter Dimov
7178a52909 Merge pull request #187 from eagleoflqj/ohos
OpenHarmony doesn't support pthread_setcancelstate.
2025-01-08 16:45:11 +02:00
Qijia Liu
9a3febf848 OpenHarmony doesn't support pthread_setcancelstate. 2025-01-07 21:13:58 -05:00
Peter Dimov
3e147e4ced Merge pull request #183 from Flamefire/warning
Avoid `-Wzero-as-null-pointer-constant` warning in string_view ctor
2025-01-05 17:25:14 +02:00
Alexander Grund
1222948a8e Avoid -Wzero-as-null-pointer-constant warning in string_view ctor 2025-01-05 11:57:02 +01:00
Peter Dimov
749b6340b5 Update ci.yml 2024-11-27 20:58:46 +02:00
Peter Dimov
92f6cfb3cc Remove hash_value overload for basic_string_view; it's no longer needed 2024-11-11 03:18:02 +02:00
Peter Dimov
ed452c57a3 Add sv_hash_test to test/CMakeLists.txt 2024-11-11 02:31:11 +02:00
Peter Dimov
78885aab8e Disable serialization tests under MinGW 32 bit 2024-11-10 22:35:54 +02:00
9 changed files with 157 additions and 29 deletions

View File

@@ -124,7 +124,7 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
linux_pipeline(
"Linux 16.04 GCC 4.8 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11', ADDRMD: '32,64' },
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '03,11', ADDRMD: '32,64' },
"g++-4.8-multilib",
),

View File

@@ -125,7 +125,7 @@ jobs:
cxxstd: "03,11,14,17,20,23"
address-model: 32,64
os: ubuntu-latest
container: ubuntu:23.04
container: ubuntu:24.04
install:
- g++-13-multilib
- toolset: gcc-14
@@ -283,7 +283,7 @@ jobs:
compiler: clang++-16
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
container: ubuntu:24.04
install:
- clang-16
- libc++-16-dev
@@ -294,7 +294,7 @@ jobs:
compiler: clang++-17
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.10
container: ubuntu:24.04
install:
- clang-17
- libc++-17-dev
@@ -312,6 +312,17 @@ jobs:
- libc++abi-18-dev
cxxflags: -stdlib=libc++
linkflags: -stdlib=libc++
- toolset: clang
compiler: clang++-19
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:24.10
install:
- clang-19
- libc++-19-dev
- libc++abi-19-dev
cxxflags: -stdlib=libc++
linkflags: -stdlib=libc++
- name: UBSAN
toolset: clang
compiler: clang++-15

View File

@@ -14,6 +14,31 @@ branches:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
ADDRMD: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-12.0,msvc-14.0
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
ADDRMD: 32,64
CXXSTD: 14,17
# clang-win 32 bit fails to link with "unable to load mspdbcore.dll (error code: 126)"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: clang-win
ADDRMD: 64
CXXSTD: 14,17,latest
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: clang-win
ADDRMD: 64
CXXSTD: 14,17,latest
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
@@ -39,6 +64,13 @@ environment:
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_SUBDIR: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_INSTALL: 1
install:
- set GIT_FETCH_JOBS=8
- set BOOST_BRANCH=develop

View File

@@ -67,7 +67,7 @@ namespace core
inline void sp_thread_sleep() BOOST_NOEXCEPT
{
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__) && !defined(__OHOS__)
int oldst;
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldst );
@@ -85,7 +85,7 @@ inline void sp_thread_sleep() BOOST_NOEXCEPT
nanosleep( &rqtp, 0 );
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__) && !defined(__OHOS__)
pthread_setcancelstate( oldst, &oldst );

View File

@@ -41,9 +41,6 @@ namespace boost
// forward declaration of boost::basic_string_view from Utility
template<class Ch, class Tr> class basic_string_view;
// forward declaration of boost::hash_range from ContainerHash
template<class It> std::size_t hash_range( It, It );
namespace core
{
namespace detail
@@ -381,7 +378,7 @@ public:
}
template<class End> BOOST_CXX14_CONSTEXPR basic_string_view( Ch const* first, End last,
typename boost::enable_if<boost::core::detail::is_same<End, Ch const*> >::type* = 0 ) BOOST_NOEXCEPT: p_( first ), n_( static_cast<size_type>( last - first ) )
typename boost::enable_if<boost::core::detail::is_same<End, Ch const*>, int >::type = 0 ) BOOST_NOEXCEPT: p_( first ), n_( static_cast<size_type>( last - first ) )
{
BOOST_ASSERT( last - first >= 0 );
}
@@ -399,7 +396,7 @@ public:
#endif
template<class Ch2> basic_string_view( boost::basic_string_view<Ch2, std::char_traits<Ch2> > const& str,
typename boost::enable_if<boost::core::detail::is_same<Ch, Ch2> >::type* = 0 ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() )
typename boost::enable_if<boost::core::detail::is_same<Ch, Ch2>, int >::type = 0 ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() )
{
}
@@ -1181,11 +1178,6 @@ public:
}
#endif
inline friend std::size_t hash_value( basic_string_view const& sv )
{
return boost::hash_range( sv.begin(), sv.end() );
}
};
// stream inserter

View File

@@ -9,10 +9,19 @@ Distributed under the Boost Software License, Version 1.0.
#define BOOST_CORE_SPAN_HPP
#include <boost/core/data.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <array>
#include <iterator>
#include <type_traits>
#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<std::size_t>(-1);
@@ -273,18 +282,22 @@ public:
return span<T, C>(s_.p + O, C);
}
constexpr span<T, dynamic_extent> first(size_type c) const {
return span<T, dynamic_extent>(s_.p, c);
BOOST_CORE_SPAN_CONSTEXPR span<T, dynamic_extent> first(size_type c) const {
return BOOST_ASSERT(c <= size()),
span<T, dynamic_extent>(s_.p, c);
}
constexpr span<T, dynamic_extent> last(size_type c) const {
return span<T, dynamic_extent>(s_.p + (s_.n - c), c);
BOOST_CORE_SPAN_CONSTEXPR span<T, dynamic_extent> last(size_type c) const {
return BOOST_ASSERT(c <= size()),
span<T, dynamic_extent>(s_.p + (s_.n - c), c);
}
constexpr span<T, dynamic_extent> subspan(size_type o,
BOOST_CORE_SPAN_CONSTEXPR span<T, dynamic_extent> subspan(size_type o,
size_type c = dynamic_extent) const {
return span<T, dynamic_extent>(s_.p + o,
c == dynamic_extent ? s_.n - o : c);
return BOOST_ASSERT(o <= size() &&
(c == dynamic_extent || c + o <= size())),
span<T, dynamic_extent>(s_.p + o,
c == dynamic_extent ? s_.n - o : c);
}
constexpr size_type size() const noexcept {
@@ -299,16 +312,16 @@ public:
return s_.n == 0;
}
constexpr reference operator[](size_type i) const {
return 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 *s_.p;
BOOST_CORE_SPAN_CONSTEXPR reference front() const {
return BOOST_ASSERT(!empty()), *s_.p;
}
constexpr reference back() const {
return 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 {
@@ -398,4 +411,6 @@ as_writable_bytes(span<T, E> s) noexcept
} /* boost */
#undef BOOST_CORE_SPAN_CONSTEXPR
#endif

View File

@@ -16,6 +16,10 @@ set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::utility)
boost_test(TYPE run SOURCES sv_conversion_test2.cpp)
set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::container_hash)
boost_test(TYPE run SOURCES sv_hash_test.cpp)
set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::config Boost::move Boost::smart_ptr)
boost_test(TYPE run SOURCES fclose_deleter_test.cpp)

View File

@@ -409,6 +409,7 @@ run span_test.cpp ;
run span_types_test.cpp ;
run span_constructible_test.cpp ;
run span_deduction_guide_test.cpp ;
run span_constexpr_test.cpp ;
run as_bytes_test.cpp ;
run as_writable_bytes_test.cpp ;
compile span_boost_begin_test.cpp ;

View File

@@ -0,0 +1,73 @@
/*
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)
*/
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_NO_CXX11_CONSTEXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 50000)
#include <boost/core/span.hpp>
#include <boost/core/lightweight_test.hpp>
constexpr const int array[4]{ 5, 10, 15, 20 };
void test_first()
{
constexpr boost::span<const int> s =
boost::span<const int>(array, 4).first(2);
BOOST_TEST_EQ(s.data(), &array[0]);
BOOST_TEST_EQ(s.size(), 2);
}
void test_last()
{
constexpr boost::span<const int> s =
boost::span<const int>(array, 4).last(2);
BOOST_TEST_EQ(s.data(), &array[2]);
BOOST_TEST_EQ(s.size(), 2);
}
void test_subspan()
{
constexpr boost::span<const int> s =
boost::span<const int>(array, 4).subspan(1, 2);
BOOST_TEST_EQ(s.data(), &array[1]);
BOOST_TEST_EQ(s.size(), 2);
}
void test_index()
{
constexpr const int i = boost::span<const int>(array, 4)[1];
BOOST_TEST_EQ(i, 10);
}
void test_front()
{
constexpr const int i = boost::span<const int>(array, 4).front();
BOOST_TEST_EQ(i, 5);
}
void test_back()
{
constexpr const int i = boost::span<const int>(array, 4).back();
BOOST_TEST_EQ(i, 20);
}
int main()
{
test_first();
test_last();
test_subspan();
test_index();
test_front();
test_back();
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif