[ox/std] Fix Vector::emplace_back and make_unique to properly forward arguments
This commit is contained in:
parent
bed8c35218
commit
b6b9837bbf
4
deps/ox/src/ox/std/memory.hpp
vendored
4
deps/ox/src/ox/std/memory.hpp
vendored
@ -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)...));
|
||||
}
|
||||
|
||||
}
|
||||
|
10
deps/ox/src/ox/std/vector.hpp
vendored
10
deps/ox/src/ox/std/vector.hpp
vendored
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user