diff options
Diffstat (limited to 'system/include')
52 files changed, 4202 insertions, 1535 deletions
diff --git a/system/include/libcxx/CREDITS.TXT b/system/include/libcxx/CREDITS.TXT index 52948510..5e4d14ec 100644 --- a/system/include/libcxx/CREDITS.TXT +++ b/system/include/libcxx/CREDITS.TXT @@ -33,6 +33,14 @@ E: mclow.lists@gmail.com E: marshall@idio.com D: Minor patches and bug fixes. +N: Bill Fisher +E: william.w.fisher@gmail.com +D: Regex bug fixes. + +N: Matthew Dempsky +E: matthew@dempsky.org +D: Minor patches and bug fixes. + N: Google Inc. D: Copyright owner and contributor of the CityHash algorithm @@ -48,6 +56,10 @@ N: Argyrios Kyrtzidis E: kyrtzidis@apple.com D: Bug fixes. +N: Bruce Mitchener, Jr. +E: bruce.mitchener@gmail.com +D: Emscripten-related changes. + N: Michel Morin E: mimomorin@gmail.com D: Minor patches to is_convertible. @@ -74,6 +86,14 @@ D: Implemented Cityhash as the string hash function on 64-bit machines N: Richard Smith D: Minor patches. +N: Joerg Sonnenberger +E: joerg@NetBSD.org +D: NetBSD port. + +N: Stephan Tolksdorf +E: st@quanttec.com +D: Minor <atomic> fix + N: Michael van der Westhuizen E: r1mikey at gmail dot com @@ -85,6 +105,10 @@ N: Zhang Xiongpang E: zhangxiongpang@gmail.com D: Minor patches and bug fixes. +N: Zhihao Yuan +E: lichray@gmail.com +D: Standard compatibility fixes. + N: Jeffrey Yasskin E: jyasskin@gmail.com E: jyasskin@google.com diff --git a/system/include/libcxx/__bit_reference b/system/include/libcxx/__bit_reference index 1621deb8..857dd5a4 100644 --- a/system/include/libcxx/__bit_reference +++ b/system/include/libcxx/__bit_reference @@ -173,6 +173,8 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __b = *__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + if (__n == __dn) + return _It(__first.__seg_, __first.__ctz_ + __n); __n -= __dn; ++__first.__seg_; } @@ -207,6 +209,8 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __b = ~*__first.__seg_ & __m; if (__b) return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + if (__n == __dn) + return _It(__first.__seg_, __first.__ctz_ + __n); __n -= __dn; ++__first.__seg_; } @@ -333,7 +337,7 @@ __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) } // do middle whole words __storage_type __nw = __n / __bits_per_word; - _VSTD::memset(__first.__seg_, 0, __nw * sizeof(__storage_type)); + _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last partial word if (__n > 0) @@ -363,7 +367,7 @@ __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) } // do middle whole words __storage_type __nw = __n / __bits_per_word; - _VSTD::memset(__first.__seg_, -1, __nw * sizeof(__storage_type)); + _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last partial word if (__n > 0) @@ -430,7 +434,9 @@ __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCon // __first.__ctz_ == 0; // do middle words __storage_type __nw = __n / __bits_per_word; - _VSTD::memmove(__result.__seg_, __first.__seg_, __nw * sizeof(__storage_type)); + _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), + _VSTD::__to_raw_pointer(__first.__seg_), + __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; __result.__seg_ += __nw; // do last word @@ -569,7 +575,9 @@ __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_C __storage_type __nw = __n / __bits_per_word; __result.__seg_ -= __nw; __last.__seg_ -= __nw; - _VSTD::memmove(__result.__seg_, __last.__seg_, __nw * sizeof(__storage_type)); + _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_), + _VSTD::__to_raw_pointer(__last.__seg_), + __nw * sizeof(__storage_type)); __n -= __nw * __bits_per_word; // do last word if (__n > 0) @@ -870,6 +878,7 @@ struct __bit_array { typedef typename _Cp::difference_type difference_type; typedef typename _Cp::__storage_type __storage_type; + typedef typename _Cp::__storage_pointer __storage_pointer; typedef typename _Cp::iterator iterator; static const unsigned __bits_per_word = _Cp::__bits_per_word; static const unsigned _Np = 4; @@ -880,9 +889,15 @@ struct __bit_array _LIBCPP_INLINE_VISIBILITY static difference_type capacity() {return static_cast<difference_type>(_Np * __bits_per_word);} _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {} - _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(__word_, 0);} - _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(__word_ + __size_ / __bits_per_word, - static_cast<unsigned>(__size_ % __bits_per_word));} + _LIBCPP_INLINE_VISIBILITY iterator begin() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0); + } + _LIBCPP_INLINE_VISIBILITY iterator end() + { + return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word, + static_cast<unsigned>(__size_ % __bits_per_word)); + } }; template <class _Cp> @@ -1093,7 +1108,11 @@ private: unsigned __ctz_; public: - _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __seg_(nullptr), __ctz_(0) +#endif + {} _LIBCPP_INLINE_VISIBILITY __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT diff --git a/system/include/libcxx/__config b/system/include/libcxx/__config index 959390d5..b1f0d958 100644 --- a/system/include/libcxx/__config +++ b/system/include/libcxx/__config @@ -11,7 +11,7 @@ #ifndef _LIBCPP_CONFIG #define _LIBCPP_CONFIG -#ifndef _MSC_VER // explicit macro necessary because it is only defined below in this file +#if !defined(_MSC_VER) || defined(__clang__) #pragma GCC system_header #endif @@ -56,19 +56,36 @@ # endif // __LONG_LONG_SUPPORTED #endif // __FreeBSD__ +#ifdef __NetBSD__ +# include <sys/endian.h> +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_HAS_QUICK_EXIT +#endif // __NetBSD__ + #ifdef _WIN32 # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 // Compiler intrinsics (GCC or MSVC) -# if (defined(_MSC_VER) && _MSC_VER >= 1400) \ +# if defined(__clang__) \ + || (defined(_MSC_VER) && _MSC_VER >= 1400) \ || (defined(__GNUC__) && _GNUC_VER > 403) -# define _LIBCP_HAS_IS_BASE_OF +# define _LIBCPP_HAS_IS_BASE_OF # endif +# if defined(_MSC_VER) && !defined(__clang__) +# define _LIBCPP_MSVC // Using Microsoft Visual C++ compiler +# endif +# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library #endif // _WIN32 #ifdef __linux__ # if defined(__GNUC__) && _GNUC_VER >= 403 -# define _LIBCP_HAS_IS_BASE_OF +# define _LIBCPP_HAS_IS_BASE_OF # endif #endif @@ -116,7 +133,7 @@ #endif #ifndef _LIBCPP_INLINE_VISIBILITY -# ifdef _MSC_VER +# ifdef _LIBCPP_MSVC # define _LIBCPP_INLINE_VISIBILITY __forceinline # else // MinGW GCC and Clang # define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) @@ -128,13 +145,17 @@ #endif #ifndef _LIBCPP_ALWAYS_INLINE -# ifdef _MSC_VER +# ifdef _LIBCPP_MSVC # define _LIBCPP_ALWAYS_INLINE __forceinline # endif #endif #endif // _WIN32 +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif + #ifndef _LIBCPP_HIDDEN #define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) #endif @@ -212,7 +233,9 @@ typedef __char32_t char32_t; # define _LIBCPP_NORETURN __attribute__ ((noreturn)) #endif +#if !(__has_feature(cxx_defaulted_functions)) #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#endif // !(__has_feature(cxx_defaulted_functions)) #if !(__has_feature(cxx_deleted_functions)) #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS @@ -255,7 +278,7 @@ typedef __char32_t char32_t; #endif #if __has_feature(is_base_of) -# define _LIBCP_HAS_IS_BASE_OF +# define _LIBCPP_HAS_IS_BASE_OF #endif // Objective-C++ features (opt-in) @@ -272,9 +295,19 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_CONSTEXPR #endif -#if defined(__FreeBSD__) && (__ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L) +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +#if defined(__FreeBSD__) #define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_C11_FEATURES +#elif defined(__linux__) +#include <features.h> +#if __GLIBC_PREREQ(2, 15) +#define _LIBCPP_HAS_QUICK_EXIT +#endif +#if __GLIBC_PREREQ(2, 17) +#define _LIBCPP_HAS_C11_FEATURES +#endif +#endif #endif #if (__has_feature(cxx_noexcept)) @@ -368,7 +401,7 @@ namespace _LIBCPP_NAMESPACE { using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); } -#elif defined(_MSC_VER) +#elif defined(_LIBCPP_MSVC) #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER @@ -390,7 +423,7 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); namespace std { } -#endif // __clang__ || __GNUC___ || _MSC_VER +#endif // __clang__ || __GNUC__ || _LIBCPP_MSVC #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS typedef unsigned short char16_t; @@ -418,8 +451,14 @@ template <unsigned> struct __static_assert_check {}; #define _LIBCPP_CONSTEXPR constexpr #endif +#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_DEFAULT {} +#else +#define _LIBCPP_DEFAULT = default; +#endif + #ifdef __GNUC__ -#define _NOALIAS __attribute__((malloc)) +#define _NOALIAS __attribute__((__malloc__)) #else #define _NOALIAS #endif @@ -451,7 +490,7 @@ template <unsigned> struct __static_assert_check {}; #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; #endif -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) || defined(__NetBSD__) #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif #ifdef __FreeBSD__ @@ -476,10 +515,18 @@ template <unsigned> struct __static_assert_check {}; # endif #endif -#ifdef _LIBCPP_DEBUG2 -# include <__debug> +#ifndef _LIBCPP_STD_VER +# if __cplusplus <= 201103L +# define _LIBCPP_STD_VER 11 +# else +# define _LIBCPP_STD_VER 13 // current year, or date of c++14 ratification +# endif +#endif // _LIBCPP_STD_VER + +#if _LIBCPP_STD_VER <= 11 +#define _LIBCPP_CONSTEXPR_AFTER_CXX11 #else -# define _LIBCPP_ASSERT(x, m) ((void)0) +#define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr #endif #endif // _LIBCPP_CONFIG diff --git a/system/include/libcxx/__debug b/system/include/libcxx/__debug index 0d631bf0..bac580cf 100644 --- a/system/include/libcxx/__debug +++ b/system/include/libcxx/__debug @@ -24,6 +24,10 @@ #if _LIBCPP_DEBUG_LEVEL >= 2 +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + _LIBCPP_BEGIN_NAMESPACE_STD struct _LIBCPP_TYPE_VIS __c_node; @@ -171,7 +175,7 @@ public: bool __decrementable(const void* __i) const; bool __addable(const void* __i, ptrdiff_t __n) const; bool __subscriptable(const void* __i, ptrdiff_t __n) const; - bool __comparable(const void* __i, const void* __j) const; + bool __less_than_comparable(const void* __i, const void* __j) const; private: _LIBCPP_HIDDEN __i_node* __insert_iterator(void* __i); diff --git a/system/include/libcxx/__functional_03 b/system/include/libcxx/__functional_03 index b52d6926..662928d8 100644 --- a/system/include/libcxx/__functional_03 +++ b/system/include/libcxx/__functional_03 @@ -102,98 +102,98 @@ mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2)) template<class _Rp, class _Tp> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)()> +__mem_fn<_Rp (_Tp::*)() const> mem_fn(_Rp (_Tp::* __pm)() const) { - return __mem_fn<_Rp (_Tp::*)()>(__pm); + return __mem_fn<_Rp (_Tp::*)() const>(__pm); } template<class _Rp, class _Tp, class _A0> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0)> +__mem_fn<_Rp (_Tp::*)(_A0) const> mem_fn(_Rp (_Tp::* __pm)(_A0) const) { - return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0) const>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1) const> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>(__pm); } template<class _Rp, class _Tp> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)()> +__mem_fn<_Rp (_Tp::*)() volatile> mem_fn(_Rp (_Tp::* __pm)() volatile) { - return __mem_fn<_Rp (_Tp::*)()>(__pm); + return __mem_fn<_Rp (_Tp::*)() volatile>(__pm); } template<class _Rp, class _Tp, class _A0> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0)> +__mem_fn<_Rp (_Tp::*)(_A0) volatile> mem_fn(_Rp (_Tp::* __pm)(_A0) volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0) volatile>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>(__pm); } template<class _Rp, class _Tp> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)()> +__mem_fn<_Rp (_Tp::*)() const volatile> mem_fn(_Rp (_Tp::* __pm)() const volatile) { - return __mem_fn<_Rp (_Tp::*)()>(__pm); + return __mem_fn<_Rp (_Tp::*)() const volatile>(__pm); } template<class _Rp, class _Tp, class _A0> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0)> +__mem_fn<_Rp (_Tp::*)(_A0) const volatile> mem_fn(_Rp (_Tp::* __pm)(_A0) const volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0) const volatile>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>(__pm); } template<class _Rp, class _Tp, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)> +__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile> mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile) { - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm); + return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>(__pm); } // bad_function_call diff --git a/system/include/libcxx/__functional_base b/system/include/libcxx/__functional_base index 40a63a85..2bc2d2c1 100644 --- a/system/include/libcxx/__functional_base +++ b/system/include/libcxx/__functional_base @@ -50,13 +50,27 @@ public: static const bool value = sizeof(__test<_Tp>(0)) == 1; }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS less : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x < __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS less<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); } +}; +#endif + #ifdef _LIBCPP_HAS_NO_VARIADICS #include <__functional_base_03> @@ -292,7 +306,8 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> // bullets 1 and 2 -template <class _Fp, class _A0, class ..._Args> +template <class _Fp, class _A0, class ..._Args, + class> inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) @@ -301,7 +316,8 @@ __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...); } -template <class _Fp, class _A0, class ..._Args> +template <class _Fp, class _A0, class ..._Args, + class> inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) @@ -312,7 +328,8 @@ __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) // bullets 3 and 4 -template <class _Fp, class _A0> +template <class _Fp, class _A0, + class> inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) @@ -321,7 +338,8 @@ __invoke(_Fp&& __f, _A0&& __a0) return _VSTD::forward<_A0>(__a0).*__f; } -template <class _Fp, class _A0> +template <class _Fp, class _A0, + class> inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) diff --git a/system/include/libcxx/__hash_table b/system/include/libcxx/__hash_table index 6f6050d3..6157fcd9 100644 --- a/system/include/libcxx/__hash_table +++ b/system/include/libcxx/__hash_table @@ -20,6 +20,12 @@ #include <__undef_min_max> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -33,7 +39,6 @@ template <class _NodePtr> struct __hash_node_base { typedef __hash_node_base __first_node; - // typedef _NodePtr pointer; _NodePtr __next_; @@ -106,16 +111,70 @@ public: #endif pointer; - _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __node_(nullptr) +#endif + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(const __hash_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_iterator& operator=(const __hash_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return __node_->__value_;} + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); +#endif + return __node_->__value_; + } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__node_->__value_); + } _LIBCPP_INLINE_VISIBILITY __hash_iterator& operator++() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container iterator"); +#endif __node_ = __node_->__next_; return *this; } @@ -130,16 +189,27 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) - {return __x.__node_ == __y.__node_;} + { + return __x.__node_ == __y.__node_; + } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) - {return __x.__node_ != __y.__node_;} + {return !(__x == __y);} private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_iterator(__node_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else _LIBCPP_INLINE_VISIBILITY __hash_iterator(__node_pointer __node) _NOEXCEPT : __node_(__node) {} +#endif template <class, class, class, class> friend class __hash_table; template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator; @@ -180,20 +250,78 @@ public: __non_const_node_pointer; typedef __hash_iterator<__non_const_node_pointer> __non_const_iterator; - _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __node_(nullptr) +#endif + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_) - {} + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__x); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return __node_->__value_;} + __hash_const_iterator(const __hash_const_iterator& __i) + : __node_(__i.__node_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_const_iterator() + { + __get_db()->__erase_i(this); + } + + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator& operator=(const __hash_const_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); +#endif + return __node_->__value_; + } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__node_->__value_); + } _LIBCPP_INLINE_VISIBILITY __hash_const_iterator& operator++() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_iterator"); +#endif __node_ = __node_->__next_; return *this; } @@ -208,16 +336,27 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) - {return __x.__node_ == __y.__node_;} + { + return __x.__node_ == __y.__node_; + } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) - {return __x.__node_ != __y.__node_;} + {return !(__x == __y);} private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_iterator(__node_pointer __node, const void* __c) _NOEXCEPT + : __node_(__node) + { + __get_db()->__insert_ic(this, __c); + } +#else _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(__node_pointer __node) _NOEXCEPT : __node_(__node) {} +#endif template <class, class, class, class> friend class __hash_table; template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator; @@ -250,16 +389,71 @@ public: #endif pointer; - _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(const __hash_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return __node_->__value_;} + ~__hash_local_iterator() + { + __get_db()->__erase_i(this); + } + _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__node_->__value_;} + __hash_local_iterator& operator=(const __hash_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); +#endif + return __node_->__value_; + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__node_->__value_); + } _LIBCPP_INLINE_VISIBILITY __hash_local_iterator& operator++() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container local_iterator"); +#endif __node_ = __node_->__next_; if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_) __node_ = nullptr; @@ -276,12 +470,27 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) - {return __x.__node_ == __y.__node_;} + { + return __x.__node_ == __y.__node_; + } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) - {return __x.__node_ != __y.__node_;} + {return !(__x == __y);} private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_local_iterator(__node_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else _LIBCPP_INLINE_VISIBILITY __hash_local_iterator(__node_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT @@ -292,7 +501,7 @@ private: if (__node_ != nullptr) __node_ = __node_->__next_; } - +#endif template <class, class, class, class> friend class __hash_table; template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator; template <class> friend class _LIBCPP_TYPE_VIS __hash_map_iterator; @@ -334,22 +543,82 @@ public: #endif pointer; - _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_i(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_), __bucket_(__x.__bucket_), __bucket_count_(__x.__bucket_count_) - {} + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__iterator_copy(this, &__x); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(const __hash_const_local_iterator& __i) + : __node_(__i.__node_), + __bucket_(__i.__bucket_), + __bucket_count_(__i.__bucket_count_) + { + __get_db()->__iterator_copy(this, &__i); + } + + _LIBCPP_INLINE_VISIBILITY + ~__hash_const_local_iterator() + { + __get_db()->__erase_i(this); + } _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return __node_->__value_;} + __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) + { + if (this != &__i) + { + __get_db()->__iterator_copy(this, &__i); + __node_ = __i.__node_; + __bucket_ = __i.__bucket_; + __bucket_count_ = __i.__bucket_count_; + } + return *this; + } + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); +#endif + return __node_->__value_; + } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__node_->__value_;} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__node_->__value_); + } _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator& operator++() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_local_iterator"); +#endif __node_ = __node_->__next_; if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_) __node_ = nullptr; @@ -366,12 +635,27 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) - {return __x.__node_ == __y.__node_;} + { + return __x.__node_ == __y.__node_; + } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) - {return __x.__node_ != __y.__node_;} + {return !(__x == __y);} private: +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + __hash_const_local_iterator(__node_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT + : __node_(__node), + __bucket_(__bucket), + __bucket_count_(__bucket_count) + { + __get_db()->__insert_ic(this, __c); + if (__node_ != nullptr) + __node_ = __node_->__next_; + } +#else _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(__node_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT @@ -382,7 +666,7 @@ private: if (__node_ != nullptr) __node_ = __node_->__next_; } - +#endif template <class, class, class, class> friend class __hash_table; template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator; }; @@ -505,8 +789,15 @@ public: __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; - typedef typename __node_traits::const_pointer __node_const_pointer; + typedef typename __node_traits::pointer __node_const_pointer; typedef __hash_node_base<__node_pointer> __first_node; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__first_node> +#else + rebind<__first_node>::other +#endif + __node_base_pointer; private: @@ -558,9 +849,9 @@ public: public: typedef __hash_iterator<__node_pointer> iterator; - typedef __hash_const_iterator<__node_const_pointer> const_iterator; + typedef __hash_const_iterator<__node_pointer> const_iterator; typedef __hash_local_iterator<__node_pointer> local_iterator; - typedef __hash_const_local_iterator<__node_const_pointer> const_local_iterator; + typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; __hash_table() _NOEXCEPT_( @@ -658,7 +949,11 @@ public: template <class _Key> _LIBCPP_INLINE_VISIBILITY size_type bucket(const _Key& __k) const - {return __constrain_hash(hash_function()(__k), bucket_count());} + { + _LIBCPP_ASSERT(bucket_count() > 0, + "unordered container::bucket(key) called when bucket_count() == 0"); + return __constrain_hash(hash_function()(__k), bucket_count()); + } template <class _Key> iterator find(const _Key& __x); @@ -706,7 +1001,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const _NOEXCEPT - {return __bucket_list_.get_deleter().__alloc().max_size();} + {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());} size_type bucket_size(size_type __n) const; _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT { @@ -714,16 +1009,73 @@ public: return __bc != 0 ? (float)size() / __bc : 0.f; } _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT - {max_load_factor() = _VSTD::max(__mlf, load_factor());} - - _LIBCPP_INLINE_VISIBILITY local_iterator begin(size_type __n) - {return local_iterator(__bucket_list_[__n], __n, bucket_count());} - _LIBCPP_INLINE_VISIBILITY local_iterator end(size_type __n) - {return local_iterator(nullptr, __n, bucket_count());} - _LIBCPP_INLINE_VISIBILITY const_local_iterator cbegin(size_type __n) const - {return const_local_iterator(__bucket_list_[__n], __n, bucket_count());} - _LIBCPP_INLINE_VISIBILITY const_local_iterator cend(size_type __n) const - {return const_local_iterator(nullptr, __n, bucket_count());} + { + _LIBCPP_ASSERT(__mlf > 0, + "unordered container::max_load_factor(lf) called with lf <= 0"); + max_load_factor() = _VSTD::max(__mlf, load_factor()); + } + + _LIBCPP_INLINE_VISIBILITY + local_iterator + begin(size_type __n) + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::begin(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + local_iterator + end(size_type __n) + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::end(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return local_iterator(nullptr, __n, bucket_count(), this); +#else + return local_iterator(nullptr, __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const_local_iterator + cbegin(size_type __n) const + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::cbegin(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); +#else + return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + const_local_iterator + cend(size_type __n) const + { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::cend(n) called with n >= bucket_count()"); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_local_iterator(nullptr, __n, bucket_count(), this); +#else + return const_local_iterator(nullptr, __n, bucket_count()); +#endif + } + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + private: void __rehash(size_type __n); @@ -807,6 +1159,9 @@ private: void __deallocate(__node_pointer __np) _NOEXCEPT; __node_pointer __detach() _NOEXCEPT; + + template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap; }; template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -893,7 +1248,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) if (size() > 0) { __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } @@ -917,7 +1272,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, __p1_.first().__next_ = __u.__p1_.first().__next_; __u.__p1_.first().__next_ = nullptr; __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); size() = __u.size(); __u.size() = 0; } @@ -930,6 +1285,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { __deallocate(__p1_.first().__next_); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__erase_c(this); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -971,6 +1329,21 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np) while (__np != nullptr) { __node_pointer __next = __np->__next_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__node_ == __np) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif __node_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_traits::deallocate(__na, __np, 1); __np = __next; @@ -1014,10 +1387,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( if (size() > 0) { __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__u); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1158,7 +1534,11 @@ inline _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__p1_.first().__next_, this); +#else return iterator(__p1_.first().__next_); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1166,7 +1546,11 @@ inline _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(nullptr, this); +#else return iterator(nullptr); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1174,7 +1558,11 @@ inline _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__p1_.first().__next_, this); +#else return const_iterator(__p1_.first().__next_); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1182,7 +1570,11 @@ inline _LIBCPP_INLINE_VISIBILITY typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(nullptr, this); +#else return const_iterator(nullptr); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1236,7 +1628,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __ __node_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); __nd->__next_ = __pn->__next_; __pn->__next_ = __nd; // fix up __bucket_list_ @@ -1255,7 +1647,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __ __inserted = true; } __done: +#if _LIBCPP_DEBUG_LEVEL >= 2 + return pair<iterator, bool>(iterator(__ndptr, this), __inserted); +#else return pair<iterator, bool>(iterator(__ndptr), __inserted); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1274,7 +1670,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c __node_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); __cp->__next_ = __pn->__next_; __pn->__next_ = __cp; // fix up __bucket_list_ @@ -1312,7 +1708,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c } } ++size(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__cp, this); +#else return iterator(__cp); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1320,9 +1720,14 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( const_iterator __p, __node_pointer __cp) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif if (__p != end() && key_eq()(*__p, __cp->__value_)) { - __node_pointer __np = const_cast<__node_pointer>(__p.__node_); + __node_pointer __np = __p.__node_; __cp->__hash_ = __np->__hash_; size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) @@ -1338,7 +1743,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( __cp->__next_ = __np; __pp->__next_ = __cp; ++size(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__cp, this); +#else return iterator(__cp); +#endif } return __node_insert_multi(__cp); } @@ -1380,7 +1789,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x) __node_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); __h->__next_ = __pn->__next_; __pn->__next_ = __h.get(); // fix up __bucket_list_ @@ -1399,7 +1808,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x) __inserted = true; } __done: +#if _LIBCPP_DEBUG_LEVEL >= 2 + return pair<iterator, bool>(iterator(__nd, this), __inserted); +#else return pair<iterator, bool>(iterator(__nd), __inserted); +#endif } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1434,6 +1847,11 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( const_iterator __p, _Args&&... __args) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered container"); +#endif __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __node_insert_multi(__p, __h.get()); __h.release(); @@ -1475,6 +1893,11 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, _Pp&& __x) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::insert(const_iterator, rvalue) called with an iterator not" + " referring to this unordered container"); +#endif __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x)); iterator __r = __node_insert_multi(__p, __h.get()); __h.release(); @@ -1498,6 +1921,11 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, const value_type& __x) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container::insert(const_iterator, lvalue) called with an iterator not" + " referring to this unordered container"); +#endif __node_holder __h = __construct_node(__x); iterator __r = __node_insert_multi(__p, __h.get()); __h.release(); @@ -1534,6 +1962,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif // _LIBCPP_DEBUG_LEVEL >= 2 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); __bucket_list_.reset(__nbc > 0 ? __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); @@ -1542,7 +1973,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) { for (size_type __i = 0; __i < __nbc; ++__i) __bucket_list_[__i] = nullptr; - __node_pointer __pp(static_cast<__node_pointer>(_VSTD::addressof(__p1_.first()))); + __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))); __node_pointer __cp = __pp->__next_; if (__cp != nullptr) { @@ -1599,7 +2030,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) __nd = __nd->__next_) { if (key_eq()(__nd->__value_, __k)) +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__nd, this); +#else return iterator(__nd); +#endif } } } @@ -1624,7 +2059,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const __nd = __nd->__next_) { if (key_eq()(__nd->__value_, __k)) +#if _LIBCPP_DEBUG_LEVEL >= 2 + return const_iterator(__nd, this); +#else return const_iterator(__nd); +#endif } } @@ -1700,8 +2139,17 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) { - __node_pointer __np = const_cast<__node_pointer>(__p.__node_); + __node_pointer __np = __p.__node_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered container erase(iterator) called with an iterator not" + " referring to this container"); + _LIBCPP_ASSERT(__p != end(), + "unordered container erase(iterator) called with a non-dereferenceable iterator"); + iterator __r(__np, this); +#else iterator __r(__np); +#endif ++__r; remove(__p); return __r; @@ -1712,13 +2160,25 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, const_iterator __last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "unodered container::erase(iterator, iterator) called with an iterator not" + " referring to this unodered container"); +#endif for (const_iterator __p = __first; __first != __last; __p = __first) { ++__first; erase(__p); } - __node_pointer __np = const_cast<__node_pointer>(__last.__node_); + __node_pointer __np = __last.__node_; +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator (__np, this); +#else return iterator (__np); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1757,7 +2217,7 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { // current node - __node_pointer __cn = const_cast<__node_pointer>(__p.__node_); + __node_pointer __cn = __p.__node_; size_type __bc = bucket_count(); size_t __chash = __constrain_hash(__cn->__hash_, __bc); // find previous node @@ -1767,7 +2227,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT // Fix up __bucket_list_ // if __pn is not in same bucket (before begin is not in same bucket) && // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) - if (__pn == _VSTD::addressof(__p1_.first()) || __constrain_hash(__pn->__hash_, __bc) != __chash) + if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())) + || __constrain_hash(__pn->__hash_, __bc) != __chash) { if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash) __bucket_list_[__chash] = nullptr; @@ -1783,6 +2244,21 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT __pn->__next_ = __cn->__next_; __cn->__next_ = nullptr; --size(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + iterator* __i = static_cast<iterator*>((*__p)->__i_); + if (__i->__node_ == __cn) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif return __node_holder(__cn, _Dp(__node_alloc(), true)); } @@ -1907,16 +2383,21 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) __p3_.swap(__u.__p3_); if (size() > 0) __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(_VSTD::addressof(__p1_.first())); + static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); if (__u.size() > 0) __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] = - static_cast<__node_pointer>(_VSTD::addressof(__u.__p1_.first())); + static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first())); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->swap(this, &__u); +#endif } template <class _Tp, class _Hash, class _Equal, class _Alloc> typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { + _LIBCPP_ASSERT(__n < bucket_count(), + "unordered container::bucket_size(n) called with n >= bucket_count()"); __node_const_pointer __np = __bucket_list_[__n]; size_type __bc = bucket_count(); size_type __r = 0; @@ -1940,6 +2421,37 @@ swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, __x.swap(__y); } +#if _LIBCPP_DEBUG_LEVEL >= 2 + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const +{ + return __i->__node_ != nullptr; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const +{ + return false; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +template <class _Tp, class _Hash, class _Equal, class _Alloc> +bool +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const +{ + return false; +} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP__HASH_TABLE diff --git a/system/include/libcxx/__locale b/system/include/libcxx/__locale index 24d565b6..93147ec0 100644 --- a/system/include/libcxx/__locale +++ b/system/include/libcxx/__locale @@ -19,7 +19,7 @@ #include <cstdint> #include <cctype> #include <locale.h> -#ifdef _WIN32 +#ifdef _LIBCPP_MSVCRT # include <support/win32/locale_win32.h> #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(EMSCRIPTEN) # include <xlocale.h> @@ -339,12 +339,12 @@ public: static const mask punct = _PUNCT; static const mask xdigit = _HEX; static const mask blank = _BLANK; -#elif (defined(__APPLE__) || defined(__FreeBSD__)) || defined(EMSCRIPTEN) +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(EMSCRIPTEN) || defined(__NetBSD__) #ifdef __APPLE__ typedef __uint32_t mask; #elif defined(__FreeBSD__) typedef unsigned long mask; -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__NetBSD__) typedef unsigned short mask; #endif static const mask space = _CTYPE_S; @@ -356,7 +356,11 @@ public: static const mask digit = _CTYPE_D; static const mask punct = _CTYPE_P; static const mask xdigit = _CTYPE_X; +# if defined(__NetBSD__) + static const mask blank = _CTYPE_BL; +# else static const mask blank = _CTYPE_B; +# endif #elif defined(__sun__) typedef unsigned int mask; static const mask space = _ISSPACE; @@ -596,6 +600,10 @@ public: static const int* __classic_upper_table() _NOEXCEPT; static const int* __classic_lower_table() _NOEXCEPT; #endif +#if defined(__NetBSD__) + static const short* __classic_upper_table() _NOEXCEPT; + static const short* __classic_lower_table() _NOEXCEPT; +#endif protected: ~ctype(); diff --git a/system/include/libcxx/__split_buffer b/system/include/libcxx/__split_buffer index e0aa13b8..f1c404f7 100644 --- a/system/include/libcxx/__split_buffer +++ b/system/include/libcxx/__split_buffer @@ -290,7 +290,7 @@ void __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) { while (__begin_ != __new_begin) - __alloc_traits::destroy(__alloc(), __begin_++); + __alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++)); } template <class _Tp, class _Allocator> @@ -307,7 +307,7 @@ void __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT { while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), --__end_); + __alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_)); } template <class _Tp, class _Allocator> @@ -320,7 +320,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type template <class _Tp, class _Allocator> __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) - : __end_cap_(0, __a) + : __end_cap_(nullptr, __a) { __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr; __begin_ = __end_ = __first_ + __start; @@ -331,21 +331,21 @@ template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __split_buffer<_Tp, _Allocator>::__split_buffer() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) - : __first_(0), __begin_(0), __end_(0), __end_cap_(0) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) { } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) - : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) { } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) - : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) { } diff --git a/system/include/libcxx/__std_stream b/system/include/libcxx/__std_stream index 8ca413eb..cff43317 100644 --- a/system/include/libcxx/__std_stream +++ b/system/include/libcxx/__std_stream @@ -55,6 +55,8 @@ private: const codecvt<char_type, char, state_type>* __cv_; state_type* __st_; int __encoding_; + int_type __last_consumed_; + bool __last_consumed_is_next_; bool __always_noconv_; __stdinbuf(const __stdinbuf&); @@ -66,7 +68,9 @@ private: template <class _CharT> __stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st) : __file_(__fp), - __st_(__st) + __st_(__st), + __last_consumed_(traits_type::eof()), + __last_consumed_is_next_(false) { imbue(this->getloc()); } @@ -100,6 +104,16 @@ template <class _CharT> typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::__getchar(bool __consume) { + if (__last_consumed_is_next_) + { + int_type __result = __last_consumed_; + if (__consume) + { + __last_consumed_ = traits_type::eof(); + __last_consumed_is_next_ = false; + } + return __result; + } char __extbuf[__limit]; int __nread = _VSTD::max(1, __encoding_); for (int __i = 0; __i < __nread; ++__i) @@ -154,6 +168,8 @@ __stdinbuf<_CharT>::__getchar(bool __consume) return traits_type::eof(); } } + else + __last_consumed_ = traits_type::to_int_type(__1buf); return traits_type::to_int_type(__1buf); } @@ -162,28 +178,41 @@ typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::pbackfail(int_type __c) { if (traits_type::eq_int_type(__c, traits_type::eof())) - return __c; - char __extbuf[__limit]; - char* __enxt; - const char_type __ci = traits_type::to_char_type(__c); - const char_type* __inxt; - switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt, - __extbuf, __extbuf + sizeof(__extbuf), __enxt)) { - case _VSTD::codecvt_base::ok: - break; - case _VSTD::codecvt_base::noconv: - __extbuf[0] = static_cast<char>(__c); - __enxt = __extbuf + 1; - break; - case codecvt_base::partial: - case codecvt_base::error: - return traits_type::eof(); + if (!__last_consumed_is_next_) + { + __c = __last_consumed_; + __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_, + traits_type::eof()); + } + return __c; } - while (__enxt > __extbuf) - if (ungetc(*--__enxt, __file_) == EOF) + if (__last_consumed_is_next_) + { + char __extbuf[__limit]; + char* __enxt; + const char_type __ci = traits_type::to_char_type(__last_consumed_); + const char_type* __inxt; + switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt, + __extbuf, __extbuf + sizeof(__extbuf), __enxt)) + { + case _VSTD::codecvt_base::ok: + break; + case _VSTD::codecvt_base::noconv: + __extbuf[0] = static_cast<char>(__last_consumed_); + __enxt = __extbuf + 1; + break; + case codecvt_base::partial: + case codecvt_base::error: return traits_type::eof(); - return traits_type::not_eof(__c); + } + while (__enxt > __extbuf) + if (ungetc(*--__enxt, __file_) == EOF) + return traits_type::eof(); + } + __last_consumed_ = __c; + __last_consumed_is_next_ = true; + return __c; } // __stdoutbuf @@ -234,30 +263,31 @@ __stdoutbuf<_CharT>::overflow(int_type __c) char_type __1buf; if (!traits_type::eq_int_type(__c, traits_type::eof())) { - this->setp(&__1buf, &__1buf+1); - *this->pptr() = traits_type::to_char_type(__c); - this->pbump(1); + __1buf = traits_type::to_char_type(__c); if (__always_noconv_) { - if (fwrite(this->pbase(), sizeof(char_type), 1, __file_) != 1) + if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1) return traits_type::eof(); } else { char* __extbe = __extbuf; codecvt_base::result __r; + char_type* pbase = &__1buf; + char_type* pptr = pbase + 1; + char_type* epptr = pptr; do { const char_type* __e; - __r = __cv_->out(*__st_, this->pbase(), this->pptr(), __e, + __r = __cv_->out(*__st_, pbase, pptr, __e, __extbuf, __extbuf + sizeof(__extbuf), __extbe); - if (__e == this->pbase()) + if (__e == pbase) return traits_type::eof(); if (__r == codecvt_base::noconv) { - if (fwrite(this->pbase(), 1, 1, __file_) != 1) + if (fwrite(pbase, 1, 1, __file_) != 1) return traits_type::eof(); } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) @@ -267,15 +297,13 @@ __stdoutbuf<_CharT>::overflow(int_type __c) return traits_type::eof(); if (__r == codecvt_base::partial) { - this->setp((char_type*)__e, this->pptr()); - this->pbump(static_cast<int>(this->epptr() - this->pbase())); + pbase = (char_type*)__e; } } else return traits_type::eof(); } while (__r == codecvt_base::partial); } - this->setp(0, 0); } return traits_type::not_eof(__c); } diff --git a/system/include/libcxx/__tree b/system/include/libcxx/__tree index cd6d7efa..9ffc38d2 100644 --- a/system/include/libcxx/__tree +++ b/system/include/libcxx/__tree @@ -644,7 +644,8 @@ public: _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator++() @@ -686,7 +687,7 @@ class _LIBCPP_TYPE_VIS __tree_const_iterator { typedef _ConstNodePtr __node_pointer; typedef typename pointer_traits<__node_pointer>::element_type __node; - typedef const typename __node::base __node_base; + typedef typename __node::base __node_base; typedef typename pointer_traits<__node_pointer>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind<__node_base> @@ -729,7 +730,8 @@ public: : __ptr_(__p.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator++() @@ -779,8 +781,10 @@ public: typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; - typedef __tree_node<value_type, typename __alloc_traits::void_pointer> __node; - typedef __tree_node_base<typename __alloc_traits::void_pointer> __node_base; + typedef typename __alloc_traits::void_pointer __void_pointer; + + typedef __tree_node<value_type, __void_pointer> __node; + typedef __tree_node_base<__void_pointer> __node_base; typedef typename __alloc_traits::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__node> @@ -790,9 +794,9 @@ public: __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; - typedef typename __node_traits::const_pointer __node_const_pointer; + typedef typename __node_traits::pointer __node_const_pointer; typedef typename __node_base::pointer __node_base_pointer; - typedef typename __node_base::const_pointer __node_base_const_pointer; + typedef typename __node_base::pointer __node_base_const_pointer; private: typedef typename __node_base::base __end_node_t; typedef typename pointer_traits<__node_pointer>::template @@ -804,9 +808,9 @@ private: __end_node_ptr; typedef typename pointer_traits<__node_pointer>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<const __end_node_t> + rebind<__end_node_t> #else - rebind<const __end_node_t>::other + rebind<__end_node_t>::other #endif __end_node_const_ptr; @@ -828,7 +832,7 @@ public: { return static_cast<__node_const_pointer> ( - pointer_traits<__end_node_const_ptr>::pointer_to(__pair1_.first()) + pointer_traits<__end_node_const_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first())) ); } _LIBCPP_INLINE_VISIBILITY @@ -865,7 +869,7 @@ public: {return static_cast<__node_const_pointer>(__end_node()->__left_);} typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator; - typedef __tree_const_iterator<value_type, __node_const_pointer, difference_type> const_iterator; + typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator; explicit __tree(const value_compare& __comp) _NOEXCEPT_( @@ -1102,6 +1106,9 @@ private: __node_pointer __detach(); static __node_pointer __detach(__node_pointer); + + template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap; }; template <class _Tp, class _Compare, class _Allocator> @@ -1161,7 +1168,7 @@ __tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) { if (__cache->__parent_ == nullptr) return nullptr; - if (__tree_is_left_child(__cache)) + if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) { __cache->__parent_->__left_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); @@ -1294,7 +1301,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) __begin_node() = __end_node(); else { - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; @@ -1314,7 +1321,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __ { __begin_node() = __t.__begin_node(); __end_node()->__left_ = __t.__end_node()->__left_; - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); size() = __t.size(); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; @@ -1342,7 +1349,7 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) __begin_node() = __end_node(); else { - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; @@ -1447,11 +1454,11 @@ __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) if (size() == 0) __begin_node() = __end_node(); else - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); if (__t.size() == 0) __t.__begin_node() = __t.__end_node(); else - __t.__end_node()->__left_->__parent_ = __t.__end_node(); + __t.__end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__t.__end_node()); } template <class _Tp, class _Compare, class _Allocator> @@ -1483,7 +1490,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } @@ -1493,13 +1500,13 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1522,7 +1529,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointe __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } @@ -1532,13 +1539,13 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointe __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1563,12 +1570,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, // *prev(__hint) <= __v <= *__hint if (__hint.__ptr_->__left_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__left_; } else { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); + __parent = static_cast<__node_base_pointer>(__prior.__ptr_); return __parent->__right_; } } @@ -1600,7 +1607,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& _ __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } @@ -1610,18 +1617,18 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& _ __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1648,12 +1655,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, // *prev(__hint) < __v < *__hint if (__hint.__ptr_->__left_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__left_; } else { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); + __parent = static_cast<__node_base_pointer>(__prior.__ptr_); return __parent->__right_; } } @@ -1669,12 +1676,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, // *__hint < __v < *_VSTD::next(__hint) if (__hint.__ptr_->__right_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__right_; } else { - __parent = const_cast<__node_pointer&>(__next.__ptr_); + __parent = static_cast<__node_base_pointer>(__next.__ptr_); return __parent->__left_; } } @@ -1682,7 +1689,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, return __find_equal(__parent, __v); } // else __v == *__hint - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent; } @@ -1729,7 +1736,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_unique(_Args&&... __args) bool __inserted = false; if (__child == nullptr) { - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1747,7 +1754,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique(const_iterator __p, _Ar __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); @@ -1761,7 +1768,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } @@ -1774,7 +1781,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } @@ -1812,7 +1819,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(_Vp&& __v) __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v)); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1824,7 +1831,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, _Vp&& __v) __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v)); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1854,7 +1861,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_unique(const value_type& __v) if (__child == nullptr) { __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1871,7 +1878,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, const val if (__child == nullptr) { __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); @@ -1884,7 +1891,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const value_type& __v) __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __v); __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1895,7 +1902,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const valu __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __v); __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1909,7 +1916,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) bool __inserted = false; if (__child == nullptr) { - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; __inserted = true; } @@ -1926,7 +1933,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; } return iterator(__r); @@ -1938,7 +1945,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) { __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_); - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } @@ -1949,7 +1956,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, { __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_); - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } @@ -1957,7 +1964,7 @@ template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { - __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __np = __p.__ptr_; iterator __r(__np); ++__r; if (__begin_node() == __np) @@ -1977,7 +1984,7 @@ __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) { while (__f != __l) __f = erase(__f); - return iterator(const_cast<__node_pointer>(__l.__ptr_)); + return iterator(__l.__ptr_); } template <class _Tp, class _Compare, class _Allocator> @@ -2264,7 +2271,7 @@ template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT { - __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __np = __p.__ptr_; if (__begin_node() == __np) { if (__np->__right_ != nullptr) diff --git a/system/include/libcxx/__tuple b/system/include/libcxx/__tuple index 1213262d..9a6b6e09 100644 --- a/system/include/libcxx/__tuple +++ b/system/include/libcxx/__tuple @@ -79,47 +79,47 @@ template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {}; template <size_t _Ip, class ..._Tp> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type& get(tuple<_Tp...>&) _NOEXCEPT; template <size_t _Ip, class ..._Tp> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, tuple<_Tp...> >::type& get(const tuple<_Tp...>&) _NOEXCEPT; template <size_t _Ip, class ..._Tp> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(tuple<_Tp...>&&) _NOEXCEPT; template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(pair<_T1, _T2>&) _NOEXCEPT; template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(const pair<_T1, _T2>&) _NOEXCEPT; template <size_t _Ip, class _T1, class _T2> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& get(pair<_T1, _T2>&&) _NOEXCEPT; template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp& get(array<_Tp, _Size>&) _NOEXCEPT; template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& get(const array<_Tp, _Size>&) _NOEXCEPT; template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& get(array<_Tp, _Size>&&) _NOEXCEPT; diff --git a/system/include/libcxx/algorithm b/system/include/libcxx/algorithm index 4adcc696..2fc1f8ab 100644 --- a/system/include/libcxx/algorithm +++ b/system/include/libcxx/algorithm @@ -87,30 +87,63 @@ template <class InputIterator1, class InputIterator2> pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); +template <class InputIterator1, class InputIterator2> + pair<InputIterator1, InputIterator2> + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2); // **C++14** + template <class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + pair<InputIterator1, InputIterator2> + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + BinaryPredicate pred); // **C++14** + template <class InputIterator1, class InputIterator2> bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); +template <class InputIterator1, class InputIterator2> + bool + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2); // **C++14** + template <class InputIterator1, class InputIterator2, class BinaryPredicate> bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); +template <class InputIterator1, class InputIterator2, class BinaryPredicate> + bool + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + BinaryPredicate pred); // **C++14** + template<class ForwardIterator1, class ForwardIterator2> bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); +template<class ForwardIterator1, class ForwardIterator2> + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); // **C++14** + template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); +template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred); // **C++14** + template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, @@ -1087,6 +1120,32 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } +#if _LIBCPP_STD_VER > 11 +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, + _BinaryPredicate __pred) +{ + for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + break; + return pair<_InputIterator1, _InputIterator2>(__first1, __first2); +} + +template <class _InputIterator1, class _InputIterator2> +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} +#endif + // equal template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> @@ -1110,6 +1169,60 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } +#if _LIBCPP_STD_VER > 11 +template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2> +inline _LIBCPP_INLINE_VISIBILITY +bool +__equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred, + input_iterator_tag, input_iterator_tag ) +{ + for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + return false; + return __first1 == __last1 && __first2 == __last2; +} + +template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +inline _LIBCPP_INLINE_VISIBILITY +bool +__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag ) +{ + if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) + return false; + return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2, + typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __pred ); +} + +template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred ) +{ + return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_InputIterator1>::iterator_category(), + typename iterator_traits<_InputIterator2>::iterator_category()); +} + +template <class _InputIterator1, class _InputIterator2> +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + typedef typename iterator_traits<_InputIterator1>::value_type __v1; + typedef typename iterator_traits<_InputIterator2>::value_type __v2; + return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), + typename iterator_traits<_InputIterator1>::iterator_category(), + typename iterator_traits<_InputIterator2>::iterator_category()); +} +#endif + // is_permutation template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> @@ -1169,6 +1282,100 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } +#if _LIBCPP_STD_VER > 11 +template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> +bool +__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag ) +{ + // shorten sequences as much as possible by lopping of any equal parts + for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + goto __not_done; + return __first1 == __last1 && __first2 == __last2; +__not_done: + // __first1 != __last1 && __first2 != __last2 && *__first1 != *__first2 + typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; + _D1 __l1 = _VSTD::distance(__first1, __last1); + + typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2; + _D2 __l2 = _VSTD::distance(__first2, __last2); + if (__l1 != __l2) + return false; + + // For each element in [f1, l1) see if there are the same number of + // equal elements in [f2, l2) + for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) + { + // Have we already counted the number of *__i in [f1, l1)? + for (_ForwardIterator1 __j = __first1; __j != __i; ++__j) + if (__pred(*__j, *__i)) + goto __next_iter; + { + // Count number of *__i in [f2, l2) + _D1 __c2 = 0; + for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) + if (__pred(*__i, *__j)) + ++__c2; + if (__c2 == 0) + return false; + // Count number of *__i in [__i, l1) (we can start with 1) + _D1 __c1 = 1; + for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) + if (__pred(*__i, *__j)) + ++__c1; + if (__c1 != __c2) + return false; + } +__next_iter:; + } + return true; +} + +template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> +bool +__is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1, + _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, + _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag ) +{ + if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) + return false; + return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2, + typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __pred ); +} + +template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> +inline _LIBCPP_INLINE_VISIBILITY +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _BinaryPredicate __pred ) +{ + return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template<class _ForwardIterator1, class _ForwardIterator2> +inline _LIBCPP_INLINE_VISIBILITY +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::__is_permutation(__first1, __last1, __first2, __last2, + __equal_to<__v1, __v2>(), + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} +#endif + // search template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> @@ -1398,7 +1605,7 @@ __search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, // Find first element in sequence that matchs __value_, with a mininum of loop checks while (true) { - if (__first == __s) // return __last if no element matches __value_ + if (__first >= __s) // return __last if no element matches __value_ return __last; if (__pred(*__first, __value_)) break; @@ -1780,17 +1987,23 @@ replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator _ template <class _OutputIterator, class _Size, class _Tp> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator -__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, false_type) +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { for (; __n > 0; ++__first, --__n) *__first = __value_; return __first; } -template <class _OutputIterator, class _Size, class _Tp> +template <class _Tp, class _Size, class _Up> inline _LIBCPP_INLINE_VISIBILITY -_OutputIterator -__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, true_type) +typename enable_if +< + is_integral<_Tp>::value && sizeof(_Tp) == 1 && + !is_same<_Tp, bool>::value && + is_integral<_Up>::value && sizeof(_Up) == 1, + _Tp* +>::type +__fill_n(_Tp* __first, _Size __n,_Up __value_) { if (__n > 0) _VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n)); @@ -1802,10 +2015,7 @@ inline _LIBCPP_INLINE_VISIBILITY _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { - return _VSTD::__fill_n(__first, __n, __value_, integral_constant<bool, - is_pointer<_OutputIterator>::value && - is_trivially_copy_assignable<_Tp>::value && - sizeof(_Tp) == 1>()); + return _VSTD::__fill_n(__first, __n, __value_); } // fill @@ -3778,10 +3988,10 @@ sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) _VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); } -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( push ) #pragma warning( disable: 4231) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(void __sort<__less<char>&, char*>(char*, char*, __less<char>&)) _LIBCPP_EXTERN_TEMPLATE(void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&)) _LIBCPP_EXTERN_TEMPLATE(void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&)) @@ -3815,9 +4025,9 @@ _LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<double>&, double _LIBCPP_EXTERN_TEMPLATE(bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&)) _LIBCPP_EXTERN_TEMPLATE(unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&)) -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( pop ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC // lower_bound diff --git a/system/include/libcxx/array b/system/include/libcxx/array index bcf53478..86d1fc0b 100644 --- a/system/include/libcxx/array +++ b/system/include/libcxx/array @@ -59,14 +59,14 @@ struct array // element access: reference operator[](size_type n); - const_reference operator[](size_type n) const; - const_reference at(size_type n) const; + const_reference operator[](size_type n) const; // constexpr in C++14 + const_reference at(size_type n) const; // constexpr in C++14 reference at(size_type n); reference front(); - const_reference front() const; + const_reference front() const; // constexpr in C++14 reference back(); - const_reference back() const; + const_reference back() const; // constexpr in C++14 T* data() noexcept; const T* data() const noexcept; @@ -92,9 +92,9 @@ template <class T> class tuple_size; template <int I, class T> class tuple_element; template <class T, size_t N> struct tuple_size<array<T, N>>; template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>; -template <int I, class T, size_t N> T& get(array<T, N>&) noexcept; -template <int I, class T, size_t N> const T& get(const array<T, N>&) noexcept; -template <int I, class T, size_t N> T&& get(array<T, N>&&) noexcept; +template <int I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 +template <int I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 +template <int I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 } // std @@ -181,14 +181,14 @@ struct _LIBCPP_TYPE_VIS array // element access: _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];} - _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __elems_[__n];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference operator[](size_type __n) const {return __elems_[__n];} reference at(size_type __n); - const_reference at(size_type __n) const; + _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; _LIBCPP_INLINE_VISIBILITY reference front() {return __elems_[0];} - _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} _LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} - _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY value_type* data() _NOEXCEPT {return __elems_;} @@ -210,6 +210,7 @@ array<_Tp, _Size>::at(size_type __n) } template <class _Tp, size_t _Size> +_LIBCPP_CONSTEXPR_AFTER_CXX11 typename array<_Tp, _Size>::const_reference array<_Tp, _Size>::at(size_type __n) const { @@ -306,32 +307,32 @@ public: }; template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp& get(array<_Tp, _Size>& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); - return __a[_Ip]; + return __a.__elems_[_Ip]; } template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& get(const array<_Tp, _Size>& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); - return __a[_Ip]; + return __a.__elems_[_Ip]; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <size_t _Ip, class _Tp, size_t _Size> -_LIBCPP_INLINE_VISIBILITY inline +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& get(array<_Tp, _Size>&& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); - return _VSTD::move(__a[_Ip]); + return _VSTD::move(__a.__elems_[_Ip]); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES diff --git a/system/include/libcxx/atomic b/system/include/libcxx/atomic index db67e762..f6ab1cba 100644 --- a/system/include/libcxx/atomic +++ b/system/include/libcxx/atomic @@ -622,7 +622,12 @@ struct __atomic_base // false {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY - __atomic_base() _NOEXCEPT {} // = default; +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + __atomic_base() _NOEXCEPT = default; +#else + __atomic_base() _NOEXCEPT : __a_() {} +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS @@ -645,7 +650,7 @@ struct __atomic_base<_Tp, true> { typedef __atomic_base<_Tp, false> __base; _LIBCPP_INLINE_VISIBILITY - __atomic_base() _NOEXCEPT {} // = default; + __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} @@ -726,7 +731,7 @@ struct atomic { typedef __atomic_base<_Tp> __base; _LIBCPP_INLINE_VISIBILITY - atomic() _NOEXCEPT {} // = default; + atomic() _NOEXCEPT _LIBCPP_DEFAULT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} @@ -746,7 +751,7 @@ struct atomic<_Tp*> { typedef __atomic_base<_Tp*> __base; _LIBCPP_INLINE_VISIBILITY - atomic() _NOEXCEPT {} // = default; + atomic() _NOEXCEPT _LIBCPP_DEFAULT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} @@ -1367,7 +1372,12 @@ typedef struct atomic_flag {__c11_atomic_store(&__a_, false, __m);} _LIBCPP_INLINE_VISIBILITY - atomic_flag() _NOEXCEPT {} // = default; +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + atomic_flag() _NOEXCEPT = default; +#else + atomic_flag() _NOEXCEPT : __a_() {} +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} diff --git a/system/include/libcxx/cctype b/system/include/libcxx/cctype index e33244e7..b647903c 100644 --- a/system/include/libcxx/cctype +++ b/system/include/libcxx/cctype @@ -37,9 +37,9 @@ int toupper(int c); #include <__config> #include <ctype.h> -#if defined(_MSC_VER) +#if defined(_LIBCPP_MSVCRT) #include "support/win32/support.h" -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/system/include/libcxx/chrono b/system/include/libcxx/chrono index 3b96e816..da550498 100644 --- a/system/include/libcxx/chrono +++ b/system/include/libcxx/chrono @@ -111,16 +111,16 @@ private: duration d_; // exposition only public: - time_point(); // has value "epoch" - explicit time_point(const duration& d); // same as time_point() + d + time_point(); // has value "epoch" // constexpr in C++14 + explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 // conversions template <class Duration2> - time_point(const time_point<clock, Duration2>& t); + time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 // observer - duration time_since_epoch() const; + duration time_since_epoch() const; // constexpr in C++14 // arithmetic @@ -194,7 +194,7 @@ template <class Rep1, class Period1, class Rep2, class Period2> template <class ToDuration, class Rep, class Period> ToDuration duration_cast(const duration<Rep, Period>& d); -// time_point arithmetic +// time_point arithmetic (all constexpr in C++14) template <class Clock, class Duration1, class Rep2, class Period2> time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); @@ -208,7 +208,7 @@ template <class Clock, class Duration1, class Duration2> typename common_type<Duration1, Duration2>::type operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// time_point comparisons +// time_point comparisons (all constexpr in C++14) template <class Clock, class Duration1, class Duration2> bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); template <class Clock, class Duration1, class Duration2> @@ -222,7 +222,7 @@ template <class Clock, class Duration1, class Duration2> template <class Clock, class Duration1, class Duration2> bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); -// time_point_cast +// time_point_cast (constexpr in C++14) template <class ToDuration, class Clock, class Duration> time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); @@ -236,7 +236,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<system_clock> time_point; - static const bool is_steady = false; + static const bool is_steady = false; // constexpr in C++14 static time_point now() noexcept; static time_t to_time_t (const time_point& __t) noexcept; @@ -250,7 +250,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<steady_clock, duration> time_point; - static const bool is_steady = true; + static const bool is_steady = true; // constexpr in C++14 static time_point now() noexcept; }; @@ -259,6 +259,19 @@ typedef steady_clock high_resolution_clock; } // chrono +constexpr chrono::hours operator "" h(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14 +constexpr chrono::minutes operator "" min(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14 +constexpr chrono::seconds operator "" s(unsigned long long); // C++14 +constexpr chrono::duration<unspecified > operator "" s(long double); // C++14 +constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14 +constexpr chrono::microseconds operator "" us(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14 +constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14 + } // std */ @@ -403,7 +416,13 @@ private: rep __rep_; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration() {} // = default; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + duration() = default; +#else + duration() {} +#endif + template <class _Rep2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r, @@ -468,7 +487,7 @@ template <class _LhsDuration, class _RhsDuration> struct __duration_eq { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; return _Ct(__lhs).count() == _Ct(__rhs).count(); @@ -479,7 +498,7 @@ template <class _LhsDuration> struct __duration_eq<_LhsDuration, _LhsDuration> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {return __lhs.count() == __rhs.count();} }; @@ -509,7 +528,7 @@ template <class _LhsDuration, class _RhsDuration> struct __duration_lt { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) + bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; return _Ct(__lhs).count() < _Ct(__rhs).count(); @@ -520,7 +539,7 @@ template <class _LhsDuration> struct __duration_lt<_LhsDuration, _LhsDuration> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) + bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {return __lhs.count() < __rhs.count();} }; @@ -709,12 +728,12 @@ private: duration __d_; public: - _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {} - _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} // conversions template <class _Duration2> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point(const time_point<clock, _Duration2>& t, typename enable_if < @@ -724,12 +743,12 @@ public: // observer - _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} // arithmetic - _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} - _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} + _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} + _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} // special values @@ -749,7 +768,7 @@ struct _LIBCPP_TYPE_VIS common_type<chrono::time_point<_Clock, _Duration1>, namespace chrono { template <class _ToDuration, class _Clock, class _Duration> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, _ToDuration> time_point_cast(const time_point<_Clock, _Duration>& __t) { @@ -759,7 +778,7 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) // time_point == template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -769,7 +788,7 @@ operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point != template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -779,7 +798,7 @@ operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point < template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -789,7 +808,7 @@ operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point > template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -799,7 +818,7 @@ operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point <= template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -809,7 +828,7 @@ operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point >= template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -819,20 +838,18 @@ operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, // time_point operator+(time_point x, duration y); template <class _Clock, class _Duration1, class _Rep2, class _Period2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; - _Tr __r(__lhs.time_since_epoch()); - __r += __rhs; - return __r; + return _Tr (__lhs.time_since_epoch() + __rhs); } // time_point operator+(duration x, time_point y); template <class _Rep1, class _Period1, class _Clock, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -842,7 +859,7 @@ operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Dura // time_point operator-(time_point x, duration y); template <class _Clock, class _Duration1, class _Rep2, class _Period2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { @@ -852,7 +869,7 @@ operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Pe // duration operator-(time_point x, time_point y); template <class _Clock, class _Duration1, class _Duration2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename common_type<_Duration1, _Duration2>::type operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { @@ -870,7 +887,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<system_clock> time_point; - static const bool is_steady = false; + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; static time_point now() _NOEXCEPT; static time_t to_time_t (const time_point& __t) _NOEXCEPT; @@ -884,7 +901,7 @@ public: typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<steady_clock, duration> time_point; - static const bool is_steady = true; + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; static time_point now() _NOEXCEPT; }; @@ -893,6 +910,84 @@ typedef steady_clock high_resolution_clock; } // chrono +#if _LIBCPP_STD_VER > 11 +// Literal suffixes for chrono types +// inline // Deviation from N3690. +// We believe the inline to be a defect and have submitted an LWG issue. +// An LWG issue number has not yet been assigned. +namespace literals +{ + inline namespace chrono_literals + { + + constexpr chrono::hours operator"" h(unsigned long long __h) + { + return chrono::hours(static_cast<chrono::hours::rep>(__h)); + } + + constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h) + { + return chrono::duration<long double, ratio<3600,1>>(__h); + } + + + constexpr chrono::minutes operator"" min(unsigned long long __m) + { + return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); + } + + constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m) + { + return chrono::duration<long double, ratio<60,1>> (__m); + } + + + constexpr chrono::seconds operator"" s(unsigned long long __s) + { + return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); + } + + constexpr chrono::duration<long double> operator"" s(long double __s) + { + return chrono::duration<long double> (__s); + } + + + constexpr chrono::milliseconds operator"" ms(unsigned long long __ms) + { + return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); + } + + constexpr chrono::duration<long double, milli> operator"" ms(long double __ms) + { + return chrono::duration<long double, milli>(__ms); + } + + + constexpr chrono::microseconds operator"" us(unsigned long long __us) + { + return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); + } + + constexpr chrono::duration<long double, micro> operator"" us(long double __us) + { + return chrono::duration<long double, micro> (__us); + } + + + constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns) + { + return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); + } + + constexpr chrono::duration<long double, nano> operator"" ns(long double __ns) + { + return chrono::duration<long double, nano> (__ns); + } + +}} +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CHRONO diff --git a/system/include/libcxx/cmath b/system/include/libcxx/cmath index bd603441..3e545cea 100644 --- a/system/include/libcxx/cmath +++ b/system/include/libcxx/cmath @@ -301,7 +301,7 @@ long double truncl(long double x); #include <math.h> #include <type_traits> -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVCRT #include "support/win32/math_win32.h" #endif @@ -673,7 +673,7 @@ abs(long double __x) _NOEXCEPT {return fabsl(__x);} using ::acos; using ::acosf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float acos(float __x) _NOEXCEPT {return acosf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) _NOEXCEPT {return acosl(__x);} #endif @@ -688,7 +688,7 @@ acos(_A1 __x) _NOEXCEPT {return acos((double)__x);} using ::asin; using ::asinf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float asin(float __x) _NOEXCEPT {return asinf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) _NOEXCEPT {return asinl(__x);} #endif @@ -703,7 +703,7 @@ asin(_A1 __x) _NOEXCEPT {return asin((double)__x);} using ::atan; using ::atanf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float atan(float __x) _NOEXCEPT {return atanf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) _NOEXCEPT {return atanl(__x);} #endif @@ -718,7 +718,7 @@ atan(_A1 __x) _NOEXCEPT {return atan((double)__x);} using ::atan2; using ::atan2f; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float atan2(float __y, float __x) _NOEXCEPT {return atan2f(__y, __x);} inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) _NOEXCEPT {return atan2l(__y, __x);} #endif @@ -744,7 +744,7 @@ atan2(_A1 __y, _A2 __x) _NOEXCEPT using ::ceil; using ::ceilf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float ceil(float __x) _NOEXCEPT {return ceilf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) _NOEXCEPT {return ceill(__x);} #endif @@ -759,7 +759,7 @@ ceil(_A1 __x) _NOEXCEPT {return ceil((double)__x);} using ::cos; using ::cosf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float cos(float __x) _NOEXCEPT {return cosf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) _NOEXCEPT {return cosl(__x);} #endif @@ -774,7 +774,7 @@ cos(_A1 __x) _NOEXCEPT {return cos((double)__x);} using ::cosh; using ::coshf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float cosh(float __x) _NOEXCEPT {return coshf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) _NOEXCEPT {return coshl(__x);} #endif @@ -792,7 +792,7 @@ using ::expf; #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float exp(float __x) _NOEXCEPT {return expf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) _NOEXCEPT {return expl(__x);} #endif @@ -808,7 +808,7 @@ exp(_A1 __x) _NOEXCEPT {return exp((double)__x);} using ::fabs; using ::fabsf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float fabs(float __x) _NOEXCEPT {return fabsf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) _NOEXCEPT {return fabsl(__x);} #endif @@ -823,7 +823,7 @@ fabs(_A1 __x) _NOEXCEPT {return fabs((double)__x);} using ::floor; using ::floorf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float floor(float __x) _NOEXCEPT {return floorf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) _NOEXCEPT {return floorl(__x);} #endif @@ -840,7 +840,7 @@ using ::fmod; using ::fmodf; #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float fmod(float __x, float __y) _NOEXCEPT {return fmodf(__x, __y);} inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) _NOEXCEPT {return fmodl(__x, __y);} #endif @@ -867,7 +867,7 @@ fmod(_A1 __x, _A2 __y) _NOEXCEPT using ::frexp; using ::frexpf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float frexp(float __x, int* __e) _NOEXCEPT {return frexpf(__x, __e);} inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) _NOEXCEPT {return frexpl(__x, __e);} #endif @@ -882,7 +882,7 @@ frexp(_A1 __x, int* __e) _NOEXCEPT {return frexp((double)__x, __e);} using ::ldexp; using ::ldexpf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __x, int __e) _NOEXCEPT {return ldexpf(__x, __e);} inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) _NOEXCEPT {return ldexpl(__x, __e);} #endif @@ -899,7 +899,7 @@ using ::log; using ::logf; #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float log(float __x) _NOEXCEPT {return logf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) _NOEXCEPT {return logl(__x);} #endif @@ -915,7 +915,7 @@ log(_A1 __x) _NOEXCEPT {return log((double)__x);} using ::log10; using ::log10f; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float log10(float __x) _NOEXCEPT {return log10f(__x);} inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) _NOEXCEPT {return log10l(__x);} #endif @@ -930,7 +930,7 @@ log10(_A1 __x) _NOEXCEPT {return log10((double)__x);} using ::modf; using ::modff; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float modf(float __x, float* __y) _NOEXCEPT {return modff(__x, __y);} inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) _NOEXCEPT {return modfl(__x, __y);} #endif @@ -943,7 +943,7 @@ using ::powf; #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float pow(float __x, float __y) _NOEXCEPT {return powf(__x, __y);} inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) _NOEXCEPT {return powl(__x, __y);} #endif @@ -970,7 +970,7 @@ pow(_A1 __x, _A2 __y) _NOEXCEPT using ::sin; using ::sinf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float sin(float __x) _NOEXCEPT {return sinf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) _NOEXCEPT {return sinl(__x);} #endif @@ -985,7 +985,7 @@ sin(_A1 __x) _NOEXCEPT {return sin((double)__x);} using ::sinh; using ::sinhf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float sinh(float __x) _NOEXCEPT {return sinhf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) _NOEXCEPT {return sinhl(__x);} #endif @@ -1002,7 +1002,7 @@ using ::sqrt; using ::sqrtf; -#if !(defined(_MSC_VER) || defined(__sun__)) +#if !(defined(_LIBCPP_MSVCRT) || defined(__sun__)) inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __x) _NOEXCEPT {return sqrtf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) _NOEXCEPT {return sqrtl(__x);} #endif @@ -1018,7 +1018,7 @@ using ::tan; using ::tanf; #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float tan(float __x) _NOEXCEPT {return tanf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) _NOEXCEPT {return tanl(__x);} #endif @@ -1033,7 +1033,7 @@ tan(_A1 __x) _NOEXCEPT {return tan((double)__x);} using ::tanh; using ::tanhf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT inline _LIBCPP_INLINE_VISIBILITY float tanh(float __x) _NOEXCEPT {return tanhf(__x);} inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) _NOEXCEPT {return tanhl(__x);} #endif @@ -1045,7 +1045,7 @@ tanh(_A1 __x) _NOEXCEPT {return tanh((double)__x);} // acosh -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::acosh; using ::acoshf; @@ -1060,7 +1060,7 @@ acosh(_A1 __x) _NOEXCEPT {return acosh((double)__x);} // asinh -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::asinh; using ::asinhf; @@ -1075,7 +1075,7 @@ asinh(_A1 __x) _NOEXCEPT {return asinh((double)__x);} // atanh -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::atanh; using ::atanhf; @@ -1090,7 +1090,7 @@ atanh(_A1 __x) _NOEXCEPT {return atanh((double)__x);} // cbrt -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::cbrt; using ::cbrtf; @@ -1127,7 +1127,7 @@ copysign(_A1 __x, _A2 __y) _NOEXCEPT return copysign((__result_type)__x, (__result_type)__y); } -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT // erf @@ -1426,13 +1426,18 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<is_integral<_A1>::value, long>::type lround(_A1 __x) _NOEXCEPT {return lround((double)__x);} -// nan -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #endif // __sun__ + +// nan + +#ifndef _LIBCPP_MSVCRT using ::nan; using ::nanf; +#endif // _LIBCPP_MSVCRT + #ifndef __sun__ -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT // nearbyint @@ -1610,7 +1615,7 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<is_integral<_A1>::value, double>::type trunc(_A1 __x) _NOEXCEPT {return trunc((double)__x);} -#endif // !_MSC_VER +#endif // !_LIBCPP_MSVCRT using ::acosl; using ::asinl; @@ -1633,15 +1638,15 @@ using ::sinl; using ::sinhl; using ::sqrtl; using ::tanl; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::tanhl; using ::acoshl; using ::asinhl; using ::atanhl; using ::cbrtl; -#endif // !_MSC_VER +#endif // !_LIBCPP_MSVCRT using ::copysignl; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::erfl; using ::erfcl; using ::exp2l; @@ -1672,7 +1677,7 @@ using ::scalblnl; using ::scalbnl; using ::tgammal; using ::truncl; -#endif // !_MSC_VER +#endif // !_LIBCPP_MSVCRT #else using ::lgamma; diff --git a/system/include/libcxx/complex b/system/include/libcxx/complex index a09bf70f..dddc58e0 100644 --- a/system/include/libcxx/complex +++ b/system/include/libcxx/complex @@ -23,12 +23,12 @@ class complex public: typedef T value_type; - complex(const T& re = T(), const T& im = T()); - complex(const complex&); - template<class X> complex(const complex<X>&); + complex(const T& re = T(), const T& im = T()); // constexpr in C++14 + complex(const complex&); // constexpr in C++14 + template<class X> complex(const complex<X>&); // constexpr in C++14 - T real() const; - T imag() const; + T real() const; // constexpr in C++14 + T imag() const; // constexpr in C++14 void real(T); void imag(T); @@ -149,12 +149,12 @@ template<class T> complex<T> operator/(const complex<T>&, const T&); template<class T> complex<T> operator/(const T&, const complex<T>&); template<class T> complex<T> operator+(const complex<T>&); template<class T> complex<T> operator-(const complex<T>&); -template<class T> bool operator==(const complex<T>&, const complex<T>&); -template<class T> bool operator==(const complex<T>&, const T&); -template<class T> bool operator==(const T&, const complex<T>&); -template<class T> bool operator!=(const complex<T>&, const complex<T>&); -template<class T> bool operator!=(const complex<T>&, const T&); -template<class T> bool operator!=(const T&, const complex<T>&); +template<class T> bool operator==(const complex<T>&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator==(const complex<T>&, const T&); // constexpr in C++14 +template<class T> bool operator==(const T&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator!=(const complex<T>&, const complex<T>&); // constexpr in C++14 +template<class T> bool operator!=(const complex<T>&, const T&); // constexpr in C++14 +template<class T> bool operator!=(const T&, const complex<T>&); // constexpr in C++14 template<class T, class charT, class traits> basic_istream<charT, traits>& @@ -165,17 +165,17 @@ template<class T, class charT, class traits> // 26.3.7 values: -template<class T> T real(const complex<T>&); - long double real(long double); - double real(double); -template<Integral T> double real(T); - float real(float); +template<class T> T real(const complex<T>&); // constexpr in C++14 + long double real(long double); // constexpr in C++14 + double real(double); // constexpr in C++14 +template<Integral T> double real(T); // constexpr in C++14 + float real(float); // constexpr in C++14 -template<class T> T imag(const complex<T>&); - long double imag(long double); - double imag(double); -template<Integral T> double imag(T); - float imag(float); +template<class T> T imag(const complex<T>&); // constexpr in C++14 + long double imag(long double); // constexpr in C++14 + double imag(double); // constexpr in C++14 +template<Integral T> double imag(T); // constexpr in C++14 + float imag(float); // constexpr in C++14 template<class T> T abs(const complex<T>&); @@ -269,15 +269,15 @@ private: value_type __re_; value_type __im_; public: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 complex(const value_type& __re = value_type(), const value_type& __im = value_type()) : __re_(__re), __im_(__im) {} - template<class _Xp> _LIBCPP_INLINE_VISIBILITY + template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 complex(const complex<_Xp>& __c) : __re_(__c.real()), __im_(__c.imag()) {} - _LIBCPP_INLINE_VISIBILITY value_type real() const {return __re_;} - _LIBCPP_INLINE_VISIBILITY value_type imag() const {return __im_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;} _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} @@ -309,12 +309,12 @@ public: } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -368,12 +368,12 @@ public: } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -424,12 +424,12 @@ public: } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -480,12 +480,12 @@ public: } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c) { - *this = *this * __c; + *this = *this * complex(__c.real(), __c.imag()); return *this; } template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c) { - *this = *this / __c; + *this = *this / complex(__c.real(), __c.imag()); return *this; } }; @@ -740,7 +740,7 @@ operator-(const complex<_Tp>& __x) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) { @@ -748,7 +748,7 @@ operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const complex<_Tp>& __x, const _Tp& __y) { @@ -756,7 +756,7 @@ operator==(const complex<_Tp>& __x, const _Tp& __y) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const _Tp& __x, const complex<_Tp>& __y) { @@ -764,7 +764,7 @@ operator==(const _Tp& __x, const complex<_Tp>& __y) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) { @@ -772,7 +772,7 @@ operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const complex<_Tp>& __x, const _Tp& __y) { @@ -780,7 +780,7 @@ operator!=(const complex<_Tp>& __x, const _Tp& __y) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const _Tp& __x, const complex<_Tp>& __y) { @@ -792,21 +792,21 @@ operator!=(const _Tp& __x, const complex<_Tp>& __y) // real template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp real(const complex<_Tp>& __c) { return __c.real(); } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 long double real(long double __re) { return __re; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 double real(double __re) { @@ -814,7 +814,7 @@ real(double __re) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename enable_if < is_integral<_Tp>::value, @@ -825,7 +825,7 @@ real(_Tp __re) return __re; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 float real(float __re) { @@ -835,21 +835,21 @@ real(float __re) // imag template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp imag(const complex<_Tp>& __c) { return __c.imag(); } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 long double imag(long double __re) { return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 double imag(double __re) { @@ -857,7 +857,7 @@ imag(double __re) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename enable_if < is_integral<_Tp>::value, @@ -868,7 +868,7 @@ imag(_Tp __re) return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 float imag(float __re) { diff --git a/system/include/libcxx/cstdio b/system/include/libcxx/cstdio index 718d2f71..1cde3eee 100644 --- a/system/include/libcxx/cstdio +++ b/system/include/libcxx/cstdio @@ -138,12 +138,12 @@ using ::scanf; using ::snprintf; using ::sprintf; using ::sscanf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::vfprintf; using ::vfscanf; using ::vscanf; using ::vsscanf; -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT using ::vprintf; using ::vsnprintf; using ::vsprintf; diff --git a/system/include/libcxx/cstdlib b/system/include/libcxx/cstdlib index 95e38428..0a96fb0a 100644 --- a/system/include/libcxx/cstdlib +++ b/system/include/libcxx/cstdlib @@ -84,9 +84,9 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #include <__config> #include <stdlib.h> -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVCRT #include "support/win32/locale_win32.h" -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -154,8 +154,8 @@ using ::quick_exit; using ::aligned_alloc; #endif -// MSVC already has the correct prototype in <stdlib.h.h> #ifdef __cplusplus -#if !defined(_MSC_VER) && !defined(__sun__) +// MSVCRT already has the correct prototype in <stdlib.h> #ifdef __cplusplus +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);} #ifndef _LIBCPP_HAS_NO_LONG_LONG inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);} @@ -165,7 +165,7 @@ inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEX #ifndef _LIBCPP_HAS_NO_LONG_LONG inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);} #endif // _LIBCPP_HAS_NO_LONG_LONG -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT _LIBCPP_END_NAMESPACE_STD diff --git a/system/include/libcxx/cstring b/system/include/libcxx/cstring index 13bb1189..21c9155c 100644 --- a/system/include/libcxx/cstring +++ b/system/include/libcxx/cstring @@ -93,8 +93,8 @@ using ::strspn; using ::strstr; -// MSVC, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus -#if !defined(__GLIBC__) && !defined(_MSC_VER) && !defined(__sun__) +// MSVCRT, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus +#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_) inline _LIBCPP_INLINE_VISIBILITY char* strchr( char* __s, int __c) {return ::strchr(__s, __c);} inline _LIBCPP_INLINE_VISIBILITY char* strpbrk( char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);} inline _LIBCPP_INLINE_VISIBILITY char* strrchr( char* __s, int __c) {return ::strrchr(__s, __c);} diff --git a/system/include/libcxx/cwchar b/system/include/libcxx/cwchar index caed08de..90eae75e 100644 --- a/system/include/libcxx/cwchar +++ b/system/include/libcxx/cwchar @@ -106,9 +106,9 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, #include <__config> #include <cwctype> #include <wchar.h> -#ifdef _WIN32 +#ifdef _LIBCPP_MSVCRT #include <support/win32/support.h> // pull in *swprintf defines -#endif // _WIN32 +#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -127,12 +127,12 @@ using ::swprintf; using ::vfwprintf; using ::vswprintf; using ::vwprintf; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::swscanf; using ::vfwscanf; using ::vswscanf; using ::vwscanf; -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT using ::wprintf; using ::wscanf; using ::fgetwc; @@ -146,10 +146,10 @@ using ::putwc; using ::putwchar; using ::ungetwc; using ::wcstod; -#ifndef _MSC_VER +#ifndef _LIBCPP_MSVCRT using ::wcstof; using ::wcstold; -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT using ::wcstol; #ifndef _LIBCPP_HAS_NO_LONG_LONG using ::wcstoll; @@ -167,28 +167,37 @@ using ::wcscoll; using ::wcsncmp; using ::wcsxfrm; +#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_) + +using ::wcschr; +using ::wcspbrk; +using ::wcsrchr; +using ::wcsstr; +using ::wmemchr; + +#else + inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} -using ::wcscspn; -using ::wcslen; - inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcspbrk( wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);} inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcsrchr( wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);} -using ::wcsspn; - inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcsstr( wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);} -using ::wcstok; - inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} +#endif + +using ::wcscspn; +using ::wcslen; +using ::wcsspn; +using ::wcstok; using ::wmemcmp; using ::wmemcpy; using ::wmemmove; diff --git a/system/include/libcxx/deque b/system/include/libcxx/deque index 8e098223..86272721 100644 --- a/system/include/libcxx/deque +++ b/system/include/libcxx/deque @@ -278,7 +278,11 @@ public: typedef random_access_iterator_tag iterator_category; typedef _Reference reference; - _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __m_iter_(nullptr), __ptr_(nullptr) +#endif + {} template <class _Pp, class _Rp, class _MP> _LIBCPP_INLINE_VISIBILITY @@ -915,7 +919,14 @@ protected: __pointer_allocator; typedef allocator_traits<__pointer_allocator> __map_traits; typedef typename __map_traits::pointer __map_pointer; - typedef typename __map_traits::const_pointer __map_const_pointer; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<const_pointer> +#else + rebind_alloc<const_pointer>::other +#endif + __const_pointer_allocator; + typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; typedef __split_buffer<pointer, __pointer_allocator> __map; typedef __deque_iterator<value_type, pointer, reference, __map_pointer, @@ -1053,7 +1064,7 @@ template <class _Tp, class _Allocator> typename __deque_base<_Tp, _Allocator>::const_iterator __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT { - __map_const_pointer __mp = __map_.begin() + __start_ / __block_size; + __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); } @@ -1071,7 +1082,7 @@ typename __deque_base<_Tp, _Allocator>::const_iterator __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT { size_type __p = size() + __start_; - __map_const_pointer __mp = __map_.begin() + __p / __block_size; + __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); } @@ -1341,6 +1352,8 @@ public: _LIBCPP_INLINE_VISIBILITY bool __invariants() const {return __base::__invariants();} private: + typedef typename __base::__map_const_pointer __map_const_pointer; + _LIBCPP_INLINE_VISIBILITY static size_type __recommend_blocks(size_type __n) { @@ -2505,9 +2518,9 @@ void deque<_Tp, _Allocator>::pop_front() { allocator_type& __a = __base::__alloc(); - __alloc_traits::destroy(__a, *(__base::__map_.begin() + - __base::__start_ / __base::__block_size) + - __base::__start_ % __base::__block_size); + __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + + __base::__start_ / __base::__block_size) + + __base::__start_ % __base::__block_size)); --__base::size(); if (++__base::__start_ >= 2 * __base::__block_size) { @@ -2523,9 +2536,9 @@ deque<_Tp, _Allocator>::pop_back() { allocator_type& __a = __base::__alloc(); size_type __p = __base::size() + __base::__start_ - 1; - __alloc_traits::destroy(__a, *(__base::__map_.begin() + - __p / __base::__block_size) + - __p % __base::__block_size); + __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + + __p / __base::__block_size) + + __p % __base::__block_size)); --__base::size(); if (__back_spare() >= 2 * __base::__block_size) { @@ -2556,7 +2569,7 @@ deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __ __fe = __fb + __bs; } if (__fb <= __vt && __vt < __fe) - __vt = (const_iterator(__f.__m_iter_, __vt) -= __f - __r).__ptr_; + __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; __r = _VSTD::move(__fb, __fe, __r); __n -= __bs; __f += __bs; @@ -2587,7 +2600,7 @@ deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, it __lb = __le - __bs; } if (__lb <= __vt && __vt < __le) - __vt = (const_iterator(__l.__m_iter_, __vt) += __r - __l - 1).__ptr_; + __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; __r = _VSTD::move_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; @@ -2618,7 +2631,7 @@ deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, __fe = __fb + __bs; } if (__fb <= __vt && __vt < __fe) - __vt = (const_iterator(__f.__m_iter_, __vt) += __r - __f).__ptr_; + __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); __n -= __bs; @@ -2654,7 +2667,7 @@ deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterat __lb = __le - __bs; } if (__lb <= __vt && __vt < __le) - __vt = (const_iterator(__l.__m_iter_, __vt) -= __l - __r + 1).__ptr_; + __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; while (__le != __lb) { __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); diff --git a/system/include/libcxx/forward_list b/system/include/libcxx/forward_list index 0cbf2fdb..88bf75f9 100644 --- a/system/include/libcxx/forward_list +++ b/system/include/libcxx/forward_list @@ -232,7 +232,7 @@ public: typedef forward_iterator_tag iterator_category; typedef typename pointer_traits<__node_pointer>::element_type::value_type value_type; - typedef value_type& reference; + typedef value_type& reference; typedef typename pointer_traits<__node_pointer>::difference_type difference_type; typedef typename pointer_traits<__node_pointer>::template @@ -249,7 +249,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__ptr_->__value_;} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __forward_list_iterator& operator++() @@ -303,7 +303,7 @@ class _LIBCPP_TYPE_VIS __forward_list_const_iterator public: typedef forward_iterator_tag iterator_category; typedef typename __node::value_type value_type; - typedef const value_type& reference; + typedef const value_type& reference; typedef typename pointer_traits<__node_const_pointer>::difference_type difference_type; typedef typename pointer_traits<__node_const_pointer>::template @@ -323,7 +323,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__ptr_->__value_;} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __forward_list_const_iterator& operator++() @@ -368,18 +368,27 @@ protected: __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; - typedef typename __node_traits::const_pointer __node_const_pointer; + typedef typename __node_traits::pointer __node_const_pointer; + + typedef typename allocator_traits<allocator_type>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__begin_node> +#else + rebind_alloc<__begin_node>::other +#endif + __begin_node_allocator; + typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer; __compressed_pair<__begin_node, __node_allocator> __before_begin_; _LIBCPP_INLINE_VISIBILITY __node_pointer __before_begin() _NOEXCEPT - {return pointer_traits<__node_pointer>::pointer_to( - static_cast<__node&>(__before_begin_.first()));} + {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>:: + pointer_to(__before_begin_.first()));} _LIBCPP_INLINE_VISIBILITY __node_const_pointer __before_begin() const _NOEXCEPT - {return pointer_traits<__node_const_pointer>::pointer_to( - static_cast<const __node&>(__before_begin_.first()));} + {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>:: + pointer_to(const_cast<__begin_node&>(__before_begin_.first())));} _LIBCPP_INLINE_VISIBILITY __node_allocator& __alloc() _NOEXCEPT @@ -389,7 +398,7 @@ protected: {return __before_begin_.second();} typedef __forward_list_iterator<__node_pointer> iterator; - typedef __forward_list_const_iterator<__node_const_pointer> const_iterator; + typedef __forward_list_const_iterator<__node_pointer> const_iterator; _LIBCPP_INLINE_VISIBILITY __forward_list_base() @@ -1050,7 +1059,7 @@ template <class... _Args> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) { - __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer const __r = __p.__ptr_; __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); @@ -1067,7 +1076,7 @@ template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) { - __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer const __r = __p.__ptr_; __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); @@ -1083,7 +1092,7 @@ template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) { - __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer const __r = __p.__ptr_; __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); @@ -1098,7 +1107,7 @@ typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const value_type& __v) { - __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __r = __p.__ptr_; if (__n > 0) { __node_allocator& __a = base::__alloc(); @@ -1148,7 +1157,7 @@ typename enable_if forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l) { - __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __r = __p.__ptr_; if (__f != __l) { __node_allocator& __a = base::__alloc(); @@ -1192,7 +1201,7 @@ template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) { - __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); + __node_pointer __p = __f.__ptr_; __node_pointer __n = __p->__next_; __p->__next_ = __n->__next_; __node_allocator& __a = base::__alloc(); @@ -1205,10 +1214,10 @@ template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) { - __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_); + __node_pointer __e = __l.__ptr_; if (__f != __l) { - __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); + __node_pointer __p = __f.__ptr_; __node_pointer __n = __p->__next_; if (__n != __e) { @@ -1302,12 +1311,10 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, const_iterator __lm1 = __x.before_begin(); while (__lm1.__ptr_->__next_ != nullptr) ++__lm1; - const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = - const_cast<__node_pointer>(__p.__ptr_)->__next_; + __lm1.__ptr_->__next_ = __p.__ptr_->__next_; } - const_cast<__node_pointer>(__p.__ptr_)->__next_ = - const_cast<__node_pointer>(__x.__before_begin())->__next_; - const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr; + __p.__ptr_->__next_ = __x.__before_begin()->__next_; + __x.__before_begin()->__next_ = nullptr; } } @@ -1320,12 +1327,9 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, const_iterator __lm1 = _VSTD::next(__i); if (__p != __i && __p != __lm1) { - const_cast<__node_pointer>(__i.__ptr_)->__next_ = - const_cast<__node_pointer>(__lm1.__ptr_)->__next_; - const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = - const_cast<__node_pointer>(__p.__ptr_)->__next_; - const_cast<__node_pointer>(__p.__ptr_)->__next_ = - const_cast<__node_pointer>(__lm1.__ptr_); + __i.__ptr_->__next_ = __lm1.__ptr_->__next_; + __lm1.__ptr_->__next_ = __p.__ptr_->__next_; + __p.__ptr_->__next_ = __lm1.__ptr_; } } @@ -1342,12 +1346,9 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, ++__lm1; if (__f != __lm1) { - const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = - const_cast<__node_pointer>(__p.__ptr_)->__next_; - const_cast<__node_pointer>(__p.__ptr_)->__next_ = - const_cast<__node_pointer>(__f.__ptr_)->__next_; - const_cast<__node_pointer>(__f.__ptr_)->__next_ = - const_cast<__node_pointer>(__l.__ptr_); + __lm1.__ptr_->__next_ = __p.__ptr_->__next_; + __p.__ptr_->__next_ = __f.__ptr_->__next_; + __f.__ptr_->__next_ = __l.__ptr_; } } } diff --git a/system/include/libcxx/fstream b/system/include/libcxx/fstream index 0a5cf92a..e3f8306f 100644 --- a/system/include/libcxx/fstream +++ b/system/include/libcxx/fstream @@ -807,9 +807,15 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, default: return pos_type(off_type(-1)); } +#if _WIN32 + if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) + return pos_type(off_type(-1)); + pos_type __r = ftell(__file_); +#else if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) return pos_type(off_type(-1)); pos_type __r = ftello(__file_); +#endif __r.state(__st_); return __r; } @@ -820,8 +826,13 @@ basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) { if (__file_ == 0 || sync()) return pos_type(off_type(-1)); +#if _WIN32 + if (fseek(__file_, __sp, SEEK_SET)) + return pos_type(off_type(-1)); +#else if (fseeko(__file_, __sp, SEEK_SET)) return pos_type(off_type(-1)); +#endif __st_ = __sp.state(); return __sp; } @@ -880,8 +891,13 @@ basic_filebuf<_CharT, _Traits>::sync() } } } +#if _WIN32 + if (fseek(__file_, -__c, SEEK_CUR)) + return -1; +#else if (fseeko(__file_, -__c, SEEK_CUR)) return -1; +#endif if (__update_st) __st_ = __state; __extbufnext_ = __extbufend_ = __extbuf_; diff --git a/system/include/libcxx/functional b/system/include/libcxx/functional index 995db564..2130f0e3 100644 --- a/system/include/libcxx/functional +++ b/system/include/libcxx/functional @@ -68,96 +68,120 @@ template <class T> reference_wrapper<const T> cref(const T& t) noexcept; template <class T> void cref(const T&& t) = delete; template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; -template <class T> +template <class T> // <class T=void> in C++14 struct plus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct minus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct multiplies : binary_function<T, T, T> { T operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct divides : binary_function<T, T, T> { T operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct modulus : binary_function<T, T, T> { T operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct negate : unary_function<T, T> { T operator()(const T& x) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct equal_to : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct not_equal_to : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct greater : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct less : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct greater_equal : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct less_equal : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct logical_and : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct logical_or : binary_function<T, T, bool> { bool operator()(const T& x, const T& y) const; }; -template <class T> +template <class T> // <class T=void> in C++14 struct logical_not : unary_function<T, bool> { bool operator()(const T& x) const; }; +template <class T> // <class T=void> in C++14 +struct bit_and : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct bit_or : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T> // <class T=void> in C++14 +struct bit_xor : unary_function<T, bool> +{ + bool operator()(const T& x, const T& y) const; +}; + +template <class T=void> // C++14 +struct bit_xor : unary_function<T, bool> +{ + bool operator()(const T& x) const; +}; + template <class Predicate> class unary_negate : public unary_function<typename Predicate::argument_type, bool> @@ -473,127 +497,399 @@ POLICY: For non-variadic implementations, the number of arguments is limited _LIBCPP_BEGIN_NAMESPACE_STD +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS plus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x + __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS plus<void> +{ + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS minus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x - __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS minus<void> +{ + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x * __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS multiplies<void> +{ + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS divides : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x / __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS divides<void> +{ + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS modulus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x % __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS modulus<void> +{ + template <class _T1, class _T2> + _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS negate : unary_function<_Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const {return -__x;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS negate<void> +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const + { return -_VSTD::forward<_Tp>(__x); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS equal_to : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x == __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS equal_to<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x != __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS not_equal_to<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS greater : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x > __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS greater<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } +}; +#endif + + // less in <__functional_base> +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS greater_equal : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x >= __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS greater_equal<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS less_equal : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x <= __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS less_equal<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS logical_and : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x && __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS logical_and<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS logical_or : binary_function<_Tp, _Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x || __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS logical_or<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS logical_not : unary_function<_Tp, bool> { _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const {return !__x;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS logical_not<void> +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const + { return !_VSTD::forward<_Tp>(__x); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x & __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS bit_and<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x | __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS bit_or<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +#else template <class _Tp> +#endif struct _LIBCPP_TYPE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const {return __x ^ __y;} }; +#if _LIBCPP_STD_VER > 11 +template <> +struct _LIBCPP_TYPE_VIS bit_xor<void> +{ + template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } +}; +#endif + + +#if _LIBCPP_STD_VER > 11 +template <class _Tp = void> +struct _LIBCPP_TYPE_VIS bit_not : unary_function<_Tp, _Tp> +{ + _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const + {return ~__x;} +}; + +template <> +struct _LIBCPP_TYPE_VIS bit_not<void> +{ + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const + { return ~_VSTD::forward<_Tp>(__x); } +}; +#endif + template <class _Predicate> class _LIBCPP_TYPE_VIS unary_negate : public unary_function<typename _Predicate::argument_type, bool> @@ -1139,8 +1435,11 @@ public: function(const function&); function(function&&) _NOEXCEPT; template<class _Fp> - function(_Fp, - typename enable_if<__callable<_Fp>::value>::type* = 0); + function(_Fp, typename enable_if + < + __callable<_Fp>::value && + !is_same<_Fp, function>::value + >::type* = 0); template<class _Alloc> _LIBCPP_INLINE_VISIBILITY @@ -1162,7 +1461,8 @@ public: template<class _Fp> typename enable_if < - __callable<typename decay<_Fp>::type>::value, + __callable<typename decay<_Fp>::type>::value && + !is_same<typename remove_reference<_Fp>::type, function>::value, function& >::type operator=(_Fp&&); @@ -1266,7 +1566,11 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, template<class _Rp, class ..._ArgTypes> template <class _Fp> function<_Rp(_ArgTypes...)>::function(_Fp __f, - typename enable_if<__callable<_Fp>::value>::type*) + typename enable_if + < + __callable<_Fp>::value && + !is_same<_Fp, function>::value + >::type*) : __f_(0) { if (__not_null(__f)) @@ -1370,7 +1674,8 @@ template<class _Rp, class ..._ArgTypes> template <class _Fp> typename enable_if < - function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value, + function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && + !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, function<_Rp(_ArgTypes...)>& >::type function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) @@ -1594,12 +1899,24 @@ template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, class _TupleUj> struct ____mu_return; +template <bool _Invokable, class _Ti, class ..._Uj> +struct ____mu_return_invokable // false +{ + typedef __nat type; +}; + template <class _Ti, class ..._Uj> -struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > +struct ____mu_return_invokable<true, _Ti, _Uj...> { typedef typename __invoke_of<_Ti&, _Uj...>::type type; }; +template <class _Ti, class ..._Uj> +struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > + : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> +{ +}; + template <class _Ti, class _TupleUj> struct ____mu_return<_Ti, false, false, true, _TupleUj> { @@ -1737,7 +2054,9 @@ public: template <class _Gp, class ..._BA, class = typename enable_if < - is_constructible<_Fd, _Gp>::value + is_constructible<_Fd, _Gp>::value && + !is_same<typename remove_reference<_Gp>::type, + __bind>::value >::type> _LIBCPP_INLINE_VISIBILITY explicit __bind(_Gp&& __f, _BA&& ...__bound_args) @@ -1802,7 +2121,13 @@ public: #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - template <class _Gp, class ..._BA> + template <class _Gp, class ..._BA, + class = typename enable_if + < + is_constructible<_Fd, _Gp>::value && + !is_same<typename remove_reference<_Gp>::type, + __bind_r>::value + >::type> _LIBCPP_INLINE_VISIBILITY explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) : base(_VSTD::forward<_Gp>(__f), diff --git a/system/include/libcxx/future b/system/include/libcxx/future index 3d7bb6c9..dae1a4b8 100644 --- a/system/include/libcxx/future +++ b/system/include/libcxx/future @@ -403,6 +403,72 @@ _LIBCPP_DECLARE_STRONG_ENUM(launch) }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) +#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS + +#ifdef _LIBCXX_UNDERLYING_TYPE +typedef underlying_type<launch>::type __launch_underlying_type; +#else +typedef int __launch_underlying_type; +#endif + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator&(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) & + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator|(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) | + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator^(launch __x, launch __y) +{ + return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^ + static_cast<__launch_underlying_type>(__y)); +} + +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR +launch +operator~(launch __x) +{ + return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3); +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator&=(launch& __x, launch __y) +{ + __x = __x & __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator|=(launch& __x, launch __y) +{ + __x = __x | __y; return __x; +} + +inline _LIBCPP_INLINE_VISIBILITY +launch& +operator^=(launch& __x, launch __y) +{ + __x = __x ^ __y; return __x; +} + +#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS + //enum class future_status _LIBCPP_DECLARE_STRONG_ENUM(future_status) { diff --git a/system/include/libcxx/ios b/system/include/libcxx/ios index 25bbfc0b..c10003d0 100644 --- a/system/include/libcxx/ios +++ b/system/include/libcxx/ios @@ -983,6 +983,33 @@ defaultfloat(ios_base& __str) return __str; } +template <class _CharT, class _Traits> +class __save_flags +{ + typedef basic_ios<_CharT, _Traits> __stream_type; + typedef typename __stream_type::fmtflags fmtflags; + + __stream_type& __stream_; + fmtflags __fmtflags_; + _CharT __fill_; + + __save_flags(const __save_flags&); + __save_flags& operator=(const __save_flags&); +public: + _LIBCPP_INLINE_VISIBILITY + explicit __save_flags(__stream_type& __stream) + : __stream_(__stream), + __fmtflags_(__stream.flags()), + __fill_(__stream.fill()) + {} + _LIBCPP_INLINE_VISIBILITY + ~__save_flags() + { + __stream_.flags(__fmtflags_); + __stream_.fill(__fill_); + } +}; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_IOS diff --git a/system/include/libcxx/istream b/system/include/libcxx/istream index 3f629f68..f3e74c38 100644 --- a/system/include/libcxx/istream +++ b/system/include/libcxx/istream @@ -1144,8 +1144,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) break; } ++__gc_; - char_type __ch = traits_type::to_char_type(__i); - if (traits_type::eq(__ch, static_cast<char_type>(__dlm))) + if (traits_type::eq_int_type(__i, __dlm)) break; } } @@ -1160,8 +1159,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) break; } ++__gc_; - char_type __ch = traits_type::to_char_type(__i); - if (traits_type::eq(__ch, static_cast<char_type>(__dlm))) + if (traits_type::eq_int_type(__i, __dlm)) break; } } diff --git a/system/include/libcxx/iterator b/system/include/libcxx/iterator index 3b078a2a..858510d1 100644 --- a/system/include/libcxx/iterator +++ b/system/include/libcxx/iterator @@ -321,8 +321,10 @@ template <class T, size_t N> T* end(T (&array)[N]); #include <Availability.h> #endif -#ifdef _LIBCPP_DEBUG -#include <cassert> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -1091,6 +1093,9 @@ private: iterator_type __i; public: _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __i{} +#endif { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); @@ -1135,7 +1140,14 @@ public: #endif return *__i; } - _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable iterator"); +#endif + return (pointer)&reinterpret_cast<const volatile char&>(*__i); + } _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1257,10 +1269,6 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), - "Attempted to compare incomparable iterators"); -#endif return __x.base() == __y.base(); } @@ -1270,7 +1278,7 @@ bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), "Attempted to compare incomparable iterators"); #endif return __x.base() < __y.base(); @@ -1346,7 +1354,7 @@ typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), "Attempted to subtract incompatible iterators"); #endif return __x.base() - __y.base(); diff --git a/system/include/libcxx/limits b/system/include/libcxx/limits index 9b9d7a6f..c995ef59 100644 --- a/system/include/libcxx/limits +++ b/system/include/libcxx/limits @@ -111,9 +111,9 @@ template<> class numeric_limits<cv long double>; #include <__undef_min_max> -#if defined(_MSC_VER) +#if defined(_LIBCPP_MSVCRT) #include "support/win32/limits_win32.h" -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/system/include/libcxx/list b/system/include/libcxx/list index 06904d96..4b1272a8 100644 --- a/system/include/libcxx/list +++ b/system/include/libcxx/list @@ -178,6 +178,12 @@ template <class T, class Alloc> #include <__undef_min_max> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -196,13 +202,20 @@ struct __list_node_base rebind<__list_node<_Tp, _VoidPtr> >::other pointer; #endif + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__list_node_base> __base_pointer; +#else + rebind<__list_node_base>::other __base_pointer; +#endif + pointer __prev_; pointer __next_; _LIBCPP_INLINE_VISIBILITY __list_node_base() - : __prev_(static_cast<pointer>(this)), - __next_(static_cast<pointer>(this)) + : __prev_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))), + __next_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))) {} }; @@ -260,7 +273,7 @@ public: typedef typename pointer_traits<pointer>::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY - __list_iterator() _NOEXCEPT + __list_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); @@ -305,7 +318,14 @@ public: return __ptr_->__value_; } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &(operator*());} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__value_); + } _LIBCPP_INLINE_VISIBILITY __list_iterator& operator++() @@ -336,10 +356,6 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_iterator& __x, const __list_iterator& __y) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), - "Attempted to compare non-comparable list::iterator"); -#endif return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY @@ -352,9 +368,9 @@ class _LIBCPP_TYPE_VIS __list_const_iterator { typedef typename pointer_traits<_VoidPtr>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<const __list_node<_Tp, _VoidPtr> > __node_pointer; + rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; #else - rebind<const __list_node<_Tp, _VoidPtr> >::other __node_pointer; + rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; #endif __node_pointer __ptr_; @@ -387,14 +403,14 @@ public: typedef typename pointer_traits<pointer>::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY - __list_const_iterator() _NOEXCEPT + __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); #endif } _LIBCPP_INLINE_VISIBILITY - __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) _NOEXCEPT + __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT : __ptr_(__p.__ptr_) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -439,7 +455,14 @@ public: return __ptr_->__value_; } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &(operator*());} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__value_); + } _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator++() @@ -470,10 +493,6 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), - "Attempted to compare non-comparable list::const_iterator"); -#endif return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY @@ -505,11 +524,20 @@ protected: __node_allocator; typedef allocator_traits<__node_allocator> __node_alloc_traits; typedef typename __node_alloc_traits::pointer __node_pointer; - typedef typename __node_alloc_traits::const_pointer __node_const_pointer; + typedef typename __node_alloc_traits::pointer __node_const_pointer; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node_base> +#else + rebind_alloc<__node_base>::other +#endif + __node_base_allocator; + typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; + __node_base __end_; __compressed_pair<size_type, __node_allocator> __size_alloc_; @@ -525,7 +553,7 @@ protected: const __node_allocator& __node_alloc() const _NOEXCEPT {return __size_alloc_.second();} - static void __unlink_nodes(__node_base& __f, __node_base& __l) _NOEXCEPT; + static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT; __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); @@ -557,18 +585,22 @@ protected: iterator end() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(static_cast<__node_pointer>(&__end_), this); + return iterator(static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)), this); #else - return iterator(static_cast<__node_pointer>(&__end_)); + return iterator(static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_))); #endif } _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - return const_iterator(static_cast<__node_const_pointer>(&__end_), this); + return const_iterator(static_cast<__node_const_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this); #else - return const_iterator(static_cast<__node_const_pointer>(&__end_)); + return const_iterator(static_cast<__node_const_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_)))); #endif } @@ -637,11 +669,11 @@ private: template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY void -__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l) +__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT { - __f.__prev_->__next_ = __l.__next_; - __l.__next_->__prev_ = __f.__prev_; + __f->__prev_->__next_ = __l->__next_; + __l->__next_->__prev_ = __f->__prev_; } template <class _Tp, class _Alloc> @@ -676,15 +708,16 @@ __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT { __node_allocator& __na = __node_alloc(); __node_pointer __f = __end_.__next_; - __node_pointer __l = static_cast<__node_pointer>(&__end_); - __unlink_nodes(*__f, *__l->__prev_); + __node_pointer __l = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); + __unlink_nodes(__f, __l->__prev_); __sz() = 0; while (__f != __l) { - __node& __n = *__f; + __node_pointer __n = __f; __f = __f->__next_; - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); @@ -719,16 +752,20 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) swap(__sz(), __c.__sz()); swap(__end_, __c.__end_); if (__sz() == 0) - __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_); + __end_.__next_ = __end_.__prev_ = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); else __end_.__prev_->__next_ = __end_.__next_->__prev_ - = &static_cast<__node&>(__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); if (__c.__sz() == 0) __c.__end_.__next_ = __c.__end_.__prev_ - = &static_cast<__node&>(__c.__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); else __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ - = &static_cast<__node&>(__c.__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); @@ -740,7 +777,8 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) { --__p; const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->__ptr_ == static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ == static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn2->__add(*__p); if (--__cn1->end_ != __p) @@ -753,7 +791,8 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) { --__p; const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->__ptr_ == static_cast<__node_pointer>(&__end_)) + if (__i->__ptr_ == static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_))) { __cn1->__add(*__p); if (--__cn2->end_ != __p) @@ -775,6 +814,8 @@ class _LIBCPP_TYPE_VIS list typedef typename base::__node_allocator __node_allocator; typedef typename base::__node_pointer __node_pointer; typedef typename base::__node_alloc_traits __node_alloc_traits; + typedef typename base::__node_base __node_base; + typedef typename base::__node_base_pointer __node_base_pointer; public: typedef _Tp value_type; @@ -1014,7 +1055,7 @@ public: #endif // _LIBCPP_DEBUG_LEVEL >= 2 private: - static void __link_nodes(__node& __p, __node& __f, __node& __l); + static void __link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l); iterator __iterator(size_type __n); template <class _Comp> static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); @@ -1028,12 +1069,12 @@ private: template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY void -list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l) +list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l) { - __p.__prev_->__next_ = &__f; - __f.__prev_ = __p.__prev_; - __p.__prev_ = &__l; - __l.__next_ = &__p; + __p->__prev_->__next_ = __f; + __f->__prev_ = __p->__prev_; + __p->__prev_ = __l; + __l->__next_ = __p; } template <class _Tp, class _Alloc> @@ -1290,9 +1331,13 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__hold.release(), this); +#else return iterator(__hold.release()); +#endif } template <class _Tp, class _Alloc> @@ -1303,9 +1348,9 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, n, x) called with an iterator not" " referring to this list"); - iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); + iterator __r(__p.__ptr_, this); #else - iterator __r(const_cast<__node_pointer>(__p.__ptr_)); + iterator __r(__p.__ptr_); #endif if (__n > 0) { @@ -1355,7 +1400,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; @@ -1371,9 +1416,9 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, range) called with an iterator not" " referring to this list"); - iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); + iterator __r(__p.__ptr_, this); #else - iterator __r(const_cast<__node_pointer>(__p.__ptr_)); + iterator __r(__p.__ptr_); #endif if (__f != __l) { @@ -1423,7 +1468,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; @@ -1437,7 +1482,7 @@ list<_Tp, _Alloc>::push_front(const value_type& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1450,7 +1495,8 @@ list<_Tp, _Alloc>::push_back(const value_type& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1465,7 +1511,7 @@ list<_Tp, _Alloc>::push_front(value_type&& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1478,7 +1524,8 @@ list<_Tp, _Alloc>::push_back(value_type&& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1494,7 +1541,7 @@ list<_Tp, _Alloc>::emplace_front(_Args&&... __args) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1508,7 +1555,8 @@ list<_Tp, _Alloc>::emplace_back(_Args&&... __args) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1518,12 +1566,17 @@ template <class... _Args> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::emplace(iterator, args...) called with an iterator not" + " referring to this list"); +#endif __node_allocator& __na = base::__node_alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__hold.release(), this); @@ -1548,7 +1601,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__hold.release(), this); @@ -1565,7 +1618,7 @@ list<_Tp, _Alloc>::pop_front() { _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); __node_allocator& __na = base::__node_alloc(); - __node& __n = *base::__end_.__next_; + __node_pointer __n = base::__end_.__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1574,7 +1627,7 @@ list<_Tp, _Alloc>::pop_front() { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1583,17 +1636,17 @@ list<_Tp, _Alloc>::pop_front() } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } template <class _Tp, class _Alloc> void list<_Tp, _Alloc>::pop_back() { - _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); + _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); __node_allocator& __na = base::__node_alloc(); - __node& __n = *base::__end_.__prev_; + __node_pointer __n = base::__end_.__prev_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1602,7 +1655,7 @@ list<_Tp, _Alloc>::pop_back() { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1611,8 +1664,8 @@ list<_Tp, _Alloc>::pop_back() } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } template <class _Tp, class _Alloc> @@ -1624,9 +1677,11 @@ list<_Tp, _Alloc>::erase(const_iterator __p) "list::erase(iterator) called with an iterator not" " referring to this list"); #endif + _LIBCPP_ASSERT(__p != end(), + "list::erase(iterator) called with a non-dereferenceable iterator"); __node_allocator& __na = base::__node_alloc(); - __node& __n = const_cast<__node&>(*__p.__ptr_); - __node_pointer __r = __n.__next_; + __node_pointer __n = __p.__ptr_; + __node_pointer __r = __n->__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1635,7 +1690,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1644,8 +1699,8 @@ list<_Tp, _Alloc>::erase(const_iterator __p) } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__r, this); #else @@ -1665,10 +1720,10 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) if (__f != __l) { __node_allocator& __na = base::__node_alloc(); - base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_); + base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); while (__f != __l) { - __node& __n = const_cast<__node&>(*__f.__ptr_); + __node_pointer __n = __f.__ptr_; ++__f; --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1677,7 +1732,7 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1686,14 +1741,14 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } } #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(const_cast<__node_pointer>(__l.__ptr_), this); + return iterator(__l.__ptr_, this); #else - return iterator(const_cast<__node_pointer>(__l.__ptr_)); + return iterator(__l.__ptr_); #endif } @@ -1751,7 +1806,8 @@ list<_Tp, _Alloc>::resize(size_type __n) throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } @@ -1810,7 +1866,8 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } @@ -1828,10 +1885,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) #endif if (!__c.empty()) { - __node& __f = *__c.__end_.__next_; - __node& __l = *__c.__end_.__prev_; + __node_pointer __f = __c.__end_.__next_; + __node_pointer __l = __c.__end_.__prev_; base::__unlink_nodes(__f, __l); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l); + __link_nodes(__p.__ptr_, __f, __l); base::__sz() += __c.__sz(); __c.__sz() = 0; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1842,7 +1899,8 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -1872,9 +1930,9 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) #endif if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) { - __node& __f = const_cast<__node&>(*__i.__ptr_); + __node_pointer __f = __i.__ptr_; base::__unlink_nodes(__f, __f); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f); + __link_nodes(__p.__ptr_, __f, __f); --__c.__sz(); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1885,7 +1943,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) { --__p; iterator* __j = static_cast<iterator*>((*__p)->__i_); - if (__j->__ptr_ == &__f) + if (__j->__ptr_ == __f) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -1926,11 +1984,11 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con __c.__sz() -= __s; base::__sz() += __s; } - __node& __first = const_cast<__node&>(*__f.__ptr_); + __node_pointer __first = __f.__ptr_; --__l; - __node& __last = const_cast<__node&>(*__l.__ptr_); + __node_pointer __last = __l.__ptr_; base::__unlink_nodes(__first, __last); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last); + __link_nodes(__p.__ptr_, __first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); @@ -1939,7 +1997,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con { --__p; iterator* __j = static_cast<iterator*>((*__p)->__i_); - for (__node_pointer __k = const_cast<__node_pointer>(__f.__ptr_); + for (__node_pointer __k = __f.__ptr_; __k != __l.__ptr_; __k = __k->__next_) { if (__j->__ptr_ == __k) @@ -2045,12 +2103,12 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) ; base::__sz() += __ds; __c.__sz() -= __ds; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2065,7 +2123,8 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -2108,9 +2167,9 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ case 2: if (__comp(*--__e2, *__f1)) { - __node& __f = *__e2.__ptr_; + __node_pointer __f = __e2.__ptr_; base::__unlink_nodes(__f, __f); - __link_nodes(*__f1.__ptr_, __f, __f); + __link_nodes(__f1.__ptr_, __f, __f); return __e2; } return __f1; @@ -2124,13 +2183,13 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; __r = __f2; __e1 = __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2142,14 +2201,14 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; if (__e1 == __f2) __e1 = __m2; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2187,7 +2246,8 @@ template <class _Tp, class _Alloc> bool list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const { - return __i->__ptr_ != &this->__end_; + return __i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_))); } template <class _Tp, class _Alloc> diff --git a/system/include/libcxx/locale b/system/include/libcxx/locale index 05020e17..00a275f9 100644 --- a/system/include/libcxx/locale +++ b/system/include/libcxx/locale @@ -186,11 +186,11 @@ template <class charT> class messages_byname; #endif #include <cstdlib> #include <ctime> -#ifdef _WIN32 +#ifdef _LIBCPP_MSVCRT #include <support/win32/locale_win32.h> -#else // _WIN32 +#else // _LIBCPP_MSVCRT #include <nl_types.h> -#endif // !_WIN32 +#endif // !_LIBCPP_MSVCRT #ifdef __APPLE__ #include <Availability.h> @@ -206,6 +206,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_GET_C_LOCALE 0 +#elif defined(__NetBSD__) +# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE #else # define _LIBCPP_GET_C_LOCALE __cloc() // Get the C locale object @@ -355,20 +357,6 @@ size_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, } inline -int __sprintf_l(char *__s, locale_t __l, const char *__format, ...) { - va_list __va; - va_start(__va, __format); -#ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __res = vsprintf_l(__s, __l, __format, __va); -#else - __locale_raii __current(uselocale(__l), uselocale); - int __res = vsprintf(__s, __format, __va); -#endif - va_end(__va); - return __res; -} - -inline int __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { va_list __va; va_start(__va, __format); @@ -634,8 +622,7 @@ __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& } return -1; } - if (__a_end-__a < __num_get_buf_sz - 1) - *__a_end++ = __src[__f]; + *__a_end++ = __src[__f]; ++__dc; return 0; } @@ -646,8 +633,6 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) { - if (__a_end-__a >= __num_get_buf_sz - 1) - return -1; if (__ct == __decimal_point) { if (!__in_units) @@ -694,8 +679,7 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex *__g_end++ = __dc; } } - if (__a_end-__a < __num_get_buf_sz - ((__exp & 0x80) ? 1 : 11)) - *__a_end++ = __x; + *__a_end++ = __x; if (__f >= 22) return 0; ++__dc; @@ -906,13 +890,20 @@ __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) { if (__a != __a_end) { + typename remove_reference<decltype(errno)>::type __save_errno = errno; + errno = 0; char *__p2; long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE); + typename remove_reference<decltype(errno)>::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; if (__p2 != __a_end) { __err = ios_base::failbit; return 0; } + else if (__current_errno == ERANGE) + __err = ios_base::failbit; return static_cast<_Tp>(__ld); } __err = ios_base::failbit; @@ -968,16 +959,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1003,16 +1006,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1038,16 +1053,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1073,16 +1100,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1108,16 +1147,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1143,16 +1194,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, char_type __atoms[26]; char_type __thousands_sep; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1180,7 +1243,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1188,11 +1253,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1220,7 +1295,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1228,11 +1305,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1260,7 +1347,9 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; @@ -1268,11 +1357,21 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; + } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 @@ -1300,16 +1399,28 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, string __grouping; use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src, __num_get_base::__src + 26, __atoms); - char __a[__num_get_base::__num_get_buf_sz] = {0}; + string __buf; + __buf.resize(__buf.capacity()); + char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) + { + if (__a_end - __a == __buf.size()) + { + size_t __tmp = __buf.size(); + __buf.resize(2*__buf.size()); + __buf.resize(__buf.capacity()); + __a = &__buf[0]; + __a_end = __a + __tmp; + } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; + } // Stage 3 __a[sizeof(__a)-1] = 0; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS @@ -1678,9 +1789,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + 1; char __nar[__nbuf]; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); + int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); #else - int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); + int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v); #endif char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); @@ -1708,9 +1819,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + 1; char __nar[__nbuf]; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); + int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); #else - int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); + int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v); #endif char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); @@ -1738,9 +1849,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + 1; char __nar[__nbuf]; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); + int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); #else - int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); + int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v); #endif char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); @@ -1768,9 +1879,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, + 1; char __nar[__nbuf]; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); + int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); #else - int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); + int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v); #endif char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); @@ -1932,9 +2043,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, const unsigned __nbuf = 20; char __nar[__nbuf]; #ifdef _LIBCPP_LOCALE__L_EXTENSIONS - int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); + int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); #else - int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); + int __nc = __snprintf_l(__nar, sizeof(__nar), __cloc(), __fmt, __v); #endif char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); diff --git a/system/include/libcxx/map b/system/include/libcxx/map index abc07a35..953743a6 100644 --- a/system/include/libcxx/map +++ b/system/include/libcxx/map @@ -381,7 +381,7 @@ swap(multimap<Key, T, Compare, Allocator>& x, _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::value +template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value #if __has_feature(is_final) && !__is_final(_Compare) #endif @@ -389,8 +389,6 @@ template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::valu class __map_value_compare : private _Compare { - typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _CP; public: _LIBCPP_INLINE_VISIBILITY __map_value_compare() @@ -404,41 +402,20 @@ public: const _Compare& key_comp() const _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _CP& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _CP& __x, const _Pp& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y.first);} + {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _Key& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _CP& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Pp& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Key& __y) const - {return static_cast<const _Compare&>(*this)(__x.first, __y);} + {return static_cast<const _Compare&>(*this)(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const - {return static_cast<const _Compare&>(*this)(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Pp& __y) const - {return static_cast<const _Compare&>(*this)(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Key& __y) const - {return static_cast<const _Compare&>(*this)(__x, __y);} + {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);} }; -template <class _Key, class _Tp, class _Compare> -class __map_value_compare<_Key, _Tp, _Compare, false> +template <class _Key, class _CP, class _Compare> +class __map_value_compare<_Key, _CP, _Compare, false> { _Compare comp; - typedef pair<typename std::remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _CP; - public: _LIBCPP_INLINE_VISIBILITY __map_value_compare() @@ -453,31 +430,13 @@ public: _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _CP& __y) const - {return comp(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _CP& __x, const _Pp& __y) const - {return comp(__x.first, __y.first);} + {return comp(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _Key& __y) const - {return comp(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _CP& __y) const - {return comp(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Pp& __y) const - {return comp(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Key& __y) const - {return comp(__x.first, __y);} + {return comp(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const - {return comp(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Pp& __y) const - {return comp(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Key& __y) const - {return comp(__x, __y);} + {return comp(__x, __y.__cc.first);} }; template <class _Allocator> @@ -489,8 +448,8 @@ class __map_node_destructor public: typedef typename __alloc_traits::pointer pointer; private: - typedef typename value_type::first_type first_type; - typedef typename value_type::second_type second_type; + typedef typename value_type::value_type::first_type first_type; + typedef typename value_type::value_type::second_type second_type; allocator_type& __na_; @@ -522,9 +481,9 @@ public: void operator()(pointer __p) _NOEXCEPT { if (__second_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); if (__first_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } @@ -542,8 +501,8 @@ class _LIBCPP_TYPE_VIS __map_iterator _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::second_type __mapped_type; + typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -564,9 +523,9 @@ public: __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_iterator& operator++() {++__i_; return *this;} @@ -607,8 +566,8 @@ class _LIBCPP_TYPE_VIS __map_const_iterator _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::second_type __mapped_type; + typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -634,9 +593,9 @@ public: : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_const_iterator& operator++() {++__i_; return *this;} @@ -679,6 +638,7 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; @@ -699,8 +659,51 @@ public: }; private: - typedef pair<key_type, mapped_type> __value_type; - typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; + +#if __cplusplus >= 201103L + union __value_type + { + typedef typename map::value_type value_type; + typedef typename map::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + }; +#else + struct __value_type + { + typedef typename map::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + }; +#endif + typedef __map_value_compare<key_type, __value_type, key_compare> __vc; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__value_type> @@ -764,7 +767,14 @@ public: _LIBCPP_INLINE_VISIBILITY map& operator=(const map& __m) { +#if __cplusplus >= 201103L __tree_ = __m.__tree_; +#else + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); +#endif return *this; } @@ -986,32 +996,17 @@ private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); template <class _A0> - typename enable_if - < - is_constructible<value_type, _A0>::value, - __node_holder - >::type - __construct_node(_A0&& __a0); - template <class _A0> - typename enable_if - < - is_constructible<key_type, _A0>::value, - __node_holder - >::type - __construct_node(_A0&& __a0); + __node_holder __construct_node(_A0&& __a0); + __node_holder __construct_node_with_key(key_type&& __k); #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _A0, class _A1, class ..._Args> __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - __node_holder __construct_node(const key_type& __k); #endif + __node_holder __construct_node_with_key(const key_type& __k); __node_base_pointer& __find_equal_key(__node_base_pointer& __parent, const key_type& __k); - __node_base_pointer& - __find_equal_key(const_iterator __hint, - __node_base_pointer& __parent, const key_type& __k); __node_base_const_pointer __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const; }; @@ -1030,97 +1025,37 @@ map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __pa { while (true) { - if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } - else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __tree_.__end_node(); + __parent = static_cast<__node_base_pointer>(__tree_.__end_node()); return __parent->__left_; } -// Find place to insert if __k doesn't exist -// First check prior to __hint. -// Next check after __hint. -// Next do O(log N) search. -// Set __parent to parent of null leaf -// Return reference to null leaf -// If __k exists, set parent to node of __k and return reference to node of __k -template <class _Key, class _Tp, class _Compare, class _Allocator> -typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& -map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint, - __node_base_pointer& __parent, - const key_type& __k) -{ - if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first)) // check before - { - // __k < *__hint - const_iterator __prior = __hint; - if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k)) - { - // *prev(__hint) < __k < *__hint - if (__hint.__ptr_->__left_ == nullptr) - { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent->__left_; - } - else - { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); - return __parent->__right_; - } - } - // __k <= *prev(__hint) - return __find_equal_key(__parent, __k); - } - else if (__tree_.value_comp().key_comp()(__hint->first, __k)) // check after - { - // *__hint < __k - const_iterator __next = _VSTD::next(__hint); - if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first)) - { - // *__hint < __k < *next(__hint) - if (__hint.__ptr_->__right_ == nullptr) - { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent->__right_; - } - else - { - __parent = const_cast<__node_pointer&>(__next.__ptr_); - return __parent->__left_; - } - } - // *next(__hint) <= __k - return __find_equal_key(__parent, __k); - } - // else __k == *__hint - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent; -} - // Find __k // Set __parent to parent of null leaf and // return reference to null leaf iv __k does not exist. @@ -1135,34 +1070,34 @@ map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer { while (true) { - if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return const_cast<const __node_base_const_pointer&>(__parent->__left_); } } - else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return const_cast<const __node_base_const_pointer&>(__parent->__right_); } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __tree_.__end_node(); + __parent = static_cast<__node_base_pointer>(__tree_.__end_node()); return const_cast<const __node_base_const_pointer&>(__parent->__left_); } @@ -1187,20 +1122,16 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node() { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } template <class _Key, class _Tp, class _Compare, class _Allocator> template <class _A0> -typename enable_if -< - is_constructible<pair<const _Key, _Tp>, _A0>::value, - typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder ->::type +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); @@ -1212,21 +1143,16 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) } template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0> -typename enable_if -< - is_constructible<_Key, _A0>::value, - typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder ->::type -map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) +typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; - return __h; + return _VSTD::move(__h); } #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -1248,23 +1174,21 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _ #endif // _LIBCPP_HAS_NO_VARIADICS -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Key, class _Tp, class _Compare, class _Allocator> typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder -map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k) +map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return _VSTD::move(__h); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Key, class _Tp, class _Compare, class _Allocator> _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) @@ -1274,11 +1198,11 @@ map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __node_holder __h = __construct_node(__k); - __tree_.__insert_node_at(__parent, __child, __h.get()); + __node_holder __h = __construct_node_with_key(__k); + __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } - return __r->__value_.second; + return __r->__value_.__cc.second; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1292,11 +1216,11 @@ map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __node_holder __h = __construct_node(_VSTD::move(__k)); - __tree_.__insert_node_at(__parent, __child, __h.get()); + __node_holder __h = __construct_node_with_key(_VSTD::move(__k)); + __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } - return __r->__value_.second; + return __r->__value_.__cc.second; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1311,7 +1235,7 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS - return static_cast<__node_pointer>(__child)->__value_.second; + return static_cast<__node_pointer>(__child)->__value_.__cc.second; } template <class _Key, class _Tp, class _Compare, class _Allocator> @@ -1324,7 +1248,7 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS - return static_cast<__node_const_pointer>(__child)->__value_.second; + return static_cast<__node_const_pointer>(__child)->__value_.__cc.second; } #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -1429,6 +1353,7 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; @@ -1450,8 +1375,50 @@ public: }; private: - typedef pair<key_type, mapped_type> __value_type; - typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; +#if __cplusplus >= 201103L + union __value_type + { + typedef typename multimap::value_type value_type; + typedef typename multimap::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + }; +#else + struct __value_type + { + typedef typename multimap::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + }; +#endif + typedef __map_value_compare<key_type, __value_type, key_compare> __vc; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__value_type> @@ -1516,7 +1483,14 @@ public: _LIBCPP_INLINE_VISIBILITY multimap& operator=(const multimap& __m) { +#if __cplusplus >= 201103L __tree_ = __m.__tree_; +#else + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); +#endif return *this; } @@ -1725,18 +1699,7 @@ private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); template <class _A0> - typename enable_if - < - is_constructible<value_type, _A0>::value, - __node_holder - >::type - __construct_node(_A0&& __a0); - template <class _A0> - typename enable_if - < - is_constructible<key_type, _A0>::value, - __node_holder - >::type + __node_holder __construct_node(_A0&& __a0); #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _A0, class _A1, class ..._Args> @@ -1766,20 +1729,16 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node() { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } template <class _Key, class _Tp, class _Compare, class _Allocator> template <class _A0> -typename enable_if -< - is_constructible<pair<const _Key, _Tp>, _A0>::value, - typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder ->::type +typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); @@ -1790,24 +1749,6 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) return __h; } -template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0> -typename enable_if -< - is_constructible<_Key, _A0>::value, - typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder ->::type -multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) -{ - __node_allocator& __na = __tree_.__node_alloc(); - __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); - __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); - __h.get_deleter().__second_constructed = true; - return __h; -} - #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _Key, class _Tp, class _Compare, class _Allocator> diff --git a/system/include/libcxx/memory b/system/include/libcxx/memory index fe352382..ffd0cd0c 100644 --- a/system/include/libcxx/memory +++ b/system/include/libcxx/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 { @@ -621,7 +625,7 @@ inline _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) _NOEXCEPT { - return (_Tp*)&(char&)__x; + return (_Tp*)&reinterpret_cast<const volatile char&>(__x); } #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) @@ -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();} @@ -2485,6 +2489,7 @@ struct _LIBCPP_TYPE_VIS default_delete _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT { static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); delete __ptr; } }; @@ -2507,6 +2512,7 @@ public: typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT { static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); delete [] __ptr; } }; @@ -3077,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. @@ -3102,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; @@ -3161,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) { @@ -3183,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); } @@ -3207,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); @@ -3259,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; diff --git a/system/include/libcxx/random b/system/include/libcxx/random index 92722ea6..2e7a4854 100644 --- a/system/include/libcxx/random +++ b/system/include/libcxx/random @@ -1880,7 +1880,7 @@ public: seed(_Sseq& __q) {__seed(__q, integral_constant<unsigned, 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 - : (__m-1) / 0x100000000ull)>());} + : (__m > 0x100000000ull))>());} // generating functions _LIBCPP_INLINE_VISIBILITY @@ -1969,37 +1969,10 @@ linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, uint32_t __ar[__k+3]; __q.generate(__ar, __ar + __k + 3); result_type __s = static_cast<result_type>((__ar[3] + - (uint64_t)__ar[4] << 32) % __m); + ((uint64_t)__ar[4] << 32)) % __m); __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; } -template <class _CharT, class _Traits> -class __save_flags -{ - typedef basic_ios<_CharT, _Traits> __stream_type; - typedef typename __stream_type::fmtflags fmtflags; - - __stream_type& __stream_; - fmtflags __fmtflags_; - _CharT __fill_; - - __save_flags(const __save_flags&); - __save_flags& operator=(const __save_flags&); -public: - _LIBCPP_INLINE_VISIBILITY - explicit __save_flags(__stream_type& __stream) - : __stream_(__stream), - __fmtflags_(__stream.flags()), - __fill_(__stream.fill()) - {} - _LIBCPP_INLINE_VISIBILITY - ~__save_flags() - { - __stream_.flags(__fmtflags_); - __stream_.fill(__fill_); - } -}; - template <class _CharT, class _Traits, class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> inline _LIBCPP_INLINE_VISIBILITY diff --git a/system/include/libcxx/readme.txt b/system/include/libcxx/readme.txt index 97d8db86..7687e5b2 100644 --- a/system/include/libcxx/readme.txt +++ b/system/include/libcxx/readme.txt @@ -1 +1 @@ -These files are from libc++, svn revision 178253, Mar 29 2013 +These files are from libc++, svn revision 187959, 2013-08-08. diff --git a/system/include/libcxx/regex b/system/include/libcxx/regex index d1afa54a..bde3af7e 100644 --- a/system/include/libcxx/regex +++ b/system/include/libcxx/regex @@ -2769,7 +2769,7 @@ private: void __push_end_marked_subexpression(unsigned); void __push_empty(); void __push_word_boundary(bool); - void __push_lookahead(const basic_regex&, bool); + void __push_lookahead(const basic_regex&, bool, unsigned); template <class _Allocator> bool @@ -2843,6 +2843,15 @@ private: const basic_regex<_Cp, _Tp>& __e, regex_constants::match_flag_type __flags); + template <class _Iter, class _Ap, class _Cp, class _Tp> + friend + bool + regex_search(__wrap_iter<_Iter> __first, + __wrap_iter<_Iter> __last, + match_results<__wrap_iter<_Iter>, _Ap>& __m, + const basic_regex<_Cp, _Tp>& __e, + regex_constants::match_flag_type __flags); + template <class, class> friend class __lookahead; }; @@ -2898,6 +2907,7 @@ class __lookahead typedef __owns_one_state<_CharT> base; basic_regex<_CharT, _Traits> __exp_; + unsigned __mexp_; bool __invert_; __lookahead(const __lookahead&); @@ -2906,8 +2916,8 @@ public: typedef _VSTD::__state<_CharT> __state; _LIBCPP_INLINE_VISIBILITY - __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s) - : base(__s), __exp_(__exp), __invert_(__invert) {} + __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) + : base(__s), __exp_(__exp), __invert_(__invert), __mexp_(__mexp) {} virtual void __exec(__state&) const; }; @@ -2921,11 +2931,14 @@ __lookahead<_CharT, _Traits>::__exec(__state& __s) const bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, __m, __s.__flags_ | regex_constants::match_continuous, - true); + __s.__at_first_ && __s.__current_ == __s.__first_); if (__matched != __invert_) { __s.__do_ = __state::__accept_but_not_consume; __s.__node_ = this->first(); + for (unsigned __i = 1; __i < __m.size(); ++__i) { + __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; + } } else { @@ -3420,6 +3433,7 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, case '+': case '?': case '{': + case '}': __push_char(*__temp); __first = ++__temp; break; @@ -3903,7 +3917,7 @@ basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, { __val = 8 * __val + *__first - '0'; if (++__first != __last && ('0' <= *__first && *__first <= '7')) - __val = 8 * __val + *__first - '0'; + __val = 8 * __val + *__first++ - '0'; } if (__str) *__str = _CharT(__val); @@ -4158,7 +4172,9 @@ basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, basic_regex __exp; __exp.__flags_ = __flags_; __temp = __exp.__parse(++__temp, __last); - __push_lookahead(_VSTD::move(__exp), false); + unsigned __mexp = __exp.__marked_count_; + __push_lookahead(_VSTD::move(__exp), false, __marked_count_); + __marked_count_ += __mexp; #ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last || *__temp != ')') throw regex_error(regex_constants::error_paren); @@ -4171,7 +4187,9 @@ basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, basic_regex __exp; __exp.__flags_ = __flags_; __temp = __exp.__parse(++__temp, __last); - __push_lookahead(_VSTD::move(__exp), true); + unsigned __mexp = __exp.__marked_count_; + __push_lookahead(_VSTD::move(__exp), true, __marked_count_); + __marked_count_ += __mexp; #ifndef _LIBCPP_NO_EXCEPTIONS if (__temp == __last || *__temp != ')') throw regex_error(regex_constants::error_paren); @@ -4408,7 +4426,8 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, case 'c': if ((__t = _VSTD::next(__first)) != __last) { - if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z') + if (('A' <= *__t && *__t <= 'Z') || + ('a' <= *__t && *__t <= 'z')) { if (__str) *__str = _CharT(*__t % 32); @@ -4416,7 +4435,15 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, __push_char(_CharT(*__t % 32)); __first = ++__t; } +#ifndef _LIBCPP_NO_EXCEPTIONS + else + throw regex_error(regex_constants::error_escape); +#endif // _LIBCPP_NO_EXCEPTIONS } +#ifndef _LIBCPP_NO_EXCEPTIONS + else + throw regex_error(regex_constants::error_escape); +#endif // _LIBCPP_NO_EXCEPTIONS break; case 'u': ++__first; @@ -4481,7 +4508,7 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, ++__first; } #ifndef _LIBCPP_NO_EXCEPTIONS - else if (__str) + else throw regex_error(regex_constants::error_escape); #endif // _LIBCPP_NO_EXCEPTIONS break; @@ -4740,10 +4767,11 @@ basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) template <class _CharT, class _Traits> void basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, - bool __invert) + bool __invert, + unsigned __mexp) { __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, - __end_->first()); + __end_->first(), __mexp); __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); } @@ -5763,7 +5791,8 @@ basic_regex<_CharT, _Traits>::__search( { __m.__init(1 + mark_count(), __first, __last, __flags & regex_constants::__no_update_pos); - if (__match_at_start(__first, __last, __m, __flags, true)) + if (__match_at_start(__first, __last, __m, __flags, + !(__flags & regex_constants::__no_update_pos))) { __m.__prefix_.second = __m[0].first; __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; @@ -5800,9 +5829,25 @@ regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, regex_constants::match_flag_type __flags = regex_constants::match_default) { - basic_string<_CharT> __s(__first, __last); + int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; + basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); match_results<const _CharT*> __mc; - bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); + bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); + __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); + return __r; +} + +template <class _Iter, class _Allocator, class _CharT, class _Traits> +inline _LIBCPP_INLINE_VISIBILITY +bool +regex_search(__wrap_iter<_Iter> __first, + __wrap_iter<_Iter> __last, + match_results<__wrap_iter<_Iter>, _Allocator>& __m, + const basic_regex<_CharT, _Traits>& __e, + regex_constants::match_flag_type __flags = regex_constants::match_default) +{ + match_results<const _CharT*> __mc; + bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); return __r; } @@ -6044,7 +6089,7 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() { __flags_ |= regex_constants::__no_update_pos; _BidirectionalIterator __start = __match_[0].second; - if (__match_.length() == 0) + if (__match_.empty()) { if (__start == __end_) { diff --git a/system/include/libcxx/sstream b/system/include/libcxx/sstream index c431fec0..a8f8148a 100644 --- a/system/include/libcxx/sstream +++ b/system/include/libcxx/sstream @@ -260,17 +260,36 @@ template <class _CharT, class _Traits, class _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { - ptrdiff_t __ninp = __rhs.gptr() - __rhs.eback(); - ptrdiff_t __einp = __rhs.egptr() - __rhs.eback(); - ptrdiff_t __nout = __rhs.pptr() - __rhs.pbase(); - ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase(); - ptrdiff_t __hm = __rhs.__hm_ - __rhs.pbase(); + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __binp = -1; + ptrdiff_t __ninp = -1; + ptrdiff_t __einp = -1; + if (__rhs.eback() != nullptr) + { + __binp = __rhs.eback() - __p; + __ninp = __rhs.gptr() - __p; + __einp = __rhs.egptr() - __p; + } + ptrdiff_t __bout = -1; + ptrdiff_t __nout = -1; + ptrdiff_t __eout = -1; + if (__rhs.pbase() != nullptr) + { + __bout = __rhs.pbase() - __p; + __nout = __rhs.pptr() - __p; + __eout = __rhs.epptr() - __p; + } + ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; __str_ = _VSTD::move(__rhs.__str_); - char_type* __p = const_cast<char_type*>(__str_.data()); - this->setg(__p, __p + __ninp, __p + __einp); - this->setp(__p, __p + __eout); - this->pbump(__nout); - __hm_ = __p + __hm; + __p = const_cast<char_type*>(__str_.data()); + if (__binp != -1) + this->setg(__p + __binp, __p + __ninp, __p + __einp); + if (__bout != -1) + { + this->setp(__p + __bout, __p + __eout); + this->pbump(__nout); + } + __hm_ = __hm == -1 ? nullptr : __p + __hm; __p = const_cast<char_type*>(__rhs.__str_.data()); __rhs.setg(__p, __p, __p); __rhs.setp(__p, __p); @@ -282,18 +301,37 @@ template <class _CharT, class _Traits, class _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>& basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) { - ptrdiff_t __ninp = __rhs.gptr() - __rhs.eback(); - ptrdiff_t __einp = __rhs.egptr() - __rhs.eback(); - ptrdiff_t __nout = __rhs.pptr() - __rhs.pbase(); - ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase(); - ptrdiff_t __hm = __rhs.__hm_ - __rhs.pbase(); - __mode_ = __rhs.__mode_; + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __binp = -1; + ptrdiff_t __ninp = -1; + ptrdiff_t __einp = -1; + if (__rhs.eback() != nullptr) + { + __binp = __rhs.eback() - __p; + __ninp = __rhs.gptr() - __p; + __einp = __rhs.egptr() - __p; + } + ptrdiff_t __bout = -1; + ptrdiff_t __nout = -1; + ptrdiff_t __eout = -1; + if (__rhs.pbase() != nullptr) + { + __bout = __rhs.pbase() - __p; + __nout = __rhs.pptr() - __p; + __eout = __rhs.epptr() - __p; + } + ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; __str_ = _VSTD::move(__rhs.__str_); - char_type* __p = const_cast<char_type*>(__str_.data()); - this->setg(__p, __p + __ninp, __p + __einp); - this->setp(__p, __p + __eout); - this->pbump(__nout); - __hm_ = __p + __hm; + __p = const_cast<char_type*>(__str_.data()); + if (__binp != -1) + this->setg(__p + __binp, __p + __ninp, __p + __einp); + if (__bout != -1) + { + this->setp(__p + __bout, __p + __eout); + this->pbump(__nout); + } + __hm_ = __hm == -1 ? nullptr : __p + __hm; + __mode_ = __rhs.__mode_; __p = const_cast<char_type*>(__rhs.__str_.data()); __rhs.setg(__p, __p, __p); __rhs.setp(__p, __p); @@ -308,28 +346,74 @@ template <class _CharT, class _Traits, class _Allocator> void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) { - ptrdiff_t __rninp = __rhs.gptr() - __rhs.eback(); - ptrdiff_t __reinp = __rhs.egptr() - __rhs.eback(); - ptrdiff_t __rnout = __rhs.pptr() - __rhs.pbase(); - ptrdiff_t __reout = __rhs.epptr() - __rhs.pbase(); - ptrdiff_t __rhm = __rhs.__hm_ - __rhs.pbase(); - ptrdiff_t __lninp = this->gptr() - this->eback(); - ptrdiff_t __leinp = this->egptr() - this->eback(); - ptrdiff_t __lnout = this->pptr() - this->pbase(); - ptrdiff_t __leout = this->epptr() - this->pbase(); - ptrdiff_t __lhm = this->__hm_ - this->pbase(); + char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); + ptrdiff_t __rbinp = -1; + ptrdiff_t __rninp = -1; + ptrdiff_t __reinp = -1; + if (__rhs.eback() != nullptr) + { + __rbinp = __rhs.eback() - __p; + __rninp = __rhs.gptr() - __p; + __reinp = __rhs.egptr() - __p; + } + ptrdiff_t __rbout = -1; + ptrdiff_t __rnout = -1; + ptrdiff_t __reout = -1; + if (__rhs.pbase() != nullptr) + { + __rbout = __rhs.pbase() - __p; + __rnout = __rhs.pptr() - __p; + __reout = __rhs.epptr() - __p; + } + ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; + __p = const_cast<char_type*>(__str_.data()); + ptrdiff_t __lbinp = -1; + ptrdiff_t __lninp = -1; + ptrdiff_t __leinp = -1; + if (this->eback() != nullptr) + { + __lbinp = this->eback() - __p; + __lninp = this->gptr() - __p; + __leinp = this->egptr() - __p; + } + ptrdiff_t __lbout = -1; + ptrdiff_t __lnout = -1; + ptrdiff_t __leout = -1; + if (this->pbase() != nullptr) + { + __lbout = this->pbase() - __p; + __lnout = this->pptr() - __p; + __leout = this->epptr() - __p; + } + ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; _VSTD::swap(__mode_, __rhs.__mode_); __str_.swap(__rhs.__str_); - char_type* __p = const_cast<char_type*>(__str_.data()); - this->setg(__p, __p + __rninp, __p + __reinp); - this->setp(__p, __p + __reout); - this->pbump(__rnout); - __hm_ = __p + __rhm; + __p = const_cast<char_type*>(__str_.data()); + if (__rbinp != -1) + this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); + else + this->setg(nullptr, nullptr, nullptr); + if (__rbout != -1) + { + this->setp(__p + __rbout, __p + __reout); + this->pbump(__rnout); + } + else + this->setp(nullptr, nullptr); + __hm_ = __rhm == -1 ? nullptr : __p + __rhm; __p = const_cast<char_type*>(__rhs.__str_.data()); - __rhs.setg(__p, __p + __lninp, __p + __leinp); - __rhs.setp(__p, __p + __leout); - __rhs.pbump(__lnout); - __rhs.__hm_ = __p + __lhm; + if (__lbinp != -1) + __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); + else + __rhs.setg(nullptr, nullptr, nullptr); + if (__lbout != -1) + { + __rhs.setp(__p + __lbout, __p + __leout); + __rhs.pbump(__lnout); + } + else + __rhs.setp(nullptr, nullptr); + __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; locale __tl = __rhs.getloc(); __rhs.pubimbue(this->getloc()); this->pubimbue(__tl); diff --git a/system/include/libcxx/string b/system/include/libcxx/string index de668bba..83dc53a1 100644 --- a/system/include/libcxx/string +++ b/system/include/libcxx/string @@ -100,8 +100,8 @@ public: noexcept(is_nothrow_move_constructible<allocator_type>::value); basic_string(const basic_string& str, size_type pos, size_type n = npos, const allocator_type& a = allocator_type()); - basic_string(const_pointer s, const allocator_type& a = allocator_type()); - basic_string(const_pointer s, size_type n, const allocator_type& a = allocator_type()); + basic_string(const value_type* s, const allocator_type& a = allocator_type()); + basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); template<class InputIterator> basic_string(InputIterator begin, InputIterator end, @@ -117,7 +117,7 @@ public: noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); - basic_string& operator=(const_pointer s); + basic_string& operator=(const value_type* s); basic_string& operator=(value_type c); basic_string& operator=(initializer_list<value_type>); @@ -156,14 +156,14 @@ public: reference at(size_type n); basic_string& operator+=(const basic_string& str); - basic_string& operator+=(const_pointer s); + basic_string& operator+=(const value_type* s); basic_string& operator+=(value_type c); basic_string& operator+=(initializer_list<value_type>); basic_string& append(const basic_string& str); basic_string& append(const basic_string& str, size_type pos, size_type n); - basic_string& append(const_pointer s, size_type n); - basic_string& append(const_pointer s); + basic_string& append(const value_type* s, size_type n); + basic_string& append(const value_type* s); basic_string& append(size_type n, value_type c); template<class InputIterator> basic_string& append(InputIterator first, InputIterator last); @@ -179,8 +179,8 @@ public: basic_string& assign(const basic_string& str); basic_string& assign(basic_string&& str); basic_string& assign(const basic_string& str, size_type pos, size_type n); - basic_string& assign(const_pointer s, size_type n); - basic_string& assign(const_pointer s); + basic_string& assign(const value_type* s, size_type n); + basic_string& assign(const value_type* s); basic_string& assign(size_type n, value_type c); template<class InputIterator> basic_string& assign(InputIterator first, InputIterator last); @@ -189,8 +189,8 @@ public: basic_string& insert(size_type pos1, const basic_string& str); basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n); - basic_string& insert(size_type pos, const_pointer s, size_type n); - basic_string& insert(size_type pos, const_pointer s); + basic_string& insert(size_type pos, const value_type* s, size_type n); + basic_string& insert(size_type pos, const value_type* s); basic_string& insert(size_type pos, size_type n, value_type c); iterator insert(const_iterator p, value_type c); iterator insert(const_iterator p, size_type n, value_type c); @@ -205,66 +205,66 @@ public: basic_string& replace(size_type pos1, size_type n1, const basic_string& str); basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2); - basic_string& replace(size_type pos, size_type n1, const_pointer s, size_type n2); - basic_string& replace(size_type pos, size_type n1, const_pointer s); + basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); + basic_string& replace(size_type pos, size_type n1, const value_type* s); basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); - basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s, size_type n); - basic_string& replace(const_iterator i1, const_iterator i2, const_pointer s); + basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); + basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); template<class InputIterator> basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); - size_type copy(pointer s, size_type n, size_type pos = 0) const; + size_type copy(value_type* s, size_type n, size_type pos = 0) const; basic_string substr(size_type pos = 0, size_type n = npos) const; void swap(basic_string& str) noexcept(!allocator_type::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) - const_pointer c_str() const noexcept; - const_pointer data() const noexcept; + const value_type* c_str() const noexcept; + const value_type* data() const noexcept; allocator_type get_allocator() const noexcept; size_type find(const basic_string& str, size_type pos = 0) const noexcept; - size_type find(const_pointer s, size_type pos, size_type n) const noexcept; - size_type find(const_pointer s, size_type pos = 0) const noexcept; + size_type find(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find(const value_type* s, size_type pos = 0) const noexcept; size_type find(value_type c, size_type pos = 0) const noexcept; size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; - size_type rfind(const_pointer s, size_type pos, size_type n) const noexcept; - size_type rfind(const_pointer s, size_type pos = npos) const noexcept; + size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; + size_type rfind(const value_type* s, size_type pos = npos) const noexcept; size_type rfind(value_type c, size_type pos = npos) const noexcept; size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; - size_type find_first_of(const_pointer s, size_type pos, size_type n) const noexcept; - size_type find_first_of(const_pointer s, size_type pos = 0) const noexcept; + size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; size_type find_first_of(value_type c, size_type pos = 0) const noexcept; size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; - size_type find_last_of(const_pointer s, size_type pos, size_type n) const noexcept; - size_type find_last_of(const_pointer s, size_type pos = npos) const noexcept; + size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; size_type find_last_of(value_type c, size_type pos = npos) const noexcept; size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; - size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const noexcept; - size_type find_first_not_of(const_pointer s, size_type pos = 0) const noexcept; + size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; - size_type find_last_not_of(const_pointer s, size_type pos, size_type n) const noexcept; - size_type find_last_not_of(const_pointer s, size_type pos = npos) const noexcept; + size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; + size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; int compare(const basic_string& str) const noexcept; int compare(size_type pos1, size_type n1, const basic_string& str) const; int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2) const; - int compare(const_pointer s) const noexcept; - int compare(size_type pos1, size_type n1, const_pointer s) const; - int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const; + int compare(const value_type* s) const noexcept; + int compare(size_type pos1, size_type n1, const value_type* s) const; + int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; bool __invariants() const; }; @@ -422,6 +422,11 @@ template <> struct hash<u16string>; template <> struct hash<u32string>; template <> struct hash<wstring>; +basic_string<char> operator "" s( const char *str, size_t len ); // C++14 +basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14 +basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14 +basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14 + } // std */ @@ -1027,14 +1032,29 @@ __basic_string_common<__b>::__throw_out_of_range() const #endif } -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( push ) #pragma warning( disable: 4231 ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>) -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( pop ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC + +#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT + +template <class _CharT, size_t = sizeof(_CharT)> +struct __padding +{ + unsigned char __xx[sizeof(_CharT)-1]; +}; + +template <class _CharT> +struct __padding<_CharT, 1> +{ +}; + +#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT template<class _CharT, class _Traits, class _Allocator> class _LIBCPP_TYPE_VIS basic_string @@ -1069,6 +1089,39 @@ public: typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; private: + +#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT + + struct __long + { + pointer __data_; + size_type __size_; + size_type __cap_; + }; + +#if _LIBCPP_BIG_ENDIAN + enum {__short_mask = 0x01}; + enum {__long_mask = 0x1ul}; +#else // _LIBCPP_BIG_ENDIAN + enum {__short_mask = 0x80}; + enum {__long_mask = ~(size_type(~0) >> 1)}; +#endif // _LIBCPP_BIG_ENDIAN + + enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? + (sizeof(__long) - 1)/sizeof(value_type) : 2}; + + struct __short + { + value_type __data_[__min_cap]; + struct + : __padding<value_type> + { + unsigned char __size_; + }; + }; + +#else + struct __long { size_type __cap_; @@ -1084,8 +1137,6 @@ private: enum {__long_mask = 0x1ul}; #endif // _LIBCPP_BIG_ENDIAN - enum {__mask = size_type(~0) >> 1}; - enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? (sizeof(__long) - 1)/sizeof(value_type) : 2}; @@ -1099,6 +1150,8 @@ private: value_type __data_[__min_cap]; }; +#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT + union __lx{__long __lx; __short __lxx;}; enum {__n_words = sizeof(__lx) / sizeof(size_type)}; @@ -1144,13 +1197,13 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str, const allocator_type& __a); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s); + _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s); _LIBCPP_INLINE_VISIBILITY - basic_string(const_pointer __s, const allocator_type& __a); + basic_string(const value_type* __s, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(const_pointer __s, size_type __n); + basic_string(const value_type* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY - basic_string(const_pointer __s, size_type __n, const allocator_type& __a); + basic_string(const value_type* __s, size_type __n, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY basic_string(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY @@ -1179,7 +1232,7 @@ public: _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); #endif - _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} basic_string& operator=(value_type __c); #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY @@ -1192,13 +1245,13 @@ public: {return iterator(__get_pointer());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT - {return const_iterator(data());} + {return const_iterator(__get_pointer());} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(__get_pointer() + size());} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT - {return const_iterator(data() + size());} + {return const_iterator(__get_pointer() + size());} #else // _LIBCPP_DEBUG _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());} @@ -1255,7 +1308,7 @@ public: reference at(size_type __n); _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);} - _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s) {return append(__s);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);} _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;} #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} @@ -1264,8 +1317,8 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& append(const basic_string& __str); basic_string& append(const basic_string& __str, size_type __pos, size_type __n); - basic_string& append(const_pointer __s, size_type __n); - basic_string& append(const_pointer __s); + basic_string& append(const value_type* __s, size_type __n); + basic_string& append(const value_type* __s); basic_string& append(size_type __n, value_type __c); template<class _InputIterator> typename enable_if @@ -1303,8 +1356,8 @@ public: {*this = _VSTD::move(str); return *this;} #endif basic_string& assign(const basic_string& __str, size_type __pos, size_type __n); - basic_string& assign(const_pointer __s, size_type __n); - basic_string& assign(const_pointer __s); + basic_string& assign(const value_type* __s, size_type __n); + basic_string& assign(const value_type* __s); basic_string& assign(size_type __n, value_type __c); template<class _InputIterator> typename enable_if @@ -1329,8 +1382,8 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& insert(size_type __pos1, const basic_string& __str); basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n); - basic_string& insert(size_type __pos, const_pointer __s, size_type __n); - basic_string& insert(size_type __pos, const_pointer __s); + basic_string& insert(size_type __pos, const value_type* __s, size_type __n); + basic_string& insert(size_type __pos, const value_type* __s); basic_string& insert(size_type __pos, size_type __n, value_type __c); iterator insert(const_iterator __pos, value_type __c); _LIBCPP_INLINE_VISIBILITY @@ -1365,15 +1418,15 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2); - basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2); - basic_string& replace(size_type __pos, size_type __n1, const_pointer __s); + basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); + basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); _LIBCPP_INLINE_VISIBILITY - basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n); + basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY - basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s); + basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); template<class _InputIterator> @@ -1389,7 +1442,7 @@ public: {return replace(__i1, __i2, __il.begin(), __il.end());} #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - size_type copy(pointer __s, size_type __n, size_type __pos = 0) const; + size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; _LIBCPP_INLINE_VISIBILITY basic_string substr(size_type __pos = 0, size_type __n = npos) const; @@ -1399,56 +1452,56 @@ public: __is_nothrow_swappable<allocator_type>::value); _LIBCPP_INLINE_VISIBILITY - const_pointer c_str() const _NOEXCEPT {return data();} + const value_type* c_str() const _NOEXCEPT {return data();} _LIBCPP_INLINE_VISIBILITY - const_pointer data() const _NOEXCEPT {return __get_pointer();} + const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return __alloc();} _LIBCPP_INLINE_VISIBILITY size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; - size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; + size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; - size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; + size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; - size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; + size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; - size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; + size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; - size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; + size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; - size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; + size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; + size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; @@ -1457,11 +1510,16 @@ public: _LIBCPP_INLINE_VISIBILITY int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const; - int compare(const_pointer __s) const _NOEXCEPT; - int compare(size_type __pos1, size_type __n1, const_pointer __s) const; - int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const; + int compare(const value_type* __s) const _NOEXCEPT; + int compare(size_type __pos1, size_type __n1, const value_type* __s) const; + int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; _LIBCPP_INLINE_VISIBILITY bool __invariants() const; + + _LIBCPP_INLINE_VISIBILITY + bool __is_long() const _NOEXCEPT + {return bool(__r_.first().__s.__size_ & __short_mask);} + private: _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() _NOEXCEPT @@ -1470,24 +1528,44 @@ private: const allocator_type& __alloc() const _NOEXCEPT {return __r_.second();} +#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT + _LIBCPP_INLINE_VISIBILITY - bool __is_long() const _NOEXCEPT - {return bool(__r_.first().__s.__size_ & __short_mask);} + void __set_short_size(size_type __s) _NOEXCEPT +# if _LIBCPP_BIG_ENDIAN + {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} +# else + {__r_.first().__s.__size_ = (unsigned char)(__s);} +# endif + + _LIBCPP_INLINE_VISIBILITY + size_type __get_short_size() const _NOEXCEPT +# if _LIBCPP_BIG_ENDIAN + {return __r_.first().__s.__size_ >> 1;} +# else + {return __r_.first().__s.__size_;} +# endif + +#else // _LIBCPP_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT -#if _LIBCPP_BIG_ENDIAN +# if _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s);} -#else +# else {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} -#endif +# endif + _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT -#if _LIBCPP_BIG_ENDIAN +# if _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_;} -#else +# else {return __r_.first().__s.__size_ >> 1;} -#endif +# endif + +#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT + _LIBCPP_INLINE_VISIBILITY void __set_long_size(size_type __s) _NOEXCEPT {__r_.first().__l.__size_ = __s;} @@ -1516,10 +1594,10 @@ private: {return __r_.first().__l.__data_;} _LIBCPP_INLINE_VISIBILITY pointer __get_short_pointer() _NOEXCEPT - {return __r_.first().__s.__data_;} + {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} _LIBCPP_INLINE_VISIBILITY const_pointer __get_short_pointer() const _NOEXCEPT - {return __r_.first().__s.__data_;} + {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} _LIBCPP_INLINE_VISIBILITY pointer __get_pointer() _NOEXCEPT {return __is_long() ? __get_long_pointer() : __get_short_pointer();} @@ -1546,8 +1624,8 @@ private: __align<sizeof(value_type) < __alignment ? __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} - void __init(const_pointer __s, size_type __sz, size_type __reserve); - void __init(const_pointer __s, size_type __sz); + void __init(const value_type* __s, size_type __sz, size_type __reserve); + void __init(const value_type* __s, size_type __sz); void __init(size_type __n, value_type __c); template <class _InputIterator> @@ -1571,7 +1649,7 @@ private: size_type __n_copy, size_type __n_del, size_type __n_add = 0); void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, size_type __n_copy, size_type __n_del, - size_type __n_add, const_pointer __p_new_stuff); + size_type __n_add, const value_type* __p_new_stuff); _LIBCPP_INLINE_VISIBILITY void __erase_to_end(size_type __pos); @@ -1728,7 +1806,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __ template <class _CharT, class _Traits, class _Allocator> void -basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve) +basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) { if (__reserve > max_size()) this->__throw_length_error(); @@ -1746,13 +1824,13 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type _ __set_long_cap(__cap+1); __set_long_size(__sz); } - traits_type::copy(__p, __s, __sz); + traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); traits_type::assign(__p[__sz], value_type()); } template <class _CharT, class _Traits, class _Allocator> void -basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz) +basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) { if (__sz > max_size()) this->__throw_length_error(); @@ -1770,13 +1848,13 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type _ __set_long_cap(__cap+1); __set_long_size(__sz); } - traits_type::copy(__p, __s, __sz); + traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); traits_type::assign(__p[__sz], value_type()); } template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline -basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -1786,7 +1864,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s) template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline -basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a) : __r_(__a) { #ifdef _LIBCPP_DEBUG @@ -1797,7 +1875,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline -basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -1807,7 +1885,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_ template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline -basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a) : __r_(__a) { #ifdef _LIBCPP_DEBUG @@ -1823,7 +1901,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; else - __init(__str.__get_long_pointer(), __str.__get_long_size()); + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); } template <class _CharT, class _Traits, class _Allocator> @@ -1833,7 +1911,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; else - __init(__str.__get_long_pointer(), __str.__get_long_size()); + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1858,7 +1936,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co if (__a == __str.__alloc() || !__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; else - __init(__str.__get_long_pointer(), __str.__get_long_size()); + __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); __str.__zero(); #ifdef _LIBCPP_DEBUG __str.__invalidate_all_iterators(); @@ -1887,7 +1965,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) __set_long_cap(__cap+1); __set_long_size(__n); } - traits_type::assign(__p, __n, __c); + traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c); traits_type::assign(__p[__n], value_type()); } @@ -2025,7 +2103,7 @@ template <class _CharT, class _Traits, class _Allocator> void basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace (size_type __old_cap, size_type __delta_cap, size_type __old_sz, - size_type __n_copy, size_type __n_del, size_type __n_add, const_pointer __p_new_stuff) + size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) { size_type __ms = max_size(); if (__delta_cap > __ms - __old_cap - 1) @@ -2037,12 +2115,14 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); if (__n_copy != 0) - traits_type::copy(__p, __old_p, __n_copy); + traits_type::copy(_VSTD::__to_raw_pointer(__p), + _VSTD::__to_raw_pointer(__old_p), __n_copy); if (__n_add != 0) - traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add); + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add); size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; if (__sec_cp_sz != 0) - traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz); + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, + _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); if (__old_cap+1 != __min_cap) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); @@ -2067,10 +2147,13 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); if (__n_copy != 0) - traits_type::copy(__p, __old_p, __n_copy); + traits_type::copy(_VSTD::__to_raw_pointer(__p), + _VSTD::__to_raw_pointer(__old_p), __n_copy); size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; if (__sec_cp_sz != 0) - traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz); + traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, + _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, + __sec_cp_sz); if (__old_cap+1 != __min_cap) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); @@ -2081,7 +2164,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2089,7 +2172,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type _ size_type __cap = capacity(); if (__cap >= __n) { - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::move(__p, __s, __n); traits_type::assign(__p[__n], value_type()); __set_size(__n); @@ -2115,7 +2198,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) } else __invalidate_iterators_past(__n); - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::assign(__p, __n, __c); traits_type::assign(__p[__n], value_type()); __set_size(__n); @@ -2257,7 +2340,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2269,7 +2352,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s) template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2280,7 +2363,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type _ { if (__n) { - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::copy(__p + __sz, __s, __n); __sz += __n; __set_size(__sz); @@ -2303,7 +2386,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); pointer __p = __get_pointer(); - traits_type::assign(__p + __sz, __n, __c); + traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c); __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); @@ -2315,14 +2398,37 @@ template <class _CharT, class _Traits, class _Allocator> void basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) { - size_type __cap = capacity(); - size_type __sz = size(); + bool __is_short = !__is_long(); + size_type __cap; + size_type __sz; + if (__is_short) + { + __cap = __min_cap - 1; + __sz = __get_short_size(); + } + else + { + __cap = __get_long_cap() - 1; + __sz = __get_long_size(); + } if (__sz == __cap) + { __grow_by(__cap, 1, __sz, __sz, 0); - pointer __p = __get_pointer() + __sz; + __is_short = !__is_long(); + } + pointer __p; + if (__is_short) + { + __p = __get_short_pointer() + __sz; + __set_short_size(__sz+1); + } + else + { + __p = __get_long_pointer() + __sz; + __set_long_size(__sz+1); + } traits_type::assign(*__p, __c); traits_type::assign(*++__p, value_type()); - __set_size(__sz+1); } template <class _CharT, class _Traits, class _Allocator> @@ -2385,7 +2491,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2397,7 +2503,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s) template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2410,7 +2516,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer { if (__n) { - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __pos; if (__n_move != 0) { @@ -2439,10 +2545,10 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n if (__n) { size_type __cap = capacity(); - pointer __p; + value_type* __p; if (__cap - __sz >= __n) { - __p = __get_pointer(); + __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __pos; if (__n_move != 0) traits_type::move(__p + __pos + __n, __p + __pos, __n_move); @@ -2450,7 +2556,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n else { __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); - __p = __get_long_pointer(); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } traits_type::assign(__p + __pos, __n, __c); __sz += __n; @@ -2494,10 +2600,10 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) { - pointer __p; + value_type* __p; if (__cap - __sz >= __n) { - __p = __get_pointer(); + __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __ip; if (__n_move != 0) traits_type::move(__p + __ip + __n, __p + __ip, __n_move); @@ -2505,7 +2611,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward else { __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); - __p = __get_long_pointer(); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } __sz += __n; __set_size(__sz); @@ -2537,7 +2643,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_ template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2552,15 +2658,15 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_ty size_type __ip = static_cast<size_type>(__pos - begin()); size_type __sz = size(); size_type __cap = capacity(); - pointer __p; + value_type* __p; if (__cap == __sz) { __grow_by(__cap, 1, __sz, __ip, 0, 1); - __p = __get_long_pointer(); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } else { - __p = __get_pointer(); + __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __ip; if (__n_move != 0) traits_type::move(__p + __ip + 1, __p + __ip, __n_move); @@ -2585,7 +2691,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_typ template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2) +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2597,7 +2703,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ size_type __cap = capacity(); if (__cap - __sz + __n1 >= __n2) { - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); if (__n1 != __n2) { size_type __n_move = __sz - __pos - __n1; @@ -2646,10 +2752,10 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ this->__throw_out_of_range(); __n1 = _VSTD::min(__n1, __sz - __pos); size_type __cap = capacity(); - pointer __p; + value_type* __p; if (__cap - __sz + __n1 >= __n2) { - __p = __get_pointer(); + __p = _VSTD::__to_raw_pointer(__get_pointer()); if (__n1 != __n2) { size_type __n_move = __sz - __pos - __n1; @@ -2660,7 +2766,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ else { __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); - __p = __get_long_pointer(); + __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } traits_type::assign(__p + __pos, __n2, __c); __sz += __n2 - __n1; @@ -2719,7 +2825,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _ template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -2739,7 +2845,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) { return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); } @@ -2747,7 +2853,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline basic_string<_CharT, _Traits, _Allocator>& -basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s) +basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) { return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); } @@ -2771,7 +2877,7 @@ basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) this->__throw_out_of_range(); if (__n) { - pointer __p = __get_pointer(); + value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); __n = _VSTD::min(__n, __sz - __pos); size_type __n_move = __sz - __pos - __n; if (__n_move != 0) @@ -2929,7 +3035,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) return; } #else // _LIBCPP_NO_EXCEPTIONS - if (__new_data == 0) + if (__new_data == nullptr) return; #endif // _LIBCPP_NO_EXCEPTIONS } @@ -2937,7 +3043,8 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) __was_long = __is_long(); __p = __get_pointer(); } - traits_type::copy(__new_data, __p, size()+1); + traits_type::copy(_VSTD::__to_raw_pointer(__new_data), + _VSTD::__to_raw_pointer(__p), size()+1); if (__was_long) __alloc_traits::deallocate(__alloc(), __p, __cap+1); if (__now_long) @@ -3038,7 +3145,7 @@ basic_string<_CharT, _Traits, _Allocator>::back() const template <class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const +basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const { size_type __sz = size(); if (__pos > __sz) @@ -3084,7 +3191,7 @@ struct _LIBCPP_HIDDEN __traits_eq template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3096,8 +3203,8 @@ basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, return npos; if (__n == 0) return __pos; - const_pointer __p = data(); - const_pointer __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n, + const value_type* __p = data(); + const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n, __traits_eq<traits_type>()); if (__r == __p + __sz) return npos; @@ -3116,7 +3223,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3133,8 +3240,8 @@ basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __sz = size(); if (__pos >= __sz) return npos; - const_pointer __p = data(); - const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c); + const value_type* __p = data(); + const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c); if (__r == 0) return npos; return static_cast<size_type>(__r - __p); @@ -3144,7 +3251,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3157,8 +3264,8 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, __pos += __n; else __pos = __sz; - const_pointer __p = data(); - const_pointer __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n, + const value_type* __p = data(); + const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n, __traits_eq<traits_type>()); if (__n > 0 && __r == __p + __pos) return npos; @@ -3177,7 +3284,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3198,8 +3305,8 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, ++__pos; else __pos = __sz; - const_pointer __p = data(); - for (const_pointer __ps = __p + __pos; __ps != __p;) + const value_type* __p = data(); + for (const value_type* __ps = __p + __pos; __ps != __p;) { if (traits_type::eq(*--__ps, __c)) return static_cast<size_type>(__ps - __p); @@ -3212,7 +3319,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3222,8 +3329,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, size_type __sz = size(); if (__pos >= __sz || __n == 0) return npos; - const_pointer __p = data(); - const_pointer __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s, + const value_type* __p = data(); + const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s, __s + __n, __traits_eq<traits_type>()); if (__r == __p + __sz) return npos; @@ -3242,7 +3349,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3264,7 +3371,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3278,10 +3385,10 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, ++__pos; else __pos = __sz; - const_pointer __p = data(); - for (const_pointer __ps = __p + __pos; __ps != __p;) + const value_type* __p = data(); + for (const value_type* __ps = __p + __pos; __ps != __p;) { - const_pointer __r = traits_type::find(__s, __n, *--__ps); + const value_type* __r = traits_type::find(__s, __n, *--__ps); if (__r) return static_cast<size_type>(__ps - __p); } @@ -3301,7 +3408,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3323,7 +3430,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3333,9 +3440,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, size_type __sz = size(); if (__pos < __sz) { - const_pointer __p = data(); - const_pointer __pe = __p + __sz; - for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps) + const value_type* __p = data(); + const value_type* __pe = __p + __sz; + for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps) if (traits_type::find(__s, __n, *__ps) == 0) return static_cast<size_type>(__ps - __p); } @@ -3354,7 +3461,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3372,9 +3479,9 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __sz = size(); if (__pos < __sz) { - const_pointer __p = data(); - const_pointer __pe = __p + __sz; - for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps) + const value_type* __p = data(); + const value_type* __pe = __p + __sz; + for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps) if (!traits_type::eq(*__ps, __c)) return static_cast<size_type>(__ps - __p); } @@ -3385,7 +3492,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, template<class _CharT, class _Traits, class _Allocator> typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { @@ -3397,8 +3504,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, ++__pos; else __pos = __sz; - const_pointer __p = data(); - for (const_pointer __ps = __p + __pos; __ps != __p;) + const value_type* __p = data(); + for (const value_type* __ps = __p + __pos; __ps != __p;) if (traits_type::find(__s, __n, *--__ps) == 0) return static_cast<size_type>(__ps - __p); return npos; @@ -3416,7 +3523,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& template<class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline typename basic_string<_CharT, _Traits, _Allocator>::size_type -basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG @@ -3436,8 +3543,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, ++__pos; else __pos = __sz; - const_pointer __p = data(); - for (const_pointer __ps = __p + __pos; __ps != __p;) + const value_type* __p = data(); + for (const value_type* __ps = __p + __pos; __ps != __p;) if (!traits_type::eq(*--__ps, __c)) return static_cast<size_type>(__ps - __p); return npos; @@ -3490,7 +3597,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, template <class _CharT, class _Traits, class _Allocator> int -basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT +basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -3502,7 +3609,7 @@ template <class _CharT, class _Traits, class _Allocator> int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, - const_pointer __s) const + const value_type* __s) const { #ifdef _LIBCPP_DEBUG assert(__s != 0); @@ -3514,7 +3621,7 @@ template <class _CharT, class _Traits, class _Allocator> int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, - const_pointer __s, + const value_type* __s, size_type __n2) const { #ifdef _LIBCPP_DEBUG @@ -3561,9 +3668,29 @@ bool operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { - return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(), - __rhs.data(), - __lhs.size()) == 0; + size_t __lhs_sz = __lhs.size(); + return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), + __rhs.data(), + __lhs_sz) == 0; +} + +template<class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +bool +operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, + const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT +{ + size_t __lhs_sz = __lhs.size(); + if (__lhs_sz != __rhs.size()) + return false; + const char* __lp = __lhs.data(); + const char* __rp = __rhs.data(); + if (__lhs.__is_long()) + return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; + for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) + if (*__lp != *__rp) + return false; + return true; } template<class _CharT, class _Traits, class _Allocator> @@ -3975,6 +4102,42 @@ getline(basic_istream<_CharT, _Traits>&& __is, #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER > 11 +// Literal suffixes for basic_string [basic.string.literals] +// inline // Deviation from N3690. +// We believe the inline to be a defect and have submitted an LWG issue. +// An LWG issue number has not yet been assigned. +namespace literals +{ + inline namespace string_literals + { + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char> operator "" s( const char *__str, size_t __len ) + { + return basic_string<char> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) + { + return basic_string<wchar_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) + { + return basic_string<char16_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY + basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) + { + return basic_string<char32_t> (__str, __len); + } + } +} +#endif + _LIBCPP_EXTERN_TEMPLATE(class basic_string<char>) _LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>) diff --git a/system/include/libcxx/support/win32/limits_win32.h b/system/include/libcxx/support/win32/limits_win32.h index 671631df..52229c4d 100644 --- a/system/include/libcxx/support/win32/limits_win32.h +++ b/system/include/libcxx/support/win32/limits_win32.h @@ -11,8 +11,8 @@ #ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H #define _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H -#if !defined(_MSC_VER) -#error "This header is MSVC specific, Clang and GCC should not include it" +#if !defined(_LIBCPP_MSVCRT) +#error "This header complements Microsoft's C Runtime library, and should not be included otherwise." #else #ifndef NOMINMAX @@ -74,6 +74,6 @@ #define __builtin_nansf(__dummy) _FSnan._Float #define __builtin_nansl(__dummy) _LSnan._Long_double -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #endif // _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H diff --git a/system/include/libcxx/support/win32/locale_win32.h b/system/include/libcxx/support/win32/locale_win32.h index e035420f..019586c0 100644 --- a/system/include/libcxx/support/win32/locale_win32.h +++ b/system/include/libcxx/support/win32/locale_win32.h @@ -65,8 +65,21 @@ decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) #define strtoull_l _strtoui64_l // FIXME: current msvcrt does not know about long double #define strtold_l _strtod_l -#define islower_l _islower_l -#define isupper_l _isupper_l + +inline _LIBCPP_INLINE_VISIBILITY +int +islower_l(int c, _locale_t loc) +{ + return _islower_l((int)c, loc); +} + +inline _LIBCPP_INLINE_VISIBILITY +int +isupper_l(int c, _locale_t loc) +{ + return _isupper_l((int)c, loc); +} + #define isdigit_l _isdigit_l #define isxdigit_l _isxdigit_l #define strcoll_l _strcoll_l diff --git a/system/include/libcxx/support/win32/math_win32.h b/system/include/libcxx/support/win32/math_win32.h index 41c50d62..22400c0d 100644 --- a/system/include/libcxx/support/win32/math_win32.h +++ b/system/include/libcxx/support/win32/math_win32.h @@ -11,8 +11,8 @@ #ifndef _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H #define _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H -#if !defined(_MSC_VER) -#error "This header is MSVC specific, Clang and GCC should not include it" +#if !defined(_LIBCPP_MSVCRT) +#error "This header complements Microsoft's C Runtime library, and should not be included otherwise." #else #include <math.h> @@ -108,6 +108,6 @@ _LIBCPP_ALWAYS_INLINE int fpclassify( double num ) return _fpclass(num); } -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H diff --git a/system/include/libcxx/support/win32/support.h b/system/include/libcxx/support/win32/support.h index 0b8a912a..17abb915 100644 --- a/system/include/libcxx/support/win32/support.h +++ b/system/include/libcxx/support/win32/support.h @@ -15,26 +15,23 @@ Functions and constants used in libc++ that are missing from the Windows C library. */ -#include <__config> -#include <wchar.h> // mbstate_t -#include <stdio.h> // _snwprintf +#include <cwchar> // mbstate_t +#include <cstdarg> // va_ macros #define swprintf _snwprintf #define vswprintf _vsnwprintf -#define vfscnaf fscanf -int vasprintf( char **sptr, const char *__restrict fmt , va_list ap ); -int asprintf( char **sptr, const char *__restrict fmt, ...); -//int vfscanf( FILE *__restrict stream, const char *__restrict format, -// va_list arg); +extern "C" { +int vasprintf( char **sptr, const char *__restrict fmt, va_list ap ); +int asprintf( char **sptr, const char *__restrict fmt, ...); size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src, size_t nmc, size_t len, mbstate_t *__restrict ps ); size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src, size_t nwc, size_t len, mbstate_t *__restrict ps ); +} -#if defined(_MSC_VER) +#if defined(_LIBCPP_MSVCRT) #define snprintf _snprintf - #include <xlocinfo.h> #define atoll _atoi64 #define strtoll _strtoi64 @@ -85,9 +82,11 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int x ) _BitScanReverse(&r, x); return static_cast<int>(r); } + // sizeof(long) == sizeof(int) on Windows _LIBCPP_ALWAYS_INLINE int __builtin_ctzl( unsigned long x ) { return __builtin_ctz( static_cast<int>(x) ); } + _LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long x ) { DWORD r = 0; @@ -110,6 +109,6 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x ) return static_cast<int>(r); } #endif // !__clang__ -#endif // _MSC_VER +#endif // _LIBCPP_MSVCRT #endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H diff --git a/system/include/libcxx/thread b/system/include/libcxx/thread index 8d3aab2a..f41ea290 100644 --- a/system/include/libcxx/thread +++ b/system/include/libcxx/thread @@ -328,7 +328,7 @@ __thread_specific_ptr<__thread_struct>& __thread_local_data(); template <class _Fp, class ..._Args, size_t ..._Indices> inline _LIBCPP_INLINE_VISIBILITY void -__threaad_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>) +__thread_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>) { __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...); } @@ -340,7 +340,7 @@ __thread_proxy(void* __vp) __thread_local_data().reset(new __thread_struct); std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index; - __threaad_execute(*__p, _Index()); + __thread_execute(*__p, _Index()); return nullptr; } diff --git a/system/include/libcxx/tuple b/system/include/libcxx/tuple index 7f299e9d..94876c91 100644 --- a/system/include/libcxx/tuple +++ b/system/include/libcxx/tuple @@ -21,19 +21,19 @@ template <class... T> class tuple { public: constexpr tuple(); - explicit tuple(const T&...); + explicit tuple(const T&...); // constexpr in C++14 template <class... U> - explicit tuple(U&&...); + explicit tuple(U&&...); // constexpr in C++14 tuple(const tuple&) = default; tuple(tuple&&) = default; template <class... U> - tuple(const tuple<U...>&); + tuple(const tuple<U...>&); // constexpr in C++14 template <class... U> - tuple(tuple<U...>&&); + tuple(tuple<U...>&&); // constexpr in C++14 template <class U1, class U2> - tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 + tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14 template <class U1, class U2> - tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 + tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14 // allocator-extended constructors template <class Alloc> @@ -72,10 +72,10 @@ public: const unspecified ignore; -template <class... T> tuple<V...> make_tuple(T&&...); +template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; template <class... T> tuple<T&...> tie(T&...) noexcept; -template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); +template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 // 20.4.1.4, tuple helper classes: template <class T> class tuple_size; // undefined @@ -86,21 +86,28 @@ template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>; // 20.4.1.5, element access: template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& - get(tuple<T...>&) noexcept; + get(tuple<T...>&) noexcept; // constexpr in C++14 template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& - get(const tuple<T...>&) noexcept; + get(const tuple<T...>&) noexcept; // constexpr in C++14 template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type&& - get(tuple<T...>&&) noexcept; + get(tuple<T...>&&) noexcept; // constexpr in C++14 + +template <class T1, class... T> + constexpr T1& get(tuple<T...>&) noexcept; // C++14 +template <class T1, class... T> + constexpr T1 const& get(const tuple<T...>&) noexcept; // C++14 +template <class T1, class... T> + constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 // 20.4.1.6, relational operators: -template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); -template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); -template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); -template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); -template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); -template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); +template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 +template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 template <class... Types, class Alloc> struct uses_allocator<tuple<Types...>, Alloc>; @@ -259,7 +266,7 @@ public: template <class _Tp, class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) : value(_VSTD::forward<_Tp>(__t)) {static_assert(!is_reference<_Hp>::value || @@ -316,15 +323,17 @@ public: >::value)), "Attempted to construct a reference element in a tuple with an rvalue");} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 __tuple_leaf(const __tuple_leaf& __t) _NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value) : value(__t.get()) {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");} - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY - explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) - _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value)) - : value(__t.get()) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + __tuple_leaf(__tuple_leaf&& __t) _NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value) + : value(_VSTD::move(__t.get())) + {} template <class _Tp> _LIBCPP_INLINE_VISIBILITY @@ -342,8 +351,8 @@ public: return 0; } - _LIBCPP_INLINE_VISIBILITY _Hp& get() _NOEXCEPT {return value;} - _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;} }; template <size_t _Ip, class _Hp> @@ -372,7 +381,7 @@ public: template <class _Tp, class = typename enable_if<is_constructible<_Hp, _Tp>::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) : _Hp(_VSTD::forward<_Tp>(__t)) {} @@ -393,12 +402,6 @@ public: template <class _Tp> _LIBCPP_INLINE_VISIBILITY - explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) - _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value)) - : _Hp(__t.get()) {} - - template <class _Tp> - _LIBCPP_INLINE_VISIBILITY __tuple_leaf& operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) { @@ -414,8 +417,8 @@ public: return 0; } - _LIBCPP_INLINE_VISIBILITY _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} - _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);} }; template <class ..._Tp> @@ -450,7 +453,7 @@ struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> template <size_t ..._Uf, class ..._Tf, size_t ..._Ul, class ..._Tl, class ..._Up> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, __tuple_indices<_Ul...>, __tuple_types<_Tl...>, @@ -477,10 +480,10 @@ struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> template <class _Tuple, class = typename enable_if < - __tuple_convertible<_Tuple, tuple<_Tp...> >::value + __tuple_constructible<_Tuple, tuple<_Tp...> >::value >::type > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) : __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx, @@ -539,11 +542,11 @@ class _LIBCPP_TYPE_VIS tuple base base_; - template <size_t _Jp, class ..._Up> friend + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; - template <size_t _Jp, class ..._Up> friend + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT; - template <size_t _Jp, class ..._Up> friend + template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; public: @@ -551,7 +554,7 @@ public: _LIBCPP_CONSTEXPR tuple() _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), @@ -586,7 +589,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Up&&... __u) _NOEXCEPT_(( is_nothrow_constructible< @@ -626,7 +629,7 @@ public: bool >::type =false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(_Up&&... __u) _NOEXCEPT_(( @@ -674,7 +677,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) : base_(_VSTD::forward<_Tuple>(__t)) {} @@ -686,7 +689,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) : base_(_VSTD::forward<_Tuple>(__t)) {} @@ -756,7 +759,7 @@ swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) // get template <size_t _Ip, class ..._Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type& get(tuple<_Tp...>& __t) _NOEXCEPT { @@ -765,7 +768,7 @@ get(tuple<_Tp...>& __t) _NOEXCEPT } template <size_t _Ip, class ..._Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, tuple<_Tp...> >::type& get(const tuple<_Tp...>& __t) _NOEXCEPT { @@ -774,7 +777,7 @@ get(const tuple<_Tp...>& __t) _NOEXCEPT } template <size_t _Ip, class ..._Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(tuple<_Tp...>&& __t) _NOEXCEPT { @@ -783,6 +786,64 @@ get(tuple<_Tp...>&& __t) _NOEXCEPT static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get()); } +#if _LIBCPP_STD_VER > 11 +// get by type +template <typename _T1, size_t _Idx, typename... _Args> +struct __find_exactly_one_t_helper; + +// -- find exactly one +template <typename _T1, size_t _Idx, typename... _Args> +struct __find_exactly_one_t_checker { + static constexpr size_t value = _Idx; +// Check the rest of the list to make sure there's only one + static_assert ( __find_exactly_one_t_helper<_T1, 0, _Args...>::value == -1, "type can only occur once in type list" ); + }; + + +template <typename _T1, size_t _Idx> +struct __find_exactly_one_t_helper <_T1, _Idx> { + static constexpr size_t value = -1; + }; + +template <typename _T1, size_t _Idx, typename _Head, typename... _Args> +struct __find_exactly_one_t_helper <_T1, _Idx, _Head, _Args...> { + static constexpr size_t value = + std::conditional< + std::is_same<_T1, _Head>::value, + __find_exactly_one_t_checker<_T1, _Idx, Â Â _Args...>, + __find_exactly_one_t_helper <_T1, _Idx+1, _Args...> + >::type::value; + }; + +template <typename _T1, typename... _Args> +struct __find_exactly_one_t { + static constexpr size_t value = __find_exactly_one_t_helper<_T1, 0, _Args...>::value; + static_assert ( value != -1, "type not found in type list" ); + }; + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1& get(tuple<_Args...>& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template <class _T1, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); +} + +#endif + // tie template <class ..._Tp> @@ -824,7 +885,7 @@ struct __make_tuple_return }; template <class... _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple<typename __make_tuple_return<_Tp>::type...> make_tuple(_Tp&&... __t) { @@ -832,6 +893,14 @@ make_tuple(_Tp&&... __t) } template <class... _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&&...> +__forward_as_tuple(_Tp&&... __t) _NOEXCEPT +{ + return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); +} + +template <class... _Tp> inline _LIBCPP_INLINE_VISIBILITY tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) _NOEXCEPT @@ -843,7 +912,7 @@ template <size_t _Ip> struct __tuple_equal { template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp& __x, const _Up& __y) { return __tuple_equal<_Ip - 1>()(__x, __y) && get<_Ip-1>(__x) == get<_Ip-1>(__y); @@ -854,7 +923,7 @@ template <> struct __tuple_equal<0> { template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp&, const _Up&) { return true; @@ -862,7 +931,7 @@ struct __tuple_equal<0> }; template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -870,7 +939,7 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -881,7 +950,7 @@ template <size_t _Ip> struct __tuple_less { template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp& __x, const _Up& __y) { return __tuple_less<_Ip-1>()(__x, __y) || @@ -893,7 +962,7 @@ template <> struct __tuple_less<0> { template <class _Tp, class _Up> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp&, const _Up&) { return false; @@ -901,7 +970,7 @@ struct __tuple_less<0> }; template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -909,7 +978,7 @@ operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -917,7 +986,7 @@ operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -925,7 +994,7 @@ operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template <class ..._Tp, class ..._Up> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -983,7 +1052,7 @@ struct __tuple_cat_return<> typedef tuple<> type; }; -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple<> tuple_cat() { @@ -1030,16 +1099,16 @@ template <class ..._Types, size_t ..._I0, size_t ..._J0> struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > { template <class _Tuple0> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type operator()(tuple<_Types...> __t, _Tuple0&& __t0) { - return _VSTD::forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))..., + return __forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))..., get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); } template <class _Tuple0, class _Tuple1, class ..._Tuples> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) { @@ -1049,7 +1118,7 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type, typename __make_tuple_indices<tuple_size<_T1>::value>::type>() - (_VSTD::forward_as_tuple( + (__forward_as_tuple( _VSTD::forward<_Types>(get<_I0>(__t))..., get<_J0>(_VSTD::forward<_Tuple0>(__t0))... ), @@ -1059,7 +1128,7 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J }; template <class _Tuple0, class... _Tuples> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return<_Tuple0, _Tuples...>::type tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) { diff --git a/system/include/libcxx/type_traits b/system/include/libcxx/type_traits index f60f71b5..99e34d13 100644 --- a/system/include/libcxx/type_traits +++ b/system/include/libcxx/type_traits @@ -129,6 +129,7 @@ namespace std template <class T> struct alignment_of; template <size_t Len, size_t Align = most_stringent_alignment_requirement> struct aligned_storage; + template <size_t Len, class... Types> struct aligned_union; template <class T> struct decay; template <class... T> struct common_type; @@ -136,6 +137,64 @@ namespace std template <class> class result_of; // undefined template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; + // const-volatile modifications: + template <class T> + using remove_const_t = typename remove_const<T>::type; // C++14 + template <class T> + using remove_volatile_t = typename remove_volatile<T>::type; // C++14 + template <class T> + using remove_cv_t = typename remove_cv<T>::type; // C++14 + template <class T> + using add_const_t = typename add_const<T>::type; // C++14 + template <class T> + using add_volatile_t = typename add_volatile<T>::type; // C++14 + template <class T> + using add_cv_t = typename add_cv<T>::type; // C++14 + + // reference modifications: + template <class T> + using remove_reference_t = typename remove_reference<T>::type; // C++14 + template <class T> + using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14 + template <class T> + using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14 + + // sign modifications: + template <class T> + using make_signed_t = typename make_signed<T>::type; // C++14 + template <class T> + using make_unsigned_t = typename make_unsigned<T>::type; // C++14 + + // array modifications: + template <class T> + using remove_extent_t = typename remove_extent<T>::type; // C++14 + template <class T> + using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14 + + // pointer modifications: + template <class T> + using remove_pointer_t = typename remove_pointer<T>::type; // C++14 + template <class T> + using add_pointer_t = typename add_pointer<T>::type; // C++14 + + // other transformations: + template <size_t Len, std::size_t Align=default-alignment> + using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14 + template <std::size_t Len, class... Types> + using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14 + template <class T> + using decay_t = typename decay<T>::type; // C++14 + template <bool b, class T=void> + using enable_if_t = typename enable_if<b,T>::type; // C++14 + template <bool b, class T, class F> + using conditional_t = typename conditional<b,T,F>::type; // C++14 + template <class... T> + using common_type_t = typename common_type<T...>::type; // C++14 + template <class T> + using underlying_type_t = typename underlying_type<T>::type; // C++14 + template <class F, class... ArgTypes> + using result_of_t = typename result_of<F(ArgTypes...)>::type; // C++14 + } // std */ @@ -153,9 +212,18 @@ template <bool _Bp, class _If, class _Then> template <class _If, class _Then> struct _LIBCPP_TYPE_VIS conditional<false, _If, _Then> {typedef _Then type;}; +#if _LIBCPP_STD_VER > 11 +template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type; +#endif + template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS enable_if {}; template <class _Tp> struct _LIBCPP_TYPE_VIS enable_if<true, _Tp> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type; +#endif + + struct __two {char __lx[2];}; // helper class: @@ -168,6 +236,10 @@ struct _LIBCPP_TYPE_VIS integral_constant typedef integral_constant type; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator value_type() const {return value;} +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + constexpr value_type operator ()() const {return value;} +#endif }; template <class _Tp, _Tp __v> @@ -190,16 +262,25 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS is_volatile<_Tp volatile> : public template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const {typedef _Tp type;}; template <class _Tp> struct _LIBCPP_TYPE_VIS remove_const<const _Tp> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type; +#endif // remove_volatile template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile {typedef _Tp type;}; template <class _Tp> struct _LIBCPP_TYPE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type; +#endif // remove_cv template <class _Tp> struct _LIBCPP_TYPE_VIS remove_cv {typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type; +#endif // is_void @@ -445,6 +526,10 @@ struct __add_const<_Tp, false> {typedef const _Tp type;}; template <class _Tp> struct _LIBCPP_TYPE_VIS add_const {typedef typename __add_const<_Tp>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_const_t = typename add_const<_Tp>::type; +#endif + // add_volatile template <class _Tp, bool = is_reference<_Tp>::value || @@ -458,11 +543,19 @@ struct __add_volatile<_Tp, false> {typedef volatile _Tp type;}; template <class _Tp> struct _LIBCPP_TYPE_VIS add_volatile {typedef typename __add_volatile<_Tp>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; +#endif + // add_cv template <class _Tp> struct _LIBCPP_TYPE_VIS add_cv {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type; +#endif + // remove_reference template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference {typedef _Tp type;}; @@ -471,6 +564,10 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&> {typedef _T template <class _Tp> struct _LIBCPP_TYPE_VIS remove_reference<_Tp&&> {typedef _Tp type;}; #endif +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type; +#endif + // add_lvalue_reference template <class _Tp> struct _LIBCPP_TYPE_VIS add_lvalue_reference {typedef _Tp& type;}; @@ -480,6 +577,10 @@ template <> struct _LIBCPP_TYPE_VIS add_lvalue_reference<const void> template <> struct _LIBCPP_TYPE_VIS add_lvalue_reference<volatile void> {typedef volatile void type;}; template <> struct _LIBCPP_TYPE_VIS add_lvalue_reference<const volatile void> {typedef const volatile void type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; +#endif + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> struct _LIBCPP_TYPE_VIS add_rvalue_reference {typedef _Tp&& type;}; @@ -488,6 +589,10 @@ template <> struct _LIBCPP_TYPE_VIS add_rvalue_reference<const void> template <> struct _LIBCPP_TYPE_VIS add_rvalue_reference<volatile void> {typedef volatile void type;}; template <> struct _LIBCPP_TYPE_VIS add_rvalue_reference<const volatile void> {typedef const volatile void type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; +#endif + #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -517,11 +622,19 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const> template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* volatile> {typedef _Tp type;}; template <class _Tp> struct _LIBCPP_TYPE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type; +#endif + // add_pointer template <class _Tp> struct _LIBCPP_TYPE_VIS add_pointer {typedef typename remove_reference<_Tp>::type* type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type; +#endif + // is_signed template <class _Tp, bool = is_integral<_Tp>::value> @@ -583,6 +696,10 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[]> template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_extent<_Tp[_Np]> {typedef _Tp type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type; +#endif + // remove_all_extents template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents @@ -592,6 +709,10 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[]> template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS remove_all_extents<_Tp[_Np]> {typedef typename remove_all_extents<_Tp>::type type;}; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type; +#endif + // is_abstract namespace __is_abstract_imp @@ -609,7 +730,7 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS is_abstract : public __libcpp_abstr // is_base_of -#ifdef _LIBCP_HAS_IS_BASE_OF +#ifdef _LIBCPP_HAS_IS_BASE_OF template <class _Bp, class _Dp> struct _LIBCPP_TYPE_VIS is_base_of @@ -802,17 +923,13 @@ struct _LIBCPP_TYPE_VIS is_polymorphic #else -template <class _Tp> struct __is_polymorphic1 : public _Tp {}; -template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();}; - -template <class _Tp, bool = is_class<_Tp>::value> -struct __libcpp_polymorphic - : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {}; - -template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {}; +template<typename _Tp> char &__is_polymorphic_impl( + typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0, + int>::type); +template<typename _Tp> __two &__is_polymorphic_impl(...); template <class _Tp> struct _LIBCPP_TYPE_VIS is_polymorphic - : public __libcpp_polymorphic<_Tp> {}; + : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {}; #endif // __has_feature(is_polymorphic) @@ -832,10 +949,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor // alignment_of -template <class _Tp> struct __alignment_of {_Tp __lx;}; - template <class _Tp> struct _LIBCPP_TYPE_VIS alignment_of - : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {}; + : public integral_constant<size_t, __alignof__(_Tp)> {}; // aligned_storage @@ -921,7 +1036,7 @@ template <class _Hp, class _Tp, size_t _Len> struct __find_max_align<__type_list<_Hp, _Tp>, _Len> : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {}; -template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value> +template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value> struct _LIBCPP_TYPE_VIS aligned_storage { typedef typename __find_pod<__all_types, _Align>::type _Aligner; @@ -933,6 +1048,11 @@ struct _LIBCPP_TYPE_VIS aligned_storage }; }; +#if _LIBCPP_STD_VER > 11 +template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value> + using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; +#endif + #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \ template <size_t _Len>\ struct _LIBCPP_TYPE_VIS aligned_storage<_Len, n>\ @@ -958,12 +1078,48 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000); // MSDN says that MSVC does not support alignment beyond 8192 (=0x2000) -#if !defined(_MSC_VER) +#if !defined(_LIBCPP_MSVC) _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); -#endif // !_MSC_VER +#endif // !_LIBCPP_MSVC #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION +#ifndef _LIBCPP_HAS_NO_VARIADICS + +// aligned_union + +template <size_t _I0, size_t ..._In> +struct __static_max; + +template <size_t _I0> +struct __static_max<_I0> +{ + static const size_t value = _I0; +}; + +template <size_t _I0, size_t _I1, size_t ..._In> +struct __static_max<_I0, _I1, _In...> +{ + static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value : + __static_max<_I1, _In...>::value; +}; + +template <size_t _Len, class _Type0, class ..._Types> +struct aligned_union +{ + static const size_t alignment_value = __static_max<__alignof__(_Type0), + __alignof__(_Types)...>::value; + static const size_t __len = __static_max<_Len, sizeof(_Type0), + sizeof(_Types)...>::value; + typedef typename aligned_storage<__len, alignment_value>::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type; +#endif + +#endif // _LIBCPP_HAS_NO_VARIADICS + // __promote template <class _A1, class _A2 = void, class _A3 = void, @@ -1123,6 +1279,10 @@ struct _LIBCPP_TYPE_VIS make_signed typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type; }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type; +#endif + template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> struct __make_unsigned {}; @@ -1148,6 +1308,10 @@ struct _LIBCPP_TYPE_VIS make_unsigned typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type; }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type; +#endif + #ifdef _LIBCPP_HAS_NO_VARIADICS template <class _Tp, class _Up = void, class V = void> @@ -1206,6 +1370,10 @@ struct _LIBCPP_TYPE_VIS common_type<_Tp, _Up, _Vp...> typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type; }; +#if _LIBCPP_STD_VER > 11 +template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type; +#endif + #endif // _LIBCPP_HAS_NO_VARIADICS // is_assignable @@ -1298,7 +1466,7 @@ struct is_destructible #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename remove_reference<_Tp>::type&& move(_Tp&& __t) _NOEXCEPT { @@ -1307,7 +1475,7 @@ move(_Tp&& __t) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT { @@ -1315,7 +1483,7 @@ forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT { @@ -1384,6 +1552,10 @@ public: >::type type; }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using decay_t = typename decay<_Tp>::type; +#endif + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> @@ -1626,7 +1798,7 @@ struct __member_pointer_traits_imp<_Rp _Class::*, false, true> template <class _MP> struct __member_pointer_traits - : public __member_pointer_traits_imp<_MP, + : public __member_pointer_traits_imp<typename remove_cv<_MP>::type, is_member_function_pointer<_MP>::value, is_member_object_pointer<_MP>::value> { @@ -2851,13 +3023,27 @@ __invoke(__any, _Args&& ...__args) // bullets 1 and 2 -template <class _Fp, class _A0, class ..._Args> +template <class _Fp, class _A0, class ..._Args, + class = typename enable_if + < + is_member_function_pointer<typename remove_reference<_Fp>::type>::value && + is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType, + typename remove_reference<_A0>::type>::value + >::type + > _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)); -template <class _Fp, class _A0, class ..._Args> +template <class _Fp, class _A0, class ..._Args, + class = typename enable_if + < + is_member_function_pointer<typename remove_reference<_Fp>::type>::value && + !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType, + typename remove_reference<_A0>::type>::value + >::type + > _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) @@ -2865,13 +3051,27 @@ __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) // bullets 3 and 4 -template <class _Fp, class _A0> +template <class _Fp, class _A0, + class = typename enable_if + < + is_member_object_pointer<typename remove_reference<_Fp>::type>::value && + is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType, + typename remove_reference<_A0>::type>::value + >::type + > _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) -> decltype(_VSTD::forward<_A0>(__a0).*__f); -template <class _Fp, class _A0> +template <class _Fp, class _A0, + class = typename enable_if + < + is_member_object_pointer<typename remove_reference<_Fp>::type>::value && + !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType, + typename remove_reference<_A0>::type>::value + >::type + > _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) @@ -2929,6 +3129,10 @@ class _LIBCPP_TYPE_VIS result_of<_Fp(_Args...)> { }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using result_of_t = typename result_of<_Tp>::type; +#endif + #endif // _LIBCPP_HAS_NO_VARIADICS template <class _Tp> @@ -3023,6 +3227,10 @@ struct underlying_type typedef _LIBCXX_UNDERLYING_TYPE(_Tp) type; }; +#if _LIBCPP_STD_VER > 11 +template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type; +#endif + #else // _LIBCXX_UNDERLYING_TYPE template <class _Tp, bool _Support = false> diff --git a/system/include/libcxx/unordered_map b/system/include/libcxx/unordered_map index 235b2eab..eebf2f5e 100644 --- a/system/include/libcxx/unordered_map +++ b/system/include/libcxx/unordered_map @@ -325,7 +325,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc> _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value +template <class _Key, class _Cp, class _Hash, bool = is_empty<_Hash>::value #if __has_feature(is_final) && !__is_final(_Hash) #endif @@ -333,8 +333,6 @@ template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value class __unordered_map_hasher : private _Hash { - typedef pair<typename remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _Cp; public: _LIBCPP_INLINE_VISIBILITY __unordered_map_hasher() @@ -347,23 +345,18 @@ public: _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY - size_t operator()(const _Pp& __x) const - {return static_cast<const _Hash&>(*this)(__x.first);} - _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Cp& __x) const - {return static_cast<const _Hash&>(*this)(__x.first);} + {return static_cast<const _Hash&>(*this)(__x.__cc.first);} _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Key& __x) const {return static_cast<const _Hash&>(*this)(__x);} }; -template <class _Key, class _Tp, class _Hash> -class __unordered_map_hasher<_Key, _Tp, _Hash, false> +template <class _Key, class _Cp, class _Hash> +class __unordered_map_hasher<_Key, _Cp, _Hash, false> { _Hash __hash_; - typedef pair<typename remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _Cp; public: _LIBCPP_INLINE_VISIBILITY __unordered_map_hasher() @@ -376,17 +369,14 @@ public: _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const _NOEXCEPT {return __hash_;} _LIBCPP_INLINE_VISIBILITY - size_t operator()(const _Pp& __x) const - {return __hash_(__x.first);} - _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Cp& __x) const - {return __hash_(__x.first);} + {return __hash_(__x.__cc.first);} _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Key& __x) const {return __hash_(__x);} }; -template <class _Key, class _Tp, class _Pred, bool = is_empty<_Pred>::value +template <class _Key, class _Cp, class _Pred, bool = is_empty<_Pred>::value #if __has_feature(is_final) && !__is_final(_Pred) #endif @@ -394,8 +384,6 @@ template <class _Key, class _Tp, class _Pred, bool = is_empty<_Pred>::value class __unordered_map_equal : private _Pred { - typedef pair<typename remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _Cp; public: _LIBCPP_INLINE_VISIBILITY __unordered_map_equal() @@ -408,41 +396,21 @@ public: _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Pp& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Cp& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Key& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Cp& __x, const _Pp& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY bool operator()(const _Cp& __x, const _Cp& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} + {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Cp& __x, const _Key& __y) const - {return static_cast<const _Pred&>(*this)(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Pp& __y) const - {return static_cast<const _Pred&>(*this)(__x, __y.first);} + {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _Cp& __y) const - {return static_cast<const _Pred&>(*this)(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Key& __y) const - {return static_cast<const _Pred&>(*this)(__x, __y);} + {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);} }; -template <class _Key, class _Tp, class _Pred> -class __unordered_map_equal<_Key, _Tp, _Pred, false> +template <class _Key, class _Cp, class _Pred> +class __unordered_map_equal<_Key, _Cp, _Pred, false> { _Pred __pred_; - typedef pair<typename remove_const<_Key>::type, _Tp> _Pp; - typedef pair<const _Key, _Tp> _Cp; public: _LIBCPP_INLINE_VISIBILITY __unordered_map_equal() @@ -455,32 +423,14 @@ public: _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const _NOEXCEPT {return __pred_;} _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Pp& __y) const - {return __pred_(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Cp& __y) const - {return __pred_(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Pp& __x, const _Key& __y) const - {return __pred_(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Cp& __x, const _Pp& __y) const - {return __pred_(__x.first, __y.first);} - _LIBCPP_INLINE_VISIBILITY bool operator()(const _Cp& __x, const _Cp& __y) const - {return __pred_(__x.first, __y.first);} + {return __pred_(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Cp& __x, const _Key& __y) const - {return __pred_(__x.first, __y);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Pp& __y) const - {return __pred_(__x, __y.first);} + {return __pred_(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _Cp& __y) const - {return __pred_(__x, __y.first);} - _LIBCPP_INLINE_VISIBILITY - bool operator()(const _Key& __x, const _Key& __y) const - {return __pred_(__x, __y);} + {return __pred_(__x, __y.__cc.first);} }; template <class _Alloc> @@ -492,8 +442,8 @@ class __hash_map_node_destructor public: typedef typename __alloc_traits::pointer pointer; private: - typedef typename value_type::first_type first_type; - typedef typename value_type::second_type second_type; + typedef typename value_type::value_type::first_type first_type; + typedef typename value_type::value_type::second_type second_type; allocator_type& __na_; @@ -535,9 +485,9 @@ public: void operator()(pointer __p) _NOEXCEPT { if (__second_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); if (__first_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } @@ -549,8 +499,8 @@ class _LIBCPP_TYPE_VIS __hash_map_iterator _HashIterator __i_; typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; - typedef const typename _HashIterator::value_type::first_type key_type; - typedef typename _HashIterator::value_type::second_type mapped_type; + typedef const typename _HashIterator::value_type::value_type::first_type key_type; + typedef typename _HashIterator::value_type::value_type::second_type mapped_type; public: typedef forward_iterator_tag iterator_category; typedef pair<key_type, mapped_type> value_type; @@ -571,9 +521,9 @@ public: __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} @@ -605,8 +555,8 @@ class _LIBCPP_TYPE_VIS __hash_map_const_iterator _HashIterator __i_; typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; - typedef const typename _HashIterator::value_type::first_type key_type; - typedef typename _HashIterator::value_type::second_type mapped_type; + typedef const typename _HashIterator::value_type::value_type::first_type key_type; + typedef typename _HashIterator::value_type::value_type::second_type mapped_type; public: typedef forward_iterator_tag iterator_category; typedef pair<key_type, mapped_type> value_type; @@ -632,9 +582,9 @@ public: : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator& operator++() {++__i_; return *this;} @@ -671,13 +621,58 @@ public: typedef _Pred key_equal; typedef _Alloc allocator_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef value_type& reference; typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); private: - typedef pair<key_type, mapped_type> __value_type; - typedef __unordered_map_hasher<key_type, mapped_type, hasher> __hasher; - typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal; +#if __cplusplus >= 201103L + union __value_type + { + typedef typename unordered_map::value_type value_type; + typedef typename unordered_map::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + }; +#else + struct __value_type + { + typedef typename unordered_map::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + }; +#endif + typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; + typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__value_type> @@ -713,7 +708,11 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) - {} // = default; + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } explicit unordered_map(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); unordered_map(size_type __n, const hasher& __hf, @@ -750,7 +749,16 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(const unordered_map& __u) { +#if __cplusplus >= 201103L __table_ = __u.__table_; +#else + __table_.clear(); + __table_.hash_function() = __u.__table_.hash_function(); + __table_.key_eq() = __u.__table_.key_eq(); + __table_.max_load_factor() = __u.__table_.max_load_factor(); + __table_.__copy_assign_alloc(__u.__table_); + insert(__u.begin(), __u.end()); +#endif return *this; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -793,8 +801,18 @@ public: template <class... _Args> _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator emplace_hint(const_iterator __p, _Args&&... __args) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered_map"); + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; + } +#else iterator emplace_hint(const_iterator, _Args&&... __args) {return emplace(_VSTD::forward<_Args>(__args)...).first;} +#endif #endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY @@ -808,14 +826,34 @@ public: {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, const value_type& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_map"); + return insert(__x).first; + } +#else iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} +#endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Pp, class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, _Pp&& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" + " referring to this unordered_map"); + return insert(_VSTD::forward<_Pp>(__x)).first; + } +#else iterator insert(const_iterator, _Pp&& __x) {return insert(_VSTD::forward<_Pp>(__x)).first;} +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _InputIterator> void insert(_InputIterator __first, _InputIterator __last); @@ -903,30 +941,32 @@ public: _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) {__table_.reserve(__n);} +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(&__i->__i_);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(&__i->__i_);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); template <class _A0> - typename enable_if - < - is_constructible<value_type, _A0>::value, - __node_holder - >::type - __construct_node(_A0&& __a0); - template <class _A0> - typename enable_if - < - is_constructible<key_type, _A0>::value, - __node_holder - >::type + __node_holder __construct_node(_A0&& __a0); + __node_holder __construct_node_with_key(key_type&& __k); #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _A0, class _A1, class ..._Args> __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - __node_holder __construct_node(const key_type& __k); -#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + __node_holder __construct_node_with_key(const key_type& __k); }; template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> @@ -934,6 +974,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -943,6 +986,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -952,6 +998,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const allocator_type& __a) : __table_(__a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> @@ -959,6 +1008,9 @@ template <class _InputIterator> unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( _InputIterator __first, _InputIterator __last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__first, __last); } @@ -969,6 +1021,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -980,6 +1035,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -989,6 +1047,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const unordered_map& __u) : __table_(__u.__table_) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -998,6 +1059,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const unordered_map& __u, const allocator_type& __a) : __table_(__u.__table_, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -1011,6 +1075,10 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) : __table_(_VSTD::move(__u.__table_)) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> @@ -1018,6 +1086,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( unordered_map&& __u, const allocator_type& __a) : __table_(_VSTD::move(__u.__table_), __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif if (__a != __u.get_allocator()) { iterator __i = __u.begin(); @@ -1026,6 +1097,10 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) ); } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1036,6 +1111,9 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( initializer_list<value_type> __il) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__il.begin(), __il.end()); } @@ -1045,6 +1123,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -1055,6 +1136,9 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -1105,11 +1189,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node() template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> template <class _A0> -typename enable_if -< - is_constructible<pair<const _Key, _Tp>, _A0>::value, - typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder ->::type +typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) { __node_allocator& __na = __table_.__node_alloc(); @@ -1122,22 +1202,16 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> -template <class _A0> -typename enable_if -< - is_constructible<_Key, _A0>::value, - typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder ->::type -unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) +typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k) { __node_allocator& __na = __table_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), - _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; - return __h; + return _VSTD::move(__h); } #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -1172,23 +1246,21 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args) } #endif // _LIBCPP_HAS_NO_VARIADICS -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder -unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) +unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) { __node_allocator& __na = __table_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return _VSTD::move(__h); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> template <class _InputIterator> inline _LIBCPP_INLINE_VISIBILITY @@ -1207,7 +1279,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) iterator __i = find(__k); if (__i != end()) return __i->second; - __node_holder __h = __construct_node(__k); + __node_holder __h = __construct_node_with_key(__k); pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); __h.release(); return __r.first->second; @@ -1222,7 +1294,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) iterator __i = find(__k); if (__i != end()) return __i->second; - __node_holder __h = __construct_node(_VSTD::move(__k)); + __node_holder __h = __construct_node_with_key(_VSTD::move(__k)); pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); __h.release(); return __r.first->second; @@ -1304,13 +1376,58 @@ public: typedef _Pred key_equal; typedef _Alloc allocator_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef value_type& reference; typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); private: - typedef pair<key_type, mapped_type> __value_type; - typedef __unordered_map_hasher<key_type, mapped_type, hasher> __hasher; - typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal; +#if __cplusplus >= 201103L + union __value_type + { + typedef typename unordered_multimap::value_type value_type; + typedef typename unordered_multimap::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + }; +#else + struct __value_type + { + typedef typename unordered_multimap::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + }; +#endif + typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; + typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__value_type> @@ -1344,7 +1461,11 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_multimap() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) - {} // = default; + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); unordered_multimap(size_type __n, const hasher& __hf, @@ -1382,7 +1503,16 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(const unordered_multimap& __u) { +#if __cplusplus >= 201103L __table_ = __u.__table_; +#else + __table_.clear(); + __table_.hash_function() = __u.__table_.hash_function(); + __table_.key_eq() = __u.__table_.key_eq(); + __table_.max_load_factor() = __u.__table_.max_load_factor(); + __table_.__copy_assign_alloc(__u.__table_); + insert(__u.begin(), __u.end()); +#endif return *this; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1525,22 +1655,24 @@ public: _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) {__table_.reserve(__n);} +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(&__i->__i_);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(&__i->__i_);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(&__i->__i_, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); template <class _A0> - typename enable_if - < - is_constructible<value_type, _A0>::value, - __node_holder - >::type - __construct_node(_A0&& __a0); - template <class _A0> - typename enable_if - < - is_constructible<key_type, _A0>::value, - __node_holder - >::type + __node_holder __construct_node(_A0&& __a0); #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _A0, class _A1, class ..._Args> @@ -1554,6 +1686,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -1563,6 +1698,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -1571,6 +1709,9 @@ template <class _InputIterator> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( _InputIterator __first, _InputIterator __last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__first, __last); } @@ -1581,6 +1722,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -1592,6 +1736,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -1602,6 +1749,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const allocator_type& __a) : __table_(__a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> @@ -1609,6 +1759,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const unordered_multimap& __u) : __table_(__u.__table_) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -1618,6 +1771,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const unordered_multimap& __u, const allocator_type& __a) : __table_(__u.__table_, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -1631,6 +1787,10 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) : __table_(_VSTD::move(__u.__table_)) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> @@ -1638,16 +1798,23 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( unordered_multimap&& __u, const allocator_type& __a) : __table_(_VSTD::move(__u.__table_), __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif if (__a != __u.get_allocator()) { iterator __i = __u.begin(); while (__u.size() != 0) -{ + { __table_.__insert_multi( _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) ); -} + } } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1658,6 +1825,9 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( initializer_list<value_type> __il) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__il.begin(), __il.end()); } @@ -1667,6 +1837,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -1677,6 +1850,9 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -1727,11 +1903,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node() template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> template <class _A0> -typename enable_if -< - is_constructible<pair<const _Key, _Tp>, _A0>::value, - typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder ->::type +typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) { __node_allocator& __na = __table_.__node_alloc(); @@ -1743,25 +1915,6 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0 return __h; } -template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> -template <class _A0> -typename enable_if -< - is_constructible<_Key, _A0>::value, - typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder ->::type -unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) -{ - __node_allocator& __na = __table_.__node_alloc(); - __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), - _VSTD::forward<_A0>(__a0)); - __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); - __h.get_deleter().__second_constructed = true; - return __h; -} - #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> diff --git a/system/include/libcxx/unordered_set b/system/include/libcxx/unordered_set index 119251dc..8be36df6 100644 --- a/system/include/libcxx/unordered_set +++ b/system/include/libcxx/unordered_set @@ -324,6 +324,8 @@ public: typedef _Alloc allocator_type; typedef value_type& reference; typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); private: typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; @@ -344,7 +346,11 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_set() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) - {} // = default; + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } explicit unordered_set(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, @@ -422,8 +428,18 @@ public: {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);} template <class... _Args> _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator emplace_hint(const_iterator __p, _Args&&... __args) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not" + " referring to this unordered_set"); + return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; + } +#else iterator emplace_hint(const_iterator, _Args&&... __args) {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;} +#endif #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> insert(const value_type& __x) @@ -434,12 +450,32 @@ public: {return __table_.__insert_unique(_VSTD::move(__x));} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, const value_type& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" + " referring to this unordered_set"); + return insert(__x).first; + } +#else iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} +#endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY +#if _LIBCPP_DEBUG_LEVEL >= 2 + iterator insert(const_iterator __p, value_type&& __x) + { + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" + " referring to this unordered_set"); + return insert(_VSTD::move(__x)).first; + } +#else iterator insert(const_iterator, value_type&& __x) {return insert(_VSTD::move(__x)).first;} +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _InputIterator> void insert(_InputIterator __first, _InputIterator __last); @@ -515,6 +551,20 @@ public: void rehash(size_type __n) {__table_.rehash(__n);} _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(__i);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(__i);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + }; template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -522,6 +572,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -530,6 +583,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -538,6 +594,9 @@ template <class _InputIterator> unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( _InputIterator __first, _InputIterator __last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__first, __last); } @@ -548,6 +607,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -559,6 +621,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -569,6 +634,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const allocator_type& __a) : __table_(__a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif } template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -576,6 +644,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const unordered_set& __u) : __table_(__u.__table_) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -585,6 +656,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const unordered_set& __u, const allocator_type& __a) : __table_(__u.__table_, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -598,6 +672,10 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) : __table_(_VSTD::move(__u.__table_)) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif } template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -605,12 +683,19 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( unordered_set&& __u, const allocator_type& __a) : __table_(_VSTD::move(__u.__table_), __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif if (__a != __u.get_allocator()) { iterator __i = __u.begin(); while (__u.size() != 0) __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -621,6 +706,9 @@ template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( initializer_list<value_type> __il) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__il.begin(), __il.end()); } @@ -630,6 +718,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -640,6 +731,9 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -736,6 +830,8 @@ public: typedef _Alloc allocator_type; typedef value_type& reference; typedef const value_type& const_reference; + static_assert((is_same<value_type, typename allocator_type::value_type>::value), + "Invalid allocator::value_type"); private: typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; @@ -756,7 +852,11 @@ public: _LIBCPP_INLINE_VISIBILITY unordered_multiset() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) - {} // = default + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); unordered_multiset(size_type __n, const hasher& __hf, @@ -925,6 +1025,20 @@ public: void rehash(size_type __n) {__table_.rehash(__n);} _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) {__table_.reserve(__n);} + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const + {return __table_.__dereferenceable(__i);} + bool __decrementable(const const_iterator* __i) const + {return __table_.__decrementable(__i);} + bool __addable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const + {return __table_.__addable(__i, __n);} + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + }; template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -932,6 +1046,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( size_type __n, const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -941,6 +1058,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); } @@ -949,6 +1069,9 @@ template <class _InputIterator> unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( _InputIterator __first, _InputIterator __last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__first, __last); } @@ -959,6 +1082,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const hasher& __hf, const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -970,6 +1096,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__first, __last); } @@ -980,6 +1109,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const allocator_type& __a) : __table_(__a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif } template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -987,6 +1119,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const unordered_multiset& __u) : __table_(__u.__table_) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -996,6 +1131,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const unordered_multiset& __u, const allocator_type& __a) : __table_(__u.__table_, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__u.bucket_count()); insert(__u.begin(), __u.end()); } @@ -1009,6 +1147,10 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) : __table_(_VSTD::move(__u.__table_)) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); + __get_db()->swap(this, &__u); +#endif } template <class _Value, class _Hash, class _Pred, class _Alloc> @@ -1016,12 +1158,19 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( unordered_multiset&& __u, const allocator_type& __a) : __table_(_VSTD::move(__u.__table_), __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif if (__a != __u.get_allocator()) { iterator __i = __u.begin(); while (__u.size() != 0) __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); } +#if _LIBCPP_DEBUG_LEVEL >= 2 + else + __get_db()->swap(this, &__u); +#endif } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1032,6 +1181,9 @@ template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( initializer_list<value_type> __il) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif insert(__il.begin(), __il.end()); } @@ -1041,6 +1193,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const key_equal& __eql) : __table_(__hf, __eql) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } @@ -1051,6 +1206,9 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( const key_equal& __eql, const allocator_type& __a) : __table_(__hf, __eql, __a) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif __table_.rehash(__n); insert(__il.begin(), __il.end()); } 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 diff --git a/system/include/libcxx/vector b/system/include/libcxx/vector index d1bc23e6..0758f75b 100644 --- a/system/include/libcxx/vector +++ b/system/include/libcxx/vector @@ -272,6 +272,12 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) #include <__undef_min_max> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -309,14 +315,14 @@ __vector_base_common<__b>::__throw_out_of_range() const #endif } -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( push ) #pragma warning( disable: 4231 ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(class __vector_base_common<true>) -#ifdef _MSC_VER +#ifdef _LIBCPP_MSVC #pragma warning( pop ) -#endif // _MSC_VER +#endif // _LIBCPP_MSVC template <class _Tp, class _Allocator> class __vector_base @@ -365,12 +371,7 @@ protected: {return static_cast<size_type>(__end_cap() - __begin_);} _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT - {__destruct_at_end(__new_last, false_type());} - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT; + void __destruct_at_end(pointer __new_last) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base& __c) @@ -437,43 +438,35 @@ private: template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT +__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_)); -} - -template <class _Tp, class _Allocator> -_LIBCPP_INLINE_VISIBILITY inline -void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT -{ - __end_ = const_cast<pointer>(__new_last); + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) - : __begin_(0), - __end_(0), - __end_cap_(0) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr) { } template <class _Tp, class _Allocator> _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) - : __begin_(0), - __end_(0), - __end_cap_(0, __a) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr, __a) { } template <class _Tp, class _Allocator> __vector_base<_Tp, _Allocator>::~__vector_base() { - if (__begin_ != 0) + if (__begin_ != nullptr) { clear(); __alloc_traits::deallocate(__alloc(), __begin_, capacity()); @@ -797,7 +790,7 @@ private: _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); void __move_assign(vector& __c, false_type); _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT + void __destruct_at_end(pointer __new_last) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); @@ -878,11 +871,11 @@ template <class _Tp, class _Allocator> void vector<_Tp, _Allocator>::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { clear(); __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); - this->__begin_ = this->__end_ = this->__end_cap() = 0; + this->__begin_ = this->__end_ = this->__end_cap() = nullptr; } } @@ -1171,7 +1164,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x) this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); - __x.__begin_ = __x.__end_ = __x.__end_cap() = 0; + __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; } template <class _Tp, class _Allocator> @@ -1597,7 +1590,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __position) #endif _LIBCPP_ASSERT(__position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator"); - pointer __p = const_cast<pointer>(&*__position); + difference_type __ps = __position - cbegin(); + pointer __p = this->__begin_ + __ps; iterator __r = __make_iter(__p); this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); return __r; @@ -1615,7 +1609,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); pointer __p = this->__begin_ + (__first - begin()); iterator __r = __make_iter(__p); - this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); + if (__first != __last) + this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); return __r; } @@ -1942,9 +1937,9 @@ template <class _Tp, class _Allocator> bool vector<_Tp, _Allocator>::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { - if (this->__end_ != 0 || this->__end_cap() != 0) + if (this->__end_ != nullptr || this->__end_cap() != nullptr) return false; } else @@ -2306,7 +2301,7 @@ private: {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT - {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);} + {return begin() + (__p - cbegin());} #endif // _LIBCPP_DEBUG _LIBCPP_INLINE_VISIBILITY @@ -2413,11 +2408,11 @@ template <class _Allocator> void vector<bool, _Allocator>::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); __invalidate_all_iterators(); - this->__begin_ = 0; + this->__begin_ = nullptr; this->__size_ = this->__cap() = 0; } } @@ -2480,7 +2475,7 @@ template <class _Allocator> _LIBCPP_INLINE_VISIBILITY inline vector<bool, _Allocator>::vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2489,7 +2484,7 @@ vector<bool, _Allocator>::vector() template <class _Allocator> _LIBCPP_INLINE_VISIBILITY inline vector<bool, _Allocator>::vector(const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2497,7 +2492,7 @@ vector<bool, _Allocator>::vector(const allocator_type& __a) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2510,7 +2505,7 @@ vector<bool, _Allocator>::vector(size_type __n) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2523,7 +2518,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) template <class _Allocator> vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2539,7 +2534,7 @@ template <class _InputIterator> vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2553,7 +2548,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2566,7 +2561,7 @@ template <class _InputIterator> vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2580,7 +2575,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2592,7 +2587,7 @@ template <class _Allocator> template <class _ForwardIterator> vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2608,7 +2603,7 @@ template <class _Allocator> template <class _ForwardIterator> vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2624,7 +2619,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la template <class _Allocator> vector<bool, _Allocator>::vector(initializer_list<value_type> __il) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2638,7 +2633,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il) template <class _Allocator> vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2655,7 +2650,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca template <class _Allocator> vector<bool, _Allocator>::~vector() { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); #ifdef _LIBCPP_DEBUG __invalidate_all_iterators(); @@ -2664,7 +2659,7 @@ vector<bool, _Allocator>::~vector() template <class _Allocator> vector<bool, _Allocator>::vector(const vector& __v) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { @@ -2677,7 +2672,7 @@ vector<bool, _Allocator>::vector(const vector& __v) template <class _Allocator> vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -2719,14 +2714,14 @@ vector<bool, _Allocator>::vector(vector&& __v) __size_(__v.__size_), __cap_alloc_(__v.__cap_alloc_) { - __v.__begin_ = 0; + __v.__begin_ = nullptr; __v.__size_ = 0; __v.__cap() = 0; } template <class _Allocator> vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -3122,7 +3117,7 @@ template <class _Allocator> bool vector<bool, _Allocator>::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { if (this->__size_ != 0 || this->__cap() != 0) return false; |