Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
singly_linked_node.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_SINGLY_LINKED_NODE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_SINGLY_LINKED_NODE_HPP_
7
8#include "arene/base/intrusive/detail/default_tag.hpp"
9
10// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
11
12namespace arene {
13namespace base {
14namespace intrusive {
15
16// Forward declare, so it can be referenced in the friend declaration
17// IWYU pragma: begin_keep
18template <typename T, typename Tag>
19class queue;
20// IWYU pragma: end_keep
21
22namespace detail {
23/// @brief Pass-key type for accessing singly-linked nodes
24class singly_linked_node_pass_key {
25 /// @brief Private constructor, so only friends can construct instances
26 constexpr explicit singly_linked_node_pass_key() = default;
27
28 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Passkey idiom permitted by by A11-3-1 Permit #1 v1.0.0"
29 /// @brief Friend declaration to allow @c intrusive_queue to construct instances.
30 /// @tparam T the type of element in the queue
31 /// @tparam Tag The tag of the element. Used to support adding the same
32 /// element to multiple intrusive containers.
33 template <typename T, typename Tag>
34 friend class intrusive::queue;
35 // parasoft-end-suppress AUTOSAR-A11_3_1-a
36};
37} // namespace detail
38
39/// @brief Singly linked hook. User type can be derived from this
40/// class to support intrusive containers.
41/// @tparam T The type of the element.
42/// @tparam Tag The tag of the element. Used to support adding the same
43/// element to multiple intrusive containers.
44template <class Tag = detail::default_tag>
46 /// @brief The next node in the list
47 singly_linked_node* next_{nullptr};
48
49 public:
50 // parasoft-begin-suppress AUTOSAR-A7_1_7-a "False positive: no expression statement and identifier declaration on
51 // same line"
52 /// @brief Check if the element is linked to a container.
53 /// @return @c true if the element is linked to a container, @c false
54 constexpr auto is_linked() const noexcept -> bool { return next_ != nullptr; }
55 // parasoft-end-suppress AUTOSAR-A7_1_7-a
56
57 // parasoft-begin-suppress AUTOSAR-A7_1_1-a "Declaring 'element' as reference to const changes semantics"
58 // parasoft-begin-suppress AUTOSAR-M7_1_2-c "Declaring 'element' as reference to const changes semantics"
59 // parasoft-begin-suppress AUTOSAR-A8_4_9-a "Declaring 'element' as reference to const changes semantics"
60 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
61 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
62 // translation units"
63 /// @brief Getter to the next_ member. singly_linked_node_pass_key idiom is
64 /// used to grant access only to the intrusive queue.
65 /// @param element The element to get the next_ member from
66 /// @return Reference to the next_ member
67 friend constexpr auto get_next_link(singly_linked_node& element, Tag, detail::singly_linked_node_pass_key) noexcept
69 return element.singly_linked_node<Tag>::next_;
70 }
71 // parasoft-end-suppress AUTOSAR-A0_1_3-a
72 // parasoft-end-suppress AUTOSAR-A11_3_1-a
73 // parasoft-end-suppress AUTOSAR-A8_4_9-a
74 // parasoft-end-suppress AUTOSAR-M7_1_2-c
75 // parasoft-end-suppress AUTOSAR-A7_1_1-a
76};
77} // namespace intrusive
78} // namespace base
79} // namespace arene
80#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_SINGLY_LINKED_NODE_HPP_
Intrusive queue implementation.
Definition queue.hpp:33
Singly linked hook. User type can be derived from this class to support intrusive containers.
Definition singly_linked_node.hpp:45
friend constexpr auto get_next_link(singly_linked_node &element, Tag, detail::singly_linked_node_pass_key) noexcept -> singly_linked_node *&
Getter to the next_ member. singly_linked_node_pass_key idiom is used to grant access only to the int...
Definition singly_linked_node.hpp:67
constexpr auto is_linked() const noexcept -> bool
Check if the element is linked to a container.
Definition singly_linked_node.hpp:54
Definition binary_tree_node.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10