-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.hpp
47 lines (37 loc) · 1.55 KB
/
Vector.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <algorithm>
#include <vector>
/*
* Wrapping std::vector, because I kinda like the QVector's interface,
* but the thing doesn't support move-semantics in reallocs.
* Might revert to QVector some time in the future, when Qt finally advances
* to 21st century.
*/
template <typename T>
class Vector {
public:
Vector() = default;
Vector(Vector &&other) = default;
Vector(std::initializer_list <T> elems) : m_data{elems} {}
~Vector() = default;
Vector & operator = (Vector &&) = default;
void clear() noexcept { m_data.clear(); }
bool contains(const T &value) const noexcept { return std::find(m_data.begin(), m_data.end(), value) != m_data.end(); }
int count() const noexcept { return m_data.size(); }
bool empty() const noexcept { return m_data.empty(); }
T & front() noexcept { return m_data.front(); }
const T & front() const noexcept { return m_data.front(); }
T & back() noexcept { return m_data.back(); }
const T & back() const noexcept { return m_data.back(); }
template <typename TT>
void push_back(TT &&value) noexcept { m_data.push_back(std::forward<TT>(value)); }
void pop_back() noexcept { m_data.pop_back(); }
decltype(auto) begin() noexcept { return m_data.begin(); }
decltype(auto) begin() const noexcept { return m_data.begin(); }
decltype(auto) cbegin() const noexcept { return m_data.begin(); }
decltype(auto) end() noexcept { return m_data.end(); }
decltype(auto) end() const noexcept { return m_data.end(); }
decltype(auto) cend() const noexcept { return m_data.end(); }
private:
std::vector <T> m_data;
};