Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
circular_buffer.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_CIRCULAR_BUFFER_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_CIRCULAR_BUFFER_HPP_
7
8
#
include
"arene/base/constraints/constraints.hpp"
9
#
include
"arene/base/inline_container/deque.hpp"
10
#
include
"arene/base/inline_container/detail/try_construct_interface.hpp"
11
#
include
"arene/base/iterator/distance.hpp"
12
#
include
"arene/base/stdlib_choice/cstddef.hpp"
13
#
include
"arene/base/stdlib_choice/enable_if.hpp"
14
#
include
"arene/base/stdlib_choice/initializer_list.hpp"
15
#
include
"arene/base/stdlib_choice/is_constructible.hpp"
16
#
include
"arene/base/stdlib_choice/is_copy_constructible.hpp"
17
#
include
"arene/base/stdlib_choice/iterator_traits.hpp"
18
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
19
20
// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
21
22
namespace
arene
{
23
namespace
base
{
24
25
/// @brief A container with fixed capacity featuring constant time insertion and
26
/// removal at opposite ends; i.e., with an interface similar to std::queue. The
27
/// storage for the elements is held directly within the class. Storing more
28
/// than @c Capacity elements results in overwriting the oldest element.
29
/// @tparam T The type of each element
30
/// @tparam Capacity The maximum number of elements that can be stored
31
// parasoft-begin-suppress AUTOSAR-A10_1_1-a "False positive: try_construct_interface is an interface"
32
template
<
typename
T, std::size_t Capacity>
33
class
circular_buffer
34
:
private
inline_deque_detail
::
inline_deque_impl
<
T
,
Capacity
,
true
>
35
,
public
inline_container_detail
::
try_construct_interface
<
36
circular_buffer
<
T
,
Capacity
>,
37
typename
inline_deque_detail
::
inline_deque_try_construct_policy
<
T
,
Capacity
>> {
38
/// @brief The implementation class, separate to share implementations with other similar queues
39
using
impl
=
inline_deque_detail
::
inline_deque_impl
<
T
,
Capacity
,
true
>;
40
41
/// @brief Shorthand to the mixin type that synthesizes @c try_construct functions based on the normal constructors
42
using
try_construct_interface
=
inline_container_detail
::
try_construct_interface
<
43
circular_buffer
,
44
typename
inline_deque_detail
::
inline_deque_try_construct_policy
<
T
,
Capacity
>>;
45
46
public
:
47
/// @copydoc impl::const_iterator
48
using
typename
impl
::
const_iterator
;
49
/// @copydoc impl::const_reference
50
using
typename
impl
::
const_reference
;
51
/// @copydoc impl::iterator
52
using
typename
impl
::
iterator
;
53
/// @copydoc impl::reference
54
using
typename
impl
::
reference
;
55
/// @copydoc impl::size_type
56
using
typename
impl
::
size_type
;
57
/// @copydoc impl::value_type
58
using
typename
impl
::
value_type
;
59
60
/// @copydoc impl::wrapping_allowed
61
using
impl
::
wrapping_allowed
;
62
63
// parasoft-begin-suppress AUTOSAR-A12_7_1-a "False positive: this is not the default implementation"
64
// parasoft-begin-suppress AUTOSAR-A12_1_1-a "False positive: all base class constructors are explicitly called"
65
/// @brief Construct an empty queue
66
constexpr
circular_buffer
()
noexcept
67
:
impl
(),
68
try_construct_interface
(
this
) {}
69
// parasoft-end-suppress AUTOSAR-A12_7_1-a
70
// parasoft-end-suppress AUTOSAR-A12_1_1-a
71
72
/// @brief Construct a queue from a range of elements, taken to be in front -> back order
73
/// @tparam Iterator The type of the iterators to construct from
74
/// @param in_begin An iterator to the beginning (front) of the input range
75
/// @param in_end An iterator to the end (back+1) of the input range
76
/// @pre <c>distance(in_begin, in_end) >= 0</c> and <c><= capacity()</c>, otherwise @c ARENE_PRECONDITION violation
77
/// @pre If the behaviour of <c>distance(in_begin, in_end)</c> is undefined, then this function's behaviour is too
78
template
<
79
typename
Iterator
,
80
constraints
<
81
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
Iterator
>>,
82
std
::
enable_if_t
<
83
std
::
is_constructible
<
value_type
,
typename
std
::
iterator_traits
<
Iterator
>::
reference
>::
value
>> =
nullptr
>
84
constexpr
circular_buffer
(
Iterator
in_begin
,
Iterator
in_end
)
noexcept
(
85
noexcept
(::
arene
::
base
::
distance
(
in_begin
,
in_end
)) &&
86
std
::
is_nothrow_constructible
<
value_type
,
typename
std
::
iterator_traits
<
Iterator
>::
reference
>::
value
87
)
88
:
impl
(
in_begin
,
in_end
),
89
try_construct_interface
(
this
) {}
90
91
// parasoft-begin-suppress AUTOSAR-A12_1_1-a "False positive: this is a delegating constructor"
92
/// @brief Construct a queue by copying from an initializer list of elements, taken to be in front -> back order
93
/// @param init An initializer list of the value type
94
/// @pre <c>init.size() <= capacity()</c>, otherwise @c ARENE_PRECONDITION violation
95
template
<
typename
U
=
value_type
,
constraints
<
std
::
enable_if_t
<
std
::
is_copy_constructible
<
U
>::
value
>> =
nullptr
>
96
constexpr
circular_buffer
(
std
::
initializer_list
<
value_type
>
init
97
)
noexcept
(
noexcept
(
circular_buffer
(
init
.
begin
(),
init
.
end
())))
98
:
circular_buffer
(
init
.
begin
(),
init
.
end
()) {}
99
// parasoft-end-suppress AUTOSAR-A12_1_1-a
100
101
/// @copydoc impl::capacity
102
using
impl
::
capacity
;
103
/// @copydoc impl::empty
104
using
impl
::
empty
;
105
/// @copydoc impl::size
106
using
impl
::
size
;
107
108
/// @copydoc impl::begin
109
using
impl
::
begin
;
110
/// @copydoc impl::cbegin
111
using
impl
::
cbegin
;
112
/// @copydoc impl::cend
113
using
impl
::
cend
;
114
/// @copydoc impl::crbegin
115
using
impl
::
crbegin
;
116
/// @copydoc impl::crend
117
using
impl
::
crend
;
118
/// @copydoc impl::end
119
using
impl
::
end
;
120
/// @copydoc impl::rbegin
121
using
impl
::
rbegin
;
122
/// @copydoc impl::rend
123
using
impl
::
rend
;
124
125
/// @copydoc impl::back
126
using
impl
::
back
;
127
/// @copydoc impl::front
128
using
impl
::
front
;
129
/// @copydoc impl::operator[]
130
using
impl
::
operator
[];
131
132
/// @copydoc impl::emplace_back
133
using
impl
::
emplace_back
;
134
/// @copydoc impl::pop_front
135
using
impl
::
pop_front
;
136
/// @copydoc impl::push_back
137
using
impl
::
push_back
;
138
};
139
// parasoft-end-suppress AUTOSAR-A10_1_1-a
140
141
}
// namespace base
142
}
// namespace arene
143
144
// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
145
146
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_CIRCULAR_BUFFER_HPP_
arene::base::circular_buffer
A container with fixed capacity featuring constant time insertion and removal at opposite ends; i....
Definition
circular_buffer.hpp:37
arene::base::circular_buffer::circular_buffer
constexpr circular_buffer() noexcept
Construct an empty queue.
Definition
circular_buffer.hpp:66
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
inline_container
circular_buffer.hpp
Generated by
1.13.2