From 1869201ee64cab23ad7ecf9ec10fe36d0937bc51 Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:37:50 -0500 Subject: [PATCH 1/6] Fix issue where contiguous iterators were interpreted as contiguous --- source/include/gch/small_vector.hpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/source/include/gch/small_vector.hpp b/source/include/gch/small_vector.hpp index f9fe555..5007d5c 100644 --- a/source/include/gch/small_vector.hpp +++ b/source/include/gch/small_vector.hpp @@ -274,6 +274,12 @@ # endif #endif +#if defined (__cpp_lib_to_address) && __cpp_lib_to_address >= 201711L +# ifndef GCH_LIB_TO_ADDRESS +# define GCH_LIB_TO_ADDRESS +# endif +#endif + // TODO: // Make sure we don't need any laundering in the internal class functions. // I also need some sort of test case to actually show where UB is occurring, @@ -499,11 +505,26 @@ namespace gch static_assert ( NullablePointer); static_assert (! NullablePointer); + template + concept LegacyContiguousIterator = + std::random_access_iterator + && std::is_lvalue_reference>::value + && std::same_as, std::remove_cvref_t>> +#ifdef GCH_LIB_TO_ADDRESS + && requires (const I& i) + { + { std::to_address (i) } -> std::same_as>>; + } +#endif + ; + template concept AllocatorFor = - NoThrowCopyConstructible + CopyConstructible && requires (A a, typename std::allocator_traits::template rebind_alloc b, + A a1, + A a2, U xp, typename std::allocator_traits::pointer p, typename std::allocator_traits::const_pointer cp, @@ -516,12 +537,12 @@ namespace gch // A::pointer requires NullablePointer< typename std::allocator_traits::pointer>; requires std::random_access_iterator::pointer>; - requires std::contiguous_iterator< typename std::allocator_traits::pointer>; + requires LegacyContiguousIterator< typename std::allocator_traits::pointer>; // A::const_pointer requires NullablePointer< typename std::allocator_traits::const_pointer>; requires std::random_access_iterator::const_pointer>; - requires std::contiguous_iterator< typename std::allocator_traits::const_pointer>; + requires LegacyContiguousIterator< typename std::allocator_traits::const_pointer>; requires std::convertible_to::pointer, typename std::allocator_traits::const_pointer>; From ac4a5e32b99cb2864ad3cb4e419f520302813917 Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:39:30 -0500 Subject: [PATCH 2/6] Fix issue where non-explicitly noexcept allocators were not allowed --- source/include/gch/small_vector.hpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/source/include/gch/small_vector.hpp b/source/include/gch/small_vector.hpp index 5007d5c..b493dce 100644 --- a/source/include/gch/small_vector.hpp +++ b/source/include/gch/small_vector.hpp @@ -639,8 +639,10 @@ namespace gch || requires { { a.destroy (xp) } -> std::convertible_to; }; /** Relationship between instances **/ - requires NoThrowConstructibleFrom; - requires NoThrowConstructibleFrom; + { a1 == a2 } -> std::same_as; + { a1 != a2 } -> std::same_as; + requires ConstructibleFrom; + requires ConstructibleFrom; requires BoolConstant::is_always_equal>; @@ -660,14 +662,6 @@ namespace gch requires BoolConstant< typename std::allocator_traits::propagate_on_container_swap>; - - { a == b } -> std::same_as; - { a != b } -> std::same_as; - } - && requires (A a1, A a2) - { - { a1 == a2 } -> std::same_as; - { a1 != a2 } -> std::same_as; }; static_assert (AllocatorFor, int>, From 765ce1d93358e0c0cf527b7191a099b06bfef8a3 Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:41:46 -0500 Subject: [PATCH 3/6] Fix issue where some compilers would fail to compile with allocators which were not default constructible --- source/include/gch/small_vector.hpp | 76 +++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/source/include/gch/small_vector.hpp b/source/include/gch/small_vector.hpp index b493dce..628aa40 100644 --- a/source/include/gch/small_vector.hpp +++ b/source/include/gch/small_vector.hpp @@ -5178,7 +5178,7 @@ namespace gch GCH_CPP20_CONSTEXPR small_vector (void) - noexcept (noexcept (allocator_type ())) + noexcept (std::is_nothrow_default_constructible::value) #ifdef GCH_LIB_CONCEPTS requires concepts::DefaultConstructible #endif @@ -5223,7 +5223,15 @@ namespace gch { } GCH_CPP20_CONSTEXPR explicit - small_vector (size_type count, const allocator_type& alloc = allocator_type ()) + small_vector (size_type count) +#ifdef GCH_LIB_CONCEPTS + requires DefaultInsertable && concepts::DefaultConstructible +#endif + : small_vector (count, allocator_type ()) + { } + + GCH_CPP20_CONSTEXPR explicit + small_vector (size_type count, const allocator_type& alloc) #ifdef GCH_LIB_CONCEPTS requires DefaultInsertable #endif @@ -5231,8 +5239,15 @@ namespace gch { } GCH_CPP20_CONSTEXPR - small_vector (size_type count, const_reference value, - const allocator_type& alloc = allocator_type ()) + small_vector (size_type count, const_reference value) +#ifdef GCH_LIB_CONCEPTS + requires CopyInsertable && concepts::DefaultConstructible +#endif + : small_vector (count, value, allocator_type ()) + { } + + GCH_CPP20_CONSTEXPR + small_vector (size_type count, const_reference value, const allocator_type& alloc) #ifdef GCH_LIB_CONCEPTS requires CopyInsertable #endif @@ -5243,13 +5258,30 @@ namespace gch template requires std::invocable && EmplaceConstructible>::value + && concepts::DefaultConstructible #else template ::value>::type * = nullptr> + ! std::is_convertible::value + &&! std::is_convertible::value>::type * = nullptr> #endif GCH_CPP20_CONSTEXPR - small_vector (size_type count, Generator g, const allocator_type& alloc = allocator_type ()) + small_vector (size_type count, Generator g) + : small_vector (count, g, allocator_type ()) + { } + + #ifdef GCH_LIB_CONCEPTS + template + requires std::invocable + && EmplaceConstructible>::value +#else + template ::value + &&! std::is_convertible::value>::type * = nullptr> +#endif + GCH_CPP20_CONSTEXPR + small_vector (size_type count, Generator g, const allocator_type& alloc) : base (count, g, alloc) { } @@ -5257,6 +5289,7 @@ namespace gch template requires EmplaceConstructible>::value && (std::forward_iterator || MoveInsertable) + && concepts::DefaultConstructible #else template ::type * = nullptr> #endif GCH_CPP20_CONSTEXPR - small_vector (InputIt first, InputIt last, const allocator_type& alloc = allocator_type ()) + small_vector (InputIt first, InputIt last) + : small_vector (first, last, allocator_type ()) + { } + +#ifdef GCH_LIB_CONCEPTS + template + requires EmplaceConstructible>::value + && (std::forward_iterator || MoveInsertable) +#else + template ::iterator_category>::value + >::type * = nullptr> +#endif + GCH_CPP20_CONSTEXPR + small_vector (InputIt first, InputIt last, const allocator_type& alloc) : base (first, last, typename std::iterator_traits::iterator_category { }, alloc) { } GCH_CPP20_CONSTEXPR - small_vector (std::initializer_list init, - const allocator_type& alloc = allocator_type ()) + small_vector (std::initializer_list init) +#ifdef GCH_LIB_CONCEPTS + requires EmplaceConstructible::value + && concepts::DefaultConstructible +#endif + : small_vector (init.begin (), init.end (), allocator_type ()) + { } + + GCH_CPP20_CONSTEXPR + small_vector (std::initializer_list init, const allocator_type& alloc) #ifdef GCH_LIB_CONCEPTS requires EmplaceConstructible::value #endif From e1d1a54edc4f7329c51109b6bef0cb14b91dd581 Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:43:39 -0500 Subject: [PATCH 4/6] Use Boost CONFIG find-module --- source/bench/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/bench/CMakeLists.txt b/source/bench/CMakeLists.txt index 88a191a..9b983c4 100644 --- a/source/bench/CMakeLists.txt +++ b/source/bench/CMakeLists.txt @@ -13,7 +13,7 @@ if (GCH_SMALL_VECTOR_BENCH_ENABLE_BOOST OR NOT DEFINED GCH_SMALL_VECTOR_BENCH_EN endfunction () if (GCH_SMALL_VECTOR_BENCH_ENABLE_BOOST) - find_package (Boost REQUIRED COMPONENTS container) + find_package (Boost CONFIG REQUIRED COMPONENTS container) check_boost_header (HAVE_BOOST_SMALL_VECTOR_HPP) @@ -21,7 +21,7 @@ if (GCH_SMALL_VECTOR_BENCH_ENABLE_BOOST OR NOT DEFINED GCH_SMALL_VECTOR_BENCH_EN message (FATAL_ERROR "Found Boost, but could not compile with boost/container/small_vector.hpp") endif () else () - find_package (Boost QUIET COMPONENTS container) + find_package (Boost CONFIG QUIET COMPONENTS container) if (Boost_FOUND) check_boost_header (HAVE_BOOST_SMALL_VECTOR_HPP QUIET) From 3b52793324d6cb0e77c73b0f2cafe99cdcb1ecca Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:44:02 -0500 Subject: [PATCH 5/6] Add a PMR allocator integration test --- source/test/CMakeLists.txt | 1 + source/test/integration/CMakeLists.txt | 4 +++ source/test/integration/boost/CMakeLists.txt | 16 +++++++++ .../test/integration/boost/pmr_allocator.cpp | 34 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 source/test/integration/CMakeLists.txt create mode 100644 source/test/integration/boost/CMakeLists.txt create mode 100644 source/test/integration/boost/pmr_allocator.cpp diff --git a/source/test/CMakeLists.txt b/source/test/CMakeLists.txt index 4057d99..6b4e156 100644 --- a/source/test/CMakeLists.txt +++ b/source/test/CMakeLists.txt @@ -168,4 +168,5 @@ endif () add_custom_target (small_vector.ctest) +add_subdirectory (integration) add_subdirectory (unit) diff --git a/source/test/integration/CMakeLists.txt b/source/test/integration/CMakeLists.txt new file mode 100644 index 0000000..73ac973 --- /dev/null +++ b/source/test/integration/CMakeLists.txt @@ -0,0 +1,4 @@ +find_package (Boost CONFIG QUIET COMPONENTS interprocess) +if (Boost_FOUND) + add_subdirectory (boost) +endif () diff --git a/source/test/integration/boost/CMakeLists.txt b/source/test/integration/boost/CMakeLists.txt new file mode 100644 index 0000000..de2cc02 --- /dev/null +++ b/source/test/integration/boost/CMakeLists.txt @@ -0,0 +1,16 @@ +foreach (version ${GCH_SMALL_VECTOR_TEST_STANDARD_VERSIONS}) + set (_TARGET_NAME small_vector.test.integration.boost.pmr_allocator.c++${version}) + add_executable (${_TARGET_NAME} pmr_allocator.cpp) + target_link_libraries (${_TARGET_NAME} PRIVATE gch::small_vector Boost::boost) + target_compile_options (${_TARGET_NAME} PRIVATE "$<$:-fconcepts-diagnostics-depth=100>") + set_target_properties ( + ${_TARGET_NAME} + PROPERTIES + CXX_STANDARD + ${version} + CXX_STANDARD_REQUIRED + NO + CXX_EXTENSIONS + NO + ) +endforeach () diff --git a/source/test/integration/boost/pmr_allocator.cpp b/source/test/integration/boost/pmr_allocator.cpp new file mode 100644 index 0000000..c883836 --- /dev/null +++ b/source/test/integration/boost/pmr_allocator.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +namespace bi = boost::interprocess; +using namespace gch; + +template +using alloc = bi::adaptive_pool; + +using ipc_row = small_vector>::value, alloc>; +using scoped_alloc = std::scoped_allocator_adaptor>; +using ipc_matrix = small_vector::value, scoped_alloc>; + +int main() +{ + bi::managed_shared_memory s(bi::create_only, "Demo", 65536); + + // create vector of vectors in shared memory + ipc_matrix v(s.get_segment_manager()); + + // for all these additions, the inner vectors obtain their allocator arguments + // from the outer vector's scoped_allocator_adaptor + v.resize(1); + v[0].push_back(1); + v.emplace_back(2); +// std::vector local_row = {1, 2, 3}; + small_vector local_row = {1, 2, 3}; + v.emplace_back(local_row.begin(), local_row.end()); + + bi::shared_memory_object::remove("Demo"); +} From effa6a6fd53ff36207cb8f46258ee755b0d87cca Mon Sep 17 00:00:00 2001 From: Gene Harvey Date: Sun, 30 Mar 2025 14:44:11 -0500 Subject: [PATCH 6/6] Update the version --- CMakeLists.txt | 2 +- conanfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33e3ce9..c2992ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 3.15) project ( small_vector VERSION - 0.10.1 + 0.10.2 LANGUAGES CXX ) diff --git a/conanfile.py b/conanfile.py index 3e672db..2f1c82d 100644 --- a/conanfile.py +++ b/conanfile.py @@ -6,7 +6,7 @@ class GchSmallVectorConan(ConanFile): name = "small_vector" author = "Gene Harvey " - version = "0.10.1" + version = "0.10.2" license = "MIT" url = "https://github.com/gharveymn/small_vector" description = "A fully featured single header library implementing a vector container with a small buffer optimization."