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.hpp"
8#include <array>
9
10namespace hi::inline v1 {
11
12template<typename T, std::size_t N>
14 using value_type = T;
16 using iterator = typename array_type::iterator;
17 using const_iterator = typename array_type::iterator;
18
19 array_type items;
20 iterator _end;
21
22public:
23 constexpr small_vector() noexcept
24 {
25 _end = items.begin();
26 }
27
28 constexpr auto begin() noexcept
29 {
30 return items.begin();
31 }
32
33 constexpr auto end() noexcept
34 {
35 return _end;
36 }
37
38 constexpr std::size_t size() const noexcept
39 {
40 return static_cast<std::size_t>(_end - items.begin());
41 }
42
43 constexpr void clear() noexcept
44 {
45 _end = items.begin();
46 }
47
48 constexpr bool push_back(value_type &&value) noexcept
49 {
50 if (_end == items.end()) {
51 return false;
52 }
53 *(_end++) = std::move(value);
54 return true;
55 }
56
57 constexpr bool push_back(value_type const &value) noexcept
58 {
59 if (_end == items.end()) {
60 return false;
61 }
62 *(_end++) = value;
63 return true;
64 }
65};
66
67} // namespace hi::inline v1
Utilities used by the HikoGUI library itself.
DOXYGEN BUG.
Definition algorithm.hpp:15
Definition small_vector.hpp:13
T begin(T... args)
T end(T... args)
T move(T... args)