[ox/std] Add initializer_list constructor to Vector

This commit is contained in:
Gary Talent 2021-07-29 20:29:49 -05:00
parent 99d342b8b3
commit 24ca5623e8

View File

@ -8,6 +8,10 @@
#pragma once #pragma once
#if __has_include(<initializer_list>)
#include <initializer_list>
#endif
#include "bit.hpp" #include "bit.hpp"
#include "iterator.hpp" #include "iterator.hpp"
#include "math.hpp" #include "math.hpp"
@ -186,6 +190,10 @@ class Vector: detail::SmallVector<T, SmallVectorSize> {
explicit Vector(std::size_t size) noexcept; explicit Vector(std::size_t size) noexcept;
#if __has_include(<initializer_list>)
Vector(std::initializer_list<T> list) noexcept;
#endif
Vector(const Vector &other); Vector(const Vector &other);
Vector(Vector &&other) noexcept; Vector(Vector &&other) noexcept;
@ -304,6 +312,15 @@ Vector<T, SmallVectorSize>::Vector(std::size_t size) noexcept {
} }
} }
#if __has_include(<initializer_list>)
template<typename T, std::size_t SmallVectorSize>
Vector<T, SmallVectorSize>::Vector(std::initializer_list<T> list) noexcept {
for (auto &item : list) {
emplace_back(item);
}
}
#endif
template<typename T, std::size_t SmallVectorSize> template<typename T, std::size_t SmallVectorSize>
Vector<T, SmallVectorSize>::Vector(const Vector &other) { Vector<T, SmallVectorSize>::Vector(const Vector &other) {
m_size = other.m_size; m_size = other.m_size;