diff options
author | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-08-08 15:29:07 +0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-08-09 09:53:12 +0700 |
commit | 6f894d481d19e05fbc10f3ce7d74d9180d1cbb64 (patch) | |
tree | 8260bbd04f17fbee780c654b35175e89c10129fa /system/include/libcxx/utility | |
parent | 6c275bebb45d6aac7e4a024b825ab34971b178d2 (diff) |
Update libcxx to revision 187959, 2013-08-08.
Diffstat (limited to 'system/include/libcxx/utility')
-rw-r--r-- | system/include/libcxx/utility | 265 |
1 files changed, 225 insertions, 40 deletions
diff --git a/system/include/libcxx/utility b/system/include/libcxx/utility index 2df4b361..d36cf9dd 100644 --- a/system/include/libcxx/utility +++ b/system/include/libcxx/utility @@ -38,10 +38,10 @@ template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); -template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; -template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; +template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 +template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 -template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; +template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 template <class T> typename conditional @@ -50,7 +50,7 @@ template <class T> const T&, T&& >::type - move_if_noexcept(T& x) noexcept; + move_if_noexcept(T& x) noexcept; // constexpr in C++14 template <class T> typename add_rvalue_reference<T>::type declval() noexcept; @@ -66,10 +66,10 @@ struct pair pair(const pair&) = default; pair(pair&&) = default; constexpr pair(); - pair(const T1& x, const T2& y); - template <class U, class V> pair(U&& x, V&& y); - template <class U, class V> pair(const pair<U, V>& p); - template <class U, class V> pair(pair<U, V>&& p); + pair(const T1& x, const T2& y); // constexpr in C++14 + template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14 + template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14 + template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14 template <class... Args1, class... Args2> pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args); @@ -83,14 +83,14 @@ struct pair noexcept(swap(second, p.second))); }; -template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); -template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); -template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); -template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); -template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); -template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); +template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 +template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 -template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); +template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 template <class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); @@ -107,16 +107,48 @@ template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >; template<size_t I, class T1, class T2> typename tuple_element<I, std::pair<T1, T2> >::type& - get(std::pair<T1, T2>&) noexcept; + get(std::pair<T1, T2>&) noexcept; // constexpr in C++14 template<size_t I, class T1, class T2> const typename const tuple_element<I, std::pair<T1, T2> >::type& - get(const std::pair<T1, T2>&) noexcept; + get(const std::pair<T1, T2>&) noexcept; // constexpr in C++14 template<size_t I, class T1, class T2> typename tuple_element<I, std::pair<T1, T2> >::type&& - get(std::pair<T1, T2>&&) noexcept; + get(std::pair<T1, T2>&&) noexcept; // constexpr in C++14 +template<class T1, class T2> + constexpr T1& get(std::pair<T1, T2>&) noexcept; // C++14 + +template<size_t I, class T1, class T2> + constexpr T1 const& get(std::pair<T1, T2> const &) noexcept; // C++14 + +template<size_t I, class T1, class T2> + constexpr T1&& get(std::pair<T1, T2>&&) noexcept; // C++14 + +// C++14 + +template<class T, T... I> +struct integer_sequence +{ + typedef T value_type; + + static constexpr size_t size() noexcept; +}; + +template<size_t... I> + using index_sequence = integer_sequence<size_t, I...>; + +template<class T, T N> + using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; +template<size_t N> + using make_index_sequence = make_integer_sequence<size_t, N>; + +template<class... T> + using index_sequence_for = make_index_sequence<sizeof...(T)>; + +template<class T, class U=T> + T exchange(T& obj, U&& new_value); } // std */ @@ -189,7 +221,7 @@ swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::v } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename conditional < @@ -226,11 +258,12 @@ struct _LIBCPP_TYPE_VIS pair _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} - _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(const _T1& __x, const _T2& __y) : first(__x), second(__y) {} template<class _U1, class _U2> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(const pair<_U1, _U2>& __p #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE ,typename enable_if<is_convertible<const _U1&, _T1>::value && @@ -239,6 +272,10 @@ struct _LIBCPP_TYPE_VIS pair ) : first(__p.first), second(__p.second) {} +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY + pair(const pair& __p) = default; +#else _LIBCPP_INLINE_VISIBILITY pair(const pair& __p) _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && @@ -247,6 +284,7 @@ struct _LIBCPP_TYPE_VIS pair second(__p.second) { } +#endif _LIBCPP_INLINE_VISIBILITY pair& operator=(const pair& __p) @@ -263,20 +301,24 @@ struct _LIBCPP_TYPE_VIS pair template <class _U1, class _U2, class = typename enable_if<is_convertible<_U1, first_type>::value && is_convertible<_U2, second_type>::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(_U1&& __u1, _U2&& __u2) : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} template<class _U1, class _U2> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(pair<_U1, _U2>&& __p, typename enable_if<is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value>::type* = 0) : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY + pair(pair&& __p) = default; +#else _LIBCPP_INLINE_VISIBILITY pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && is_nothrow_move_constructible<second_type>::value) @@ -284,6 +326,7 @@ struct _LIBCPP_TYPE_VIS pair second(_VSTD::forward<second_type>(__p.second)) { } +#endif _LIBCPP_INLINE_VISIBILITY pair& @@ -299,7 +342,7 @@ struct _LIBCPP_TYPE_VIS pair template<class _Tuple, class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(_Tuple&& __p) : first(_VSTD::forward<typename tuple_element<0, typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))), @@ -355,7 +398,7 @@ private: }; template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -363,7 +406,7 @@ operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -371,7 +414,7 @@ operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -379,7 +422,7 @@ operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -387,7 +430,7 @@ operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -395,7 +438,7 @@ operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -440,7 +483,7 @@ struct __make_pair_return }; template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> make_pair(_T1&& __t1, _T2&& __t2) { @@ -503,13 +546,13 @@ struct __get_pair<0> { template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} @@ -517,7 +560,7 @@ struct __get_pair<0> template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} @@ -529,13 +572,13 @@ struct __get_pair<1> { template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} @@ -543,7 +586,7 @@ struct __get_pair<1> template <class _T1, class _T2> static - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} @@ -551,7 +594,7 @@ struct __get_pair<1> }; template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(pair<_T1, _T2>& __p) _NOEXCEPT { @@ -559,7 +602,7 @@ get(pair<_T1, _T2>& __p) _NOEXCEPT } template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(const pair<_T1, _T2>& __p) _NOEXCEPT { @@ -569,7 +612,7 @@ get(const pair<_T1, _T2>& __p) _NOEXCEPT #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& get(pair<_T1, _T2>&& __p) _NOEXCEPT { @@ -578,6 +621,148 @@ get(pair<_T1, _T2>&& __p) _NOEXCEPT #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER > 11 +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT +{ + return __get_pair<0>::get(__p); +} + +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT +{ + return __get_pair<0>::get(__p); +} + +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT +{ + return __get_pair<0>::get(_VSTD::move(__p)); +} + +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT +{ + return __get_pair<1>::get(__p); +} + +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT +{ + return __get_pair<1>::get(__p); +} + +template <class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY inline +constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT +{ + return __get_pair<1>::get(_VSTD::move(__p)); +} + +#endif + +#if _LIBCPP_STD_VER > 11 + +template<class _Tp, _Tp... _Ip> +struct _LIBCPP_TYPE_VIS integer_sequence +{ + typedef _Tp value_type; + static_assert( is_integral<_Tp>::value, + "std::integer_sequence can only be instantiated with an integral type" ); + static + _LIBCPP_INLINE_VISIBILITY + constexpr + size_t + size() noexcept { return sizeof...(_Ip); } +}; + +template<size_t... _Ip> + using index_sequence = integer_sequence<size_t, _Ip...>; + +namespace __detail { + +template<typename _Tp, size_t ..._Extra> struct __repeat; +template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> { + typedef integer_sequence<_Tp, + _Np..., + sizeof...(_Np) + _Np..., + 2 * sizeof...(_Np) + _Np..., + 3 * sizeof...(_Np) + _Np..., + 4 * sizeof...(_Np) + _Np..., + 5 * sizeof...(_Np) + _Np..., + 6 * sizeof...(_Np) + _Np..., + 7 * sizeof...(_Np) + _Np..., + _Extra...> type; +}; + +template<size_t _Np> struct __parity; +template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; + +template<> struct __make<0> { typedef integer_sequence<size_t> type; }; +template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; }; +template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; }; +template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; }; +template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; }; +template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; }; +template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; }; +template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; }; + +template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; }; +template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; }; +template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; +template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; + +template<typename _Tp, typename _Up> struct __convert { + template<typename> struct __result; + template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; }; +}; +template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; }; + +} + +template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = + typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type; + +template <class _Tp, _Tp _Ep> +struct __make_integer_sequence +{ + static_assert(is_integral<_Tp>::value, + "std::make_integer_sequence can only be instantiated with an integral type" ); + static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative"); + typedef __make_integer_sequence_unchecked<_Tp, _Ep> type; +}; + +template<class _Tp, _Tp _Np> + using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type; + +template<size_t _Np> + using make_index_sequence = make_integer_sequence<size_t, _Np>; + +template<class... _Tp> + using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; + +#endif // _LIBCPP_STD_VER > 11 + +#if _LIBCPP_STD_VER > 11 +template<class _T1, class _T2 = _T1> +_LIBCPP_INLINE_VISIBILITY inline +_T1 exchange(_T1& __obj, _T2 && __new_value) +{ + _T1 __old_value = _VSTD::move(__obj); + __obj = _VSTD::forward<_T2>(__new_value); + return __old_value; +} +#endif // _LIBCPP_STD_VER > 11 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_UTILITY |