Skip to content

Commit 44f9d2f

Browse files
committed
Merge branch 'get_allocator-doc' into 'develop'
get_allocator-doc See merge request correaa/boost-multi!1980
2 parents c9a70cb + 1ae48bd commit 44f9d2f

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

include/boost/multi/array.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,23 @@ struct
149149
using array_alloc = detail::array_allocator<typename multi::allocator_traits<DummyAlloc>::template rebind_alloc<T>>;
150150

151151
public:
152-
using detail::array_allocator<typename multi::allocator_traits<DummyAlloc>::template rebind_alloc<T>>::get_allocator;
153-
154-
/// Alloc
152+
/// Allocator type (returned by `get_allocator()`)
155153
using allocator_type = typename detail::array_allocator<typename multi::allocator_traits<DummyAlloc>::template rebind_alloc<T>>::allocator_type; // NOLINT(readability-redundant-typename) needed for C++17
154+
156155
/// Layout type (generally a strided layout `multi::layout_t<D>`)
157156
using layout_type = typename array_ref<T, D, typename multi::allocator_traits<allocator_type>::pointer>::layout_type; // NOLINT(readability-redundant-typename) needed for C++17
157+
158158
/// Associalted array value type (generally itself, `multi::array<element, dimensionality, allocator_type>`)
159159
using decay_type = array<T, D, allocator_type>;
160160

161-
[[deprecated]] auto operator new(std::size_t count) -> void* { return ::operator new(count); }
162-
[[deprecated]] auto operator new(std::size_t count, void* ptr) -> void* { return ::operator new(count, ptr); }
161+
/// returns the allocator that is used to acquire/release memory and to construct/destroy the elements in that memory
162+
BOOST_MULTI_HD constexpr auto get_allocator() const -> allocator_type { return detail::array_allocator<
163+
typename allocator_traits<DummyAlloc>::template rebind_alloc<T>>::get_allocator(); }
164+
165+
/*[[deprecated]]*/ auto operator new(std::size_t count) -> void* { return ::operator new(count); } // overrides the deleted new operator in reference (base) class subarray
166+
/*[[deprecated]]*/ auto operator new(std::size_t count, void* ptr) -> void* { return ::operator new(count, ptr); } // overrides the deleted new operator in reference (base) class subarray
163167

164-
[[deprecated]] void operator delete(void* ptr) noexcept { ::operator delete(ptr); } // this overrides the deleted delete operator in reference (base) class subarray
168+
/*[[deprecated]]*/ void operator delete(void* ptr) noexcept { ::operator delete(ptr); } // overrides the deleted delete operator in reference (base) class subarray
165169

166170
protected: // TODO(correaa) make private
167171
/// Associated array reference type, also its base class (generally `multi::array_ref<element, dimensionality, allocator_type>`)
@@ -867,7 +871,7 @@ struct
867871
/// Random-access iterator in the leading dimension, in general they dereference to an immutable subarrays of lower dimension (`multi::const_subarray<...>`) or, for `D == 1`, to an element immutable reference (`T const&`)
868872
using const_iterator = multi::detail::array_iterator<T, D, typename dynamic_array::element_ptr, true>;
869873

870-
friend auto get_allocator(dynamic_array const& self) -> allocator_type { return self.get_allocator(); }
874+
// friend auto get_allocator(dynamic_array const& self) -> allocator_type { return self.get_allocator(); }
871875

872876
/// gets a const-pointer to a contigous range of size `.num_elements()` containing the data of the array
873877
BOOST_MULTI_HD constexpr auto data_elements() const& -> element_const_ptr { return this->base_; } // cppcheck-suppress duplInheritedMember ; to override

include/boost/multi/array_ref.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,12 +1405,13 @@ class const_subarray : public array_types<T, D, ElementPtr, Layout> {
14051405
using default_allocator_type = typename multi::pointer_traits<const_subarray::element_ptr>::default_allocator_type;
14061406

14071407
public:
1408+
/// returns the associated allocator
14081409
BOOST_MULTI_HD constexpr auto get_allocator() const -> default_allocator_type {
14091410
using multi::get_allocator;
14101411
return get_allocator(this->base());
14111412
}
14121413

1413-
BOOST_MULTI_FRIEND_CONSTEXPR auto get_allocator(const_subarray const& self) -> default_allocator_type { return self.get_allocator(); }
1414+
// BOOST_MULTI_FRIEND_CONSTEXPR auto get_allocator(const_subarray const& self) -> default_allocator_type { return self.get_allocator(); }
14141415

14151416
/// Associated type that this reference decays to (when true copies are needed)
14161417
using decay_type = array<std::decay_t<typename types::element>, D, typename multi::pointer_traits<typename const_subarray::element_ptr>::default_allocator_type>;

test/allocator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ auto main() -> int { // NOLINT(readability-function-cognitive-complexity,bugpro
282282

283283
multi::array<char, 2, std::pmr::polymorphic_allocator<char>> Barr({3, 2}, 'o', &pool);
284284

285+
BOOST_TEST( Aarr.get_allocator() == Barr.get_allocator() );
286+
285287
BOOST_TEST(( buffer != std::array<char, 13>{{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'}} ));
286288

287289
#ifdef __GLIBCXX__

0 commit comments

Comments
 (0)