iceoryx_hoofs 2.0.3
stack.hpp
1// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16#ifndef IOX_HOOFS_CXX_STACK_HPP
17#define IOX_HOOFS_CXX_STACK_HPP
18
19#include "iceoryx_hoofs/cxx/optional.hpp"
20#include <cstdint>
21
22namespace iox
23{
24namespace cxx
25{
29template <typename T, uint64_t Capacity>
30class stack
31{
32 public:
36
41 template <typename... Targs>
42 bool push(Targs&&... args) noexcept;
43
45 uint64_t size() const noexcept;
46
48 static constexpr uint64_t capacity() noexcept;
49
50 private:
51 using element_t = uint8_t[sizeof(T)];
52 alignas(T) element_t m_data[Capacity];
53 uint64_t m_size = 0U;
54};
55} // namespace cxx
56} // namespace iox
57
58#include "iceoryx_hoofs/internal/cxx/stack.inl"
59
60#endif
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition: optional.hpp:69
stack implementation with a simple push pop interface
Definition: stack.hpp:31
uint64_t size() const noexcept
returns the stack size
bool push(Targs &&... args) noexcept
pushed an element into the stack by forwarding all arguments to the constructor of T
static constexpr uint64_t capacity() noexcept
returns the stack capacity
cxx::optional< T > pop() noexcept
returns the last pushed element when the stack contains elements otherwise a cxx::nullopt
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29