OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
safe_vec.hpp
1#pragma once
3#include <ossia/detail/ptr_set.hpp>
4
5#include <vector>
6
7namespace ossia
8{
9template <typename T>
10class safe_vector
11{
12public:
13 safe_vector() { static_assert(sizeof(T) <= 64, "use this only for small types"); }
14
15 safe_vector(const safe_vector&) = delete;
16 safe_vector(safe_vector&&) noexcept = default;
17 safe_vector& operator=(const safe_vector&) = delete;
18 safe_vector& operator=(safe_vector&&) noexcept = default;
19
20 bool contains(T t) noexcept { return ossia::contains(impl, t); }
21
22 void clear() noexcept { impl.clear(); }
23
24 void push_back(T t) { impl.push_back(t); }
25
26 [[nodiscard]] bool empty() const noexcept { return impl.empty(); }
27
28 void remove_all(T t) { ossia::remove_erase(impl, t); }
29
30 void reserve(std::size_t N) { impl.reserve(N); }
31
32 auto size() const { return impl.size(); }
33
34 auto copy() const { return impl; }
35
36 auto& reference() noexcept { return impl; }
37
38 auto& reference() const noexcept { return impl; }
39
40private:
41 std::vector<T> impl;
42};
43
44template <typename T>
45class safe_set
46{
47public:
48 static_assert(sizeof(T) <= 64, "use this only for small types");
49 safe_set() = default;
50 safe_set(const safe_set&) = default;
51 safe_set(safe_set&&) noexcept = default;
52 safe_set& operator=(const safe_set&) = default;
53 safe_set& operator=(safe_set&&) noexcept = default;
54
55 bool contains(T t) { return ossia::contains(impl, t); }
56
57 void clear() { impl.clear(); }
58
59 void push_back(T t) { impl.insert(t); }
60
61 void remove_all(T t) { impl.erase(t); }
62
63 void reserve(std::size_t N) { impl.reserve(N); }
64
65 auto copy() const { return impl; }
66
67 auto& reference() { return impl; }
68
69 auto& reference() const { return impl; }
70
71 auto size() const { return impl.size(); }
72
73 auto empty() const { return impl.empty(); }
74
75 auto begin() const { return impl.begin(); }
76
77 auto end() const { return impl.end(); }
78
79private:
80 ossia::ptr_set<T> impl;
81};
82}
Definition git_info.h:7