diff options
Diffstat (limited to 'EASTL/include/EASTL/unique_ptr.h')
-rw-r--r-- | EASTL/include/EASTL/unique_ptr.h | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/EASTL/include/EASTL/unique_ptr.h b/EASTL/include/EASTL/unique_ptr.h index c5d2480..195cc42 100644 --- a/EASTL/include/EASTL/unique_ptr.h +++ b/EASTL/include/EASTL/unique_ptr.h @@ -536,27 +536,12 @@ namespace eastl /// /// auto pArray = make_unique<Test[]>(4); /// - namespace Internal - { - template <typename T> - struct unique_type - { typedef unique_ptr<T> unique_type_single; }; - - template <typename T> - struct unique_type<T[]> - { typedef unique_ptr<T[]> unique_type_unbounded_array; }; - - template <typename T, size_t N> - struct unique_type<T[N]> - { typedef void unique_type_bounded_array; }; - } - template <typename T, typename... Args> - inline typename Internal::unique_type<T>::unique_type_single make_unique(Args&&... args) + inline typename eastl::enable_if<!eastl::is_array<T>::value, eastl::unique_ptr<T>>::type make_unique(Args&&... args) { return unique_ptr<T>(new T(eastl::forward<Args>(args)...)); } template <typename T> - inline typename Internal::unique_type<T>::unique_type_unbounded_array make_unique(size_t n) + inline typename eastl::enable_if<eastl::is_unbounded_array<T>::value, eastl::unique_ptr<T>>::type make_unique(size_t n) { typedef typename eastl::remove_extent<T>::type TBase; return unique_ptr<T>(new TBase[n]); @@ -564,7 +549,7 @@ namespace eastl // It's not possible to create a unique_ptr for arrays of a known bound (e.g. int[4] as opposed to int[]). template <typename T, typename... Args> - typename Internal::unique_type<T>::unique_type_bounded_array + typename eastl::enable_if<eastl::is_bounded_array<T>::value>::type make_unique(Args&&...) = delete; @@ -596,12 +581,20 @@ namespace eastl { return (a.get() == b.get()); } - + #if defined(EA_COMPILER_HAS_THREE_WAY_COMPARISON) + template <typename T1, typename D1, typename T2, typename D2> + requires std::three_way_comparable_with<typename unique_ptr<T1, D1>::pointer, typename unique_ptr<T2, D2>::pointer> + inline std::compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer, typename unique_ptr<T2, D2>::pointer> operator<=>(const unique_ptr<T1, D1>& a, const unique_ptr<T2, D2>& b) + { + return a.get() <=> b.get(); + } + #else template <typename T1, typename D1, typename T2, typename D2> inline bool operator!=(const unique_ptr<T1, D1>& a, const unique_ptr<T2, D2>& b) { return !(a.get() == b.get()); } + #endif /// Returns which unique_ptr is 'less' than the other. Useful when storing /// sorted containers of unique_ptr objects. @@ -646,6 +639,14 @@ namespace eastl return !a; } +#if defined(EA_COMPILER_HAS_THREE_WAY_COMPARISON) + template <typename T, typename D> + requires std::three_way_comparable_with<typename unique_ptr<T, D>::pointer, std::nullptr_t> + inline std::compare_three_way_result_t<typename unique_ptr<T, D>::pointer, std::nullptr_t> operator<=>(const unique_ptr<T, D>& a, std::nullptr_t) + { + return a.get() <=> nullptr; + } +#else template <typename T, typename D> inline bool operator==(std::nullptr_t, const unique_ptr<T, D>& a) EA_NOEXCEPT { @@ -663,6 +664,7 @@ namespace eastl { return static_cast<bool>(a); } +#endif template <typename T, typename D> inline bool operator<(const unique_ptr<T, D>& a, std::nullptr_t) |