diff options
author | theraven <theraven@FreeBSD.org> | 2013-07-10 16:28:24 +0000 |
---|---|---|
committer | theraven <theraven@FreeBSD.org> | 2013-07-10 16:28:24 +0000 |
commit | 214e4f8fe625ad54aac3b215909e0b994a5768ec (patch) | |
tree | f757844d307e5ebbf92ab857f2376cceb7807147 /contrib/libc++ | |
parent | c660176671bf640bee3fd09dbfa32ad187a9b942 (diff) | |
download | FreeBSD-src-214e4f8fe625ad54aac3b215909e0b994a5768ec.zip FreeBSD-src-214e4f8fe625ad54aac3b215909e0b994a5768ec.tar.gz |
Import new libcxxrt / libc++. This brings some bug fixes, including a potential race condition for static initialisers.
Diffstat (limited to 'contrib/libc++')
34 files changed, 2246 insertions, 1502 deletions
diff --git a/contrib/libc++/include/__bit_reference b/contrib/libc++/include/__bit_reference index 1621deb..8ff3bf6 100644 --- a/contrib/libc++/include/__bit_reference +++ b/contrib/libc++/include/__bit_reference @@ -333,7 +333,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 +363,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 +430,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 +571,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 +874,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 +885,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> diff --git a/contrib/libc++/include/__config b/contrib/libc++/include/__config index 959390d..ca850d3 100644 --- a/contrib/libc++/include/__config +++ b/contrib/libc++/include/__config @@ -56,6 +56,18 @@ # 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 @@ -135,6 +147,10 @@ #endif // _WIN32 +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif + #ifndef _LIBCPP_HIDDEN #define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) #endif @@ -212,7 +228,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 @@ -272,9 +290,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)) @@ -418,8 +446,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 +485,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,6 +510,14 @@ template <unsigned> struct __static_assert_check {}; # endif #endif +#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 + #ifdef _LIBCPP_DEBUG2 # include <__debug> #else diff --git a/contrib/libc++/include/__functional_base b/contrib/libc++/include/__functional_base index 40a63a8..5b0d720 100644 --- a/contrib/libc++/include/__functional_base +++ b/contrib/libc++/include/__functional_base @@ -292,7 +292,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 +302,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 +314,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 +324,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/contrib/libc++/include/__hash_table b/contrib/libc++/include/__hash_table index 6f6050d..2b282d3 100644 --- a/contrib/libc++/include/__hash_table +++ b/contrib/libc++/include/__hash_table @@ -33,7 +33,6 @@ template <class _NodePtr> struct __hash_node_base { typedef __hash_node_base __first_node; - // typedef _NodePtr pointer; _NodePtr __next_; @@ -111,7 +110,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __node_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);} _LIBCPP_INLINE_VISIBILITY __hash_iterator& operator++() @@ -189,7 +188,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __node_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return _VSTD::addressof(__node_->__value_);} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);} _LIBCPP_INLINE_VISIBILITY __hash_const_iterator& operator++() @@ -255,7 +254,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __node_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__node_->__value_;} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);} _LIBCPP_INLINE_VISIBILITY __hash_local_iterator& operator++() @@ -345,7 +344,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __node_->__value_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__node_->__value_;} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__node_->__value_);} _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator& operator++() @@ -505,8 +504,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 +564,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_( @@ -706,7 +712,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 { @@ -807,6 +813,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 +902,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 +926,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; } @@ -1014,7 +1023,7 @@ __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; } @@ -1236,7 +1245,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_ @@ -1274,7 +1283,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_ @@ -1322,7 +1331,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( { 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) @@ -1380,7 +1389,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_ @@ -1542,7 +1551,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) { @@ -1700,7 +1709,7 @@ 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_; iterator __r(__np); ++__r; remove(__p); @@ -1717,7 +1726,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, ++__first; erase(__p); } - __node_pointer __np = const_cast<__node_pointer>(__last.__node_); + __node_pointer __np = __last.__node_; return iterator (__np); } @@ -1757,7 +1766,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 +1776,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; @@ -1907,10 +1917,10 @@ __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())); } template <class _Tp, class _Hash, class _Equal, class _Alloc> diff --git a/contrib/libc++/include/__locale b/contrib/libc++/include/__locale index 24d565b..92f4e0c 100644 --- a/contrib/libc++/include/__locale +++ b/contrib/libc++/include/__locale @@ -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/contrib/libc++/include/__split_buffer b/contrib/libc++/include/__split_buffer index e0aa13b..f1c404f 100644 --- a/contrib/libc++/include/__split_buffer +++ b/contrib/libc++/include/__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/contrib/libc++/include/__std_stream b/contrib/libc++/include/__std_stream index 8ca413e..cff4331 100644 --- a/contrib/libc++/include/__std_stream +++ b/contrib/libc++/include/__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/contrib/libc++/include/__tree b/contrib/libc++/include/__tree index cd6d7ef..9ffc38d 100644 --- a/contrib/libc++/include/__tree +++ b/contrib/libc++/include/__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/contrib/libc++/include/algorithm b/contrib/libc++/include/algorithm index 39191db..703a9b3 100644 --- a/contrib/libc++/include/algorithm +++ b/contrib/libc++/include/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> diff --git a/contrib/libc++/include/atomic b/contrib/libc++/include/atomic index db67e76..f6ab1cb 100644 --- a/contrib/libc++/include/atomic +++ b/contrib/libc++/include/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/contrib/libc++/include/deque b/contrib/libc++/include/deque index 8e09822..6c0216d 100644 --- a/contrib/libc++/include/deque +++ b/contrib/libc++/include/deque @@ -915,7 +915,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 +1060,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 +1078,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 +1348,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 +2514,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 +2532,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 +2565,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 +2596,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 +2627,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 +2663,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/contrib/libc++/include/forward_list b/contrib/libc++/include/forward_list index 0cbf2fd..88bf75f 100644 --- a/contrib/libc++/include/forward_list +++ b/contrib/libc++/include/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/contrib/libc++/include/functional b/contrib/libc++/include/functional index 995db56..d1a6301 100644 --- a/contrib/libc++/include/functional +++ b/contrib/libc++/include/functional @@ -1139,8 +1139,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 +1165,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 +1270,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 +1378,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 +1603,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 +1758,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 +1825,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/contrib/libc++/include/future b/contrib/libc++/include/future index 3d7bb6c..dae1a4b 100644 --- a/contrib/libc++/include/future +++ b/contrib/libc++/include/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/contrib/libc++/include/istream b/contrib/libc++/include/istream index 3f629f6..f3e74c3 100644 --- a/contrib/libc++/include/istream +++ b/contrib/libc++/include/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/contrib/libc++/include/iterator b/contrib/libc++/include/iterator index 3b078a2..dda053d 100644 --- a/contrib/libc++/include/iterator +++ b/contrib/libc++/include/iterator @@ -1135,7 +1135,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 diff --git a/contrib/libc++/include/list b/contrib/libc++/include/list index c6000c9..628a35b 100644 --- a/contrib/libc++/include/list +++ b/contrib/libc++/include/list @@ -196,13 +196,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))) {} }; @@ -305,7 +312,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++() @@ -352,9 +366,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_; @@ -439,7 +453,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++() @@ -505,11 +526,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 +555,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 +587,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 +671,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 +710,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 +754,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 +779,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 +793,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 +816,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 +1057,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 +1071,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,7 +1333,7 @@ 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); @@ -1307,9 +1350,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) { @@ -1359,7 +1402,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; @@ -1375,9 +1418,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) { @@ -1427,7 +1470,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; @@ -1441,7 +1484,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(); } @@ -1454,7 +1497,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(); } @@ -1469,7 +1513,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(); } @@ -1482,7 +1526,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(); } @@ -1498,7 +1543,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(); } @@ -1512,7 +1557,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(); } @@ -1532,7 +1578,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) 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); @@ -1557,7 +1603,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); @@ -1574,7 +1620,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 @@ -1583,7 +1629,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) @@ -1592,17 +1638,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 @@ -1611,7 +1657,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) @@ -1620,8 +1666,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> @@ -1636,8 +1682,8 @@ list<_Tp, _Alloc>::erase(const_iterator __p) _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 @@ -1646,7 +1692,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) @@ -1655,8 +1701,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 @@ -1676,10 +1722,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 @@ -1688,7 +1734,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) @@ -1697,14 +1743,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 } @@ -1762,7 +1808,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; } } @@ -1821,7 +1868,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; } } @@ -1839,10 +1887,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 @@ -1853,7 +1901,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; @@ -1883,9 +1932,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 @@ -1896,7 +1945,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; @@ -1937,11 +1986,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); @@ -1950,7 +1999,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) @@ -2056,12 +2105,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 @@ -2076,7 +2125,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; @@ -2119,9 +2169,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; @@ -2135,13 +2185,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 @@ -2153,14 +2203,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 @@ -2198,7 +2248,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/contrib/libc++/include/locale b/contrib/libc++/include/locale index 49f9c08..ef7603d 100644 --- a/contrib/libc++/include/locale +++ b/contrib/libc++/include/locale @@ -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); @@ -1801,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); @@ -1831,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); @@ -1861,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); @@ -1891,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); @@ -2055,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/contrib/libc++/include/map b/contrib/libc++/include/map index abc07a3..953743a 100644 --- a/contrib/libc++/include/map +++ b/contrib/libc++/include/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/contrib/libc++/include/memory b/contrib/libc++/include/memory index 2a8b7e6..ffd0cd0 100644 --- a/contrib/libc++/include/memory +++ b/contrib/libc++/include/memory @@ -350,6 +350,10 @@ class bad_weak_ptr bad_weak_ptr() noexcept; }; +template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 +template<class T> unique_ptr<T> make_unique(size_t n); // C++14 +template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] + template<class T> class shared_ptr { @@ -1750,7 +1754,7 @@ public: typedef const _Tp* const_pointer; typedef const _Tp& reference; typedef const _Tp& const_reference; - typedef _Tp value_type; + typedef const _Tp value_type; typedef true_type propagate_on_container_move_assignment; @@ -2036,6 +2040,10 @@ public: return *this; } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> @@ -2051,10 +2059,6 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} @@ -2131,6 +2135,10 @@ public: return *this; } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> @@ -2146,10 +2154,6 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} @@ -2227,6 +2231,10 @@ public: return *this; } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> @@ -2243,10 +2251,6 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} @@ -2321,6 +2325,10 @@ public: return *this; } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> @@ -2336,10 +2344,6 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} @@ -2409,6 +2413,10 @@ public: return *this; } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args1, class... _Args2> @@ -2422,10 +2430,6 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} @@ -3079,8 +3083,61 @@ move(unique_ptr<_Tp, _Dp>& __t) #endif +#if _LIBCPP_STD_VER > 11 + +template<class _Tp> +struct __unique_if +{ + typedef unique_ptr<_Tp> __unique_single; +}; + +template<class _Tp> +struct __unique_if<_Tp[]> +{ + typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; +}; + +template<class _Tp, size_t _Np> +struct __unique_if<_Tp[_Np]> +{ + typedef void __unique_array_known_bound; +}; + +template<class _Tp, class... _Args> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_single +make_unique(_Args&&... __args) +{ + return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...)); +} + +template<class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __unique_if<_Tp>::__unique_array_unknown_bound +make_unique(size_t __n) +{ + typedef typename remove_extent<_Tp>::type _Up; + return unique_ptr<_Tp>(new _Up[__n]()); +} + +template<class _Tp, class... _Args> + typename __unique_if<_Tp>::__unique_array_known_bound + make_unique(_Args&&...) = delete; + +#endif // _LIBCPP_STD_VER > 11 + template <class _Tp> struct hash; +template <class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_Size +__loadword(const void* __p) +{ + _Size __r; + std::memcpy(&__r, __p, sizeof(__r)); + return __r; +} + // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t // is 64 bits. This is because cityhash64 uses 64bit x 64bit // multiplication, which can be very slow on 32-bit systems. @@ -3104,7 +3161,7 @@ __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) const unsigned char* __data = static_cast<const unsigned char*>(__key); for (; __len >= 4; __data += 4, __len -= 4) { - _Size __k = *(const _Size*)__data; + _Size __k = __loadword<_Size>(__data); __k *= __m; __k ^= __k >> __r; __k *= __m; @@ -3163,13 +3220,13 @@ struct __murmur2_or_cityhash<_Size, 64> static _Size __hash_len_0_to_16(const char* __s, _Size __len) { if (__len > 8) { - const _Size __a = *(const _Size*)__s; - const _Size __b = *(const _Size*)(__s + __len - 8); + const _Size __a = __loadword<_Size>(__s); + const _Size __b = __loadword<_Size>(__s + __len - 8); return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; } if (__len >= 4) { - const uint32_t __a = *(const uint32_t*)(__s); - const uint32_t __b = *(const uint32_t*)(__s + __len - 4); + const uint32_t __a = __loadword<uint32_t>(__s); + const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); return __hash_len_16(__len + (__a << 3), __b); } if (__len > 0) { @@ -3185,10 +3242,10 @@ struct __murmur2_or_cityhash<_Size, 64> } static _Size __hash_len_17_to_32(const char *__s, _Size __len) { - const _Size __a = *(const _Size*)(__s) * __k1; - const _Size __b = *(const _Size*)(__s + 8); - const _Size __c = *(const _Size*)(__s + __len - 8) * __k2; - const _Size __d = *(const _Size*)(__s + __len - 16) * __k0; + const _Size __a = __loadword<_Size>(__s) * __k1; + const _Size __b = __loadword<_Size>(__s + 8); + const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; + const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, __a + __rotate(__b ^ __k3, 20) - __c + __len); } @@ -3209,33 +3266,33 @@ struct __murmur2_or_cityhash<_Size, 64> // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. static pair<_Size, _Size> __weak_hash_len_32_with_seeds( const char* __s, _Size __a, _Size __b) { - return __weak_hash_len_32_with_seeds(*(const _Size*)(__s), - *(const _Size*)(__s + 8), - *(const _Size*)(__s + 16), - *(const _Size*)(__s + 24), + return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), + __loadword<_Size>(__s + 8), + __loadword<_Size>(__s + 16), + __loadword<_Size>(__s + 24), __a, __b); } // Return an 8-byte hash for 33 to 64 bytes. static _Size __hash_len_33_to_64(const char *__s, size_t __len) { - _Size __z = *(const _Size*)(__s + 24); - _Size __a = *(const _Size*)(__s) + - (__len + *(const _Size*)(__s + __len - 16)) * __k0; + _Size __z = __loadword<_Size>(__s + 24); + _Size __a = __loadword<_Size>(__s) + + (__len + __loadword<_Size>(__s + __len - 16)) * __k0; _Size __b = __rotate(__a + __z, 52); _Size __c = __rotate(__a, 37); - __a += *(const _Size*)(__s + 8); + __a += __loadword<_Size>(__s + 8); __c += __rotate(__a, 7); - __a += *(const _Size*)(__s + 16); + __a += __loadword<_Size>(__s + 16); _Size __vf = __a + __z; _Size __vs = __b + __rotate(__a, 31) + __c; - __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32); - __z += *(const _Size*)(__s + __len - 8); + __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); + __z += __loadword<_Size>(__s + __len - 8); __b = __rotate(__a + __z, 52); __c = __rotate(__a, 37); - __a += *(const _Size*)(__s + __len - 24); + __a += __loadword<_Size>(__s + __len - 24); __c += __rotate(__a, 7); - __a += *(const _Size*)(__s + __len - 16); + __a += __loadword<_Size>(__s + __len - 16); _Size __wf = __a + __z; _Size __ws = __b + __rotate(__a, 31) + __c; _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); @@ -3261,26 +3318,26 @@ __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) // For strings over 64 bytes we hash the end first, and then as we // loop we keep 56 bytes of state: v, w, x, y, and z. - _Size __x = *(const _Size*)(__s + __len - 40); - _Size __y = *(const _Size*)(__s + __len - 16) + - *(const _Size*)(__s + __len - 56); - _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len, - *(const _Size*)(__s + __len - 24)); + _Size __x = __loadword<_Size>(__s + __len - 40); + _Size __y = __loadword<_Size>(__s + __len - 16) + + __loadword<_Size>(__s + __len - 56); + _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, + __loadword<_Size>(__s + __len - 24)); pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); - __x = __x * __k1 + *(const _Size*)(__s); + __x = __x * __k1 + __loadword<_Size>(__s); // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. __len = (__len - 1) & ~static_cast<_Size>(63); do { - __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1; - __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1; + __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; + __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; __x ^= __w.second; - __y += __v.first + *(const _Size*)(__s + 40); + __y += __v.first + __loadword<_Size>(__s + 40); __z = __rotate(__z + __w.first, 33) * __k1; __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, - __y + *(const _Size*)(__s + 16)); + __y + __loadword<_Size>(__s + 16)); std::swap(__z, __x); __s += 64; __len -= 64; diff --git a/contrib/libc++/include/random b/contrib/libc++/include/random index 92722ea..46cbc4b 100644 --- a/contrib/libc++/include/random +++ b/contrib/libc++/include/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,7 +1969,7 @@ 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; } diff --git a/contrib/libc++/include/regex b/contrib/libc++/include/regex index d1afa54..312ca11 100644 --- a/contrib/libc++/include/regex +++ b/contrib/libc++/include/regex @@ -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; }; @@ -2921,7 +2930,7 @@ __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; @@ -3420,6 +3429,7 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, case '+': case '?': case '{': + case '}': __push_char(*__temp); __first = ++__temp; break; @@ -3903,7 +3913,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); @@ -4481,7 +4491,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; @@ -5807,6 +5817,21 @@ regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, 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; +} + template <class _Allocator, class _CharT, class _Traits> inline _LIBCPP_INLINE_VISIBILITY bool @@ -6044,7 +6069,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/contrib/libc++/include/string b/contrib/libc++/include/string index fa44f68..89f75cd 100644 --- a/contrib/libc++/include/string +++ b/contrib/libc++/include/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; }; @@ -1036,6 +1036,21 @@ _LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>) #pragma warning( pop ) #endif // _MSC_VER +#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 : private __basic_string_common<true> @@ -1069,6 +1084,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 +1132,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 +1145,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 +1192,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 +1227,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 +1240,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 +1303,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 +1312,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 +1351,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 +1377,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 +1413,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 +1437,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 +1447,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,9 +1505,9 @@ 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; @@ -1475,20 +1523,44 @@ private: const allocator_type& __alloc() const _NOEXCEPT {return __r_.second();} +#ifdef _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 << 1);} +# else {__r_.first().__s.__size_ = (unsigned char)(__s);} -#else +# 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 + {__r_.first().__s.__size_ = (unsigned char)(__s);} +# 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;} @@ -1517,10 +1589,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();} @@ -1547,8 +1619,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> @@ -1572,7 +1644,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); @@ -1729,7 +1801,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(); @@ -1747,13 +1819,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(); @@ -1771,13 +1843,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); @@ -1787,7 +1859,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 @@ -1798,7 +1870,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); @@ -1808,7 +1880,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 @@ -1824,7 +1896,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> @@ -1834,7 +1906,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 @@ -1859,7 +1931,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(); @@ -1888,7 +1960,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()); } @@ -2026,7 +2098,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) @@ -2038,12 +2110,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); @@ -2068,10 +2142,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); @@ -2082,7 +2159,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); @@ -2090,7 +2167,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); @@ -2116,7 +2193,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); @@ -2258,7 +2335,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); @@ -2270,7 +2347,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); @@ -2281,7 +2358,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); @@ -2304,7 +2381,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()); @@ -2316,14 +2393,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> @@ -2386,7 +2486,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); @@ -2398,7 +2498,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); @@ -2411,7 +2511,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) { @@ -2440,10 +2540,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); @@ -2451,7 +2551,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; @@ -2495,10 +2595,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); @@ -2506,7 +2606,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); @@ -2538,7 +2638,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); @@ -2553,15 +2653,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); @@ -2586,7 +2686,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); @@ -2598,7 +2698,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; @@ -2647,10 +2747,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; @@ -2661,7 +2761,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; @@ -2720,7 +2820,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); @@ -2740,7 +2840,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); } @@ -2748,7 +2848,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); } @@ -2772,7 +2872,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) @@ -2930,7 +3030,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 } @@ -2938,7 +3038,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) @@ -3039,7 +3140,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) @@ -3085,7 +3186,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 { @@ -3097,8 +3198,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; @@ -3117,7 +3218,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 @@ -3134,8 +3235,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); @@ -3145,7 +3246,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 { @@ -3158,8 +3259,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; @@ -3178,7 +3279,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 @@ -3199,8 +3300,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); @@ -3213,7 +3314,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 { @@ -3223,8 +3324,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; @@ -3243,7 +3344,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 @@ -3265,7 +3366,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 { @@ -3279,10 +3380,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); } @@ -3302,7 +3403,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 @@ -3324,7 +3425,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 { @@ -3334,9 +3435,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); } @@ -3355,7 +3456,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 @@ -3373,9 +3474,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); } @@ -3386,7 +3487,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 { @@ -3398,8 +3499,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; @@ -3417,7 +3518,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 @@ -3437,8 +3538,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; @@ -3491,7 +3592,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); @@ -3503,7 +3604,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); @@ -3515,7 +3616,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 diff --git a/contrib/libc++/include/type_traits b/contrib/libc++/include/type_traits index ab0e222..450b592 100644 --- a/contrib/libc++/include/type_traits +++ b/contrib/libc++/include/type_traits @@ -137,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 */ @@ -154,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: @@ -191,16 +258,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 @@ -446,6 +522,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 || @@ -459,11 +539,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;}; @@ -472,6 +560,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;}; @@ -481,6 +573,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;}; @@ -489,6 +585,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 @@ -518,11 +618,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> @@ -584,6 +692,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 @@ -593,6 +705,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 @@ -916,7 +1032,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; @@ -928,6 +1044,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>\ @@ -989,6 +1110,10 @@ struct aligned_union 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 @@ -1150,6 +1275,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 {}; @@ -1175,6 +1304,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> @@ -1233,6 +1366,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 @@ -1411,6 +1548,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> @@ -1653,7 +1794,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> { @@ -2878,13 +3019,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) @@ -2892,13 +3047,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) @@ -2956,6 +3125,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> @@ -3050,6 +3223,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/contrib/libc++/include/unordered_map b/contrib/libc++/include/unordered_map index 235b2ea..78e6307 100644 --- a/contrib/libc++/include/unordered_map +++ b/contrib/libc++/include/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,56 @@ 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; 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> @@ -750,7 +743,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 @@ -907,26 +909,15 @@ 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> @@ -1105,11 +1096,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 +1109,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 +1153,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 +1186,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 +1201,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 +1283,56 @@ 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; 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> @@ -1382,7 +1404,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 @@ -1529,18 +1560,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> @@ -1727,11 +1747,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 +1759,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/contrib/libc++/include/utility b/contrib/libc++/include/utility index 2df4b36..ba65649 100644 --- a/contrib/libc++/include/utility +++ b/contrib/libc++/include/utility @@ -117,6 +117,27 @@ template<size_t I, class T1, class T2> typename tuple_element<I, std::pair<T1, T2> >::type&& get(std::pair<T1, T2>&&) noexcept; +// 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)>; + } // std */ @@ -578,6 +599,92 @@ get(pair<_T1, _T2>&& __p) _NOEXCEPT #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#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 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_UTILITY diff --git a/contrib/libc++/include/vector b/contrib/libc++/include/vector index e04c267..046d92d 100644 --- a/contrib/libc++/include/vector +++ b/contrib/libc++/include/vector @@ -365,12 +365,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 +432,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 +784,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 +865,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 +1158,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 +1584,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; @@ -1943,9 +1931,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 @@ -2307,7 +2295,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 @@ -2414,11 +2402,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; } } @@ -2481,7 +2469,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) { @@ -2490,7 +2478,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)) { @@ -2498,7 +2486,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) { @@ -2511,7 +2499,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) { @@ -2524,7 +2512,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)) { @@ -2540,7 +2528,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) { @@ -2554,7 +2542,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; @@ -2567,7 +2555,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)) { @@ -2581,7 +2569,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; @@ -2593,7 +2581,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) { @@ -2609,7 +2597,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)) { @@ -2625,7 +2613,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) { @@ -2639,7 +2627,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)) { @@ -2656,7 +2644,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(); @@ -2665,7 +2653,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())) { @@ -2678,7 +2666,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) { @@ -2720,14 +2708,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) { @@ -3123,7 +3111,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; diff --git a/contrib/libc++/src/debug.cpp b/contrib/libc++/src/debug.cpp index 06040af..04d570e 100644 --- a/contrib/libc++/src/debug.cpp +++ b/contrib/libc++/src/debug.cpp @@ -143,7 +143,7 @@ __libcpp_db::__insert_c(void* __c) if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1); - __c_node** cbeg = (__c_node**)calloc(nc, sizeof(void*)); + __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*))); if (cbeg == nullptr) #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); @@ -168,7 +168,8 @@ __libcpp_db::__insert_c(void* __c) } size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); __c_node* p = __cbeg_[hc]; - __c_node* r = __cbeg_[hc] = (__c_node*)malloc(sizeof(__c_node)); + __c_node* r = __cbeg_[hc] = + static_cast<__c_node*>(malloc(sizeof(__c_node))); if (__cbeg_[hc] == nullptr) #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); @@ -407,7 +408,8 @@ __c_node::__add(__i_node* i) size_t nc = 2*static_cast<size_t>(cap_ - beg_); if (nc == 0) nc = 1; - __i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*)); + __i_node** beg = + static_cast<__i_node**>(malloc(nc * sizeof(__i_node*))); if (beg == nullptr) #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); @@ -433,7 +435,7 @@ __libcpp_db::__insert_iterator(void* __i) if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1); - __i_node** ibeg = (__i_node**)calloc(nc, sizeof(void*)); + __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*))); if (ibeg == nullptr) #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); @@ -458,7 +460,8 @@ __libcpp_db::__insert_iterator(void* __i) } size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_); __i_node* p = __ibeg_[hi]; - __i_node* r = __ibeg_[hi] = (__i_node*)malloc(sizeof(__i_node)); + __i_node* r = __ibeg_[hi] = + static_cast<__i_node*>(malloc(sizeof(__i_node))); if (r == nullptr) #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_alloc(); diff --git a/contrib/libc++/src/hash.cpp b/contrib/libc++/src/hash.cpp index 65a9d51..388ab2e 100644 --- a/contrib/libc++/src/hash.cpp +++ b/contrib/libc++/src/hash.cpp @@ -12,12 +12,9 @@ #include "stdexcept" #include "type_traits" -// Don't silence a non-existent warning if clang doesn't yet have this warning. #ifdef __clang__ -#if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 2)) #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif -#endif _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/contrib/libc++/src/iostream.cpp b/contrib/libc++/src/iostream.cpp index 7fc71df..f413681 100644 --- a/contrib/libc++/src/iostream.cpp +++ b/contrib/libc++/src/iostream.cpp @@ -54,13 +54,13 @@ ios_base::Init::Init() ios_base::Init::~Init() { - ostream* cout_ptr = (ostream*)cout; - ostream* clog_ptr = (ostream*)clog; + ostream* cout_ptr = reinterpret_cast<ostream*>(cout); + ostream* clog_ptr = reinterpret_cast<ostream*>(clog); cout_ptr->flush(); clog_ptr->flush(); - wostream* wcout_ptr = (wostream*)wcout; - wostream* wclog_ptr = (wostream*)wclog; + wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); + wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); wcout_ptr->flush(); wclog_ptr->flush(); } diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp index 49c1cf2..b15f077 100644 --- a/contrib/libc++/src/locale.cpp +++ b/contrib/libc++/src/locale.cpp @@ -230,8 +230,10 @@ locale::__imp::__imp(const string& name, size_t refs) // NOTE avoid the `base class should be explicitly initialized in the // copy constructor` warning emitted by GCC +#if defined(__clang__) || _GNUC_VER >= 406 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wextra" +#endif locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, other.facets_.size())), @@ -243,7 +245,9 @@ locale::__imp::__imp(const __imp& other) facets_[i]->__add_shared(); } +#if defined(__clang__) || _GNUC_VER >= 406 #pragma GCC diagnostic pop +#endif locale::__imp::__imp(const __imp& other, const string& name, locale::category c) : facets_(N), @@ -786,7 +790,7 @@ ctype<wchar_t>::do_toupper(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c; -#elif defined(__GLIBC__) || defined(EMSCRIPTEN) +#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__) return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c; #else return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c; @@ -799,7 +803,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low; -#elif defined(__GLIBC__) || defined(EMSCRIPTEN) +#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__) *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low] : *low; #else @@ -813,7 +817,7 @@ ctype<wchar_t>::do_tolower(char_type c) const { #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c; -#elif defined(__GLIBC__) || defined(EMSCRIPTEN) +#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__) return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c; #else return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c; @@ -826,7 +830,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low; -#elif defined(__GLIBC__) || defined(EMSCRIPTEN) +#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__) *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low] : *low; #else @@ -893,9 +897,11 @@ ctype<char>::do_toupper(char_type c) const #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c; +#elif defined(__NetBSD__) + return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]); #elif defined(__GLIBC__) || defined(EMSCRIPTEN) return isascii(c) ? - static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c; + static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c; #else return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c; #endif @@ -908,6 +914,8 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low; +#elif defined(__NetBSD__) + *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]); #elif defined(__GLIBC__) || defined(EMSCRIPTEN) *low = isascii(*low) ? static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low; @@ -923,7 +931,9 @@ ctype<char>::do_tolower(char_type c) const #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c; -#elif defined(__GLIBC__) || defined(EMSCRIPTEN) +#elif defined(__NetBSD__) + return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]); +#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__) return isascii(c) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c; #else @@ -937,6 +947,8 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const for (; low != high; ++low) #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low; +#elif defined(__NetBSD__) + *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]); #elif defined(__GLIBC__) || defined(EMSCRIPTEN) *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low; #else @@ -989,6 +1001,8 @@ ctype<char>::classic_table() _NOEXCEPT { #if defined(__APPLE__) || defined(__FreeBSD__) return _DefaultRuneLocale.__runetype; +#elif defined(__NetBSD__) + return _C_ctype_tab_ + 1; #elif defined(__GLIBC__) return __cloc()->__ctype_b; #elif __sun__ @@ -1020,9 +1034,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT { return __cloc()->__ctype_toupper; } -#endif // __GLIBC__ +#elif __NetBSD__ +const short* +ctype<char>::__classic_lower_table() _NOEXCEPT +{ + return _C_tolower_tab_ + 1; +} -#if defined(EMSCRIPTEN) +const short* +ctype<char>::__classic_upper_table() _NOEXCEPT +{ + return _C_toupper_tab_ + 1; +} + +#elif defined(EMSCRIPTEN) const int* ctype<char>::__classic_lower_table() _NOEXCEPT { @@ -1034,7 +1059,7 @@ ctype<char>::__classic_upper_table() _NOEXCEPT { return *__ctype_toupper_loc(); } -#endif // EMSCRIPTEN +#endif // __GLIBC__ || EMSCRIPTEN || __NETBSD__ // template <> class ctype_byname<char> @@ -1068,28 +1093,28 @@ ctype_byname<char>::~ctype_byname() char ctype_byname<char>::do_toupper(char_type c) const { - return static_cast<char>(toupper_l(c, __l)); + return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l)); } const char* ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const { for (; low != high; ++low) - *low = static_cast<char>(toupper_l(*low, __l)); + *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l)); return low; } char ctype_byname<char>::do_tolower(char_type c) const { - return static_cast<char>(tolower_l(c, __l)); + return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l)); } const char* ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const { for (; low != high; ++low) - *low = static_cast<char>(tolower_l(*low, __l)); + *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l)); return low; } @@ -1372,7 +1397,7 @@ locale::id codecvt<wchar_t, char, mbstate_t>::id; codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), - __l(0) + __l(_LIBCPP_GET_C_LOCALE) { } @@ -1389,7 +1414,7 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs) codecvt<wchar_t, char, mbstate_t>::~codecvt() { - if (__l != 0) + if (__l != _LIBCPP_GET_C_LOCALE) freelocale(__l); } @@ -5315,7 +5340,7 @@ __time_put::__time_put(const string& nm) __time_put::~__time_put() { - if (__loc_) + if (__loc_ != _LIBCPP_GET_C_LOCALE) freelocale(__loc_); } diff --git a/contrib/libc++/src/stdexcept.cpp b/contrib/libc++/src/stdexcept.cpp index 0c4e832..8d25f3e 100644 --- a/contrib/libc++/src/stdexcept.cpp +++ b/contrib/libc++/src/stdexcept.cpp @@ -61,7 +61,7 @@ __libcpp_nmstr::__libcpp_nmstr(const char* msg) c[0] = c[1] = len; str_ += offset; count() = 0; - std::strcpy(const_cast<char*>(c_str()), msg); + std::memcpy(const_cast<char*>(c_str()), msg, len + 1); } inline diff --git a/contrib/libc++/src/string.cpp b/contrib/libc++/src/string.cpp index c71af4f..c6fe408 100644 --- a/contrib/libc++/src/string.cpp +++ b/contrib/libc++/src/string.cpp @@ -11,6 +11,8 @@ #include "cstdlib" #include "cwchar" #include "cerrno" +#include "limits" +#include "stdexcept" #ifdef _WIN32 #include "support/win32/support.h" #endif // _WIN32 @@ -26,662 +28,499 @@ template string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); -int -stoi(const string& str, size_t* idx, int base) +namespace +{ + +template<typename T> +inline +void throw_helper( const string& msg ) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw T( msg ); +#else + abort(); +#endif +} + +inline +void throw_from_string_out_of_range( const string& func ) +{ + throw_helper<out_of_range>(func + ": out of range"); +} + +inline +void throw_from_string_invalid_arg( const string& func ) +{ + throw_helper<invalid_argument>(func + ": no conversion"); +} + +// as_integer + +template<typename V, typename S, typename F> +inline +V +as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) { - char* ptr; - const char* const p = str.c_str(); + typename S::value_type* ptr; + const typename S::value_type* const p = str.c_str(); typename remove_reference<decltype(errno)>::type errno_save = errno; errno = 0; - long r = strtol(p, &ptr, base); + V r = f(p, &ptr, base); swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE || r < numeric_limits<int>::min() || - numeric_limits<int>::max() < r) - throw out_of_range("stoi: out of range"); + if (errno_save == ERANGE) + throw_from_string_out_of_range(func); if (ptr == p) - throw invalid_argument("stoi: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS + throw_from_string_invalid_arg(func); if (idx) *idx = static_cast<size_t>(ptr - p); + return r; +} + +template<typename V, typename S> +inline +V +as_integer(const string& func, const S& s, size_t* idx, int base); + +// string +template<> +inline +int +as_integer(const string& func, const string& s, size_t* idx, int base ) +{ + // Use long as no Stantard string to integer exists. + long r = as_integer_helper<long>( func, s, idx, base, strtol ); + if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) + throw_from_string_out_of_range(func); return static_cast<int>(r); } +template<> +inline +long +as_integer(const string& func, const string& s, size_t* idx, int base ) +{ + return as_integer_helper<long>( func, s, idx, base, strtol ); +} + +template<> +inline +unsigned long +as_integer( const string& func, const string& s, size_t* idx, int base ) +{ + return as_integer_helper<unsigned long>( func, s, idx, base, strtoul ); +} + +template<> +inline +long long +as_integer( const string& func, const string& s, size_t* idx, int base ) +{ + return as_integer_helper<long long>( func, s, idx, base, strtoll ); +} + +template<> +inline +unsigned long long +as_integer( const string& func, const string& s, size_t* idx, int base ) +{ + return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull ); +} + +// wstring +template<> +inline int -stoi(const wstring& str, size_t* idx, int base) +as_integer( const string& func, const wstring& s, size_t* idx, int base ) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long r = wcstol(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE || r < numeric_limits<int>::min() || - numeric_limits<int>::max() < r) - throw out_of_range("stoi: out of range"); - if (ptr == p) - throw invalid_argument("stoi: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); + // Use long as no Stantard string to integer exists. + long r = as_integer_helper<long>( func, s, idx, base, wcstol ); + if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) + throw_from_string_out_of_range(func); return static_cast<int>(r); } +template<> +inline long -stol(const string& str, size_t* idx, int base) +as_integer( const string& func, const wstring& s, size_t* idx, int base ) +{ + return as_integer_helper<long>( func, s, idx, base, wcstol ); +} + +template<> +inline +unsigned long +as_integer( const string& func, const wstring& s, size_t* idx, int base ) +{ + return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul ); +} + +template<> +inline +long long +as_integer( const string& func, const wstring& s, size_t* idx, int base ) +{ + return as_integer_helper<long long>( func, s, idx, base, wcstoll ); +} + +template<> +inline +unsigned long long +as_integer( const string& func, const wstring& s, size_t* idx, int base ) +{ + return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull ); +} + +// as_float + +template<typename V, typename S, typename F> +inline +V +as_float_helper(const string& func, const S& str, size_t* idx, F f ) { - char* ptr; - const char* const p = str.c_str(); + typename S::value_type* ptr; + const typename S::value_type* const p = str.c_str(); typename remove_reference<decltype(errno)>::type errno_save = errno; errno = 0; - long r = strtol(p, &ptr, base); + V r = f(p, &ptr); swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS if (errno_save == ERANGE) - throw out_of_range("stol: out of range"); + throw_from_string_out_of_range(func); if (ptr == p) - throw invalid_argument("stol: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS + throw_from_string_invalid_arg(func); if (idx) *idx = static_cast<size_t>(ptr - p); return r; } +template<typename V, typename S> +inline +V as_float( const string& func, const S& s, size_t* idx = nullptr ); + +template<> +inline +float +as_float( const string& func, const string& s, size_t* idx ) +{ + return as_float_helper<float>( func, s, idx, strtof ); +} + +template<> +inline +double +as_float(const string& func, const string& s, size_t* idx ) +{ + return as_float_helper<double>( func, s, idx, strtod ); +} + +template<> +inline +long double +as_float( const string& func, const string& s, size_t* idx ) +{ + return as_float_helper<long double>( func, s, idx, strtold ); +} + +template<> +inline +float +as_float( const string& func, const wstring& s, size_t* idx ) +{ + return as_float_helper<float>( func, s, idx, wcstof ); +} + +template<> +inline +double +as_float( const string& func, const wstring& s, size_t* idx ) +{ + return as_float_helper<double>( func, s, idx, wcstod ); +} + +template<> +inline +long double +as_float( const string& func, const wstring& s, size_t* idx ) +{ + return as_float_helper<long double>( func, s, idx, wcstold ); +} + +} // unnamed namespace + +int +stoi(const string& str, size_t* idx, int base) +{ + return as_integer<int>( "stoi", str, idx, base ); +} + +int +stoi(const wstring& str, size_t* idx, int base) +{ + return as_integer<int>( "stoi", str, idx, base ); +} + +long +stol(const string& str, size_t* idx, int base) +{ + return as_integer<long>( "stol", str, idx, base ); +} + long stol(const wstring& str, size_t* idx, int base) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long r = wcstol(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stol: out of range"); - if (ptr == p) - throw invalid_argument("stol: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<long>( "stol", str, idx, base ); } unsigned long stoul(const string& str, size_t* idx, int base) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - unsigned long r = strtoul(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoul: out of range"); - if (ptr == p) - throw invalid_argument("stoul: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<unsigned long>( "stoul", str, idx, base ); } unsigned long stoul(const wstring& str, size_t* idx, int base) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - unsigned long r = wcstoul(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoul: out of range"); - if (ptr == p) - throw invalid_argument("stoul: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<unsigned long>( "stoul", str, idx, base ); } long long stoll(const string& str, size_t* idx, int base) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long long r = strtoll(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoll: out of range"); - if (ptr == p) - throw invalid_argument("stoll: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<long long>( "stoll", str, idx, base ); } long long stoll(const wstring& str, size_t* idx, int base) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long long r = wcstoll(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoll: out of range"); - if (ptr == p) - throw invalid_argument("stoll: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<long long>( "stoll", str, idx, base ); } unsigned long long stoull(const string& str, size_t* idx, int base) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - unsigned long long r = strtoull(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoull: out of range"); - if (ptr == p) - throw invalid_argument("stoull: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<unsigned long long>( "stoull", str, idx, base ); } unsigned long long stoull(const wstring& str, size_t* idx, int base) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - unsigned long long r = wcstoull(p, &ptr, base); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stoull: out of range"); - if (ptr == p) - throw invalid_argument("stoull: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_integer<unsigned long long>( "stoull", str, idx, base ); } float stof(const string& str, size_t* idx) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - float r = strtof(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stof: out of range"); - if (ptr == p) - throw invalid_argument("stof: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<float>( "stof", str, idx ); } float stof(const wstring& str, size_t* idx) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - float r = wcstof(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stof: out of range"); - if (ptr == p) - throw invalid_argument("stof: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<float>( "stof", str, idx ); } double stod(const string& str, size_t* idx) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - double r = strtod(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stod: out of range"); - if (ptr == p) - throw invalid_argument("stod: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<double>( "stod", str, idx ); } double stod(const wstring& str, size_t* idx) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - double r = wcstod(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stod: out of range"); - if (ptr == p) - throw invalid_argument("stod: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<double>( "stod", str, idx ); } long double stold(const string& str, size_t* idx) { - char* ptr; - const char* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long double r = strtold(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stold: out of range"); - if (ptr == p) - throw invalid_argument("stold: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<long double>( "stold", str, idx ); } long double stold(const wstring& str, size_t* idx) { - wchar_t* ptr; - const wchar_t* const p = str.c_str(); - typename remove_reference<decltype(errno)>::type errno_save = errno; - errno = 0; - long double r = wcstold(p, &ptr); - swap(errno, errno_save); -#ifndef _LIBCPP_NO_EXCEPTIONS - if (errno_save == ERANGE) - throw out_of_range("stold: out of range"); - if (ptr == p) - throw invalid_argument("stold: no conversion"); -#endif // _LIBCPP_NO_EXCEPTIONS - if (idx) - *idx = static_cast<size_t>(ptr - p); - return r; + return as_float<long double>( "stold", str, idx ); } -string to_string(int val) +// to_string + +namespace +{ + +// as_string + +template<typename S, typename P, typename V > +inline +S +as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) { - string s; - s.resize(s.capacity()); + typedef typename S::size_type size_type; + size_type available = s.size(); while (true) { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%d", val)); - if (n2 <= s.size()) + int status = sprintf_like(&s[0], available + 1, fmt, a); + if ( status >= 0 ) { - s.resize(n2); - break; + size_type used = static_cast<size_type>(status); + if ( used <= available ) + { + s.resize( used ); + break; + } + available = used; // Assume this is advice of how much space we need. } - s.resize(n2); + else + available = available * 2 + 1; + s.resize(available); } return s; } -string to_string(unsigned val) +template <class S, class V, bool = is_floating_point<V>::value> +struct initial_string; + +template <class V, bool b> +struct initial_string<string, V, b> { - string s; - s.resize(s.capacity()); - while (true) + string + operator()() const { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%u", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); + string s; + s.resize(s.capacity()); + return s; } - return s; -} +}; -string to_string(long val) +template <class V> +struct initial_string<wstring, V, false> { - string s; - s.resize(s.capacity()); - while (true) + wstring + operator()() const { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%ld", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); + const size_t n = (numeric_limits<unsigned long long>::digits / 3) + + ((numeric_limits<unsigned long long>::digits % 3) != 0) + + 1; + wstring s(n, wchar_t()); + s.resize(s.capacity()); + return s; } - return s; -} +}; -string to_string(unsigned long val) +template <class V> +struct initial_string<wstring, V, true> { - string s; - s.resize(s.capacity()); - while (true) + wstring + operator()() const { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lu", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); + wstring s(20, wchar_t()); + s.resize(s.capacity()); + return s; } - return s; +}; + +typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...); + +inline +wide_printf +get_swprintf() +{ +#ifndef _WIN32 + return swprintf; +#else + return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(swprintf); +#endif +} + +} // unnamed namespace + +string to_string(int val) +{ + return as_string(snprintf, initial_string<string, int>()(), "%d", val); +} + +string to_string(unsigned val) +{ + return as_string(snprintf, initial_string<string, unsigned>()(), "%u", val); +} + +string to_string(long val) +{ + return as_string(snprintf, initial_string<string, long>()(), "%ld", val); +} + +string to_string(unsigned long val) +{ + return as_string(snprintf, initial_string<string, unsigned long>()(), "%lu", val); } string to_string(long long val) { - string s; - s.resize(s.capacity()); - while (true) - { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%lld", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return s; + return as_string(snprintf, initial_string<string, long long>()(), "%lld", val); } string to_string(unsigned long long val) { - string s; - s.resize(s.capacity()); - while (true) - { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%llu", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return s; + return as_string(snprintf, initial_string<string, unsigned long long>()(), "%llu", val); } string to_string(float val) { - string s; - s.resize(s.capacity()); - while (true) - { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return s; + return as_string(snprintf, initial_string<string, float>()(), "%f", val); } string to_string(double val) { - string s; - s.resize(s.capacity()); - while (true) - { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%f", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return s; + return as_string(snprintf, initial_string<string, double>()(), "%f", val); } string to_string(long double val) { - string s; - s.resize(s.capacity()); - while (true) - { - size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size()+1, "%Lf", val)); - if (n2 <= s.size()) - { - s.resize(n2); - break; - } - s.resize(n2); - } - return s; + return as_string(snprintf, initial_string<string, long double>()(), "%Lf", val); } wstring to_wstring(int val) { - const size_t n = (numeric_limits<int>::digits / 3) - + ((numeric_limits<int>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%d", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, int>()(), L"%d", val); } wstring to_wstring(unsigned val) { - const size_t n = (numeric_limits<unsigned>::digits / 3) - + ((numeric_limits<unsigned>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%u", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, unsigned>()(), L"%u", val); } wstring to_wstring(long val) { - const size_t n = (numeric_limits<long>::digits / 3) - + ((numeric_limits<long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%ld", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, long>()(), L"%ld", val); } wstring to_wstring(unsigned long val) { - const size_t n = (numeric_limits<unsigned long>::digits / 3) - + ((numeric_limits<unsigned long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%lu", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, unsigned long>()(), L"%lu", val); } wstring to_wstring(long long val) { - const size_t n = (numeric_limits<long long>::digits / 3) - + ((numeric_limits<long long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%lld", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, long long>()(), L"%lld", val); } wstring to_wstring(unsigned long long val) { - const size_t n = (numeric_limits<unsigned long long>::digits / 3) - + ((numeric_limits<unsigned long long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%llu", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, unsigned long long>()(), L"%llu", val); } wstring to_wstring(float val) { - const size_t n = 20; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%f", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, float>()(), L"%f", val); } wstring to_wstring(double val) { - const size_t n = 20; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%f", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, double>()(), L"%f", val); } wstring to_wstring(long double val) { - const size_t n = 20; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - while (true) - { - int n2 = swprintf(&s[0], s.size()+1, L"%Lf", val); - if (n2 > 0) - { - s.resize(static_cast<size_t>(n2)); - break; - } - s.resize(2*s.size()); - s.resize(s.capacity()); - } - return s; + return as_string(get_swprintf(), initial_string<wstring, long double>()(), L"%Lf", val); } - _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp index c6f6748..1fd8bb0 100644 --- a/contrib/libc++/src/thread.cpp +++ b/contrib/libc++/src/thread.cpp @@ -16,11 +16,17 @@ #if !defined(_WIN32) #if !defined(__sun__) && !defined(__linux__) #include <sys/sysctl.h> -#else -#include <unistd.h> #endif // !__sun__ && !__linux__ +#include <unistd.h> #endif // !_WIN32 +#if defined(__NetBSD__) +#pragma weak pthread_create // Do not create libpthread dependency +#endif +#if defined(_WIN32) +#include <windows.h> +#endif + _LIBCPP_BEGIN_NAMESPACE_STD thread::~thread() @@ -67,7 +73,7 @@ thread::hardware_concurrency() _NOEXCEPT std::size_t s = sizeof(n); sysctl(mib, 2, &n, &s, 0, 0); return n; -#elif (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)) || defined(EMSCRIPTEN) +#elif defined(_SC_NPROCESSORS_ONLN) long result = sysconf(_SC_NPROCESSORS_ONLN); // sysconf returns -1 if the name is invalid, the option does not exist or // does not have a definite limit. @@ -76,9 +82,14 @@ thread::hardware_concurrency() _NOEXCEPT if (result < 0) return 0; return static_cast<unsigned>(result); +#elif defined(_WIN32) + SYSTEM_INFO info; + GetSystemInfo(&info); + return info.dwNumberOfProcessors; #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. +#warning hardware_concurrency not yet implemented return 0; // Means not computable [thread.thread.static] #endif // defined(CTL_HW) && defined(HW_NCPU) } |