Sane C++ Libraries
C++ Platform Abstraction Libraries
SmallVector.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Containers/Vector.h"
5
6namespace SC
7{
8template <typename T, int N>
9struct SmallVector;
10} // namespace SC
11
14
24template <typename T, int N>
25struct SC::SmallVector : public Vector<T>
26{
27 // clang-format off
28 SmallVector() : Vector<T>(inlineHeader, N * sizeof(T)) {}
29 SmallVector(const Vector<T>& other) : SmallVector() { Vector<T>::operator=(other); }
31 Vector<T>& operator=(const Vector<T>& other) { return Vector<T>::operator=(other); }
32 Vector<T>& operator=(Vector<T>&& other) { return Vector<T>::operator=(move(other)); }
33
34 SmallVector(const SmallVector& other) : SmallVector() { Vector<T>::operator=(other); }
36 SmallVector& operator=(const SmallVector& other) { Vector<T>::operator=(other); return *this; }
37 SmallVector& operator=(SmallVector&& other) { Vector<T>::operator=(move(other)); return *this; }
38 // clang-format on
39
40 private:
41 SegmentHeader inlineHeader;
42 char inlineBuffer[N * sizeof(T)];
43};
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition: Compiler.h:269
Definition: Segment.h:11
A Vector that can hold up to N elements inline and > N on heap.
Definition: SmallVector.h:26
A contiguous sequence of heap allocated elements.
Definition: Vector.h:257