[ox/std] Fix Vector::emplace_back and make_unique to properly forward arguments

This commit is contained in:
Gary Talent 2021-07-23 03:30:00 -05:00
parent bed8c35218
commit b6b9837bbf
2 changed files with 12 additions and 2 deletions

View File

@ -29,6 +29,8 @@ class UniquePtr {
explicit constexpr UniquePtr(T *t = nullptr) noexcept: m_t(t) {
}
constexpr UniquePtr(UniquePtr&) = delete;
constexpr UniquePtr(const UniquePtr&) = delete;
template<typename U>
@ -114,7 +116,7 @@ constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
template<typename T, typename ...Args>
[[nodiscard]]
constexpr auto make_unique(Args&&... args) {
return UniquePtr(new T(args...));
return UniquePtr(new T(static_cast<Args&&>(args)...));
}
}

View File

@ -24,6 +24,10 @@ struct SmallVector {
private:
AllocAlias<T> m_data[Size] = {};
public:
SmallVector() noexcept = default;
SmallVector(SmallVector&) noexcept = default;
SmallVector(SmallVector&&) noexcept = default;
protected:
constexpr void initItems(T **items, std::size_t cap) noexcept {
if (cap <= Size) {
@ -54,6 +58,10 @@ struct SmallVector {
template<typename T>
struct SmallVector<T, 0> {
public:
SmallVector() noexcept = default;
SmallVector(SmallVector&) noexcept = default;
SmallVector(SmallVector&&) noexcept = default;
protected:
constexpr void initItems(T **items, std::size_t cap) noexcept {
*items = bit_cast<T*>(new AllocAlias<T>[cap]);
@ -480,7 +488,7 @@ void Vector<T, SmallVectorSize>::emplace_back(Args&&... args) {
if (m_size == m_cap) {
expandCap(m_cap ? m_cap * 2 : 100);
}
new (&m_items[m_size]) T{args...};
new (&m_items[m_size]) T{static_cast<Args>(args)...};
++m_size;
}