[ox/std] Add proper forward function

This commit is contained in:
Gary Talent 2021-07-23 21:29:57 -05:00
parent 78d444c2e5
commit 7ea0654af6
4 changed files with 25 additions and 2 deletions

View File

@ -116,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(static_cast<Args&&>(args)...));
return UniquePtr(new T(forward<Args>(args)...));
}
}

View File

@ -175,4 +175,7 @@ struct remove_reference<T&&> {
using type = T;
};
template<typename T>
using remove_reference_t = typename remove_reference<T>::type;
}

View File

@ -12,9 +12,28 @@
namespace ox {
template<class T>
constexpr T &&forward(remove_reference_t<T> &t) noexcept {
return static_cast<T&&>(t);
}
template<class T>
constexpr T &&forward(remove_reference_t<T> &&t) noexcept {
return static_cast<T&&>(t);
}
template<typename T>
constexpr typename remove_reference<T>::type &&move(T &&t) noexcept {
return static_cast<typename remove_reference<T>::type&&>(t);
}
}
#if !__has_include(<utility>)
namespace std {
template<typename T>
constexpr typename ox::remove_reference<T>::type &&move(T &&t) noexcept {
return static_cast<typename ox::remove_reference<T>::type&&>(t);
}
}
#endif

View File

@ -67,6 +67,7 @@ struct SmallVector<T, 0> {
*items = bit_cast<T*>(new AllocAlias<T>[cap]);
}
[[maybe_unused]]
constexpr void moveItemsFrom(T**, SmallVector&, const std::size_t, const std::size_t) noexcept {
}
@ -488,7 +489,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{static_cast<Args>(args)...};
new (&m_items[m_size]) T{forward<Args>(args)...};
++m_size;
}