HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
small_vector.hpp
1// Copyright Take Vos 2019.
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 "required.hpp"
8#include <array>
9
10namespace tt {
11
12template<typename T,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 _end = items.begin();
25 }
26
27 constexpr auto begin() noexcept {
28 return items.begin();
29 }
30
31 constexpr auto end() noexcept {
32 return _end;
33 }
34
35 constexpr size_t size() const noexcept {
36 return static_cast<size_t>(_end - items.begin());
37 }
38
39 constexpr void clear() noexcept {
40 _end = items.begin();
41 }
42
43 constexpr bool push_back(value_type &&value) noexcept {
44 if (_end == items.end()) {
45 return false;
46 }
47 *(_end++) = std::move(value);
48 return true;
49 }
50
51 constexpr bool push_back(value_type const &value) noexcept {
52 if (_end == items.end()) {
53 return false;
54 }
55 *(_end++) = value;
56 return true;
57 }
58
59};
60
61}
Definition small_vector.hpp:13
T begin(T... args)
T end(T... args)
T move(T... args)