IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
resizable_container.hxx
Go to the documentation of this file.
1
3
4#pragma once
6
7namespace ice::container
8{
9
11 {
12 template<ice::concepts::ResizableContainer Self>
13 constexpr bool is_full(this Self const& self) noexcept
14 {
15 return self.size() == self.capacity();
16 }
17
18 template<ice::concepts::ResizableContainer Self>
19 constexpr bool not_full(this Self const& self) noexcept
20 {
21 return self.size() < self.capacity();
22 }
23
24 template<ice::concepts::ResizableContainer Self>
25 constexpr void reserve(this Self& self, ice::ncount min_capacity) noexcept
26 {
27 if (self.capacity() < min_capacity)
28 {
29 self.set_capacity(min_capacity);
30 }
31 }
32
33 template<ice::concepts::ResizableContainer Self>
34 constexpr void grow(this Self& self, ice::ncount min_capacity = ice::ncount_none) noexcept
35 {
36 ice::ncount new_capacity = self.capacity() * 2 + 4;
37 if (new_capacity < min_capacity)
38 {
39 new_capacity = min_capacity;
40 }
41 self.set_capacity(new_capacity);
42 }
43
44 template<ice::concepts::ResizableContainer Self>
45 constexpr void shrink(this Self& self) noexcept
46 {
47 self.set_capacity(self.size());
48 }
49 };
50
51} // namespace ice
Definition associative_container.hxx:8
static constexpr ice::ncount_invalid_t ncount_none
Definition ncount.hxx:60
Definition resizable_container.hxx:11
constexpr void reserve(this Self &self, ice::ncount min_capacity) noexcept
Definition resizable_container.hxx:25
constexpr bool is_full(this Self const &self) noexcept
Definition resizable_container.hxx:13
constexpr void grow(this Self &self, ice::ncount min_capacity=ice::ncount_none) noexcept
Definition resizable_container.hxx:34
constexpr bool not_full(this Self const &self) noexcept
Definition resizable_container.hxx:19
constexpr void shrink(this Self &self) noexcept
Definition resizable_container.hxx:45
Definition ncount.hxx:14