CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
13#include <vector>
14
15namespace CeresEngine {
17 template<typename T, typename RawAllocator = DefaultAllocator> using Vector = std::vector<T, ScopedAllocatorAdaptor<StdAllocator<T, RawAllocator>>>;
18
20 template<typename T> using TemporaryVector = Vector<T, TemporaryAllocator>;
21
24 template<typename RawAllocator, typename Range> auto toVector(Range& range) {
25 using T = std::decay_t<decltype(*range.begin())>;
26 return Vector<T, RawAllocator>(range.begin(), range.end());
27 }
28
31 template<typename RawAllocator, typename Range> auto toVector(Range&& range) {
32 using T = std::decay_t<decltype(*range.begin())>;
33 return Vector<T, RawAllocator>(range.begin(), range.end());
34 }
35
38 template<typename RawAllocator, typename Range> auto toVector(const Range& range) {
39 using T = std::decay_t<decltype(*range.begin())>;
40 return Vector<T, RawAllocator>(range.begin(), range.end());
41 }
42
45 template<typename Range> auto toVector(Range&& range) { return toVector<DefaultAllocator>(range); }
46
49 template<typename Range> auto toVector(const Range& range) { return toVector<DefaultAllocator>(range); }
50
53 template<typename Range> auto toTemporaryVector(Range& range) { return toVector<TemporaryAllocator>(range); }
54
57 template<typename Range> auto toTemporaryVector(const Range& range) { return toVector<TemporaryAllocator>(range); }
58
59} // namespace CeresEngine
60
61template<typename T, typename Allocator> struct std::hash<CeresEngine::Vector<T, Allocator>> {
63 inline size_t operator()(const Type& object) const noexcept {
64 size_t seed = CeresEngine::hash(object.size());
65 for(const T& value : object) {
66 CeresEngine::combine(seed, value);
67 }
68 return seed;
69 }
70};
Definition Application.hpp:19
auto toTemporaryVector(Range &range)
Converts a range into a TemporaryVector.
Definition Vector.hpp:53
Vector< T, TemporaryAllocator > TemporaryVector
A special Vector that uses a fast temporary allocator.
Definition Vector.hpp:20
auto range()
Returns an iterator that increases it's value from 0 to end by 1 for each step.
Definition Iterator.hpp:350
constexpr void combine(std::size_t &seed, const T &v)
Generates a new hash for the provided type using the default standard hasher and combines it with a p...
Definition Hash.hpp:32
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
auto toVector(Range &range)
Converts a range into a Vector using a custom RawAllocator.
Definition Vector.hpp:24
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25