Skip to main content

intrusive-list.h File

C++ header file with the declarations for the µOS++ intrusive list iterator and list class templates. More...

Included Headers

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespaceutils

The µOS++ utilities definitions. More...

Classes Index

classintrusive_list<T, N, MP, L, U>

A class template for a list of nodes which store the links inside themselves as intrusive nodes. More...

classintrusive_list_iterator<T, N, MP, U>

A class template for the intrusive list iterator. More...

Description

C++ header file with the declarations for the µOS++ intrusive list iterator and list class templates.

The intrusive-list.h header file contains the C++ declarations of the intrusive_list_iterator and intrusive_list class templates.

The class implementations are in intrusive-list-inlines.h.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 */
11
12// ----------------------------------------------------------------------------
24
25#ifndef MICRO_OS_PLUS_UTILS_LISTS_INTRUSIVE_LIST_H_
26#define MICRO_OS_PLUS_UTILS_LISTS_INTRUSIVE_LIST_H_
27
28// ----------------------------------------------------------------------------
29
30#include "doubly-list.h"
31
32// ----------------------------------------------------------------------------
33
34#if defined(__cplusplus)
35
36// ----------------------------------------------------------------------------
37
38#if defined(__GNUC__)
39#pragma GCC diagnostic push
40
41#pragma GCC diagnostic ignored "-Waggregate-return"
42#if defined(__clang__)
43#pragma clang diagnostic ignored "-Wc++98-compat"
44#endif // defined(__clang__)
45#endif // defined(__GNUC__)
46
48{
49 // ==========================================================================
50
69 template <class T, class N, N T::* MP, class U = T>
71 {
72 public:
76 using value_type = U;
77
82
87
91 using iterator_pointer = N*;
92
96 using difference_type = ptrdiff_t;
97
101 using iterator_category = std::bidirectional_iterator_tag;
102
103 // ------------------------------------------------------------------------
104
109 constexpr intrusive_list_iterator () noexcept;
110
116 constexpr explicit intrusive_list_iterator (
117 iterator_pointer const node) noexcept;
118
129 constexpr explicit intrusive_list_iterator (reference element) noexcept
130 requires std::derived_from<U, T>;
131
132 // DO NOT delete the copy constructors, since this implies that
133 // the default ones will be used.
134
140 [[nodiscard]] pointer
141 operator->() const noexcept;
142
148 [[nodiscard]] reference
149 operator* () const noexcept;
150
157 operator++ () noexcept;
158
165 operator++ (int) noexcept;
166
173 operator-- () noexcept;
174
181 operator-- (int) noexcept;
182
194 [[nodiscard]] constexpr bool
195 operator== (const intrusive_list_iterator& other) const noexcept;
196
204 [[nodiscard]] pointer
205 get_pointer (void) const noexcept;
206
214 [[nodiscard]] constexpr iterator_pointer
215 get_iterator_pointer (void) const noexcept;
216
217 protected:
225 };
226
227 // ==========================================================================
228
229#if defined(__clang__)
230#pragma clang diagnostic push
231#pragma clang diagnostic ignored "-Wdocumentation"
232#endif // defined(__clang__)
272#if defined(__clang__)
273#pragma clang diagnostic pop
274#endif // defined(__clang__)
275
276 template <class T, doubly_list_links_node N, N T::* MP,
278 class intrusive_list : public doubly_list<N, L>
279 {
280 public:
285 using links_type = L;
286
290 using value_type = U;
291
296
301
306
310 using reverse_iterator = std::reverse_iterator<iterator>;
311
316 typename links_type::is_statically_allocated;
317
321 using iterator_pointer = N*;
322
326 using difference_type = ptrdiff_t;
327
331 constexpr intrusive_list () noexcept;
332
333 // This class follows the rule of five.
334
343 intrusive_list (const intrusive_list&) = delete;
344
354
364 operator= (const intrusive_list&)
365 = delete;
366
375 operator= (intrusive_list&&)
376 = delete;
377
381 constexpr ~intrusive_list ();
382
383 public:
392 bool
393 initialise_once (void) noexcept;
394
403 [[nodiscard]] constexpr bool
404 empty (void) const noexcept;
405
413 void
414 link_tail (reference node) noexcept;
415
423 void
424 link_head (reference node) noexcept;
425
434 [[nodiscard]] pointer
435 unlink_tail (void) noexcept;
436
445 [[nodiscard]] pointer
446 unlink_head (void) noexcept;
447
448 // ------------------------------------------------------------------------
449
455 [[nodiscard]] iterator
456 begin () const noexcept;
457
463 [[nodiscard]] iterator
464 end () const noexcept;
465
471 [[nodiscard]] reverse_iterator
472 rbegin () const noexcept;
473
479 [[nodiscard]] reverse_iterator
480 rend () const noexcept;
481
482 // ------------------------------------------------------------------------
483 protected:
490 [[nodiscard]] pointer
491 get_pointer (iterator_pointer node) const noexcept;
492 };
493
494 // --------------------------------------------------------------------------
495} // namespace micro_os_plus::utils
496
497#if defined(__GNUC__)
498#pragma GCC diagnostic pop
499#endif // defined(__GNUC__)
500
501// ----------------------------------------------------------------------------
502
503#endif // defined(__cplusplus)
504
505// ============================================================================
506// Templates & constexpr implementations.
507
509
510// ----------------------------------------------------------------------------
511
512#endif // MICRO_OS_PLUS_UTILS_LISTS_INTRUSIVE_LIST_H_
513
514// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.