iceoryx_hoofs 2.0.8
Loading...
Searching...
No Matches
vector.hpp
1// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// SPDX-License-Identifier: Apache-2.0
17#ifndef IOX_HOOFS_CXX_VECTOR_HPP
18#define IOX_HOOFS_CXX_VECTOR_HPP
19
20#include "iceoryx_hoofs/cxx/requires.hpp"
21
22#include <algorithm>
23#include <cstdint>
24#include <cstdio>
25#include <utility>
26
27namespace iox
28{
29namespace cxx
30{
37template <typename T, uint64_t Capacity>
38class vector
39{
40 public:
41 using value_type = T;
42
43 using iterator = T*;
44 using const_iterator = const T*;
45
47 vector() noexcept = default;
48
52 vector(const uint64_t count, const T& value) noexcept;
53
56 vector(const uint64_t count) noexcept;
57
59 vector(const vector& rhs) noexcept;
60
62 vector(vector&& rhs) noexcept;
63
66 ~vector() noexcept;
67
71 vector& operator=(const vector& rhs) noexcept;
72
76 vector& operator=(vector&& rhs) noexcept;
77
81 iterator begin() noexcept;
82
86 const_iterator begin() const noexcept;
87
90 iterator end() noexcept;
91
94 const_iterator end() const noexcept;
95
98 T* data() noexcept;
99
102 const T* data() const noexcept;
103
105 // is undefined if the element at index does not exist.
107 T& at(const uint64_t index) noexcept;
108
112 const T& at(const uint64_t index) const noexcept;
113
115 // is undefined if the element at index does not exist.
117 T& operator[](const uint64_t index) noexcept;
118
122 const T& operator[](const uint64_t index) const noexcept;
123
127 T& front() noexcept;
128
132 const T& front() const noexcept;
133
137 T& back() noexcept;
138
142 const T& back() const noexcept;
143
146 uint64_t capacity() const noexcept;
147
150 uint64_t size() const noexcept;
151
153 bool empty() const noexcept;
154
156 void clear() noexcept;
157
167 template <typename... Targs>
168 bool resize(const uint64_t count, const Targs&... args) noexcept;
169
173 template <typename... Targs>
174 bool emplace(const uint64_t position, Targs&&... args) noexcept;
175
178 template <typename... Targs>
179 bool emplace_back(Targs&&... args) noexcept;
180
183 bool push_back(const T& value) noexcept;
184
187 bool push_back(T&& value) noexcept;
188
191 bool pop_back() noexcept;
192
196 iterator erase(iterator position) noexcept;
197
198 private:
199 using element_t = uint8_t[sizeof(T)];
200 alignas(T) element_t m_data[Capacity];
201 uint64_t m_size = 0u;
202};
203} // namespace cxx
204} // namespace iox
205
206template <typename T, uint64_t CapacityLeft, uint64_t CapacityRight>
207bool operator==(const iox::cxx::vector<T, CapacityLeft>& lhs, const iox::cxx::vector<T, CapacityRight>& rhs) noexcept;
208
209template <typename T, uint64_t CapacityLeft, uint64_t CapacityRight>
210bool operator!=(const iox::cxx::vector<T, CapacityLeft>& lhs, const iox::cxx::vector<T, CapacityRight>& rhs) noexcept;
211
212#include "iceoryx_hoofs/internal/cxx/vector.inl"
213
214#endif // IOX_HOOFS_CXX_VECTOR_HPP
bool push_back(const PosixGroup &value) noexcept
bool emplace_back(Targs &&... args) noexcept
iterator erase(iterator position) noexcept
vector() noexcept=default
creates an empty vector
PosixGroup & at(const uint64_t index) noexcept
bool resize(const uint64_t count, const Targs &... args) noexcept
bool emplace(const uint64_t position, Targs &&... args) noexcept
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29