HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
small_vector.hpp
1// Copyright Take Vos 2019, 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <array>
10
11
12
13namespace hi::inline v1 {
14
15template<typename T, std::size_t N>
17 using value_type = T;
19 using iterator = typename array_type::iterator;
20 using const_iterator = typename array_type::iterator;
21
22 array_type items;
23 iterator _end;
24
25public:
26 constexpr small_vector() noexcept
27 {
28 _end = items.begin();
29 }
30
31 constexpr auto begin() noexcept
32 {
33 return items.begin();
34 }
35
36 constexpr auto end() noexcept
37 {
38 return _end;
39 }
40
41 constexpr std::size_t size() const noexcept
42 {
43 return static_cast<std::size_t>(_end - items.begin());
44 }
45
46 constexpr void clear() noexcept
47 {
48 _end = items.begin();
49 }
50
51 constexpr bool push_back(value_type &&value) noexcept
52 {
53 if (_end == items.end()) {
54 return false;
55 }
56 *(_end++) = std::move(value);
57 return true;
58 }
59
60 constexpr bool push_back(value_type const &value) noexcept
61 {
62 if (_end == items.end()) {
63 return false;
64 }
65 *(_end++) = value;
66 return true;
67 }
68};
69
70} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition small_vector.hpp:16
T begin(T... args)
T end(T... args)
T move(T... args)