Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
const_iterator_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 / \ | | ___ _ __ | |__ __ __
6 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / /
7 / ___ \| | __/ |_) | | | |_____\ V V /
8 /_/ \_\_|\___| .__/|_| |_| \_/\_/
9 |_|
10
11 This file is part of Aleph-w library
12
13 Copyright (c) 2002-2026 Leandro Rabindranath Leon
14
15 Permission is hereby granted, free of charge, to any person obtaining a copy
16 of this software and associated documentation files (the "Software"), to deal
17 in the Software without restriction, including without limitation the rights
18 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions:
21
22 The above copyright notice and this permission notice shall be included in all
23 copies or substantial portions of the Software.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 SOFTWARE.
32*/
33
41#include <gtest/gtest.h>
42
43#include <ah-iterator.H>
44#include <ah-zip.H>
45#include <ahFunctional.H>
46#include <filter_iterator.H>
47#include <htlist.H>
48#include <tpl_array.H>
49#include <tpl_arrayHeap.H>
50#include <tpl_arrayQueue.H>
51#include <tpl_arrayStack.H>
52#include <tpl_dynArray.H>
53#include <tpl_dynArrayHeap.H>
54#include <tpl_dynBinHeap.H>
55#include <tpl_dynDlist.H>
56#include <tpl_dynListQueue.H>
57#include <tpl_dynListStack.H>
58#include <tpl_dynMapTree.H>
59#include <tpl_dynSetHash.H>
60#include <tpl_dynSetTree.H>
61#include <tpl_dynSkipList.H>
62#include <tpl_hash.H>
63#include <tpl_odhash.H>
64#include <tpl_olhash.H>
65#include <tpl_memArray.H>
66#include <tpl_random_queue.H>
67#include <tpl_small_vector.H>
68
69#include <algorithm>
70#include <iterator>
71#include <type_traits>
72#include <utility>
73
74using namespace Aleph;
75
76namespace
77{
78 template <class C>
79 constexpr bool iterator_rejects_a_constant_container =
80 not std::is_constructible_v<typename C::Iterator, const C &>
81 and std::is_constructible_v<typename C::Iterator, C &>
82 and std::is_constructible_v<typename C::Const_Iterator, const C &>;
83
84 // What get_curr() hands out on the iterator of C and on its read-only view.
85 template <class C>
86 using curr_t = decltype(std::declval<const typename C::Iterator &>().get_curr());
87
88 template <class C>
89 using const_curr_t = decltype(std::declval<const const_iterator_t<C> &>().get_curr());
90
91 // The expressions that a client must not be able to write. They are
92 // templates so that an ill-formed expression makes the requires-expression
93 // false instead of making the program ill-formed.
94 template <class C>
95 constexpr bool writes_through_call = requires (const C & c) { c(0) = 7; };
96
97 template <class It>
98 constexpr bool writes_through_curr = requires (It it) { it.get_curr() = 8; };
99
100 template <class It>
101 constexpr bool removes_through_it = requires (It it) { it.del(); };
102
103 template <class C>
104 constexpr bool const_traverse_takes_a_modifying_operation = requires (const C & c)
105 {
106 c.traverse([] (typename C::Item_Type & x) { x = 9; return true; });
107 };
108
109 template <class C>
110 constexpr bool const_traverse_takes_a_reading_operation = requires (const C & c)
111 {
112 c.traverse([] (const typename C::Item_Type & x) { return x == 9; });
113 };
114}
115
116TEST(ConstIterator, the_iterators_that_hand_out_modifiable_references_reject_constant_containers)
117{
118 // The families whose Iterator::get_curr() returns T &: they are built from
119 // a modifiable container only, and a constant one yields a Const_Iterator.
120 static_assert(iterator_rejects_a_constant_container<MemArray<int>>);
121 static_assert(iterator_rejects_a_constant_container<Array<int>>);
122 static_assert(iterator_rejects_a_constant_container<ArrayStack<int>>);
123 static_assert(iterator_rejects_a_constant_container<FixedStack<int>>);
124 static_assert(iterator_rejects_a_constant_container<ArrayQueue<int>>);
125 static_assert(iterator_rejects_a_constant_container<FixedQueue<int>>);
126 static_assert(iterator_rejects_a_constant_container<Random_Set<int>>);
127 static_assert(iterator_rejects_a_constant_container<DynArray<int>>);
128 static_assert(iterator_rejects_a_constant_container<DynList<int>>);
129 static_assert(iterator_rejects_a_constant_container<DynDlist<int>>);
130 static_assert(iterator_rejects_a_constant_container<DynListQueue<int>>);
131 static_assert(iterator_rejects_a_constant_container<DynListStack<int>>);
132 static_assert(iterator_rejects_a_constant_container<DynSetTree<int>>);
133 static_assert(iterator_rejects_a_constant_container<DynMapTree<int, int>>);
134 static_assert(iterator_rejects_a_constant_container<DynSetHash<int>>);
135 static_assert(iterator_rejects_a_constant_container<DynMapHash<int, int>>);
136 static_assert(iterator_rejects_a_constant_container<ODhashTable<int>>);
137 static_assert(iterator_rejects_a_constant_container<OLhashTable<int>>);
138
139 static_assert(std::is_same_v<curr_t<DynList<int>>, int &>);
140 static_assert(std::is_same_v<const_curr_t<DynList<int>>, const int &>);
141 static_assert(std::is_same_v<curr_t<Array<int>>, int &>);
142 static_assert(std::is_same_v<const_curr_t<Array<int>>, const int &>);
143 static_assert(std::is_same_v<const_curr_t<DynArray<int>>, const int &>);
144
145 // The heaps are read-only through their iterators: the heap order must not
146 // be broken.
147 static_assert(std::is_same_v<curr_t<ArrayHeap<int>>, const int &>);
148 static_assert(std::is_same_v<curr_t<DynArrayHeap<int>>, const int &>);
149 static_assert(std::is_same_v<curr_t<DynBinHeap<int>>, const int &>);
150
151 // The skip list keeps its keys sorted: its iterator is read-only.
152 static_assert(std::is_constructible_v<DynSkipList<int>::Iterator, const DynSkipList<int> &>);
153 static_assert(std::is_same_v<decltype(std::declval<DynSkipList<int>::Iterator &>().get_curr()),
154 const int &>);
155
156 // A constant iterator object of a set hands out a reference to const; the
157 // view keeps the underlying iterator and its typedefs.
158 static_assert(std::is_same_v<curr_t<DynSetTree<int>>, const int &>);
159 static_assert(std::is_same_v<decltype(std::declval<DynMapTree<int, int>::Iterator &>().get_curr()),
160 std::pair<int, int> &>);
161 static_assert(std::is_same_v<const_curr_t<DynMapTree<int, int>>, const std::pair<int, int> &>);
162 static_assert(std::is_same_v<const_iterator_t<DynSetTree<int>>::Itor, DynSetTree<int>::Iterator>);
163 static_assert(std::is_same_v<const_iterator_t<DynList<int>>::Item_Type, int>);
164 static_assert(std::is_same_v<const_iterator_t<DynList<int>>::Set_Type, DynList<int>>);
165 static_assert(std::is_same_v<const_curr_t<HashSet<int>>, const int &>);
166}
167
168TEST(ConstIterator, get_it_depends_on_the_constness_of_the_container)
169{
170 DynList<int> l = {1, 2, 3};
171 const DynList<int> & cl = l;
172 static_assert(std::is_same_v<decltype(l.get_it()), DynList<int>::Iterator>);
173 static_assert(std::is_same_v<decltype(cl.get_it()), DynList<int>::Const_Iterator>);
174 static_assert(std::is_same_v<decltype(cl.get_it(1)), DynList<int>::Const_Iterator>);
175 static_assert(std::is_same_v<decltype(iterator_for(l)), DynList<int>::Iterator>);
176 static_assert(std::is_same_v<decltype(iterator_for(cl)), DynList<int>::Const_Iterator>);
177
178 l.get_it().get_curr() = 10; // modifiable through the modifiable container
179 EXPECT_EQ(cl.get_first(), 10);
180
181 int sum = 0;
182 for (auto it = cl.get_it(); it.has_curr(); it.next_ne())
183 sum += it.get_curr();
184 EXPECT_EQ(sum, 15);
185 EXPECT_EQ(cl.get_it(2).get_curr(), 3);
186}
187
188// The view adds nothing to the iterator that it wraps, in any ABI: its
189// typedefs come from a single chain of empty bases, which the Microsoft
190// layout also optimizes away (it does not with two separate empty bases).
191template <class C>
193 sizeof(const_iterator_t<C>) == sizeof(typename C::Iterator);
194
195TEST(ConstIterator, is_as_large_as_the_iterator_that_it_wraps)
196{
197 static_assert(const_iterator_is_as_large_as_the_iterator<MemArray<int>>);
198 static_assert(const_iterator_is_as_large_as_the_iterator<Array<int>>);
199 static_assert(const_iterator_is_as_large_as_the_iterator<ArrayQueue<int>>);
200 static_assert(const_iterator_is_as_large_as_the_iterator<DynArray<int>>);
201 static_assert(const_iterator_is_as_large_as_the_iterator<DynList<int>>);
202 static_assert(const_iterator_is_as_large_as_the_iterator<DynDlist<int>>);
203 static_assert(const_iterator_is_as_large_as_the_iterator<DynSetTree<int>>);
204 static_assert(const_iterator_is_as_large_as_the_iterator<DynSetHash<int>>);
205
206 // The typedefs of the underlying iterator are still there.
207 static_assert(std::is_same_v<DynList<int>::Const_Iterator::Item_Type,
209 static_assert(std::is_same_v<DynList<int>::Const_Iterator::Set_Type,
211}
212
213TEST(ConstIterator, reads_the_container_like_the_iterator)
214{
216 for (int i = 0; i < 5; ++i)
217 l.append(i);
218 const DynDlist<int> & cl = l;
219
221 ASSERT_TRUE(it.has_curr());
222 EXPECT_EQ(it.get_curr(), 0);
223 EXPECT_EQ(it.get_pos(), 0);
224 it.next();
225 EXPECT_EQ(it.get_curr_ne(), 1);
226 it.reset_last();
227 EXPECT_EQ(it.get_curr(), 4);
228 EXPECT_TRUE(it.is_in_last());
229 it.prev();
230 EXPECT_EQ(it.get_curr(), 3);
231 it.reset_first();
232 EXPECT_EQ(it.get_curr(), 0);
233
234 // Copies and exchanges, as the iterator.
236 copy.next();
237 EXPECT_EQ(it.get_curr(), 0);
238 EXPECT_EQ(copy.get_curr(), 1);
239 it.swap(copy);
240 EXPECT_EQ(it.get_curr(), 1);
241 EXPECT_EQ(copy.get_curr(), 0);
242
243 // A view over an existing iterator starts at its position.
244 auto mit = l.get_it(3);
246 EXPECT_EQ(view.get_curr(), 3);
247
248 // The end of the sequence.
249 it.end();
250 EXPECT_FALSE(it.has_curr());
251}
252
253TEST(ConstIterator, the_stl_const_iterator_is_read_only_and_random_access_on_arrays)
254{
255 Array<int> a;
256 for (int i = 0; i < 10; ++i)
257 a.append(i);
258 const Array<int> & ca = a;
259
260 static_assert(std::random_access_iterator<decltype(ca.begin())>);
261 static_assert(std::is_same_v<decltype(*ca.begin()), const int &>);
262 static_assert(std::is_same_v<decltype(*a.begin()), int &>);
263
264 EXPECT_EQ(std::count_if(ca.begin(), ca.end(), [] (int x) { return x % 2 == 0; }), 5);
265 EXPECT_EQ(ca.end() - ca.begin(), 10);
266 EXPECT_EQ(ca.begin()[7], 7);
267 EXPECT_TRUE(std::is_sorted(ca.begin(), ca.end()));
268
269 int sum = 0;
270 for (const int & x : ca)
271 sum += x;
272 EXPECT_EQ(sum, 45);
273
274 const DynList<int> cl = {3, 1, 2};
275 EXPECT_EQ(*std::max_element(cl.begin(), cl.end()), 3);
276}
277
278TEST(ConstIterator, a_constant_dynarray_is_read_without_allocating)
279{
280 DynArray<int> a(16); // sixteen entries never written
282 const DynArray<int> & ca = a;
283
284 int sum = 0;
285 for (auto it = ca.get_it(); it.has_curr(); it.next_ne())
286 sum += it.get_curr();
287 EXPECT_EQ(sum, 16 * 7);
288 EXPECT_EQ(ca.get_first(), 7);
289 EXPECT_EQ(ca.get_last(), 7);
290 EXPECT_EQ(ca.read(3), 7);
291 for (size_t i = 0; i < 16; ++i)
292 EXPECT_FALSE(ca.exist(i)); // nothing was allocated by reading
293
294 // The modifiable iterator allocates (the whole block of the entry), as
295 // a[i] does.
297 it.get_curr() = 1;
298 EXPECT_TRUE(ca.exist(0));
299 EXPECT_EQ(ca(0), 1);
300 EXPECT_EQ(ca.get_first(), 1);
301 EXPECT_EQ(ca.get_last(), 7);
302}
303
304TEST(ConstIterator, the_accessors_of_a_constant_container_hand_out_references_to_const)
305{
306 using CA = const Array<int> &;
307 static_assert(std::is_same_v<decltype(std::declval<CA>()[0]), const int &>);
308 static_assert(std::is_same_v<decltype(std::declval<CA>()(0)), const int &>);
309 static_assert(std::is_same_v<decltype(std::declval<CA>().get_first()), const int &>);
310 static_assert(std::is_same_v<decltype(std::declval<CA>().get_last()), const int &>);
311 static_assert(std::is_same_v<decltype(std::declval<Array<int> &>()[0]), int &>);
312
313 using CQ = const ArrayQueue<int> &;
314 static_assert(std::is_same_v<decltype(std::declval<CQ>().front()), const int &>);
315 static_assert(std::is_same_v<decltype(std::declval<CQ>().rear()), const int &>);
316 static_assert(std::is_same_v<decltype(std::declval<CQ>()[0]), const int &>);
317 static_assert(std::is_same_v<decltype(std::declval<CQ>().top()), const int &>);
318 static_assert(std::is_same_v<decltype(std::declval<ArrayQueue<int> &>().front()), int &>);
319
320 using CL = const DynList<int> &;
321 static_assert(std::is_same_v<decltype(std::declval<CL>().get_first()), const int &>);
322 static_assert(std::is_same_v<decltype(std::declval<CL>().get_last_ne()), const int &>);
323 static_assert(std::is_same_v<decltype(std::declval<CL>().top()), const int &>);
324 static_assert(std::is_same_v<decltype(std::declval<DynList<int> &>().get_first()), int &>);
325
326 using CD = const DynDlist<int> &;
327 static_assert(std::is_same_v<decltype(std::declval<CD>().get_first()), const int &>);
328 static_assert(std::is_same_v<decltype(std::declval<CD>()[0]), const int &>);
329 static_assert(std::is_same_v<decltype(std::declval<DynDlist<int> &>()[0]), int &>);
330
331 using CDA = const DynArray<int> &;
332 static_assert(std::is_same_v<decltype(std::declval<CDA>()(0)), const int &>);
333 static_assert(std::is_same_v<decltype(std::declval<CDA>().access(0)), const int &>);
334 static_assert(std::is_same_v<decltype(std::declval<CDA>().top()), const int &>);
335
336 static_assert(std::is_same_v<decltype(std::declval<const DynSetTree<int> &>().find(0)), const int &>);
337 static_assert(std::is_same_v<decltype(std::declval<const DynSetTree<int> &>().search(0)), const int *>);
338 static_assert(std::is_same_v<decltype(std::declval<DynSetTree<int> &>().find(0)), int &>);
339 static_assert(std::is_same_v<decltype(std::declval<const DynMapTree<int, int> &>().search(0)),
340 const std::pair<int, int> *>);
341 static_assert(std::is_same_v<decltype(std::declval<const HashSet<int> &>().get_first()), const int &>);
342 static_assert(std::is_same_v<decltype(std::declval<const DynSetHash<int> &>().search(0)), const int *>);
343 static_assert(std::is_same_v<decltype(std::declval<DynSetHash<int> &>().search(0)), int *>);
344 static_assert(std::is_same_v<decltype(std::declval<const DynMapHash<int, int> &>().search(0)),
345 const std::pair<int, int> *>);
346 static_assert(std::is_same_v<decltype(std::declval<const ODhashTable<int> &>().search(0)), const int *>);
347 static_assert(std::is_same_v<decltype(std::declval<const OLhashTable<int> &>().search(0)), const int *>);
348 static_assert(std::is_same_v<decltype(std::declval<const DynSkipList<int> &>().search(0)), const int *>);
349 static_assert(std::is_same_v<decltype(std::declval<DynSkipList<int> &>().search(0)), int *>);
350 static_assert(std::is_same_v<decltype(std::declval<const DynBinHeap<int> &>().top()), const int &>);
351 static_assert(std::is_same_v<decltype(std::declval<const DynList<int> &>().nth(0)), const int &>);
352
353 // The modifiable path still writes.
354 DynList<int> l = {1, 2};
355 l.get_first() = 5;
356 l.nth(1) = 6;
357 EXPECT_EQ(l.get_first(), 5);
358 EXPECT_EQ(l.get_last(), 6);
360 m.insert(1, 10);
361 m.find(1) = 11;
362 EXPECT_EQ(m.find(1), 11);
363 EXPECT_EQ(std::as_const(m).search(1)->second, 11);
364}
365
366TEST(ConstIterator, the_leaks_found_from_a_client_no_longer_compile)
367{
368 // DynArray::operator()(size_t) const handed out T &.
369 static_assert(not writes_through_call<DynArray<int>>);
370 // The iterator of a constant Array handed out T & from get_curr().
371 static_assert(not std::is_constructible_v<Array<int>::Iterator, const Array<int> &>);
372 static_assert(not writes_through_curr<Array<int>::Const_Iterator>);
373 static_assert(writes_through_curr<Array<int>::Iterator>);
374 // SmallVector::traverse() const passed T & to the operation.
375 static_assert(not const_traverse_takes_a_modifying_operation<SmallVector<int, 4>>);
376 static_assert(const_traverse_takes_a_reading_operation<SmallVector<int, 4>>);
377 static_assert(not const_traverse_takes_a_modifying_operation<DynList<int>>);
378 static_assert(const_traverse_takes_a_reading_operation<DynList<int>>);
379 // Through a constant DynArray, the shared default value cannot be written.
380 static_assert(not writes_through_curr<DynArray<int>::Const_Iterator>);
381 // A Const_Iterator has no modifying members.
382 static_assert(not removes_through_it<DynList<int>::Const_Iterator>);
383 static_assert(removes_through_it<DynList<int>::Iterator>);
384}
385
386TEST(ConstIterator, the_generic_code_reads_constant_containers)
387{
388 const DynList<int> a = {1, 2, 3};
389 const DynList<int> b = {4, 5, 6};
390
391 // zip, pairs and filters.
392 int sum = 0;
393 for (auto it = get_pair_it(a, b); it.has_curr(); it.next_ne())
394 {
395 const auto [x, y] = it.get_curr();
396 sum += x * y;
397 }
398 EXPECT_EQ(sum, 4 + 10 + 18);
399 EXPECT_EQ(zip(a, b).size(), 3u);
400
402 odd(a, [] (const int & x) { return x % 2 == 1; });
403 static_assert(std::is_same_v<decltype(odd)::Item_Type, int>);
404 int count = 0;
405 for (; odd.has_curr(); odd.next())
406 ++count;
407 EXPECT_EQ(count, 2);
408
409 // The mixins and the free functions.
410 EXPECT_TRUE(a.all([] (const int & x) { return x > 0; }));
411 EXPECT_EQ(*a.find_ptr([] (const int & x) { return x == 2; }), 2);
412 static_assert(std::is_same_v<decltype(a.find_ptr([] (const int & x) { return x == 2; })), const int *>);
413 EXPECT_EQ(a.nth(2), 3);
414 EXPECT_TRUE(a == DynList<int>({1, 2, 3}));
415 EXPECT_FALSE(a == b);
416 ASSERT_NE(min_ptr(a), nullptr);
417 EXPECT_EQ(*min_ptr(a), 1);
418}
STL-compatible iterator adapters for Aleph containers.
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
Queue implemented with a single dynamic array.
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:331
Read-only view of an Aleph iterator: the iterator of a constant container.
auto reset_first() noexcept(noexcept(std::declval< I & >().reset_first())) -> decltype(std::declval< I & >().reset_first())
Position the view on the first item.
auto is_in_last() const noexcept(noexcept(std::declval< I & >().is_in_last())) -> decltype(std::declval< I & >().is_in_last())
true if the current item is the last one.
auto reset_last() noexcept(noexcept(std::declval< I & >().reset_last())) -> decltype(std::declval< I & >().reset_last())
Position the view on the last item.
auto get_pos() const noexcept(noexcept(std::declval< I & >().get_pos())) -> decltype(std::declval< I & >().get_pos())
Ordinal position of the current item.
auto prev() noexcept(noexcept(std::declval< I & >().prev())) -> decltype(std::declval< I & >().prev())
Move to the previous item; what the underlying iterator throws.
void swap(Const_Iterator &other) noexcept(std::is_nothrow_swappable_v< It >)
Exchange the views.
auto end() noexcept(noexcept(std::declval< I & >().end())) -> decltype(std::declval< I & >().end())
Position the view past the last item.
auto next() noexcept(noexcept(std::declval< I & >().next())) -> decltype(std::declval< I & >().next())
Move to the next item; what the underlying iterator throws.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
auto get_curr_ne() const noexcept(noexcept(std::declval< I & >().get_curr_ne())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr_ne())>
get_curr() without the checks of the underlying iterator.
auto get_curr() const noexcept(noexcept(std::declval< I & >().get_curr())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr())>
The current item, read-only.
Iterator on the items of array.
T & get_curr() const
Return the current item.
void set_default_initial_value(const T &value) noexcept(std::is_nothrow_copy_assignable_v< T >)
Set the default value.
Iterator get_it()
Iterator on the modifiable array, positioned on entry 0.
const T & read(const size_t i) const
Read entry i without allocating memory.
T & get_first()
Return a modifiable reference to the first item of array (as if this was a queue)
bool exist(const size_t i) const
Return true if the i-th entry is accessible.
T & get_last()
Return a modifiable reference to the last item of array (as if this was a queue)
Dynamic doubly linked list with O(1) size and bidirectional access.
Iterator on the items of list.
Definition htlist.H:1614
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & get_first()
Return the first item of the list.
Definition htlist.H:1548
T & append(const T &item)
Definition htlist.H:1362
T & get_last()
Return the last item of the list.
Definition htlist.H:1529
Generic key-value map implemented on top of a binary search tree.
Dynamic ordered set implemented with a Skip List.
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Definition ah-dry.H:1666
Type & nth(const size_t n)
Return the n-th item of the container.
Definition ah-dry.H:774
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr(Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:825
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Definition hashDry.H:507
Key & find(const Key &key)
Finds a key and returns a reference to it.
Definition hashDry.H:782
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
constexpr bool const_iterator_is_as_large_as_the_iterator
#define TEST(name)
Generic filter iterator wrapper for Aleph containers.
Singly linked list implementations with head-tail access.
static mpfr_t y
Definition mpfr_mul_d.c:3
Main namespace for Aleph-w library functions.
T Item_Type
Type of elements from the first container.
Definition ah-zip.H:161
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
auto get_curr() const
Return the current tuple (bounds-checked).
Definition ah-zip.H:192
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
Definition ahAlgo.H:230
and
Check uniqueness with explicit hash + equality functors.
Itor1 search(Itor1 beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Search for a subrange within a range.
Definition ahAlgo.H:309
auto get_pair_it(C1 &c1, C2 &c2)
Create a Pair_Iterator for two containers.
auto iterator_for(C &c)
Iterator on c positioned on its first item: the container's own iterator on a modifiable container.
const Container::Item_Type * min_ptr(const Container &container, Cmp cmp=Cmp())
Find the minimum element in a container.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Fixed-capacity binary heap and heapsort algorithms.
Circular queue implementations backed by arrays.
Stack implementations backed by dynamic or fixed arrays.
Dynamic array container with automatic resizing.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.
Dynamic key-value map based on balanced binary search trees.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Dynamic ordered set implemented with a Skip List.
Unified hash table interface.
Simple, scalable, contiguous dynamic array.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.
Random access queue (bag) with O(1) random pop.
Dynamic array with inline storage (Aleph::SmallVector).
DynList< int > l