summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/memory
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/include/memory')
-rw-r--r--contrib/libc++/include/memory163
1 files changed, 110 insertions, 53 deletions
diff --git a/contrib/libc++/include/memory b/contrib/libc++/include/memory
index 2a8b7e6..ffd0cd0 100644
--- a/contrib/libc++/include/memory
+++ b/contrib/libc++/include/memory
@@ -350,6 +350,10 @@ class bad_weak_ptr
bad_weak_ptr() noexcept;
};
+template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
+template<class T> unique_ptr<T> make_unique(size_t n); // C++14
+template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
+
template<class T>
class shared_ptr
{
@@ -1750,7 +1754,7 @@ public:
typedef const _Tp* const_pointer;
typedef const _Tp& reference;
typedef const _Tp& const_reference;
- typedef _Tp value_type;
+ typedef const _Tp value_type;
typedef true_type propagate_on_container_move_assignment;
@@ -2036,6 +2040,10 @@ public:
return *this;
}
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2051,10 +2059,6 @@ public:
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
_LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
_LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
@@ -2131,6 +2135,10 @@ public:
return *this;
}
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2146,10 +2154,6 @@ public:
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
_LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
@@ -2227,6 +2231,10 @@ public:
return *this;
}
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2243,10 +2251,6 @@ public:
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
_LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
_LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
@@ -2321,6 +2325,10 @@ public:
return *this;
}
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
@@ -2336,10 +2344,6 @@ public:
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
_LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
@@ -2409,6 +2413,10 @@ public:
return *this;
}
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args1, class... _Args2>
@@ -2422,10 +2430,6 @@ public:
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-
_LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
_LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
@@ -3079,8 +3083,61 @@ move(unique_ptr<_Tp, _Dp>& __t)
#endif
+#if _LIBCPP_STD_VER > 11
+
+template<class _Tp>
+struct __unique_if
+{
+ typedef unique_ptr<_Tp> __unique_single;
+};
+
+template<class _Tp>
+struct __unique_if<_Tp[]>
+{
+ typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
+};
+
+template<class _Tp, size_t _Np>
+struct __unique_if<_Tp[_Np]>
+{
+ typedef void __unique_array_known_bound;
+};
+
+template<class _Tp, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __unique_if<_Tp>::__unique_single
+make_unique(_Args&&... __args)
+{
+ return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __unique_if<_Tp>::__unique_array_unknown_bound
+make_unique(size_t __n)
+{
+ typedef typename remove_extent<_Tp>::type _Up;
+ return unique_ptr<_Tp>(new _Up[__n]());
+}
+
+template<class _Tp, class... _Args>
+ typename __unique_if<_Tp>::__unique_array_known_bound
+ make_unique(_Args&&...) = delete;
+
+#endif // _LIBCPP_STD_VER > 11
+
template <class _Tp> struct hash;
+template <class _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+_Size
+__loadword(const void* __p)
+{
+ _Size __r;
+ std::memcpy(&__r, __p, sizeof(__r));
+ return __r;
+}
+
// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
// is 64 bits. This is because cityhash64 uses 64bit x 64bit
// multiplication, which can be very slow on 32-bit systems.
@@ -3104,7 +3161,7 @@ __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
const unsigned char* __data = static_cast<const unsigned char*>(__key);
for (; __len >= 4; __data += 4, __len -= 4)
{
- _Size __k = *(const _Size*)__data;
+ _Size __k = __loadword<_Size>(__data);
__k *= __m;
__k ^= __k >> __r;
__k *= __m;
@@ -3163,13 +3220,13 @@ struct __murmur2_or_cityhash<_Size, 64>
static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
if (__len > 8) {
- const _Size __a = *(const _Size*)__s;
- const _Size __b = *(const _Size*)(__s + __len - 8);
+ const _Size __a = __loadword<_Size>(__s);
+ const _Size __b = __loadword<_Size>(__s + __len - 8);
return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
}
if (__len >= 4) {
- const uint32_t __a = *(const uint32_t*)(__s);
- const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
+ const uint32_t __a = __loadword<uint32_t>(__s);
+ const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
return __hash_len_16(__len + (__a << 3), __b);
}
if (__len > 0) {
@@ -3185,10 +3242,10 @@ struct __murmur2_or_cityhash<_Size, 64>
}
static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
- const _Size __a = *(const _Size*)(__s) * __k1;
- const _Size __b = *(const _Size*)(__s + 8);
- const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
- const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
+ const _Size __a = __loadword<_Size>(__s) * __k1;
+ const _Size __b = __loadword<_Size>(__s + 8);
+ const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
+ const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
__a + __rotate(__b ^ __k3, 20) - __c + __len);
}
@@ -3209,33 +3266,33 @@ struct __murmur2_or_cityhash<_Size, 64>
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
const char* __s, _Size __a, _Size __b) {
- return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
- *(const _Size*)(__s + 8),
- *(const _Size*)(__s + 16),
- *(const _Size*)(__s + 24),
+ return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
+ __loadword<_Size>(__s + 8),
+ __loadword<_Size>(__s + 16),
+ __loadword<_Size>(__s + 24),
__a,
__b);
}
// Return an 8-byte hash for 33 to 64 bytes.
static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
- _Size __z = *(const _Size*)(__s + 24);
- _Size __a = *(const _Size*)(__s) +
- (__len + *(const _Size*)(__s + __len - 16)) * __k0;
+ _Size __z = __loadword<_Size>(__s + 24);
+ _Size __a = __loadword<_Size>(__s) +
+ (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
_Size __b = __rotate(__a + __z, 52);
_Size __c = __rotate(__a, 37);
- __a += *(const _Size*)(__s + 8);
+ __a += __loadword<_Size>(__s + 8);
__c += __rotate(__a, 7);
- __a += *(const _Size*)(__s + 16);
+ __a += __loadword<_Size>(__s + 16);
_Size __vf = __a + __z;
_Size __vs = __b + __rotate(__a, 31) + __c;
- __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
- __z += *(const _Size*)(__s + __len - 8);
+ __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
+ __z += __loadword<_Size>(__s + __len - 8);
__b = __rotate(__a + __z, 52);
__c = __rotate(__a, 37);
- __a += *(const _Size*)(__s + __len - 24);
+ __a += __loadword<_Size>(__s + __len - 24);
__c += __rotate(__a, 7);
- __a += *(const _Size*)(__s + __len - 16);
+ __a += __loadword<_Size>(__s + __len - 16);
_Size __wf = __a + __z;
_Size __ws = __b + __rotate(__a, 31) + __c;
_Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
@@ -3261,26 +3318,26 @@ __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
// For strings over 64 bytes we hash the end first, and then as we
// loop we keep 56 bytes of state: v, w, x, y, and z.
- _Size __x = *(const _Size*)(__s + __len - 40);
- _Size __y = *(const _Size*)(__s + __len - 16) +
- *(const _Size*)(__s + __len - 56);
- _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
- *(const _Size*)(__s + __len - 24));
+ _Size __x = __loadword<_Size>(__s + __len - 40);
+ _Size __y = __loadword<_Size>(__s + __len - 16) +
+ __loadword<_Size>(__s + __len - 56);
+ _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
+ __loadword<_Size>(__s + __len - 24));
pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
- __x = __x * __k1 + *(const _Size*)(__s);
+ __x = __x * __k1 + __loadword<_Size>(__s);
// Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
__len = (__len - 1) & ~static_cast<_Size>(63);
do {
- __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
- __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
+ __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
+ __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
__x ^= __w.second;
- __y += __v.first + *(const _Size*)(__s + 40);
+ __y += __v.first + __loadword<_Size>(__s + 40);
__z = __rotate(__z + __w.first, 33) * __k1;
__v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
__w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
- __y + *(const _Size*)(__s + 16));
+ __y + __loadword<_Size>(__s + 16));
std::swap(__z, __x);
__s += 64;
__len -= 64;
OpenPOWER on IntegriCloud