diff options
author | 2018-09-11 18:18:58 +0000 | |
---|---|---|
committer | 2018-09-11 18:18:58 +0000 | |
commit | 820e1f31efc1d6ed04795ba2e79f3044e1907492 (patch) | |
tree | 815cebb3734784074b661935c33f00bd5eb4d862 /lib/libcxx/include | |
parent | Nuke unused LIST() ieee80211com_head. (diff) | |
download | wireguard-openbsd-820e1f31efc1d6ed04795ba2e79f3044e1907492.tar.xz wireguard-openbsd-820e1f31efc1d6ed04795ba2e79f3044e1907492.zip |
import of libc++ 6.0.0
Diffstat (limited to 'lib/libcxx/include')
114 files changed, 17235 insertions, 8386 deletions
diff --git a/lib/libcxx/include/CMakeLists.txt b/lib/libcxx/include/CMakeLists.txt index 219d1b73083..b98e09260ca 100644 --- a/lib/libcxx/include/CMakeLists.txt +++ b/lib/libcxx/include/CMakeLists.txt @@ -10,31 +10,31 @@ set(LIBCXX_HEADER_PATTERN ${LIBCXX_SUPPORT_HEADER_PATTERN} ) -file(COPY . - DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1" - FILES_MATCHING - ${LIBCXX_HEADER_PATTERN} - ) +if(NOT LIBCXX_USING_INSTALLED_LLVM AND LLVM_BINARY_DIR) + file(COPY . + DESTINATION "${LLVM_BINARY_DIR}/include/c++/v1" + FILES_MATCHING + ${LIBCXX_HEADER_PATTERN} + ) +endif() if (LIBCXX_INSTALL_HEADERS) install(DIRECTORY . - DESTINATION include/c++/v1 - COMPONENT libcxx-headers + DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 + COMPONENT cxx-headers FILES_MATCHING ${LIBCXX_HEADER_PATTERN} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) if (LIBCXX_NEEDS_SITE_CONFIG) - set(UNIX_CAT cat) - if (WIN32) - set(UNIX_CAT type) - endif() # Generate and install a custom __config header. The new header is created # by prepending __config_site to the current __config header. add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config - COMMAND ${CMAKE_COMMAND} -E copy ${LIBCXX_BINARY_DIR}/__config_site ${LIBCXX_BINARY_DIR}/__generated_config - COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> ${LIBCXX_BINARY_DIR}/__generated_config + COMMAND ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/cat_files.py + ${LIBCXX_BINARY_DIR}/__config_site + ${LIBCXX_SOURCE_DIR}/include/__config + -o ${LIBCXX_BINARY_DIR}/__generated_config DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config ${LIBCXX_BINARY_DIR}/__config_site ) @@ -44,20 +44,26 @@ if (LIBCXX_INSTALL_HEADERS) set(generated_config_deps generate_config_header) # Install the generated header as __config. install(FILES ${LIBCXX_BINARY_DIR}/__generated_config - DESTINATION include/c++/v1 + DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ RENAME __config - COMPONENT libcxx-headers) + COMPONENT cxx-headers) endif() if (NOT CMAKE_CONFIGURATION_TYPES) # this target is just needed as a placeholder for the distribution target - add_custom_target(libcxx-headers) - add_custom_target(install-libcxx-headers - DEPENDS libcxx-headers ${generated_config_deps} + add_custom_target(cxx-headers) + add_custom_target(install-cxx-headers + DEPENDS cxx-headers ${generated_config_deps} COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=libcxx-headers + -DCMAKE_INSTALL_COMPONENT=cxx-headers -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + # Stripping is a no-op for headers + add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers) + + add_custom_target(libcxx-headers) + add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers) + add_custom_target(install-libcxx-headers-stripped DEPENDS install-cxx-headers-stripped) endif() endif() diff --git a/lib/libcxx/include/__bit_reference b/lib/libcxx/include/__bit_reference index 5659ed06824..3e4a21d261f 100644 --- a/lib/libcxx/include/__bit_reference +++ b/lib/libcxx/include/__bit_reference @@ -14,12 +14,14 @@ #include <__config> #include <algorithm> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator; @@ -40,11 +42,8 @@ class __bit_reference __storage_pointer __seg_; __storage_type __mask_; -#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC) friend typename _Cp::__self; -#else - friend class _Cp::__self; -#endif + friend class __bit_const_reference<_Cp>; friend class __bit_iterator<_Cp, false>; public: @@ -130,11 +129,7 @@ class __bit_const_reference __storage_pointer __seg_; __storage_type __mask_; -#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC) friend typename _Cp::__self; -#else - friend class _Cp::__self; -#endif friend class __bit_iterator<_Cp, true>; public: _LIBCPP_INLINE_VISIBILITY @@ -163,7 +158,7 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + static const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { @@ -199,7 +194,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type { typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { @@ -251,7 +246,7 @@ __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; typedef typename _It::difference_type difference_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + const int __bits_per_word = _It::__bits_per_word; difference_type __r = 0; // do first partial word if (__first.__ctz_ != 0) @@ -282,7 +277,7 @@ __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_typ typedef __bit_iterator<_Cp, _IsConst> _It; typedef typename _It::__storage_type __storage_type; typedef typename _It::difference_type difference_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + const int __bits_per_word = _It::__bits_per_word; difference_type __r = 0; // do first partial word if (__first.__ctz_ != 0) @@ -324,7 +319,7 @@ __fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { @@ -354,7 +349,7 @@ __fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { typedef __bit_iterator<_Cp, false> _It; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + const int __bits_per_word = _It::__bits_per_word; // do first partial word if (__first.__ctz_ != 0) { @@ -412,7 +407,7 @@ __copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCon typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; - static const unsigned __bits_per_word = _In::__bits_per_word; + const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -461,7 +456,7 @@ __copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsC typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; - static const unsigned __bits_per_word = _In::__bits_per_word; + static const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -551,7 +546,7 @@ __copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_C typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; - static const unsigned __bits_per_word = _In::__bits_per_word; + const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -600,7 +595,7 @@ __copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator< typedef __bit_iterator<_Cp, _IsConst> _In; typedef typename _In::difference_type difference_type; typedef typename _In::__storage_type __storage_type; - static const unsigned __bits_per_word = _In::__bits_per_word; + const int __bits_per_word = _In::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -718,7 +713,7 @@ __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, typedef __bit_iterator<__C1, false> _I1; typedef typename _I1::difference_type difference_type; typedef typename _I1::__storage_type __storage_type; - static const unsigned __bits_per_word = _I1::__bits_per_word; + const int __bits_per_word = _I1::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -768,7 +763,7 @@ __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1 typedef __bit_iterator<__C1, false> _I1; typedef typename _I1::difference_type difference_type; typedef typename _I1::__storage_type __storage_type; - static const unsigned __bits_per_word = _I1::__bits_per_word; + const int __bits_per_word = _I1::__bits_per_word; difference_type __n = __last - __first; if (__n > 0) { @@ -959,7 +954,7 @@ __equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> typedef __bit_iterator<_Cp, _IC1> _It; typedef typename _It::difference_type difference_type; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + static const int __bits_per_word = _It::__bits_per_word; difference_type __n = __last1 - __first1; if (__n > 0) { @@ -1041,7 +1036,7 @@ __equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __ typedef __bit_iterator<_Cp, _IC1> _It; typedef typename _It::difference_type difference_type; typedef typename _It::__storage_type __storage_type; - static const unsigned __bits_per_word = _It::__bits_per_word; + static const int __bits_per_word = _It::__bits_per_word; difference_type __n = __last1 - __first1; if (__n > 0) { @@ -1221,11 +1216,8 @@ private: __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT : __seg_(__s), __ctz_(__ctz) {} -#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC) friend typename _Cp::__self; -#else - friend class _Cp::__self; -#endif + friend class __bit_reference<_Cp>; friend class __bit_const_reference<_Cp>; friend class __bit_iterator<_Cp, true>; @@ -1283,4 +1275,6 @@ private: _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___BIT_REFERENCE diff --git a/lib/libcxx/include/__bsd_locale_defaults.h b/lib/libcxx/include/__bsd_locale_defaults.h index f315ca2949e..cbc407d1030 100644 --- a/lib/libcxx/include/__bsd_locale_defaults.h +++ b/lib/libcxx/include/__bsd_locale_defaults.h @@ -15,6 +15,10 @@ #ifndef _LIBCPP_BSD_LOCALE_DEFAULTS_H #define _LIBCPP_BSD_LOCALE_DEFAULTS_H +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + #define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) #define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) #define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) diff --git a/lib/libcxx/include/__bsd_locale_fallbacks.h b/lib/libcxx/include/__bsd_locale_fallbacks.h index cbc8ad226fd..5e9e0948307 100644 --- a/lib/libcxx/include/__bsd_locale_fallbacks.h +++ b/lib/libcxx/include/__bsd_locale_fallbacks.h @@ -15,31 +15,33 @@ #define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H #include <stdlib.h> +#include <stdarg.h> #include <memory> -_LIBCPP_BEGIN_NAMESPACE_STD +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif -typedef _VSTD::remove_pointer<locale_t>::type __use_locale_struct; -typedef _VSTD::unique_ptr<__use_locale_struct, decltype(&uselocale)> __locale_raii; +_LIBCPP_BEGIN_NAMESPACE_STD inline _LIBCPP_ALWAYS_INLINE decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return MB_CUR_MAX; } inline _LIBCPP_ALWAYS_INLINE wint_t __libcpp_btowc_l(int __c, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return btowc(__c); } inline _LIBCPP_ALWAYS_INLINE int __libcpp_wctob_l(wint_t __c, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return wctob(__c); } @@ -47,14 +49,14 @@ inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, size_t __len, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return wcsnrtombs(__dest, __src, __nwc, __len, __ps); } inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return wcrtomb(__s, __wc, __ps); } @@ -62,7 +64,7 @@ inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, size_t __len, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return mbsnrtowcs(__dest, __src, __nms, __len, __ps); } @@ -70,28 +72,28 @@ inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return mbrtowc(__pwc, __s, __n, __ps); } inline _LIBCPP_ALWAYS_INLINE int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return mbtowc(__pwc, __pmb, __max); } inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return mbrlen(__s, __n, __ps); } inline _LIBCPP_ALWAYS_INLINE lconv *__libcpp_localeconv_l(locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return localeconv(); } @@ -99,7 +101,7 @@ inline _LIBCPP_ALWAYS_INLINE size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, mbstate_t *__ps, locale_t __l) { - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); return mbsrtowcs(__dest, __src, __len, __ps); } @@ -107,7 +109,7 @@ inline int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { va_list __va; va_start(__va, __format); - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); int __res = vsnprintf(__s, __n, __format, __va); va_end(__va); return __res; @@ -117,7 +119,7 @@ inline int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) { va_list __va; va_start(__va, __format); - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); int __res = vasprintf(__s, __format, __va); va_end(__va); return __res; @@ -127,7 +129,7 @@ inline int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { va_list __va; va_start(__va, __format); - __locale_raii __current( uselocale(__l), uselocale ); + __libcpp_locale_guard __current(__l); int __res = vsscanf(__s, __format, __va); va_end(__va); return __res; diff --git a/lib/libcxx/include/__config_site.in b/lib/libcxx/include/__config_site.in index 6c2b7bb446d..86418a3e17b 100644 --- a/lib/libcxx/include/__config_site.in +++ b/lib/libcxx/include/__config_site.in @@ -12,6 +12,8 @@ #cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ #cmakedefine _LIBCPP_ABI_UNSTABLE +#cmakedefine _LIBCPP_ABI_FORCE_ITANIUM +#cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT #cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE #cmakedefine _LIBCPP_HAS_NO_STDIN #cmakedefine _LIBCPP_HAS_NO_STDOUT @@ -20,5 +22,11 @@ #cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS #cmakedefine _LIBCPP_HAS_MUSL_LIBC #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD +#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL +#cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL +#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#cmakedefine _LIBCPP_NO_VCRUNTIME + +@_LIBCPP_ABI_DEFINES@ #endif // _LIBCPP_CONFIG_SITE diff --git a/lib/libcxx/include/__debug b/lib/libcxx/include/__debug index a21f9a89884..d01bacdf7ed 100644 --- a/lib/libcxx/include/__debug +++ b/lib/libcxx/include/__debug @@ -17,23 +17,103 @@ #pragma GCC system_header #endif -#if _LIBCPP_DEBUG_LEVEL >= 1 +#if defined(_LIBCPP_HAS_NO_NULLPTR) +# include <cstddef> +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) # include <cstdlib> # include <cstdio> # include <cstddef> -# ifndef _LIBCPP_ASSERT -# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::fprintf(stderr, "%s\n", m), _VSTD::abort())) -# endif +# include <exception> +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_ASSERT) +# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : \ + _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m))) +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 2 +#ifndef _LIBCPP_DEBUG_ASSERT +#define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m) +#endif +#define _LIBCPP_DEBUG_MODE(...) __VA_ARGS__ #endif #ifndef _LIBCPP_ASSERT # define _LIBCPP_ASSERT(x, m) ((void)0) #endif +#ifndef _LIBCPP_DEBUG_ASSERT +# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) +#endif +#ifndef _LIBCPP_DEBUG_MODE +#define _LIBCPP_DEBUG_MODE(...) ((void)0) +#endif -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL < 1 +class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception; +#endif _LIBCPP_BEGIN_NAMESPACE_STD +struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info() + : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) + : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} + const char* __file_; + int __line_; + const char* __pred_; + const char* __msg_; +}; + +/// __libcpp_debug_function_type - The type of the assertion failure handler. +typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&); + +/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT +/// fails. +extern _LIBCPP_EXTERN_VIS __libcpp_debug_function_type __libcpp_debug_function; + +/// __libcpp_abort_debug_function - A debug handler that aborts when called. +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __libcpp_abort_debug_function(__libcpp_debug_info const&); + +/// __libcpp_throw_debug_function - A debug handler that throws +/// an instance of __libcpp_debug_exception when called. + _LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __libcpp_throw_debug_function(__libcpp_debug_info const&); + +/// __libcpp_set_debug_function - Set the debug handler to the specified +/// function. +_LIBCPP_FUNC_VIS +bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); + +// Setup the throwing debug handler during dynamic initialization. +#if _LIBCPP_DEBUG_LEVEL >= 1 && defined(_LIBCPP_DEBUG_USE_EXCEPTIONS) +# if defined(_LIBCPP_NO_EXCEPTIONS) +# error _LIBCPP_DEBUG_USE_EXCEPTIONS cannot be used when exceptions are disabled. +# endif +static bool __init_dummy = __libcpp_set_debug_function(__libcpp_throw_debug_function); +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) +class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception : public exception { +public: + __libcpp_debug_exception() _NOEXCEPT; + explicit __libcpp_debug_exception(__libcpp_debug_info const& __i); + __libcpp_debug_exception(__libcpp_debug_exception const&); + ~__libcpp_debug_exception() _NOEXCEPT; + const char* what() const _NOEXCEPT; +private: + struct __libcpp_debug_exception_imp; + __libcpp_debug_exception_imp *__imp_; +}; +#endif + +#if _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY) + struct _LIBCPP_TYPE_VIS __c_node; struct _LIBCPP_TYPE_VIS __i_node @@ -42,7 +122,7 @@ struct _LIBCPP_TYPE_VIS __i_node __i_node* __next_; __c_node* __c_; -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __i_node(const __i_node&) = delete; __i_node& operator=(const __i_node&) = delete; #else @@ -65,7 +145,7 @@ struct _LIBCPP_TYPE_VIS __c_node __i_node** end_; __i_node** cap_; -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __c_node(const __c_node&) = delete; __c_node& operator=(const __c_node&) = delete; #else @@ -102,7 +182,7 @@ struct _C_node }; template <class _Cont> -bool +inline bool _C_node<_Cont>::__dereferenceable(const void* __i) const { typedef typename _Cont::const_iterator iterator; @@ -112,7 +192,7 @@ _C_node<_Cont>::__dereferenceable(const void* __i) const } template <class _Cont> -bool +inline bool _C_node<_Cont>::__decrementable(const void* __i) const { typedef typename _Cont::const_iterator iterator; @@ -122,7 +202,7 @@ _C_node<_Cont>::__decrementable(const void* __i) const } template <class _Cont> -bool +inline bool _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const { typedef typename _Cont::const_iterator iterator; @@ -132,7 +212,7 @@ _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const } template <class _Cont> -bool +inline bool _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const { typedef typename _Cont::const_iterator iterator; @@ -152,7 +232,7 @@ class _LIBCPP_TYPE_VIS __libcpp_db __libcpp_db(); public: -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __libcpp_db(const __libcpp_db&) = delete; __libcpp_db& operator=(const __libcpp_db&) = delete; #else @@ -214,9 +294,9 @@ _LIBCPP_FUNC_VIS __libcpp_db* __get_db(); _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db(); -_LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY) -#endif +_LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_DEBUG_H diff --git a/lib/libcxx/include/__functional_03 b/lib/libcxx/include/__functional_03 index 4edbb0996ca..13d8a3d9600 100644 --- a/lib/libcxx/include/__functional_03 +++ b/lib/libcxx/include/__functional_03 @@ -445,7 +445,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const } // __function template<class _Rp> -class _LIBCPP_TYPE_VIS_ONLY function<_Rp()> +class _LIBCPP_TEMPLATE_VIS function<_Rp()> { typedef __function::__base<_Rp()> __base; aligned_storage<3*sizeof(void*)>::type __buf_; @@ -642,6 +642,8 @@ template<class _Rp> void function<_Rp()>::swap(function& __f) { + if (_VSTD::addressof(__f) == this) + return; if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -679,10 +681,8 @@ template<class _Rp> _Rp function<_Rp()>::operator()() const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(); } @@ -704,7 +704,7 @@ function<_Rp()>::target() { if (__f_ == 0) return (_Tp*)0; - return (_Tp*)__f_->target(typeid(_Tp)); + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); } template<class _Rp> @@ -720,7 +720,7 @@ function<_Rp()>::target() const #endif // _LIBCPP_NO_RTTI template<class _Rp, class _A0> -class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)> : public unary_function<_A0, _Rp> { typedef __function::__base<_Rp(_A0)> __base; @@ -918,6 +918,8 @@ template<class _Rp, class _A0> void function<_Rp(_A0)>::swap(function& __f) { + if (_VSTD::addressof(__f) == this) + return; if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -955,10 +957,8 @@ template<class _Rp, class _A0> _Rp function<_Rp(_A0)>::operator()(_A0 __a0) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(__a0); } @@ -980,7 +980,7 @@ function<_Rp(_A0)>::target() { if (__f_ == 0) return (_Tp*)0; - return (_Tp*)__f_->target(typeid(_Tp)); + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); } template<class _Rp, class _A0> @@ -996,7 +996,7 @@ function<_Rp(_A0)>::target() const #endif // _LIBCPP_NO_RTTI template<class _Rp, class _A0, class _A1> -class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)> : public binary_function<_A0, _A1, _Rp> { typedef __function::__base<_Rp(_A0, _A1)> __base; @@ -1194,6 +1194,8 @@ template<class _Rp, class _A0, class _A1> void function<_Rp(_A0, _A1)>::swap(function& __f) { + if (_VSTD::addressof(__f) == this) + return; if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -1231,10 +1233,8 @@ template<class _Rp, class _A0, class _A1> _Rp function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(__a0, __a1); } @@ -1256,7 +1256,7 @@ function<_Rp(_A0, _A1)>::target() { if (__f_ == 0) return (_Tp*)0; - return (_Tp*)__f_->target(typeid(_Tp)); + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); } template<class _Rp, class _A0, class _A1> @@ -1272,7 +1272,7 @@ function<_Rp(_A0, _A1)>::target() const #endif // _LIBCPP_NO_RTTI template<class _Rp, class _A0, class _A1, class _A2> -class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)> { typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; aligned_storage<3*sizeof(void*)>::type __buf_; @@ -1470,6 +1470,8 @@ template<class _Rp, class _A0, class _A1, class _A2> void function<_Rp(_A0, _A1, _A2)>::swap(function& __f) { + if (_VSTD::addressof(__f) == this) + return; if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -1507,10 +1509,8 @@ template<class _Rp, class _A0, class _A1, class _A2> _Rp function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(__a0, __a1, __a2); } @@ -1532,7 +1532,7 @@ function<_Rp(_A0, _A1, _A2)>::target() { if (__f_ == 0) return (_Tp*)0; - return (_Tp*)__f_->target(typeid(_Tp)); + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); } template<class _Rp, class _A0, class _A1, class _A2> diff --git a/lib/libcxx/include/__functional_base b/lib/libcxx/include/__functional_base index 1a08ea29dee..12af4dc9675 100644 --- a/lib/libcxx/include/__functional_base +++ b/lib/libcxx/include/__functional_base @@ -16,6 +16,7 @@ #include <typeinfo> #include <exception> #include <new> +#include <utility> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -23,15 +24,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Arg, class _Result> -struct _LIBCPP_TYPE_VIS_ONLY unary_function -{ - typedef _Arg argument_type; - typedef _Result result_type; -}; - template <class _Arg1, class _Arg2, class _Result> -struct _LIBCPP_TYPE_VIS_ONLY binary_function +struct _LIBCPP_TEMPLATE_VIS binary_function { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; @@ -54,7 +48,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -63,7 +57,7 @@ struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY less<void> +struct _LIBCPP_TEMPLATE_VIS less<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -257,7 +251,7 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> }; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG // 3 or more arguments template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> @@ -302,10 +296,6 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> typedef _Rp result_type; }; -#endif // _LIBCPP_HAS_NO_VARIADICS - -#ifndef _LIBCPP_CXX03_LANG - template <class _Tp, class ..._Args> struct __invoke_return { @@ -322,7 +312,7 @@ struct __invoke_return template <class _Ret> struct __invoke_void_return_wrapper { -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class ..._Args> static _Ret __call(_Args&&... __args) { return __invoke(_VSTD::forward<_Args>(__args)...); @@ -353,7 +343,7 @@ struct __invoke_void_return_wrapper template <> struct __invoke_void_return_wrapper<void> { -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class ..._Args> static void __call(_Args&&... __args) { __invoke(_VSTD::forward<_Args>(__args)...); @@ -382,7 +372,7 @@ struct __invoke_void_return_wrapper<void> }; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY reference_wrapper +class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> { public: @@ -395,7 +385,7 @@ public: // construct/copy/destroy _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT : __f_(_VSTD::addressof(__f)) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG private: reference_wrapper(type&&); public: // = delete; // do not bind to temps #endif @@ -403,7 +393,7 @@ public: _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG // invoke template <class... _ArgTypes> _LIBCPP_INLINE_VISIBILITY @@ -516,7 +506,7 @@ public: operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { return __invoke(get(), __a0, __a1, __a2); } -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG }; @@ -552,45 +542,29 @@ cref(reference_wrapper<_Tp> __t) _NOEXCEPT return cref(__t.get()); } -#ifndef _LIBCPP_HAS_NO_VARIADICS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS - +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> void ref(const _Tp&&) = delete; template <class _Tp> void cref(const _Tp&&) = delete; - -#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS - -template <class _Tp> void ref(const _Tp&&);// = delete; -template <class _Tp> void cref(const _Tp&&);// = delete; - -#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif #if _LIBCPP_STD_VER > 11 -template <class _Tp1, class _Tp2 = void> -struct __is_transparent -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::is_transparent* = 0); -public: - static const bool value = sizeof(__test<_Tp1>(0)) == 1; -}; +template <class _Tp, class, class = void> +struct __is_transparent : false_type {}; + +template <class _Tp, class _Up> +struct __is_transparent<_Tp, _Up, + typename __void_t<typename _Tp::is_transparent>::type> + : true_type {}; #endif // allocator_arg_t -struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { }; +struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { }; -#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY) +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_MEMORY) extern const allocator_arg_t allocator_arg; #else -constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +/* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); #endif // uses_allocator @@ -620,19 +594,25 @@ struct __uses_allocator<_Tp, _Alloc, false> }; template <class _Tp, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator +struct _LIBCPP_TEMPLATE_VIS uses_allocator : public __uses_allocator<_Tp, _Alloc> { }; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Alloc> +_LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; +#endif + +#ifndef _LIBCPP_CXX03_LANG // allocator construction template <class _Tp, class _Alloc, class ..._Args> struct __uses_alloc_ctor_imp { - static const bool __ua = uses_allocator<_Tp, _Alloc>::value; + typedef typename __uncvref<_Alloc>::type _RawAlloc; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; static const int value = __ua ? 2 - __ic : 0; @@ -650,6 +630,7 @@ void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, con new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); } +// FIXME: This should have a version which takes a non-const alloc. template <class _Tp, class _Allocator, class... _Args> inline _LIBCPP_INLINE_VISIBILITY void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) @@ -657,6 +638,7 @@ void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, con new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); } +// FIXME: This should have a version which takes a non-const alloc. template <class _Tp, class _Allocator, class... _Args> inline _LIBCPP_INLINE_VISIBILITY void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) @@ -664,6 +646,7 @@ void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, con new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); } +// FIXME: Theis should have a version which takes a non-const alloc. template <class _Tp, class _Allocator, class... _Args> inline _LIBCPP_INLINE_VISIBILITY void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args) @@ -673,7 +656,7 @@ void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __storage, __a, _VSTD::forward<_Args>(__args)... ); } -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__hash_table b/lib/libcxx/include/__hash_table index 08bc519ae17..3f430af1283 100644 --- a/lib/libcxx/include/__hash_table +++ b/lib/libcxx/include/__hash_table @@ -18,9 +18,7 @@ #include <algorithm> #include <cmath> #include <utility> - -#include <__undef_min_max> -#include <__undef___deallocate> +#include <type_traits> #include <__debug> @@ -28,9 +26,12 @@ #pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_PUSH_MACROS +#include <__undef_macros> +_LIBCPP_BEGIN_NAMESPACE_STD + #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp> union __hash_value_type; @@ -39,6 +40,15 @@ template <class _Key, class _Tp> struct __hash_value_type; #endif +template <class _Key, class _Cp, class _Hash, + bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value> +class __unordered_map_hasher; + +template <class _Key, class _Cp, class _Pred, + bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value + > +class __unordered_map_equal; + #ifndef _LIBCPP_CXX03_LANG template <class _Tp> struct __is_hash_value_type_imp : false_type {}; @@ -59,9 +69,38 @@ size_t __next_prime(size_t __n); template <class _NodePtr> struct __hash_node_base { + typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef __hash_node_base __first_node; + typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; + typedef _NodePtr __node_pointer; + +#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) + typedef __node_base_pointer __next_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + __node_base_pointer, + __node_pointer>::type __next_pointer; +#endif + + __next_pointer __next_; + + _LIBCPP_INLINE_VISIBILITY + __next_pointer __ptr() _NOEXCEPT { + return static_cast<__next_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __upcast() _NOEXCEPT { + return static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(*this)); + } - _NodePtr __next_; + _LIBCPP_INLINE_VISIBILITY + size_t __hash() const _NOEXCEPT { + return static_cast<__node_type const&>(*this).__hash_; + } _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} }; @@ -75,7 +114,7 @@ struct __hash_node { typedef _Tp __node_value_type; - size_t __hash_; + size_t __hash_; __node_value_type __value_; }; @@ -98,18 +137,18 @@ inline _LIBCPP_INLINE_VISIBILITY size_t __next_hash_pow2(size_t __n) { - return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1)); + return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1))); } template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table; -template <class _NodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_iterator; -template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; -template <class _NodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator; -template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; -template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator; -template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; +template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator; +template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; +template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator; +template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; +template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; +template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; template <class _Tp> struct __hash_key_value_types { @@ -219,11 +258,14 @@ public: typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type __node_base_pointer; + typedef typename __node_base_type::__next_pointer __next_pointer; + typedef _Tp __node_value_type; typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type __node_value_type_pointer; typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type __const_node_value_type_pointer; + private: static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); @@ -233,8 +275,6 @@ private: _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); }; - - template <class _HashIterator> struct __hash_node_types_from_iterator; template <class _NodePtr> @@ -255,12 +295,13 @@ struct __make_hash_node_types { }; template <class _NodePtr> -class _LIBCPP_TYPE_VIS_ONLY __hash_iterator +class _LIBCPP_TEMPLATE_VIS __hash_iterator { typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; - __node_pointer __node_; + __next_pointer __node_; public: typedef forward_iterator_tag iterator_category; @@ -269,18 +310,11 @@ public: typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; - _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT -#if _LIBCPP_STD_VER > 11 - : __node_(nullptr) -#endif - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__insert_i(this); -#endif + _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_INLINE_VISIBILITY __hash_iterator(const __hash_iterator& __i) : __node_(__i.__node_) @@ -304,35 +338,26 @@ public: } return *this; } - #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to dereference a non-dereferenceable unordered container iterator"); -#endif - return __node_->__value_; - } + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container iterator"); + return __node_->__upcast()->__value_; + } + _LIBCPP_INLINE_VISIBILITY - pointer operator->() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container iterator"); -#endif - return pointer_traits<pointer>::pointer_to(__node_->__value_); - } + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } _LIBCPP_INLINE_VISIBILITY - __hash_iterator& operator++() - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + __hash_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container iterator"); -#endif __node_ = __node_->__next_; return *this; } @@ -357,33 +382,33 @@ public: private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - __hash_iterator(__node_pointer __node, const void* __c) _NOEXCEPT + __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY - __hash_iterator(__node_pointer __node) _NOEXCEPT + __hash_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif - template <class, class, class, class> friend class __hash_table; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template <class _NodePtr> -class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator +class _LIBCPP_TEMPLATE_VIS __hash_const_iterator { static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, ""); typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; - __node_pointer __node_; + __next_pointer __node_; public: typedef __hash_iterator<_NodePtr> __non_const_iterator; @@ -395,26 +420,18 @@ public: typedef typename _NodeTypes::__const_node_value_type_pointer pointer; - _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT -#if _LIBCPP_STD_VER > 11 - : __node_(nullptr) -#endif - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__insert_i(this); -#endif + _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } + _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__iterator_copy(this, &__x); -#endif + _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); } #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_INLINE_VISIBILITY __hash_const_iterator(const __hash_const_iterator& __i) : __node_(__i.__node_) @@ -438,35 +455,25 @@ public: } return *this; } - #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_iterator"); -#endif - return __node_->__value_; - } + return __node_->__upcast()->__value_; + } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_iterator"); -#endif - return pointer_traits<pointer>::pointer_to(__node_->__value_); - } + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } _LIBCPP_INLINE_VISIBILITY - __hash_const_iterator& operator++() - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to increment non-incrementable unordered container const_iterator"); -#endif + __hash_const_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to increment non-incrementable unordered container const_iterator"); __node_ = __node_->__next_; return *this; } @@ -491,31 +498,31 @@ public: private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - __hash_const_iterator(__node_pointer __node, const void* __c) _NOEXCEPT + __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY - __hash_const_iterator(__node_pointer __node) _NOEXCEPT + __hash_const_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif - template <class, class, class, class> friend class __hash_table; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template <class _NodePtr> -class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator +class _LIBCPP_TEMPLATE_VIS __hash_local_iterator { typedef __hash_node_types<_NodePtr> _NodeTypes; - typedef _NodePtr __node_pointer; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; - __node_pointer __node_; + __next_pointer __node_; size_t __bucket_; size_t __bucket_count_; @@ -526,15 +533,11 @@ public: typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; - _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__insert_i(this); -#endif + _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_INLINE_VISIBILITY __hash_local_iterator(const __hash_local_iterator& __i) : __node_(__i.__node_), @@ -562,37 +565,28 @@ public: } return *this; } - #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container local_iterator"); -#endif - return __node_->__value_; - } + return __node_->__upcast()->__value_; + } + _LIBCPP_INLINE_VISIBILITY - pointer operator->() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to dereference a non-dereferenceable unordered container local_iterator"); -#endif - return pointer_traits<pointer>::pointer_to(__node_->__value_); - } + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable unordered container local_iterator"); + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } _LIBCPP_INLINE_VISIBILITY - __hash_local_iterator& operator++() - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + __hash_local_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container local_iterator"); -#endif __node_ = __node_->__next_; - if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_) + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } @@ -617,7 +611,7 @@ public: private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - __hash_local_iterator(__node_pointer __node, size_t __bucket, + __hash_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node), __bucket_(__bucket), @@ -629,7 +623,7 @@ private: } #else _LIBCPP_INLINE_VISIBILITY - __hash_local_iterator(__node_pointer __node, size_t __bucket, + __hash_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT : __node_(__node), __bucket_(__bucket), @@ -640,17 +634,18 @@ private: } #endif template <class, class, class, class> friend class __hash_table; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; }; template <class _ConstNodePtr> -class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator +class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator { typedef __hash_node_types<_ConstNodePtr> _NodeTypes; - typedef _ConstNodePtr __node_pointer; + typedef _ConstNodePtr __node_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; - __node_pointer __node_; + __next_pointer __node_; size_t __bucket_; size_t __bucket_count_; @@ -670,11 +665,8 @@ public: typedef typename _NodeTypes::__const_node_value_type_pointer pointer; - _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__insert_i(this); -#endif + _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) { + _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); } _LIBCPP_INLINE_VISIBILITY @@ -683,13 +675,10 @@ public: __bucket_(__x.__bucket_), __bucket_count_(__x.__bucket_count_) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __get_db()->__iterator_copy(this, &__x); -#endif + _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); } #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator(const __hash_const_local_iterator& __i) : __node_(__i.__node_), @@ -717,37 +706,28 @@ public: } return *this; } - #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - reference operator*() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + reference operator*() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); -#endif - return __node_->__value_; - } + return __node_->__upcast()->__value_; + } + _LIBCPP_INLINE_VISIBILITY - pointer operator->() const - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + pointer operator->() const { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); -#endif - return pointer_traits<pointer>::pointer_to(__node_->__value_); - } + return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); + } _LIBCPP_INLINE_VISIBILITY - __hash_const_local_iterator& operator++() - { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + __hash_const_local_iterator& operator++() { + _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable unordered container const_local_iterator"); -#endif __node_ = __node_->__next_; - if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_) + if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) __node_ = nullptr; return *this; } @@ -772,7 +752,7 @@ public: private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY - __hash_const_local_iterator(__node_pointer __node, size_t __bucket, + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node), __bucket_(__bucket), @@ -784,7 +764,7 @@ private: } #else _LIBCPP_INLINE_VISIBILITY - __hash_const_local_iterator(__node_pointer __node, size_t __bucket, + __hash_const_local_iterator(__next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT : __node_(__node), __bucket_(__bucket), @@ -795,7 +775,7 @@ private: } #endif template <class, class, class, class> friend class __hash_table; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; }; template <class _Alloc> @@ -819,8 +799,7 @@ public: _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) : __data_(__size, __a) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __bucket_list_deallocator(__bucket_list_deallocator&& __x) _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) @@ -828,8 +807,7 @@ public: { __x.size() = 0; } - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif _LIBCPP_INLINE_VISIBILITY size_type& size() _NOEXCEPT {return __data_.first();} @@ -887,6 +865,37 @@ public: template <class> friend class __hash_map_node_destructor; }; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Hash, class _Equal, class _Alloc> +struct __diagnose_hash_table_helper { + static constexpr bool __trigger_diagnostics() + _LIBCPP_DIAGNOSE_WARNING(__check_hash_requirements<_Key, _Hash>::value + && !__invokable<_Hash const&, _Key const&>::value, + "the specified hash functor does not provide a const call operator") + _LIBCPP_DIAGNOSE_WARNING(is_copy_constructible<_Equal>::value + && !__invokable<_Equal const&, _Key const&, _Key const&>::value, + "the specified comparator type does not provide a const call operator") + { + static_assert(__check_hash_requirements<_Key, _Hash>::value, + "the specified hash does not meet the Hash requirements"); + static_assert(is_copy_constructible<_Equal>::value, + "the specified comparator is required to be copy constructible"); + return true; + } +}; + +template <class _Key, class _Value, class _Hash, class _Equal, class _Alloc> +struct __diagnose_hash_table_helper< + __hash_value_type<_Key, _Value>, + __unordered_map_hasher<_Key, __hash_value_type<_Key, _Value>, _Hash>, + __unordered_map_equal<_Key, __hash_value_type<_Key, _Value>, _Equal>, + _Alloc> +: __diagnose_hash_table_helper<_Key, _Hash, _Equal, _Alloc> +{ +}; +#endif // _LIBCPP_CXX03_LANG + template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table { @@ -927,6 +936,7 @@ public: typedef typename _NodeTypes::__node_pointer __node_const_pointer; typedef typename _NodeTypes::__node_base_type __first_node; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__next_pointer __next_pointer; private: // check for sane allocator pointer rebinding semantics. Rebinding the @@ -942,11 +952,15 @@ private: private: - typedef typename __rebind_alloc_helper<__node_traits, __node_pointer>::type __pointer_allocator; + typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; - typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list; + typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; - typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; + +#ifndef _LIBCPP_CXX03_LANG + static_assert(__diagnose_hash_table_helper<_Tp, _Hash, _Equal, _Alloc>::__trigger_diagnostics(), ""); +#endif // --- Member data begin --- __bucket_list __bucket_list_; @@ -1033,8 +1047,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { - return allocator_traits<__pointer_allocator>::max_size( - __bucket_list_.get_deleter().__alloc()); + return std::min<size_type>( + __node_traits::max_size(__node_alloc()), + numeric_limits<difference_type >::max() + ); } pair<iterator, bool> __node_insert_unique(__node_pointer __nd); @@ -1129,6 +1145,7 @@ public: #else // !defined(_LIBCPP_CXX03_LANG) template <class _Key, class _Args> + _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args); iterator __insert_multi(const __container_value_type& __x); @@ -1207,7 +1224,7 @@ public: void swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 - _NOEXCEPT_( + _NOEXCEPT_DEBUG_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) @@ -1215,12 +1232,12 @@ public: || __is_nothrow_swappable<__node_allocator>::value) ); #else - _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); + _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); #endif _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const _NOEXCEPT - {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());} + {return max_size(); } size_type bucket_size(size_type __n) const; _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT { @@ -1347,11 +1364,11 @@ private: void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} #endif // _LIBCPP_CXX03_LANG - void __deallocate(__node_pointer __np) _NOEXCEPT; - __node_pointer __detach() _NOEXCEPT; + void __deallocate_node(__next_pointer __np) _NOEXCEPT; + __next_pointer __detach() _NOEXCEPT; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; }; template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -1384,7 +1401,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__node_allocator(__a)), + __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, __hf), __p3_(1.0f, __eql) { @@ -1393,7 +1410,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, template <class _Tp, class _Hash, class _Equal, class _Alloc> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__node_allocator(__a)), + __p1_(__second_tag(), __node_allocator(__a)), __p2_(0), __p3_(1.0f) { @@ -1405,7 +1422,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) __bucket_list_deleter(allocator_traits<__pointer_allocator>:: select_on_container_copy_construction( __u.__bucket_list_.get_deleter().__alloc()), 0)), - __p1_(allocator_traits<__node_allocator>:: + __p1_(__second_tag(), allocator_traits<__node_allocator>:: select_on_container_copy_construction(__u.__node_alloc())), __p2_(0, __u.hash_function()), __p3_(__u.__p3_) @@ -1416,7 +1433,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__node_allocator(__a)), + __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, __u.hash_function()), __p3_(__u.__p3_) { @@ -1439,8 +1456,8 @@ __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>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } @@ -1450,7 +1467,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__node_allocator(__a)), + __p1_(__second_tag(), __node_allocator(__a)), __p2_(0, _VSTD::move(__u.hash_function())), __p3_(_VSTD::move(__u.__p3_)) { @@ -1463,8 +1480,8 @@ __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>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); size() = __u.size(); __u.size() = 0; } @@ -1476,11 +1493,14 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, template <class _Tp, class _Hash, class _Equal, class _Alloc> __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { +#if defined(_LIBCPP_CXX03_LANG) static_assert((is_copy_constructible<key_equal>::value), "Predicate must be copy-constructible."); static_assert((is_copy_constructible<hasher>::value), "Hasher must be copy-constructible."); - __deallocate(__p1_.first().__next_); +#endif + + __deallocate_node(__p1_.first().__next_); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__erase_c(this); #endif @@ -1518,13 +1538,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) template <class _Tp, class _Hash, class _Equal, class _Alloc> void -__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np) +__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) _NOEXCEPT { __node_allocator& __na = __node_alloc(); while (__np != nullptr) { - __node_pointer __next = __np->__next_; + __next_pointer __next = __np->__next_; #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __p = __c->end_; __p != __c->beg_; ) @@ -1540,21 +1560,22 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np) } __get_db()->unlock(); #endif - __node_traits::destroy(__na, _NodeTypes::__get_ptr(__np->__value_)); - __node_traits::deallocate(__na, __np, 1); + __node_pointer __real_np = __np->__upcast(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); + __node_traits::deallocate(__na, __real_np, 1); __np = __next; } } template <class _Tp, class _Hash, class _Equal, class _Alloc> -typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer +typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; size() = 0; - __node_pointer __cache = __p1_.first().__next_; + __next_pointer __cache = __p1_.first().__next_; __p1_.first().__next_ = nullptr; return __cache; } @@ -1582,8 +1603,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( __p1_.first().__next_ = __u.__p1_.first().__next_; if (size() > 0) { - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } @@ -1606,7 +1627,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( max_load_factor() = __u.max_load_factor(); if (bucket_count() != 0) { - __node_pointer __cache = __detach(); + __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { @@ -1614,20 +1635,21 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( const_iterator __i = __u.begin(); while (__cache != nullptr && __u.size() != 0) { - __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_); - __node_pointer __next = __cache->__next_; - __node_insert_multi(__cache); + __cache->__upcast()->__value_ = + _VSTD::move(__u.remove(__i++)->__value_); + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - __deallocate(__cache); + __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __deallocate(__cache); + __deallocate_node(__cache); } const_iterator __i = __u.begin(); while (__u.size() != 0) @@ -1669,27 +1691,27 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first if (bucket_count() != 0) { - __node_pointer __cache = __detach(); + __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { - __cache->__value_ = *__first; - __node_pointer __next = __cache->__next_; - __node_insert_unique(__cache); + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_unique(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - __deallocate(__cache); + __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __deallocate(__cache); + __deallocate_node(__cache); } for (; __first != __last; ++__first) __insert_unique(*__first); @@ -1709,27 +1731,27 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, " or the nodes value type"); if (bucket_count() != 0) { - __node_pointer __cache = __detach(); + __next_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { - __cache->__value_ = *__first; - __node_pointer __next = __cache->__next_; - __node_insert_multi(__cache); + __cache->__upcast()->__value_ = *__first; + __next_pointer __next = __cache->__next_; + __node_insert_multi(__cache->__upcast()); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - __deallocate(__cache); + __deallocate_node(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __deallocate(__cache); + __deallocate_node(__cache); } for (; __first != __last; ++__first) __insert_multi(_NodeTypes::__get_value(*__first)); @@ -1789,7 +1811,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { if (size() > 0) { - __deallocate(__p1_.first().__next_); + __deallocate_node(__p1_.first().__next_); __p1_.first().__next_ = nullptr; size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) @@ -1805,7 +1827,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __ __nd->__hash_ = hash_function()(__nd->__value_); size_type __bc = bucket_count(); bool __inserted = false; - __node_pointer __ndptr; + __next_pointer __ndptr; size_t __chash; if (__bc != 0) { @@ -1814,10 +1836,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __ if (__ndptr != nullptr) { for (__ndptr = __ndptr->__next_; __ndptr != nullptr && - __constrain_hash(__ndptr->__hash_, __bc) == __chash; + __constrain_hash(__ndptr->__hash(), __bc) == __chash; __ndptr = __ndptr->__next_) { - if (key_eq()(__ndptr->__value_, __nd->__value_)) + if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_)) goto __done; } } @@ -1831,23 +1853,23 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __ __chash = __constrain_hash(__nd->__hash_, __bc); } // insert_after __bucket_list_[__chash], or __first_node if bucket is null - __node_pointer __pn = __bucket_list_[__chash]; + __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __pn =__p1_.first().__ptr(); __nd->__next_ = __pn->__next_; - __pn->__next_ = __nd; + __pn->__next_ = __nd->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__nd->__next_ != nullptr) - __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd; + __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); } else { __nd->__next_ = __pn->__next_; - __pn->__next_ = __nd; + __pn->__next_ = __nd->__ptr(); } - __ndptr = __nd; + __ndptr = __nd->__ptr(); // increment size ++size(); __inserted = true; @@ -1873,21 +1895,22 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c __bc = bucket_count(); } size_t __chash = __constrain_hash(__cp->__hash_, __bc); - __node_pointer __pn = __bucket_list_[__chash]; + __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __pn =__p1_.first().__ptr(); __cp->__next_ = __pn->__next_; - __pn->__next_ = __cp; + __pn->__next_ = __cp->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__cp->__next_ != nullptr) - __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp; + __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] + = __cp->__ptr(); } else { for (bool __found = false; __pn->__next_ != nullptr && - __constrain_hash(__pn->__next_->__hash_, __bc) == __chash; + __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; __pn = __pn->__next_) { // __found key_eq() action @@ -1895,8 +1918,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c // true true loop // false true set __found to true // true false break - if (__found != (__pn->__next_->__hash_ == __cp->__hash_ && - key_eq()(__pn->__next_->__value_, __cp->__value_))) + if (__found != (__pn->__next_->__hash() == __cp->__hash_ && + key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_))) { if (!__found) __found = true; @@ -1905,19 +1928,19 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __c } } __cp->__next_ = __pn->__next_; - __pn->__next_ = __cp; + __pn->__next_ = __cp->__ptr(); if (__cp->__next_ != nullptr) { - size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc); + size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); if (__nhash != __chash) - __bucket_list_[__nhash] = __cp; + __bucket_list_[__nhash] = __cp->__ptr(); } } ++size(); #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(__cp, this); + return iterator(__cp->__ptr(), this); #else - return iterator(__cp); + return iterator(__cp->__ptr()); #endif } @@ -1933,8 +1956,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( #endif if (__p != end() && key_eq()(*__p, __cp->__value_)) { - __node_pointer __np = __p.__node_; - __cp->__hash_ = __np->__hash_; + __next_pointer __np = __p.__node_; + __cp->__hash_ = __np->__hash(); size_type __bc = bucket_count(); if (size()+1 > __bc * max_load_factor() || __bc == 0) { @@ -1943,16 +1966,16 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( __bc = bucket_count(); } size_t __chash = __constrain_hash(__cp->__hash_, __bc); - __node_pointer __pp = __bucket_list_[__chash]; + __next_pointer __pp = __bucket_list_[__chash]; while (__pp->__next_ != __np) __pp = __pp->__next_; __cp->__next_ = __np; - __pp->__next_ = __cp; + __pp->__next_ = static_cast<__next_pointer>(__cp); ++size(); #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(__cp, this); + return iterator(static_cast<__next_pointer>(__cp), this); #else - return iterator(__cp); + return iterator(static_cast<__next_pointer>(__cp)); #endif } return __node_insert_multi(__cp); @@ -1963,13 +1986,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( #ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Hash, class _Equal, class _Alloc> template <class _Key, class ..._Args> -_LIBCPP_INLINE_VISIBILITY pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) #else template <class _Tp, class _Hash, class _Equal, class _Alloc> template <class _Key, class _Args> -_LIBCPP_INLINE_VISIBILITY pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) #endif @@ -1978,7 +1999,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& size_t __hash = hash_function()(__k); size_type __bc = bucket_count(); bool __inserted = false; - __node_pointer __nd; + __next_pointer __nd; size_t __chash; if (__bc != 0) { @@ -1987,10 +2008,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && - __constrain_hash(__nd->__hash_, __bc) == __chash; + (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { - if (key_eq()(__nd->__value_, __k)) + if (key_eq()(__nd->__upcast()->__value_, __k)) goto __done; } } @@ -2009,23 +2030,24 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __chash = __constrain_hash(__hash, __bc); } // insert_after __bucket_list_[__chash], or __first_node if bucket is null - __node_pointer __pn = __bucket_list_[__chash]; + __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = static_cast<__node_pointer>(static_cast<__void_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))); + __pn = __p1_.first().__ptr(); __h->__next_ = __pn->__next_; - __pn->__next_ = __h.get(); + __pn->__next_ = __h.get()->__ptr(); // fix up __bucket_list_ __bucket_list_[__chash] = __pn; if (__h->__next_ != nullptr) - __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get(); + __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] + = __h.get()->__ptr(); } else { __h->__next_ = __pn->__next_; - __pn->__next_ = __h.get(); + __pn->__next_ = static_cast<__next_pointer>(__h.get()); } - __nd = __h.release(); + __nd = static_cast<__next_pointer>(__h.release()); // increment size ++size(); __inserted = true; @@ -2149,17 +2171,17 @@ __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>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))); - __node_pointer __cp = __pp->__next_; + __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __cp = __pp->__next_; if (__cp != nullptr) { - size_type __chash = __constrain_hash(__cp->__hash_, __nbc); + size_type __chash = __constrain_hash(__cp->__hash(), __nbc); __bucket_list_[__chash] = __pp; size_type __phash = __chash; for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; __cp = __pp->__next_) { - __chash = __constrain_hash(__cp->__hash_, __nbc); + __chash = __constrain_hash(__cp->__hash(), __nbc); if (__chash == __phash) __pp = __cp; else @@ -2172,9 +2194,10 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) } else { - __node_pointer __np = __cp; + __next_pointer __np = __cp; for (; __np->__next_ != nullptr && - key_eq()(__cp->__value_, __np->__next_->__value_); + key_eq()(__cp->__upcast()->__value_, + __np->__next_->__upcast()->__value_); __np = __np->__next_) ; __pp->__next_ = __np->__next_; @@ -2198,15 +2221,16 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) if (__bc != 0) { size_t __chash = __constrain_hash(__hash, __bc); - __node_pointer __nd = __bucket_list_[__chash]; + __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && - (__nd->__hash_ == __hash - || __constrain_hash(__nd->__hash_, __bc) == __chash); + (__nd->__hash() == __hash + || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { - if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k)) + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__nd, this); #else @@ -2228,14 +2252,16 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const if (__bc != 0) { size_t __chash = __constrain_hash(__hash, __bc); - __node_const_pointer __nd = __bucket_list_[__chash]; + __next_pointer __nd = __bucket_list_[__chash]; if (__nd != nullptr) { for (__nd = __nd->__next_; __nd != nullptr && - (__hash == __nd->__hash_ || __constrain_hash(__nd->__hash_, __bc) == __chash); + (__hash == __nd->__hash() + || __constrain_hash(__nd->__hash(), __bc) == __chash); __nd = __nd->__next_) { - if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k)) + if ((__nd->__hash() == __hash) + && key_eq()(__nd->__upcast()->__value_, __k)) #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(__nd, this); #else @@ -2320,7 +2346,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 = __p.__node_; + __next_pointer __np = __p.__node_; #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered container erase(iterator) called with an iterator not" @@ -2354,7 +2380,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, ++__first; erase(__p); } - __node_pointer __np = __last.__node_; + __next_pointer __np = __last.__node_; #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator (__np, this); #else @@ -2398,26 +2424,27 @@ 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 = __p.__node_; + __next_pointer __cn = __p.__node_; size_type __bc = bucket_count(); - size_t __chash = __constrain_hash(__cn->__hash_, __bc); + size_t __chash = __constrain_hash(__cn->__hash(), __bc); // find previous node - __node_pointer __pn = __bucket_list_[__chash]; + __next_pointer __pn = __bucket_list_[__chash]; for (; __pn->__next_ != __cn; __pn = __pn->__next_) ; // 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 == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())) - || __constrain_hash(__pn->__hash_, __bc) != __chash) + if (__pn == __p1_.first().__ptr() + || __constrain_hash(__pn->__hash(), __bc) != __chash) { - if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash) + if (__cn->__next_ == nullptr + || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) __bucket_list_[__chash] = nullptr; } // if __cn->__next_ is not in same bucket (nullptr is in same bucket) if (__cn->__next_ != nullptr) { - size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc); + size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); if (__nhash != __chash) __bucket_list_[__nhash] = __pn; } @@ -2427,20 +2454,20 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT --size(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); - for (__i_node** __p = __c->end_; __p != __c->beg_; ) + for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) { - --__p; - iterator* __i = static_cast<iterator*>((*__p)->__i_); + --__dp; + iterator* __i = static_cast<iterator*>((*__dp)->__i_); if (__i->__node_ == __cn) { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + (*__dp)->__c_ = nullptr; + if (--__c->end_ != __dp) + memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif - return __node_holder(__cn, _Dp(__node_alloc(), true)); + return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -2543,7 +2570,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 - _NOEXCEPT_( + _NOEXCEPT_DEBUG_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) @@ -2551,9 +2578,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) || __is_nothrow_swappable<__node_allocator>::value) ) #else - _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) + _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) #endif { + _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value || + this->__node_alloc() == __u.__node_alloc(), + "list::swap: Either propagate_on_container_swap must be true" + " or the allocators must compare equal"); { __node_pointer_pointer __npp = __bucket_list_.release(); __bucket_list_.reset(__u.__bucket_list_.release()); @@ -2567,11 +2598,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) __p2_.swap(__u.__p2_); __p3_.swap(__u.__p3_); if (size() > 0) - __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] = - static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())); + __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = + __p1_.first().__ptr(); if (__u.size() > 0) - __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] = - static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first())); + __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = + __u.__p1_.first().__ptr(); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__u); #endif @@ -2583,13 +2614,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { _LIBCPP_ASSERT(__n < bucket_count(), "unordered container::bucket_size(n) called with n >= bucket_count()"); - __node_const_pointer __np = __bucket_list_[__n]; + __next_pointer __np = __bucket_list_[__n]; size_type __bc = bucket_count(); size_type __r = 0; if (__np != nullptr) { for (__np = __np->__next_; __np != nullptr && - __constrain_hash(__np->__hash_, __bc) == __n; + __constrain_hash(__np->__hash(), __bc) == __n; __np = __np->__next_, ++__r) ; } @@ -2637,6 +2668,9 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, } #endif // _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP__HASH_TABLE diff --git a/lib/libcxx/include/__libcpp_version b/lib/libcxx/include/__libcpp_version new file mode 100644 index 00000000000..a77fd92cf17 --- /dev/null +++ b/lib/libcxx/include/__libcpp_version @@ -0,0 +1 @@ +6000 diff --git a/lib/libcxx/include/__mutex_base b/lib/libcxx/include/__mutex_base index 38a76ac6f2e..402a52d945e 100644 --- a/lib/libcxx/include/__mutex_base +++ b/lib/libcxx/include/__mutex_base @@ -16,10 +16,15 @@ #include <system_error> #include <__threading_support> + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_THREADS @@ -34,7 +39,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex { -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#ifndef _LIBCPP_CXX03_LANG __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; #else __libcpp_mutex_t __m_; @@ -42,8 +47,8 @@ class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mut public: _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_CONSTEXPR - constexpr mutex() _NOEXCEPT _LIBCPP_DEFAULT +#ifndef _LIBCPP_CXX03_LANG + constexpr mutex() = default; #else mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;} #endif @@ -62,11 +67,14 @@ public: _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;} }; +static_assert(is_nothrow_default_constructible<mutex>::value, + "the default constructor for std::mutex must be nothrow"); + struct _LIBCPP_TYPE_VIS defer_lock_t {}; struct _LIBCPP_TYPE_VIS try_to_lock_t {}; struct _LIBCPP_TYPE_VIS adopt_lock_t {}; -#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MUTEX) +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_MUTEX) extern const defer_lock_t defer_lock; extern const try_to_lock_t try_to_lock; @@ -74,27 +82,15 @@ extern const adopt_lock_t adopt_lock; #else -constexpr defer_lock_t defer_lock = defer_lock_t(); -constexpr try_to_lock_t try_to_lock = try_to_lock_t(); -constexpr adopt_lock_t adopt_lock = adopt_lock_t(); - -#endif - +/* _LIBCPP_INLINE_VAR */ constexpr defer_lock_t defer_lock = defer_lock_t(); +/* _LIBCPP_INLINE_VAR */ constexpr try_to_lock_t try_to_lock = try_to_lock_t(); +/* _LIBCPP_INLINE_VAR */ constexpr adopt_lock_t adopt_lock = adopt_lock_t(); -// Forward declare lock_guard as a variadic template even in C++03 to keep -// the mangling consistent between dialects. -#if defined(_LIBCPP_ABI_VARIADIC_LOCK_GUARD) -template <class ..._Mutexes> -class _LIBCPP_TYPE_VIS_ONLY lock_guard; #endif template <class _Mutex> -class _LIBCPP_TYPE_VIS_ONLY _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) -#if !defined(_LIBCPP_ABI_VARIADIC_LOCK_GUARD) +class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) lock_guard -#else -lock_guard<_Mutex> -#endif { public: typedef _Mutex mutex_type; @@ -118,7 +114,7 @@ private: }; template <class _Mutex> -class _LIBCPP_TYPE_VIS_ONLY unique_lock +class _LIBCPP_TEMPLATE_VIS unique_lock { public: typedef _Mutex mutex_type; @@ -162,7 +158,7 @@ private: unique_lock& operator=(unique_lock const&); // = delete; public: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unique_lock(unique_lock&& __u) _NOEXCEPT : __m_(__u.__m_), __owns_(__u.__owns_) @@ -179,7 +175,7 @@ public: return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG void lock(); bool try_lock(); @@ -291,7 +287,7 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) class _LIBCPP_TYPE_VIS condition_variable { -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#ifndef _LIBCPP_CXX03_LANG __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; #else __libcpp_condvar_t __cv_; @@ -299,8 +295,8 @@ class _LIBCPP_TYPE_VIS condition_variable public: _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_CONSTEXPR - constexpr condition_variable() _NOEXCEPT _LIBCPP_DEFAULT +#ifndef _LIBCPP_CXX03_LANG + constexpr condition_variable() _NOEXCEPT = default; #else condition_variable() _NOEXCEPT {__cv_ = (__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;} #endif @@ -316,20 +312,24 @@ public: void wait(unique_lock<mutex>& __lk) _NOEXCEPT; template <class _Predicate> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait(unique_lock<mutex>& __lk, _Predicate __pred); template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t); template <class _Clock, class _Duration, class _Predicate> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred); template <class _Rep, class _Period> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d); @@ -410,8 +410,8 @@ condition_variable::wait_for(unique_lock<mutex>& __lk, typedef time_point<system_clock, duration<long double, nano> > __sys_tpf; typedef time_point<system_clock, nanoseconds> __sys_tpi; __sys_tpf _Max = __sys_tpi::max(); - system_clock::time_point __s_now = system_clock::now(); steady_clock::time_point __c_now = steady_clock::now(); + system_clock::time_point __s_now = system_clock::now(); if (_Max - __d > __s_now) __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d)); else @@ -435,4 +435,6 @@ condition_variable::wait_for(unique_lock<mutex>& __lk, _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___MUTEX_BASE diff --git a/lib/libcxx/include/__nullptr b/lib/libcxx/include/__nullptr index 95415a6325a..a341234f5d1 100644 --- a/lib/libcxx/include/__nullptr +++ b/lib/libcxx/include/__nullptr @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_TYPE_VIS_ONLY nullptr_t +struct _LIBCPP_TEMPLATE_VIS nullptr_t { void* __lx; @@ -42,10 +42,6 @@ struct _LIBCPP_TYPE_VIS_ONLY nullptr_t friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;} friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;} }; inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);} diff --git a/lib/libcxx/include/__split_buffer b/lib/libcxx/include/__split_buffer index 79d1aa1d7c4..1daa4e5ada3 100644 --- a/lib/libcxx/include/__split_buffer +++ b/lib/libcxx/include/__split_buffer @@ -6,12 +6,14 @@ #include <type_traits> #include <algorithm> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <bool> @@ -66,7 +68,7 @@ public: __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); ~__split_buffer(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG __split_buffer(__split_buffer&& __c) _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); @@ -74,7 +76,7 @@ public: _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value) || !__alloc_traits::propagate_on_container_move_assignment::value); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} @@ -99,14 +101,12 @@ public: void shrink_to_fit() _NOEXCEPT; void push_front(const_reference __x); _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +#ifndef _LIBCPP_CXX03_LANG void push_front(value_type&& __x); void push_back(value_type&& __x); -#if !defined(_LIBCPP_HAS_NO_VARIADICS) template <class... _Args> void emplace_back(_Args&&... __args); -#endif // !defined(_LIBCPP_HAS_NO_VARIADICS) -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +#endif // !defined(_LIBCPP_CXX03_LANG) _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);} _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);} @@ -343,7 +343,7 @@ __split_buffer<_Tp, _Allocator>::~__split_buffer() __alloc_traits::deallocate(__alloc(), __first_, capacity()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) @@ -361,7 +361,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) template <class _Tp, class _Allocator> __split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) - : __end_cap_(__a) + : __end_cap_(__second_tag(), __a) { if (__a == __c.__alloc()) { @@ -405,7 +405,7 @@ __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> void @@ -492,7 +492,7 @@ __split_buffer<_Tp, _Allocator>::push_front(const_reference __x) --__begin_; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> void @@ -524,7 +524,7 @@ __split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) --__begin_; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -556,7 +556,7 @@ __split_buffer<_Tp, _Allocator>::push_back(const_reference __x) ++__end_; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> void @@ -588,8 +588,6 @@ __split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) ++__end_; } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Allocator> template <class... _Args> void @@ -621,9 +619,7 @@ __split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) ++__end_; } -#endif // _LIBCPP_HAS_NO_VARIADICS - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -634,7 +630,8 @@ swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) __x.swap(__y); } - _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_SPLIT_BUFFER diff --git a/lib/libcxx/include/__sso_allocator b/lib/libcxx/include/__sso_allocator index ca3b937c013..8147e75ec2c 100644 --- a/lib/libcxx/include/__sso_allocator +++ b/lib/libcxx/include/__sso_allocator @@ -15,8 +15,6 @@ #include <type_traits> #include <new> -#include <__undef___deallocate> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -64,7 +62,7 @@ public: if (__p == (pointer)&buf_) __allocated_ = false; else - _VSTD::__deallocate(__p); + _VSTD::__libcpp_deallocate(__p); } _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} diff --git a/lib/libcxx/include/__std_stream b/lib/libcxx/include/__std_stream index f867cd23bdd..db90795f66f 100644 --- a/lib/libcxx/include/__std_stream +++ b/lib/libcxx/include/__std_stream @@ -17,12 +17,14 @@ #include <__locale> #include <cstdio> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD static const int __limit = 8; @@ -297,7 +299,7 @@ __stdoutbuf<_CharT>::overflow(int_type __c) return traits_type::eof(); if (__r == codecvt_base::partial) { - pbase = (char_type*)__e; + pbase = const_cast<char_type*>(__e); } } else @@ -355,4 +357,6 @@ __stdoutbuf<_CharT>::imbue(const locale& __loc) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___STD_STREAM diff --git a/lib/libcxx/include/__string b/lib/libcxx/include/__string new file mode 100644 index 00000000000..d30c7fddc8d --- /dev/null +++ b/lib/libcxx/include/__string @@ -0,0 +1,877 @@ +// -*- C++ -*- +//===-------------------------- __string ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___STRING +#define _LIBCPP___STRING + +/* + string synopsis + +namespace std +{ + +template <class charT> +struct char_traits +{ + typedef charT char_type; + typedef ... int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static constexpr void assign(char_type& c1, const char_type& c2) noexcept; + static constexpr bool eq(char_type c1, char_type c2) noexcept; + static constexpr bool lt(char_type c1, char_type c2) noexcept; + + static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); + static constexpr size_t length(const char_type* s); + static constexpr const char_type* + find(const char_type* s, size_t n, const char_type& a); + static char_type* move(char_type* s1, const char_type* s2, size_t n); + static char_type* copy(char_type* s1, const char_type* s2, size_t n); + static char_type* assign(char_type* s, size_t n, char_type a); + + static constexpr int_type not_eof(int_type c) noexcept; + static constexpr char_type to_char_type(int_type c) noexcept; + static constexpr int_type to_int_type(char_type c) noexcept; + static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; + static constexpr int_type eof() noexcept; +}; + +template <> struct char_traits<char>; +template <> struct char_traits<wchar_t>; + +} // std + +*/ + +#include <__config> +#include <algorithm> // for search and min +#include <cstdio> // For EOF. +#include <memory> // for __murmur2_or_cityhash + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +// char_traits + +template <class _CharT> +struct _LIBCPP_TEMPLATE_VIS char_traits +{ + typedef _CharT char_type; + typedef int int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14 + assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s); + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a); + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a); + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(EOF);} +}; + +template <class _CharT> +_LIBCPP_CONSTEXPR_AFTER_CXX14 int +char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +template <class _CharT> +inline +_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t +char_traits<_CharT>::length(const char_type* __s) +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +template <class _CharT> +inline +_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT* +char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +template <class _CharT> +_CharT* +char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +template <class _CharT> +inline +_CharT* +char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +template <class _CharT> +inline +_CharT* +char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +// char_traits<char> + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char> +{ + typedef char char_type; + typedef int int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return (unsigned char)__c1 < (unsigned char)__c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 + length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} + static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); + } + static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type((unsigned char)__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(EOF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + if (__n == 0) + return 0; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_memcmp(__s1, __s2, __n); +#elif _LIBCPP_STD_VER <= 14 + return memcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char* +char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return NULL; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_char_memchr(__s, to_int_type(__a), __n); +#elif _LIBCPP_STD_VER <= 14 + return (const char_type*) memchr(__s, to_int_type(__a), __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return NULL; +#endif +} + + +// char_traits<wchar_t> + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> +{ + typedef wchar_t char_type; + typedef wint_t int_type; + typedef streamoff off_type; + typedef streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);} + static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n); + } + static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT + {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);} + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(WEOF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + if (__n == 0) + return 0; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wmemcmp(__s1, __s2, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemcmp(__s1, __s2, __n); +#else + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT +{ +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wcslen(__s); +#elif _LIBCPP_STD_VER <= 14 + return wcslen(__s); +#else + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +#endif +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const wchar_t* +char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + if (__n == 0) + return NULL; +#if __has_feature(cxx_constexpr_string_builtins) + return __builtin_wmemchr(__s, __a, __n); +#elif _LIBCPP_STD_VER <= 14 + return wmemchr(__s, __a, __n); +#else + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return NULL; +#endif +} + + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t> +{ + typedef char16_t char_type; + typedef uint_least16_t int_type; + typedef streamoff off_type; + typedef u16streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(0xFFFF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char16_t* +char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +inline +char16_t* +char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +inline +char16_t* +char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +inline +char16_t* +char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +template <> +struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t> +{ + typedef char32_t char_type; + typedef uint_least32_t int_type; + typedef streamoff off_type; + typedef u32streampos pos_type; + typedef mbstate_t state_type; + + static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 + void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} + static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT + {return __c1 < __c2;} + + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + size_t length(const char_type* __s) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 + const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; + + static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT + {return eq_int_type(__c, eof()) ? ~eof() : __c;} + static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT + {return char_type(__c);} + static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT + {return int_type(__c);} + static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + {return __c1 == __c2;} + static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT + {return int_type(0xFFFFFFFF);} +}; + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +int +char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + for (; __n; --__n, ++__s1, ++__s2) + { + if (lt(*__s1, *__s2)) + return -1; + if (lt(*__s2, *__s1)) + return 1; + } + return 0; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +size_t +char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT +{ + size_t __len = 0; + for (; !eq(*__s, char_type(0)); ++__s) + ++__len; + return __len; +} + +inline _LIBCPP_CONSTEXPR_AFTER_CXX14 +const char32_t* +char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT +{ + for (; __n; --__n) + { + if (eq(*__s, __a)) + return __s; + ++__s; + } + return 0; +} + +inline +char32_t* +char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + char_type* __r = __s1; + if (__s1 < __s2) + { + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + } + else if (__s2 < __s1) + { + __s1 += __n; + __s2 += __n; + for (; __n; --__n) + assign(*--__s1, *--__s2); + } + return __r; +} + +inline +char32_t* +char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT +{ + _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + char_type* __r = __s1; + for (; __n; --__n, ++__s1, ++__s2) + assign(*__s1, *__s2); + return __r; +} + +inline +char32_t* +char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT +{ + char_type* __r = __s; + for (; __n; --__n, ++__s) + assign(*__s, __a); + return __r; +} + +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +// helper fns for basic_string and string_view + +// __str_find +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos >= __sz) + return __npos; + const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c); + if (__r == 0) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + +template <class _CharT, class _Traits> +inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT * +__search_substring(const _CharT *__first1, const _CharT *__last1, + const _CharT *__first2, const _CharT *__last2) { + // Take advantage of knowing source and pattern lengths. + // Stop short when source is smaller than pattern. + const ptrdiff_t __len2 = __last2 - __first2; + if (__len2 == 0) + return __first1; + + ptrdiff_t __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + + // First element of __first2 is loop invariant. + _CharT __f2 = *__first2; + while (true) { + __len1 = __last1 - __first1; + // Check whether __first1 still has at least __len2 bytes. + if (__len1 < __len2) + return __last1; + + // Find __f2 the first byte matching in __first1. + __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2); + if (__first1 == 0) + return __last1; + + // It is faster to compare from the first byte of __first1 even if we + // already know that it matches the first byte of __first2: this is because + // __first2 is most likely aligned, as it is user's "pattern" string, and + // __first1 + 1 is most likely not aligned, as the match is in the middle of + // the string. + if (_Traits::compare(__first1, __first2, __len2) == 0) + return __first1; + + ++__first1; + } +} + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos > __sz) + return __npos; + + if (__n == 0) // There is nothing to search, just return __pos. + return __pos; + + const _CharT *__r = __search_substring<_CharT, _Traits>( + __p + __pos, __p + __sz, __s, __s + __n); + + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + + +// __str_rfind + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_rfind(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__sz < 1) + return __npos; + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + if (_Traits::eq(*--__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_rfind(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + __pos = _VSTD::min(__pos, __sz); + if (__n < __sz - __pos) + __pos += __n; + else + __pos = __sz; + const _CharT* __r = _VSTD::__find_end( + __p, __p + __pos, __s, __s + __n, _Traits::eq, + random_access_iterator_tag(), random_access_iterator_tag()); + if (__n > 0 && __r == __p + __pos) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + +// __str_find_first_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos >= __sz || __n == 0) + return __npos; + const _CharT* __r = _VSTD::__find_first_of_ce + (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + + +// __str_find_last_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT + { + if (__n != 0) + { + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + const _CharT* __r = _Traits::find(__s, __n, *--__ps); + if (__r) + return static_cast<_SizeT>(__ps - __p); + } + } + return __npos; +} + + +// __str_find_first_not_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (_Traits::find(__s, __n, *__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_first_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (!_Traits::eq(*__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +// __str_find_last_not_of +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (_Traits::find(__s, __n, *--__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + + +template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> +inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +__str_find_last_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (!_Traits::eq(*--__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + +template<class _Ptr> +inline _LIBCPP_INLINE_VISIBILITY +size_t __do_string_hash(_Ptr __p, _Ptr __e) +{ + typedef typename iterator_traits<_Ptr>::value_type value_type; + return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type)); +} + +template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> > +struct __quoted_output_proxy +{ + _Iter __first; + _Iter __last; + _CharT __delim; + _CharT __escape; + + __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) + : __first(__f), __last(__l), __delim(__d), __escape(__e) {} + // This would be a nice place for a string_ref +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___STRING diff --git a/lib/libcxx/include/__threading_support b/lib/libcxx/include/__threading_support index c9a4ea9d094..5d4c907966e 100644 --- a/lib/libcxx/include/__threading_support +++ b/lib/libcxx/include/__threading_support @@ -12,194 +12,628 @@ #define _LIBCPP_THREADING_SUPPORT #include <__config> +#include <chrono> +#include <errno.h> #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #pragma GCC system_header #endif -#ifndef _LIBCPP_HAS_NO_THREADS +#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) +# include <__external_threading> +#elif !defined(_LIBCPP_HAS_NO_THREADS) #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) -#include <pthread.h> -#include <sched.h> +# include <pthread.h> +# include <sched.h> +#elif defined(_LIBCPP_HAS_THREAD_API_WIN32) +#include <windows.h> +#include <process.h> +#include <fibersapi.h> +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \ + defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) +#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS +#else +#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY +#endif + +#if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(no_thread_safety_analysis) +#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +#else +#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS #endif _LIBCPP_BEGIN_NAMESPACE_STD #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) - // Mutex -#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER typedef pthread_mutex_t __libcpp_mutex_t; +#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +typedef pthread_mutex_t __libcpp_recursive_mutex_t; + +// Condition Variable +typedef pthread_cond_t __libcpp_condvar_t; +#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER + +// Execute once +typedef pthread_once_t __libcpp_exec_once_flag; +#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT + +// Thread id +typedef pthread_t __libcpp_thread_id; + +// Thread +#define _LIBCPP_NULL_THREAD 0U + +typedef pthread_t __libcpp_thread_t; + +// Thrad Local Storage +typedef pthread_key_t __libcpp_tls_key; + +#define _LIBCPP_TLS_DESTRUCTOR_CC +#else +// Mutex +typedef SRWLOCK __libcpp_mutex_t; +#define _LIBCPP_MUTEX_INITIALIZER SRWLOCK_INIT + +typedef CRITICAL_SECTION __libcpp_recursive_mutex_t; + +// Condition Variable +typedef CONDITION_VARIABLE __libcpp_condvar_t; +#define _LIBCPP_CONDVAR_INITIALIZER CONDITION_VARIABLE_INIT -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_recursive_mutex_init(__libcpp_mutex_t* __m) +// Execute Once +typedef INIT_ONCE __libcpp_exec_once_flag; +#define _LIBCPP_EXEC_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT + +// Thread ID +typedef DWORD __libcpp_thread_id; + +// Thread +#define _LIBCPP_NULL_THREAD 0U + +typedef HANDLE __libcpp_thread_t; + +// Thread Local Storage +typedef DWORD __libcpp_tls_key; + +#define _LIBCPP_TLS_DESTRUCTOR_CC WINAPI +#endif + +// Mutex +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_mutex_lock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m); + +// Condition variable +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_signal(__libcpp_condvar_t* __cv); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); + +_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); + +// Execute once +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_execute_once(__libcpp_exec_once_flag *flag, + void (*init_routine)(void)); + +// Thread id +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2); + +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2); + +// Thread +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg); + +_LIBCPP_THREAD_ABI_VISIBILITY +__libcpp_thread_id __libcpp_thread_get_current_id(); + +_LIBCPP_THREAD_ABI_VISIBILITY +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_join(__libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_thread_detach(__libcpp_thread_t *__t); + +_LIBCPP_THREAD_ABI_VISIBILITY +void __libcpp_thread_yield(); + +_LIBCPP_THREAD_ABI_VISIBILITY +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns); + +// Thread local storage +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_tls_create(__libcpp_tls_key* __key, + void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*)); + +_LIBCPP_THREAD_ABI_VISIBILITY +void *__libcpp_tls_get(__libcpp_tls_key __key); + +_LIBCPP_THREAD_ABI_VISIBILITY +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p); + +#if !defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \ + defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) + +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) + +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) { - pthread_mutexattr_t attr; - int __ec = pthread_mutexattr_init(&attr); - if (__ec) return __ec; - __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - if (__ec) - { - pthread_mutexattr_destroy(&attr); - return __ec; - } - __ec = pthread_mutex_init(__m, &attr); - if (__ec) - { - pthread_mutexattr_destroy(&attr); - return __ec; - } - __ec = pthread_mutexattr_destroy(&attr); - if (__ec) - { - pthread_mutex_destroy(__m); - return __ec; - } - return 0; + pthread_mutexattr_t attr; + int __ec = pthread_mutexattr_init(&attr); + if (__ec) + return __ec; + __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (__ec) { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutex_init(__m, &attr); + if (__ec) { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutexattr_destroy(&attr); + if (__ec) { + pthread_mutex_destroy(__m); + return __ec; + } + return 0; } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_mutex_lock(__libcpp_mutex_t* __m) +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) { - return pthread_mutex_lock(__m); + return pthread_mutex_lock(__m); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_mutex_trylock(__libcpp_mutex_t* __m) +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) { - return pthread_mutex_trylock(__m); + return pthread_mutex_trylock(__m) == 0; } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_mutex_unlock(__libcpp_mutex_t* __m) +int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m) { - return pthread_mutex_unlock(__m); + return pthread_mutex_unlock(__m); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) { - return pthread_mutex_destroy(__m); + return pthread_mutex_destroy(__m); } -// Condition variable -#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER -typedef pthread_cond_t __libcpp_condvar_t; +int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +{ + return pthread_mutex_lock(__m); +} -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_condvar_signal(__libcpp_condvar_t* __cv) +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) { - return pthread_cond_signal(__cv); + return pthread_mutex_trylock(__m) == 0; } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv) +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) { - return pthread_cond_broadcast(__cv); + return pthread_mutex_unlock(__m); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m) +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) { - return pthread_cond_wait(__cv, __m); + return pthread_mutex_destroy(__m); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, timespec* __ts) +// Condition Variable +int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) { - return pthread_cond_timedwait(__cv, __m, __ts); + return pthread_cond_signal(__cv); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv) +int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) { - return pthread_cond_destroy(__cv); + return pthread_cond_broadcast(__cv); } -// Thread id -typedef pthread_t __libcpp_thread_id; +int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) +{ + return pthread_cond_wait(__cv, __m); +} + +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts) +{ + return pthread_cond_timedwait(__cv, __m, __ts); +} +int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) +{ + return pthread_cond_destroy(__cv); +} + +// Execute once +int __libcpp_execute_once(__libcpp_exec_once_flag *flag, + void (*init_routine)(void)) { + return pthread_once(flag, init_routine); +} + +// Thread id // Returns non-zero if the thread ids are equal, otherwise 0 -inline _LIBCPP_ALWAYS_INLINE bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) { - return pthread_equal(t1, t2) != 0; + return pthread_equal(t1, t2) != 0; } // Returns non-zero if t1 < t2, otherwise 0 -inline _LIBCPP_ALWAYS_INLINE bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) { - return t1 < t2; + return t1 < t2; } // Thread -typedef pthread_t __libcpp_thread_t; +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { + return *__t == 0; +} -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg) +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg) { - return pthread_create(__t, 0, __func, __arg); + return pthread_create(__t, 0, __func, __arg); } -inline _LIBCPP_ALWAYS_INLINE __libcpp_thread_id __libcpp_thread_get_current_id() { - return pthread_self(); + return pthread_self(); } -inline _LIBCPP_ALWAYS_INLINE -__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t) +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) { - return *__t; + return *__t; } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_thread_join(__libcpp_thread_t* __t) +int __libcpp_thread_join(__libcpp_thread_t *__t) { - return pthread_join(*__t, 0); + return pthread_join(*__t, 0); } -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_thread_detach(__libcpp_thread_t* __t) +int __libcpp_thread_detach(__libcpp_thread_t *__t) { - return pthread_detach(*__t); + return pthread_detach(*__t); } -inline _LIBCPP_ALWAYS_INLINE void __libcpp_thread_yield() { - sched_yield(); + sched_yield(); +} + +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) +{ + using namespace chrono; + seconds __s = duration_cast<seconds>(__ns); + timespec __ts; + typedef decltype(__ts.tv_sec) ts_sec; + _LIBCPP_CONSTEXPR ts_sec __ts_sec_max = numeric_limits<ts_sec>::max(); + + if (__s.count() < __ts_sec_max) + { + __ts.tv_sec = static_cast<ts_sec>(__s.count()); + __ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count()); + } + else + { + __ts.tv_sec = __ts_sec_max; + __ts.tv_nsec = 999999999; // (10^9 - 1) + } + + while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR); } // Thread local storage -typedef pthread_key_t __libcpp_tl_key; +int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *)) +{ + return pthread_key_create(__key, __at_exit); +} + +void *__libcpp_tls_get(__libcpp_tls_key __key) +{ + return pthread_getspecific(__key); +} -inline _LIBCPP_ALWAYS_INLINE -int __libcpp_tl_create(__libcpp_tl_key* __key, void (*__at_exit)(void*)) +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) { - return pthread_key_create(__key, __at_exit); + return pthread_setspecific(__key, __p); } -inline _LIBCPP_ALWAYS_INLINE -void* __libcpp_tl_get(__libcpp_tl_key __key) +#elif defined(_LIBCPP_HAS_THREAD_API_WIN32) + +// Mutex +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) { - return pthread_getspecific(__key); + InitializeCriticalSection(__m); + return 0; } -inline _LIBCPP_ALWAYS_INLINE -void __libcpp_tl_set(__libcpp_tl_key __key, void* __p) +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) { - pthread_setspecific(__key, __p); + EnterCriticalSection(__m); + return 0; } -#else // !_LIBCPP_HAS_THREAD_API_PTHREAD - #error "No thread API selected." -#endif +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) +{ + return TryEnterCriticalSection(__m) != 0; +} + +int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m) +{ + LeaveCriticalSection(__m); + return 0; +} + +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) +{ + DeleteCriticalSection(__m); + return 0; +} + +int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +{ + AcquireSRWLockExclusive(__m); + return 0; +} + +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) +{ + return TryAcquireSRWLockExclusive(__m) != 0; +} + +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) +{ + ReleaseSRWLockExclusive(__m); + return 0; +} + +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) +{ + static_cast<void>(__m); + return 0; +} + +// Condition Variable +int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) +{ + WakeConditionVariable(__cv); + return 0; +} + +int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) +{ + WakeAllConditionVariable(__cv); + return 0; +} + +int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) +{ + SleepConditionVariableSRW(__cv, __m, INFINITE, 0); + return 0; +} + +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts) +{ + using namespace _VSTD::chrono; + + auto duration = seconds(__ts->tv_sec) + nanoseconds(__ts->tv_nsec); + auto abstime = + system_clock::time_point(duration_cast<system_clock::duration>(duration)); + auto timeout_ms = duration_cast<milliseconds>(abstime - system_clock::now()); + + if (!SleepConditionVariableSRW(__cv, __m, + timeout_ms.count() > 0 ? timeout_ms.count() + : 0, + 0)) + { + auto __ec = GetLastError(); + return __ec == ERROR_TIMEOUT ? ETIMEDOUT : __ec; + } + return 0; +} + +int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) +{ + static_cast<void>(__cv); + return 0; +} + +// Execute Once +static inline _LIBCPP_ALWAYS_INLINE BOOL CALLBACK +__libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter, + PVOID *__context) +{ + static_cast<void>(__init_once); + static_cast<void>(__context); + + void (*init_routine)(void) = reinterpret_cast<void (*)(void)>(__parameter); + init_routine(); + return TRUE; +} + +int __libcpp_execute_once(__libcpp_exec_once_flag *__flag, + void (*__init_routine)(void)) +{ + if (!InitOnceExecuteOnce(__flag, __libcpp_init_once_execute_once_thunk, + reinterpret_cast<void *>(__init_routine), NULL)) + return GetLastError(); + return 0; +} + +// Thread ID +bool __libcpp_thread_id_equal(__libcpp_thread_id __lhs, + __libcpp_thread_id __rhs) +{ + return __lhs == __rhs; +} + +bool __libcpp_thread_id_less(__libcpp_thread_id __lhs, __libcpp_thread_id __rhs) +{ + return __lhs < __rhs; +} + +// Thread +struct __libcpp_beginthreadex_thunk_data +{ + void *(*__func)(void *); + void *__arg; +}; + +static inline _LIBCPP_ALWAYS_INLINE unsigned WINAPI +__libcpp_beginthreadex_thunk(void *__raw_data) +{ + auto *__data = + static_cast<__libcpp_beginthreadex_thunk_data *>(__raw_data); + auto *__func = __data->__func; + void *__arg = __data->__arg; + delete __data; + return static_cast<unsigned>(reinterpret_cast<uintptr_t>(__func(__arg))); +} + +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { + return *__t == 0; +} + +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg) +{ + auto *__data = new __libcpp_beginthreadex_thunk_data; + __data->__func = __func; + __data->__arg = __arg; + + *__t = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, + __libcpp_beginthreadex_thunk, + __data, 0, nullptr)); + + if (*__t) + return 0; + return GetLastError(); +} + +__libcpp_thread_id __libcpp_thread_get_current_id() +{ + return GetCurrentThreadId(); +} + +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) +{ + return GetThreadId(*__t); +} + +int __libcpp_thread_join(__libcpp_thread_t *__t) +{ + if (WaitForSingleObjectEx(*__t, INFINITE, FALSE) == WAIT_FAILED) + return GetLastError(); + if (!CloseHandle(*__t)) + return GetLastError(); + return 0; +} + +int __libcpp_thread_detach(__libcpp_thread_t *__t) +{ + if (!CloseHandle(*__t)) + return GetLastError(); + return 0; +} + +void __libcpp_thread_yield() +{ + SwitchToThread(); +} + +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) +{ + using namespace chrono; + // round-up to the nearest milisecond + milliseconds __ms = + duration_cast<milliseconds>(__ns + chrono::nanoseconds(999999)); + // FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx) + Sleep(__ms.count()); +} + +// Thread Local Storage +int __libcpp_tls_create(__libcpp_tls_key* __key, + void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*)) +{ + *__key = FlsAlloc(__at_exit); + if (*__key == FLS_OUT_OF_INDEXES) + return GetLastError(); + return 0; +} + +void *__libcpp_tls_get(__libcpp_tls_key __key) +{ + return FlsGetValue(__key); +} + +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) +{ + if (!FlsSetValue(__key, __p)) + return GetLastError(); + return 0; +} + +#endif // _LIBCPP_HAS_THREAD_API_PTHREAD + +#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP_HAS_NO_THREADS +_LIBCPP_POP_MACROS + +#endif // !_LIBCPP_HAS_NO_THREADS #endif // _LIBCPP_THREADING_SUPPORT diff --git a/lib/libcxx/include/__tree b/lib/libcxx/include/__tree index b560bf071e8..3ccfcb70031 100644 --- a/lib/libcxx/include/__tree +++ b/lib/libcxx/include/__tree @@ -21,13 +21,17 @@ #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _Compare, class _Allocator> class __tree; template <class _Tp, class _NodePtr, class _DiffType> - class _LIBCPP_TYPE_VIS_ONLY __tree_iterator; + class _LIBCPP_TEMPLATE_VIS __tree_iterator; template <class _Tp, class _ConstNodePtr, class _DiffType> - class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator; + class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; template <class _Pointer> class __tree_end_node; template <class _VoidPtr> class __tree_node_base; @@ -41,9 +45,13 @@ template <class _Key, class _Value> struct __value_type; #endif +template <class _Key, class _CP, class _Compare, + bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value> +class __map_value_compare; + template <class _Allocator> class __map_node_destructor; -template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_iterator; -template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_iterator; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_const_iterator; /* @@ -76,7 +84,7 @@ __tree_is_left_child(_NodePtr __x) _NOEXCEPT return __x == __x->__parent_->__left_; } -// Determintes if the subtree rooted at __x is a proper red black subtree. If +// Determines if the subtree rooted at __x is a proper red black subtree. If // __x is a proper subtree, returns the black height (null counts as 1). If // __x is an improper subtree, returns 0. template <class _NodePtr> @@ -111,7 +119,7 @@ __tree_sub_invariant(_NodePtr __x) return __h + __x->__is_black_; // return black height of this node } -// Determintes if the red black tree rooted at __root is a proper red black tree. +// Determines if the red black tree rooted at __root is a proper red black tree. // __root == nullptr is a proper tree. Returns true is __root is a proper // red black tree, else returns false. template <class _NodePtr> @@ -797,7 +805,7 @@ public: template <class _Tp, class _NodePtr, class _DiffType> -class _LIBCPP_TYPE_VIS_ONLY __tree_iterator +class _LIBCPP_TEMPLATE_VIS __tree_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; @@ -861,16 +869,16 @@ private: _LIBCPP_INLINE_VISIBILITY __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template <class, class, class> friend class __tree; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_iterator; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY set; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multiset; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; }; template <class _Tp, class _NodePtr, class _DiffType> -class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator +class _LIBCPP_TEMPLATE_VIS __tree_const_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef typename _NodeTypes::__node_pointer __node_pointer; @@ -947,13 +955,32 @@ private: __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template <class, class, class> friend class __tree; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY set; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multiset; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; + +}; + +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp, class _Compare, class _Allocator> +struct __diagnose_tree_helper { + static constexpr bool __trigger_diagnostics() + _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Compare const&, _Tp const&, _Tp const&>::value, + "the specified comparator type does not provide a const call operator") + { return true; } +}; +template <class _Key, class _Value, class _KeyComp, class _Alloc> +struct __diagnose_tree_helper< + __value_type<_Key, _Value>, + __map_value_compare<_Key, __value_type<_Key, _Value>, _KeyComp>, + _Alloc +> : __diagnose_tree_helper<_Key, _KeyComp, _Alloc> +{ }; +#endif // !_LIBCPP_CXX03_LANG template <class _Tp, class _Compare, class _Allocator> class __tree @@ -1080,7 +1107,7 @@ public: void __assign_unique(_InputIterator __first, _InputIterator __last); template <class _InputIterator> void __assign_multi(_InputIterator __first, _InputIterator __last); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG __tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value && @@ -1091,7 +1118,7 @@ public: __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<value_compare>::value && is_nothrow_move_assignable<__node_allocator>::value); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG ~__tree(); @@ -1106,19 +1133,22 @@ public: _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return __node_traits::max_size(__node_alloc());} + {return std::min<size_type>( + __node_traits::max_size(__node_alloc()), + numeric_limits<difference_type >::max());} void clear() _NOEXCEPT; void swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable<value_compare>::value -#if _LIBCPP_STD_VER <= 11 && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) -#endif ); - +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value); +#endif #ifndef _LIBCPP_CXX03_LANG template <class _Key, class ..._Args> @@ -1394,10 +1424,17 @@ private: __node_base_pointer& __find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v); + // FIXME: Make this function const qualified. Unfortunetly doing so + // breaks existing code which uses non-const callable comparators. template <class _Key> __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v); template <class _Key> + _LIBCPP_INLINE_VISIBILITY __node_base_pointer& + __find_equal(__parent_pointer& __parent, const _Key& __v) const { + return const_cast<__tree*>(this)->__find_equal(__parent, __v); + } + template <class _Key> __node_base_pointer& __find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, @@ -1425,7 +1462,7 @@ private: __node_alloc() = __t.__node_alloc(); } _LIBCPP_INLINE_VISIBILITY - void __copy_assign_alloc(const __tree& __t, false_type) {} + void __copy_assign_alloc(const __tree&, false_type) {} void __move_assign(__tree& __t, false_type); void __move_assign(__tree& __t, true_type) @@ -1445,13 +1482,13 @@ private: _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {__node_alloc() = _VSTD::move(__t.__node_alloc());} _LIBCPP_INLINE_VISIBILITY - void __move_assign_alloc(__tree& __t, false_type) _NOEXCEPT {} + void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} __node_pointer __detach(); static __node_pointer __detach(__node_pointer); - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; }; template <class _Tp, class _Compare, class _Allocator> @@ -1467,7 +1504,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) : __begin_node_(__iter_pointer()), - __pair1_(__node_allocator(__a)), + __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0) { __begin_node() = __end_node(); @@ -1477,7 +1514,7 @@ template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a) : __begin_node_(__iter_pointer()), - __pair1_(__node_allocator(__a)), + __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, __comp) { __begin_node() = __end_node(); @@ -1634,13 +1671,13 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) : __begin_node_(__iter_pointer()), - __pair1_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())), + __pair1_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), __pair3_(0, __t.value_comp()) { __begin_node() = __end_node(); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) @@ -1664,7 +1701,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) - : __pair1_(__node_allocator(__a)), + : __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, _VSTD::move(__t.value_comp())) { if (__a == __t.__alloc()) @@ -1770,14 +1807,18 @@ __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::~__tree() { static_assert((is_copy_constructible<value_compare>::value), "Comparator must be copy-constructible."); - destroy(__root()); +#ifndef _LIBCPP_CXX03_LANG + static_assert((__diagnose_tree_helper<_Tp, _Compare, _Allocator>:: + __trigger_diagnostics()), ""); +#endif + destroy(__root()); } template <class _Tp, class _Compare, class _Allocator> @@ -1797,13 +1838,15 @@ __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT template <class _Tp, class _Compare, class _Allocator> void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable<value_compare>::value -#if _LIBCPP_STD_VER <= 11 && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) -#endif ) +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value) +#endif { using _VSTD::swap; swap(__begin_node_, __t.__begin_node_); @@ -2644,4 +2687,6 @@ swap(__tree<_Tp, _Compare, _Allocator>& __x, _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___TREE diff --git a/lib/libcxx/include/__tuple b/lib/libcxx/include/__tuple index cc9fbbebc09..69d6ee96111 100644 --- a/lib/libcxx/include/__tuple +++ b/lib/libcxx/include/__tuple @@ -22,38 +22,56 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_size; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size; + +#if !defined(_LIBCPP_CXX03_LANG) +template <class _Tp, class...> +using __enable_if_tuple_size_imp = _Tp; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<const _Tp> - : public tuple_size<_Tp> {}; +class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + const _Tp, + typename enable_if<!is_volatile<_Tp>::value>::type, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<volatile _Tp> - : public tuple_size<_Tp> {}; +class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + volatile _Tp, + typename enable_if<!is_const<_Tp>::value>::type, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<const volatile _Tp> - : public tuple_size<_Tp> {}; +class _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< + const volatile _Tp, + integral_constant<size_t, sizeof(tuple_size<_Tp>)>>> + : public integral_constant<size_t, tuple_size<_Tp>::value> {}; -template <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_element; +#else +template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {}; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {}; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {}; +#endif + +template <size_t _Ip, class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_element; template <size_t _Ip, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const _Tp> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> { public: typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; }; template <size_t _Ip, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, volatile _Tp> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> { public: typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; }; template <size_t _Ip, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const volatile _Tp> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> { public: typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; @@ -67,7 +85,7 @@ template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_li // tuple specializations -#if !defined(_LIBCPP_HAS_NO_VARIADICS) +#ifndef _LIBCPP_CXX03_LANG template <size_t...> struct __tuple_indices {}; @@ -142,10 +160,16 @@ struct __make_tuple_indices }; -template <class ..._Tp> class _LIBCPP_TYPE_VIS_ONLY tuple; +template <class ..._Tp> class _LIBCPP_TEMPLATE_VIS tuple; template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {}; +template <class ..._Tp> +class _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> > + : public integral_constant<size_t, sizeof...(_Tp)> +{ +}; + template <size_t _Ip, class ..._Tp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type& @@ -165,7 +189,8 @@ template <size_t _Ip, class ..._Tp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(const tuple<_Tp...>&&) _NOEXCEPT; -#endif + +#endif // !defined(_LIBCPP_CXX03_LANG) // pair specializations @@ -181,7 +206,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, pair<_T1, _T2> >::type& get(const pair<_T1, _T2>&) _NOEXCEPT; -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +#ifndef _LIBCPP_CXX03_LANG template <size_t _Ip, class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& @@ -195,7 +220,7 @@ get(const pair<_T1, _T2>&&) _NOEXCEPT; // array specializations -template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array; +template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array; template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {}; @@ -209,7 +234,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& get(const array<_Tp, _Size>&) _NOEXCEPT; -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +#ifndef _LIBCPP_CXX03_LANG template <size_t _Ip, class _Tp, size_t _Size> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& @@ -221,8 +246,7 @@ const _Tp&& get(const array<_Tp, _Size>&&) _NOEXCEPT; #endif -#if !defined(_LIBCPP_HAS_NO_VARIADICS) - +#ifndef _LIBCPP_CXX03_LANG // __tuple_types @@ -258,7 +282,7 @@ using __type_pack_element = typename decltype( #endif template <size_t _Ip, class ..._Types> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<_Types...>> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> { public: static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range"); @@ -267,7 +291,7 @@ public: template <class ..._Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<__tuple_types<_Tp...> > +class _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> { }; @@ -368,7 +392,7 @@ template <bool ..._Preds> struct __all_dummy; template <bool ..._Pred> -using __all = is_same<__all_dummy<_Pred...>, __all_dummy<(_Pred, true)...>>; +using __all = is_same<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>; struct __tuple_sfinae_base { template <template <class, class...> class _Trait, @@ -431,7 +455,101 @@ struct __tuple_assignable<_Tp, _Up, true, true> > {}; -#endif // _LIBCPP_HAS_NO_VARIADICS + +template <size_t _Ip, class ..._Tp> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > +{ +public: + typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template <size_t _Ip, class ..._Tp> +using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; +#endif + +template <bool _IsTuple, class _SizeTrait, size_t _Expected> +struct __tuple_like_with_size_imp : false_type {}; + +template <class _SizeTrait, size_t _Expected> +struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected> + : integral_constant<bool, _SizeTrait::value == _Expected> {}; + +template <class _Tuple, size_t _ExpectedSize, + class _RawTuple = typename __uncvref<_Tuple>::type> +using __tuple_like_with_size = __tuple_like_with_size_imp< + __tuple_like<_RawTuple>::value, + tuple_size<_RawTuple>, _ExpectedSize + >; + +struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { + template <class ...> + static constexpr bool __enable_default() { return false; } + template <class ...> + static constexpr bool __enable_explicit() { return false; } + template <class ...> + static constexpr bool __enable_implicit() { return false; } + template <class ...> + static constexpr bool __enable_assign() { return false; } +}; +#endif // !defined(_LIBCPP_CXX03_LANG) + +#if _LIBCPP_STD_VER > 14 + +template <bool _CanCopy, bool _CanMove> +struct __sfinae_ctor_base {}; +template <> +struct __sfinae_ctor_base<false, false> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base &&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base<true, false> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base(__sfinae_ctor_base &&) = delete; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; +template <> +struct __sfinae_ctor_base<false, true> { + __sfinae_ctor_base() = default; + __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; + __sfinae_ctor_base(__sfinae_ctor_base &&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; + __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; +}; + +template <bool _CanCopy, bool _CanMove> +struct __sfinae_assign_base {}; +template <> +struct __sfinae_assign_base<false, false> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base<true, false> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; +}; +template <> +struct __sfinae_assign_base<false, true> { + __sfinae_assign_base() = default; + __sfinae_assign_base(__sfinae_assign_base const&) = default; + __sfinae_assign_base(__sfinae_assign_base &&) = default; + __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; + __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default; +}; +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__undef_macros b/lib/libcxx/include/__undef_macros new file mode 100644 index 00000000000..60ab1dbfb5f --- /dev/null +++ b/lib/libcxx/include/__undef_macros @@ -0,0 +1,34 @@ +// -*- C++ -*- +//===------------------------ __undef_macros ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +#ifdef min +#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX " + "before any Windows header. #undefing min") +#else +#warning: macro min is incompatible with C++. #undefing min +#endif +#endif +#undef min +#endif + +#ifdef max +#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX " + "before any Windows header. #undefing max") +#else +#warning: macro max is incompatible with C++. #undefing max +#endif +#endif +#undef max +#endif diff --git a/lib/libcxx/include/algorithm b/lib/libcxx/include/algorithm index 7a6db7abd26..35c6129ea50 100644 --- a/lib/libcxx/include/algorithm +++ b/lib/libcxx/include/algorithm @@ -35,6 +35,9 @@ template <class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f); +template<class InputIterator, class Size, class Function> + InputIterator for_each_n(InputIterator first, Size n, Function f); // C++17 + template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T& value); @@ -89,7 +92,7 @@ template <class InputIterator1, class InputIterator2> template <class InputIterator1, class InputIterator2> pair<InputIterator1, InputIterator2> - mismatch(InputIterator1 first1, InputIterator1 last1, + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); // **C++14** template <class InputIterator1, class InputIterator2, class BinaryPredicate> @@ -109,7 +112,7 @@ template <class InputIterator1, class InputIterator2> template <class InputIterator1, class InputIterator2> bool - equal(InputIterator1 first1, InputIterator1 last1, + equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); // **C++14** template <class InputIterator1, class InputIterator2, class BinaryPredicate> @@ -281,12 +284,18 @@ template <class ForwardIterator, class OutputIterator> template <class RandomAccessIterator> void - random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14 + random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17 template <class RandomAccessIterator, class RandomNumberGenerator> void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, - RandomNumberGenerator& rand); // deprecated in C++14 + RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17 + +template<class PopulationIterator, class SampleIterator, + class Distance, class UniformRandomBitGenerator> + SampleIterator sample(PopulationIterator first, PopulationIterator last, + SampleIterator out, Distance n, + UniformRandomBitGenerator&& g); // C++17 template<class RandomAccessIterator, class UniformRandomNumberGenerator> void shuffle(RandomAccessIterator first, RandomAccessIterator last, @@ -638,18 +647,20 @@ template <class BidirectionalIterator, class Compare> #if defined(__IBMCPP__) #include "support/ibm/support.h" #endif -#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) -#include "support/win32/support.h" +#if defined(_LIBCPP_COMPILER_MSVC) +#include <intrin.h> #endif -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // I'd like to replace these with _VSTD::equal_to<void>, but can't because: @@ -688,7 +699,7 @@ struct __equal_to<_T1, const _T1> template <class _T1, class _T2 = _T1> struct __less { - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -723,15 +734,15 @@ struct __less<_T1, const _T1> }; template <class _Predicate> -class __negate +class __invert // invert the sense of a comparison { private: _Predicate __p_; public: - _LIBCPP_INLINE_VISIBILITY __negate() {} + _LIBCPP_INLINE_VISIBILITY __invert() {} _LIBCPP_INLINE_VISIBILITY - explicit __negate(_Predicate __p) : __p_(__p) {} + explicit __invert(_Predicate __p) : __p_(__p) {} template <class _T1> _LIBCPP_INLINE_VISIBILITY @@ -739,7 +750,7 @@ public: template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY - bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);} + bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} }; #ifdef _LIBCPP_DEBUG @@ -749,65 +760,160 @@ struct __debug_less { _Compare __comp_; __debug_less(_Compare& __c) : __comp_(__c) {} + template <class _Tp, class _Up> bool operator()(const _Tp& __x, const _Up& __y) { bool __r = __comp_(__x, __y); if (__r) - _LIBCPP_ASSERT(!__comp_(__y, __x), "Comparator does not induce a strict weak ordering"); + __do_compare_assert(0, __y, __x); return __r; } + + template <class _LHS, class _RHS> + inline _LIBCPP_INLINE_VISIBILITY + decltype((void)_VSTD::declval<_Compare&>()( + _VSTD::declval<_LHS const&>(), _VSTD::declval<_RHS const&>())) + __do_compare_assert(int, _LHS const& __l, _RHS const& __r) { + _LIBCPP_ASSERT(!__comp_(__l, __r), + "Comparator does not induce a strict weak ordering"); + } + + template <class _LHS, class _RHS> + inline _LIBCPP_INLINE_VISIBILITY + void __do_compare_assert(long, _LHS const&, _RHS const&) {} }; #endif // _LIBCPP_DEBUG // Precondition: __x != 0 inline _LIBCPP_INLINE_VISIBILITY -unsigned -__ctz(unsigned __x) -{ +unsigned __ctz(unsigned __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned>(__builtin_ctz(__x)); +#else + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + static_assert(sizeof(unsigned long) == 4, ""); + unsigned long where; + // Search from LSB to MSB for first set bit. + // Returns zero if no set bit is found. + if (_BitScanForward(&where, __x)) + return where; + return 32; +#endif } inline _LIBCPP_INLINE_VISIBILITY -unsigned long -__ctz(unsigned long __x) -{ +unsigned long __ctz(unsigned long __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned long>(__builtin_ctzl(__x)); +#else + static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); + return __ctz(static_cast<unsigned>(__x)); +#endif } inline _LIBCPP_INLINE_VISIBILITY -unsigned long long -__ctz(unsigned long long __x) -{ +unsigned long long __ctz(unsigned long long __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned long long>(__builtin_ctzll(__x)); +#else + unsigned long where; +// Search from LSB to MSB for first set bit. +// Returns zero if no set bit is found. +#if defined(_LIBCPP_HAS_BITSCAN64) + (defined(_M_AMD64) || defined(__x86_64__)) + if (_BitScanForward64(&where, __x)) + return static_cast<int>(where); +#else + // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. + // Scan the Low Word. + if (_BitScanForward(&where, static_cast<unsigned long>(__x))) + return where; + // Scan the High Word. + if (_BitScanForward(&where, static_cast<unsigned long>(__x >> 32))) + return where + 32; // Create a bit offset from the LSB. +#endif + return 64; +#endif // _LIBCPP_COMPILER_MSVC } // Precondition: __x != 0 inline _LIBCPP_INLINE_VISIBILITY -unsigned -__clz(unsigned __x) -{ +unsigned __clz(unsigned __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned>(__builtin_clz(__x)); +#else + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + static_assert(sizeof(unsigned long) == 4, ""); + unsigned long where; + // Search from LSB to MSB for first set bit. + // Returns zero if no set bit is found. + if (_BitScanReverse(&where, __x)) + return 31 - where; + return 32; // Undefined Behavior. +#endif } inline _LIBCPP_INLINE_VISIBILITY -unsigned long -__clz(unsigned long __x) -{ +unsigned long __clz(unsigned long __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned long>(__builtin_clzl (__x)); +#else + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + return __clz(static_cast<unsigned>(__x)); +#endif } inline _LIBCPP_INLINE_VISIBILITY -unsigned long long -__clz(unsigned long long __x) -{ +unsigned long long __clz(unsigned long long __x) { +#ifndef _LIBCPP_COMPILER_MSVC return static_cast<unsigned long long>(__builtin_clzll(__x)); +#else + unsigned long where; +// BitScanReverse scans from MSB to LSB for first set bit. +// Returns 0 if no set bit is found. +#if defined(_LIBCPP_HAS_BITSCAN64) + if (_BitScanReverse64(&where, __x)) + return static_cast<int>(63 - where); +#else + // Scan the high 32 bits. + if (_BitScanReverse(&where, static_cast<unsigned long>(__x >> 32))) + return 63 - (where + 32); // Create a bit offset from the MSB. + // Scan the low 32 bits. + if (_BitScanReverse(&where, static_cast<unsigned long>(__x))) + return 63 - where; +#endif + return 64; // Undefined Behavior. +#endif // _LIBCPP_COMPILER_MSVC +} + +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) { +#ifndef _LIBCPP_COMPILER_MSVC + return __builtin_popcount (__x); +#else + static_assert(sizeof(unsigned) == 4, ""); + return __popcnt(__x); +#endif } -inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {return __builtin_popcount (__x);} -inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {return __builtin_popcountl (__x);} -inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {return __builtin_popcountll(__x);} +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) { +#ifndef _LIBCPP_COMPILER_MSVC + return __builtin_popcountl (__x); +#else + static_assert(sizeof(unsigned long) == 4, ""); + return __popcnt(__x); +#endif +} + +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) { +#ifndef _LIBCPP_COMPILER_MSVC + return __builtin_popcountll(__x); +#else + static_assert(sizeof(unsigned long long) == 8, ""); + return __popcnt64(__x); +#endif +} // all_of @@ -857,9 +963,29 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) { for (; __first != __last; ++__first) __f(*__first); - return _LIBCPP_EXPLICIT_MOVE(__f); // explicitly moved for (emulated) C++03 + return __f; } +#if _LIBCPP_STD_VER > 14 +// for_each_n + +template <class _InputIterator, class _Size, class _Function> +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) +{ + typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; + _IntegralSize __n = __orig_n; + while (__n > 0) + { + __f(*__first); + ++__first; + --__n; + } + return __first; +} +#endif + // find template <class _InputIterator, class _Tp> @@ -1215,7 +1341,7 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2> inline _LIBCPP_INLINE_VISIBILITY bool -__equal(_InputIterator1 __first1, _InputIterator1 __last1, +__equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred, input_iterator_tag, input_iterator_tag ) { @@ -1228,8 +1354,8 @@ __equal(_InputIterator1 __first1, _InputIterator1 __last1, template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> inline _LIBCPP_INLINE_VISIBILITY bool -__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, - _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, +__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)) @@ -1242,11 +1368,11 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> inline _LIBCPP_INLINE_VISIBILITY bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, +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, + (__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(), typename iterator_traits<_InputIterator2>::iterator_category()); } @@ -1254,7 +1380,7 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, template <class _InputIterator1, class _InputIterator2> inline _LIBCPP_INLINE_VISIBILITY bool -equal(_InputIterator1 __first1, _InputIterator1 __last1, +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; @@ -1328,7 +1454,7 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> bool __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag ) { @@ -1379,7 +1505,7 @@ __next_iter:; template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> bool __is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1, - _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, + _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag ) { @@ -1458,7 +1584,7 @@ __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> -_LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_RandomAccessIterator1, _RandomAccessIterator1> __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, @@ -1474,9 +1600,9 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, if (__len1 < __len2) return make_pair(__last1, __last1); const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + while (true) { -#if !_LIBCPP_UNROLL_LOOPS while (true) { if (__first1 == __s) @@ -1485,40 +1611,9 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, break; ++__first1; } -#else // !_LIBCPP_UNROLL_LOOPS - for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll) - { - if (__pred(*__first1, *__first2)) - goto __phase2; - if (__pred(*++__first1, *__first2)) - goto __phase2; - if (__pred(*++__first1, *__first2)) - goto __phase2; - if (__pred(*++__first1, *__first2)) - goto __phase2; - ++__first1; - } - switch (__s - __first1) - { - case 3: - if (__pred(*__first1, *__first2)) - break; - ++__first1; - case 2: - if (__pred(*__first1, *__first2)) - break; - ++__first1; - case 1: - if (__pred(*__first1, *__first2)) - break; - case 0: - return make_pair(__last1, __last1); - } - __phase2: -#endif // !_LIBCPP_UNROLL_LOOPS + _RandomAccessIterator1 __m1 = __first1; _RandomAccessIterator2 __m2 = __first2; -#if !_LIBCPP_UNROLL_LOOPS while (true) { if (++__m2 == __last2) @@ -1530,43 +1625,6 @@ __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, break; } } -#else // !_LIBCPP_UNROLL_LOOPS - ++__m2; - ++__m1; - for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll) - { - if (!__pred(*__m1, *__m2)) - goto __continue; - if (!__pred(*++__m1, *++__m2)) - goto __continue; - if (!__pred(*++__m1, *++__m2)) - goto __continue; - if (!__pred(*++__m1, *++__m2)) - goto __continue; - ++__m1; - ++__m2; - } - switch (__last2 - __m2) - { - case 3: - if (!__pred(*__m1, *__m2)) - break; - ++__m1; - ++__m2; - case 2: - if (!__pred(*__m1, *__m2)) - break; - ++__m1; - ++__m2; - case 1: - if (!__pred(*__m1, *__m2)) - break; - case 0: - return make_pair(__first1, __first1 + __len2); - } - __continue: - ++__first1; -#endif // !_LIBCPP_UNROLL_LOOPS } } @@ -1729,6 +1787,20 @@ __unwrap_iter(__wrap_iter<_Tp*> __i) return __i.base(); } +#else + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i) +{ + return __i; +} + #endif // _LIBCPP_DEBUG_LEVEL < 2 template <class _InputIterator, class _OutputIterator> @@ -1802,7 +1874,9 @@ _BidirectionalIterator2 copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - return _VSTD::__copy_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); + return _VSTD::__copy_backward(__unwrap_iter(__first), + __unwrap_iter(__last), + __unwrap_iter(__result)); } // copy_if @@ -2417,7 +2491,7 @@ __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIt template<typename _Integral> inline _LIBCPP_INLINE_VISIBILITY _Integral -__gcd(_Integral __x, _Integral __y) +__algo_gcd(_Integral __x, _Integral __y) { do { @@ -2442,7 +2516,7 @@ __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran _VSTD::swap_ranges(__first, __middle, __middle); return __middle; } - const difference_type __g = _VSTD::__gcd(__m1, __m2); + const difference_type __g = _VSTD::__algo_gcd(__m1, __m2); for (_RandomAccessIterator __p = __first + __g; __p != __first;) { value_type __t(_VSTD::move(*--__p)); @@ -2580,7 +2654,7 @@ min(const _Tp& __a, const _Tp& __b) return _VSTD::min(__a, __b, __less<_Tp>()); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -2598,7 +2672,7 @@ min(initializer_list<_Tp> __t) return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // max_element @@ -2645,7 +2719,7 @@ max(const _Tp& __a, const _Tp& __b) return _VSTD::max(__a, __b, __less<_Tp>()); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -2663,7 +2737,7 @@ max(initializer_list<_Tp> __t) return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 // clamp @@ -2764,7 +2838,7 @@ minmax(const _Tp& __a, const _Tp& __b) return _VSTD::minmax(__a, __b, __less<_Tp>()); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -2785,7 +2859,7 @@ minmax(initializer_list<_Tp> __t, _Compare __comp) __result.second = *__first; ++__first; } - + while (__first != __last) { _Tp __prev = *__first++; @@ -2797,7 +2871,7 @@ minmax(initializer_list<_Tp> __t, _Compare __comp) if ( __comp(__prev, __result.first)) __result.first = __prev; if (!__comp(*__first, __result.second)) __result.second = *__first; } - + __first++; } return __result; @@ -2811,7 +2885,7 @@ minmax(initializer_list<_Tp> __t) return _VSTD::minmax(__t, __less<_Tp>()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // random_shuffle @@ -2836,11 +2910,11 @@ struct __log2_imp<0, _Rp> static const size_t value = _Rp + 1; }; -template <class _UI, _UI _Xp> +template <class _UIntType, _UIntType _Xp> struct __log2 { static const size_t value = __log2_imp<_Xp, - sizeof(_UI) * __CHAR_BIT__ - 1>::value; + sizeof(_UIntType) * __CHAR_BIT__ - 1>::value; }; template<class _Engine, class _UIntType> @@ -2869,7 +2943,7 @@ private: _Engine_result_type __mask0_; _Engine_result_type __mask1_; -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + _Working_result_type(1); #else @@ -2939,6 +3013,7 @@ template<class _Engine, class _UIntType> _UIntType __independent_bits_engine<_Engine, _UIntType>::__eval(true_type) { + const size_t _WRt = numeric_limits<result_type>::digits; result_type _Sp = 0; for (size_t __k = 0; __k < __n0_; ++__k) { @@ -2947,7 +3022,7 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type) { __u = __e_() - _Engine::min(); } while (__u >= __y0_); - if (__w0_ < _WDt) + if (__w0_ < _WRt) _Sp <<= __w0_; else _Sp = 0; @@ -2960,7 +3035,7 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type) { __u = __e_() - _Engine::min(); } while (__u >= __y1_); - if (__w0_ < _WDt - 1) + if (__w0_ < _WRt - 1) _Sp <<= __w0_ + 1; else _Sp = 0; @@ -3058,6 +3133,8 @@ uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p return static_cast<result_type>(__u + __p.a()); } +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \ + || defined(_LIBCPP_BUILDING_LIBRARY) class _LIBCPP_TYPE_VIS __rs_default; _LIBCPP_FUNC_VIS __rs_default __rs_get(); @@ -3110,7 +3187,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) template <class _RandomAccessIterator, class _RandomNumberGenerator> void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _RandomNumberGenerator&& __rand) #else _RandomNumberGenerator& __rand) @@ -3127,10 +3204,83 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, } } } +#endif + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator & __g, + input_iterator_tag) { + + _Distance __k = 0; + for (; __first != __last && __k < __n; ++__first, (void)++__k) + __output_iter[__k] = *__first; + _Distance __sz = __k; + for (; __first != __last; ++__first, (void)++__k) { + _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); + if (__r < __sz) + __output_iter[__r] = *__first; + } + return __output_iter + _VSTD::min(__n, __k); +} + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator& __g, + forward_iterator_tag) { + _Distance __unsampled_sz = _VSTD::distance(__first, __last); + for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) { + _Distance __r = + _VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); + if (__r < __n) { + *__output_iter++ = *__first; + --__n; + } + } + return __output_iter; +} + +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +_LIBCPP_INLINE_VISIBILITY +_SampleIterator __sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, _UniformRandomNumberGenerator& __g) { + typedef typename iterator_traits<_PopulationIterator>::iterator_category + _PopCategory; + typedef typename iterator_traits<_PopulationIterator>::difference_type + _Difference; + static_assert(__is_forward_iterator<_PopulationIterator>::value || + __is_random_access_iterator<_SampleIterator>::value, + "SampleIterator must meet the requirements of RandomAccessIterator"); + typedef typename common_type<_Distance, _Difference>::type _CommonType; + _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); + return _VSTD::__sample( + __first, __last, __output_iter, _CommonType(__n), + __g, _PopCategory()); +} + +#if _LIBCPP_STD_VER > 14 +template <class _PopulationIterator, class _SampleIterator, class _Distance, + class _UniformRandomNumberGenerator> +inline _LIBCPP_INLINE_VISIBILITY +_SampleIterator sample(_PopulationIterator __first, + _PopulationIterator __last, _SampleIterator __output_iter, + _Distance __n, _UniformRandomNumberGenerator&& __g) { + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); +} +#endif // _LIBCPP_STD_VER > 14 template<class _RandomAccessIterator, class _UniformRandomNumberGenerator> void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _UniformRandomNumberGenerator&& __g) #else _UniformRandomNumberGenerator& __g) @@ -4085,10 +4235,6 @@ sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) _VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); } -#ifdef _LIBCPP_MSVC -#pragma warning( push ) -#pragma warning( disable: 4231) -#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&)) @@ -4122,9 +4268,6 @@ _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&)) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC // lower_bound @@ -4423,9 +4566,9 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator ::new(__p) value_type(_VSTD::move(*__i)); typedef reverse_iterator<_BidirectionalIterator> _RBi; typedef reverse_iterator<value_type*> _Rv; - __half_inplace_merge(_Rv(__p), _Rv(__buff), + __half_inplace_merge(_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), - _RBi(__last), __negate<_Compare>(__comp)); + _RBi(__last), __invert<_Compare>(__comp)); } } @@ -4871,7 +5014,8 @@ push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) template <class _Compare, class _RandomAccessIterator> void -__sift_down(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, +__sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/, + _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, _RandomAccessIterator __start) { @@ -5403,9 +5547,9 @@ __set_union(_InputIterator1 __first1, _InputIterator1 __last1, } else { - *__result = *__first1; if (!__comp(*__first1, *__first2)) ++__first2; + *__result = *__first1; ++__first1; } } @@ -5756,4 +5900,6 @@ prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_ALGORITHM diff --git a/lib/libcxx/include/any b/lib/libcxx/include/any new file mode 100644 index 00000000000..d7161b0d6f4 --- /dev/null +++ b/lib/libcxx/include/any @@ -0,0 +1,667 @@ +// -*- C++ -*- +//===------------------------------ any -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ANY +#define _LIBCPP_ANY + +/* + any synopsis + +namespace std { + + class bad_any_cast : public bad_cast + { + public: + virtual const char* what() const noexcept; + }; + + class any + { + public: + + // 6.3.1 any construct/destruct + any() noexcept; + + any(const any& other); + any(any&& other) noexcept; + + template <class ValueType> + any(ValueType&& value); + + ~any(); + + // 6.3.2 any assignments + any& operator=(const any& rhs); + any& operator=(any&& rhs) noexcept; + + template <class ValueType> + any& operator=(ValueType&& rhs); + + // 6.3.3 any modifiers + template <class ValueType, class... Args> + decay_t<ValueType>& emplace(Args&&... args); + template <class ValueType, class U, class... Args> + decay_t<ValueType>& emplace(initializer_list<U>, Args&&...); + void reset() noexcept; + void swap(any& rhs) noexcept; + + // 6.3.4 any observers + bool has_value() const noexcept; + const type_info& type() const noexcept; + }; + + // 6.4 Non-member functions + void swap(any& x, any& y) noexcept; + + template <class T, class ...Args> + any make_any(Args&& ...args); + template <class T, class U, class ...Args> + any make_any(initializer_list<U>, Args&& ...args); + + template<class ValueType> + ValueType any_cast(const any& operand); + template<class ValueType> + ValueType any_cast(any& operand); + template<class ValueType> + ValueType any_cast(any&& operand); + + template<class ValueType> + const ValueType* any_cast(const any* operand) noexcept; + template<class ValueType> + ValueType* any_cast(any* operand) noexcept; + +} // namespace std + +*/ + +#include <experimental/__config> +#include <memory> +#include <new> +#include <typeinfo> +#include <type_traits> +#include <cstdlib> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std { +class _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast +{ +public: + virtual const char* what() const _NOEXCEPT; +}; +} // namespace std + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_bad_any_cast() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_any_cast(); +#else + _VSTD::abort(); +#endif +} + +// Forward declarations +class _LIBCPP_TEMPLATE_VIS any; + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +add_pointer_t<add_const_t<_ValueType>> +any_cast(any const *) _NOEXCEPT; + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT; + +namespace __any_imp +{ + using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>; + + template <class _Tp> + using _IsSmallObject = integral_constant<bool + , sizeof(_Tp) <= sizeof(_Buffer) + && alignment_of<_Buffer>::value + % alignment_of<_Tp>::value == 0 + && is_nothrow_move_constructible<_Tp>::value + >; + + enum class _Action { + _Destroy, + _Copy, + _Move, + _Get, + _TypeInfo + }; + + template <class _Tp> struct _SmallHandler; + template <class _Tp> struct _LargeHandler; + + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo { static constexpr int __id = 0; }; + template <class _Tp> constexpr int __unique_typeinfo<_Tp>::__id; + + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + constexpr const void* __get_fallback_typeid() { + return &__unique_typeinfo<decay_t<_Tp>>::__id; + } + + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + bool __compare_typeid(type_info const* __id, const void* __fallback_id) + { +#if !defined(_LIBCPP_NO_RTTI) + if (__id && *__id == typeid(_Tp)) + return true; +#endif + if (!__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>()) + return true; + return false; + } + + template <class _Tp> + using _Handler = conditional_t< + _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>; + +} // namespace __any_imp + +class _LIBCPP_TEMPLATE_VIS any +{ +public: + // construct/destruct + _LIBCPP_INLINE_VISIBILITY + constexpr any() _NOEXCEPT : __h(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + any(any const & __other) : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Copy, this); + } + + _LIBCPP_INLINE_VISIBILITY + any(any && __other) _NOEXCEPT : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Move, this); + } + + template < + class _ValueType + , class _Tp = decay_t<_ValueType> + , class = enable_if_t< + !is_same<_Tp, any>::value && + !__is_inplace_type<_ValueType>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + any(_ValueType && __value); + + template <class _ValueType, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, _Args...>::value && + is_copy_constructible<_Tp>::value + > + > + _LIBCPP_INLINE_VISIBILITY + explicit any(in_place_type_t<_ValueType>, _Args&&... __args); + + template <class _ValueType, class _Up, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args); + + _LIBCPP_INLINE_VISIBILITY + ~any() { this->reset(); } + + // assignments + _LIBCPP_INLINE_VISIBILITY + any & operator=(any const & __rhs) { + any(__rhs).swap(*this); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + any & operator=(any && __rhs) _NOEXCEPT { + any(_VSTD::move(__rhs)).swap(*this); + return *this; + } + + template < + class _ValueType + , class _Tp = decay_t<_ValueType> + , class = enable_if_t< + !is_same<_Tp, any>::value + && is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + any & operator=(_ValueType && __rhs); + + template <class _ValueType, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... args); + + template <class _ValueType, class _Up, class ..._Args, + class _Tp = decay_t<_ValueType>, + class = enable_if_t< + is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && + is_copy_constructible<_Tp>::value> + > + _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up>, _Args&&...); + + // 6.3.3 any modifiers + _LIBCPP_INLINE_VISIBILITY + void reset() _NOEXCEPT { if (__h) this->__call(_Action::_Destroy); } + + _LIBCPP_INLINE_VISIBILITY + void swap(any & __rhs) _NOEXCEPT; + + // 6.3.4 any observers + _LIBCPP_INLINE_VISIBILITY + bool has_value() const _NOEXCEPT { return __h != nullptr; } + +#if !defined(_LIBCPP_NO_RTTI) + _LIBCPP_INLINE_VISIBILITY + const type_info & type() const _NOEXCEPT { + if (__h) { + return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo)); + } else { + return typeid(void); + } + } +#endif + +private: + typedef __any_imp::_Action _Action; + using _HandleFuncPtr = void* (*)(_Action, any const *, any *, const type_info *, + const void* __fallback_info); + + union _Storage { + constexpr _Storage() : __ptr(nullptr) {} + void * __ptr; + __any_imp::_Buffer __buf; + }; + + _LIBCPP_ALWAYS_INLINE + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr, + const void* __fallback_info = nullptr) const + { + return __h(__a, this, __other, __info, __fallback_info); + } + + _LIBCPP_ALWAYS_INLINE + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr, + const void* __fallback_info = nullptr) + { + return __h(__a, this, __other, __info, __fallback_info); + } + + template <class> + friend struct __any_imp::_SmallHandler; + template <class> + friend struct __any_imp::_LargeHandler; + + template <class _ValueType> + friend add_pointer_t<add_const_t<_ValueType>> + any_cast(any const *) _NOEXCEPT; + + template <class _ValueType> + friend add_pointer_t<_ValueType> + any_cast(any *) _NOEXCEPT; + + _HandleFuncPtr __h = nullptr; + _Storage __s; +}; + +namespace __any_imp +{ + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS _SmallHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, any * __other, + type_info const * __info, const void* __fallback_info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info, __fallback_info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + static _Tp& __create(any & __dest, _Args&&... __args) { + _Tp* __ret = ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Args>(__args)...); + __dest.__h = &_SmallHandler::__handle; + return *__ret; + } + + private: + _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this) { + _Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf)); + __value.~_Tp(); + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) { + _SmallHandler::__create(__dest, *static_cast<_Tp const *>( + static_cast<void const *>(&__this.__s.__buf))); + } + + _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) { + _SmallHandler::__create(__dest, _VSTD::move( + *static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf)))); + __destroy(__this); + } + + _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, + type_info const * __info, + const void* __fallback_id) + { + if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id)) + return static_cast<void*>(&__this.__s.__buf); + return nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + + template <class _Tp> + struct _LIBCPP_TEMPLATE_VIS _LargeHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, + any * __other, type_info const * __info, + void const* __fallback_info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info, __fallback_info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class ..._Args> + _LIBCPP_INLINE_VISIBILITY + static _Tp& __create(any & __dest, _Args&&... __args) { + typedef allocator<_Tp> _Alloc; + typedef __allocator_destructor<_Alloc> _Dp; + _Alloc __a; + unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + _Tp* __ret = ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Args>(__args)...); + __dest.__s.__ptr = __hold.release(); + __dest.__h = &_LargeHandler::__handle; + return *__ret; + } + + private: + + _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this){ + delete static_cast<_Tp*>(__this.__s.__ptr); + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) { + _LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr)); + } + + _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) { + __dest.__s.__ptr = __this.__s.__ptr; + __dest.__h = &_LargeHandler::__handle; + __this.__h = nullptr; + } + + _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, type_info const * __info, + void const* __fallback_info) + { + if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info)) + return static_cast<void*>(__this.__s.__ptr); + return nullptr; + + } + + _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + +} // namespace __any_imp + + +template <class _ValueType, class _Tp, class> +any::any(_ValueType && __v) : __h(nullptr) +{ + __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v)); +} + +template <class _ValueType, class ..._Args, class _Tp, class> +any::any(in_place_type_t<_ValueType>, _Args&&... __args) { + __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...); +}; + +template <class _ValueType, class _Up, class ..._Args, class _Tp, class> +any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) { + __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType, class, class> +inline _LIBCPP_INLINE_VISIBILITY +any & any::operator=(_ValueType && __v) +{ + any(_VSTD::forward<_ValueType>(__v)).swap(*this); + return *this; +} + +template <class _ValueType, class ..._Args, class _Tp, class> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& any::emplace(_Args&&... __args) { + reset(); + return __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType, class _Up, class ..._Args, class _Tp, class> +inline _LIBCPP_INLINE_VISIBILITY +_Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) { + reset(); + return __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...); +} + +inline _LIBCPP_INLINE_VISIBILITY +void any::swap(any & __rhs) _NOEXCEPT +{ + if (this == &__rhs) + return; + if (__h && __rhs.__h) { + any __tmp; + __rhs.__call(_Action::_Move, &__tmp); + this->__call(_Action::_Move, &__rhs); + __tmp.__call(_Action::_Move, this); + } + else if (__h) { + this->__call(_Action::_Move, &__rhs); + } + else if (__rhs.__h) { + __rhs.__call(_Action::_Move, this); + } +} + +// 6.4 Non-member functions + +inline _LIBCPP_INLINE_VISIBILITY +void swap(any & __lhs, any & __rhs) _NOEXCEPT +{ + __lhs.swap(__rhs); +} + +template <class _Tp, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +any make_any(_Args&&... __args) { + return any(in_place_type<_Tp>, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp, class _Up, class ..._Args> +inline _LIBCPP_INLINE_VISIBILITY +any make_any(initializer_list<_Up> __il, _Args&&... __args) { + return any(in_place_type<_Tp>, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any const & __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType const &>::value, + "ValueType is required to be a const lvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<add_const_t<_RawValueType>>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(*__tmp); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any & __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType &>::value, + "ValueType is required to be an lvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<_RawValueType>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(*__tmp); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any && __v) +{ + using _RawValueType = __uncvref_t<_ValueType>; + static_assert(is_constructible<_ValueType, _RawValueType>::value, + "ValueType is required to be an rvalue reference " + "or a CopyConstructible type"); + auto __tmp = _VSTD::any_cast<_RawValueType>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return static_cast<_ValueType>(_VSTD::move(*__tmp)); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +add_pointer_t<add_const_t<_ValueType>> +any_cast(any const * __any) _NOEXCEPT +{ + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + return _VSTD::any_cast<_ValueType>(const_cast<any *>(__any)); +} + +template <class _RetType> +inline _LIBCPP_INLINE_VISIBILITY +_RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept { + return static_cast<_RetType>(__p); +} + +template <class _RetType> +inline _LIBCPP_INLINE_VISIBILITY +_RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept { + return nullptr; +} + +template <class _ValueType> +add_pointer_t<_ValueType> +any_cast(any * __any) _NOEXCEPT +{ + using __any_imp::_Action; + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + typedef typename add_pointer<_ValueType>::type _ReturnType; + if (__any && __any->__h) { + void *__p = __any->__call(_Action::_Get, nullptr, +#if !defined(_LIBCPP_NO_RTTI) + &typeid(_ValueType), +#else + nullptr, +#endif + __any_imp::__get_fallback_typeid<_ValueType>()); + return _VSTD::__pointer_or_func_cast<_ReturnType>( + __p, is_function<_ValueType>{}); + } + return nullptr; +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ANY diff --git a/lib/libcxx/include/array b/lib/libcxx/include/array index 719286d52ea..4eb2fe6fc62 100644 --- a/lib/libcxx/include/array +++ b/lib/libcxx/include/array @@ -108,18 +108,17 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce #include <iterator> #include <algorithm> #include <stdexcept> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include <cassert> -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, size_t _Size> -struct _LIBCPP_TYPE_VIS_ONLY array +struct _LIBCPP_TEMPLATE_VIS array { // types: typedef array __self; @@ -152,31 +151,31 @@ struct _LIBCPP_TYPE_VIS_ONLY array { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} // iterators: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator begin() _NOEXCEPT {return iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cbegin() const _NOEXCEPT {return begin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cend() const _NOEXCEPT {return end();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crend() const _NOEXCEPT {return rend();} // capacity: @@ -184,36 +183,37 @@ struct _LIBCPP_TYPE_VIS_ONLY array _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} // element access: - _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference operator[](size_type __n) const {return __elems_[__n];} - reference at(size_type __n); + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](size_type __n) {return __elems_[__n];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const_reference operator[](size_type __n) const {return __elems_[__n];} + + _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; - _LIBCPP_INLINE_VISIBILITY reference front() {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} - _LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 value_type* data() _NOEXCEPT {return __elems_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const value_type* data() const _NOEXCEPT {return __elems_;} }; template <class _Tp, size_t _Size> +_LIBCPP_CONSTEXPR_AFTER_CXX14 typename array<_Tp, _Size>::reference array<_Tp, _Size>::at(size_type __n) { if (__n >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("array::at"); -#else - assert(!"array::at out_of_range"); -#endif + __throw_out_of_range("array::at"); + return __elems_[__n]; } @@ -223,11 +223,7 @@ typename array<_Tp, _Size>::const_reference array<_Tp, _Size>::at(size_type __n) const { if (__n >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("array::at"); -#else - assert(!"array::at out_of_range"); -#endif + __throw_out_of_range("array::at"); return __elems_[__n]; } @@ -294,12 +290,13 @@ swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) } template <class _Tp, size_t _Size> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<array<_Tp, _Size> > +class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {}; template <size_t _Ip, class _Tp, size_t _Size> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, array<_Tp, _Size> > +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > { + static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); public: typedef _Tp type; }; @@ -322,7 +319,7 @@ get(const array<_Tp, _Size>& __a) _NOEXCEPT return __a.__elems_[_Ip]; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <size_t _Ip, class _Tp, size_t _Size> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -342,7 +339,7 @@ get(const array<_Tp, _Size>&& __a) _NOEXCEPT return _VSTD::move(__a.__elems_[_Ip]); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/atomic b/lib/libcxx/include/atomic index 11f2152e5bc..f55e28ff5e9 100644 --- a/lib/libcxx/include/atomic +++ b/lib/libcxx/include/atomic @@ -557,10 +557,25 @@ void atomic_signal_fence(memory_order m) noexcept; #endif #if _LIBCPP_STD_VER > 14 -// FIXME: use the right feature test macro value as chose by SG10. # define __cpp_lib_atomic_is_always_lock_free 201603L #endif +#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ + _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \ + __m == memory_order_acquire || \ + __m == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + +#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ + _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \ + __m == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + +#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ + _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \ + __f == memory_order_acq_rel, \ + "memory order argument to atomic operation is invalid") + _LIBCPP_BEGIN_NAMESPACE_STD typedef enum memory_order @@ -580,11 +595,11 @@ struct __gcc_atomic_t { #endif _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __gcc_atomic_t() _NOEXCEPT = default; #else __gcc_atomic_t() _NOEXCEPT : __a_value() {} -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT : __a_value(value) {} _Tp __a_value; @@ -846,16 +861,29 @@ kill_dependency(_Tp __y) _NOEXCEPT return __y; } -#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE -#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE -#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE -#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE -#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE -#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE -#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE -#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE -#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE -#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE +#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) +# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE +# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE +# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE +# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE +# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE +# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE +# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE +# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE +# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE +# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE +#else +# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE +# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE +# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE +# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE +# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE +# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE +# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE +# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE +# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE +# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE +#endif // general atomic<T> @@ -882,15 +910,19 @@ struct __atomic_base // false {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} _LIBCPP_INLINE_VISIBILITY void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {__c11_atomic_store(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {__c11_atomic_store(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {return __c11_atomic_load(&__a_, __m);} _LIBCPP_INLINE_VISIBILITY _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {return __c11_atomic_load(&__a_, __m);} _LIBCPP_INLINE_VISIBILITY operator _Tp() const volatile _NOEXCEPT {return load();} @@ -905,18 +937,22 @@ struct __atomic_base // false _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, @@ -936,24 +972,24 @@ struct __atomic_base // false {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __atomic_base() _NOEXCEPT = default; #else __atomic_base() _NOEXCEPT : __a_() {} -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __atomic_base(const __atomic_base&) = delete; __atomic_base& operator=(const __atomic_base&) = delete; __atomic_base& operator=(const __atomic_base&) volatile = delete; -#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#else private: __atomic_base(const __atomic_base&); __atomic_base& operator=(const __atomic_base&); __atomic_base& operator=(const __atomic_base&) volatile; -#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#endif }; #if defined(__cpp_lib_atomic_is_always_lock_free) @@ -1182,6 +1218,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY void atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { __o->store(__d, __m); } @@ -1190,6 +1227,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY void atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { __o->store(__d, __m); } @@ -1218,6 +1256,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _Tp atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { return __o->load(__m); } @@ -1226,6 +1265,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { return __o->load(__m); } @@ -1310,6 +1350,7 @@ bool atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { return __o->compare_exchange_weak(*__e, __d, __s, __f); } @@ -1319,6 +1360,7 @@ inline _LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { return __o->compare_exchange_weak(*__e, __d, __s, __f); } @@ -1331,6 +1373,7 @@ bool atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { return __o->compare_exchange_strong(*__e, __d, __s, __f); } @@ -1341,6 +1384,7 @@ bool atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { return __o->compare_exchange_strong(*__e, __d, __s, __f); } @@ -1691,25 +1735,25 @@ typedef struct atomic_flag {__c11_atomic_store(&__a_, false, __m);} _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG atomic_flag() _NOEXCEPT = default; #else atomic_flag() _NOEXCEPT : __a_() {} -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG atomic_flag(const atomic_flag&) = delete; atomic_flag& operator=(const atomic_flag&) = delete; atomic_flag& operator=(const atomic_flag&) volatile = delete; -#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#else private: atomic_flag(const atomic_flag&); atomic_flag& operator=(const atomic_flag&); atomic_flag& operator=(const atomic_flag&) volatile; -#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#endif } atomic_flag; inline _LIBCPP_INLINE_VISIBILITY diff --git a/lib/libcxx/include/bitset b/lib/libcxx/include/bitset index 3f9b964e45a..cd6c289b4c4 100644 --- a/lib/libcxx/include/bitset +++ b/lib/libcxx/include/bitset @@ -113,10 +113,6 @@ template <size_t N> struct hash<std::bitset<N>>; */ -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - #include <__config> #include <__bit_reference> #include <cstddef> @@ -125,11 +121,14 @@ template <size_t N> struct hash<std::bitset<N>>; #include <stdexcept> #include <iosfwd> #include <__functional_base> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include <cassert> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header #endif -#include <__undef_min_max> +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD @@ -200,11 +199,11 @@ protected: _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT; private: -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG void __init(unsigned long long __v, false_type) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __init(unsigned long long __v, true_type) _NOEXCEPT; -#endif // _LIBCPP_HAS_NO_CONSTEXPR +#endif // _LIBCPP_CXX03_LANG unsigned long to_ulong(false_type) const; _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong(true_type) const; @@ -220,24 +219,29 @@ template <size_t _N_words, size_t _Size> inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#ifndef _LIBCPP_CXX03_LANG : __first_{0} #endif { -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG _VSTD::fill_n(__first_, _N_words, __storage_type(0)); #endif } -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG template <size_t _N_words, size_t _Size> void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; - for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) - __t[__i] = static_cast<__storage_type>(__v); + size_t __sz = _Size; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) + if ( __sz < __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; + else + __t[__i] = static_cast<__storage_type>(__v); + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); @@ -249,26 +253,31 @@ void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { __first_[0] = __v; + if (_Size < __bits_per_word) + __first_[0] &= ( 1ULL << _Size ) - 1; + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); } -#endif // _LIBCPP_HAS_NO_CONSTEXPR +#endif // _LIBCPP_CXX03_LANG template <size_t _N_words, size_t _Size> inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#ifndef _LIBCPP_CXX03_LANG #if __SIZEOF_SIZE_T__ == 8 : __first_{__v} #elif __SIZEOF_SIZE_T__ == 4 - : __first_{__v, __v >> __bits_per_word} + : __first_{static_cast<__storage_type>(__v), + _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) + : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} #else #error This constructor has not been ported to this platform #endif #endif { -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); #endif } @@ -326,11 +335,8 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); if (__i != __e) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw overflow_error("bitset to_ulong overflow error"); -#else - assert(!"bitset to_ulong overflow error"); -#endif + __throw_overflow_error("bitset to_ulong overflow error"); + return __first_[0]; } @@ -349,11 +355,8 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); if (__i != __e) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw overflow_error("bitset to_ullong overflow error"); -#else - assert(!"bitset to_ullong overflow error"); -#endif + __throw_overflow_error("bitset to_ullong overflow error"); + return to_ullong(true_type()); } @@ -510,7 +513,10 @@ template <size_t _Size> inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT - : __first_(static_cast<__storage_type>(__v)) + : __first_( + _Size == __bits_per_word ? static_cast<__storage_type>(__v) + : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) + ) { } @@ -655,11 +661,11 @@ __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT { } -template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset; +template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; template <size_t _Size> struct hash<bitset<_Size> >; template <size_t _Size> -class _LIBCPP_TYPE_VIS_ONLY bitset +class _LIBCPP_TEMPLATE_VIS bitset : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> { public: @@ -763,11 +769,8 @@ bitset<_Size>::bitset(const _CharT* __str, size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); for (size_t __i = 0; __i < __rlen; ++__i) if (__str[__i] != __zero && __str[__i] != __one) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw invalid_argument("bitset string ctor has invalid argument"); -#else - assert(!"bitset string ctor has invalid argument"); -#endif + __throw_invalid_argument("bitset string ctor has invalid argument"); + size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) @@ -789,19 +792,13 @@ bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __zero, _CharT __one) { if (__pos > __str.size()) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset string pos out of range"); -#else - assert(!"bitset string pos out of range"); -#endif + __throw_out_of_range("bitset string pos out of range"); + size_t __rlen = _VSTD::min(__n, __str.size() - __pos); for (size_t __i = __pos; __i < __pos + __rlen; ++__i) if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw invalid_argument("bitset string ctor has invalid argument"); -#else - assert(!"bitset string ctor has invalid argument"); -#endif + __throw_invalid_argument("bitset string ctor has invalid argument"); + size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) @@ -876,11 +873,8 @@ bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset set argument out of range"); -#else - assert(!"bitset set argument out of range"); -#endif + __throw_out_of_range("bitset set argument out of range"); + (*this)[__pos] = __val; return *this; } @@ -899,11 +893,8 @@ bitset<_Size>& bitset<_Size>::reset(size_t __pos) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset reset argument out of range"); -#else - assert(!"bitset reset argument out of range"); -#endif + __throw_out_of_range("bitset reset argument out of range"); + (*this)[__pos] = false; return *this; } @@ -932,11 +923,8 @@ bitset<_Size>& bitset<_Size>::flip(size_t __pos) { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset flip argument out of range"); -#else - assert(!"bitset flip argument out of range"); -#endif + __throw_out_of_range("bitset flip argument out of range"); + reference r = base::__make_ref(__pos); r = ~r; return *this; @@ -1027,11 +1015,8 @@ bool bitset<_Size>::test(size_t __pos) const { if (__pos >= _Size) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("bitset test argument out of range"); -#else - assert(!"bitset test argument out of range"); -#endif + __throw_out_of_range("bitset test argument out of range"); + return (*this)[__pos]; } @@ -1102,7 +1087,7 @@ operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT } template <size_t _Size> -struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> > +struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public unary_function<bitset<_Size>, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -1120,4 +1105,6 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_BITSET diff --git a/lib/libcxx/include/chrono b/lib/libcxx/include/chrono index 68484e98243..809f773b6c6 100644 --- a/lib/libcxx/include/chrono +++ b/lib/libcxx/include/chrono @@ -26,7 +26,7 @@ duration_cast(const duration<Rep, Period>& fd); template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; -template <class Rep> constexpr bool treat_as_floating_point_v +template <class Rep> inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<Rep>::value; // C++17 template <class Rep> @@ -48,7 +48,7 @@ class duration static_assert(Period::num > 0, "duration period must be positive"); public: typedef Rep rep; - typedef Period period; + typedef typename _Period::type period; constexpr duration() = default; template <class Rep2> @@ -75,15 +75,15 @@ public: // arithmetic - constexpr duration operator+() const; - constexpr duration operator-() const; - duration& operator++(); - duration operator++(int); - duration& operator--(); - duration operator--(int); + constexpr common_type<duration>::type operator+() const; + constexpr common_type<duration>::type operator-() const; + constexpr duration& operator++(); + constexpr duration operator++(int); + constexpr duration& operator--(); + constexpr duration operator--(int); - duration& operator+=(const duration& d); - duration& operator-=(const duration& d); + constexpr duration& operator+=(const duration& d); + constexpr duration& operator-=(const duration& d); duration& operator*=(const rep& rhs); duration& operator/=(const rep& rhs); @@ -283,18 +283,18 @@ typedef steady_clock high_resolution_clock; } // chrono -constexpr chrono::hours operator "" h(unsigned long long); // C++14 -constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double); // C++14 -constexpr chrono::minutes operator "" min(unsigned long long); // C++14 -constexpr chrono::duration<unspecified , ratio<60,1>> operator "" min(long double); // C++14 -constexpr chrono::seconds operator "" s(unsigned long long); // C++14 -constexpr chrono::duration<unspecified > operator "" s(long double); // C++14 -constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14 -constexpr chrono::duration<unspecified , milli> operator "" ms(long double); // C++14 -constexpr chrono::microseconds operator "" us(unsigned long long); // C++14 -constexpr chrono::duration<unspecified , micro> operator "" us(long double); // C++14 -constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14 -constexpr chrono::duration<unspecified , nano> operator "" ns(long double); // C++14 +constexpr chrono::hours operator ""h(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 +constexpr chrono::minutes operator ""min(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 +constexpr chrono::seconds operator ""s(unsigned long long); // C++14 +constexpr chrono::duration<unspecified > operator ""s(long double); // C++14 +constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 +constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 +constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 +constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 } // std */ @@ -305,18 +305,20 @@ constexpr chrono::duration<unspecified , nano> operator "" ns(long doub #include <ratio> #include <limits> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { -template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TYPE_VIS_ONLY duration; +template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration; template <class _Tp> struct __is_duration : false_type {}; @@ -336,7 +338,7 @@ struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; } // chrono template <class _Rep1, class _Period1, class _Rep2, class _Period2> -struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::duration<_Rep1, _Period1>, +struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > { typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, @@ -414,15 +416,16 @@ duration_cast(const duration<_Rep, _Period>& __fd) } template <class _Rep> -struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {}; +struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Rep> _LIBCPP_CONSTEXPR bool treat_as_floating_point_v +template <class _Rep> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value; #endif template <class _Rep> -struct _LIBCPP_TYPE_VIS_ONLY duration_values +struct _LIBCPP_TEMPLATE_VIS duration_values { public: _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);} @@ -485,7 +488,7 @@ round(const duration<_Rep, _Period>& __d) // duration template <class _Rep, class _Period> -class _LIBCPP_TYPE_VIS_ONLY duration +class _LIBCPP_TEMPLATE_VIS duration { static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); @@ -523,13 +526,13 @@ class _LIBCPP_TYPE_VIS_ONLY duration public: typedef _Rep rep; - typedef _Period period; + typedef typename _Period::type period; private: rep __rep_; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG duration() = default; #else duration() {} @@ -565,20 +568,20 @@ public: // arithmetic - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator+() const {return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration operator-() const {return duration(-__rep_);} - _LIBCPP_INLINE_VISIBILITY duration& operator++() {++__rep_; return *this;} - _LIBCPP_INLINE_VISIBILITY duration operator++(int) {return duration(__rep_++);} - _LIBCPP_INLINE_VISIBILITY duration& operator--() {--__rep_; return *this;} - _LIBCPP_INLINE_VISIBILITY duration operator--(int) {return duration(__rep_--);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} - _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} - _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} - _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} - _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} // special values @@ -828,7 +831,7 @@ operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2 ////////////////////////////////////////////////////////// template <class _Clock, class _Duration = typename _Clock::duration> -class _LIBCPP_TYPE_VIS_ONLY time_point +class _LIBCPP_TEMPLATE_VIS time_point { static_assert(__is_duration<_Duration>::value, "Second template parameter of time_point must be a std::chrono::duration"); @@ -872,7 +875,7 @@ public: } // chrono template <class _Clock, class _Duration1, class _Duration2> -struct _LIBCPP_TYPE_VIS_ONLY common_type<chrono::time_point<_Clock, _Duration1>, +struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> > { typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; @@ -1026,7 +1029,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __lhs + (-__rhs); + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; + return _Ret(__lhs.time_since_epoch() -__rhs); } // duration operator-(time_point x, time_point y); @@ -1084,67 +1088,67 @@ inline namespace literals inline namespace chrono_literals { - constexpr chrono::hours operator"" h(unsigned long long __h) + constexpr chrono::hours operator""h(unsigned long long __h) { return chrono::hours(static_cast<chrono::hours::rep>(__h)); } - constexpr chrono::duration<long double, ratio<3600,1>> operator"" h(long double __h) + constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h) { return chrono::duration<long double, ratio<3600,1>>(__h); } - constexpr chrono::minutes operator"" min(unsigned long long __m) + constexpr chrono::minutes operator""min(unsigned long long __m) { return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); } - constexpr chrono::duration<long double, ratio<60,1>> operator"" min(long double __m) + constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m) { return chrono::duration<long double, ratio<60,1>> (__m); } - constexpr chrono::seconds operator"" s(unsigned long long __s) + constexpr chrono::seconds operator""s(unsigned long long __s) { return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); } - constexpr chrono::duration<long double> operator"" s(long double __s) + constexpr chrono::duration<long double> operator""s(long double __s) { return chrono::duration<long double> (__s); } - constexpr chrono::milliseconds operator"" ms(unsigned long long __ms) + constexpr chrono::milliseconds operator""ms(unsigned long long __ms) { return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); } - constexpr chrono::duration<long double, milli> operator"" ms(long double __ms) + constexpr chrono::duration<long double, milli> operator""ms(long double __ms) { return chrono::duration<long double, milli>(__ms); } - constexpr chrono::microseconds operator"" us(unsigned long long __us) + constexpr chrono::microseconds operator""us(unsigned long long __us) { return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); } - constexpr chrono::duration<long double, micro> operator"" us(long double __us) + constexpr chrono::duration<long double, micro> operator""us(long double __us) { return chrono::duration<long double, micro> (__us); } - constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns) + constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) { return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); } - constexpr chrono::duration<long double, nano> operator"" ns(long double __ns) + constexpr chrono::duration<long double, nano> operator""ns(long double __ns) { return chrono::duration<long double, nano> (__ns); } @@ -1159,4 +1163,6 @@ namespace chrono { // hoist the literals into namespace std::chrono _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_CHRONO diff --git a/lib/libcxx/include/cmath b/lib/libcxx/include/cmath index b3e959405e9..917928a1f42 100644 --- a/lib/libcxx/include/cmath +++ b/lib/libcxx/include/cmath @@ -331,7 +331,6 @@ using ::double_t; using ::abs; #endif -#ifndef __sun__ using ::acos; using ::acosf; using ::asin; @@ -346,58 +345,47 @@ using ::cos; using ::cosf; using ::cosh; using ::coshf; -#endif // __sun__ using ::exp; using ::expf; -#ifndef __sun__ using ::fabs; using ::fabsf; using ::floor; using ::floorf; -#endif //__sun__ using ::fmod; using ::fmodf; -#ifndef __sun__ using ::frexp; using ::frexpf; using ::ldexp; using ::ldexpf; -#endif // __sun__ using ::log; using ::logf; -#ifndef __sun__ using ::log10; using ::log10f; using ::modf; using ::modff; -#endif // __sun__ using ::pow; using ::powf; -#ifndef __sun__ using ::sin; using ::sinf; using ::sinh; using ::sinhf; -#endif // __sun__ using ::sqrt; using ::sqrtf; using ::tan; using ::tanf; -#ifndef __sun__ using ::tanh; using ::tanhf; -#ifndef _LIBCPP_MSVCRT using ::acosh; using ::acoshf; using ::asinh; @@ -406,12 +394,10 @@ using ::atanh; using ::atanhf; using ::cbrt; using ::cbrtf; -#endif using ::copysign; using ::copysignf; -#ifndef _LIBCPP_MSVCRT using ::erf; using ::erff; using ::erfc; @@ -448,16 +434,10 @@ using ::lrint; using ::lrintf; using ::lround; using ::lroundf; -#endif // _LIBCPP_MSVCRT -#endif // __sun__ -#ifndef _LIBCPP_MSVCRT using ::nan; using ::nanf; -#endif // _LIBCPP_MSVCRT -#ifndef __sun__ -#ifndef _LIBCPP_MSVCRT using ::nearbyint; using ::nearbyintf; using ::nextafter; @@ -480,7 +460,6 @@ using ::tgamma; using ::tgammaf; using ::trunc; using ::truncf; -#endif // !_LIBCPP_MSVCRT using ::acosl; using ::asinl; @@ -504,17 +483,14 @@ using ::sinhl; using ::sqrtl; using ::tanl; -#ifndef _LIBCPP_MSVCRT using ::tanhl; using ::acoshl; using ::asinhl; using ::atanhl; using ::cbrtl; -#endif // !_LIBCPP_MSVCRT using ::copysignl; -#ifndef _LIBCPP_MSVCRT using ::erfl; using ::erfcl; using ::exp2l; @@ -545,12 +521,6 @@ using ::scalblnl; using ::scalbnl; using ::tgammal; using ::truncl; -#endif // !_LIBCPP_MSVCRT - -#else -using ::lgamma; -using ::lgammaf; -#endif // __sun__ #if _LIBCPP_STD_VER > 14 inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } @@ -559,23 +529,83 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y template <class _A1, class _A2, class _A3> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename __lazy_enable_if < - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value && - std::is_arithmetic<_A3>::value, - std::__promote<_A1, _A2, _A3> + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value && + is_arithmetic<_A3>::value, + __promote<_A1, _A2, _A3> >::type hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT { - typedef typename std::__promote<_A1, _A2, _A3>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value && - std::is_same<_A3, __result_type>::value)), ""); + typedef typename __promote<_A1, _A2, _A3>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value && + is_same<_A3, __result_type>::value)), ""); return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); } #endif +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isnan) + return __builtin_isnan(__lcpp_x); +#else + return isnan(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isnan(__lcpp_x); +} + +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isinf) + return __builtin_isinf(__lcpp_x); +#else + return isinf(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isinf(__lcpp_x); +} + +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ +#if __has_builtin(__builtin_isfinite) + return __builtin_isfinite(__lcpp_x); +#else + return isfinite(__lcpp_x); +#endif +} + +template <class _A1> +_LIBCPP_ALWAYS_INLINE +_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT +{ + return isfinite(__lcpp_x); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CMATH diff --git a/lib/libcxx/include/codecvt b/lib/libcxx/include/codecvt index 6eff107cd1c..46f56acff71 100644 --- a/lib/libcxx/include/codecvt +++ b/lib/libcxx/include/codecvt @@ -182,7 +182,7 @@ protected: template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0> -class _LIBCPP_TYPE_VIS_ONLY codecvt_utf8 +class _LIBCPP_TEMPLATE_VIS codecvt_utf8 : public __codecvt_utf8<_Elem> { public: @@ -410,7 +410,7 @@ protected: template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0> -class _LIBCPP_TYPE_VIS_ONLY codecvt_utf16 +class _LIBCPP_TEMPLATE_VIS codecvt_utf16 : public __codecvt_utf16<_Elem, _Mode & little_endian> { public: @@ -533,7 +533,7 @@ protected: template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0> -class _LIBCPP_TYPE_VIS_ONLY codecvt_utf8_utf16 +class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16 : public __codecvt_utf8_utf16<_Elem> { public: diff --git a/lib/libcxx/include/complex b/lib/libcxx/include/complex index f56138fa2d1..41a47cfba47 100644 --- a/lib/libcxx/include/complex +++ b/lib/libcxx/include/complex @@ -245,9 +245,6 @@ template<class T, class charT, class traits> #include <stdexcept> #include <cmath> #include <sstream> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include <cassert> -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -255,13 +252,13 @@ template<class T, class charT, class traits> _LIBCPP_BEGIN_NAMESPACE_STD -template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY complex; +template<class _Tp> class _LIBCPP_TEMPLATE_VIS complex; template<class _Tp> complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w); template<class _Tp> complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y); template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY complex +class _LIBCPP_TEMPLATE_VIS complex { public: typedef _Tp value_type; @@ -319,11 +316,11 @@ public: } }; -template<> class _LIBCPP_TYPE_VIS_ONLY complex<double>; -template<> class _LIBCPP_TYPE_VIS_ONLY complex<long double>; +template<> class _LIBCPP_TEMPLATE_VIS complex<double>; +template<> class _LIBCPP_TEMPLATE_VIS complex<long double>; template<> -class _LIBCPP_TYPE_VIS_ONLY complex<float> +class _LIBCPP_TEMPLATE_VIS complex<float> { float __re_; float __im_; @@ -381,7 +378,7 @@ public: }; template<> -class _LIBCPP_TYPE_VIS_ONLY complex<double> +class _LIBCPP_TEMPLATE_VIS complex<double> { double __re_; double __im_; @@ -439,7 +436,7 @@ public: }; template<> -class _LIBCPP_TYPE_VIS_ONLY complex<long double> +class _LIBCPP_TEMPLATE_VIS complex<long double> { long double __re_; long double __im_; @@ -602,39 +599,39 @@ operator*(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __bc = __b * __c; _Tp __x = __ac - __bd; _Tp __y = __ad + __bc; - if (isnan(__x) && isnan(__y)) + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) { bool __recalc = false; - if (isinf(__a) || isinf(__b)) + if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) { - __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a); - __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b); - if (isnan(__c)) + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) __c = copysign(_Tp(0), __c); - if (isnan(__d)) + if (__libcpp_isnan_or_builtin(__d)) __d = copysign(_Tp(0), __d); __recalc = true; } - if (isinf(__c) || isinf(__d)) + if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d)) { - __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c); - __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d); - if (isnan(__a)) + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + if (__libcpp_isnan_or_builtin(__a)) __a = copysign(_Tp(0), __a); - if (isnan(__b)) + if (__libcpp_isnan_or_builtin(__b)) __b = copysign(_Tp(0), __b); __recalc = true; } - if (!__recalc && (isinf(__ac) || isinf(__bd) || - isinf(__ad) || isinf(__bc))) + if (!__recalc && (__libcpp_isinf_or_builtin(__ac) || __libcpp_isinf_or_builtin(__bd) || + __libcpp_isinf_or_builtin(__ad) || __libcpp_isinf_or_builtin(__bc))) { - if (isnan(__a)) + if (__libcpp_isnan_or_builtin(__a)) __a = copysign(_Tp(0), __a); - if (isnan(__b)) + if (__libcpp_isnan_or_builtin(__b)) __b = copysign(_Tp(0), __b); - if (isnan(__c)) + if (__libcpp_isnan_or_builtin(__c)) __c = copysign(_Tp(0), __c); - if (isnan(__d)) + if (__libcpp_isnan_or_builtin(__d)) __d = copysign(_Tp(0), __d); __recalc = true; } @@ -677,7 +674,7 @@ operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __c = __w.real(); _Tp __d = __w.imag(); _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); - if (isfinite(__logbw)) + if (__libcpp_isfinite_or_builtin(__logbw)) { __ilogbw = static_cast<int>(__logbw); __c = scalbn(__c, -__ilogbw); @@ -686,24 +683,24 @@ operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __denom = __c * __c + __d * __d; _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); - if (isnan(__x) && isnan(__y)) + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) { - if ((__denom == _Tp(0)) && (!isnan(__a) || !isnan(__b))) + if ((__denom == _Tp(0)) && (!__libcpp_isnan_or_builtin(__a) || !__libcpp_isnan_or_builtin(__b))) { __x = copysign(_Tp(INFINITY), __c) * __a; __y = copysign(_Tp(INFINITY), __c) * __b; } - else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d)) + else if ((__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) && __libcpp_isfinite_or_builtin(__c) && __libcpp_isfinite_or_builtin(__d)) { - __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a); - __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b); + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); __x = _Tp(INFINITY) * (__a * __c + __b * __d); __y = _Tp(INFINITY) * (__b * __c - __a * __d); } - else if (isinf(__logbw) && __logbw > _Tp(0) && isfinite(__a) && isfinite(__b)) + else if (__libcpp_isinf_or_builtin(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite_or_builtin(__a) && __libcpp_isfinite_or_builtin(__b)) { - __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c); - __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d); + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); __x = _Tp(0) * (__a * __c + __b * __d); __y = _Tp(0) * (__b * __c - __a * __d); } @@ -795,45 +792,41 @@ operator!=(const _Tp& __x, const complex<_Tp>& __y) // 26.3.7 values: -// real +template <class _Tp, bool = is_integral<_Tp>::value, + bool = is_floating_point<_Tp>::value + > +struct __libcpp_complex_overload_traits {}; -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -_Tp -real(const complex<_Tp>& __c) +// Integral Types +template <class _Tp> +struct __libcpp_complex_overload_traits<_Tp, true, false> { - return __c.real(); -} + typedef double _ValueType; + typedef complex<double> _ComplexType; +}; -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -long double -real(long double __re) +// Floating point types +template <class _Tp> +struct __libcpp_complex_overload_traits<_Tp, false, true> { - return __re; -} + typedef _Tp _ValueType; + typedef complex<_Tp> _ComplexType; +}; -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -double -real(double __re) -{ - return __re; -} +// real template<class _Tp> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -typename enable_if -< - is_integral<_Tp>::value, - double ->::type -real(_Tp __re) +_Tp +real(const complex<_Tp>& __c) { - return __re; + return __c.real(); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -float -real(float __re) +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +real(_Tp __re) { return __re; } @@ -848,35 +841,10 @@ imag(const complex<_Tp>& __c) return __c.imag(); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -long double -imag(long double __re) -{ - return 0; -} - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -double -imag(double __re) -{ - return 0; -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -typename enable_if -< - is_integral<_Tp>::value, - double ->::type -imag(_Tp __re) -{ - return 0; -} - -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -float -imag(float __re) +typename __libcpp_complex_overload_traits<_Tp>::_ValueType +imag(_Tp) { return 0; } @@ -901,25 +869,22 @@ arg(const complex<_Tp>& __c) return atan2(__c.imag(), __c.real()); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -long double -arg(long double __re) +typename enable_if< + is_same<_Tp, long double>::value, + long double +>::type +arg(_Tp __re) { return atan2l(0.L, __re); } -inline _LIBCPP_INLINE_VISIBILITY -double -arg(double __re) -{ - return atan2(0., __re); -} - template<class _Tp> inline _LIBCPP_INLINE_VISIBILITY typename enable_if < - is_integral<_Tp>::value, + is_integral<_Tp>::value || is_same<_Tp, double>::value, double >::type arg(_Tp __re) @@ -927,9 +892,13 @@ arg(_Tp __re) return atan2(0., __re); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -float -arg(float __re) +typename enable_if< + is_same<_Tp, float>::value, + float +>::type +arg(_Tp __re) { return atan2f(0.F, __re); } @@ -941,44 +910,20 @@ inline _LIBCPP_INLINE_VISIBILITY _Tp norm(const complex<_Tp>& __c) { - if (isinf(__c.real())) + if (__libcpp_isinf_or_builtin(__c.real())) return abs(__c.real()); - if (isinf(__c.imag())) + if (__libcpp_isinf_or_builtin(__c.imag())) return abs(__c.imag()); return __c.real() * __c.real() + __c.imag() * __c.imag(); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -long double -norm(long double __re) -{ - return __re * __re; -} - -inline _LIBCPP_INLINE_VISIBILITY -double -norm(double __re) -{ - return __re * __re; -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_integral<_Tp>::value, - double ->::type +typename __libcpp_complex_overload_traits<_Tp>::_ValueType norm(_Tp __re) { - return (double)__re * __re; -} - -inline _LIBCPP_INLINE_VISIBILITY -float -norm(float __re) -{ - return __re * __re; + typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType; + return static_cast<_ValueType>(__re) * __re; } // conj @@ -991,38 +936,16 @@ conj(const complex<_Tp>& __c) return complex<_Tp>(__c.real(), -__c.imag()); } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -complex<long double> -conj(long double __re) -{ - return complex<long double>(__re); -} - -inline _LIBCPP_INLINE_VISIBILITY -complex<double> -conj(double __re) -{ - return complex<double>(__re); -} - -template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_integral<_Tp>::value, - complex<double> ->::type +typename __libcpp_complex_overload_traits<_Tp>::_ComplexType conj(_Tp __re) { - return complex<double>(__re); + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); } -inline _LIBCPP_INLINE_VISIBILITY -complex<float> -conj(float __re) -{ - return complex<float>(__re); -} + // proj @@ -1032,48 +955,36 @@ complex<_Tp> proj(const complex<_Tp>& __c) { std::complex<_Tp> __r = __c; - if (isinf(__c.real()) || isinf(__c.imag())) + if (__libcpp_isinf_or_builtin(__c.real()) || __libcpp_isinf_or_builtin(__c.imag())) __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag())); return __r; } +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -complex<long double> -proj(long double __re) -{ - if (isinf(__re)) - __re = abs(__re); - return complex<long double>(__re); -} - -inline _LIBCPP_INLINE_VISIBILITY -complex<double> -proj(double __re) +typename enable_if +< + is_floating_point<_Tp>::value, + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType +>::type +proj(_Tp __re) { - if (isinf(__re)) + if (__libcpp_isinf_or_builtin(__re)) __re = abs(__re); - return complex<double>(__re); + return complex<_Tp>(__re); } -template<class _Tp> +template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value, - complex<double> + typename __libcpp_complex_overload_traits<_Tp>::_ComplexType >::type proj(_Tp __re) { - return complex<double>(__re); -} - -inline _LIBCPP_INLINE_VISIBILITY -complex<float> -proj(float __re) -{ - if (isinf(__re)) - __re = abs(__re); - return complex<float>(__re); + typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType; + return _ComplexType(__re); } // polar @@ -1082,25 +993,25 @@ template<class _Tp> complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta = _Tp(0)) { - if (isnan(__rho) || signbit(__rho)) + if (__libcpp_isnan_or_builtin(__rho) || signbit(__rho)) return complex<_Tp>(_Tp(NAN), _Tp(NAN)); - if (isnan(__theta)) + if (__libcpp_isnan_or_builtin(__theta)) { - if (isinf(__rho)) + if (__libcpp_isinf_or_builtin(__rho)) return complex<_Tp>(__rho, __theta); return complex<_Tp>(__theta, __theta); } - if (isinf(__theta)) + if (__libcpp_isinf_or_builtin(__theta)) { - if (isinf(__rho)) + if (__libcpp_isinf_or_builtin(__rho)) return complex<_Tp>(__rho, _Tp(NAN)); return complex<_Tp>(_Tp(NAN), _Tp(NAN)); } _Tp __x = __rho * cos(__theta); - if (isnan(__x)) + if (__libcpp_isnan_or_builtin(__x)) __x = 0; _Tp __y = __rho * sin(__theta); - if (isnan(__y)) + if (__libcpp_isnan_or_builtin(__y)) __y = 0; return complex<_Tp>(__x, __y); } @@ -1131,13 +1042,13 @@ template<class _Tp> complex<_Tp> sqrt(const complex<_Tp>& __x) { - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(_Tp(INFINITY), __x.imag()); - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { if (__x.real() > _Tp(0)) - return complex<_Tp>(__x.real(), isnan(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); - return complex<_Tp>(isnan(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); + return complex<_Tp>(__x.real(), __libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); + return complex<_Tp>(__libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); } return polar(sqrt(abs(__x)), arg(__x) / _Tp(2)); } @@ -1149,21 +1060,21 @@ complex<_Tp> exp(const complex<_Tp>& __x) { _Tp __i = __x.imag(); - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { if (__x.real() < _Tp(0)) { - if (!isfinite(__i)) + if (!__libcpp_isfinite_or_builtin(__i)) __i = _Tp(1); } - else if (__i == 0 || !isfinite(__i)) + else if (__i == 0 || !__libcpp_isfinite_or_builtin(__i)) { - if (isinf(__i)) + if (__libcpp_isinf_or_builtin(__i)) __i = _Tp(NAN); return complex<_Tp>(__x.real(), __i); } } - else if (isnan(__x.real()) && __x.imag() == 0) + else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) return __x; _Tp __e = exp(__x.real()); return complex<_Tp>(__e * cos(__i), __e * sin(__i)); @@ -1221,23 +1132,23 @@ complex<_Tp> asinh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return __x; - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); } - if (isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.imag(), __x.real()); if (__x.imag() == 0) return __x; return complex<_Tp>(__x.real(), __x.real()); } - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag())); complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) + _Tp(1))); return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); @@ -1250,11 +1161,11 @@ complex<_Tp> acosh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.real()), __x.imag()); - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { if (__x.real() > 0) return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); @@ -1265,13 +1176,13 @@ acosh(const complex<_Tp>& __x) return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); } - if (isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.imag()), __x.real()); return complex<_Tp>(__x.real(), __x.real()); } - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag())); complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1))); return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag())); @@ -1284,21 +1195,21 @@ complex<_Tp> atanh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); } - if (isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) { - if (isinf(__x.real()) || __x.real() == 0) + if (__libcpp_isinf_or_builtin(__x.real()) || __x.real() == 0) return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag()); return complex<_Tp>(__x.imag(), __x.imag()); } - if (isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { return complex<_Tp>(__x.real(), __x.real()); } - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); } @@ -1316,11 +1227,11 @@ template<class _Tp> complex<_Tp> sinh(const complex<_Tp>& __x) { - if (isinf(__x.real()) && !isfinite(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), _Tp(NAN)); - if (__x.real() == 0 && !isfinite(__x.imag())) + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), _Tp(NAN)); - if (__x.imag() == 0 && !isfinite(__x.real())) + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) return __x; return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag())); } @@ -1331,13 +1242,13 @@ template<class _Tp> complex<_Tp> cosh(const complex<_Tp>& __x) { - if (isinf(__x.real()) && !isfinite(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.real()), _Tp(NAN)); - if (__x.real() == 0 && !isfinite(__x.imag())) + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(_Tp(NAN), __x.real()); if (__x.real() == 0 && __x.imag() == 0) return complex<_Tp>(_Tp(1), __x.imag()); - if (__x.imag() == 0 && !isfinite(__x.real())) + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) return complex<_Tp>(abs(__x.real()), __x.imag()); return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag())); } @@ -1348,19 +1259,19 @@ template<class _Tp> complex<_Tp> tanh(const complex<_Tp>& __x) { - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (!isfinite(__x.imag())) + if (!__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(_Tp(1), _Tp(0)); return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag()))); } - if (isnan(__x.real()) && __x.imag() == 0) + if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) return __x; _Tp __2r(_Tp(2) * __x.real()); _Tp __2i(_Tp(2) * __x.imag()); _Tp __d(cosh(__2r) + cos(__2i)); _Tp __2rsh(sinh(__2r)); - if (isinf(__2rsh) && isinf(__d)) + if (__libcpp_isinf_or_builtin(__2rsh) && __libcpp_isinf_or_builtin(__d)) return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1), __2i > _Tp(0) ? _Tp(0) : _Tp(-0.)); return complex<_Tp>(__2rsh/__d, sin(__2i)/__d); @@ -1383,11 +1294,11 @@ complex<_Tp> acos(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return complex<_Tp>(__x.imag(), __x.real()); - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { if (__x.real() < _Tp(0)) return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag()); @@ -1397,13 +1308,13 @@ acos(const complex<_Tp>& __x) return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real()); return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real()); } - if (isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), -__x.imag()); return complex<_Tp>(__x.real(), __x.real()); } - if (isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__pi/_Tp(2), -__x.imag()); if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag()))) return complex<_Tp>(__pi/_Tp(2), -__x.imag()); diff --git a/lib/libcxx/include/condition_variable b/lib/libcxx/include/condition_variable index 10e00770167..c45a326d898 100644 --- a/lib/libcxx/include/condition_variable +++ b/lib/libcxx/include/condition_variable @@ -133,12 +133,14 @@ public: void notify_all() _NOEXCEPT; template <class _Lock> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait(_Lock& __lock); template <class _Lock, class _Predicate> _LIBCPP_INLINE_VISIBILITY void wait(_Lock& __lock, _Predicate __pred); template <class _Lock, class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t); diff --git a/lib/libcxx/include/cstddef b/lib/libcxx/include/cstddef index edd106c001b..adeefdac9be 100644 --- a/lib/libcxx/include/cstddef +++ b/lib/libcxx/include/cstddef @@ -28,6 +28,7 @@ Types: size_t max_align_t nullptr_t + byte // C++17 } // std @@ -48,7 +49,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD using ::ptrdiff_t; using ::size_t; -#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) +#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \ + defined(__DEFINED_max_align_t) // Re-use the compiler's <stddef.h> max_align_t where possible. using ::max_align_t; #else @@ -57,4 +59,55 @@ typedef long double max_align_t; _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER > 14 +namespace std // purposefully not versioned +{ +enum class byte : unsigned char {}; + +constexpr byte operator| (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs | __rhs; } + +constexpr byte operator& (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs & __rhs; } + +constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs) + )); +} + +constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs ^ __rhs; } + +constexpr byte operator~ (byte __b) noexcept +{ + return static_cast<byte>( + static_cast<unsigned char>( + ~static_cast<unsigned int>(__b) + )); +} + +} + +#include <type_traits> // rest of byte +#endif + #endif // _LIBCPP_CSTDDEF diff --git a/lib/libcxx/include/cstdlib b/lib/libcxx/include/cstdlib index 10ed231078d..78c428403c3 100644 --- a/lib/libcxx/include/cstdlib +++ b/lib/libcxx/include/cstdlib @@ -89,6 +89,12 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #pragma GCC system_header #endif +#ifdef __GNUC__ +#define _LIBCPP_UNREACHABLE() __builtin_unreachable() +#else +#define _LIBCPP_UNREACHABLE() _VSTD::abort() +#endif + _LIBCPP_BEGIN_NAMESPACE_STD using ::size_t; @@ -124,8 +130,10 @@ using ::abort; using ::atexit; using ::exit; using ::_Exit; +#ifndef _LIBCPP_WINDOWS_STORE_APP using ::getenv; using ::system; +#endif using ::bsearch; using ::qsort; using ::abs; @@ -138,11 +146,9 @@ using ::ldiv; #ifndef _LIBCPP_HAS_NO_LONG_LONG using ::lldiv; #endif // _LIBCPP_HAS_NO_LONG_LONG -#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS using ::mblen; using ::mbtowc; using ::wctomb; -#endif using ::mbstowcs; using ::wcstombs; #ifdef _LIBCPP_HAS_QUICK_EXIT diff --git a/lib/libcxx/include/ctype.h b/lib/libcxx/include/ctype.h index 22d6c49be9e..e97ff3c4887 100644 --- a/lib/libcxx/include/ctype.h +++ b/lib/libcxx/include/ctype.h @@ -40,15 +40,6 @@ int toupper(int c); #ifdef __cplusplus -#if defined(_LIBCPP_MSVCRT) -// We support including .h headers inside 'extern "C"' contexts, so switch -// back to C++ linkage before including these C++ headers. -extern "C++" { - #include "support/win32/support.h" - #include "support/win32/locale_win32.h" -} -#endif // _LIBCPP_MSVCRT - #undef isalnum #undef isalpha #undef isblank diff --git a/lib/libcxx/include/cwchar b/lib/libcxx/include/cwchar index 52dde9e1802..d268e8bbd39 100644 --- a/lib/libcxx/include/cwchar +++ b/lib/libcxx/include/cwchar @@ -123,11 +123,9 @@ using ::fwscanf; using ::swprintf; using ::vfwprintf; using ::vswprintf; -#ifndef _LIBCPP_MSVCRT using ::swscanf; using ::vfwscanf; using ::vswscanf; -#endif // _LIBCPP_MSVCRT using ::fgetwc; using ::fgetws; using ::fputwc; @@ -137,10 +135,8 @@ using ::getwc; using ::putwc; using ::ungetwc; using ::wcstod; -#ifndef _LIBCPP_MSVCRT using ::wcstof; using ::wcstold; -#endif // _LIBCPP_MSVCRT using ::wcstol; #ifndef _LIBCPP_HAS_NO_LONG_LONG using ::wcstoll; @@ -182,9 +178,7 @@ using ::wcsrtombs; #ifndef _LIBCPP_HAS_NO_STDIN using ::getwchar; -#ifndef _LIBCPP_MSVCRT using ::vwscanf; -#endif // _LIBCPP_MSVCRT using ::wscanf; #endif diff --git a/lib/libcxx/include/deque b/lib/libcxx/include/deque index 57650427645..08cb295408b 100644 --- a/lib/libcxx/include/deque +++ b/lib/libcxx/include/deque @@ -110,8 +110,8 @@ public: void push_front(value_type&& v); void push_back(const value_type& v); void push_back(value_type&& v); - template <class... Args> void emplace_front(Args&&... args); - template <class... Args> void emplace_back(Args&&... args); + template <class... Args> reference emplace_front(Args&&... args); // reference in C++17 + template <class... Args> reference emplace_back(Args&&... args); // reference in C++17 template <class... Args> iterator emplace(const_iterator p, Args&&... args); iterator insert(const_iterator p, const value_type& v); iterator insert(const_iterator p, value_type&& v); @@ -150,10 +150,6 @@ template <class T, class Allocator> */ -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - #include <__config> #include <__split_buffer> #include <type_traits> @@ -162,16 +158,22 @@ template <class T, class Allocator> #include <algorithm> #include <stdexcept> -#include <__undef_min_max> +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _Allocator> class __deque_base; -template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY deque; +template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque; template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, class _DiffType, _DiffType _BlockSize> -class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; +class _LIBCPP_TEMPLATE_VIS __deque_iterator; template <class _RAIter, class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> @@ -276,7 +278,7 @@ template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, __deque_block_size<_ValueType, _DiffType>::value #endif > -class _LIBCPP_TYPE_VIS_ONLY __deque_iterator +class _LIBCPP_TEMPLATE_VIS __deque_iterator { typedef _MapPointer __map_iterator; public: @@ -428,9 +430,9 @@ private: : __m_iter_(__m), __ptr_(__p) {} template <class _Tp, class _Ap> friend class __deque_base; - template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque; + template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque; template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> - friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; + friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; template <class _RAIter, class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> @@ -895,26 +897,22 @@ template <bool> class __deque_base_common { protected: - void __throw_length_error() const; - void __throw_out_of_range() const; + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; }; template <bool __b> void __deque_base_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("deque"); -#endif + _VSTD::__throw_length_error("deque"); } template <bool __b> void __deque_base_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("deque"); -#endif + _VSTD::__throw_out_of_range("deque"); } template <class _Tp, class _Allocator> @@ -972,13 +970,12 @@ protected: public: ~__deque_base(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG __deque_base(__deque_base&& __c) _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); __deque_base(__deque_base&& __c, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES void swap(__deque_base& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; @@ -1112,7 +1109,7 @@ __deque_base<_Tp, _Allocator>::~__deque_base() __alloc_traits::deallocate(__alloc(), *__i, __block_size); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) @@ -1144,7 +1141,7 @@ __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_ } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> void @@ -1187,7 +1184,7 @@ __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT } template <class _Tp, class _Allocator /*= allocator<_Tp>*/> -class _LIBCPP_TYPE_VIS_ONLY deque +class _LIBCPP_TEMPLATE_VIS deque : private __deque_base<_Tp, _Allocator> { public: @@ -1234,18 +1231,16 @@ public: typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); deque(const deque& __c); deque(const deque& __c, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + deque& operator=(const deque& __c); + +#ifndef _LIBCPP_CXX03_LANG deque(initializer_list<value_type> __il); deque(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - deque& operator=(const deque& __c); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); _LIBCPP_INLINE_VISIBILITY @@ -1254,7 +1249,10 @@ public: deque& operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG template <class _InputIter> void assign(_InputIter __f, _InputIter __l, @@ -1264,10 +1262,6 @@ public: void assign(_RAIter __f, _RAIter __l, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); void assign(size_type __n, const value_type& __v); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; @@ -1314,11 +1308,13 @@ public: size_type size() const _NOEXCEPT {return __base::size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return __alloc_traits::max_size(__base::__alloc());} + {return std::min<size_type>( + __alloc_traits::max_size(__base::__alloc()), + numeric_limits<difference_type>::max());} void resize(size_type __n); void resize(size_type __n, const value_type& __v); void shrink_to_fit() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __base::size() == 0;} // element access: @@ -1342,16 +1338,24 @@ public: // 23.2.2.3 modifiers: void push_front(const value_type& __v); void push_back(const value_type& __v); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class... _Args> void emplace_front(_Args&&... __args); - template <class... _Args> void emplace_back(_Args&&... __args); +#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 + template <class... _Args> reference emplace_front(_Args&&... __args); + template <class... _Args> reference emplace_back (_Args&&... __args); +#else + template <class... _Args> void emplace_front(_Args&&... __args); + template <class... _Args> void emplace_back (_Args&&... __args); +#endif template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); -#endif // _LIBCPP_HAS_NO_VARIADICS + void push_front(value_type&& __v); void push_back(value_type&& __v); iterator insert(const_iterator __p, value_type&& __v); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list<value_type> __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG iterator insert(const_iterator __p, const value_type& __v); iterator insert(const_iterator __p, size_type __n, const value_type& __v); template <class _InputIter> @@ -1365,11 +1369,7 @@ public: template <class _BiIter> iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - iterator insert(const_iterator __p, initializer_list<value_type> __il) - {return insert(__p, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + void pop_front(); void pop_back(); iterator erase(const_iterator __p); @@ -1524,7 +1524,19 @@ deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) __append(__c.begin(), __c.end()); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +template <class _Tp, class _Allocator> +deque<_Tp, _Allocator>& +deque<_Tp, _Allocator>::operator=(const deque& __c) +{ + if (this != &__c) + { + __copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} + +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) @@ -1539,22 +1551,6 @@ deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator __append(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -template <class _Tp, class _Allocator> -deque<_Tp, _Allocator>& -deque<_Tp, _Allocator>::operator=(const deque& __c) -{ - if (this != &__c) - { - __copy_assign_alloc(__c); - assign(__c.begin(), __c.end()); - } - return *this; -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Allocator> inline deque<_Tp, _Allocator>::deque(deque&& __c) @@ -1610,7 +1606,7 @@ deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) __base::__move_assign(__c); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> template <class _InputIter> @@ -1806,8 +1802,20 @@ deque<_Tp, _Allocator>::push_back(const value_type& __v) ++__base::size(); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp, class _Allocator> +void +deque<_Tp, _Allocator>::push_front(const value_type& __v) +{ + allocator_type& __a = __base::__alloc(); + if (__front_spare() == 0) + __add_front_capacity(); + // __front_spare() >= 1 + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + --__base::__start_; + ++__base::size(); +} +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> void deque<_Tp, _Allocator>::push_back(value_type&& __v) @@ -1820,39 +1828,27 @@ deque<_Tp, _Allocator>::push_back(value_type&& __v) ++__base::size(); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Allocator> template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename deque<_Tp, _Allocator>::reference +#else void +#endif deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) { allocator_type& __a = __base::__alloc(); if (__back_spare() == 0) __add_back_capacity(); // __back_spare() >= 1 - __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); - ++__base::size(); -} - -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp, class _Allocator> -void -deque<_Tp, _Allocator>::push_front(const value_type& __v) -{ - allocator_type& __a = __base::__alloc(); - if (__front_spare() == 0) - __add_front_capacity(); - // __front_spare() >= 1 - __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); - --__base::__start_; + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), + _VSTD::forward<_Args>(__args)...); ++__base::size(); +#if _LIBCPP_STD_VER > 14 + return *--__base::end(); +#endif } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Allocator> void deque<_Tp, _Allocator>::push_front(value_type&& __v) @@ -1866,11 +1862,14 @@ deque<_Tp, _Allocator>::push_front(value_type&& __v) ++__base::size(); } -#ifndef _LIBCPP_HAS_NO_VARIADICS template <class _Tp, class _Allocator> template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename deque<_Tp, _Allocator>::reference +#else void +#endif deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) { allocator_type& __a = __base::__alloc(); @@ -1880,14 +1879,14 @@ deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); --__base::__start_; ++__base::size(); +#if _LIBCPP_STD_VER > 14 + return *__base::begin(); +#endif } -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Allocator> typename deque<_Tp, _Allocator>::iterator -deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) +deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; @@ -1899,23 +1898,20 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) // __front_spare() >= 1 if (__pos == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); --__base::__start_; ++__base::size(); } else { - const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); - if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) - __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); --__base::__start_; ++__base::size(); if (__pos > 1) - __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); - *__b = *__vt; + __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); + *__b = _VSTD::move(__v); } } else @@ -1926,31 +1922,27 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) size_type __de = __base::size() - __pos; if (__de == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); ++__base::size(); } else { - const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); - if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) - __vt = pointer_traits<const_pointer>::pointer_to(*__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) - __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); - *--__e = *__vt; + __e = _VSTD::move_backward(__e - __de, __em1, __e); + *--__e = _VSTD::move(__v); } } return __base::begin() + __pos; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Allocator> +template <class... _Args> typename deque<_Tp, _Allocator>::iterator -deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) +deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; @@ -1962,12 +1954,13 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) // __front_spare() >= 1 if (__pos == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); --__base::__start_; ++__base::size(); } else { + __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); @@ -1975,7 +1968,7 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) ++__base::size(); if (__pos > 1) __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); - *__b = _VSTD::move(__v); + *__b = _VSTD::move(__tmp.get()); } } else @@ -1986,29 +1979,30 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) size_type __de = __base::size() - __pos; if (__de == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); ++__base::size(); } else { + __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) __e = _VSTD::move_backward(__e - __de, __em1, __e); - *--__e = _VSTD::move(__v); + *--__e = _VSTD::move(__tmp.get()); } } return __base::begin() + __pos; } -#ifndef _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG + template <class _Tp, class _Allocator> -template <class... _Args> typename deque<_Tp, _Allocator>::iterator -deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) +deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; @@ -2020,21 +2014,23 @@ deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) // __front_spare() >= 1 if (__pos == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); + __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); --__base::__start_; ++__base::size(); } else { - __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); + if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) + __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); --__base::__start_; ++__base::size(); if (__pos > 1) - __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); - *__b = _VSTD::move(__tmp.get()); + __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); + *__b = *__vt; } } else @@ -2045,27 +2041,26 @@ deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) size_type __de = __base::size() - __pos; if (__de == 0) { - __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); + __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); ++__base::size(); } else { - __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); + const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); + if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) + __vt = pointer_traits<const_pointer>::pointer_to(*__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) - __e = _VSTD::move_backward(__e - __de, __em1, __e); - *--__e = _VSTD::move(__tmp.get()); + __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); + *--__e = *__vt; } } return __base::begin() + __pos; } -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Allocator> typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) @@ -2228,7 +2223,11 @@ deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, !__is_forward_iterator<_InpIter>::value>::type*) { for (; __f != __l; ++__f) +#ifdef _LIBCPP_CXX03_LANG push_back(*__f); +#else + emplace_back(*__f); +#endif } template <class _Tp, class _Allocator> @@ -2734,7 +2733,7 @@ deque<_Tp, _Allocator>::erase(const_iterator __f) difference_type __pos = __f - __b; iterator __p = __b + __pos; allocator_type& __a = __base::__alloc(); - if (__pos <= (__base::size() - 1) / 2) + if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2) { // erase from front _VSTD::move_backward(__b, __p, _VSTD::next(__p)); __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); @@ -2772,7 +2771,7 @@ deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) if (__n > 0) { allocator_type& __a = __base::__alloc(); - if (__pos <= (__base::size() - __n) / 2) + if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2) { // erase from front iterator __i = _VSTD::move_backward(__b, __p, __p + __n); for (; __b != __i; ++__b) @@ -2906,4 +2905,6 @@ swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_DEQUE diff --git a/lib/libcxx/include/exception b/lib/libcxx/include/exception index 186d379f08f..79bd6ac2ae3 100644 --- a/lib/libcxx/include/exception +++ b/lib/libcxx/include/exception @@ -79,10 +79,11 @@ template <class E> void rethrow_if_nested(const E& e); #include <__config> #include <cstddef> -#include <type_traits> -#if defined(_LIBCPP_NO_EXCEPTIONS) -#include <cstdio> #include <cstdlib> +#include <type_traits> + +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#include <vcruntime_exception.h> #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -92,6 +93,7 @@ template <class E> void rethrow_if_nested(const E& e); namespace std // purposefully not using versioning namespace { +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) class _LIBCPP_EXCEPTION_ABI exception { public: @@ -108,11 +110,16 @@ public: virtual ~bad_exception() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME +#if _LIBCPP_STD_VER <= 14 \ + || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ + || defined(_LIBCPP_BUILDING_LIBRARY) typedef void (*unexpected_handler)(); _LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; _LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected(); +#endif typedef void (*terminate_handler)(); _LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT; @@ -120,30 +127,33 @@ _LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT; _LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT; -_LIBCPP_FUNC_VIS int uncaught_exceptions() _NOEXCEPT; +_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT; class _LIBCPP_TYPE_VIS exception_ptr; _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); +#ifndef _LIBCPP_ABI_MICROSOFT + class _LIBCPP_TYPE_VIS exception_ptr { void* __ptr_; public: _LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {} _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} + exception_ptr(const exception_ptr&) _NOEXCEPT; exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; ~exception_ptr() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_EXPLICIT - operator bool() const _NOEXCEPT {return __ptr_ != nullptr;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT + {return __ptr_ != nullptr;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {return !(__x == __y);} @@ -165,9 +175,60 @@ make_exception_ptr(_Ep __e) _NOEXCEPT { return current_exception(); } -#endif // _LIBCPP_NO_EXCEPTIONS +#else + ((void)__e); + _VSTD::abort(); +#endif } +#else // _LIBCPP_ABI_MICROSOFT + +class _LIBCPP_TYPE_VIS exception_ptr +{ +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-private-field" +#endif + void* __ptr1_; + void* __ptr2_; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif +public: + exception_ptr() _NOEXCEPT; + exception_ptr(nullptr_t) _NOEXCEPT; + exception_ptr(const exception_ptr& __other) _NOEXCEPT; + exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; + exception_ptr& operator=(nullptr_t) _NOEXCEPT; + ~exception_ptr() _NOEXCEPT; + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT; +}; + +_LIBCPP_FUNC_VIS +bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; + +inline _LIBCPP_INLINE_VISIBILITY +bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT + {return !(__x == __y);} + +_LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; + +_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr); +_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p); + +// This is a built-in template function which automagically extracts the required +// information. +template <class _E> void *__GetExceptionInfo(_E); + +template<class _Ep> +exception_ptr +make_exception_ptr(_Ep __e) _NOEXCEPT +{ + return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e)); +} + +#endif // _LIBCPP_ABI_MICROSOFT // nested_exception class _LIBCPP_EXCEPTION_ABI nested_exception @@ -192,52 +253,71 @@ struct __nested _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} }; -template <class _Tp> -_LIBCPP_NORETURN -void -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested(_Tp&& __t, typename enable_if< - is_class<typename remove_reference<_Tp>::type>::value && - !is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value - && !__libcpp_is_final<typename remove_reference<_Tp>::type>::value - >::type* = 0) -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested (_Tp& __t, typename enable_if< - is_class<_Tp>::value && !is_base_of<nested_exception, _Tp>::value - >::type* = 0) -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -{ #ifndef _LIBCPP_NO_EXCEPTIONS - throw __nested<typename remove_reference<_Tp>::type>(_VSTD::forward<_Tp>(__t)); +template <class _Tp, class _Up, bool> +struct __throw_with_nested; + +template <class _Tp, class _Up> +struct __throw_with_nested<_Tp, _Up, true> { + _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void +#ifndef _LIBCPP_CXX03_LANG + __do_throw(_Tp&& __t) +#else + __do_throw (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG + { + throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); + } +}; + +template <class _Tp, class _Up> +struct __throw_with_nested<_Tp, _Up, false> { + _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void +#ifndef _LIBCPP_CXX03_LANG + __do_throw(_Tp&& __t) +#else + __do_throw (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG + { + throw _VSTD::forward<_Tp>(__t); + } +}; #endif -} template <class _Tp> _LIBCPP_NORETURN void -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested(_Tp&& __t, typename enable_if< - !is_class<typename remove_reference<_Tp>::type>::value || - is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value - || __libcpp_is_final<typename remove_reference<_Tp>::type>::value - >::type* = 0) -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES -throw_with_nested (_Tp& __t, typename enable_if< - !is_class<_Tp>::value || is_base_of<nested_exception, _Tp>::value - >::type* = 0) -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG +throw_with_nested(_Tp&& __t) +#else +throw_with_nested (_Tp& __t) +#endif // _LIBCPP_CXX03_LANG { #ifndef _LIBCPP_NO_EXCEPTIONS - throw _VSTD::forward<_Tp>(__t); + typedef typename decay<_Tp>::type _Up; + static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); + __throw_with_nested<_Tp, _Up, + is_class<_Up>::value && + !is_base_of<nested_exception, _Up>::value && + !__libcpp_is_final<_Up>::value>:: + __do_throw(_VSTD::forward<_Tp>(__t)); +#else + ((void)__t); + // FIXME: Make this abort #endif } +template <class _From, class _To> +struct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT( + is_polymorphic<_From>::value && + (!is_base_of<_To, _From>::value || + is_convertible<const _From*, const _To*>::value)) {}; + template <class _Ep> inline _LIBCPP_INLINE_VISIBILITY void -rethrow_if_nested(const _Ep& __e, typename enable_if< - is_polymorphic<_Ep>::value - >::type* = 0) +rethrow_if_nested(const _Ep& __e, + typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) { const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e)); if (__nep) @@ -247,27 +327,11 @@ rethrow_if_nested(const _Ep& __e, typename enable_if< template <class _Ep> inline _LIBCPP_INLINE_VISIBILITY void -rethrow_if_nested(const _Ep&, typename enable_if< - !is_polymorphic<_Ep>::value - >::type* = 0) +rethrow_if_nested(const _Ep&, + typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) { } } // std -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _Exception> -_LIBCPP_INLINE_VISIBILITY -inline void __libcpp_throw(_Exception const& __e) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw __e; -#else - _VSTD::fprintf(stderr, "%s\n", __e.what()); - _VSTD::abort(); -#endif -} - -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP_EXCEPTION diff --git a/lib/libcxx/include/experimental/__config b/lib/libcxx/include/experimental/__config index 9a7bbe85d8d..37f88c166dd 100644 --- a/lib/libcxx/include/experimental/__config +++ b/lib/libcxx/include/experimental/__config @@ -44,6 +44,13 @@ #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \ } } _LIBCPP_END_NAMESPACE_EXPERIMENTAL +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace coroutines_v1 { + +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES \ + } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _VSTD_CORO _VSTD_EXPERIMENTAL::coroutines_v1 #define _VSTD_FS ::std::experimental::filesystem::v1 diff --git a/lib/libcxx/include/experimental/algorithm b/lib/libcxx/include/experimental/algorithm index 3902111c54e..a6a28f07181 100644 --- a/lib/libcxx/include/experimental/algorithm +++ b/lib/libcxx/include/experimental/algorithm @@ -39,17 +39,18 @@ SampleIterator sample(PopulationIterator first, PopulationIterator last, #include <algorithm> #include <type_traits> -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_LFTS +_LIBCPP_PUSH_MACROS +#include <__undef_macros> +_LIBCPP_BEGIN_NAMESPACE_LFTS + template <class _ForwardIterator, class _Searcher> _LIBCPP_INLINE_VISIBILITY _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) @@ -58,63 +59,15 @@ _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searc template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator> -_LIBCPP_INLINE_VISIBILITY -_SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __out, - _Distance __n, - _UniformRandomNumberGenerator &&__g, - input_iterator_tag) { - - _Distance __k = 0; - for (; __first != __last && __k < __n; ++__first, (void)++__k) - __out[__k] = *__first; - _Distance __sz = __k; - for (; __first != __last; ++__first, (void)++__k) { - _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); - if (__r < __sz) - __out[__r] = *__first; - } - return __out + _VSTD::min(__n, __k); -} - -template <class _PopulationIterator, class _SampleIterator, class _Distance, - class _UniformRandomNumberGenerator> -_LIBCPP_INLINE_VISIBILITY -_SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __out, - _Distance __n, - _UniformRandomNumberGenerator &&__g, - forward_iterator_tag) { - _Distance __unsampled_sz = _VSTD::distance(__first, __last); - for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) { - _Distance __r = - _VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); - if (__r < __n) { - *__out++ = *__first; - --__n; - } - } - return __out; -} - -template <class _PopulationIterator, class _SampleIterator, class _Distance, - class _UniformRandomNumberGenerator> -_LIBCPP_INLINE_VISIBILITY -_SampleIterator sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __out, - _Distance __n, _UniformRandomNumberGenerator &&__g) { - typedef typename iterator_traits<_PopulationIterator>::iterator_category - _PopCategory; - typedef typename iterator_traits<_PopulationIterator>::difference_type - _Difference; - typedef typename common_type<_Distance, _Difference>::type _CommonType; - _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); - return _VSTD_LFTS::__sample( - __first, __last, __out, _CommonType(__n), - _VSTD::forward<_UniformRandomNumberGenerator>(__g), - _PopCategory()); +inline _LIBCPP_INLINE_VISIBILITY +_SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last, + _SampleIterator __output_iter, _Distance __n, + _UniformRandomNumberGenerator &&__g) { + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); } _LIBCPP_END_NAMESPACE_LFTS +_LIBCPP_POP_MACROS + #endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */ diff --git a/lib/libcxx/include/experimental/any b/lib/libcxx/include/experimental/any index 4c732496c52..083a2909033 100644 --- a/lib/libcxx/include/experimental/any +++ b/lib/libcxx/include/experimental/any @@ -82,7 +82,6 @@ inline namespace fundamentals_v1 { #include <typeinfo> #include <type_traits> #include <cstdlib> -#include <cassert> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -90,7 +89,7 @@ inline namespace fundamentals_v1 { _LIBCPP_BEGIN_NAMESPACE_LFTS -class _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast { public: virtual const char* what() const _NOEXCEPT; @@ -98,13 +97,14 @@ public: #if _LIBCPP_STD_VER > 11 // C++ > 11 -_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY -inline void __throw_bad_any_cast() +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST +void __throw_bad_any_cast() { #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_any_cast(); #else - assert(!"bad_any_cast"); + _VSTD::abort(); #endif } @@ -293,7 +293,7 @@ namespace __any_imp { template <class _Tp> - struct _LIBCPP_TYPE_VIS_ONLY _SmallHandler + struct _LIBCPP_TEMPLATE_VIS _SmallHandler { _LIBCPP_INLINE_VISIBILITY static void* __handle(_Action __act, any const * __this, any * __other, @@ -374,7 +374,7 @@ namespace __any_imp }; template <class _Tp> - struct _LIBCPP_TYPE_VIS_ONLY _LargeHandler + struct _LIBCPP_TEMPLATE_VIS _LargeHandler { _LIBCPP_INLINE_VISIBILITY static void* __handle(_Action __act, any const * __this, any * __other, @@ -507,7 +507,7 @@ void swap(any & __lhs, any & __rhs) _NOEXCEPT } template <class _ValueType> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const & __v) { static_assert( @@ -523,7 +523,7 @@ _ValueType any_cast(any const & __v) } template <class _ValueType> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any & __v) { static_assert( @@ -538,7 +538,7 @@ _ValueType any_cast(any & __v) } template <class _ValueType> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any && __v) { static_assert( diff --git a/lib/libcxx/include/experimental/coroutine b/lib/libcxx/include/experimental/coroutine new file mode 100644 index 00000000000..ce795ad452c --- /dev/null +++ b/lib/libcxx/include/experimental/coroutine @@ -0,0 +1,296 @@ +// -*- C++ -*- +//===----------------------------- coroutine -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_COROUTINE +#define _LIBCPP_EXPERIMENTAL_COROUTINE + +/** + experimental/coroutine synopsis + +// C++next + +namespace std { +namespace experimental { +inline namespace coroutines_v1 { + + // 18.11.1 coroutine traits +template <typename R, typename... ArgTypes> +class coroutine_traits; +// 18.11.2 coroutine handle +template <typename Promise = void> +class coroutine_handle; +// 18.11.2.7 comparison operators: +bool operator==(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator!=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +// 18.11.3 trivial awaitables +struct suspend_never; +struct suspend_always; +// 18.11.2.8 hash support: +template <class T> struct hash; +template <class P> struct hash<coroutine_handle<P>>; + +} // namespace coroutines_v1 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <new> +#include <type_traits> +#include <functional> +#include <memory> // for hash<T*> +#include <cstddef> +#include <cassert> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_COROUTINES +# if defined(_LIBCPP_WARNING) + _LIBCPP_WARNING("<experimental/coroutine> cannot be used with this compiler") +# else +# warning <experimental/coroutine> cannot be used with this compiler +# endif +#endif + +#ifndef _LIBCPP_HAS_NO_COROUTINES + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES + +template <class _Tp, class = void> +struct __coroutine_traits_sfinae {}; + +template <class _Tp> +struct __coroutine_traits_sfinae< + _Tp, typename __void_t<typename _Tp::promise_type>::type> +{ + using promise_type = typename _Tp::promise_type; +}; + +template <typename _Ret, typename... _Args> +struct _LIBCPP_TEMPLATE_VIS coroutine_traits + : public __coroutine_traits_sfinae<_Ret> +{ +}; + +template <typename _Promise = void> +class _LIBCPP_TEMPLATE_VIS coroutine_handle; + +template <> +class _LIBCPP_TEMPLATE_VIS coroutine_handle<void> { +public: + _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR coroutine_handle() _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR coroutine_handle(nullptr_t) _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_ALWAYS_INLINE + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + __handle_ = nullptr; + return *this; + } + + _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR void* address() const _NOEXCEPT { return __handle_; } + + _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return __handle_; } + + _LIBCPP_ALWAYS_INLINE + void operator()() { resume(); } + + _LIBCPP_ALWAYS_INLINE + void resume() { + _LIBCPP_ASSERT(__is_suspended(), + "resume() can only be called on suspended coroutines"); + _LIBCPP_ASSERT(!done(), + "resume() has undefined behavior when the coroutine is done"); + __builtin_coro_resume(__handle_); + } + + _LIBCPP_ALWAYS_INLINE + void destroy() { + _LIBCPP_ASSERT(__is_suspended(), + "destroy() can only be called on suspended coroutines"); + __builtin_coro_destroy(__handle_); + } + + _LIBCPP_ALWAYS_INLINE + bool done() const { + _LIBCPP_ASSERT(__is_suspended(), + "done() can only be called on suspended coroutines"); + return __builtin_coro_done(__handle_); + } + +public: + _LIBCPP_ALWAYS_INLINE + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // FIXME: Should from_address(nullptr) be allowed? + _LIBCPP_ALWAYS_INLINE + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { + return coroutine_handle(nullptr); + } + + template <class _Tp, bool _CallIsValid = false> + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, + "coroutine_handle<void>::from_address cannot be called with " + "non-void pointers"); + } + +private: + bool __is_suspended() const _NOEXCEPT { + // FIXME actually implement a check for if the coro is suspended. + return __handle_; + } + + template <class _PromiseT> friend class coroutine_handle; + void* __handle_; +}; + +// 18.11.2.7 comparison operators: +inline _LIBCPP_ALWAYS_INLINE +bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __x.address() == __y.address(); +} +inline _LIBCPP_ALWAYS_INLINE +bool operator!=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x == __y); +} +inline _LIBCPP_ALWAYS_INLINE +bool operator<(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return less<void*>()(__x.address(), __y.address()); +} +inline _LIBCPP_ALWAYS_INLINE +bool operator>(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __y < __x; +} +inline _LIBCPP_ALWAYS_INLINE +bool operator<=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x > __y); +} +inline _LIBCPP_ALWAYS_INLINE +bool operator>=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x < __y); +} + +template <typename _Promise> +class _LIBCPP_TEMPLATE_VIS coroutine_handle : public coroutine_handle<> { + using _Base = coroutine_handle<>; +public: +#ifndef _LIBCPP_CXX03_LANG + // 18.11.2.1 construct/reset + using coroutine_handle<>::coroutine_handle; +#else + _LIBCPP_ALWAYS_INLINE coroutine_handle() _NOEXCEPT : _Base() {} + _LIBCPP_ALWAYS_INLINE coroutine_handle(nullptr_t) _NOEXCEPT : _Base(nullptr) {} +#endif + _LIBCPP_INLINE_VISIBILITY + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + _Base::operator=(nullptr); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _Promise& promise() const { + return *reinterpret_cast<_Promise*>( + __builtin_coro_promise(this->__handle_, __alignof(_Promise), false)); + } + +public: + _LIBCPP_ALWAYS_INLINE + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // NOTE: this overload isn't required by the standard but is needed so + // the deleted _Promise* overload doesn't make from_address(nullptr) + // ambiguous. + // FIXME: should from_address work with nullptr? + _LIBCPP_ALWAYS_INLINE + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { + return coroutine_handle(nullptr); + } + + template <class _Tp, bool _CallIsValid = false> + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, + "coroutine_handle<promise_type>::from_address cannot be called with " + "non-void pointers"); + } + + template <bool _CallIsValid = false> + static coroutine_handle from_address(_Promise*) { + static_assert(_CallIsValid, + "coroutine_handle<promise_type>::from_address cannot be used with " + "pointers to the coroutine's promise type; use 'from_promise' instead"); + } + + _LIBCPP_ALWAYS_INLINE + static coroutine_handle from_promise(_Promise& __promise) _NOEXCEPT { + typedef typename remove_cv<_Promise>::type _RawPromise; + coroutine_handle __tmp; + __tmp.__handle_ = __builtin_coro_promise( + _VSTD::addressof(const_cast<_RawPromise&>(__promise)), + __alignof(_Promise), true); + return __tmp; + } +}; + +struct _LIBCPP_TYPE_VIS suspend_never { + _LIBCPP_ALWAYS_INLINE + bool await_ready() const _NOEXCEPT { return true; } + _LIBCPP_ALWAYS_INLINE + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_ALWAYS_INLINE + void await_resume() const _NOEXCEPT {} +}; + +struct _LIBCPP_TYPE_VIS suspend_always { + _LIBCPP_ALWAYS_INLINE + bool await_ready() const _NOEXCEPT { return false; } + _LIBCPP_ALWAYS_INLINE + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_ALWAYS_INLINE + void await_resume() const _NOEXCEPT {} +}; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp> +struct hash<_VSTD_CORO::coroutine_handle<_Tp> > { + using __arg_type = _VSTD_CORO::coroutine_handle<_Tp>; + _LIBCPP_INLINE_VISIBILITY + size_t operator()(__arg_type const& __v) const _NOEXCEPT + {return hash<void*>()(__v.address());} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // !defined(_LIBCPP_HAS_NO_COROUTINES) + +#endif /* _LIBCPP_EXPERIMENTAL_COROUTINE */ diff --git a/lib/libcxx/include/experimental/dynarray b/lib/libcxx/include/experimental/dynarray index 4a06908e11b..16193317ad2 100644 --- a/lib/libcxx/include/experimental/dynarray +++ b/lib/libcxx/include/experimental/dynarray @@ -11,9 +11,6 @@ #ifndef _LIBCPP_DYNARRAY #define _LIBCPP_DYNARRAY -#include <__config> -#if _LIBCPP_STD_VER > 11 - /* dynarray synopsis @@ -96,6 +93,8 @@ public: }} // std::experimental */ +#include <__config> +#if _LIBCPP_STD_VER > 11 #include <__functional_base> #include <iterator> @@ -104,20 +103,17 @@ public: #include <new> #include <algorithm> -#include <__undef___deallocate> - -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include <cassert> -#endif - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + namespace std { namespace experimental { inline namespace __array_extensions_v1 { template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY dynarray +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_DYNARRAY dynarray { public: // types: @@ -142,19 +138,14 @@ private: static inline _LIBCPP_INLINE_VISIBILITY value_type* __allocate ( size_t count ) { if ( numeric_limits<size_t>::max() / sizeof (value_type) <= count ) - { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_array_length(); -#else - assert(!"dynarray::allocation"); -#endif - } + __throw_bad_array_length(); + return static_cast<value_type *> (_VSTD::__allocate (sizeof(value_type) * count)); } - static inline _LIBCPP_INLINE_VISIBILITY void __deallocate ( value_type* __ptr ) noexcept + static inline _LIBCPP_INLINE_VISIBILITY void __deallocate_value( value_type* __ptr ) noexcept { - _VSTD::__deallocate (static_cast<void *> (__ptr)); + _VSTD::__libcpp_deallocate (static_cast<void *> (__ptr)); } public: @@ -274,7 +265,7 @@ dynarray<_Tp>::~dynarray() value_type *__data = data () + __size_; for ( size_t i = 0; i < __size_; ++i ) (--__data)->value_type::~value_type(); - __deallocate ( __base_ ); + __deallocate_value( __base_ ); } template <class _Tp> @@ -283,13 +274,8 @@ typename dynarray<_Tp>::reference dynarray<_Tp>::at(size_type __n) { if (__n >= __size_) - { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("dynarray::at"); -#else - assert(!"dynarray::at out_of_range"); -#endif - } + __throw_out_of_range("dynarray::at"); + return data()[__n]; } @@ -299,13 +285,8 @@ typename dynarray<_Tp>::const_reference dynarray<_Tp>::at(size_type __n) const { if (__n >= __size_) - { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("dynarray::at"); -#else - assert(!"dynarray::at out_of_range"); -#endif - } + __throw_out_of_range("dynarray::at"); + return data()[__n]; } @@ -314,8 +295,10 @@ dynarray<_Tp>::at(size_type __n) const _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<std::experimental::dynarray<_Tp>, _Alloc> : true_type {}; +struct _LIBCPP_TEMPLATE_VIS uses_allocator<std::experimental::dynarray<_Tp>, _Alloc> : true_type {}; _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // if _LIBCPP_STD_VER > 11 #endif // _LIBCPP_DYNARRAY diff --git a/lib/libcxx/include/experimental/filesystem b/lib/libcxx/include/experimental/filesystem index 7de93fdf8f1..674490f6038 100644 --- a/lib/libcxx/include/experimental/filesystem +++ b/lib/libcxx/include/experimental/filesystem @@ -81,10 +81,10 @@ path canonical(const path& p, const path& base, error_code& ec); void copy(const path& from, const path& to); - void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT; + void copy(const path& from, const path& to, error_code& ec); void copy(const path& from, const path& to, copy_options options); void copy(const path& from, const path& to, copy_options options, - error_code& ec) _NOEXCEPT; + error_code& ec); bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT; @@ -228,7 +228,7 @@ #include <system_error> #include <utility> #include <iomanip> // for quoted -#include <experimental/string_view> +#include <string_view> #include <__debug> @@ -249,7 +249,7 @@ struct _LIBCPP_TYPE_VIS space_info uintmax_t available; }; -enum class _LIBCPP_TYPE_VIS file_type : signed char +enum class _LIBCPP_ENUM_VIS file_type : signed char { none = 0, not_found = -1, @@ -263,7 +263,7 @@ enum class _LIBCPP_TYPE_VIS file_type : signed char unknown = 8 }; -enum class _LIBCPP_TYPE_VIS perms : unsigned +enum class _LIBCPP_ENUM_VIS perms : unsigned { none = 0, @@ -323,7 +323,7 @@ _LIBCPP_INLINE_VISIBILITY inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; } -enum class _LIBCPP_TYPE_VIS copy_options : unsigned short +enum class _LIBCPP_ENUM_VIS copy_options : unsigned short { none = 0, skip_existing = 1, @@ -367,7 +367,7 @@ inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) { return _LHS = _LHS ^ _RHS; } -enum class directory_options : unsigned char +enum class _LIBCPP_ENUM_VIS directory_options : unsigned char { none = 0, follow_directory_symlink = 1, @@ -408,8 +408,10 @@ class _LIBCPP_TYPE_VIS file_status public: // constructors _LIBCPP_INLINE_VISIBILITY - explicit file_status(file_type __ft = file_type::none, - perms __prms = perms::unknown) _NOEXCEPT + file_status() _NOEXCEPT : file_status(file_type::none) {} + _LIBCPP_INLINE_VISIBILITY + explicit file_status(file_type __ft, + perms __prms = perms::unknown) _NOEXCEPT : __ft_(__ft), __prms_(__prms) {} @@ -453,6 +455,9 @@ class _LIBCPP_TYPE_VIS directory_entry; template <class _Tp> struct __can_convert_char { static const bool value = false; }; +template <class _Tp> struct __can_convert_char<const _Tp> + : public __can_convert_char<_Tp> { +}; template <> struct __can_convert_char<char> { static const bool value = true; using __char_type = char; @@ -498,6 +503,21 @@ struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>, } }; + +template <class _ECharT, class _Traits> +struct __is_pathable_string<basic_string_view<_ECharT, _Traits>, + _Void<typename __can_convert_char<_ECharT>::__char_type>> +: public __can_convert_char<_ECharT> +{ + using _Str = basic_string_view<_ECharT, _Traits>; + using _Base = __can_convert_char<_ECharT>; + static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } + static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); } + static _ECharT __first_or_null(_Str const& __s) { + return __s.empty() ? _ECharT{} : __s[0]; + } +}; + template <class _Source, class _DS = typename decay<_Source>::type, class _UnqualPtrType = typename remove_const< @@ -605,13 +625,23 @@ struct _PathCVT { template <> struct _PathCVT<char> { + template <class _Iter> - static void __append_range(string& __dest, _Iter __b, _Iter __e) { + static typename enable_if< + __is_exactly_input_iterator<_Iter>::value + >::type __append_range(string& __dest, _Iter __b, _Iter __e) { for (; __b != __e; ++__b) __dest.push_back(*__b); } template <class _Iter> + static typename enable_if< + __is_forward_iterator<_Iter>::value + >::type __append_range(string& __dest, _Iter __b, _Iter __e) { + __dest.__append_forward_unsafe(__b, __e); + } + + template <class _Iter> static void __append_range(string& __dest, _Iter __b, _NullSentinal) { const char __sentinal = char{}; for (; *__b != __sentinal; ++__b) @@ -622,7 +652,8 @@ struct _PathCVT<char> { static void __append_source(string& __dest, _Source const& __s) { using _Traits = __is_pathable<_Source>; - __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s)); + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); } }; @@ -642,6 +673,7 @@ class _LIBCPP_TYPE_VIS path public: typedef char value_type; typedef basic_string<value_type> string_type; + typedef _VSTD::string_view __string_view; static _LIBCPP_CONSTEXPR value_type preferred_separator = '/'; // constructors and destructor @@ -690,6 +722,7 @@ public: return *this; } + template <class = void> _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) _NOEXCEPT { __pn_ = _VSTD::move(__s); @@ -740,6 +773,8 @@ private: public: // appends path& operator/=(const path& __p) { + _LIBCPP_ASSERT(!__p.has_root_name(), + "cannot append to a path with a root name"); __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]); __pn_ += __p.native(); return *this; @@ -788,6 +823,12 @@ public: } _LIBCPP_INLINE_VISIBILITY + path& operator+=(__string_view __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY path& operator+=(const value_type* __x) { __pn_ += __x; return *this; @@ -799,7 +840,6 @@ public: return *this; } - template <class _ECharT> typename enable_if<__can_convert_char<_ECharT>::value, path&>::type operator+=(_ECharT __x) @@ -837,7 +877,15 @@ public: } path& make_preferred() { return *this; } - path& remove_filename() { return *this = parent_path(); } + + _LIBCPP_INLINE_VISIBILITY + path& remove_filename() { + if (__pn_.size() == __root_path_raw().size()) + clear(); + else + __pn_ = __parent_path(); + return *this; + } path& replace_filename(const path& __replacement) { remove_filename(); @@ -896,37 +944,40 @@ public: std::u32string generic_u32string() const { return string<char32_t>(); } private: - _LIBCPP_FUNC_VIS int __compare(const value_type*) const; - _LIBCPP_FUNC_VIS string_view __root_name() const; - _LIBCPP_FUNC_VIS string_view __root_directory() const; - _LIBCPP_FUNC_VIS string_view __relative_path() const; - _LIBCPP_FUNC_VIS string_view __parent_path() const; - _LIBCPP_FUNC_VIS string_view __filename() const; - _LIBCPP_FUNC_VIS string_view __stem() const; - _LIBCPP_FUNC_VIS string_view __extension() const; + int __compare(__string_view) const; + __string_view __root_name() const; + __string_view __root_directory() const; + __string_view __root_path_raw() const; + __string_view __relative_path() const; + __string_view __parent_path() const; + __string_view __filename() const; + __string_view __stem() const; + __string_view __extension() const; public: // compare - _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.c_str());} - _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s.c_str()); } + _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);} + _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); } + _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); } _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); } // decomposition - _LIBCPP_INLINE_VISIBILITY path root_name() const { return __root_name().to_string(); } - _LIBCPP_INLINE_VISIBILITY path root_directory() const { return __root_directory().to_string(); } - _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(__root_directory().to_string()); } - _LIBCPP_INLINE_VISIBILITY path relative_path() const { return __relative_path().to_string(); } - _LIBCPP_INLINE_VISIBILITY path parent_path() const { return __parent_path().to_string(); } - _LIBCPP_INLINE_VISIBILITY path filename() const { return __filename().to_string(); } - _LIBCPP_INLINE_VISIBILITY path stem() const { return __stem().to_string();} - _LIBCPP_INLINE_VISIBILITY path extension() const { return __extension().to_string(); } + _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); } + _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); } + _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); } + _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); } + _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); } + _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); } + _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());} + _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); } // query - _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); } + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT { return __pn_.empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); } - _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !(__root_name().empty() && __root_directory().empty()); } + _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); } @@ -940,12 +991,12 @@ public: class _LIBCPP_TYPE_VIS iterator; typedef iterator const_iterator; - _LIBCPP_FUNC_VIS iterator begin() const; - _LIBCPP_FUNC_VIS iterator end() const; + iterator begin() const; + iterator end() const; private: inline _LIBCPP_INLINE_VISIBILITY - path& __assign_view(string_view const& __s) noexcept { __pn_ = __s.to_string(); return *this; } + path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; } string_type __pn_; }; @@ -1041,13 +1092,17 @@ class _LIBCPP_TYPE_VIS path::iterator { public: typedef bidirectional_iterator_tag iterator_category; + typedef path value_type; typedef std::ptrdiff_t difference_type; typedef const path* pointer; typedef const path& reference; + + typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator public: _LIBCPP_INLINE_VISIBILITY - iterator() : __elem_(), __path_ptr_(nullptr), __pos_(0) {} + iterator() : __stashed_elem_(), __path_ptr_(nullptr), + __entry_(), __state_(__singular) {} iterator(const iterator&) = default; ~iterator() = default; @@ -1056,16 +1111,20 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const { - return __elem_; + return __stashed_elem_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { - return &__elem_; + return &__stashed_elem_; } _LIBCPP_INLINE_VISIBILITY iterator& operator++() { + _LIBCPP_ASSERT(__state_ != __singular, + "attempting to increment a singular iterator"); + _LIBCPP_ASSERT(__state_ != __at_end, + "attempting to increment the end iterator"); return __increment(); } @@ -1078,6 +1137,10 @@ public: _LIBCPP_INLINE_VISIBILITY iterator& operator--() { + _LIBCPP_ASSERT(__state_ != __singular, + "attempting to decrement a singular iterator"); + _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), + "attempting to decrement the begin iterator"); return __decrement(); } @@ -1090,20 +1153,26 @@ public: private: friend class path; + + static constexpr unsigned char __singular = 0; + static constexpr unsigned char __at_end = 6; + + inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&, const iterator&); - _LIBCPP_FUNC_VIS iterator& __increment(); - _LIBCPP_FUNC_VIS iterator& __decrement(); + iterator& __increment(); + iterator& __decrement(); - path __elem_; + path __stashed_elem_; const path* __path_ptr_; - size_t __pos_; + path::__string_view __entry_; + unsigned char __state_; }; inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) { return __lhs.__path_ptr_ == __rhs.__path_ptr_ && - __lhs.__pos_ == __rhs.__pos_; + __lhs.__entry_.data() == __rhs.__entry_.data(); } inline _LIBCPP_INLINE_VISIBILITY @@ -1143,7 +1212,6 @@ public: return __paths_->second; } - _LIBCPP_FUNC_VIS ~filesystem_error() override; // key function // TODO(ericwf): Create a custom error message. @@ -1154,6 +1222,21 @@ private: shared_ptr<_Storage> __paths_; }; +template <class... _Args> +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +#ifndef _LIBCPP_NO_EXCEPTIONS +void __throw_filesystem_error(_Args && ...__args) +{ + throw filesystem_error(std::forward<_Args>(__args)...); +} +#else +void __throw_filesystem_error(_Args&&...) +{ + _VSTD::abort(); +} +#endif + + // operational functions _LIBCPP_FUNC_VIS @@ -1269,7 +1352,7 @@ void copy(const path& __from, const path& __to) { } inline _LIBCPP_INLINE_VISIBILITY -void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { +void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); } @@ -1280,7 +1363,7 @@ void copy(const path& __from, const path& __to, copy_options __opt) { inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, - copy_options __opt, error_code& __ec) _NOEXCEPT { + copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); } @@ -1479,7 +1562,7 @@ bool is_empty(const path& __p) { } inline _LIBCPP_INLINE_VISIBILITY -bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT { +bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); } @@ -1821,12 +1904,12 @@ public: : directory_iterator(__p, nullptr, __opts) { } - directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + directory_iterator(const path& __p, error_code& __ec) : directory_iterator(__p, &__ec) { } directory_iterator(const path& __p, directory_options __opts, - error_code& __ec) _NOEXCEPT + error_code& __ec) : directory_iterator(__p, &__ec, __opts) { } @@ -1846,7 +1929,7 @@ public: const directory_entry& operator*() const { _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced"); - return __deref(); + return __dereference(); } const directory_entry* operator->() const @@ -1861,20 +1944,24 @@ public: return __p; } - directory_iterator& increment(error_code& __ec) _NOEXCEPT + directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } private: + inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const directory_iterator& __lhs, const directory_iterator& __rhs) _NOEXCEPT; // construct the dir_stream _LIBCPP_FUNC_VIS - directory_iterator(const path&, error_code *, directory_options = directory_options::none); + directory_iterator(const path&, error_code *, + directory_options = directory_options::none); + _LIBCPP_FUNC_VIS directory_iterator& __increment(error_code * __ec = nullptr); + _LIBCPP_FUNC_VIS - const directory_entry& __deref() const; + const directory_entry& __dereference() const; private: shared_ptr<__dir_stream> __imp_; @@ -1927,12 +2014,12 @@ public: _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator(const path& __p, - directory_options __xoptions, error_code& __ec) _NOEXCEPT + directory_options __xoptions, error_code& __ec) : recursive_directory_iterator(__p, __xoptions, &__ec) { } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + recursive_directory_iterator(const path& __p, error_code& __ec) : recursive_directory_iterator(__p, directory_options::none, &__ec) { } @@ -1957,11 +2044,11 @@ public: _LIBCPP_INLINE_VISIBILITY const directory_entry& operator*() const - { return __deref(); } + { return __dereference(); } _LIBCPP_INLINE_VISIBILITY const directory_entry* operator->() const - { return &__deref(); } + { return &__dereference(); } recursive_directory_iterator& operator++() { return __increment(); } @@ -1974,7 +2061,7 @@ public: } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT + recursive_directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } _LIBCPP_FUNC_VIS directory_options options() const; @@ -2000,7 +2087,7 @@ private: error_code *__ec); _LIBCPP_FUNC_VIS - const directory_entry& __deref() const; + const directory_entry& __dereference() const; _LIBCPP_FUNC_VIS bool __try_recursion(error_code* __ec); @@ -2014,6 +2101,7 @@ private: _LIBCPP_FUNC_VIS void __pop(error_code* __ec=nullptr); + inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const recursive_directory_iterator&, const recursive_directory_iterator&) _NOEXCEPT; @@ -2023,9 +2111,9 @@ private: }; // class recursive_directory_iterator -_LIBCPP_INLINE_VISIBILITY -inline bool operator==(const recursive_directory_iterator& __lhs, - const recursive_directory_iterator& __rhs) _NOEXCEPT +inline _LIBCPP_INLINE_VISIBILITY +bool operator==(const recursive_directory_iterator& __lhs, + const recursive_directory_iterator& __rhs) _NOEXCEPT { return __lhs.__imp_ == __rhs.__imp_; } diff --git a/lib/libcxx/include/experimental/functional b/lib/libcxx/include/experimental/functional index 75fc8e99f35..a136cbb57c8 100644 --- a/lib/libcxx/include/experimental/functional +++ b/lib/libcxx/include/experimental/functional @@ -89,21 +89,22 @@ inline namespace fundamentals_v1 { #include <experimental/__config> #include <functional> - #include <algorithm> #include <type_traits> #include <vector> #include <array> #include <unordered_map> -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_LFTS #if _LIBCPP_STD_VER > 11 @@ -456,4 +457,6 @@ make_boyer_moore_horspool_searcher( _RandomAccessIterator __f, _RandomAccessIter _LIBCPP_END_NAMESPACE_LFTS +_LIBCPP_POP_MACROS + #endif /* _LIBCPP_EXPERIMENTAL_FUNCTIONAL */ diff --git a/lib/libcxx/include/experimental/iterator b/lib/libcxx/include/experimental/iterator index da593febe2b..ea672e96631 100644 --- a/lib/libcxx/include/experimental/iterator +++ b/lib/libcxx/include/experimental/iterator @@ -75,19 +75,19 @@ public: typedef void reference; ostream_joiner(ostream_type& __os, _Delim&& __d) - : __out(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} ostream_joiner(ostream_type& __os, const _Delim& __d) - : __out(_VSTD::addressof(__os)), __delim(__d), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} template<typename _Tp> ostream_joiner& operator=(const _Tp& __v) { if (!__first) - *__out << __delim; + *__output_iter << __delim; __first = false; - *__out << __v; + *__output_iter << __v; return *this; } @@ -96,7 +96,7 @@ public: ostream_joiner& operator++(int) _NOEXCEPT { return *this; } private: - ostream_type* __out; + ostream_type* __output_iter; _Delim __delim; bool __first; }; diff --git a/lib/libcxx/include/experimental/memory_resource b/lib/libcxx/include/experimental/memory_resource index 9b345210ee5..d101f3e0811 100644 --- a/lib/libcxx/include/experimental/memory_resource +++ b/lib/libcxx/include/experimental/memory_resource @@ -82,6 +82,9 @@ namespace pmr { #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR // Round __s up to next multiple of __a. @@ -93,7 +96,7 @@ size_t __aligned_allocation_size(size_t __s, size_t __a) _NOEXCEPT } // 8.5, memory.resource -class _LIBCPP_TYPE_VIS_ONLY memory_resource +class _LIBCPP_TEMPLATE_VIS memory_resource { static const size_t __max_align = alignof(max_align_t); @@ -151,7 +154,7 @@ memory_resource * set_default_resource(memory_resource * __new_res) _NOEXCEPT; // 8.6.1, memory.polymorphic.allocator.overview template <class _ValueType> -class _LIBCPP_TYPE_VIS_ONLY polymorphic_allocator +class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { public: typedef _ValueType value_type; @@ -181,10 +184,10 @@ public: // 8.6.3, memory.polymorphic.allocator.mem _LIBCPP_INLINE_VISIBILITY _ValueType* allocate(size_t __n) { - if (__n > max_size()) { - __libcpp_throw(length_error( + if (__n > __max_size()) { + __throw_length_error( "std::experimental::pmr::polymorphic_allocator<T>::allocate(size_t n)" - " 'n' exceeds maximum supported size")); + " 'n' exceeds maximum supported size"); } return static_cast<_ValueType*>( __res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType)) @@ -193,7 +196,7 @@ public: _LIBCPP_INLINE_VISIBILITY void deallocate(_ValueType * __p, size_t __n) _NOEXCEPT { - _LIBCPP_ASSERT(__n <= max_size(), + _LIBCPP_ASSERT(__n <= __max_size(), "deallocate called for size which exceeds max_size()"); __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); } @@ -266,10 +269,6 @@ public: { __p->~_Tp(); } _LIBCPP_INLINE_VISIBILITY - size_t max_size() const _NOEXCEPT - { return numeric_limits<size_t>::max() / sizeof(value_type); } - - _LIBCPP_INLINE_VISIBILITY polymorphic_allocator select_on_container_copy_construction() const _NOEXCEPT { return polymorphic_allocator(); } @@ -309,6 +308,10 @@ private: return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., resource()); } + _LIBCPP_INLINE_VISIBILITY + size_t __max_size() const _NOEXCEPT + { return numeric_limits<size_t>::max() / sizeof(value_type); } + memory_resource * __res_; }; @@ -334,7 +337,7 @@ bool operator!=(polymorphic_allocator<_Tp> const & __lhs, // 8.7.1, memory.resource.adaptor.overview template <class _CharAlloc> -class _LIBCPP_TYPE_VIS_ONLY __resource_adaptor_imp +class _LIBCPP_TEMPLATE_VIS __resource_adaptor_imp : public memory_resource { using _CTraits = allocator_traits<_CharAlloc>; @@ -383,9 +386,9 @@ protected: virtual void * do_allocate(size_t __bytes, size_t) { if (__bytes > __max_size()) { - __libcpp_throw(length_error( + __throw_length_error( "std::experimental::pmr::resource_adaptor<T>::do_allocate(size_t bytes, size_t align)" - " 'bytes' exceeds maximum supported size")); + " 'bytes' exceeds maximum supported size"); } size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign; return __alloc_.allocate(__s); @@ -419,4 +422,6 @@ using resource_adaptor = __resource_adaptor_imp< _LIBCPP_END_NAMESPACE_LFTS_PMR +_LIBCPP_POP_MACROS + #endif /* _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE */ diff --git a/lib/libcxx/include/experimental/numeric b/lib/libcxx/include/experimental/numeric new file mode 100644 index 00000000000..d784c08f0fe --- /dev/null +++ b/lib/libcxx/include/experimental/numeric @@ -0,0 +1,119 @@ +// -*- C++ -*- +//===--------------------------- numeric ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_NUMERIC +#define _LIBCPP_EXPERIMENTAL_NUMERIC +/* + experimental/numeric synopsis + +// C++1z +namespace std { +namespace experimental { +inline namespace fundamentals_v2 { + + // 13.1.2, Greatest common divisor + template<class M, class N> + constexpr common_type_t<M,N> gcd(M m, N n); + + // 13.1.3, Least common multiple + template<class M, class N> + constexpr common_type_t<M,N> lcm(M m, N n); + +} // namespace fundamentals_v2 +} // namespace experimental +} // namespace std + + */ + +#include <experimental/__config> +#include <numeric> +#include <type_traits> // is_integral +#include <limits> // numeric_limits + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER > 11 + +_LIBCPP_BEGIN_NAMESPACE_LFTS_V2 + +template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __abs; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, true> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept + { + if (__t >= 0) return __t; + if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t); + return -__t; + } +}; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, false> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept { return __t; } +}; + + +template<class _Tp> +_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN +inline _Tp __gcd(_Tp __m, _Tp __n) +{ + static_assert((!is_signed<_Tp>::value), "" ); + return __n == 0 ? __m : _VSTD_LFTS_V2::__gcd<_Tp>(__n, __m % __n); +} + + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +gcd(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" ); + using _Rp = common_type_t<_Tp,_Up>; + using _Wp = make_unsigned_t<_Rp>; + return static_cast<_Rp>(_VSTD_LFTS_V2::__gcd( + static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)), + static_cast<_Wp>(__abs<_Rp, _Up>()(__n)))); +} + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +lcm(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" ); + if (__m == 0 || __n == 0) + return 0; + + using _Rp = common_type_t<_Tp,_Up>; + _Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD_LFTS_V2::gcd(__m, __n); + _Rp __val2 = __abs<_Rp, _Up>()(__n); + _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); + return __val1 * __val2; +} + +_LIBCPP_END_NAMESPACE_LFTS_V2 + +#endif /* _LIBCPP_STD_VER > 11 */ + +_LIBCPP_POP_MACROS + +#endif /* _LIBCPP_EXPERIMENTAL_NUMERIC */ diff --git a/lib/libcxx/include/experimental/optional b/lib/libcxx/include/experimental/optional index 3912438ec10..b251748fbf3 100644 --- a/lib/libcxx/include/experimental/optional +++ b/lib/libcxx/include/experimental/optional @@ -8,8 +8,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP_OPTIONAL -#define _LIBCPP_OPTIONAL +#ifndef _LIBCPP_EXPERIMENTAL_OPTIONAL +#define _LIBCPP_EXPERIMENTAL_OPTIONAL /* optional synopsis @@ -143,9 +143,24 @@ namespace std { namespace experimental { inline namespace fundamentals_v1 { #include <experimental/__config> #include <functional> #include <stdexcept> +#if _LIBCPP_STD_VER > 11 +#include <initializer_list> +#include <type_traits> +#include <new> +#include <__functional_base> +#include <__debug> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL -class _LIBCPP_EXCEPTION_ABI bad_optional_access +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access : public std::logic_error { public: @@ -160,17 +175,6 @@ _LIBCPP_END_NAMESPACE_EXPERIMENTAL #if _LIBCPP_STD_VER > 11 -#include <initializer_list> -#include <type_traits> -#include <new> -#include <__functional_base> -#include <__undef_min_max> -#include <__debug> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - _LIBCPP_BEGIN_NAMESPACE_LFTS struct in_place_t {}; @@ -211,7 +215,7 @@ protected: : __engaged_(__x.__engaged_) { if (__engaged_) - ::new(_VSTD::addressof(__val_)) value_type(__x.__val_); + ::new((void*)_VSTD::addressof(__val_)) value_type(__x.__val_); } _LIBCPP_INLINE_VISIBILITY @@ -220,7 +224,7 @@ protected: : __engaged_(__x.__engaged_) { if (__engaged_) - ::new(_VSTD::addressof(__val_)) value_type(_VSTD::move(__x.__val_)); + ::new((void*)_VSTD::addressof(__val_)) value_type(_VSTD::move(__x.__val_)); } _LIBCPP_INLINE_VISIBILITY @@ -262,7 +266,7 @@ protected: : __engaged_(__x.__engaged_) { if (__engaged_) - ::new(_VSTD::addressof(__val_)) value_type(__x.__val_); + ::new((void*)_VSTD::addressof(__val_)) value_type(__x.__val_); } _LIBCPP_INLINE_VISIBILITY @@ -271,7 +275,7 @@ protected: : __engaged_(__x.__engaged_) { if (__engaged_) - ::new(_VSTD::addressof(__val_)) value_type(_VSTD::move(__x.__val_)); + ::new((void*)_VSTD::addressof(__val_)) value_type(_VSTD::move(__x.__val_)); } _LIBCPP_INLINE_VISIBILITY @@ -368,7 +372,7 @@ public: if (this->__engaged_) this->__val_.~value_type(); else - ::new(_VSTD::addressof(this->__val_)) value_type(__opt.__val_); + ::new((void*)_VSTD::addressof(this->__val_)) value_type(__opt.__val_); this->__engaged_ = __opt.__engaged_; } return *this; @@ -390,7 +394,8 @@ public: if (this->__engaged_) this->__val_.~value_type(); else - ::new(_VSTD::addressof(this->__val_)) value_type(_VSTD::move(__opt.__val_)); + ::new((void*)_VSTD::addressof(this->__val_)) + value_type(_VSTD::move(__opt.__val_)); this->__engaged_ = __opt.__engaged_; } return *this; @@ -412,7 +417,7 @@ public: this->__val_ = _VSTD::forward<_Up>(__v); else { - ::new(_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Up>(__v)); + ::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Up>(__v)); this->__engaged_ = true; } return *this; @@ -429,7 +434,8 @@ public: emplace(_Args&&... __args) { *this = nullopt; - ::new(_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); + ::new((void*)_VSTD::addressof(this->__val_)) + value_type(_VSTD::forward<_Args>(__args)...); this->__engaged_ = true; } @@ -444,7 +450,8 @@ public: emplace(initializer_list<_Up> __il, _Args&&... __args) { *this = nullopt; - ::new(_VSTD::addressof(this->__val_)) value_type(__il, _VSTD::forward<_Args>(__args)...); + ::new((void*)_VSTD::addressof(this->__val_)) + value_type(__il, _VSTD::forward<_Args>(__args)...); this->__engaged_ = true; } @@ -464,12 +471,14 @@ public: { if (this->__engaged_) { - ::new(_VSTD::addressof(__opt.__val_)) value_type(_VSTD::move(this->__val_)); + ::new((void*)_VSTD::addressof(__opt.__val_)) + value_type(_VSTD::move(this->__val_)); this->__val_.~value_type(); } else { - ::new(_VSTD::addressof(this->__val_)) value_type(_VSTD::move(__opt.__val_)); + ::new((void*)_VSTD::addressof(this->__val_)) + value_type(_VSTD::move(__opt.__val_)); __opt.__val_.~value_type(); } swap(this->__engaged_, __opt.__engaged_); @@ -482,7 +491,11 @@ public: operator->() const { _LIBCPP_ASSERT(this->__engaged_, "optional operator-> called for disengaged value"); +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + return __builtin_addressof(this->__val_); +#else return __operator_arrow(__has_operator_addressof<value_type>{}); +#endif } _LIBCPP_INLINE_VISIBILITY @@ -513,27 +526,32 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr explicit operator bool() const noexcept {return this->__engaged_;} - _LIBCPP_INLINE_VISIBILITY - constexpr value_type const& value() const - { - if (!this->__engaged_) + _LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_NO_EXCEPTIONS +_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS +#endif + constexpr void __throw_bad_optional_access() const + { #ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_optional_access(); + throw bad_optional_access(); #else - assert(!"bad optional access"); + _VSTD::abort(); #endif + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS + constexpr value_type const& value() const + { + if (!this->__engaged_) + __throw_bad_optional_access(); return this->__val_; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS value_type& value() { if (!this->__engaged_) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_optional_access(); -#else - assert(!"bad optional access"); -#endif + __throw_bad_optional_access(); return this->__val_; } @@ -710,7 +728,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY constexpr bool -operator<=(nullopt_t, const optional<_Tp>& __x) noexcept +operator<=(nullopt_t, const optional<_Tp>&) noexcept { return true; } @@ -728,7 +746,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY constexpr bool -operator>(nullopt_t, const optional<_Tp>& __x) noexcept +operator>(nullopt_t, const optional<_Tp>&) noexcept { return false; } @@ -883,7 +901,7 @@ _LIBCPP_END_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY hash<std::experimental::optional<_Tp> > +struct _LIBCPP_TEMPLATE_VIS hash<std::experimental::optional<_Tp> > { typedef std::experimental::optional<_Tp> argument_type; typedef size_t result_type; @@ -899,4 +917,6 @@ _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER > 11 -#endif // _LIBCPP_OPTIONAL +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_EXPERIMENTAL_OPTIONAL diff --git a/lib/libcxx/include/experimental/propagate_const b/lib/libcxx/include/experimental/propagate_const index f267ba275c2..e7f7e9fc683 100644 --- a/lib/libcxx/include/experimental/propagate_const +++ b/lib/libcxx/include/experimental/propagate_const @@ -123,8 +123,14 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 template <class _Tp> class propagate_const; -template <class _Up> _LIBCPP_CONSTEXPR const _Up& get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT; -template <class _Up> _LIBCPP_CONSTEXPR _Up& get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT; + +template <class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +const _Up& get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT; + +template <class _Up> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_Up& get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT; template <class _Tp> class propagate_const @@ -462,14 +468,12 @@ _LIBCPP_CONSTEXPR void swap(propagate_const<_Tp>& __pc1, propagate_const<_Tp>& _ } template <class _Tp> -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const _Tp& get_underlying(const propagate_const<_Tp>& __pt) _NOEXCEPT { return __pt.__t_; } template <class _Tp> -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp& get_underlying(propagate_const<_Tp>& __pt) _NOEXCEPT { return __pt.__t_; diff --git a/lib/libcxx/include/experimental/string_view b/lib/libcxx/include/experimental/string_view index 0a7239b4c0b..da104f9a121 100644 --- a/lib/libcxx/include/experimental/string_view +++ b/lib/libcxx/include/experimental/string_view @@ -189,10 +189,13 @@ namespace std { #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_LFTS template<class _CharT, class _Traits = _VSTD::char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_string_view { + class _LIBCPP_TEMPLATE_VIS basic_string_view { public: // types typedef _Traits traits_type; @@ -281,7 +284,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS const_reference at(size_type __pos) const { return __pos >= size() - ? (__libcpp_throw(out_of_range("string_view::at")), __data[0]) + ? (__throw_out_of_range("string_view::at"), __data[0]) : __data[__pos]; } @@ -352,7 +355,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const { if ( __pos > size()) - __libcpp_throw(out_of_range("string_view::copy")); + __throw_out_of_range("string_view::copy"); size_type __rlen = _VSTD::min( __n, size() - __pos ); _VSTD::copy_n(begin() + __pos, __rlen, __s ); return __rlen; @@ -362,11 +365,11 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS basic_string_view substr(size_type __pos = 0, size_type __n = npos) const { // if (__pos > size()) -// throw out_of_range("string_view::substr"); +// __throw_out_of_range("string_view::substr"); // size_type __rlen = _VSTD::min( __n, size() - __pos ); // return basic_string_view(data() + __pos, __rlen); return __pos > size() - ? (__libcpp_throw((out_of_range("string_view::substr"))), basic_string_view()) + ? (__throw_out_of_range("string_view::substr"), basic_string_view()) : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); } @@ -783,7 +786,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // [string.view.hash] // Shamelessly stolen from <string> template<class _CharT, class _Traits> -struct _LIBCPP_TYPE_VIS_ONLY hash<std::experimental::basic_string_view<_CharT, _Traits> > +struct _LIBCPP_TEMPLATE_VIS hash<std::experimental::basic_string_view<_CharT, _Traits> > : public unary_function<std::experimental::basic_string_view<_CharT, _Traits>, size_t> { size_t operator()(const std::experimental::basic_string_view<_CharT, _Traits>& __val) const _NOEXCEPT; @@ -810,4 +813,6 @@ quoted ( std::experimental::basic_string_view <_CharT, _Traits> __sv, _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_LFTS_STRING_VIEW diff --git a/lib/libcxx/include/experimental/type_traits b/lib/libcxx/include/experimental/type_traits index ae49fc176c0..3a7593620a7 100644 --- a/lib/libcxx/include/experimental/type_traits +++ b/lib/libcxx/include/experimental/type_traits @@ -172,6 +172,45 @@ inline namespace fundamentals_v1 { template <class T> using raw_invocation_type_t = typename raw_invocation_type<T>::type; + // 3.3.3, Logical operator traits + template<class... B> struct conjunction; + template<class... B> constexpr bool conjunction_v = conjunction<B...>::value; + template<class... B> struct disjunction; + template<class... B> constexpr bool disjunction_v = disjunction<B...>::value; + template<class B> struct negation; + template<class B> constexpr bool negation_v = negation<B>::value; + + // 3.3.4, Detection idiom + template <class...> using void_t = void; + + struct nonesuch { + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; + }; + + template <template<class...> class Op, class... Args> + using is_detected = see below; + template <template<class...> class Op, class... Args> + constexpr bool is_detected_v = is_detected<Op, Args...>::value; + template <template<class...> class Op, class... Args> + using detected_t = see below; + template <class Default, template<class...> class Op, class... Args> + using detected_or = see below; + template <class Default, template<class...> class Op, class... Args> + using detected_or_t = typename detected_or<Default, Op, Args...>::type; + template <class Expected, template<class...> class Op, class... Args> + using is_detected_exact = is_same<Expected, detected_t<Op, Args...>>; + template <class Expected, template<class...> class Op, class... Args> + constexpr bool is_detected_exact_v + = is_detected_exact<Expected, Op, Args...>::value; + template <class To, template<class...> class Op, class... Args> + using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>; + template <class To, template<class...> class Op, class... Args> + constexpr bool is_detected_convertible_v + = is_detected_convertible<To, Op, Args...>::value; + } // namespace fundamentals_v1 } // namespace experimental } // namespace std @@ -402,16 +441,16 @@ template <class _Tp, class _Up> _LIBCPP_CONSTEXPR bool is_convertible_v // 3.3.2, Other type transformations /* template <class> -class _LIBCPP_TYPE_VIS_ONLY raw_invocation_type; +class _LIBCPP_TEMPLATE_VIS raw_invocation_type; template <class _Fn, class ..._Args> -class _LIBCPP_TYPE_VIS_ONLY raw_invocation_type<_Fn(_Args...)>; +class _LIBCPP_TEMPLATE_VIS raw_invocation_type<_Fn(_Args...)>; template <class> -class _LIBCPP_TYPE_VIS_ONLY invokation_type; +class _LIBCPP_TEMPLATE_VIS invokation_type; template <class _Fn, class ..._Args> -class _LIBCPP_TYPE_VIS_ONLY invokation_type<_Fn(_Args...)>; +class _LIBCPP_TEMPLATE_VIS invokation_type<_Fn(_Args...)>; template <class _Tp> using invokation_type_t = typename invokation_type<_Tp>::type; @@ -420,6 +459,70 @@ template <class _Tp> using raw_invocation_type_t = typename raw_invocation_type<_Tp>::type; */ +// 3.3.3, Logical operator traits +template <class...> using void_t = void; + +template <class... _Args> +struct conjunction : _VSTD::__and_<_Args...> {}; +template <class... _Args> +_LIBCPP_CONSTEXPR bool conjunction_v = conjunction<_Args...>::value; + +template <class... _Args> +struct disjunction : _VSTD::__or_<_Args...> {}; +template <class... _Args> +_LIBCPP_CONSTEXPR bool disjunction_v = disjunction<_Args...>::value; + +template <class _Tp> +struct negation : _VSTD::__not_<_Tp> {}; +template<class _Tp> +_LIBCPP_CONSTEXPR bool negation_v = negation<_Tp>::value; + +// 3.3.4, Detection idiom +template <class...> using void_t = void; + +struct nonesuch { + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch (nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; + }; + +template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args> +struct _DETECTOR { + using value_t = false_type; + using type = _Default; + }; + +template <class _Default, template <class...> class _Op, class... _Args> +struct _DETECTOR<_Default, void_t<_Op<_Args...>>, _Op, _Args...> { + using value_t = true_type; + using type = _Op<_Args...>; + }; + + +template <template<class...> class _Op, class... _Args> + using is_detected = typename _DETECTOR<nonesuch, void, _Op, _Args...>::value_t; +template <template<class...> class _Op, class... _Args> + using detected_t = typename _DETECTOR<nonesuch, void, _Op, _Args...>::type; +template <template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_v = is_detected<_Op, _Args...>::value; + +template <class Default, template<class...> class _Op, class... _Args> + using detected_or = _DETECTOR<Default, void, _Op, _Args...>; +template <class Default, template<class...> class _Op, class... _Args> + using detected_or_t = typename detected_or<Default, _Op, _Args...>::type; + +template <class Expected, template<class...> class _Op, class... _Args> + using is_detected_exact = is_same<Expected, detected_t<_Op, _Args...>>; +template <class Expected, template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_exact_v = is_detected_exact<Expected, _Op, _Args...>::value; + +template <class To, template<class...> class _Op, class... _Args> + using is_detected_convertible = is_convertible<detected_t<_Op, _Args...>, To>; +template <class To, template<class...> class _Op, class... _Args> + _LIBCPP_CONSTEXPR bool is_detected_convertible_v = is_detected_convertible<To, _Op, _Args...>::value; + + _LIBCPP_END_NAMESPACE_LFTS #endif /* _LIBCPP_STD_VER > 11 */ diff --git a/lib/libcxx/include/experimental/utility b/lib/libcxx/include/experimental/utility index b5fca6c775b..8effa71c131 100644 --- a/lib/libcxx/include/experimental/utility +++ b/lib/libcxx/include/experimental/utility @@ -40,7 +40,7 @@ inline namespace fundamentals_v1 { _LIBCPP_BEGIN_NAMESPACE_LFTS - struct _LIBCPP_TYPE_VIS_ONLY erased_type { }; + struct _LIBCPP_TEMPLATE_VIS erased_type { }; _LIBCPP_END_NAMESPACE_LFTS diff --git a/lib/libcxx/include/ext/__hash b/lib/libcxx/include/ext/__hash index 5675d54055e..318cb1f97b0 100644 --- a/lib/libcxx/include/ext/__hash +++ b/lib/libcxx/include/ext/__hash @@ -19,9 +19,9 @@ namespace __gnu_cxx { using namespace std; -template <typename _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash { }; +template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<const char*> +template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*> : public unary_function<const char*, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -31,7 +31,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<const char*> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char *> +template <> struct _LIBCPP_TEMPLATE_VIS hash<char *> : public unary_function<char*, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -41,7 +41,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char *> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char> +template <> struct _LIBCPP_TEMPLATE_VIS hash<char> : public unary_function<char, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -51,7 +51,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> +template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> : public unary_function<signed char, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -61,7 +61,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> : public unary_function<unsigned char, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -71,7 +71,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<short> +template <> struct _LIBCPP_TEMPLATE_VIS hash<short> : public unary_function<short, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -81,7 +81,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<short> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> : public unary_function<unsigned short, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -91,7 +91,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<int> +template <> struct _LIBCPP_TEMPLATE_VIS hash<int> : public unary_function<int, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -101,7 +101,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<int> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> : public unary_function<unsigned int, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -111,7 +111,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<long> +template <> struct _LIBCPP_TEMPLATE_VIS hash<long> : public unary_function<long, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -121,7 +121,7 @@ template <> struct _LIBCPP_TYPE_VIS_ONLY hash<long> } }; -template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> +template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> : public unary_function<unsigned long, size_t> { _LIBCPP_INLINE_VISIBILITY diff --git a/lib/libcxx/include/ext/hash_map b/lib/libcxx/include/ext/hash_map index 5e1e9f542b1..998e8f65994 100644 --- a/lib/libcxx/include/ext/hash_map +++ b/lib/libcxx/include/ext/hash_map @@ -207,7 +207,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc> #include <ext/__hash> #if __DEPRECATED -#if defined(_MSC_VER) && ! defined(__clang__) +#if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>") #else # warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map> @@ -331,7 +331,7 @@ public: __second_constructed(false) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) : __na_(__x.__na_), @@ -340,7 +340,7 @@ public: { __x.__value_constructed = false; } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#else // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) : __na_(__x.__na_), @@ -349,7 +349,7 @@ public: { const_cast<bool&>(__x.__value_constructed) = false; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) @@ -364,7 +364,7 @@ public: }; template <class _HashIterator> -class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator +class _LIBCPP_TEMPLATE_VIS __hash_map_iterator { _HashIterator __i_; @@ -401,15 +401,15 @@ public: bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_multimap; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; }; template <class _HashIterator> -class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator +class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator { _HashIterator __i_; @@ -454,15 +454,15 @@ public: bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_multimap; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; }; template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, class _Alloc = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY hash_map +class _LIBCPP_TEMPLATE_VIS hash_map { public: // types @@ -736,7 +736,7 @@ operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, class _Alloc = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY hash_multimap +class _LIBCPP_TEMPLATE_VIS hash_multimap { public: // types diff --git a/lib/libcxx/include/ext/hash_set b/lib/libcxx/include/ext/hash_set index 91850b566d5..38f81ed3b5c 100644 --- a/lib/libcxx/include/ext/hash_set +++ b/lib/libcxx/include/ext/hash_set @@ -199,7 +199,7 @@ template <class Value, class Hash, class Pred, class Alloc> #include <ext/__hash> #if __DEPRECATED -#if defined(_MSC_VER) && ! defined(__clang__) +#if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>") #else # warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set> @@ -212,7 +212,7 @@ using namespace std; template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> > -class _LIBCPP_TYPE_VIS_ONLY hash_set +class _LIBCPP_TEMPLATE_VIS hash_set { public: // types @@ -434,7 +434,7 @@ operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> > -class _LIBCPP_TYPE_VIS_ONLY hash_multiset +class _LIBCPP_TEMPLATE_VIS hash_multiset { public: // types diff --git a/lib/libcxx/include/forward_list b/lib/libcxx/include/forward_list index 18b300d8470..7b820413720 100644 --- a/lib/libcxx/include/forward_list +++ b/lib/libcxx/include/forward_list @@ -87,7 +87,7 @@ public: reference front(); const_reference front() const; - template <class... Args> void emplace_front(Args&&... args); + template <class... Args> reference emplace_front(Args&&... args); // reference in C++17 void push_front(const value_type& v); void push_front(value_type&& v); @@ -167,19 +167,20 @@ template <class T, class Allocator> */ #include <__config> - #include <initializer_list> #include <memory> #include <limits> #include <iterator> #include <algorithm> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _VoidPtr> struct __forward_list_node; @@ -266,11 +267,11 @@ struct __forward_list_node }; -template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY forward_list; -template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator; +template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list; +template<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; template <class _NodePtr> -class _LIBCPP_TYPE_VIS_ONLY __forward_list_iterator +class _LIBCPP_TEMPLATE_VIS __forward_list_iterator { typedef __forward_node_traits<_NodePtr> __traits; typedef typename __traits::__node_pointer __node_pointer; @@ -302,8 +303,8 @@ class _LIBCPP_TYPE_VIS_ONLY __forward_list_iterator explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__traits::__as_iter_node(__p)) {} - template<class, class> friend class _LIBCPP_TYPE_VIS_ONLY forward_list; - template<class> friend class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator; + template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list; + template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; public: typedef forward_iterator_tag iterator_category; @@ -348,7 +349,7 @@ public: }; template <class _NodeConstPtr> -class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator +class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator { static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), ""); typedef _NodeConstPtr _NodePtr; @@ -478,14 +479,14 @@ protected: __forward_list_base(const allocator_type& __a) : __before_begin_(__begin_node(), __node_allocator(__a)) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG public: _LIBCPP_INLINE_VISIBILITY __forward_list_base(__forward_list_base&& __x) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG private: __forward_list_base(const __forward_list_base&); @@ -531,7 +532,7 @@ private: } _LIBCPP_INLINE_VISIBILITY - void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT + void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__forward_list_base& __x, true_type) @@ -539,7 +540,7 @@ private: {__alloc() = _VSTD::move(__x.__alloc());} }; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> inline @@ -563,7 +564,7 @@ __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> __forward_list_base<_Tp, _Alloc>::~__forward_list_base() @@ -604,7 +605,7 @@ __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT } template <class _Tp, class _Alloc /*= allocator<_Tp>*/> -class _LIBCPP_TYPE_VIS_ONLY forward_list +class _LIBCPP_TEMPLATE_VIS forward_list : private __forward_list_base<_Tp, _Alloc> { typedef __forward_list_base<_Tp, _Alloc> base; @@ -656,32 +657,33 @@ public: >::type* = nullptr); forward_list(const forward_list& __x); forward_list(const forward_list& __x, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + + forward_list& operator=(const forward_list& __x); + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY forward_list(forward_list&& __x) _NOEXCEPT_(is_nothrow_move_constructible<base>::value) : base(_VSTD::move(__x)) {} forward_list(forward_list&& __x, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + forward_list(initializer_list<value_type> __il); forward_list(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - // ~forward_list() = default; - - forward_list& operator=(const forward_list& __x); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY forward_list& operator=(forward_list&& __x) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY forward_list& operator=(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il); +#endif // _LIBCPP_CXX03_LANG + + // ~forward_list() = default; template <class _InputIterator> typename enable_if @@ -691,10 +693,6 @@ public: >::type assign(_InputIterator __f, _InputIterator __l); void assign(size_type __n, const value_type& __v); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - void assign(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT @@ -730,35 +728,41 @@ public: const_iterator cbefore_begin() const _NOEXCEPT {return const_iterator(base::__before_begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::__before_begin()->__next_ == nullptr;} _LIBCPP_INLINE_VISIBILITY - size_type max_size() const _NOEXCEPT - {return numeric_limits<size_type>::max();} + size_type max_size() const _NOEXCEPT { + return std::min<size_type>( + __node_traits::max_size(base::__alloc()), + numeric_limits<difference_type>::max()); + } _LIBCPP_INLINE_VISIBILITY reference front() {return base::__before_begin()->__next_->__value_;} _LIBCPP_INLINE_VISIBILITY const_reference front() const {return base::__before_begin()->__next_->__value_;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class... _Args> void emplace_front(_Args&&... __args); +#ifndef _LIBCPP_CXX03_LANG +#if _LIBCPP_STD_VER > 14 + template <class... _Args> reference emplace_front(_Args&&... __args); +#else + template <class... _Args> void emplace_front(_Args&&... __args); #endif void push_front(value_type&& __v); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG void push_front(const value_type& __v); void pop_front(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class... _Args> iterator emplace_after(const_iterator __p, _Args&&... __args); -#endif // _LIBCPP_HAS_NO_VARIADICS + iterator insert_after(const_iterator __p, value_type&& __v); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator insert_after(const_iterator __p, initializer_list<value_type> __il) + {return insert_after(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG iterator insert_after(const_iterator __p, const value_type& __v); iterator insert_after(const_iterator __p, size_type __n, const value_type& __v); template <class _InputIterator> @@ -769,10 +773,6 @@ public: iterator >::type insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - iterator insert_after(const_iterator __p, initializer_list<value_type> __il) - {return insert_after(__p, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS iterator erase_after(const_iterator __p); iterator erase_after(const_iterator __f, const_iterator __l); @@ -792,7 +792,7 @@ public: _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {base::clear();} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x); _LIBCPP_INLINE_VISIBILITY @@ -800,7 +800,7 @@ public: _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG void splice_after(const_iterator __p, forward_list& __x); void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); void splice_after(const_iterator __p, forward_list& __x, @@ -810,14 +810,14 @@ public: _LIBCPP_INLINE_VISIBILITY void unique() {unique(__equal_to<value_type>());} template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x) {merge(__x, __less<value_type>());} template <class _Compare> _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x, _Compare __comp) {merge(__x, _VSTD::move(__comp));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list& __x) {merge(__x, __less<value_type>());} template <class _Compare> void merge(forward_list& __x, _Compare __comp); @@ -828,11 +828,11 @@ public: private: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG void __move_assign(forward_list& __x, true_type) _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); void __move_assign(forward_list& __x, false_type); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Compare> static @@ -873,8 +873,9 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n) #if _LIBCPP_STD_VER > 11 template <class _Tp, class _Alloc> -forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a) - : base ( __a ) +forward_list<_Tp, _Alloc>::forward_list(size_type __n, + const allocator_type& __base_alloc) + : base ( __base_alloc ) { if (__n > 0) { @@ -947,8 +948,19 @@ forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, insert_after(cbefore_begin(), __x.begin(), __x.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) +{ + if (this != &__x) + { + base::__copy_assign_alloc(__x); + assign(__x.begin(), __x.end()); + } + return *this; +} +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, const allocator_type& __a) @@ -961,10 +973,6 @@ forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp, class _Alloc> forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) { @@ -979,22 +987,6 @@ forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, insert_after(cbefore_begin(), __il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -template <class _Tp, class _Alloc> -forward_list<_Tp, _Alloc>& -forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) -{ - if (this != &__x) - { - base::__copy_assign_alloc(__x); - assign(__x.begin(), __x.end()); - } - return *this; -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Alloc> void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) @@ -1032,10 +1024,6 @@ forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp, class _Alloc> inline forward_list<_Tp, _Alloc>& @@ -1045,7 +1033,7 @@ forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> template <class _InputIterator> @@ -1082,7 +1070,7 @@ forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) erase_after(__i, __e); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> inline @@ -1092,14 +1080,13 @@ forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) assign(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Alloc> template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename forward_list<_Tp, _Alloc>::reference +#else void +#endif forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) { __node_allocator& __a = base::__alloc(); @@ -1109,10 +1096,11 @@ forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) _VSTD::forward<_Args>(__args)...); __h->__next_ = base::__before_begin()->__next_; base::__before_begin()->__next_ = __h.release(); +#if _LIBCPP_STD_VER > 14 + return base::__before_begin()->__next_->__value_; +#endif } -#endif // _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Alloc> void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) @@ -1125,7 +1113,7 @@ forward_list<_Tp, _Alloc>::push_front(value_type&& __v) base::__before_begin()->__next_ = __h.release(); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> void @@ -1150,8 +1138,7 @@ forward_list<_Tp, _Alloc>::pop_front() __node_traits::deallocate(__a, __p, 1); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> template <class... _Args> @@ -1169,8 +1156,6 @@ forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) return iterator(__r->__next_); } -#endif // _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) @@ -1185,7 +1170,7 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) return iterator(__r->__next_); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> typename forward_list<_Tp, _Alloc>::iterator @@ -1421,7 +1406,7 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, template <class _Tp, class _Alloc> void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, - forward_list& __x, + forward_list& /*__other*/, const_iterator __i) { const_iterator __lm1 = _VSTD::next(__i); @@ -1436,7 +1421,7 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, template <class _Tp, class _Alloc> void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, - forward_list& __x, + forward_list& /*__other*/, const_iterator __f, const_iterator __l) { if (__f != __l && __p != __f) @@ -1453,7 +1438,7 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, } } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY @@ -1484,7 +1469,7 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, splice_after(__p, __x, __f, __l); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> void @@ -1735,4 +1720,6 @@ swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_FORWARD_LIST diff --git a/lib/libcxx/include/fstream b/lib/libcxx/include/fstream index 3cb3b13bd10..f57908c8dfa 100644 --- a/lib/libcxx/include/fstream +++ b/lib/libcxx/include/fstream @@ -171,16 +171,18 @@ typedef basic_fstream<wchar_t> wfstream; #include <__locale> #include <cstdio> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_filebuf +class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> { public: @@ -193,13 +195,13 @@ public: // 27.9.1.2 Constructors/destructor: basic_filebuf(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG basic_filebuf(basic_filebuf&& __rhs); #endif virtual ~basic_filebuf(); // 27.9.1.3 Assign/swap: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_filebuf& operator=(basic_filebuf&& __rhs); #endif @@ -276,7 +278,7 @@ basic_filebuf<_CharT, _Traits>::basic_filebuf() setbuf(0, 4096); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) @@ -313,7 +315,7 @@ basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) else this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); - this->pbump(__rhs. pptr() - __rhs.pbase()); + this->__pbump(__rhs. pptr() - __rhs.pbase()); } else if (__rhs.eback()) { @@ -352,7 +354,7 @@ basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> basic_filebuf<_CharT, _Traits>::~basic_filebuf() @@ -432,7 +434,7 @@ basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) ptrdiff_t __e = this->epptr() - this->pbase(); this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e); - this->pbump(__n); + this->__pbump(__n); } if (__rhs.eback() == (char_type*)__extbuf_min_) { @@ -448,7 +450,7 @@ basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e); - __rhs.pbump(__n); + __rhs.__pbump(__n); } } @@ -615,13 +617,12 @@ basic_filebuf<_CharT, _Traits>::underflow() static_cast<size_t>(__extbufend_ - __extbufnext_)); codecvt_base::result __r; __st_last_ = __st_; - size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_); + size_t __nr = fread((void*) const_cast<char *>(__extbufnext_), 1, __nmemb, __file_); if (__nr != 0) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __throw_bad_cast(); + __extbufend_ = __extbufnext_ + __nr; char_type* __inext; __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, @@ -629,7 +630,8 @@ basic_filebuf<_CharT, _Traits>::underflow() this->eback() + __ibs_, __inext); if (__r == codecvt_base::noconv) { - this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + (char_type*)const_cast<char *>(__extbufend_)); __c = traits_type::to_int_type(*this->gptr()); } else if (__inext != this->eback() + __unget_sz) @@ -700,10 +702,9 @@ basic_filebuf<_CharT, _Traits>::overflow(int_type __c) codecvt_base::result __r; do { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __throw_bad_cast(); + const char_type* __e; __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); @@ -722,8 +723,8 @@ basic_filebuf<_CharT, _Traits>::overflow(int_type __c) return traits_type::eof(); if (__r == codecvt_base::partial) { - this->setp((char_type*)__e, this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->setp(const_cast<char_type*>(__e), this->pptr()); + this->__pbump(this->epptr() - this->pbase()); } } else @@ -793,10 +794,9 @@ typename basic_filebuf<_CharT, _Traits>::pos_type basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __throw_bad_cast(); + int __width = __cv_->encoding(); if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) return pos_type(off_type(-1)); @@ -816,7 +816,7 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, default: return pos_type(off_type(-1)); } -#if defined(_WIN32) || defined(_NEWLIB_VERSION) +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) return pos_type(off_type(-1)); pos_type __r = ftell(__file_); @@ -835,7 +835,7 @@ basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) { if (__file_ == 0 || sync()) return pos_type(off_type(-1)); -#if defined(_WIN32) || defined(_NEWLIB_VERSION) +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, __sp, SEEK_SET)) return pos_type(off_type(-1)); #else @@ -852,10 +852,9 @@ basic_filebuf<_CharT, _Traits>::sync() { if (__file_ == 0) return 0; -#ifndef _LIBCPP_NO_EXCEPTIONS if (!__cv_) - throw bad_cast(); -#endif + __throw_bad_cast(); + if (__cm_ & ios_base::out) { if (this->pptr() != this->pbase()) @@ -900,7 +899,7 @@ basic_filebuf<_CharT, _Traits>::sync() } } } -#if defined(_WIN32) || defined(_NEWLIB_VERSION) +#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, -__c, SEEK_CUR)) return -1; #else @@ -1003,7 +1002,7 @@ basic_filebuf<_CharT, _Traits>::__write_mode() // basic_ifstream template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_ifstream +class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> { public: @@ -1021,12 +1020,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_ifstream(basic_ifstream&& __rhs); -#endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_ifstream& operator=(basic_ifstream&& __rhs); #endif @@ -1075,7 +1072,7 @@ basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::ope } #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1096,7 +1093,7 @@ basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1165,7 +1162,7 @@ basic_ifstream<_CharT, _Traits>::close() // basic_ofstream template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_ofstream +class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> { public: @@ -1181,12 +1178,10 @@ public: explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); _LIBCPP_INLINE_VISIBILITY explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_ofstream(basic_ofstream&& __rhs); -#endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_ofstream& operator=(basic_ofstream&& __rhs); #endif @@ -1235,7 +1230,7 @@ basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::ope } #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1256,7 +1251,7 @@ basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1325,7 +1320,7 @@ basic_ofstream<_CharT, _Traits>::close() // basic_fstream template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_fstream +class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> { public: @@ -1343,12 +1338,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_fstream(basic_fstream&& __rhs); -#endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_fstream& operator=(basic_fstream&& __rhs); #endif @@ -1397,7 +1390,7 @@ basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openm } #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1418,7 +1411,7 @@ basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> inline @@ -1486,4 +1479,6 @@ basic_fstream<_CharT, _Traits>::close() _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_FSTREAM diff --git a/lib/libcxx/include/functional b/lib/libcxx/include/functional index 581f965b2b8..3e5215b137b 100644 --- a/lib/libcxx/include/functional +++ b/lib/libcxx/include/functional @@ -212,6 +212,13 @@ template <class F> unspecified not_fn(F&& f); // C++17 template<class T> struct is_bind_expression; template<class T> struct is_placeholder; + // See C++14 20.9.9, Function object binders +template <class T> inline constexpr bool is_bind_expression_v + = is_bind_expression<T>::value; // C++17 +template <class T> inline constexpr int is_placeholder_v + = is_placeholder<T>::value; // C++17 + + template<class Fn, class... BoundArgs> unspecified bind(Fn&&, BoundArgs&&...); template<class R, class Fn, class... BoundArgs> @@ -228,7 +235,7 @@ namespace placeholders { } template <class Operation> -class binder1st +class binder1st // deprecated in C++11, removed in C++17 : public unary_function<typename Operation::second_argument_type, typename Operation::result_type> { @@ -242,10 +249,10 @@ public: }; template <class Operation, class T> -binder1st<Operation> bind1st(const Operation& op, const T& x); +binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 template <class Operation> -class binder2nd +class binder2nd // deprecated in C++11, removed in C++17 : public unary_function<typename Operation::first_argument_type, typename Operation::result_type> { @@ -259,9 +266,9 @@ public: }; template <class Operation, class T> -binder2nd<Operation> bind2nd(const Operation& op, const T& x); +binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 -template <class Arg, class Result> +template <class Arg, class Result> // deprecated in C++11, removed in C++17 class pointer_to_unary_function : public unary_function<Arg, Result> { public: @@ -270,9 +277,9 @@ public: }; template <class Arg, class Result> -pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); +pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 -template <class Arg1, class Arg2, class Result> +template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> { public: @@ -281,9 +288,9 @@ public: }; template <class Arg1, class Arg2, class Result> -pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); +pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 -template<class S, class T> +template<class S, class T> // deprecated in C++11, removed in C++17 class mem_fun_t : public unary_function<T*, S> { public: @@ -292,18 +299,18 @@ public: }; template<class S, class T, class A> -class mem_fun1_t : public binary_function<T*, A, S> +class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 { public: explicit mem_fun1_t(S (T::*p)(A)); S operator()(T* p, A x) const; }; -template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); -template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); +template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 +template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 template<class S, class T> -class mem_fun_ref_t : public unary_function<T, S> +class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 { public: explicit mem_fun_ref_t(S (T::*p)()); @@ -311,18 +318,18 @@ public: }; template<class S, class T, class A> -class mem_fun1_ref_t : public binary_function<T, A, S> +class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 { public: explicit mem_fun1_ref_t(S (T::*p)(A)); S operator()(T& p, A x) const; }; -template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); -template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); +template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 +template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 template <class S, class T> -class const_mem_fun_t : public unary_function<const T*, S> +class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun_t(S (T::*p)() const); @@ -330,18 +337,18 @@ public: }; template <class S, class T, class A> -class const_mem_fun1_t : public binary_function<const T*, A, S> +class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun1_t(S (T::*p)(A) const); S operator()(const T* p, A x) const; }; -template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); -template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); +template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 +template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 template <class S, class T> -class const_mem_fun_ref_t : public unary_function<T, S> +class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun_ref_t(S (T::*p)() const); @@ -349,15 +356,15 @@ public: }; template <class S, class T, class A> -class const_mem_fun1_ref_t : public binary_function<T, A, S> +class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun1_ref_t(S (T::*p)(A) const); S operator()(const T& p, A x) const; }; -template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); -template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); +template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 +template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 template<class R, class T> unspecified mem_fn(R T::*); @@ -386,15 +393,15 @@ public: template<class F> function(F); template<Allocator Alloc> - function(allocator_arg_t, const Alloc&) noexcept; + function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; + function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, const function&); + function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, function&&); + function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 template<class F, Allocator Alloc> - function(allocator_arg_t, const Alloc&, F); + function(allocator_arg_t, const Alloc&, F); // removed in C++17 function& operator=(const function&); function& operator=(function&&) noexcept; @@ -463,6 +470,7 @@ template <> struct hash<double>; template <> struct hash<long double>; template<class T> struct hash<T*>; +template <> struct hash<nullptr_t>; // C++17 } // std @@ -478,6 +486,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited #include <exception> #include <memory> #include <tuple> +#include <utility> #include <__functional_base> @@ -492,7 +501,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -501,7 +510,7 @@ struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY plus<void> +struct _LIBCPP_TEMPLATE_VIS plus<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -519,7 +528,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -528,7 +537,7 @@ struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY minus<void> +struct _LIBCPP_TEMPLATE_VIS minus<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -546,7 +555,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -555,7 +564,7 @@ struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY multiplies<void> +struct _LIBCPP_TEMPLATE_VIS multiplies<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -573,7 +582,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -582,7 +591,7 @@ struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY divides<void> +struct _LIBCPP_TEMPLATE_VIS divides<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -600,7 +609,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -609,7 +618,7 @@ struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY modulus<void> +struct _LIBCPP_TEMPLATE_VIS modulus<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -627,7 +636,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const @@ -636,7 +645,7 @@ struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY negate<void> +struct _LIBCPP_TEMPLATE_VIS negate<void> { template <class _Tp> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -654,7 +663,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -663,7 +672,7 @@ struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY equal_to<void> +struct _LIBCPP_TEMPLATE_VIS equal_to<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -681,7 +690,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -690,7 +699,7 @@ struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void> +struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -708,7 +717,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -717,7 +726,7 @@ struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY greater<void> +struct _LIBCPP_TEMPLATE_VIS greater<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -737,7 +746,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -746,7 +755,7 @@ struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void> +struct _LIBCPP_TEMPLATE_VIS greater_equal<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -764,7 +773,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -773,7 +782,7 @@ struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY less_equal<void> +struct _LIBCPP_TEMPLATE_VIS less_equal<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -791,7 +800,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -800,7 +809,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY logical_and<void> +struct _LIBCPP_TEMPLATE_VIS logical_and<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -818,7 +827,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool> +struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const @@ -827,7 +836,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY logical_or<void> +struct _LIBCPP_TEMPLATE_VIS logical_or<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -845,7 +854,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool> +struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const @@ -854,7 +863,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY logical_not<void> +struct _LIBCPP_TEMPLATE_VIS logical_not<void> { template <class _Tp> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -872,7 +881,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -881,7 +890,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY bit_and<void> +struct _LIBCPP_TEMPLATE_VIS bit_and<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -899,7 +908,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -908,7 +917,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY bit_or<void> +struct _LIBCPP_TEMPLATE_VIS bit_or<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -926,7 +935,7 @@ template <class _Tp = void> #else template <class _Tp> #endif -struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const @@ -935,7 +944,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp> #if _LIBCPP_STD_VER > 11 template <> -struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void> +struct _LIBCPP_TEMPLATE_VIS bit_xor<void> { template <class _T1, class _T2> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -950,7 +959,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void> #if _LIBCPP_STD_VER > 11 template <class _Tp = void> -struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const @@ -958,7 +967,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp> }; template <> -struct _LIBCPP_TYPE_VIS_ONLY bit_not<void> +struct _LIBCPP_TEMPLATE_VIS bit_not<void> { template <class _Tp> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY @@ -971,7 +980,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_not<void> #endif template <class _Predicate> -class _LIBCPP_TYPE_VIS_ONLY unary_negate +class _LIBCPP_TEMPLATE_VIS unary_negate : public unary_function<typename _Predicate::argument_type, bool> { _Predicate __pred_; @@ -990,7 +999,7 @@ unary_negate<_Predicate> not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} template <class _Predicate> -class _LIBCPP_TYPE_VIS_ONLY binary_negate +class _LIBCPP_TEMPLATE_VIS binary_negate : public binary_function<typename _Predicate::first_argument_type, typename _Predicate::second_argument_type, bool> @@ -1011,8 +1020,9 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY binary_negate<_Predicate> not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) template <class __Operation> -class _LIBCPP_TYPE_VIS_ONLY binder1st +class _LIBCPP_TEMPLATE_VIS binder1st : public unary_function<typename __Operation::second_argument_type, typename __Operation::result_type> { @@ -1038,7 +1048,7 @@ bind1st(const __Operation& __op, const _Tp& __x) {return binder1st<__Operation>(__op, __x);} template <class __Operation> -class _LIBCPP_TYPE_VIS_ONLY binder2nd +class _LIBCPP_TEMPLATE_VIS binder2nd : public unary_function<typename __Operation::first_argument_type, typename __Operation::result_type> { @@ -1064,7 +1074,7 @@ bind2nd(const __Operation& __op, const _Tp& __x) {return binder2nd<__Operation>(__op, __x);} template <class _Arg, class _Result> -class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function +class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function : public unary_function<_Arg, _Result> { _Result (*__f_)(_Arg); @@ -1082,7 +1092,7 @@ ptr_fun(_Result (*__f)(_Arg)) {return pointer_to_unary_function<_Arg,_Result>(__f);} template <class _Arg1, class _Arg2, class _Result> -class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function +class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function : public binary_function<_Arg1, _Arg2, _Result> { _Result (*__f_)(_Arg1, _Arg2); @@ -1100,7 +1110,7 @@ ptr_fun(_Result (*__f)(_Arg1,_Arg2)) {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} template<class _Sp, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp> +class _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp> { _Sp (_Tp::*__p_)(); public: @@ -1111,7 +1121,7 @@ public: }; template<class _Sp, class _Tp, class _Ap> -class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> +class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> { _Sp (_Tp::*__p_)(_Ap); public: @@ -1134,7 +1144,7 @@ mem_fun(_Sp (_Tp::*__f)(_Ap)) {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} template<class _Sp, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp> +class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp> { _Sp (_Tp::*__p_)(); public: @@ -1145,7 +1155,7 @@ public: }; template<class _Sp, class _Tp, class _Ap> -class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> +class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> { _Sp (_Tp::*__p_)(_Ap); public: @@ -1168,7 +1178,7 @@ mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} template <class _Sp, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp> +class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp> { _Sp (_Tp::*__p_)() const; public: @@ -1179,7 +1189,7 @@ public: }; template <class _Sp, class _Tp, class _Ap> -class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> +class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> { _Sp (_Tp::*__p_)(_Ap) const; public: @@ -1202,7 +1212,7 @@ mem_fun(_Sp (_Tp::*__f)(_Ap) const) {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} template <class _Sp, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp> +class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp> { _Sp (_Tp::*__p_)() const; public: @@ -1213,7 +1223,7 @@ public: }; template <class _Sp, class _Tp, class _Ap> -class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t +class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> { _Sp (_Tp::*__p_)(_Ap) const; @@ -1235,6 +1245,7 @@ inline _LIBCPP_INLINE_VISIBILITY const_mem_fun1_ref_t<_Sp,_Tp,_Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} +#endif //////////////////////////////////////////////////////////////////////////////// // MEMFUN @@ -1253,7 +1264,7 @@ private: public: _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG // invoke template <class... _ArgTypes> _LIBCPP_INLINE_VISIBILITY @@ -1380,9 +1391,25 @@ mem_fn(_Rp _Tp::* __pm) _NOEXCEPT class _LIBCPP_EXCEPTION_ABI bad_function_call : public exception { +#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +public: + virtual ~bad_function_call() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#endif }; -template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_bad_function_call() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_function_call(); +#else + _VSTD::abort(); +#endif +} + +template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined namespace __function { @@ -1427,7 +1454,7 @@ bool __not_null(function<_Fp> const& __f) { return !!__f; } } // namespace __function -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG namespace __function { @@ -1558,7 +1585,7 @@ __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT } // __function template<class _Rp, class ..._ArgTypes> -class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> +class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> { @@ -1570,9 +1597,11 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> return reinterpret_cast<__base*>(p); } - template <class _Fp, bool = !is_same<_Fp, function>::value && - __invokable<_Fp&, _ArgTypes...>::value> - struct __callable; + template <class _Fp, bool = __lazy_and< + integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>, + __invokable<_Fp&, _ArgTypes...> + >::value> + struct __callable; template <class _Fp> struct __callable<_Fp, true> { @@ -1585,6 +1614,9 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> { static const bool value = false; }; + + template <class _Fp> + using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type; public: typedef _Rp result_type; @@ -1595,13 +1627,10 @@ public: function(nullptr_t) _NOEXCEPT : __f_(0) {} function(const function&); function(function&&) _NOEXCEPT; - template<class _Fp> - function(_Fp, typename enable_if - < - __callable<_Fp>::value && - !is_same<_Fp, function>::value - >::type* = 0); + template<class _Fp, class = _EnableIfCallable<_Fp>> + function(_Fp); +#if _LIBCPP_STD_VER <= 14 template<class _Alloc> _LIBCPP_INLINE_VISIBILITY function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} @@ -1612,21 +1641,15 @@ public: function(allocator_arg_t, const _Alloc&, const function&); template<class _Alloc> function(allocator_arg_t, const _Alloc&, function&&); - template<class _Fp, class _Alloc> - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if<__callable<_Fp>::value>::type* = 0); + template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>> + function(allocator_arg_t, const _Alloc& __a, _Fp __f); +#endif function& operator=(const function&); function& operator=(function&&) _NOEXCEPT; function& operator=(nullptr_t) _NOEXCEPT; - template<class _Fp> - typename enable_if - < - __callable<typename decay<_Fp>::type>::value && - !is_same<typename remove_reference<_Fp>::type, function>::value, - function& - >::type - operator=(_Fp&&); + template<class _Fp, class = _EnableIfCallable<_Fp>> + function& operator=(_Fp&&); ~function(); @@ -1675,6 +1698,7 @@ function<_Rp(_ArgTypes...)>::function(const function& __f) __f_ = __f.__f_->__clone(); } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> template <class _Alloc> function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, @@ -1690,6 +1714,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, else __f_ = __f.__f_->__clone(); } +#endif template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT @@ -1708,6 +1733,7 @@ function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT } } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> template <class _Alloc> function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, @@ -1726,15 +1752,11 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, __f.__f_ = 0; } } +#endif template<class _Rp, class ..._ArgTypes> -template <class _Fp> -function<_Rp(_ArgTypes...)>::function(_Fp __f, - typename enable_if - < - __callable<_Fp>::value && - !is_same<_Fp, function>::value - >::type*) +template <class _Fp, class> +function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(0) { if (__function::__not_null(__f)) @@ -1756,10 +1778,10 @@ function<_Rp(_ArgTypes...)>::function(_Fp __f, } } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> -template <class _Fp, class _Alloc> -function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if<__callable<_Fp>::value>::type*) +template <class _Fp, class _Alloc, class> +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; @@ -1782,6 +1804,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _ } } } +#endif template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>& @@ -1828,13 +1851,8 @@ function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT } template<class _Rp, class ..._ArgTypes> -template <class _Fp> -typename enable_if -< - 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 +template <class _Fp, class> +function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) { function(_VSTD::forward<_Fp>(__f)).swap(*this); @@ -1854,6 +1872,8 @@ template<class _Rp, class ..._ArgTypes> void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { + if (_VSTD::addressof(__f) == this) + return; if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -1891,10 +1911,8 @@ template<class _Rp, class ..._ArgTypes> _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); } @@ -1915,8 +1933,8 @@ _Tp* function<_Rp(_ArgTypes...)>::target() _NOEXCEPT { if (__f_ == 0) - return (_Tp*)0; - return (_Tp*)__f_->target(typeid(_Tp)); + return nullptr; + return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); } template<class _Rp, class ..._ArgTypes> @@ -1925,7 +1943,7 @@ const _Tp* function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT { if (__f_ == 0) - return (const _Tp*)0; + return nullptr; return (const _Tp*)__f_->target(typeid(_Tp)); } @@ -1957,7 +1975,7 @@ void swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT {return __x.swap(__y);} -#else // _LIBCPP_HAS_NO_VARIADICS +#else // _LIBCPP_CXX03_LANG #include <__functional_03> @@ -1968,13 +1986,23 @@ swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCE //============================================================================== template<class _Tp> struct __is_bind_expression : public false_type {}; -template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression +template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; +#endif + template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; -template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder +template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder : public __is_placeholder<typename remove_cv<_Tp>::type> {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; +#endif + namespace placeholders { @@ -1992,16 +2020,16 @@ _LIBCPP_FUNC_VIS extern const __ph<8> _8; _LIBCPP_FUNC_VIS extern const __ph<9> _9; _LIBCPP_FUNC_VIS extern const __ph<10> _10; #else -constexpr __ph<1> _1{}; -constexpr __ph<2> _2{}; -constexpr __ph<3> _3{}; -constexpr __ph<4> _4{}; -constexpr __ph<5> _5{}; -constexpr __ph<6> _6{}; -constexpr __ph<7> _7{}; -constexpr __ph<8> _8{}; -constexpr __ph<9> _9{}; -constexpr __ph<10> _10{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; +/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) } // placeholders @@ -2011,7 +2039,7 @@ struct __is_placeholder<placeholders::__ph<_Np> > : public integral_constant<int, _Np> {}; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Uj> inline _LIBCPP_INLINE_VISIBILITY @@ -2188,7 +2216,7 @@ typename __bind_return<_Fp, _BoundArgs, _Args>::type __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, _Args&& __args) { - return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); + return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); } template<class _Fp, class ..._BoundArgs> @@ -2204,36 +2232,6 @@ private: typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; public: -#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - - _LIBCPP_INLINE_VISIBILITY - __bind(const __bind& __b) - : __f_(__b.__f_), - __bound_args_(__b.__bound_args_) {} - - _LIBCPP_INLINE_VISIBILITY - __bind& operator=(const __bind& __b) - { - __f_ = __b.__f_; - __bound_args_ = __b.__bound_args_; - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __bind(__bind&& __b) - : __f_(_VSTD::move(__b.__f_)), - __bound_args_(_VSTD::move(__b.__bound_args_)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind& operator=(__bind&& __b) - { - __f_ = _VSTD::move(__b.__f_); - __bound_args_ = _VSTD::move(__b.__bound_args_); - return *this; - } - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - template <class _Gp, class ..._BA, class = typename enable_if < @@ -2251,7 +2249,7 @@ public: typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type operator()(_Args&& ...__args) { - return __apply_functor(__f_, __bound_args_, __indices(), + return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); } @@ -2260,7 +2258,7 @@ public: typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type operator()(_Args&& ...__args) const { - return __apply_functor(__f_, __bound_args_, __indices(), + return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); } }; @@ -2278,31 +2276,6 @@ class __bind_r public: typedef _Rp result_type; -#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - - _LIBCPP_INLINE_VISIBILITY - __bind_r(const __bind_r& __b) - : base(_VSTD::forward<const base&>(__b)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind_r& operator=(const __bind_r& __b) - { - base::operator=(_VSTD::forward<const base&>(__b)); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __bind_r(__bind_r&& __b) - : base(_VSTD::forward<base>(__b)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind_r& operator=(__bind_r&& __b) - { - base::operator=(_VSTD::forward<base>(__b)); - return *this; - } - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS template <class _Gp, class ..._BA, class = typename enable_if @@ -2366,241 +2339,12 @@ bind(_Fp&& __f, _BoundArgs&&... __bound_args) return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); } -#endif // _LIBCPP_HAS_NO_VARIADICS - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<bool> - : public unary_function<bool, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<char> - : public unary_function<char, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> - : public unary_function<signed char, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> - : public unary_function<unsigned char, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t> - : public unary_function<char16_t, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t> - : public unary_function<char32_t, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t> - : public unary_function<wchar_t, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<short> - : public unary_function<short, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> - : public unary_function<unsigned short, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<int> - : public unary_function<int, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> - : public unary_function<unsigned int, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<long> - : public unary_function<long, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> - : public unary_function<unsigned long, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<long long> - : public __scalar_hash<long long> -{ -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> - : public __scalar_hash<unsigned long long> -{ -}; - -#ifndef _LIBCPP_HAS_NO_INT128 - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t> - : public __scalar_hash<__int128_t> -{ -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t> - : public __scalar_hash<__uint128_t> -{ -}; - -#endif - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<float> - : public __scalar_hash<float> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(float __v) const _NOEXCEPT - { - // -0.0 and 0.0 should return same hash - if (__v == 0) - return 0; - return __scalar_hash<float>::operator()(__v); - } -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<double> - : public __scalar_hash<double> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(double __v) const _NOEXCEPT - { - // -0.0 and 0.0 should return same hash - if (__v == 0) - return 0; - return __scalar_hash<double>::operator()(__v); - } -}; - -template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<long double> - : public __scalar_hash<long double> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(long double __v) const _NOEXCEPT - { - // -0.0 and 0.0 should return same hash - if (__v == 0) - return 0; -#if defined(__i386__) - // Zero out padding bits - union - { - long double __t; - struct - { - size_t __a; - size_t __b; - size_t __c; - size_t __d; - } __s; - } __u; - __u.__s.__a = 0; - __u.__s.__b = 0; - __u.__s.__c = 0; - __u.__s.__d = 0; - __u.__t = __v; - return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; -#elif defined(__x86_64__) - // Zero out padding bits - union - { - long double __t; - struct - { - size_t __a; - size_t __b; - } __s; - } __u; - __u.__s.__a = 0; - __u.__s.__b = 0; - __u.__t = __v; - return __u.__s.__a ^ __u.__s.__b; -#else - return __scalar_hash<long double>::operator()(__v); -#endif - } -}; - -#if _LIBCPP_STD_VER > 11 -template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY hash - : public unary_function<_Tp, size_t> -{ - static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); - - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - typedef typename underlying_type<_Tp>::type type; - return hash<type>{}(static_cast<type>(__v)); - } -}; -#endif - +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 +#define __cpp_lib_invoke 201411 + template <class _Fn, class ..._Args> result_of_t<_Fn&&(_Args&&...)> invoke(_Fn&& __f, _Args&&... __args) @@ -2610,7 +2354,7 @@ invoke(_Fn&& __f, _Args&&... __args) } template <class _DecayFunc> -class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp { +class _LIBCPP_TEMPLATE_VIS __not_fn_imp { _DecayFunc __fd; public: @@ -2620,30 +2364,30 @@ public: _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) & noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) && noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) const& noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) const&& noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } private: template <class _RawFunc, diff --git a/lib/libcxx/include/future b/lib/libcxx/include/future index 936060e173b..a7c28a4746c 100644 --- a/lib/libcxx/include/future +++ b/lib/libcxx/include/future @@ -50,7 +50,7 @@ class future_error { public: future_error(error_code ec); // exposition only - + explicit future_error(future_errc); // C++17 const error_code& code() const noexcept; const char* what() const noexcept; }; @@ -156,7 +156,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; - shared_future<R> share(); + shared_future<R> share() noexcept; // retrieving the value R get(); @@ -183,7 +183,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; - shared_future<R&> share(); + shared_future<R&> share() noexcept; // retrieving the value R& get(); @@ -210,7 +210,7 @@ public: ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; - shared_future<void> share(); + shared_future<void> share() noexcept; // retrieving the value void get(); @@ -391,11 +391,11 @@ _LIBCPP_DECLARE_STRONG_ENUM(future_errc) _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc> : public true_type {}; +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {}; #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<future_errc::__lx> : public true_type { }; +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type { }; #endif //enum class launch @@ -499,30 +499,36 @@ make_error_condition(future_errc __e) _NOEXCEPT return error_condition(static_cast<int>(__e), future_category()); } -class _LIBCPP_EXCEPTION_ABI future_error +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error : public logic_error { error_code __ec_; public: future_error(error_code __ec); - +#if _LIBCPP_STD_VERS > 14 + explicit future_error(future_errc _Ev) : logic_error(), __ec_(make_error_code(_Ev)) {} +#endif _LIBCPP_INLINE_VISIBILITY const error_code& code() const _NOEXCEPT {return __ec_;} virtual ~future_error() _NOEXCEPT; }; -inline _LIBCPP_ALWAYS_INLINE +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +#ifndef _LIBCPP_NO_EXCEPTIONS +_LIBCPP_AVAILABILITY_FUTURE_ERROR +#endif void __throw_future_error(future_errc _Ev) { #ifndef _LIBCPP_NO_EXCEPTIONS throw future_error(make_error_code(_Ev)); #else - assert(!"future_error"); + ((void)_Ev); + _VSTD::abort(); #endif } -class _LIBCPP_TYPE_VIS __assoc_sub_state +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state : public __shared_count { protected: @@ -579,6 +585,7 @@ public: _LIBCPP_INLINE_VISIBILITY wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; @@ -608,7 +615,7 @@ __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) c } template <class _Rp> -class __assoc_state +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state : public __assoc_sub_state { typedef __assoc_sub_state base; @@ -648,6 +655,7 @@ __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT template <class _Rp> template <class _Arg> +_LIBCPP_AVAILABILITY_FUTURE void #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __assoc_state<_Rp>::set_value(_Arg&& __arg) @@ -703,7 +711,7 @@ __assoc_state<_Rp>::copy() } template <class _Rp> -class __assoc_state<_Rp&> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state<_Rp&> : public __assoc_sub_state { typedef __assoc_sub_state base; @@ -763,7 +771,7 @@ __assoc_state<_Rp&>::copy() } template <class _Rp, class _Alloc> -class __assoc_state_alloc +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; @@ -791,7 +799,7 @@ __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT } template <class _Rp, class _Alloc> -class __assoc_state_alloc<_Rp&, _Alloc> +class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc<_Rp&, _Alloc> : public __assoc_state<_Rp&> { typedef __assoc_state<_Rp&> base; @@ -817,7 +825,7 @@ __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT } template <class _Alloc> -class __assoc_sub_state_alloc +class _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state_alloc : public __assoc_sub_state { typedef __assoc_sub_state base; @@ -843,7 +851,7 @@ __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT } template <class _Rp, class _Fp> -class __deferred_assoc_state +class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; @@ -890,7 +898,7 @@ __deferred_assoc_state<_Rp, _Fp>::__execute() } template <class _Fp> -class __deferred_assoc_state<void, _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state<void, _Fp> : public __assoc_sub_state { typedef __assoc_sub_state base; @@ -938,7 +946,7 @@ __deferred_assoc_state<void, _Fp>::__execute() } template <class _Rp, class _Fp> -class __async_assoc_state +class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; @@ -993,7 +1001,7 @@ __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT } template <class _Fp> -class __async_assoc_state<void, _Fp> +class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state<void, _Fp> : public __assoc_sub_state { typedef __assoc_sub_state base; @@ -1048,12 +1056,12 @@ __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT base::__on_zero_shared(); } -template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY promise; -template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY shared_future; +template <class _Rp> class _LIBCPP_TEMPLATE_VIS promise; +template <class _Rp> class _LIBCPP_TEMPLATE_VIS shared_future; // future -template <class _Rp> class _LIBCPP_TYPE_VIS_ONLY future; +template <class _Rp> class _LIBCPP_TEMPLATE_VIS future; template <class _Rp, class _Fp> future<_Rp> @@ -1072,7 +1080,7 @@ __make_async_assoc_state(_Fp __f); #endif template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY future +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future { __assoc_state<_Rp>* __state_; @@ -1116,7 +1124,7 @@ public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY - shared_future<_Rp> share(); + shared_future<_Rp> share() _NOEXCEPT; // retrieving the value _Rp get(); @@ -1175,7 +1183,7 @@ future<_Rp>::get() } template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY future<_Rp&> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future<_Rp&> { __assoc_state<_Rp&>* __state_; @@ -1219,7 +1227,7 @@ public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY - shared_future<_Rp&> share(); + shared_future<_Rp&> share() _NOEXCEPT; // retrieving the value _Rp& get(); @@ -1273,7 +1281,7 @@ future<_Rp&>::get() } template <> -class _LIBCPP_TYPE_VIS future<void> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE future<void> { __assoc_sub_state* __state_; @@ -1317,7 +1325,7 @@ public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY - shared_future<void> share(); + shared_future<void> share() _NOEXCEPT; // retrieving the value void get(); @@ -1356,7 +1364,7 @@ swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT template <class _Callable> class packaged_task; template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY promise +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise { __assoc_state<_Rp>* __state_; @@ -1523,7 +1531,7 @@ promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) // promise<R&> template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY promise<_Rp&> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<_Rp&> { __assoc_state<_Rp&>* __state_; @@ -1659,7 +1667,7 @@ promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) // promise<void> template <> -class _LIBCPP_TYPE_VIS promise<void> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<void> { __assoc_sub_state* __state_; @@ -1671,6 +1679,7 @@ class _LIBCPP_TYPE_VIS promise<void> public: promise(); template <class _Allocator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS promise(allocator_arg_t, const _Allocator& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY @@ -1734,7 +1743,7 @@ swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT } template <class _Rp, class _Alloc> - struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<promise<_Rp>, _Alloc> + struct _LIBCPP_TEMPLATE_VIS uses_allocator<promise<_Rp>, _Alloc> : public true_type {}; #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -1744,7 +1753,7 @@ template <class _Rp, class _Alloc> template<class _Fp> class __packaged_task_base; template<class _Rp, class ..._ArgTypes> -class __packaged_task_base<_Rp(_ArgTypes...)> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_base<_Rp(_ArgTypes...)> { __packaged_task_base(const __packaged_task_base&); __packaged_task_base& operator=(const __packaged_task_base&); @@ -1762,7 +1771,7 @@ public: template<class _FD, class _Alloc, class _FB> class __packaged_task_func; template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> -class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __packaged_task_base<_Rp(_ArgTypes...)> { __compressed_pair<_Fp, _Alloc> __f_; @@ -1820,7 +1829,7 @@ __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... template <class _Callable> class __packaged_task_function; template<class _Rp, class ..._ArgTypes> -class __packaged_task_function<_Rp(_ArgTypes...)> +class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)> { typedef __packaged_task_base<_Rp(_ArgTypes...)> __base; typename aligned_storage<3*sizeof(void*)>::type __buf_; @@ -1995,7 +2004,7 @@ __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) cons } template<class _Rp, class ..._ArgTypes> -class _LIBCPP_TYPE_VIS_ONLY packaged_task<_Rp(_ArgTypes...)> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<_Rp(_ArgTypes...)> { public: typedef _Rp result_type; // extension @@ -2124,7 +2133,7 @@ packaged_task<_Rp(_ArgTypes...)>::reset() } template<class ..._ArgTypes> -class _LIBCPP_TYPE_VIS_ONLY packaged_task<void(_ArgTypes...)> +class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<void(_ArgTypes...)> { public: typedef void result_type; // extension @@ -2263,7 +2272,7 @@ swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT } template <class _Callable, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<packaged_task<_Callable>, _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc> : public true_type {}; template <class _Rp, class _Fp> @@ -2326,6 +2335,7 @@ inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, lau { return (int(__policy) & int(__value)) != 0; } template <class _Fp, class... _Args> +_LIBCPP_NODISCARD_AFTER_CXX17 future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> async(launch __policy, _Fp&& __f, _Args&&... __args) { @@ -2351,7 +2361,7 @@ async(launch __policy, _Fp&& __f, _Args&&... __args) } template <class _Fp, class... _Args> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type> async(_Fp&& __f, _Args&&... __args) { @@ -2364,7 +2374,7 @@ async(_Fp&& __f, _Args&&... __args) // shared_future template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY shared_future +class _LIBCPP_TEMPLATE_VIS shared_future { __assoc_state<_Rp>* __state_; @@ -2372,7 +2382,7 @@ public: _LIBCPP_INLINE_VISIBILITY shared_future() _NOEXCEPT : __state_(nullptr) {} _LIBCPP_INLINE_VISIBILITY - shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) + shared_future(const shared_future& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {if (__state_) __state_->__add_shared();} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY @@ -2383,7 +2393,7 @@ public: {__rhs.__state_ = nullptr;} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~shared_future(); - shared_future& operator=(const shared_future& __rhs); + shared_future& operator=(const shared_future& __rhs) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future& operator=(shared_future&& __rhs) _NOEXCEPT @@ -2427,7 +2437,7 @@ shared_future<_Rp>::~shared_future() template <class _Rp> shared_future<_Rp>& -shared_future<_Rp>::operator=(const shared_future& __rhs) +shared_future<_Rp>::operator=(const shared_future& __rhs) _NOEXCEPT { if (__rhs.__state_) __rhs.__state_->__add_shared(); @@ -2438,7 +2448,7 @@ shared_future<_Rp>::operator=(const shared_future& __rhs) } template <class _Rp> -class _LIBCPP_TYPE_VIS_ONLY shared_future<_Rp&> +class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&> { __assoc_state<_Rp&>* __state_; @@ -2512,7 +2522,7 @@ shared_future<_Rp&>::operator=(const shared_future& __rhs) } template <> -class _LIBCPP_TYPE_VIS shared_future<void> +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE shared_future<void> { __assoc_sub_state* __state_; @@ -2577,7 +2587,7 @@ swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT template <class _Rp> inline shared_future<_Rp> -future<_Rp>::share() +future<_Rp>::share() _NOEXCEPT { return shared_future<_Rp>(_VSTD::move(*this)); } @@ -2585,7 +2595,7 @@ future<_Rp>::share() template <class _Rp> inline shared_future<_Rp&> -future<_Rp&>::share() +future<_Rp&>::share() _NOEXCEPT { return shared_future<_Rp&>(_VSTD::move(*this)); } @@ -2594,7 +2604,7 @@ future<_Rp&>::share() inline shared_future<void> -future<void>::share() +future<void>::share() _NOEXCEPT { return shared_future<void>(_VSTD::move(*this)); } diff --git a/lib/libcxx/include/initializer_list b/lib/libcxx/include/initializer_list index 663e49b6ee4..8c234aaaab2 100644 --- a/lib/libcxx/include/initializer_list +++ b/lib/libcxx/include/initializer_list @@ -53,10 +53,10 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in namespace std // purposefully not versioned { -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _Ep> -class _LIBCPP_TYPE_VIS_ONLY initializer_list +class _LIBCPP_TEMPLATE_VIS initializer_list { const _Ep* __begin_; size_t __size_; @@ -111,7 +111,7 @@ end(initializer_list<_Ep> __il) _NOEXCEPT return __il.end(); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // !defined(_LIBCPP_CXX03_LANG) } // std diff --git a/lib/libcxx/include/inttypes.h b/lib/libcxx/include/inttypes.h index 5c5618bef88..058f54b5161 100644 --- a/lib/libcxx/include/inttypes.h +++ b/lib/libcxx/include/inttypes.h @@ -237,6 +237,13 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int #pragma GCC system_header #endif +/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed + for C++11 unless __STDC_FORMAT_MACROS is defined +*/ +#if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) +# define __STDC_FORMAT_MACROS +#endif + #include_next <inttypes.h> #ifdef __cplusplus diff --git a/lib/libcxx/include/iomanip b/lib/libcxx/include/iomanip index 9efcbe03d1a..a6bee736f45 100644 --- a/lib/libcxx/include/iomanip +++ b/lib/libcxx/include/iomanip @@ -44,6 +44,7 @@ template <class charT, class traits, class Allocator> */ #include <__config> +#include <__string> #include <istream> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -567,19 +568,6 @@ __quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _Char } -template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> > -struct __quoted_output_proxy -{ - _Iter __first; - _Iter __last; - _CharT __delim; - _CharT __escape; - - __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) - : __first(__f), __last(__l), __delim(__d), __escape(__e) {} - // This would be a nice place for a string_ref -}; - template <class _CharT, class _Traits, class _Iter> basic_ostream<_CharT, _Traits>& operator<<( basic_ostream<_CharT, _Traits>& __os, @@ -666,6 +654,15 @@ quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _Char { return __quoted(__s, __delim, __escape); } + +template <class _CharT, class _Traits> +__quoted_output_proxy<_CharT, const _CharT *, _Traits> +quoted (basic_string_view <_CharT, _Traits> __sv, + _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted_output_proxy<_CharT, const _CharT *, _Traits> + ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape ); +} #endif _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/ios b/lib/libcxx/include/ios index cbea478a74a..61d00b90ee0 100644 --- a/lib/libcxx/include/ios +++ b/lib/libcxx/include/ios @@ -393,11 +393,11 @@ _LIBCPP_DECLARE_STRONG_ENUM(io_errc) _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc> : public true_type { }; +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { }; #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc::__lx> : public true_type { }; +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { }; #endif _LIBCPP_FUNC_VIS @@ -572,8 +572,15 @@ ios_base::exceptions(iostate __iostate) clear(__rdstate_); } +#if defined(_LIBCPP_CXX03_LANG) +struct _LIBCPP_TYPE_VIS __cxx03_bool { + typedef void (__cxx03_bool::*__bool_type)(); + void __true_value() {} +}; +#endif + template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_ios +class _LIBCPP_TEMPLATE_VIS basic_ios : public ios_base { public: @@ -585,9 +592,19 @@ public: typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; + // __true_value will generate undefined references when linking unless + // we give it internal linkage. + +#if defined(_LIBCPP_CXX03_LANG) _LIBCPP_ALWAYS_INLINE - _LIBCPP_EXPLICIT - operator bool() const {return !fail();} + operator __cxx03_bool::__bool_type() const { + return !fail() ? &__cxx03_bool::__true_value : nullptr; + } +#else + _LIBCPP_ALWAYS_INLINE + _LIBCPP_EXPLICIT operator bool() const {return !fail();} +#endif + _LIBCPP_ALWAYS_INLINE bool operator!() const {return fail();} _LIBCPP_ALWAYS_INLINE iostate rdstate() const {return ios_base::rdstate();} _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);} @@ -640,7 +657,7 @@ protected: _LIBCPP_INLINE_VISIBILITY void move(basic_ios& __rhs); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_ALWAYS_INLINE void move(basic_ios&& __rhs) {move(__rhs);} #endif diff --git a/lib/libcxx/include/iosfwd b/lib/libcxx/include/iosfwd index e4149ef2237..d4384859e41 100644 --- a/lib/libcxx/include/iosfwd +++ b/lib/libcxx/include/iosfwd @@ -97,47 +97,47 @@ _LIBCPP_BEGIN_NAMESPACE_STD class _LIBCPP_TYPE_VIS ios_base; -template<class _CharT> struct _LIBCPP_TYPE_VIS_ONLY char_traits; -template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY allocator; +template<class _CharT> struct _LIBCPP_TEMPLATE_VIS char_traits; +template<class _Tp> class _LIBCPP_TEMPLATE_VIS allocator; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_ios; + class _LIBCPP_TEMPLATE_VIS basic_ios; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_streambuf; + class _LIBCPP_TEMPLATE_VIS basic_streambuf; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_istream; + class _LIBCPP_TEMPLATE_VIS basic_istream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_ostream; + class _LIBCPP_TEMPLATE_VIS basic_ostream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_iostream; + class _LIBCPP_TEMPLATE_VIS basic_iostream; template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_stringbuf; + class _LIBCPP_TEMPLATE_VIS basic_stringbuf; template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_istringstream; + class _LIBCPP_TEMPLATE_VIS basic_istringstream; template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_ostringstream; + class _LIBCPP_TEMPLATE_VIS basic_ostringstream; template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_stringstream; + class _LIBCPP_TEMPLATE_VIS basic_stringstream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_filebuf; + class _LIBCPP_TEMPLATE_VIS basic_filebuf; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_ifstream; + class _LIBCPP_TEMPLATE_VIS basic_ifstream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_ofstream; + class _LIBCPP_TEMPLATE_VIS basic_ofstream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_fstream; + class _LIBCPP_TEMPLATE_VIS basic_fstream; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator; + class _LIBCPP_TEMPLATE_VIS istreambuf_iterator; template <class _CharT, class _Traits = char_traits<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator; + class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator; typedef basic_ios<char> ios; typedef basic_ios<wchar_t> wios; @@ -172,7 +172,7 @@ typedef basic_ifstream<wchar_t> wifstream; typedef basic_ofstream<wchar_t> wofstream; typedef basic_fstream<wchar_t> wfstream; -template <class _State> class _LIBCPP_TYPE_VIS_ONLY fpos; +template <class _State> class _LIBCPP_TEMPLATE_VIS fpos; typedef fpos<mbstate_t> streampos; typedef fpos<mbstate_t> wstreampos; #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -190,14 +190,14 @@ typedef long long streamoff; // for char_traits in <string> template <class _CharT, // for <stdexcept> class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> > - class _LIBCPP_TYPE_VIS_ONLY basic_string; + class _LIBCPP_TEMPLATE_VIS basic_string; typedef basic_string<char, char_traits<char>, allocator<char> > string; typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring; // Include other forward declarations here template <class _Tp, class _Alloc = allocator<_Tp> > -class _LIBCPP_TYPE_VIS_ONLY vector; +class _LIBCPP_TEMPLATE_VIS vector; _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/istream b/lib/libcxx/include/istream index ee694003a3d..5c73df38f65 100644 --- a/lib/libcxx/include/istream +++ b/lib/libcxx/include/istream @@ -162,16 +162,18 @@ template <class charT, class traits, class T> #include <__config> #include <ostream> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_istream +class _LIBCPP_TEMPLATE_VIS basic_istream : virtual public basic_ios<_CharT, _Traits> { streamsize __gc_; @@ -184,39 +186,49 @@ public: typedef typename traits_type::off_type off_type; // 27.7.1.1.1 Constructor/destructor: - explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0) + { this->init(__sb); } virtual ~basic_istream(); protected: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_istream(basic_istream&& __rhs); -#endif + // 27.7.1.1.2 Assign/swap: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY + inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator=(basic_istream&& __rhs); #endif - void swap(basic_istream& __rhs); -#if _LIBCPP_STD_VER > 11 -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void swap(basic_istream& __rhs) { + _VSTD::swap(__gc_, __rhs.__gc_); + basic_ios<char_type, traits_type>::swap(__rhs); + } + +#ifndef _LIBCPP_CXX03_LANG basic_istream (const basic_istream& __rhs) = delete; basic_istream& operator=(const basic_istream& __rhs) = delete; -#else - basic_istream (const basic_istream& __rhs); // not defined - basic_istream& operator=(const basic_istream& __rhs); // not defined -#endif #endif public: // 27.7.1.1.3 Prefix/suffix: - class _LIBCPP_TYPE_VIS_ONLY sentry; + class _LIBCPP_TEMPLATE_VIS sentry; // 27.7.1.2 Formatted input: - basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) + { return __pf(*this); } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& operator>>(basic_ios<char_type, traits_type>& - (*__pf)(basic_ios<char_type, traits_type>&)); - basic_istream& operator>>(ios_base& (*__pf)(ios_base&)); + (*__pf)(basic_ios<char_type, traits_type>&)) + { __pf(*this); return *this; } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) + { __pf(*this); return *this; } + basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb); basic_istream& operator>>(bool& __n); basic_istream& operator>>(short& __n); @@ -236,13 +248,31 @@ public: _LIBCPP_INLINE_VISIBILITY streamsize gcount() const {return __gc_;} int_type get(); - basic_istream& get(char_type& __c); - basic_istream& get(char_type* __s, streamsize __n); + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& get(char_type& __c) { + int_type __ch = get(); + if (__ch != traits_type::eof()) + __c = traits_type::to_char_type(__ch); + return *this; + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& get(char_type* __s, streamsize __n) + { return get(__s, __n, this->widen('\n')); } + basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); - basic_istream& get(basic_streambuf<char_type, traits_type>& __sb); + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) + { return get(__sb, this->widen('\n')); } + basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm); - basic_istream& getline(char_type* __s, streamsize __n); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_istream& getline(char_type* __s, streamsize __n) + { return getline(__s, __n, this->widen('\n')); } + basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); @@ -260,7 +290,7 @@ public: }; template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_istream<_CharT, _Traits>::sentry +class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry { bool __ok_; @@ -303,18 +333,9 @@ basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& _ __is.setstate(ios_base::failbit); } -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb) - : __gc_(0) -{ - this->init(__sb); -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) { @@ -323,7 +344,6 @@ basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) { @@ -331,7 +351,7 @@ basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> basic_istream<_CharT, _Traits>::~basic_istream() @@ -339,15 +359,6 @@ basic_istream<_CharT, _Traits>::~basic_istream() } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs) -{ - _VSTD::swap(__gc_, __rhs.__gc_); - basic_ios<char_type, traits_type>::swap(__rhs); -} - -template <class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) { @@ -724,33 +735,6 @@ basic_istream<_CharT, _Traits>::operator>>(int& __n) return *this; } -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&)) -{ - return __pf(*this); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>& - (*__pf)(basic_ios<char_type, traits_type>&)) -{ - __pf(*this); - return *this; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&)) -{ - __pf(*this); - return *this; -} - template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) @@ -947,17 +931,6 @@ basic_istream<_CharT, _Traits>::get() } template<class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::get(char_type& __c) -{ - int_type __ch = get(); - if (__ch != traits_type::eof()) - __c = traits_type::to_char_type(__ch); - return *this; -} - -template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) { @@ -1006,14 +979,6 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __ } template<class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n) -{ - return get(__s, __n, this->widen('\n')); -} - -template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm) @@ -1068,14 +1033,6 @@ basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __s } template<class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb) -{ - return get(__sb, this->widen('\n')); -} - -template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) { @@ -1112,16 +1069,18 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ this->rdbuf()->sbumpc(); ++__gc_; } - if (__n > 0) - *__s = char_type(); if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); } + if (__n > 0) + *__s = char_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { + if (__n > 0) + *__s = char_type(); this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS @@ -1129,14 +1088,6 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ } template<class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n) -{ - return getline(__s, __n, this->widen('\n')); -} - -template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) { @@ -1476,21 +1427,21 @@ ws(basic_istream<_CharT, _Traits>& __is) return __is; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Tp> inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& -operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) +operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) { - __is >> __x; + __is >> _VSTD::forward<_Tp>(__x); return __is; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_iostream +class _LIBCPP_TEMPLATE_VIS basic_iostream : public basic_istream<_CharT, _Traits>, public basic_ostream<_CharT, _Traits> { @@ -1503,41 +1454,36 @@ public: typedef typename traits_type::off_type off_type; // constructor/destructor - explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb) + : basic_istream<_CharT, _Traits>(__sb) + {} + virtual ~basic_iostream(); protected: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_iostream(basic_iostream&& __rhs); -#endif // assign/swap -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY + inline _LIBCPP_INLINE_VISIBILITY basic_iostream& operator=(basic_iostream&& __rhs); #endif - void swap(basic_iostream& __rhs); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void swap(basic_iostream& __rhs) + { basic_istream<char_type, traits_type>::swap(__rhs); } public: }; -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb) - : basic_istream<_CharT, _Traits>(__sb) -{ -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) { } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_iostream<_CharT, _Traits>& basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) { @@ -1545,21 +1491,13 @@ basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> basic_iostream<_CharT, _Traits>::~basic_iostream() { } -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs) -{ - basic_istream<char_type, traits_type>::swap(__rhs); -} - template<class _CharT, class _Traits, class _Allocator> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, @@ -1670,7 +1608,7 @@ getline(basic_istream<_CharT, _Traits>& __is, return getline(__is, __str, __is.widen('\n')); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -1690,7 +1628,7 @@ getline(basic_istream<_CharT, _Traits>&& __is, return getline(__is, __str, __is.widen('\n')); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, size_t _Size> basic_istream<_CharT, _Traits>& @@ -1705,7 +1643,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) { basic_string<_CharT, _Traits> __str; const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); - streamsize __c = 0; + size_t __c = 0; ios_base::iostate __err = ios_base::goodbit; _CharT __zero = __ct.widen('0'); _CharT __one = __ct.widen('1'); @@ -1741,10 +1679,14 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) return __is; } -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<char>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_istream<wchar_t>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_iostream<char>) +#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>) +#endif _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_ISTREAM diff --git a/lib/libcxx/include/iterator b/lib/libcxx/include/iterator index 0caabbb2ea1..8b887db037b 100644 --- a/lib/libcxx/include/iterator +++ b/lib/libcxx/include/iterator @@ -37,16 +37,6 @@ struct iterator_traits<T*> typedef random_access_iterator_tag iterator_category; }; -template<class T> -struct iterator_traits<const T*> -{ - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef const T* pointer; - typedef const T& reference; - typedef random_access_iterator_tag iterator_category; -}; - template<class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> struct iterator @@ -64,14 +54,23 @@ struct forward_iterator_tag : public input_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {}; +// 27.4.3, iterator operations // extension: second argument not conforming to C++03 -template <class InputIterator> -void advance(InputIterator& i, +template <class InputIterator> // constexpr in C++17 + constexpr void advance(InputIterator& i, typename iterator_traits<InputIterator>::difference_type n); -template <class InputIterator> -typename iterator_traits<InputIterator>::difference_type -distance(InputIterator first, InputIterator last); +template <class InputIterator> // constexpr in C++17 + constexpr typename iterator_traits<InputIterator>::difference_type + distance(InputIterator first, InputIterator last); + +template <class InputIterator> // constexpr in C++17 + constexpr InputIterator next(InputIterator x, +typename iterator_traits<InputIterator>::difference_type n = 1); + +template <class BidirectionalIterator> // constexpr in C++17 + constexpr BidirectionalIterator prev(BidirectionalIterator x, + typename iterator_traits<BidirectionalIterator>::difference_type n = 1); template <class Iterator> class reverse_iterator @@ -89,57 +88,60 @@ public: typedef typename iterator_traits<Iterator>::reference reference; typedef typename iterator_traits<Iterator>::pointer pointer; - reverse_iterator(); - explicit reverse_iterator(Iterator x); - template <class U> reverse_iterator(const reverse_iterator<U>& u); - Iterator base() const; - reference operator*() const; - pointer operator->() const; - reverse_iterator& operator++(); - reverse_iterator operator++(int); - reverse_iterator& operator--(); - reverse_iterator operator--(int); - reverse_iterator operator+ (difference_type n) const; - reverse_iterator& operator+=(difference_type n); - reverse_iterator operator- (difference_type n) const; - reverse_iterator& operator-=(difference_type n); - reference operator[](difference_type n) const; + constexpr reverse_iterator(); + constexpr explicit reverse_iterator(Iterator x); + template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); + template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); + constexpr Iterator base() const; + constexpr reference operator*() const; + constexpr pointer operator->() const; + constexpr reverse_iterator& operator++(); + constexpr reverse_iterator operator++(int); + constexpr reverse_iterator& operator--(); + constexpr reverse_iterator operator--(int); + constexpr reverse_iterator operator+ (difference_type n) const; + constexpr reverse_iterator& operator+=(difference_type n); + constexpr reverse_iterator operator- (difference_type n) const; + constexpr reverse_iterator& operator-=(difference_type n); + constexpr reference operator[](difference_type n) const; }; template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -auto +constexpr auto operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) --> decltype(__y.base() - __x.base()); +-> decltype(__y.base() - __x.base()); // constexpr in C++17 template <class Iterator> -reverse_iterator<Iterator> -operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x); +constexpr reverse_iterator<Iterator> +operator+(typename reverse_iterator<Iterator>::difference_type n, + const reverse_iterator<Iterator>& x); // constexpr in C++17 -template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14 +template <class Iterator> +constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 template <class Container> class back_insert_iterator @@ -216,61 +218,64 @@ public: typedef typename iterator_traits<Iterator>::iterator_category iterator_category; typedef value_type&& reference; - move_iterator(); - explicit move_iterator(Iterator i); - template <class U> move_iterator(const move_iterator<U>& u); - template <class U> move_iterator& operator=(const move_iterator<U>& u); - iterator_type base() const; - reference operator*() const; - pointer operator->() const; - move_iterator& operator++(); - move_iterator operator++(int); - move_iterator& operator--(); - move_iterator operator--(int); - move_iterator operator+(difference_type n) const; - move_iterator& operator+=(difference_type n); - move_iterator operator-(difference_type n) const; - move_iterator& operator-=(difference_type n); - unspecified operator[](difference_type n) const; + constexpr move_iterator(); // all the constexprs are in C++17 + constexpr explicit move_iterator(Iterator i); + template <class U> + constexpr move_iterator(const move_iterator<U>& u); + template <class U> + constexpr move_iterator& operator=(const move_iterator<U>& u); + constexpr iterator_type base() const; + constexpr reference operator*() const; + constexpr pointer operator->() const; + constexpr move_iterator& operator++(); + constexpr move_iterator operator++(int); + constexpr move_iterator& operator--(); + constexpr move_iterator operator--(int); + constexpr move_iterator operator+(difference_type n) const; + constexpr move_iterator& operator+=(difference_type n); + constexpr move_iterator operator-(difference_type n) const; + constexpr move_iterator& operator-=(difference_type n); + constexpr unspecified operator[](difference_type n) const; private: Iterator current; // exposition only }; template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -bool +constexpr bool // constexpr in C++17 operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); template <class Iterator1, class Iterator2> -auto +constexpr auto // constexpr in C++17 operator-(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); template <class Iterator> -move_iterator<Iterator> operator+(typename move_iterator<Iterator>::difference_type n, - const move_iterator<Iterator>& x); +constexpr move_iterator<Iterator> operator+( // constexpr in C++17 + typename move_iterator<Iterator>::difference_type n, + const move_iterator<Iterator>& x); -template <class Iterator> -move_iterator<Iterator> make_move_iterator(const Iterator& i); +template <class Iterator> // constexpr in C++17 +constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> @@ -372,25 +377,25 @@ public: bool failed() const noexcept; }; -template <class C> auto begin(C& c) -> decltype(c.begin()); -template <class C> auto begin(const C& c) -> decltype(c.begin()); -template <class C> auto end(C& c) -> decltype(c.end()); -template <class C> auto end(const C& c) -> decltype(c.end()); -template <class T, size_t N> T* begin(T (&array)[N]); -template <class T, size_t N> T* end(T (&array)[N]); - -template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14 -template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14 -template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14 -template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14 -template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14 -template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14 -template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14 -template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14 -template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14 -template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14 -template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 -template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14 +template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); +template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); +template <class C> constexpr auto end(C& c) -> decltype(c.end()); +template <class C> constexpr auto end(const C& c) -> decltype(c.end()); +template <class T, size_t N> constexpr T* begin(T (&array)[N]); +template <class T, size_t N> constexpr T* end(T (&array)[N]); + +template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 +template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 +template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 +template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 +template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 +template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 // 24.8, container access: template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 @@ -425,11 +430,11 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept; _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {}; -struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {}; -struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {}; -struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {}; -struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; +struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; template <class _Tp> struct __has_iterator_category @@ -472,14 +477,14 @@ struct __iterator_traits<_Iter, true> // the client expects instead of failing at compile time. template <class _Iter> -struct _LIBCPP_TYPE_VIS_ONLY iterator_traits +struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {}; template<class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*> +struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> { typedef ptrdiff_t difference_type; - typedef typename remove_const<_Tp>::type value_type; + typedef typename remove_cv<_Tp>::type value_type; typedef _Tp* pointer; typedef _Tp& reference; typedef random_access_iterator_tag iterator_category; @@ -508,12 +513,12 @@ struct __is_random_access_iterator : public __has_iterator_category_convertible_ template <class _Tp> struct __is_exactly_input_iterator : public integral_constant<bool, - __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && - !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; + __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && + !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; template<class _Category, class _Tp, class _Distance = ptrdiff_t, class _Pointer = _Tp*, class _Reference = _Tp&> -struct _LIBCPP_TYPE_VIS_ONLY iterator +struct _LIBCPP_TEMPLATE_VIS iterator { typedef _Tp value_type; typedef _Distance difference_type; @@ -523,7 +528,7 @@ struct _LIBCPP_TYPE_VIS_ONLY iterator }; template <class _InputIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) { @@ -532,7 +537,7 @@ void __advance(_InputIter& __i, } template <class _BiDirIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) { @@ -545,7 +550,7 @@ void __advance(_BiDirIter& __i, } template <class _RandIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) { @@ -553,7 +558,7 @@ void __advance(_RandIter& __i, } template <class _InputIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n) { @@ -561,7 +566,7 @@ void advance(_InputIter& __i, } template <class _InputIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_InputIter>::difference_type __distance(_InputIter __first, _InputIter __last, input_iterator_tag) { @@ -572,7 +577,7 @@ __distance(_InputIter __first, _InputIter __last, input_iterator_tag) } template <class _RandIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_RandIter>::difference_type __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) { @@ -580,7 +585,7 @@ __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) } template <class _InputIter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_InputIter>::difference_type distance(_InputIter __first, _InputIter __last) { @@ -588,29 +593,43 @@ distance(_InputIter __first, _InputIter __last) } template <class _InputIter> -inline _LIBCPP_INLINE_VISIBILITY -_InputIter +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename enable_if +< + __is_input_iterator<_InputIter>::value, + _InputIter +>::type next(_InputIter __x, - typename iterator_traits<_InputIter>::difference_type __n = 1, - typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0) + typename iterator_traits<_InputIter>::difference_type __n = 1) { _VSTD::advance(__x, __n); return __x; } -template <class _BidiretionalIter> -inline _LIBCPP_INLINE_VISIBILITY -_BidiretionalIter -prev(_BidiretionalIter __x, - typename iterator_traits<_BidiretionalIter>::difference_type __n = 1, - typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0) +template <class _BidirectionalIter> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename enable_if +< + __is_bidirectional_iterator<_BidirectionalIter>::value, + _BidirectionalIter +>::type +prev(_BidirectionalIter __x, + typename iterator_traits<_BidirectionalIter>::difference_type __n = 1) { _VSTD::advance(__x, -__n); return __x; } + +template <class _Tp, class = void> +struct __is_stashing_iterator : false_type {}; + +template <class _Tp> +struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> + : true_type {}; + template <class _Iter> -class _LIBCPP_TYPE_VIS_ONLY reverse_iterator +class _LIBCPP_TEMPLATE_VIS reverse_iterator : public iterator<typename iterator_traits<_Iter>::iterator_category, typename iterator_traits<_Iter>::value_type, typename iterator_traits<_Iter>::difference_type, @@ -618,7 +637,12 @@ class _LIBCPP_TYPE_VIS_ONLY reverse_iterator typename iterator_traits<_Iter>::reference> { private: - mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break + /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break + + static_assert(!__is_stashing_iterator<_Iter>::value, + "The specified iterator type cannot be used with reverse_iterator; " + "Using stashing iterators with reverse_iterator causes undefined behavior"); + protected: _Iter current; public: @@ -627,33 +651,45 @@ public: typedef typename iterator_traits<_Iter>::reference reference; typedef typename iterator_traits<_Iter>::pointer pointer; - _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {} - _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} - template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u) - : __t(__u.base()), current(__u.base()) {} - _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;} - _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());} - _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;} - _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int) - {reverse_iterator __tmp(*this); --current; return __tmp;} - _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;} - _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int) - {reverse_iterator __tmp(*this); ++current; return __tmp;} - _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const - {return reverse_iterator(current - __n);} - _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n) - {current -= __n; return *this;} - _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const - {return reverse_iterator(current + __n);} - _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n) - {current += __n; return *this;} - _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const - {return *(*this + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator() : __t(), current() {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator=(const reverse_iterator<_Up>& __u) + { __t = current = __u.base(); return *this; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _Iter base() const {return current;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator*() const {_Iter __tmp = current; return *--__tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + pointer operator->() const {return _VSTD::addressof(operator*());} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator++() {--current; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator--() {++current; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const {return *(*this + __n);} }; template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -661,7 +697,7 @@ operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -669,7 +705,7 @@ operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -677,7 +713,7 @@ operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -685,7 +721,7 @@ operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -693,7 +729,7 @@ operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { @@ -702,7 +738,7 @@ operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) -> decltype(__y.base() - __x.base()) @@ -720,7 +756,7 @@ operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ #endif template <class _Iter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Iter> operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) { @@ -729,7 +765,7 @@ operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_i #if _LIBCPP_STD_VER > 11 template <class _Iter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) { return reverse_iterator<_Iter>(__i); @@ -737,7 +773,7 @@ reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) #endif template <class _Container> -class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator +class _LIBCPP_TEMPLATE_VIS back_insert_iterator : public iterator<output_iterator_tag, void, void, @@ -752,10 +788,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) {container->push_back(__value_); return *this;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) {container->push_back(_VSTD::move(__value_)); return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} @@ -770,7 +806,7 @@ back_inserter(_Container& __x) } template <class _Container> -class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator +class _LIBCPP_TEMPLATE_VIS front_insert_iterator : public iterator<output_iterator_tag, void, void, @@ -785,10 +821,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) {container->push_front(__value_); return *this;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) {container->push_front(_VSTD::move(__value_)); return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} @@ -803,7 +839,7 @@ front_inserter(_Container& __x) } template <class _Container> -class _LIBCPP_TYPE_VIS_ONLY insert_iterator +class _LIBCPP_TEMPLATE_VIS insert_iterator : public iterator<output_iterator_tag, void, void, @@ -820,10 +856,10 @@ public: : container(_VSTD::addressof(__x)), iter(__i) {} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) {iter = container->insert(iter, __value_); ++iter; return *this;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} @@ -839,7 +875,7 @@ inserter(_Container& __x, typename _Container::iterator __i) template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> -class _LIBCPP_TYPE_VIS_ONLY istream_iterator +class _LIBCPP_TEMPLATE_VIS istream_iterator : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> { public: @@ -868,17 +904,39 @@ public: _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) {istream_iterator __t(*this); ++(*this); return __t;} + template <class _Up, class _CharU, class _TraitsU, class _DistanceU> friend _LIBCPP_INLINE_VISIBILITY - bool operator==(const istream_iterator& __x, const istream_iterator& __y) - {return __x.__in_stream_ == __y.__in_stream_;} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); + template <class _Up, class _CharU, class _TraitsU, class _DistanceU> friend _LIBCPP_INLINE_VISIBILITY - bool operator!=(const istream_iterator& __x, const istream_iterator& __y) - {return !(__x == __y);} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); }; +template <class _Tp, class _CharT, class _Traits, class _Distance> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return __x.__in_stream_ == __y.__in_stream_; +} + +template <class _Tp, class _CharT, class _Traits, class _Distance> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return !(__x == __y); +} + template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY ostream_iterator +class _LIBCPP_TEMPLATE_VIS ostream_iterator : public iterator<output_iterator_tag, void, void, void, void> { public: @@ -889,9 +947,9 @@ private: ostream_type* __out_stream_; const char_type* __delim_; public: - _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} - _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) + _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) { @@ -907,7 +965,7 @@ public: }; template<class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator +class _LIBCPP_TEMPLATE_VIS istreambuf_iterator : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT> @@ -950,7 +1008,6 @@ public: _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return static_cast<char_type>(__sbuf_->sgetc());} - _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;} _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() { __sbuf_->sbumpc(); @@ -978,7 +1035,7 @@ bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, {return !__a.equal(__b);} template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator +class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator : public iterator<output_iterator_tag, void, void, void, void> { public: @@ -1019,7 +1076,7 @@ public: }; template <class _Iter> -class _LIBCPP_TYPE_VIS_ONLY move_iterator +class _LIBCPP_TEMPLATE_VIS move_iterator { private: _Iter __i; @@ -1029,7 +1086,7 @@ public: typedef typename iterator_traits<iterator_type>::value_type value_type; typedef typename iterator_traits<iterator_type>::difference_type difference_type; typedef iterator_type pointer; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG typedef typename iterator_traits<iterator_type>::reference __reference; typedef typename conditional< is_reference<__reference>::value, @@ -1040,37 +1097,40 @@ public: typedef typename iterator_traits<iterator_type>::reference reference; #endif - _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {} - _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {} - template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u) - : __i(__u.base()) {} - _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;} - _LIBCPP_INLINE_VISIBILITY reference operator*() const { - return static_cast<reference>(*__i); - } - _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return __i;} - _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;} - _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int) - {move_iterator __tmp(*this); ++__i; return __tmp;} - _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;} - _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int) - {move_iterator __tmp(*this); --__i; return __tmp;} - _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const - {return move_iterator(__i + __n);} - _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n) - {__i += __n; return *this;} - _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const - {return move_iterator(__i - __n);} - _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n) - {__i -= __n; return *this;} - _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const - { - return static_cast<reference>(__i[__n]); - } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator() : __i() {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + explicit move_iterator(_Iter __x) : __i(__x) {} + template <class _Up> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator*() const { return static_cast<reference>(*__i); } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + pointer operator->() const { return __i;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator++() {++__i; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator--() {--__i; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } }; template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1078,7 +1138,7 @@ operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1086,7 +1146,7 @@ operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1094,7 +1154,7 @@ operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1102,7 +1162,7 @@ operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1110,7 +1170,7 @@ operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) } template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { @@ -1119,7 +1179,7 @@ operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) -> decltype(__x.base() - __y.base()) @@ -1137,7 +1197,7 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) #endif template <class _Iter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator<_Iter> operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) { @@ -1145,7 +1205,7 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato } template <class _Iter> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator<_Iter> make_move_iterator(_Iter __i) { @@ -1159,56 +1219,58 @@ template <class _Iter> class __wrap_iter; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY bool -operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY auto -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()); #else template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #endif template <class _Iter> _LIBCPP_INLINE_VISIBILITY __wrap_iter<_Iter> -operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; +operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG; template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2); +#if _LIBCPP_DEBUG_LEVEL < 2 + template <class _Tp> _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -1218,6 +1280,19 @@ typename enable_if >::type __unwrap_iter(__wrap_iter<_Tp*>); +#else + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i); + +#endif + template <class _Iter> class __wrap_iter { @@ -1231,7 +1306,7 @@ public: private: iterator_type __i; public: - _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG #if _LIBCPP_STD_VER > 11 : __i{} #endif @@ -1241,7 +1316,7 @@ public: #endif } template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u, - typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT + typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG : __i(__u.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1271,7 +1346,7 @@ public: __get_db()->__erase_i(this); } #endif - _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1279,7 +1354,7 @@ public: #endif return *__i; } - _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1287,7 +1362,7 @@ public: #endif return (pointer)_VSTD::addressof(*__i); } - _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1296,9 +1371,9 @@ public: ++__i; return *this; } - _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG {__wrap_iter __tmp(*this); ++(*this); return __tmp;} - _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), @@ -1307,11 +1382,11 @@ public: --__i; return *this; } - _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG {__wrap_iter __tmp(*this); --(*this); return __tmp;} - _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG {__wrap_iter __w(*this); __w += __n; return __w;} - _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), @@ -1320,11 +1395,11 @@ public: __i += __n; return *this; } - _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG {return *this + (-__n);} - _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG {*this += -__n; return *this;} - _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), @@ -1333,7 +1408,7 @@ public: return __i[__n]; } - _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;} + _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;} private: #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1342,66 +1417,67 @@ private: __get_db()->__insert_ic(this, __p); } #else - _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} + _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {} #endif template <class _Up> friend class __wrap_iter; template <class _CharT, class _Traits, class _Alloc> friend class basic_string; - template <class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector; + template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; template <class _Iter1, class _Iter2> friend bool - operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> friend bool - operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> friend bool - operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> friend bool - operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> friend bool - operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template <class _Iter1, class _Iter2> friend bool - operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> friend auto - operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT + operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()); #else template <class _Iter1, class _Iter2> friend typename __wrap_iter<_Iter1>::difference_type - operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; + operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #endif template <class _Iter1> friend __wrap_iter<_Iter1> - operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; + operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG; template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); +#if _LIBCPP_DEBUG_LEVEL < 2 template <class _Tp> friend typename enable_if @@ -1410,12 +1486,22 @@ private: _Tp* >::type __unwrap_iter(__wrap_iter<_Tp*>); +#else + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + is_trivially_copy_assignable<_Tp>::value, + __wrap_iter<_Tp*> + >::type + __unwrap_iter(__wrap_iter<_Tp*> __i); +#endif }; template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return __x.base() == __y.base(); } @@ -1423,7 +1509,7 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), @@ -1435,7 +1521,7 @@ operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__x == __y); } @@ -1443,7 +1529,7 @@ operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return __y < __x; } @@ -1451,7 +1537,7 @@ operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__x < __y); } @@ -1459,7 +1545,7 @@ operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__y < __x); } @@ -1467,7 +1553,7 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__x == __y); } @@ -1475,7 +1561,7 @@ operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return __y < __x; } @@ -1483,7 +1569,7 @@ operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXC template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__x < __y); } @@ -1491,7 +1577,7 @@ operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__y < __x); } @@ -1500,7 +1586,7 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY auto -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1513,7 +1599,7 @@ operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), @@ -1527,7 +1613,7 @@ template <class _Iter> inline _LIBCPP_INLINE_VISIBILITY __wrap_iter<_Iter> operator+(typename __wrap_iter<_Iter>::difference_type __n, - __wrap_iter<_Iter> __x) _NOEXCEPT + __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG { __x += __n; return __x; @@ -1535,19 +1621,19 @@ operator+(typename __wrap_iter<_Iter>::difference_type __n, template <class _Iter> struct __libcpp_is_trivial_iterator - : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; - + : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; + template <class _Iter> struct __libcpp_is_trivial_iterator<move_iterator<_Iter> > - : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template <class _Iter> struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > - : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template <class _Iter> struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > - : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; + : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template <class _Tp, size_t _Np> @@ -1566,10 +1652,10 @@ end(_Tp (&__array)[_Np]) return __array + _Np; } -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#if !defined(_LIBCPP_CXX03_LANG) template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(_Cp& __c) -> decltype(__c.begin()) { @@ -1577,7 +1663,7 @@ begin(_Cp& __c) -> decltype(__c.begin()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(const _Cp& __c) -> decltype(__c.begin()) { @@ -1585,7 +1671,7 @@ begin(const _Cp& __c) -> decltype(__c.begin()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(_Cp& __c) -> decltype(__c.end()) { @@ -1593,7 +1679,7 @@ end(_Cp& __c) -> decltype(__c.end()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(const _Cp& __c) -> decltype(__c.end()) { @@ -1603,28 +1689,28 @@ end(const _Cp& __c) -> decltype(__c.end()) #if _LIBCPP_STD_VER > 11 template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template <class _Ep> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) { return reverse_iterator<const _Ep*>(__il.end()); } template <class _Ep> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) { return reverse_iterator<const _Ep*>(__il.begin()); @@ -1645,42 +1731,42 @@ auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(const _Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) { return _VSTD::rbegin(__c); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) { return _VSTD::rend(__c); @@ -1689,7 +1775,7 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) #endif -#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#else // defined(_LIBCPP_CXX03_LANG) template <class _Cp> inline _LIBCPP_INLINE_VISIBILITY @@ -1723,34 +1809,70 @@ end(const _Cp& __c) return __c.end(); } -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#endif // !defined(_LIBCPP_CXX03_LANG) #if _LIBCPP_STD_VER > 14 + +// #if _LIBCPP_STD_VER > 11 +// template <> +// struct _LIBCPP_TEMPLATE_VIS plus<void> +// { +// template <class _T1, class _T2> +// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +// auto operator()(_T1&& __t, _T2&& __u) const +// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) +// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) +// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } +// typedef void is_transparent; +// }; +// #endif + template <class _Cont> -constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); } +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } template <class _Tp, size_t _Sz> -constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; } +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } template <class _Cont> -constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); } +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } template <class _Tp, size_t _Sz> -constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; } +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } template <class _Ep> +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } template <class _Cont> constexpr -auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template <class _Cont> constexpr -auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template <class _Tp, size_t _Sz> +inline _LIBCPP_INLINE_VISIBILITY constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } template <class _Ep> +inline _LIBCPP_INLINE_VISIBILITY constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } #endif diff --git a/lib/libcxx/include/limits b/lib/libcxx/include/limits index 80a1be40fe4..f530507f724 100644 --- a/lib/libcxx/include/limits +++ b/lib/libcxx/include/limits @@ -101,24 +101,25 @@ template<> class numeric_limits<cv long double>; } // std */ - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - #include <__config> #include <type_traits> -#include <__undef_min_max> - -#if defined(_LIBCPP_MSVCRT) -#include "support/win32/limits_win32.h" +#if defined(_LIBCPP_COMPILER_MSVC) +#include "support/win32/limits_msvc_win32.h" #endif // _LIBCPP_MSVCRT #if defined(__IBMCPP__) #include "support/ibm/limits.h" #endif // __IBMCPP__ +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD enum float_round_style @@ -182,14 +183,14 @@ protected: static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; }; -template <class _Tp, int digits, bool is_signed> +template <class _Tp, int __digits, bool _IsSigned> struct __libcpp_compute_min { - static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << digits); + static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits); }; -template <class _Tp, int digits> -struct __libcpp_compute_min<_Tp, digits, false> +template <class _Tp, int __digits> +struct __libcpp_compute_min<_Tp, __digits, false> { static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0); }; @@ -306,7 +307,7 @@ protected: static _LIBCPP_CONSTEXPR const bool is_signed = true; static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__; static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__; - static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103)/100000; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __FLT_MIN__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __FLT_MAX__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} @@ -352,7 +353,7 @@ protected: static _LIBCPP_CONSTEXPR const bool is_signed = true; static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__; static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__; - static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103)/100000; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __DBL_MIN__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __DBL_MAX__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} @@ -398,7 +399,7 @@ protected: static _LIBCPP_CONSTEXPR const bool is_signed = true; static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__; static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__; - static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103)/100000; + static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __LDBL_MIN__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __LDBL_MAX__;} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();} @@ -438,7 +439,7 @@ protected: }; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY numeric_limits +class _LIBCPP_TEMPLATE_VIS numeric_limits : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type> { typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base; @@ -531,7 +532,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY numeric_limits<const _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp> : private numeric_limits<_Tp> { typedef numeric_limits<_Tp> __base; @@ -624,7 +625,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR const float_round_style numeric_limits<const _Tp>::round_style; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY numeric_limits<volatile _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<volatile _Tp> : private numeric_limits<_Tp> { typedef numeric_limits<_Tp> __base; @@ -717,7 +718,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR const float_round_style numeric_limits<volatile _Tp>::round_style; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY numeric_limits<const volatile _Tp> +class _LIBCPP_TEMPLATE_VIS numeric_limits<const volatile _Tp> : private numeric_limits<_Tp> { typedef numeric_limits<_Tp> __base; @@ -811,4 +812,6 @@ template <class _Tp> _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_LIMITS diff --git a/lib/libcxx/include/limits.h b/lib/libcxx/include/limits.h new file mode 100644 index 00000000000..1867b104857 --- /dev/null +++ b/lib/libcxx/include/limits.h @@ -0,0 +1,65 @@ +// -*- C++ -*- +//===--------------------------- limits.h ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIMITS_H +#define _LIBCPP_LIMITS_H + +/* + limits.h synopsis + +Macros: + + CHAR_BIT + SCHAR_MIN + SCHAR_MAX + UCHAR_MAX + CHAR_MIN + CHAR_MAX + MB_LEN_MAX + SHRT_MIN + SHRT_MAX + USHRT_MAX + INT_MIN + INT_MAX + UINT_MAX + LONG_MIN + LONG_MAX + ULONG_MAX + LLONG_MIN // C99 + LLONG_MAX // C99 + ULLONG_MAX // C99 + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef __GNUC__ +#include_next <limits.h> +#else +// GCC header limits.h recursively includes itself through another header called +// syslimits.h for some reason. This setup breaks down if we directly +// #include_next GCC's limits.h (reasons not entirely clear to me). Therefore, +// we manually re-create the necessary include sequence below: + +// Get the system limits.h defines (force recurse into the next level) +#define _GCC_LIMITS_H_ +#define _GCC_NEXT_LIMITS_H +#include_next <limits.h> + +// Get the ISO C defines +#undef _GCC_LIMITS_H_ +#include_next <limits.h> +#endif // __GNUC__ + +#endif // _LIBCPP_LIMITS_H diff --git a/lib/libcxx/include/list b/lib/libcxx/include/list index cff0a853eff..32e9a27bd2a 100644 --- a/lib/libcxx/include/list +++ b/lib/libcxx/include/list @@ -93,10 +93,10 @@ public: size_type max_size() const noexcept; template <class... Args> - void emplace_front(Args&&... args); + reference emplace_front(Args&&... args); // reference in C++17 void pop_front(); template <class... Args> - void emplace_back(Args&&... args); + reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); void push_front(const value_type& x); void push_front(value_type&& x); @@ -177,14 +177,16 @@ template <class T, class Alloc> #include <algorithm> #include <type_traits> -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, class _VoidPtr> struct __list_node; @@ -266,12 +268,12 @@ struct __list_node } }; -template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list; +template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list; template <class _Tp, class _Alloc> class __list_imp; -template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator; +template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator; template <class _Tp, class _VoidPtr> -class _LIBCPP_TYPE_VIS_ONLY __list_iterator +class _LIBCPP_TEMPLATE_VIS __list_iterator { typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; typedef typename _NodeTraits::__link_pointer __link_pointer; @@ -394,7 +396,7 @@ public: }; template <class _Tp, class _VoidPtr> -class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator +class _LIBCPP_TEMPLATE_VIS __list_const_iterator { typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; typedef typename _NodeTraits::__link_pointer __link_pointer; @@ -479,7 +481,7 @@ public: { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to dereference a non-dereferenceable list::iterator"); + "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); } @@ -571,6 +573,10 @@ protected: {return __size_alloc_.second();} _LIBCPP_INLINE_VISIBILITY + size_type __node_alloc_max_size() const _NOEXCEPT { + return __node_alloc_traits::max_size(__node_alloc()); + } + _LIBCPP_INLINE_VISIBILITY static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -622,9 +628,9 @@ protected: void swap(__list_imp& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT; + _NOEXCEPT_DEBUG; #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -651,7 +657,7 @@ private: } _LIBCPP_INLINE_VISIBILITY - void __copy_assign_alloc(const __list_imp& __c, false_type) + void __copy_assign_alloc(const __list_imp&, false_type) {} _LIBCPP_INLINE_VISIBILITY @@ -662,9 +668,16 @@ private: } _LIBCPP_INLINE_VISIBILITY - void __move_assign_alloc(__list_imp& __c, false_type) + void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY + void __invalidate_all_iterators() { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif + } }; // Unlink nodes [__f, __l] @@ -720,21 +733,7 @@ __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); } -#if _LIBCPP_DEBUG_LEVEL >= 2 - __c_node* __c = __get_db()->__find_c_and_lock(this); - for (__i_node** __p = __c->end_; __p != __c->beg_; ) - { - --__p; - const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->__ptr_ != __l) - { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); - } - } - __get_db()->unlock(); -#endif + __invalidate_all_iterators(); } } @@ -742,9 +741,9 @@ template <class _Tp, class _Alloc> void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT + _NOEXCEPT_DEBUG #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { @@ -803,7 +802,7 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) } template <class _Tp, class _Alloc /*= allocator<_Tp>*/> -class _LIBCPP_TYPE_VIS_ONLY list +class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> { typedef __list_imp<_Tp, _Alloc> base; @@ -863,11 +862,10 @@ public: list(const list& __c, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY list& operator=(const list& __c); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG list(initializer_list<value_type> __il); list(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); @@ -878,33 +876,35 @@ public: _NOEXCEPT_( __node_alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY list& operator=(initializer_list<value_type> __il) {assign(__il.begin(), __il.end()); return *this;} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG template <class _InpIter> void assign(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); void assign(size_type __n, const value_type& __x); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - void assign(initializer_list<value_type> __il) - {assign(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return base::__sz();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::empty();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT - {return numeric_limits<difference_type>::max();} + { + return std::min<size_type>( + base::__node_alloc_max_size(), + numeric_limits<difference_type >::max()); + } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return base::begin();} @@ -963,40 +963,56 @@ public: return base::__end_.__prev_->__as_node()->__value_; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG void push_front(value_type&& __x); void push_back(value_type&& __x); -#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> - void emplace_front(_Args&&... __args); +#if _LIBCPP_STD_VER > 14 + reference emplace_front(_Args&&... __args); +#else + void emplace_front(_Args&&... __args); +#endif template <class... _Args> - void emplace_back(_Args&&... __args); +#if _LIBCPP_STD_VER > 14 + reference emplace_back(_Args&&... __args); +#else + void emplace_back(_Args&&... __args); +#endif template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); -#endif // _LIBCPP_HAS_NO_VARIADICS + iterator insert(const_iterator __p, value_type&& __x); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, initializer_list<value_type> __il) + {return insert(__p, __il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG void push_front(const value_type& __x); void push_back(const value_type& __x); +#ifndef _LIBCPP_CXX03_LANG + template <class _Arg> + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); } +#else + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(value_type const& __arg) { push_back(__arg); } +#endif + iterator insert(const_iterator __p, const value_type& __x); iterator insert(const_iterator __p, size_type __n, const value_type& __x); template <class _InpIter> iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - iterator insert(const_iterator __p, initializer_list<value_type> __il) - {return insert(__p, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY void swap(list& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT + _NOEXCEPT_DEBUG #else - _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) #endif {base::swap(__c);} @@ -1013,22 +1029,18 @@ public: void resize(size_type __n, const value_type& __x); void splice(const_iterator __p, list& __c); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c) {splice(__p, __c);} -#endif - void splice(const_iterator __p, list& __c, const_iterator __i); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c, const_iterator __i) {splice(__p, __c, __i);} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {splice(__p, __c, __f, __l);} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + void splice(const_iterator __p, list& __c, const_iterator __i); + void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); void remove(const value_type& __x); template <class _Pred> void remove_if(_Pred __pred); @@ -1038,17 +1050,17 @@ public: void unique(_BinaryPred __binary_pred); _LIBCPP_INLINE_VISIBILITY void merge(list& __c); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(list&& __c) {merge(__c);} -#endif - template <class _Comp> - void merge(list& __c, _Comp __comp); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _Comp> _LIBCPP_INLINE_VISIBILITY void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + template <class _Comp> + void merge(list& __c, _Comp __comp); + _LIBCPP_INLINE_VISIBILITY void sort(); template <class _Comp> @@ -1059,6 +1071,16 @@ public: bool __invariants() const; + typedef __allocator_destructor<__node_allocator> __node_destructor; + typedef unique_ptr<__node, __node_destructor> __hold_pointer; + + _LIBCPP_INLINE_VISIBILITY + __hold_pointer __allocate_node(__node_allocator& __na) { + __node_pointer __p = __node_alloc_traits::allocate(__na, 1); + __p->__prev_ = nullptr; + return __hold_pointer(__p, __node_destructor(__na, 1)); + } + #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; @@ -1137,7 +1159,7 @@ list<_Tp, _Alloc>::list(size_type __n) __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG emplace_back(); #else push_back(value_type()); @@ -1152,11 +1174,7 @@ list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES emplace_back(); -#else - push_back(value_type()); -#endif } #endif @@ -1190,7 +1208,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, __get_db()->__insert_c(this); #endif for (; __f != __l; ++__f) - push_back(*__f); + __emplace_back(*__f); } template <class _Tp, class _Alloc> @@ -1203,7 +1221,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, __get_db()->__insert_c(this); #endif for (; __f != __l; ++__f) - push_back(*__f); + __emplace_back(*__f); } template <class _Tp, class _Alloc> @@ -1230,7 +1248,7 @@ list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) push_back(*__i); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) @@ -1255,23 +1273,6 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il) push_back(*__i); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -template <class _Tp, class _Alloc> -inline -list<_Tp, _Alloc>& -list<_Tp, _Alloc>::operator=(const list& __c) -{ - if (this != &__c) - { - base::__copy_assign_alloc(__c); - assign(__c.begin(), __c.end()); - } - return *this; -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp, class _Alloc> inline list<_Tp, _Alloc>::list(list&& __c) @@ -1337,7 +1338,20 @@ list<_Tp, _Alloc>::__move_assign(list& __c, true_type) splice(end(), __c); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG + +template <class _Tp, class _Alloc> +inline +list<_Tp, _Alloc>& +list<_Tp, _Alloc>::operator=(const list& __c) +{ + if (this != &__c) + { + base::__copy_assign_alloc(__c); + assign(__c.begin(), __c.end()); + } + return *this; +} template <class _Tp, class _Alloc> template <class _InpIter> @@ -1353,6 +1367,9 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, insert(__e, __f, __l); else erase(__i, __e); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif } template <class _Tp, class _Alloc> @@ -1367,6 +1384,9 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) insert(__e, __n, __x); else erase(__i, __e); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__invalidate_all(this); +#endif } template <class _Tp, class _Alloc> @@ -1387,9 +1407,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); ++base::__sz(); @@ -1416,9 +1434,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1484,9 +1500,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1539,8 +1553,7 @@ void list<_Tp, _Alloc>::push_front(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_front(__nl, __nl); @@ -1553,23 +1566,21 @@ void list<_Tp, _Alloc>::push_back(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> void list<_Tp, _Alloc>::push_front(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); @@ -1581,43 +1592,54 @@ void list<_Tp, _Alloc>::push_back(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Alloc> template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename list<_Tp, _Alloc>::reference +#else void +#endif list<_Tp, _Alloc>::emplace_front(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); +#if _LIBCPP_STD_VER > 14 + return __hold.release()->__value_; +#else __hold.release(); +#endif } template <class _Tp, class _Alloc> template <class... _Args> +#if _LIBCPP_STD_VER > 14 +typename list<_Tp, _Alloc>::reference +#else void +#endif list<_Tp, _Alloc>::emplace_back(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_back(__nl, __nl); ++base::__sz(); +#if _LIBCPP_STD_VER > 14 + return __hold.release()->__value_; +#else __hold.release(); +#endif } template <class _Tp, class _Alloc> @@ -1631,9 +1653,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold.get()->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); @@ -1646,8 +1666,6 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) #endif } -#endif // _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Alloc> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) @@ -1658,9 +1676,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_pointer __nl = __hold->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); @@ -1673,7 +1689,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Alloc> void @@ -1751,15 +1767,15 @@ list<_Tp, _Alloc>::erase(const_iterator __p) --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); - for (__i_node** __p = __c->end_; __p != __c->beg_; ) + for (__i_node** __ip = __c->end_; __ip != __c->beg_; ) { - --__p; - iterator* __i = static_cast<iterator*>((*__p)->__i_); + --__ip; + iterator* __i = static_cast<iterator*>((*__ip)->__i_); if (__i->__ptr_ == __n) { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + (*__ip)->__c_ = nullptr; + if (--__c->end_ != __ip) + memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*)); } } __get_db()->unlock(); @@ -1782,6 +1798,9 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, "list::erase(iterator, iterator) called with an iterator not" " referring to this list"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this, + "list::erase(iterator, iterator) called with an iterator not" + " referring to this list"); #endif if (__f != __l) { @@ -1830,9 +1849,7 @@ list<_Tp, _Alloc>::resize(size_type __n) __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1889,9 +1906,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; __link_pointer __nl = __hold.release()->__as_link(); @@ -1961,16 +1976,16 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - --__p; - iterator* __i = static_cast<iterator*>((*__p)->__i_); + --__ip; + iterator* __i = static_cast<iterator*>((*__ip)->__i_); if (__i->__ptr_ != __c.__end_as_link()) { - __cn1->__add(*__p); - (*__p)->__c_ = __cn1; - if (--__cn2->end_ != __p) - memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } __db->unlock(); @@ -2004,16 +2019,16 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - --__p; - iterator* __j = static_cast<iterator*>((*__p)->__i_); + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); if (__j->__ptr_ == __f) { - __cn1->__add(*__p); - (*__p)->__c_ = __cn1; - if (--__cn2->end_ != __p) - memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } __db->unlock(); @@ -2058,19 +2073,19 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - --__p; - iterator* __j = static_cast<iterator*>((*__p)->__i_); + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); for (__link_pointer __k = __f.__ptr_; __k != __l.__ptr_; __k = __k->__next_) { if (__j->__ptr_ == __k) { - __cn1->__add(*__p); - (*__p)->__c_ = __cn1; - if (--__cn2->end_ != __p) - memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } } @@ -2083,7 +2098,7 @@ template <class _Tp, class _Alloc> void list<_Tp, _Alloc>::remove(const value_type& __x) { - list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing + list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing for (const_iterator __i = begin(), __e = end(); __i != __e;) { if (*__i == __x) @@ -2328,14 +2343,14 @@ list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const template <class _Tp, class _Alloc> bool -list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const +list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const { return false; } template <class _Tp, class _Alloc> bool -list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const +list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const { return false; } @@ -2401,4 +2416,6 @@ swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_LIST diff --git a/lib/libcxx/include/locale b/lib/libcxx/include/locale index 3d804e86f4d..a86645d2cc4 100644 --- a/lib/libcxx/include/locale +++ b/lib/libcxx/include/locale @@ -192,14 +192,7 @@ template <class charT> class messages_byname; #endif #include <cstdlib> #include <ctime> -#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) -#include <support/win32/locale_win32.h> -#elif defined(_NEWLIB_VERSION) -// FIXME: replace all the uses of _NEWLIB_VERSION with __NEWLIB__ preceded by an -// include of <sys/cdefs.h> once https://sourceware.org/ml/newlib-cvs/2014-q3/msg00038.html -// has had a chance to bake for a bit -#include <support/newlib/xlocale.h> -#endif +#include <cstdio> #ifdef _LIBCPP_HAS_CATOPEN #include <nl_types.h> #endif @@ -208,18 +201,20 @@ template <class charT> class messages_byname; #include <Availability.h> #endif -#include <__undef_min_max> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - #ifdef _LIBCPP_LOCALE__L_EXTENSIONS #include <__bsd_locale_defaults.h> #else #include <__bsd_locale_fallbacks.h> #endif +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD #if defined(__APPLE__) || defined(__FreeBSD__) @@ -233,9 +228,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD #define __cloc_defined #endif -typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; -typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr; - // __scan_keyword // Scans [__b, __e) until a match is found in the basic_strings range // [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). @@ -380,19 +372,57 @@ template <class _CharT> struct __num_get : protected __num_get_base { - static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep); - static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, - unsigned& __dc, _CharT __thousands_sep, const string& __grouping, - unsigned* __g, unsigned*& __g_end, _CharT* __atoms); + static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); + static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, _CharT* __atoms); + +#else + static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) + { + locale __loc = __iob.getloc(); + const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); + __thousands_sep = __np.thousands_sep(); + return __np.grouping(); + } + + const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const + { + return __do_widen_p(__iob, __atoms); + } + + + static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, const _CharT* __atoms); +private: + template<typename T> + const T* __do_widen_p(ios_base& __iob, T* __atoms) const + { + locale __loc = __iob.getloc(); + use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms); + return __atoms; + } + + const char* __do_widen_p(ios_base& __iob, char* __atoms) const + { + (void)__iob; + (void)__atoms; + return __src; + } +#endif }; +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET template <class _CharT> string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) @@ -403,6 +433,7 @@ __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& _ __thousands_sep = __np.thousands_sep(); return __np.grouping(); } +#endif template <class _CharT> string @@ -419,9 +450,16 @@ __num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& template <class _CharT> int +#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, unsigned& __dc, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, _CharT* __atoms) +#else +__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, + unsigned& __dc, _CharT __thousands_sep, const string& __grouping, + unsigned* __g, unsigned*& __g_end, const _CharT* __atoms) + +#endif { if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) { @@ -523,11 +561,11 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex return 0; } -_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get<char>) -_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>) template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY num_get +class _LIBCPP_TEMPLATE_VIS num_get : public locale::facet, private __num_get<_CharT> { @@ -623,16 +661,19 @@ protected: ~num_get() {} template <class _Fp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_floating_point (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const; template <class _Signed> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_signed (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const; template <class _Unsigned> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_unsigned (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const; @@ -779,6 +820,7 @@ long double __do_strtod<long double>(const char* __a, char** __p2) { } template <class _Tp> +_LIBCPP_HIDDEN _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) { @@ -853,9 +895,16 @@ num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e, // Stage 1 int __base = this->__get_base(__iob); // Stage 2 - char_type __atoms[26]; char_type __thousands_sep; + const int __atoms_size = 26; +#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + char_type __atoms1[__atoms_size]; + const char_type *__atoms = this->__do_widen(__iob, __atoms1); + string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); +#else + char_type __atoms[__atoms_size]; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); +#endif string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; @@ -903,9 +952,16 @@ num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e, // Stage 1 int __base = this->__get_base(__iob); // Stage 2 - char_type __atoms[26]; char_type __thousands_sep; + const int __atoms_size = 26; +#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET + char_type __atoms1[__atoms_size]; + const char_type *__atoms = this->__do_widen(__iob, __atoms1); + string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); +#else + char_type __atoms[__atoms_size]; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); +#endif string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; @@ -1042,8 +1098,8 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, return __b; } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>) struct _LIBCPP_TYPE_VIS __num_put_base { @@ -1192,11 +1248,11 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, __op = __ob + (__np - __nb); } -_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put<char>) -_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY num_put +class _LIBCPP_TEMPLATE_VIS num_put : public locale::facet, private __num_put<_CharT> { @@ -1398,6 +1454,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits<long>::digits / 3) + ((numeric_limits<long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1424,6 +1481,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits<long long>::digits / 3) + ((numeric_limits<long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1450,6 +1508,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3) + ((numeric_limits<unsigned long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1476,6 +1535,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3) + ((numeric_limits<unsigned long long>::digits % 3) != 0) + + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); @@ -1621,8 +1681,8 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_put<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_put<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>) template <class _CharT, class _InputIterator> _LIBCPP_HIDDEN @@ -1664,7 +1724,7 @@ public: }; template <class _CharT> -class _LIBCPP_TYPE_VIS_ONLY __time_get_c_storage +class _LIBCPP_TEMPLATE_VIS __time_get_c_storage { protected: typedef basic_string<_CharT> string_type; @@ -1681,8 +1741,24 @@ protected: ~__time_get_c_storage() {} }; +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__weeks() const; +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__months() const; +template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__am_pm() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__c() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const; +template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const; + +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const; +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const; +template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const; +template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const; + template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY time_get +class _LIBCPP_TEMPLATE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> @@ -2291,8 +2367,8 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, return __b; } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>) class _LIBCPP_TYPE_VIS __time_get { @@ -2305,7 +2381,7 @@ protected: }; template <class _CharT> -class _LIBCPP_TYPE_VIS_ONLY __time_get_storage +class _LIBCPP_TEMPLATE_VIS __time_get_storage : public __time_get { protected: @@ -2332,7 +2408,7 @@ private: }; template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY time_get_byname +class _LIBCPP_TEMPLATE_VIS time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> { @@ -2374,8 +2450,8 @@ private: virtual const string_type& __X() const {return this->__X_;} }; -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get_byname<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get_byname<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>) class _LIBCPP_TYPE_VIS __time_put { @@ -2392,7 +2468,7 @@ protected: }; template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY time_put +class _LIBCPP_TEMPLATE_VIS time_put : public locale::facet, private __time_put { @@ -2487,11 +2563,11 @@ time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&, return _VSTD::copy(__nb, __ne, __s); } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY time_put_byname +class _LIBCPP_TEMPLATE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> { public: @@ -2508,8 +2584,8 @@ protected: ~time_put_byname() {} }; -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put_byname<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put_byname<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>) // money_base @@ -2525,7 +2601,7 @@ public: // moneypunct template <class _CharT, bool _International = false> -class _LIBCPP_TYPE_VIS_ONLY moneypunct +class _LIBCPP_TEMPLATE_VIS moneypunct : public locale::facet, public money_base { @@ -2575,15 +2651,15 @@ template <class _CharT, bool _International> const bool moneypunct<_CharT, _International>::intl; -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<char, false>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<char, true>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<wchar_t, false>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<wchar_t, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>) // moneypunct_byname template <class _CharT, bool _International = false> -class _LIBCPP_TYPE_VIS_ONLY moneypunct_byname +class _LIBCPP_TEMPLATE_VIS moneypunct_byname : public moneypunct<_CharT, _International> { public: @@ -2627,15 +2703,15 @@ private: void init(const char*); }; -template<> void moneypunct_byname<char, false>::init(const char*); -template<> void moneypunct_byname<char, true>::init(const char*); -template<> void moneypunct_byname<wchar_t, false>::init(const char*); -template<> void moneypunct_byname<wchar_t, true>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*); +template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*); -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<char, false>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<char, true>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<wchar_t, false>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<wchar_t, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>) // money_get @@ -2691,11 +2767,11 @@ __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, } } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_get<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_get<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>) template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY money_get +class _LIBCPP_TEMPLATE_VIS money_get : public locale::facet, private __money_get<_CharT> { @@ -2821,7 +2897,7 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, return false; } } - // drop through + _LIBCPP_FALLTHROUGH(); case money_base::none: if (__p != 3) { @@ -3074,8 +3150,8 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, return __b; } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_get<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_get<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>) // money_put @@ -3249,11 +3325,11 @@ __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __m __mi = __mb; } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_put<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_put<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>) template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY money_put +class _LIBCPP_TEMPLATE_VIS money_put : public locale::facet, private __money_put<_CharT> { @@ -3402,8 +3478,8 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_put<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_put<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>) // messages @@ -3416,7 +3492,7 @@ public: }; template <class _CharT> -class _LIBCPP_TYPE_VIS_ONLY messages +class _LIBCPP_TEMPLATE_VIS messages : public locale::facet, public messages_base { @@ -3512,11 +3588,11 @@ messages<_CharT>::do_close(catalog __c) const #endif // _LIBCPP_HAS_CATOPEN } -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>) template <class _CharT> -class _LIBCPP_TYPE_VIS_ONLY messages_byname +class _LIBCPP_TEMPLATE_VIS messages_byname : public messages<_CharT> { public: @@ -3536,13 +3612,13 @@ protected: ~messages_byname() {} }; -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages_byname<char>) -_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages_byname<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>) +_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>) template<class _Codecvt, class _Elem = wchar_t, class _Wide_alloc = allocator<_Elem>, class _Byte_alloc = allocator<char> > -class _LIBCPP_TYPE_VIS_ONLY wstring_convert +class _LIBCPP_TEMPLATE_VIS wstring_convert { public: typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string; @@ -3566,7 +3642,7 @@ public: wstring_convert(_Codecvt* __pcvt, state_type __state); _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string()); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_ALWAYS_INLINE wstring_convert(wstring_convert&& __wc); #endif @@ -3625,7 +3701,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: __cvtptr_ = new _Codecvt; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> inline @@ -3639,7 +3715,7 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: __wc.__cvtptr_ = nullptr; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() @@ -3701,10 +3777,10 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: if (__r == codecvt_base::ok) return __ws; } -#ifndef _LIBCPP_NO_EXCEPTIONS + if (__wide_err_string_.empty()) - throw range_error("wstring_convert: from_bytes error"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_range_error("wstring_convert: from_bytes error"); + return __wide_err_string_; } @@ -3790,15 +3866,15 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: return __bs; } } -#ifndef _LIBCPP_NO_EXCEPTIONS + if (__byte_err_string_.empty()) - throw range_error("wstring_convert: to_bytes error"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_range_error("wstring_convert: to_bytes error"); + return __byte_err_string_; } template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > -class _LIBCPP_TYPE_VIS_ONLY wbuffer_convert +class _LIBCPP_TEMPLATE_VIS wbuffer_convert : public basic_streambuf<_Elem, _Tr> { public: @@ -3932,7 +4008,8 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz), static_cast<streamsize>(__extbufend_ - __extbufnext_)); codecvt_base::result __r; - state_type __svs = __st_; + // FIXME: Do we ever need to restore the state here? + //state_type __svs = __st_; streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb); if (__nr != 0) { @@ -3943,7 +4020,8 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() this->egptr(), __inext); if (__r == codecvt_base::noconv) { - this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + (char_type*) const_cast<char *>(__extbufend_)); __c = *this->gptr(); } else if (__inext != this->eback() + __unget_sz) @@ -4031,8 +4109,8 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) return traits_type::eof(); if (__r == codecvt_base::partial) { - this->setp((char_type*)__e, this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->setp(const_cast<char_type *>(__e), this->pptr()); + this->__pbump(this->epptr() - this->pbase()); } } else @@ -4252,4 +4330,6 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_LOCALE diff --git a/lib/libcxx/include/locale.h b/lib/libcxx/include/locale.h new file mode 100644 index 00000000000..cad7b8b53eb --- /dev/null +++ b/lib/libcxx/include/locale.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +//===---------------------------- locale.h --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LOCALE_H +#define _LIBCPP_LOCALE_H + +/* + locale.h synopsis + +Macros: + + LC_ALL + LC_COLLATE + LC_CTYPE + LC_MONETARY + LC_NUMERIC + LC_TIME + +Types: + + lconv + +Functions: + + setlocale + localeconv + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <locale.h> + +#endif // _LIBCPP_LOCALE_H diff --git a/lib/libcxx/include/map b/lib/libcxx/include/map index bdde949bc1e..95214938981 100644 --- a/lib/libcxx/include/map +++ b/lib/libcxx/include/map @@ -453,9 +453,7 @@ swap(multimap<Key, T, Compare, Allocator>& x, _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _CP, class _Compare, - bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value - > +template <class _Key, class _CP, class _Compare, bool _IsSmall> class __map_value_compare : private _Compare { @@ -482,8 +480,8 @@ public: void swap(__map_value_compare&__y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) { - using _VSTD::swap; - swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y)); + using _VSTD::swap; + swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); } #if _LIBCPP_STD_VER > 11 @@ -533,7 +531,7 @@ public: using _VSTD::swap; swap(comp, __y.comp); } - + #if _LIBCPP_STD_VER > 11 template <typename _K2> _LIBCPP_INLINE_VISIBILITY @@ -584,7 +582,7 @@ public: __second_constructed(false) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT : __na_(__x.__na_), @@ -593,7 +591,7 @@ public: { __x.__value_constructed = false; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT @@ -669,7 +667,7 @@ private: ~__value_type(); }; -#endif +#endif // _LIBCPP_CXX03_LANG template <class _Tp> struct __extract_key_value_types; @@ -682,7 +680,7 @@ struct __extract_key_value_types<__value_type<_Key, _Tp> > }; template <class _TreeIterator> -class _LIBCPP_TYPE_VIS_ONLY __map_iterator +class _LIBCPP_TEMPLATE_VIS __map_iterator { typedef typename _TreeIterator::_NodeTypes _NodeTypes; typedef typename _TreeIterator::__pointer_traits __pointer_traits; @@ -730,18 +728,18 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __map_iterator& __x, const __map_iterator& __y) {return __x.__i_ == __y.__i_;} - friend + friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; }; template <class _TreeIterator> -class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator +class _LIBCPP_TEMPLATE_VIS __map_const_iterator { typedef typename _TreeIterator::_NodeTypes _NodeTypes; typedef typename _TreeIterator::__pointer_traits __pointer_traits; @@ -797,14 +795,14 @@ public: bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map; - template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap; - template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; }; template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY map +class _LIBCPP_TEMPLATE_VIS map { public: // types: @@ -820,7 +818,7 @@ public: static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); - class _LIBCPP_TYPE_VIS_ONLY value_compare + class _LIBCPP_TEMPLATE_VIS value_compare : public binary_function<value_type, value_type, bool> { friend class map; @@ -895,7 +893,7 @@ public: #if _LIBCPP_STD_VER > 11 template <class _InputIterator> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) : map(__f, __l, key_compare(), __a) {} #endif @@ -923,7 +921,7 @@ public: return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY map(map&& __m) @@ -942,10 +940,6 @@ public: return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY map(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) @@ -961,7 +955,7 @@ public: } #if _LIBCPP_STD_VER > 11 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY map(initializer_list<value_type> __il, const allocator_type& __a) : map(__il, key_compare(), __a) {} #endif @@ -973,7 +967,7 @@ public: return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit map(const allocator_type& __a) @@ -1018,7 +1012,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -1084,6 +1078,10 @@ public: _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, value_type&& __v) {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} #endif template <class _InputIterator> @@ -1094,14 +1092,6 @@ public: insert(__e.__i_, *__f); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - - _LIBCPP_INLINE_VISIBILITY - void insert(initializer_list<value_type> __il) - {insert(__il.begin(), __il.end());} - -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - #if _LIBCPP_STD_VER > 14 template <class... _Args> @@ -1196,7 +1186,7 @@ public: return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); } -#endif +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} @@ -1297,6 +1287,7 @@ private: typedef typename __base::__node_allocator __node_allocator; typedef typename __base::__node_pointer __node_pointer; typedef typename __base::__node_base_pointer __node_base_pointer; + typedef typename __base::__parent_pointer __parent_pointer; typedef __map_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; @@ -1304,67 +1295,10 @@ private: #ifdef _LIBCPP_CXX03_LANG __node_holder __construct_node_with_key(const key_type& __k); #endif - - __node_base_pointer const& - __find_equal_key(__node_base_pointer& __parent, const key_type& __k) const; - - _LIBCPP_INLINE_VISIBILITY - __node_base_pointer& - __find_equal_key(__node_base_pointer& __parent, const key_type& __k) { - map const* __const_this = this; - return const_cast<__node_base_pointer&>( - __const_this->__find_equal_key(__parent, __k)); - } }; -// Find __k -// Set __parent to parent of null leaf and -// return reference to null leaf iv __k does not exist. -// 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 const& -map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent, - const key_type& __k) const -{ - __node_pointer __nd = __tree_.__root(); - if (__nd != nullptr) - { - while (true) - { - if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first)) - { - if (__nd->__left_ != nullptr) - __nd = static_cast<__node_pointer>(__nd->__left_); - else - { - __parent = static_cast<__node_base_pointer>(__nd); - return __parent->__left_; - } - } - 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 = static_cast<__node_base_pointer>(__nd); - return __parent->__right_; - } - } - else - { - __parent = static_cast<__node_base_pointer>(__nd); - return __parent; - } - } - } - __parent = static_cast<__node_base_pointer>(__tree_.__end_node()); - return __parent->__left_; -} - #ifndef _LIBCPP_CXX03_LANG - template <class _Key, class _Tp, class _Compare, class _Allocator> map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) @@ -1378,10 +1312,27 @@ map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) } } -#endif // !_LIBCPP_CXX03_LANG +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) +{ + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple()).first->__cc.second; +} +template <class _Key, class _Tp, class _Compare, class _Allocator> +_Tp& +map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) +{ + return __tree_.__emplace_unique_key_args(__k, + _VSTD::piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple()).first->__cc.second; +} -#ifdef _LIBCPP_CXX03_LANG +#else // _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Compare, class _Allocator> typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder @@ -1400,8 +1351,8 @@ template <class _Key, class _Tp, class _Compare, class _Allocator> _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) { - __node_base_pointer __parent; - __node_base_pointer& __child = __find_equal_key(__parent, __k); + __parent_pointer __parent; + __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { @@ -1412,36 +1363,14 @@ map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) return __r->__value_.__cc.second; } -#else - -template <class _Key, class _Tp, class _Compare, class _Allocator> -_Tp& -map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) -{ - return __tree_.__emplace_unique_key_args(__k, - _VSTD::piecewise_construct, - _VSTD::forward_as_tuple(__k), - _VSTD::forward_as_tuple()).first->__cc.second; -} - -template <class _Key, class _Tp, class _Compare, class _Allocator> -_Tp& -map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) -{ - return __tree_.__emplace_unique_key_args(__k, - _VSTD::piecewise_construct, - _VSTD::forward_as_tuple(_VSTD::move(__k)), - _VSTD::forward_as_tuple()).first->__cc.second; -} - -#endif // !_LIBCPP_CXX03_LANG +#endif // _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Compare, class _Allocator> _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) { - __node_base_pointer __parent; - __node_base_pointer& __child = __find_equal_key(__parent, __k); + __parent_pointer __parent; + __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); #ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); @@ -1453,8 +1382,8 @@ template <class _Key, class _Tp, class _Compare, class _Allocator> const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const { - __node_base_pointer __parent; - __node_base_pointer __child = __find_equal_key(__parent, __k); + __parent_pointer __parent; + __node_base_pointer __child = __tree_.__find_equal(__parent, __k); #ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); @@ -1529,7 +1458,7 @@ swap(map<_Key, _Tp, _Compare, _Allocator>& __x, template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY multimap +class _LIBCPP_TEMPLATE_VIS multimap { public: // types: @@ -1545,7 +1474,7 @@ public: static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); - class _LIBCPP_TYPE_VIS_ONLY value_compare + class _LIBCPP_TEMPLATE_VIS value_compare : public binary_function<value_type, value_type, bool> { friend class multimap; @@ -1621,7 +1550,7 @@ public: #if _LIBCPP_STD_VER > 11 template <class _InputIterator> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) : multimap(__f, __l, key_compare(), __a) {} #endif @@ -1650,7 +1579,7 @@ public: return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY multimap(multimap&& __m) @@ -1669,10 +1598,6 @@ public: return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) @@ -1688,7 +1613,7 @@ public: } #if _LIBCPP_STD_VER > 11 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY multimap(initializer_list<value_type> __il, const allocator_type& __a) : multimap(__il, key_compare(), __a) {} #endif @@ -1700,7 +1625,7 @@ public: return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit multimap(const allocator_type& __a) @@ -1744,7 +1669,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -1793,6 +1718,11 @@ public: iterator insert(const_iterator __p, value_type&& __v) {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} + #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY @@ -1810,14 +1740,6 @@ public: __tree_.__insert_multi(__e.__i_, *__f); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - - _LIBCPP_INLINE_VISIBILITY - void insert(initializer_list<value_type> __il) - {insert(__il.begin(), __il.end());} - -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY diff --git a/lib/libcxx/include/math.h b/lib/libcxx/include/math.h index 20205544d51..8c30ba85d22 100644 --- a/lib/libcxx/include/math.h +++ b/lib/libcxx/include/math.h @@ -307,10 +307,7 @@ long double truncl(long double x); extern "C++" { #include <type_traits> - -#ifdef _LIBCPP_MSVCRT -#include "support/win32/math_win32.h" -#endif +#include <limits> // signbit @@ -328,12 +325,50 @@ __libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type signbit(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x < 0; } + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type +signbit(_A1) _NOEXCEPT +{ return false; } + +#elif defined(_LIBCPP_MSVCRT) + +template <typename _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ + return ::signbit(static_cast<typename std::__promote<_A1>::type>(__lcpp_x)); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type +signbit(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x < 0; } + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type +signbit(_A1) _NOEXCEPT +{ return false; } + #endif // signbit // fpclassify @@ -352,12 +387,34 @@ __libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type +typename std::enable_if<std::is_floating_point<_A1>::value, int>::type fpclassify(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, int>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } + +#elif defined(_LIBCPP_MSVCRT) + +template <typename _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ + return ::fpclassify(static_cast<typename std::__promote<_A1>::type>(__lcpp_x)); +} + +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, int>::type +fpclassify(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL; } + #endif // fpclassify // isfinite @@ -376,12 +433,22 @@ __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type +typename std::enable_if< + std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, + bool>::type isfinite(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, + bool>::type +isfinite(_A1) _NOEXCEPT +{ return true; } + #endif // isfinite // isinf @@ -400,12 +467,22 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type +typename std::enable_if< + std::is_arithmetic<_A1>::value && std::numeric_limits<_A1>::has_infinity, + bool>::type isinf(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if< + std::is_arithmetic<_A1>::value && !std::numeric_limits<_A1>::has_infinity, + bool>::type +isinf(_A1) _NOEXCEPT +{ return false; } + #endif // isinf // isnan @@ -424,12 +501,18 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type isnan(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, bool>::type +isnan(_A1) _NOEXCEPT +{ return false; } + #endif // isnan // isnormal @@ -448,12 +531,18 @@ __libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT template <class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type +typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type isnormal(_A1 __lcpp_x) _NOEXCEPT { return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x); } +template <class _A1> +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if<std::is_integral<_A1>::value, bool>::type +isnormal(_A1 __lcpp_x) _NOEXCEPT +{ return __lcpp_x != 0; } + #endif // isnormal // isgreater @@ -636,65 +725,63 @@ isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT #endif // isunordered -#ifndef __sun__ - // abs -#if !defined(_AIX) +#if !(defined(_AIX) || defined(__sun__)) inline _LIBCPP_INLINE_VISIBILITY float -abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);} +abs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);} inline _LIBCPP_INLINE_VISIBILITY double -abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);} +abs(double __lcpp_x) _NOEXCEPT {return ::fabs(__lcpp_x);} inline _LIBCPP_INLINE_VISIBILITY long double -abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);} -#endif // !defined(_AIX) +abs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);} +#endif // !(defined(_AIX) || defined(__sun__)) // acos -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return acosf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return ::acosf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return ::acosl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);} +acos(_A1 __lcpp_x) _NOEXCEPT {return ::acos((double)__lcpp_x);} // asin -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {return asinf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {return ::asinf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return ::asinl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);} +asin(_A1 __lcpp_x) _NOEXCEPT {return ::asin((double)__lcpp_x);} // atan -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {return atanf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {return ::atanf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return ::atanl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);} +atan(_A1 __lcpp_x) _NOEXCEPT {return ::atan((double)__lcpp_x);} // atan2 -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT {return atan2f(__lcpp_y, __lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT {return ::atan2f(__lcpp_y, __lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return ::atan2l(__lcpp_y, __lcpp_x);} #endif template <class _A1, class _A2> @@ -710,86 +797,86 @@ atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x); + return ::atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x); } // ceil -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {return ceilf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {return ::ceilf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ::ceill(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);} +ceil(_A1 __lcpp_x) _NOEXCEPT {return ::ceil((double)__lcpp_x);} // cos -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {return cosf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return cosl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {return ::cosf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return ::cosl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -cos(_A1 __lcpp_x) _NOEXCEPT {return cos((double)__lcpp_x);} +cos(_A1 __lcpp_x) _NOEXCEPT {return ::cos((double)__lcpp_x);} // cosh -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {return coshf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return coshl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {return ::coshf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return ::coshl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -cosh(_A1 __lcpp_x) _NOEXCEPT {return cosh((double)__lcpp_x);} +cosh(_A1 __lcpp_x) _NOEXCEPT {return ::cosh((double)__lcpp_x);} // exp -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {return expf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return expl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {return ::expf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return ::expl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -exp(_A1 __lcpp_x) _NOEXCEPT {return exp((double)__lcpp_x);} +exp(_A1 __lcpp_x) _NOEXCEPT {return ::exp((double)__lcpp_x);} // fabs -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -fabs(_A1 __lcpp_x) _NOEXCEPT {return fabs((double)__lcpp_x);} +fabs(_A1 __lcpp_x) _NOEXCEPT {return ::fabs((double)__lcpp_x);} // floor -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {return floorf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return floorl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {return ::floorf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return ::floorl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -floor(_A1 __lcpp_x) _NOEXCEPT {return floor((double)__lcpp_x);} +floor(_A1 __lcpp_x) _NOEXCEPT {return ::floor((double)__lcpp_x);} // fmod -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fmodf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmodl(__lcpp_x, __lcpp_y);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fmodf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fmodl(__lcpp_x, __lcpp_y);} #endif template <class _A1, class _A2> @@ -805,69 +892,69 @@ fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // frexp -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpf(__lcpp_x, __lcpp_e);} -inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpl(__lcpp_x, __lcpp_e);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpf(__lcpp_x, __lcpp_e);} +inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexpl(__lcpp_x, __lcpp_e);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexp((double)__lcpp_x, __lcpp_e);} +frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return ::frexp((double)__lcpp_x, __lcpp_e);} // ldexp -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpf(__lcpp_x, __lcpp_e);} -inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpl(__lcpp_x, __lcpp_e);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpf(__lcpp_x, __lcpp_e);} +inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexpl(__lcpp_x, __lcpp_e);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexp((double)__lcpp_x, __lcpp_e);} +ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ::ldexp((double)__lcpp_x, __lcpp_e);} // log -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {return logf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return logl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {return ::logf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return ::logl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x);} +log(_A1 __lcpp_x) _NOEXCEPT {return ::log((double)__lcpp_x);} // log10 -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {return log10f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return log10l(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {return ::log10f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return ::log10l(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -log10(_A1 __lcpp_x) _NOEXCEPT {return log10((double)__lcpp_x);} +log10(_A1 __lcpp_x) _NOEXCEPT {return ::log10((double)__lcpp_x);} // modf -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT {return modff(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return modfl(__lcpp_x, __lcpp_y);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT {return ::modff(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return ::modfl(__lcpp_x, __lcpp_y);} #endif // pow -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return powf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return powl(__lcpp_x, __lcpp_y);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::powf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::powl(__lcpp_x, __lcpp_y);} #endif template <class _A1, class _A2> @@ -883,131 +970,119 @@ pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return pow((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::pow((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // sin -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {return sinf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return sinl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {return ::sinf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return ::sinl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -sin(_A1 __lcpp_x) _NOEXCEPT {return sin((double)__lcpp_x);} +sin(_A1 __lcpp_x) _NOEXCEPT {return ::sin((double)__lcpp_x);} // sinh -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {return sinhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return sinhl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {return ::sinhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return ::sinhl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -sinh(_A1 __lcpp_x) _NOEXCEPT {return sinh((double)__lcpp_x);} +sinh(_A1 __lcpp_x) _NOEXCEPT {return ::sinh((double)__lcpp_x);} // sqrt -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {return sqrtf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return sqrtl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {return ::sqrtf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return ::sqrtl(__lcpp_x);} #endif -#endif // __sun__ template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -sqrt(_A1 __lcpp_x) _NOEXCEPT {return sqrt((double)__lcpp_x);} -#ifndef __sun__ +sqrt(_A1 __lcpp_x) _NOEXCEPT {return ::sqrt((double)__lcpp_x);} // tan -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {return tanf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return tanl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {return ::tanf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return ::tanl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -tan(_A1 __lcpp_x) _NOEXCEPT {return tan((double)__lcpp_x);} +tan(_A1 __lcpp_x) _NOEXCEPT {return ::tan((double)__lcpp_x);} // tanh -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {return tanhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return tanhl(__lcpp_x);} +#if !(defined(_AIX) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {return ::tanhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return ::tanhl(__lcpp_x);} #endif template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -tanh(_A1 __lcpp_x) _NOEXCEPT {return tanh((double)__lcpp_x);} +tanh(_A1 __lcpp_x) _NOEXCEPT {return ::tanh((double)__lcpp_x);} // acosh -#ifndef _LIBCPP_MSVCRT -inline _LIBCPP_INLINE_VISIBILITY float acosh(float __lcpp_x) _NOEXCEPT {return acoshf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float acosh(float __lcpp_x) _NOEXCEPT {return ::acoshf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return ::acoshl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -acosh(_A1 __lcpp_x) _NOEXCEPT {return acosh((double)__lcpp_x);} -#endif +acosh(_A1 __lcpp_x) _NOEXCEPT {return ::acosh((double)__lcpp_x);} // asinh -#ifndef _LIBCPP_MSVCRT -inline _LIBCPP_INLINE_VISIBILITY float asinh(float __lcpp_x) _NOEXCEPT {return asinhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float asinh(float __lcpp_x) _NOEXCEPT {return ::asinhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return ::asinhl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -asinh(_A1 __lcpp_x) _NOEXCEPT {return asinh((double)__lcpp_x);} -#endif +asinh(_A1 __lcpp_x) _NOEXCEPT {return ::asinh((double)__lcpp_x);} // atanh -#ifndef _LIBCPP_MSVCRT -inline _LIBCPP_INLINE_VISIBILITY float atanh(float __lcpp_x) _NOEXCEPT {return atanhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float atanh(float __lcpp_x) _NOEXCEPT {return ::atanhf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return ::atanhl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -atanh(_A1 __lcpp_x) _NOEXCEPT {return atanh((double)__lcpp_x);} -#endif +atanh(_A1 __lcpp_x) _NOEXCEPT {return ::atanh((double)__lcpp_x);} // cbrt -#ifndef _LIBCPP_MSVCRT -inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __lcpp_x) _NOEXCEPT {return cbrtf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __lcpp_x) _NOEXCEPT {return ::cbrtf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return ::cbrtl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -cbrt(_A1 __lcpp_x) _NOEXCEPT {return cbrt((double)__lcpp_x);} -#endif +cbrt(_A1 __lcpp_x) _NOEXCEPT {return ::cbrt((double)__lcpp_x);} // copysign -#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12) inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x, float __lcpp_y) _NOEXCEPT { - return copysignf(__lcpp_x, __lcpp_y); + return ::copysignf(__lcpp_x, __lcpp_y); } inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT { - return copysignl(__lcpp_x, __lcpp_y); + return ::copysignl(__lcpp_x, __lcpp_y); } -#endif template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1022,55 +1097,53 @@ copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y); } -#ifndef _LIBCPP_MSVCRT - // erf -inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {return erff(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return erfl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {return ::erff(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return ::erfl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -erf(_A1 __lcpp_x) _NOEXCEPT {return erf((double)__lcpp_x);} +erf(_A1 __lcpp_x) _NOEXCEPT {return ::erf((double)__lcpp_x);} // erfc -inline _LIBCPP_INLINE_VISIBILITY float erfc(float __lcpp_x) _NOEXCEPT {return erfcf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return erfcl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float erfc(float __lcpp_x) _NOEXCEPT {return ::erfcf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return ::erfcl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -erfc(_A1 __lcpp_x) _NOEXCEPT {return erfc((double)__lcpp_x);} +erfc(_A1 __lcpp_x) _NOEXCEPT {return ::erfc((double)__lcpp_x);} // exp2 -inline _LIBCPP_INLINE_VISIBILITY float exp2(float __lcpp_x) _NOEXCEPT {return exp2f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return exp2l(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float exp2(float __lcpp_x) _NOEXCEPT {return ::exp2f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return ::exp2l(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -exp2(_A1 __lcpp_x) _NOEXCEPT {return exp2((double)__lcpp_x);} +exp2(_A1 __lcpp_x) _NOEXCEPT {return ::exp2((double)__lcpp_x);} // expm1 -inline _LIBCPP_INLINE_VISIBILITY float expm1(float __lcpp_x) _NOEXCEPT {return expm1f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return expm1l(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float expm1(float __lcpp_x) _NOEXCEPT {return ::expm1f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return ::expm1l(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -expm1(_A1 __lcpp_x) _NOEXCEPT {return expm1((double)__lcpp_x);} +expm1(_A1 __lcpp_x) _NOEXCEPT {return ::expm1((double)__lcpp_x);} // fdim -inline _LIBCPP_INLINE_VISIBILITY float fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fdimf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fdiml(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fdimf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fdiml(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1085,13 +1158,13 @@ fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // fma -inline _LIBCPP_INLINE_VISIBILITY float fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT {return fmaf(__lcpp_x, __lcpp_y, __lcpp_z);} -inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return fmal(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY float fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT {return ::fmaf(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return ::fmal(__lcpp_x, __lcpp_y, __lcpp_z);} template <class _A1, class _A2, class _A3> inline _LIBCPP_INLINE_VISIBILITY @@ -1108,13 +1181,13 @@ fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value && std::is_same<_A3, __result_type>::value)), ""); - return fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); + return ::fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); } // fmax -inline _LIBCPP_INLINE_VISIBILITY float fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fmaxf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmaxl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fmaxf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fmaxl(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1129,13 +1202,13 @@ fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // fmin -inline _LIBCPP_INLINE_VISIBILITY float fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fminf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fminl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::fminf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::fminl(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1150,13 +1223,13 @@ fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // hypot -inline _LIBCPP_INLINE_VISIBILITY float hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return hypotf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return hypotl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::hypotf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::hypotl(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1171,115 +1244,115 @@ hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // ilogb -inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT {return ilogbf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ilogbl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT {return ::ilogbf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ::ilogbl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, int>::type -ilogb(_A1 __lcpp_x) _NOEXCEPT {return ilogb((double)__lcpp_x);} +ilogb(_A1 __lcpp_x) _NOEXCEPT {return ::ilogb((double)__lcpp_x);} // lgamma -inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __lcpp_x) _NOEXCEPT {return lgammaf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return lgammal(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __lcpp_x) _NOEXCEPT {return ::lgammaf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return ::lgammal(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -lgamma(_A1 __lcpp_x) _NOEXCEPT {return lgamma((double)__lcpp_x);} +lgamma(_A1 __lcpp_x) _NOEXCEPT {return ::lgamma((double)__lcpp_x);} // llrint -inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT {return llrintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return llrintl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT {return ::llrintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return ::llrintl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, long long>::type -llrint(_A1 __lcpp_x) _NOEXCEPT {return llrint((double)__lcpp_x);} +llrint(_A1 __lcpp_x) _NOEXCEPT {return ::llrint((double)__lcpp_x);} // llround -inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT {return llroundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return llroundl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT {return ::llroundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return ::llroundl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, long long>::type -llround(_A1 __lcpp_x) _NOEXCEPT {return llround((double)__lcpp_x);} +llround(_A1 __lcpp_x) _NOEXCEPT {return ::llround((double)__lcpp_x);} // log1p -inline _LIBCPP_INLINE_VISIBILITY float log1p(float __lcpp_x) _NOEXCEPT {return log1pf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return log1pl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float log1p(float __lcpp_x) _NOEXCEPT {return ::log1pf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return ::log1pl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -log1p(_A1 __lcpp_x) _NOEXCEPT {return log1p((double)__lcpp_x);} +log1p(_A1 __lcpp_x) _NOEXCEPT {return ::log1p((double)__lcpp_x);} // log2 -inline _LIBCPP_INLINE_VISIBILITY float log2(float __lcpp_x) _NOEXCEPT {return log2f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return log2l(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float log2(float __lcpp_x) _NOEXCEPT {return ::log2f(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return ::log2l(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -log2(_A1 __lcpp_x) _NOEXCEPT {return log2((double)__lcpp_x);} +log2(_A1 __lcpp_x) _NOEXCEPT {return ::log2((double)__lcpp_x);} // logb -inline _LIBCPP_INLINE_VISIBILITY float logb(float __lcpp_x) _NOEXCEPT {return logbf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return logbl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float logb(float __lcpp_x) _NOEXCEPT {return ::logbf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return ::logbl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -logb(_A1 __lcpp_x) _NOEXCEPT {return logb((double)__lcpp_x);} +logb(_A1 __lcpp_x) _NOEXCEPT {return ::logb((double)__lcpp_x);} // lrint -inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT {return lrintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return lrintl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT {return ::lrintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return ::lrintl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, long>::type -lrint(_A1 __lcpp_x) _NOEXCEPT {return lrint((double)__lcpp_x);} +lrint(_A1 __lcpp_x) _NOEXCEPT {return ::lrint((double)__lcpp_x);} // lround -inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT {return lroundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return lroundl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT {return ::lroundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return ::lroundl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, long>::type -lround(_A1 __lcpp_x) _NOEXCEPT {return lround((double)__lcpp_x);} +lround(_A1 __lcpp_x) _NOEXCEPT {return ::lround((double)__lcpp_x);} // nan // nearbyint -inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __lcpp_x) _NOEXCEPT {return nearbyintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return nearbyintl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __lcpp_x) _NOEXCEPT {return ::nearbyintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return ::nearbyintl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -nearbyint(_A1 __lcpp_x) _NOEXCEPT {return nearbyint((double)__lcpp_x);} +nearbyint(_A1 __lcpp_x) _NOEXCEPT {return ::nearbyint((double)__lcpp_x);} // nextafter -inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return nextafterf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nextafterl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::nextafterf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nextafterl(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1294,23 +1367,23 @@ nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // nexttoward -inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttowardf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttowardl(__lcpp_x, __lcpp_y);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttoward((double)__lcpp_x, __lcpp_y);} +nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::nexttoward((double)__lcpp_x, __lcpp_y);} // remainder -inline _LIBCPP_INLINE_VISIBILITY float remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return remainderf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return remainderl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return ::remainderf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return ::remainderl(__lcpp_x, __lcpp_y);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1325,13 +1398,13 @@ remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y); + return ::remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y); } // remquo -inline _LIBCPP_INLINE_VISIBILITY float remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquof(__lcpp_x, __lcpp_y, __lcpp_z);} -inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquol(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY float remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT {return ::remquof(__lcpp_x, __lcpp_y, __lcpp_z);} +inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return ::remquol(__lcpp_x, __lcpp_y, __lcpp_z);} template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY @@ -1346,71 +1419,68 @@ remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT typedef typename std::__promote<_A1, _A2>::type __result_type; static_assert((!(std::is_same<_A1, __result_type>::value && std::is_same<_A2, __result_type>::value)), ""); - return remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z); + return ::remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z); } // rint -inline _LIBCPP_INLINE_VISIBILITY float rint(float __lcpp_x) _NOEXCEPT {return rintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return rintl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float rint(float __lcpp_x) _NOEXCEPT {return ::rintf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return ::rintl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -rint(_A1 __lcpp_x) _NOEXCEPT {return rint((double)__lcpp_x);} +rint(_A1 __lcpp_x) _NOEXCEPT {return ::rint((double)__lcpp_x);} // round -inline _LIBCPP_INLINE_VISIBILITY float round(float __lcpp_x) _NOEXCEPT {return roundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return roundl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float round(float __lcpp_x) _NOEXCEPT {return ::roundf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return ::roundl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -round(_A1 __lcpp_x) _NOEXCEPT {return round((double)__lcpp_x);} +round(_A1 __lcpp_x) _NOEXCEPT {return ::round((double)__lcpp_x);} // scalbln -inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalblnf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalblnl(__lcpp_x, __lcpp_y);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalbln((double)__lcpp_x, __lcpp_y);} +scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return ::scalbln((double)__lcpp_x, __lcpp_y);} // scalbn -inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnl(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbnf(__lcpp_x, __lcpp_y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbnl(__lcpp_x, __lcpp_y);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbn((double)__lcpp_x, __lcpp_y);} +scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return ::scalbn((double)__lcpp_x, __lcpp_y);} // tgamma -inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __lcpp_x) _NOEXCEPT {return tgammaf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return tgammal(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __lcpp_x) _NOEXCEPT {return ::tgammaf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return ::tgammal(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -tgamma(_A1 __lcpp_x) _NOEXCEPT {return tgamma((double)__lcpp_x);} +tgamma(_A1 __lcpp_x) _NOEXCEPT {return ::tgamma((double)__lcpp_x);} // trunc -inline _LIBCPP_INLINE_VISIBILITY float trunc(float __lcpp_x) _NOEXCEPT {return truncf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return truncl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float trunc(float __lcpp_x) _NOEXCEPT {return ::truncf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return ::truncl(__lcpp_x);} template <class _A1> inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<std::is_integral<_A1>::value, double>::type -trunc(_A1 __lcpp_x) _NOEXCEPT {return trunc((double)__lcpp_x);} - -#endif // !_LIBCPP_MSVCRT -#endif // __sun__ +trunc(_A1 __lcpp_x) _NOEXCEPT {return ::trunc((double)__lcpp_x);} } // extern "C++" diff --git a/lib/libcxx/include/memory b/lib/libcxx/include/memory index 7a3281e1793..d6b427b941b 100644 --- a/lib/libcxx/include/memory +++ b/lib/libcxx/include/memory @@ -18,7 +18,7 @@ namespace std { struct allocator_arg_t { }; -constexpr allocator_arg_t allocator_arg = allocator_arg_t(); +inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); template <class T, class Alloc> struct uses_allocator; @@ -46,6 +46,9 @@ struct pointer_traits<T*> static pointer pointer_to(<details>) noexcept; }; +template <class T> constexpr T* to_address(T* p) noexcept; // C++20 +template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20 + template <class Alloc> struct allocator_traits { @@ -81,8 +84,8 @@ struct allocator_traits template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; - static pointer allocate(allocator_type& a, size_type n); - static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); + static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20 + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; @@ -164,6 +167,7 @@ template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept template <class T> void return_temporary_buffer(T* p) noexcept; template <class T> T* addressof(T& r) noexcept; +template <class T> T* addressof(const T&& r) noexcept = delete; template <class InputIterator, class ForwardIterator> ForwardIterator @@ -180,10 +184,37 @@ template <class ForwardIterator, class Size, class T> ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x); -template <class Y> struct auto_ptr_ref {}; +template <class T> +void destroy_at(T* location); + +template <class ForwardIterator> + void destroy(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator destroy_n(ForwardIterator first, Size n); + +template <class InputIterator, class ForwardIterator> + ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); + +template <class InputIterator, class Size, class ForwardIterator> + pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); + +template <class ForwardIterator> + void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); + +template <class ForwardIterator> + void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); + +template <class ForwardIterator, class Size> + ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); + +template <class Y> struct auto_ptr_ref {}; // removed in C++17 template<class X> -class auto_ptr +class auto_ptr // removed in C++17 { public: typedef X element_type; @@ -242,7 +273,7 @@ public: template <class U, class E> unique_ptr(unique_ptr<U, E>&& u) noexcept; template <class U> - unique_ptr(auto_ptr<U>&& u) noexcept; + unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 // destructor ~unique_ptr(); @@ -356,6 +387,9 @@ template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); 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 E, class T, class Y, class D> + basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); + template<class T> class shared_ptr { @@ -376,7 +410,7 @@ public: shared_ptr(shared_ptr&& r) noexcept; template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); - template<class Y> shared_ptr(auto_ptr<Y>&& r); + template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); shared_ptr(nullptr_t) : shared_ptr() { } @@ -388,7 +422,7 @@ public: template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; shared_ptr& operator=(shared_ptr&& r) noexcept; template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); - template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); + template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); // modifiers: @@ -405,8 +439,8 @@ public: long use_count() const noexcept; bool unique() const noexcept; explicit operator bool() const noexcept; - template<class U> bool owner_before(shared_ptr<U> const& b) const; - template<class U> bool owner_before(weak_ptr<U> const& b) const; + template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; + template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; }; // shared_ptr comparisons: @@ -503,8 +537,8 @@ public: long use_count() const noexcept; bool expired() const noexcept; shared_ptr<T> lock() const noexcept; - template<class U> bool owner_before(shared_ptr<U> const& b) const; - template<class U> bool owner_before(weak_ptr<U> const& b) const; + template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; + template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; }; // weak_ptr specialized algorithms: @@ -518,9 +552,9 @@ struct owner_less<shared_ptr<T>> : binary_function<shared_ptr<T>, shared_ptr<T>, bool> { typedef bool result_type; - bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const; - bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; - bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; + bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; + bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; }; template<class T> @@ -528,9 +562,24 @@ struct owner_less<weak_ptr<T>> : binary_function<weak_ptr<T>, weak_ptr<T>, bool> { typedef bool result_type; - bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const; - bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const; - bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const; + bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; + bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; +}; + +template <> // Added in C++14 +struct owner_less<void> +{ + template <class _Tp, class _Up> + bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; + template <class _Tp, class _Up> + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; + + typedef void is_transparent; }; template<class T> @@ -582,6 +631,9 @@ template <class T> struct hash; template <class T, class D> struct hash<unique_ptr<T, D> >; template <class T> struct hash<shared_ptr<T> >; +template <class T, class Alloc> + inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; + // Pointer safety enum class pointer_safety { relaxed, preferred, strict }; void declare_reachable(void *p); @@ -610,21 +662,19 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); #include <tuple> #include <stdexcept> #include <cstring> -#if defined(_LIBCPP_NO_EXCEPTIONS) - #include <cassert> -#endif - +#include <cassert> #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) # include <atomic> #endif -#include <__undef_min_max> -#include <__undef___deallocate> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <class _ValueType> @@ -639,12 +689,24 @@ _ValueType __libcpp_relaxed_load(_ValueType const* __value) { #endif } -// addressof moved to <__functional_base> +template <class _ValueType> +inline _LIBCPP_ALWAYS_INLINE +_ValueType __libcpp_acquire_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ + defined(__ATOMIC_ACQUIRE) && \ + (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + return __atomic_load_n(__value, __ATOMIC_ACQUIRE); +#else + return *__value; +#endif +} + +// addressof moved to <type_traits> template <class _Tp> class allocator; template <> -class _LIBCPP_TYPE_VIS_ONLY allocator<void> +class _LIBCPP_TEMPLATE_VIS allocator<void> { public: typedef void* pointer; @@ -655,7 +717,7 @@ public: }; template <> -class _LIBCPP_TYPE_VIS_ONLY allocator<const void> +class _LIBCPP_TEMPLATE_VIS allocator<const void> { public: typedef const void* pointer; @@ -667,16 +729,12 @@ public: // pointer_traits +template <class _Tp, class = void> +struct __has_element_type : false_type {}; + template <class _Tp> -struct __has_element_type -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::element_type* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_element_type<_Tp, + typename __void_t<typename _Tp::element_type>::type> : true_type {}; template <class _Ptr, bool = __has_element_type<_Ptr>::value> struct __pointer_traits_element_type; @@ -755,16 +813,12 @@ struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false> #endif // _LIBCPP_HAS_NO_VARIADICS +template <class _Tp, class = void> +struct __has_difference_type : false_type {}; + template <class _Tp> -struct __has_difference_type -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::difference_type* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_difference_type<_Tp, + typename __void_t<typename _Tp::difference_type>::type> : true_type {}; template <class _Ptr, bool = __has_difference_type<_Ptr>::value> struct __pointer_traits_difference_type @@ -792,7 +846,7 @@ public: template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> struct __pointer_traits_rebind { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Tp::template rebind<_Up> type; #else typedef typename _Tp::template rebind<_Up>::other type; @@ -804,7 +858,7 @@ struct __pointer_traits_rebind template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up> struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; #else typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; @@ -822,7 +876,7 @@ struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> template <template <class> class _Sp, class _Tp, class _Up> struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Sp<_Tp>::template rebind<_Up> type; #else typedef typename _Sp<_Tp>::template rebind<_Up>::other type; @@ -838,7 +892,7 @@ struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false> template <template <class, class> class _Sp, class _Tp, class _A0, class _Up> struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type; #else typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type; @@ -855,7 +909,7 @@ template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1, class _Up> struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type; #else typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type; @@ -873,7 +927,7 @@ template <template <class, class, class, class> class _Sp, class _Tp, class _A0, class _A1, class _A2, class _Up> struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type; #else typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type; @@ -890,18 +944,18 @@ struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false> #endif // _LIBCPP_HAS_NO_VARIADICS template <class _Ptr> -struct _LIBCPP_TYPE_VIS_ONLY pointer_traits +struct _LIBCPP_TEMPLATE_VIS pointer_traits { typedef _Ptr pointer; typedef typename __pointer_traits_element_type<pointer>::type element_type; typedef typename __pointer_traits_difference_type<pointer>::type difference_type; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type; #else template <class _Up> struct rebind {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG private: struct __nat {}; @@ -913,13 +967,13 @@ public: }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*> +struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> { typedef _Tp* pointer; typedef _Tp element_type; typedef ptrdiff_t difference_type; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _Up> using rebind = _Up*; #else template <class _Up> struct rebind {typedef _Up* other;}; @@ -936,7 +990,7 @@ public: template <class _From, class _To> struct __rebind_pointer { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename pointer_traits<_From>::template rebind<_To> type; #else typedef typename pointer_traits<_From>::template rebind<_To>::other type; @@ -945,17 +999,12 @@ struct __rebind_pointer { // allocator_traits -namespace __has_pointer_type_imp -{ - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::pointer* = 0); -} +template <class _Tp, class = void> +struct __has_pointer_type : false_type {}; template <class _Tp> -struct __has_pointer_type - : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1> -{ -}; +struct __has_pointer_type<_Tp, + typename __void_t<typename _Tp::pointer>::type> : true_type {}; namespace __pointer_type_imp { @@ -980,16 +1029,12 @@ struct __pointer_type typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; }; +template <class _Tp, class = void> +struct __has_const_pointer : false_type {}; + template <class _Tp> -struct __has_const_pointer -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::const_pointer* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_const_pointer<_Tp, + typename __void_t<typename _Tp::const_pointer>::type> : true_type {}; template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> struct __const_pointer @@ -1000,23 +1045,19 @@ struct __const_pointer template <class _Tp, class _Ptr, class _Alloc> struct __const_pointer<_Tp, _Ptr, _Alloc, false> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; #else typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; #endif }; +template <class _Tp, class = void> +struct __has_void_pointer : false_type {}; + template <class _Tp> -struct __has_void_pointer -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::void_pointer* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_void_pointer<_Tp, + typename __void_t<typename _Tp::void_pointer>::type> : true_type {}; template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> struct __void_pointer @@ -1027,23 +1068,19 @@ struct __void_pointer template <class _Ptr, class _Alloc> struct __void_pointer<_Ptr, _Alloc, false> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename pointer_traits<_Ptr>::template rebind<void> type; #else typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; #endif }; +template <class _Tp, class = void> +struct __has_const_void_pointer : false_type {}; + template <class _Tp> -struct __has_const_void_pointer -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::const_void_pointer* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_const_void_pointer<_Tp, + typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {}; template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> struct __const_void_pointer @@ -1054,7 +1091,7 @@ struct __const_void_pointer template <class _Ptr, class _Alloc> struct __const_void_pointer<_Ptr, _Alloc, false> { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename pointer_traits<_Ptr>::template rebind<const void> type; #else typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; @@ -1062,13 +1099,14 @@ struct __const_void_pointer<_Ptr, _Alloc, false> }; template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp* __to_raw_pointer(_Tp* __p) _NOEXCEPT { return __p; } +#if _LIBCPP_STD_VER <= 17 template <class _Pointer> inline _LIBCPP_INLINE_VISIBILITY typename pointer_traits<_Pointer>::element_type* @@ -1076,17 +1114,48 @@ __to_raw_pointer(_Pointer __p) _NOEXCEPT { return _VSTD::__to_raw_pointer(__p.operator->()); } +#else +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p) _NOEXCEPT +-> decltype(pointer_traits<_Pointer>::to_address(__p)) +{ + return pointer_traits<_Pointer>::to_address(__p); +} + +template <class _Pointer, class... _None> +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p.operator->()); +} template <class _Tp> -struct __has_size_type +inline _LIBCPP_INLINE_VISIBILITY constexpr +_Tp* +to_address(_Tp* __p) _NOEXCEPT { -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::size_type* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; + static_assert(!is_function_v<_Tp>, "_Tp is a function type"); + return __p; +} + +template <class _Pointer> +inline _LIBCPP_INLINE_VISIBILITY +auto +to_address(const _Pointer& __p) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p); +} +#endif + +template <class _Tp, class = void> +struct __has_size_type : false_type {}; + +template <class _Tp> +struct __has_size_type<_Tp, + typename __void_t<typename _Tp::size_type>::type> : true_type {}; template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> struct __size_type @@ -1100,16 +1169,13 @@ struct __size_type<_Alloc, _DiffType, true> typedef typename _Alloc::size_type type; }; +template <class _Tp, class = void> +struct __has_propagate_on_container_copy_assignment : false_type {}; + template <class _Tp> -struct __has_propagate_on_container_copy_assignment -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_propagate_on_container_copy_assignment<_Tp, + typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type> + : true_type {}; template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> struct __propagate_on_container_copy_assignment @@ -1123,16 +1189,13 @@ struct __propagate_on_container_copy_assignment<_Alloc, true> typedef typename _Alloc::propagate_on_container_copy_assignment type; }; +template <class _Tp, class = void> +struct __has_propagate_on_container_move_assignment : false_type {}; + template <class _Tp> -struct __has_propagate_on_container_move_assignment -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_propagate_on_container_move_assignment<_Tp, + typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type> + : true_type {}; template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value> struct __propagate_on_container_move_assignment @@ -1146,16 +1209,13 @@ struct __propagate_on_container_move_assignment<_Alloc, true> typedef typename _Alloc::propagate_on_container_move_assignment type; }; +template <class _Tp, class = void> +struct __has_propagate_on_container_swap : false_type {}; + template <class _Tp> -struct __has_propagate_on_container_swap -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_propagate_on_container_swap<_Tp, + typename __void_t<typename _Tp::propagate_on_container_swap>::type> + : true_type {}; template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value> struct __propagate_on_container_swap @@ -1169,16 +1229,13 @@ struct __propagate_on_container_swap<_Alloc, true> typedef typename _Alloc::propagate_on_container_swap type; }; +template <class _Tp, class = void> +struct __has_is_always_equal : false_type {}; + template <class _Tp> -struct __has_is_always_equal -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::is_always_equal* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; +struct __has_is_always_equal<_Tp, + typename __void_t<typename _Tp::is_always_equal>::type> + : true_type {}; template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> struct __is_always_equal @@ -1285,12 +1342,12 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> #endif // _LIBCPP_HAS_NO_VARIADICS -#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#ifndef _LIBCPP_CXX03_LANG template <class _Alloc, class _SizeType, class _ConstVoidPtr> auto __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) - -> decltype(__a.allocate(__sz, __p), true_type()); + -> decltype((void)__a.allocate(__sz, __p), true_type()); template <class _Alloc, class _SizeType, class _ConstVoidPtr> auto @@ -1301,14 +1358,14 @@ template <class _Alloc, class _SizeType, class _ConstVoidPtr> struct __has_allocate_hint : integral_constant<bool, is_same< - decltype(__has_allocate_hint_test(declval<_Alloc>(), + decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), declval<_SizeType>(), declval<_ConstVoidPtr>())), true_type>::value> { }; -#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#else // _LIBCPP_CXX03_LANG template <class _Alloc, class _SizeType, class _ConstVoidPtr> struct __has_allocate_hint @@ -1316,9 +1373,9 @@ struct __has_allocate_hint { }; -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif // _LIBCPP_CXX03_LANG -#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#if !defined(_LIBCPP_CXX03_LANG) template <class _Alloc, class _Tp, class ..._Args> decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(), @@ -1334,7 +1391,7 @@ template <class _Alloc, class _Pointer, class ..._Args> struct __has_construct : integral_constant<bool, is_same< - decltype(__has_construct_test(declval<_Alloc>(), + decltype(_VSTD::__has_construct_test(declval<_Alloc>(), declval<_Pointer>(), declval<_Args>()...)), true_type>::value> @@ -1355,7 +1412,7 @@ template <class _Alloc, class _Pointer> struct __has_destroy : integral_constant<bool, is_same< - decltype(__has_destroy_test(declval<_Alloc>(), + decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), declval<_Pointer>())), true_type>::value> { @@ -1375,7 +1432,7 @@ template <class _Alloc> struct __has_max_size : integral_constant<bool, is_same< - decltype(__has_max_size_test(declval<_Alloc&>())), + decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())), true_type>::value> { }; @@ -1394,12 +1451,12 @@ template <class _Alloc> struct __has_select_on_container_copy_construction : integral_constant<bool, is_same< - decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())), + decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())), true_type>::value> { }; -#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#else // _LIBCPP_CXX03_LANG #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -1437,7 +1494,7 @@ struct __has_select_on_container_copy_construction { }; -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif // _LIBCPP_CXX03_LANG template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> struct __alloc_traits_difference_type @@ -1452,7 +1509,7 @@ struct __alloc_traits_difference_type<_Alloc, _Ptr, true> }; template <class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY allocator_traits +struct _LIBCPP_TEMPLATE_VIS allocator_traits { typedef _Alloc allocator_type; typedef typename allocator_type::value_type value_type; @@ -1474,23 +1531,23 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits typedef typename __is_always_equal<allocator_type>::type is_always_equal; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> using rebind_alloc = typename __allocator_traits_rebind<allocator_type, _Tp>::type; template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else // _LIBCPP_CXX03_LANG template <class _Tp> struct rebind_alloc {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; template <class _Tp> struct rebind_traits {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n) {return __a.allocate(__n);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) - {return allocate(__a, __n, __hint, + {return __allocate(__a, __n, __hint, __has_allocate_hint<allocator_type, size_type, const_void_pointer>());} _LIBCPP_INLINE_VISIBILITY @@ -1506,26 +1563,26 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits #else // _LIBCPP_HAS_NO_VARIADICS template <class _Tp> _LIBCPP_INLINE_VISIBILITY - static void construct(allocator_type& __a, _Tp* __p) + static void construct(allocator_type&, _Tp* __p) { ::new ((void*)__p) _Tp(); } template <class _Tp, class _A0> _LIBCPP_INLINE_VISIBILITY - static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) + static void construct(allocator_type&, _Tp* __p, const _A0& __a0) { ::new ((void*)__p) _Tp(__a0); } template <class _Tp, class _A0, class _A1> _LIBCPP_INLINE_VISIBILITY - static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, + static void construct(allocator_type&, _Tp* __p, const _A0& __a0, const _A1& __a1) { ::new ((void*)__p) _Tp(__a0, __a1); } template <class _Tp, class _A0, class _A1, class _A2> _LIBCPP_INLINE_VISIBILITY - static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0, + static void construct(allocator_type&, _Tp* __p, const _A0& __a0, const _A1& __a1, const _A2& __a2) { ::new ((void*)__p) _Tp(__a0, __a1, __a2); @@ -1544,7 +1601,7 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits _LIBCPP_INLINE_VISIBILITY static allocator_type select_on_container_copy_construction(const allocator_type& __a) - {return select_on_container_copy_construction( + {return __select_on_container_copy_construction( __has_select_on_container_copy_construction<const allocator_type>(), __a);} @@ -1568,7 +1625,7 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits is_trivially_move_constructible<_Tp>::value, void >::type - __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) + __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) { ptrdiff_t _Np = __end1 - __begin1; if (_Np > 0) @@ -1598,7 +1655,7 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits is_trivially_move_constructible<_Tp>::value, void >::type - __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) + __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) { typedef typename remove_const<_Tp>::type _Vp; ptrdiff_t _Np = __end1 - __begin1; @@ -1632,7 +1689,7 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits is_trivially_move_constructible<_Tp>::value, void >::type - __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) + __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) { ptrdiff_t _Np = __end1 - __begin1; __end2 -= _Np; @@ -1643,11 +1700,11 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits private: _LIBCPP_INLINE_VISIBILITY - static pointer allocate(allocator_type& __a, size_type __n, + static pointer __allocate(allocator_type& __a, size_type __n, const_void_pointer __hint, true_type) {return __a.allocate(__n, __hint);} _LIBCPP_INLINE_VISIBILITY - static pointer allocate(allocator_type& __a, size_type __n, + static pointer __allocate(allocator_type& __a, size_type __n, const_void_pointer, false_type) {return __a.allocate(__n);} @@ -1676,26 +1733,26 @@ private: } _LIBCPP_INLINE_VISIBILITY - static size_type __max_size(true_type, const allocator_type& __a) + static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT {return __a.max_size();} _LIBCPP_INLINE_VISIBILITY - static size_type __max_size(false_type, const allocator_type&) + static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT {return numeric_limits<size_type>::max() / sizeof(value_type);} _LIBCPP_INLINE_VISIBILITY static allocator_type - select_on_container_copy_construction(true_type, const allocator_type& __a) + __select_on_container_copy_construction(true_type, const allocator_type& __a) {return __a.select_on_container_copy_construction();} _LIBCPP_INLINE_VISIBILITY static allocator_type - select_on_container_copy_construction(false_type, const allocator_type& __a) + __select_on_container_copy_construction(false_type, const allocator_type& __a) {return __a;} }; template <class _Traits, class _Tp> struct __rebind_alloc_helper { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Traits::template rebind_alloc<_Tp> type; #else typedef typename _Traits::template rebind_alloc<_Tp>::other type; @@ -1705,7 +1762,7 @@ struct __rebind_alloc_helper // allocator template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY allocator +class _LIBCPP_TEMPLATE_VIS allocator { public: typedef size_t size_type; @@ -1727,15 +1784,16 @@ public: {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} - _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + pointer allocate(size_type __n, allocator<void>::const_pointer = 0) { if (__n > max_size()) - __libcpp_throw(length_error("allocator<T>::allocate(size_t n)" - " 'n' exceeds maximum supported size")); + __throw_length_error("allocator<T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp))); } _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT - {_VSTD::__deallocate((void*)__p);} + {_VSTD::__libcpp_deallocate((void*)__p);} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);} #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -1803,7 +1861,7 @@ public: }; template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp> +class _LIBCPP_TEMPLATE_VIS allocator<const _Tp> { public: typedef size_t size_type; @@ -1826,12 +1884,12 @@ public: _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) { if (__n > max_size()) - __libcpp_throw(length_error("allocator<const T>::allocate(size_t n)" - " 'n' exceeds maximum supported size")); + __throw_length_error("allocator<const T>::allocate(size_t n)" + " 'n' exceeds maximum supported size"); return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp))); } _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT - {_VSTD::__deallocate((void*)__p);} + {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);} #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -1847,7 +1905,7 @@ public: void construct(pointer __p) { - ::new((void*)__p) _Tp(); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(); } # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) @@ -1856,14 +1914,14 @@ public: void construct(pointer __p, _A0& __a0) { - ::new((void*)__p) _Tp(__a0); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); } template <class _A0> _LIBCPP_INLINE_VISIBILITY void construct(pointer __p, const _A0& __a0) { - ::new((void*)__p) _Tp(__a0); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0); } # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) template <class _A0, class _A1> @@ -1871,28 +1929,28 @@ public: void construct(pointer __p, _A0& __a0, _A1& __a1) { - ::new((void*)__p) _Tp(__a0, __a1); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); } template <class _A0, class _A1> _LIBCPP_INLINE_VISIBILITY void construct(pointer __p, const _A0& __a0, _A1& __a1) { - ::new((void*)__p) _Tp(__a0, __a1); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); } template <class _A0, class _A1> _LIBCPP_INLINE_VISIBILITY void construct(pointer __p, _A0& __a0, const _A1& __a1) { - ::new((void*)__p) _Tp(__a0, __a1); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); } template <class _A0, class _A1> _LIBCPP_INLINE_VISIBILITY void construct(pointer __p, const _A0& __a0, const _A1& __a1) { - ::new((void*)__p) _Tp(__a0, __a1); + ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1); } #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();} @@ -1907,7 +1965,7 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} template <class _OutputIterator, class _Tp> -class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator +class _LIBCPP_TEMPLATE_VIS raw_storage_iterator : public iterator<output_iterator_tag, _Tp, // purposefully not C++03 ptrdiff_t, // purposefully not C++03 @@ -1929,7 +1987,7 @@ public: _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) {raw_storage_iterator __t(*this); ++__x_; return __t;} #if _LIBCPP_STD_VER >= 14 - _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } + _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } #endif }; @@ -1960,6 +2018,7 @@ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);} +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template <class _Tp> struct auto_ptr_ref { @@ -1967,7 +2026,7 @@ struct auto_ptr_ref }; template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY auto_ptr +class _LIBCPP_TEMPLATE_VIS auto_ptr { private: _Tp* __ptr_; @@ -2011,961 +2070,830 @@ public: }; template <> -class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void> +class _LIBCPP_TEMPLATE_VIS auto_ptr<void> { public: typedef void element_type; }; +#endif -template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type, - typename remove_cv<_T2>::type>::value, - bool = is_empty<_T1>::value - && !__libcpp_is_final<_T1>::value, - bool = is_empty<_T2>::value - && !__libcpp_is_final<_T2>::value - > -struct __libcpp_compressed_pair_switch; +template <class _Tp, int _Idx, + bool _CanBeEmptyBase = + is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value> +struct __compressed_pair_elem { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {} + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit + __compressed_pair_elem(_Up&& __u) + : __value_(_VSTD::forward<_Up>(__u)){}; + + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#else + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY + __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} +#endif -template <class _T1, class _T2, bool IsSame> -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};}; + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return __value_; } -template <class _T1, class _T2, bool IsSame> -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};}; +private: + _Tp __value_; +}; + +template <class _Tp, int _Idx> +struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { + typedef _Tp _ParamT; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp __value_type; + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default; + + template <class _Up, class = typename enable_if< + !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit + __compressed_pair_elem(_Up&& __u) + : __value_type(_VSTD::forward<_Up>(__u)){}; + + template <class... _Args, size_t... _Indexes> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, + __tuple_indices<_Indexes...>) + : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} +#else + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {} + _LIBCPP_INLINE_VISIBILITY + __compressed_pair_elem(_ParamT __p) + : __value_type(std::forward<_ParamT>(__p)) {} +#endif -template <class _T1, class _T2, bool IsSame> -struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};}; + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY + const_reference __get() const _NOEXCEPT { return *this; } +}; -template <class _T1, class _T2> -struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};}; +// Tag used to construct the second element of the compressed pair. +struct __second_tag {}; template <class _T1, class _T2> -struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};}; - -template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value> -class __libcpp_compressed_pair_imp; +class __compressed_pair : private __compressed_pair_elem<_T1, 0>, + private __compressed_pair_elem<_T2, 1> { + typedef __compressed_pair_elem<_T1, 0> _Base1; + typedef __compressed_pair_elem<_T2, 1> _Base2; + + // NOTE: This static assert should never fire because __compressed_pair + // is *almost never* used in a scenario where it's possible for T1 == T2. + // (The exception is std::function where it is possible that the function + // object and the allocator have the same type). + static_assert((!is_same<_T1, _T2>::value), + "__compressed_pair cannot be instantated when T1 and T2 are the same type; " + "The current implementation is NOT ABI-compatible with the previous " + "implementation for this configuration"); -template <class _T1, class _T2> -class __libcpp_compressed_pair_imp<_T1, _T2, 0> -{ -private: - _T1 __first_; - _T2 __second_; public: - typedef _T1 _T1_param; - typedef _T2 _T2_param; - - typedef typename remove_reference<_T1>::type& _T1_reference; - typedef typename remove_reference<_T2>::type& _T2_reference; - - typedef const typename remove_reference<_T1>::type& _T1_const_reference; - typedef const typename remove_reference<_T2>::type& _T2_const_reference; - - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) - : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {} - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) - : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} - -#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && - is_nothrow_copy_constructible<_T2>::value) - : __first_(__p.first()), - __second_(__p.second()) {} - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && - is_nothrow_copy_assignable<_T2>::value) - { - __first_ = __p.first(); - __second_ = __p.second(); - return *this; - } +#ifndef _LIBCPP_CXX03_LANG + template <bool _Dummy = true, + class = typename enable_if< + __dependent_type<is_default_constructible<_T1>, _Dummy>::value && + __dependent_type<is_default_constructible<_T2>, _Dummy>::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + constexpr __compressed_pair() {} + + template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type, + __compressed_pair>::value, + bool>::type = true> + _LIBCPP_INLINE_VISIBILITY constexpr explicit + __compressed_pair(_Tp&& __t) + : _Base1(std::forward<_Tp>(__t)), _Base2() {} + + template <class _Tp> + _LIBCPP_INLINE_VISIBILITY constexpr + __compressed_pair(__second_tag, _Tp&& __t) + : _Base1(), _Base2(std::forward<_Tp>(__t)) {} + + template <class _U1, class _U2> + _LIBCPP_INLINE_VISIBILITY constexpr + __compressed_pair(_U1&& __t1, _U2&& __t2) + : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} + + template <class... _Args1, class... _Args2> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, + tuple<_Args2...> __second_args) + : _Base1(__pc, _VSTD::move(__first_args), + typename __make_tuple_indices<sizeof...(_Args1)>::type()), + _Base2(__pc, _VSTD::move(__second_args), + typename __make_tuple_indices<sizeof...(_Args2)>::type()) {} - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : __first_(_VSTD::forward<_T1>(__p.first())), - __second_(_VSTD::forward<_T2>(__p.second())) {} +#else + _LIBCPP_INLINE_VISIBILITY + __compressed_pair() {} - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && - is_nothrow_move_assignable<_T2>::value) - { - __first_ = _VSTD::forward<_T1>(__p.first()); - __second_ = _VSTD::forward<_T2>(__p.second()); - return *this; - } + _LIBCPP_INLINE_VISIBILITY explicit + __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {} -#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + _LIBCPP_INLINE_VISIBILITY + __compressed_pair(__second_tag, _T2 __t2) + : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {} -#ifndef _LIBCPP_HAS_NO_VARIADICS + _LIBCPP_INLINE_VISIBILITY + __compressed_pair(_T1 __t1, _T2 __t2) + : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {} +#endif - template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(piecewise_construct_t __pc, - tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args, - __tuple_indices<_I1...>, - __tuple_indices<_I2...>) - : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), - __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) - {} + _LIBCPP_INLINE_VISIBILITY + typename _Base1::reference first() _NOEXCEPT { + return static_cast<_Base1&>(*this).__get(); + } -#endif // _LIBCPP_HAS_NO_VARIADICS + _LIBCPP_INLINE_VISIBILITY + typename _Base1::const_reference first() const _NOEXCEPT { + return static_cast<_Base1 const&>(*this).__get(); + } - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} - _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} + _LIBCPP_INLINE_VISIBILITY + typename _Base2::reference second() _NOEXCEPT { + return static_cast<_Base2&>(*this).__get(); + } - _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} - _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} + _LIBCPP_INLINE_VISIBILITY + typename _Base2::const_reference second() const _NOEXCEPT { + return static_cast<_Base2 const&>(*this).__get(); + } - _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { - using _VSTD::swap; - swap(__first_, __x.__first_); - swap(__second_, __x.__second_); - } + _LIBCPP_INLINE_VISIBILITY + void swap(__compressed_pair& __x) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value) + { + using std::swap; + swap(first(), __x.first()); + swap(second(), __x.second()); + } }; template <class _T1, class _T2> -class __libcpp_compressed_pair_imp<_T1, _T2, 1> - : private _T1 -{ -private: - _T2 __second_; -public: - typedef _T1 _T1_param; - typedef _T2 _T2_param; - - typedef _T1& _T1_reference; - typedef typename remove_reference<_T2>::type& _T2_reference; - - typedef const _T1& _T1_const_reference; - typedef const typename remove_reference<_T2>::type& _T2_const_reference; - - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) - : __second_(_VSTD::forward<_T2_param>(__t2)) {} - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) - : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {} - -#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && - is_nothrow_copy_constructible<_T2>::value) - : _T1(__p.first()), __second_(__p.second()) {} - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && - is_nothrow_copy_assignable<_T2>::value) - { - _T1::operator=(__p.first()); - __second_ = __p.second(); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {} - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && - is_nothrow_move_assignable<_T2>::value) - { - _T1::operator=(_VSTD::move(__p.first())); - __second_ = _VSTD::forward<_T2>(__p.second()); - return *this; - } - -#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) - -#ifndef _LIBCPP_HAS_NO_VARIADICS - - template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(piecewise_construct_t __pc, - tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args, - __tuple_indices<_I1...>, - __tuple_indices<_I2...>) - : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), - __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) - {} - -#endif // _LIBCPP_HAS_NO_VARIADICS - - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} - _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} +inline _LIBCPP_INLINE_VISIBILITY +void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && + __is_nothrow_swappable<_T2>::value) { + __x.swap(__y); +} - _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;} - _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;} +// default_delete - _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { - using _VSTD::swap; - swap(__second_, __x.__second_); - } +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS default_delete { + static_assert(!is_function<_Tp>::value, + "default_delete cannot be instantiated for function types"); +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up>&, + typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = + 0) _NOEXCEPT {} + + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete incomplete type"); + delete __ptr; + } }; -template <class _T1, class _T2> -class __libcpp_compressed_pair_imp<_T1, _T2, 2> - : private _T2 -{ +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> { private: - _T1 __first_; -public: - typedef _T1 _T1_param; - typedef _T2 _T2_param; - - typedef typename remove_reference<_T1>::type& _T1_reference; - typedef _T2& _T2_reference; - - typedef const typename remove_reference<_T1>::type& _T1_const_reference; - typedef const _T2& _T2_const_reference; - - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : __first_(_VSTD::forward<_T1_param>(__t1)) {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) - : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {} - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {} - -#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + template <class _Up> + struct _EnableIfConvertible + : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && - is_nothrow_copy_constructible<_T2>::value) - : _T2(__p.second()), __first_(__p.first()) {} - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && - is_nothrow_copy_assignable<_T2>::value) - { - _T2::operator=(__p.second()); - __first_ = __p.first(); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {} - - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && - is_nothrow_move_assignable<_T2>::value) - { - _T2::operator=(_VSTD::forward<_T2>(__p.second())); - __first_ = _VSTD::move(__p.first()); - return *this; - } - -#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +public: +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; +#else + _LIBCPP_INLINE_VISIBILITY default_delete() {} +#endif -#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + default_delete(const default_delete<_Up[]>&, + typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {} + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + typename _EnableIfConvertible<_Up>::type + operator()(_Up* __ptr) const _NOEXCEPT { + static_assert(sizeof(_Tp) > 0, + "default_delete can not delete incomplete type"); + static_assert(!is_void<_Tp>::value, + "default_delete can not delete void type"); + delete[] __ptr; + } +}; - template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(piecewise_construct_t __pc, - tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args, - __tuple_indices<_I1...>, - __tuple_indices<_I2...>) - : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...), - __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...) - - {} -#endif // _LIBCPP_HAS_NO_VARIADICS - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;} - _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;} +#ifndef _LIBCPP_CXX03_LANG +template <class _Deleter> +struct __unique_ptr_deleter_sfinae { + static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); + typedef const _Deleter& __lval_ref_type; + typedef _Deleter&& __good_rval_ref_type; + typedef true_type __enable_rval_overload; +}; - _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} - _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter const&> { + typedef const _Deleter& __lval_ref_type; + typedef const _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; +}; - _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { - using _VSTD::swap; - swap(__first_, __x.__first_); - } +template <class _Deleter> +struct __unique_ptr_deleter_sfinae<_Deleter&> { + typedef _Deleter& __lval_ref_type; + typedef _Deleter&& __bad_rval_ref_type; + typedef false_type __enable_rval_overload; }; +#endif // !defined(_LIBCPP_CXX03_LANG) -template <class _T1, class _T2> -class __libcpp_compressed_pair_imp<_T1, _T2, 3> - : private _T1, - private _T2 -{ +template <class _Tp, class _Dp = default_delete<_Tp> > +class _LIBCPP_TEMPLATE_VIS unique_ptr { public: - typedef _T1 _T1_param; - typedef _T2 _T2_param; - - typedef _T1& _T1_reference; - typedef _T2& _T2_reference; + typedef _Tp element_type; + typedef _Dp deleter_type; + typedef typename __pointer_type<_Tp, deleter_type>::type pointer; - typedef const _T1& _T1_const_reference; - typedef const _T2& _T2_const_reference; + static_assert(!is_rvalue_reference<deleter_type>::value, + "the specified deleter type cannot be an rvalue reference"); - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : _T1(_VSTD::forward<_T1_param>(__t1)) {} - _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) - : _T2(_VSTD::forward<_T2_param>(__t2)) {} - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) - : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {} +private: + __compressed_pair<pointer, deleter_type> __ptr_; -#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + struct __nat { int __for_bool_; }; - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && - is_nothrow_copy_constructible<_T2>::value) - : _T1(__p.first()), _T2(__p.second()) {} +#ifndef _LIBCPP_CXX03_LANG + typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p) - _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && - is_nothrow_copy_assignable<_T2>::value) - { - _T1::operator=(__p.first()); - _T2::operator=(__p.second()); - return *this; - } + template <bool _Dummy> + using _LValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {} + template <bool _Dummy> + using _GoodRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p) - _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && - is_nothrow_move_assignable<_T2>::value) - { - _T1::operator=(_VSTD::move(__p.first())); - _T2::operator=(_VSTD::move(__p.second())); - return *this; - } + template <bool _Dummy> + using _BadRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; -#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; -#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class _ArgType> + using _EnableIfDeleterConstructible = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; - template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> - _LIBCPP_INLINE_VISIBILITY - __libcpp_compressed_pair_imp(piecewise_construct_t __pc, - tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args, - __tuple_indices<_I1...>, - __tuple_indices<_I2...>) - : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...), - _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) - {} + template <class _UPtr, class _Up> + using _EnableIfMoveConvertible = typename enable_if< + is_convertible<typename _UPtr::pointer, pointer>::value && + !is_array<_Up>::value + >::type; -#endif // _LIBCPP_HAS_NO_VARIADICS + template <class _UDel> + using _EnableIfDeleterConvertible = typename enable_if< + (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) + >::type; - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;} - _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;} + template <class _UDel> + using _EnableIfDeleterAssignable = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; - _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;} - _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;} - - _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - { - } -}; - -template <class _T1, class _T2> -class __compressed_pair - : private __libcpp_compressed_pair_imp<_T1, _T2> -{ - typedef __libcpp_compressed_pair_imp<_T1, _T2> base; public: - typedef typename base::_T1_param _T1_param; - typedef typename base::_T2_param _T2_param; - - typedef typename base::_T1_reference _T1_reference; - typedef typename base::_T2_reference _T2_reference; + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(__p, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } - typedef typename base::_T1_const_reference _T1_const_reference; - typedef typename base::_T2_const_reference _T2_const_reference; + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; - _LIBCPP_INLINE_VISIBILITY __compressed_pair() {} - _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1) - : base(_VSTD::forward<_T1_param>(__t1)) {} - _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2) - : base(_VSTD::forward<_T2_param>(__t2)) {} - _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2) - : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } -#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT + : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(auto_ptr<_Up>&& __p, + typename enable_if<is_convertible<_Up*, _Tp*>::value && + is_same<_Dp, default_delete<_Tp>>::value, + __nat>::type = __nat()) _NOEXCEPT + : __ptr_(__p.release()) {} +#endif - _LIBCPP_INLINE_VISIBILITY - __compressed_pair(const __compressed_pair& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value && - is_nothrow_copy_constructible<_T2>::value) - : base(__p) {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } - _LIBCPP_INLINE_VISIBILITY - __compressed_pair& operator=(const __compressed_pair& __p) - _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value && - is_nothrow_copy_assignable<_T2>::value) - { - base::operator=(__p); - return *this; - } + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } - _LIBCPP_INLINE_VISIBILITY - __compressed_pair(__compressed_pair&& __p) - _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && - is_nothrow_move_constructible<_T2>::value) - : base(_VSTD::move(__p)) {} +#else // _LIBCPP_CXX03_LANG +private: + unique_ptr(unique_ptr&); + template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&); - _LIBCPP_INLINE_VISIBILITY - __compressed_pair& operator=(__compressed_pair&& __p) - _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value && - is_nothrow_move_assignable<_T2>::value) - { - base::operator=(_VSTD::move(__p)); - return *this; - } + unique_ptr& operator=(unique_ptr&); + template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&); -#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) +public: + _LIBCPP_INLINE_VISIBILITY + unique_ptr() : __ptr_(pointer()) + { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + static_assert(is_default_constructible<deleter_type>::value, + "unique_ptr::deleter_type is not default constructible"); + } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t) : __ptr_(pointer()) + { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) + : __ptr_(_VSTD::move(__p)) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } -#ifndef _LIBCPP_HAS_NO_VARIADICS + _LIBCPP_INLINE_VISIBILITY + operator __rv<unique_ptr>() { + return __rv<unique_ptr>(*this); + } - template <class... _Args1, class... _Args2> - _LIBCPP_INLINE_VISIBILITY - __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) - : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args), - typename __make_tuple_indices<sizeof...(_Args1)>::type(), - typename __make_tuple_indices<sizeof...(_Args2) >::type()) - {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr(__rv<unique_ptr> __u) + : __ptr_(__u->release(), + _VSTD::forward<deleter_type>(__u->get_deleter())) {} + + template <class _Up, class _Ep> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + !is_array<_Up>::value && + is_convertible<typename unique_ptr<_Up, _Ep>::pointer, + pointer>::value && + is_assignable<deleter_type&, _Ep&>::value, + unique_ptr&>::type + operator=(unique_ptr<_Up, _Ep> __u) { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } -#endif // _LIBCPP_HAS_NO_VARIADICS + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, deleter_type __d) + : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + typename enable_if<is_convertible<_Up*, _Tp*>::value && + is_same<_Dp, default_delete<_Tp> >::value, + unique_ptr&>::type + operator=(auto_ptr<_Up> __p) { + reset(__p.release()); + return *this; + } +#endif - _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();} - _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();} + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } - _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();} - _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();} + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } - _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - {base::swap(__x);} -}; + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator*() const { + return *__ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } -template <class _T1, class _T2> -inline _LIBCPP_INLINE_VISIBILITY -void -swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) - _NOEXCEPT_(__is_nothrow_swappable<_T1>::value && - __is_nothrow_swappable<_T2>::value) - {__x.swap(__y);} - -// __same_or_less_cv_qualified - -template <class _Ptr1, class _Ptr2, - bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type, - typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type - >::value - > -struct __same_or_less_cv_qualified_imp - : is_convertible<_Ptr1, _Ptr2> {}; - -template <class _Ptr1, class _Ptr2> -struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false> - : false_type {}; - -template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value || - is_same<_Ptr1, _Ptr2>::value || - __has_element_type<_Ptr1>::value> -struct __same_or_less_cv_qualified - : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {}; - -template <class _Ptr1, class _Ptr2> -struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false> - : false_type {}; + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } -// default_delete + _LIBCPP_INLINE_VISIBILITY + void reset(pointer __p = pointer()) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } -template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY default_delete -{ -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default; -#else - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {} -#endif - template <class _Up> - _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&, - typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} - _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT - { - static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); - static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type"); - delete __ptr; - } + _LIBCPP_INLINE_VISIBILITY + void swap(unique_ptr& __u) _NOEXCEPT { + __ptr_.swap(__u.__ptr_); + } }; -template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]> -{ -public: -#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default; -#else - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {} -#endif - template <class _Up> - _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&, - typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {} - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - void operator() (_Up* __ptr, - typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT - { - static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type"); - static_assert(!is_void<_Tp>::value, "default_delete can not delete void type"); - delete [] __ptr; - } -}; -template <class _Tp, class _Dp = default_delete<_Tp> > -class _LIBCPP_TYPE_VIS_ONLY unique_ptr -{ +template <class _Tp, class _Dp> +class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> { public: - typedef _Tp element_type; - typedef _Dp deleter_type; - typedef typename __pointer_type<_Tp, deleter_type>::type pointer; -private: - __compressed_pair<pointer, deleter_type> __ptr_; + typedef _Tp element_type; + typedef _Dp deleter_type; + typedef typename __pointer_type<_Tp, deleter_type>::type pointer; -#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES - unique_ptr(unique_ptr&); - template <class _Up, class _Ep> - unique_ptr(unique_ptr<_Up, _Ep>&); - unique_ptr& operator=(unique_ptr&); - template <class _Up, class _Ep> - unique_ptr& operator=(unique_ptr<_Up, _Ep>&); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - - struct __nat {int __for_bool_;}; +private: + __compressed_pair<pointer, deleter_type> __ptr_; + + template <class _From> + struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; + + template <class _FromElem> + struct _CheckArrayPointerConversion<_FromElem*> + : integral_constant<bool, + is_same<_FromElem*, pointer>::value || + (is_same<pointer, element_type*>::value && + is_convertible<_FromElem(*)[], element_type(*)[]>::value) + > + {}; + +#ifndef _LIBCPP_CXX03_LANG + typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; + + template <bool _Dummy> + using _LValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; + + template <bool _Dummy> + using _GoodRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; + + template <bool _Dummy> + using _BadRValRefType = + typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; + + template <bool _Dummy, class _Deleter = typename __dependent_type< + __identity<deleter_type>, _Dummy>::type> + using _EnableIfDeleterDefaultConstructible = + typename enable_if<is_default_constructible<_Deleter>::value && + !is_pointer<_Deleter>::value>::type; + + template <class _ArgType> + using _EnableIfDeleterConstructible = + typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; + + template <class _Pp> + using _EnableIfPointerConvertible = typename enable_if< + _CheckArrayPointerConversion<_Pp>::value + >::type; + + template <class _UPtr, class _Up, + class _ElemT = typename _UPtr::element_type> + using _EnableIfMoveConvertible = typename enable_if< + is_array<_Up>::value && + is_same<pointer, element_type*>::value && + is_same<typename _UPtr::pointer, _ElemT*>::value && + is_convertible<_ElemT(*)[], element_type(*)[]>::value + >::type; + + template <class _UDel> + using _EnableIfDeleterConvertible = typename enable_if< + (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || + (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) + >::type; + + template <class _UDel> + using _EnableIfDeleterAssignable = typename enable_if< + is_assignable<_Dp&, _UDel&&>::value + >::type; - typedef typename remove_reference<deleter_type>::type& _Dp_reference; - typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT - : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT - : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT - : __ptr_(_VSTD::move(__p)) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional< - is_reference<deleter_type>::value, - deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type __d) - _NOEXCEPT - : __ptr_(__p, __d) {} - - _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d) - _NOEXCEPT - : __ptr_(__p, _VSTD::move(__d)) - { - static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); - } - _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr<_Up, _Ep>&& __u, - typename enable_if - < - !is_array<_Up>::value && - is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && - is_convertible<_Ep, deleter_type>::value && - ( - !is_reference<deleter_type>::value || - is_same<deleter_type, _Ep>::value - ), - __nat - >::type = __nat()) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {} - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, - typename enable_if< - is_convertible<_Up*, _Tp*>::value && - is_same<_Dp, default_delete<_Tp> >::value, - __nat - >::type = __nat()) _NOEXCEPT - : __ptr_(__p.release()) - { - } - - _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT - { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); - return *this; - } - - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - typename enable_if - < - !is_array<_Up>::value && - is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && - is_assignable<deleter_type&, _Ep&&>::value, - unique_ptr& - >::type - operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); - return *this; - } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - - _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() - { - return __rv<unique_ptr>(*this); - } - - _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) - : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} - - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - typename enable_if< - !is_array<_Up>::value && - is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && - is_assignable<deleter_type&, _Ep&>::value, - unique_ptr& - >::type - operator=(unique_ptr<_Up, _Ep> __u) - { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) - : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} - - template <class _Up> - _LIBCPP_INLINE_VISIBILITY - typename enable_if< - is_convertible<_Up*, _Tp*>::value && - is_same<_Dp, default_delete<_Tp> >::value, - unique_ptr& - >::type - operator=(auto_ptr<_Up> __p) - {reset(__p.release()); return *this;} + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>> + _LIBCPP_INLINE_VISIBILITY + constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterDefaultConstructible<_Dummy>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(_Pp __p) noexcept + : __ptr_(__p) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept + : __ptr_(__p, __d) {} + + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept + : __ptr_(nullptr, __d) {} + + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(__p, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} + template <bool _Dummy = true, + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept + : __ptr_(nullptr, _VSTD::move(__d)) { + static_assert(!is_reference<deleter_type>::value, + "rvalue deleter bound to reference"); + } - _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT - { - reset(); - return *this; - } + template <class _Pp, bool _Dummy = true, + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>, + class = _EnableIfPointerConvertible<_Pp>> + _LIBCPP_INLINE_VISIBILITY + unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; - _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const - {return *__ptr_.first();} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();} - _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} - _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT - {return __ptr_.second();} - _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT - {return __ptr_.second();} - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT - {return __ptr_.first() != nullptr;} + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { + } - _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT - { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); - return __t; - } + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(unique_ptr&& __u) noexcept { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); + return *this; + } - _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT - { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; - if (__tmp) - __ptr_.second()(__tmp); - } + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterConvertible<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept + : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { + } - _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT - {__ptr_.swap(__u.__ptr_);} -}; + template <class _Up, class _Ep, + class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, + class = _EnableIfDeleterAssignable<_Ep> + > + _LIBCPP_INLINE_VISIBILITY + unique_ptr& + operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { + reset(__u.release()); + __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); + return *this; + } -template <class _Tp, class _Dp> -class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp> -{ -public: - typedef _Tp element_type; - typedef _Dp deleter_type; - typedef typename __pointer_type<_Tp, deleter_type>::type pointer; +#else // _LIBCPP_CXX03_LANG private: - __compressed_pair<pointer, deleter_type> __ptr_; + template <class _Up> explicit unique_ptr(_Up); -#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES - unique_ptr(unique_ptr&); - template <class _Up> - unique_ptr(unique_ptr<_Up>&); - unique_ptr& operator=(unique_ptr&); - template <class _Up> - unique_ptr& operator=(unique_ptr<_Up>&); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + unique_ptr(unique_ptr&); + template <class _Up> unique_ptr(unique_ptr<_Up>&); - struct __nat {int __for_bool_;}; + unique_ptr& operator=(unique_ptr&); + template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&); - typedef typename remove_reference<deleter_type>::type& _Dp_reference; - typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference; + template <class _Up> + unique_ptr(_Up __u, + typename conditional< + is_reference<deleter_type>::value, deleter_type, + typename add_lvalue_reference<const deleter_type>::type>::type, + typename enable_if<is_convertible<_Up, pointer>::value, + __nat>::type = __nat()); public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT - : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT - : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p, - typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT - : __ptr_(__p) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional< - is_reference<deleter_type>::value, - deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type __d, - typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) - _NOEXCEPT - : __ptr_(__p, __d) {} - - _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional< - is_reference<deleter_type>::value, - deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type __d) - _NOEXCEPT - : __ptr_(pointer(), __d) {} - - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, - typename remove_reference<deleter_type>::type&& __d, - typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) - _NOEXCEPT - : __ptr_(__p, _VSTD::move(__d)) - { - static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); - } + _LIBCPP_INLINE_VISIBILITY + unique_ptr() : __ptr_(pointer()) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t) : __ptr_(pointer()) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } - _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d) - _NOEXCEPT - : __ptr_(pointer(), _VSTD::move(__d)) - { - static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); - } + _LIBCPP_INLINE_VISIBILITY + explicit unique_ptr(pointer __p) : __ptr_(__p) { + static_assert(!is_pointer<deleter_type>::value, + "unique_ptr constructed with null function pointer deleter"); + } - _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr(pointer __p, deleter_type __d) + : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} - _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT - { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); - return *this; - } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(nullptr_t, deleter_type __d) + : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr<_Up, _Ep>&& __u, - typename enable_if - < - is_array<_Up>::value && - __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value - && is_convertible<_Ep, deleter_type>::value && - ( - !is_reference<deleter_type>::value || - is_same<deleter_type, _Ep>::value - ), - __nat - >::type = __nat() - ) _NOEXCEPT - : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {} - - - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - typename enable_if - < - is_array<_Up>::value && - __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value && - is_assignable<deleter_type&, _Ep&&>::value, - unique_ptr& - >::type - operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT - { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); - return *this; - } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + operator __rv<unique_ptr>() { + return __rv<unique_ptr>(*this); + } - _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) - : __ptr_(__p) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } + _LIBCPP_INLINE_VISIBILITY + unique_ptr(__rv<unique_ptr> __u) + : __ptr_(__u->release(), + _VSTD::forward<deleter_type>(__u->get_deleter())) {} - _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d) - : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(__rv<unique_ptr> __u) { + reset(__u->release()); + __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); + return *this; + } - _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d) - : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} +#endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>() - { - return __rv<unique_ptr>(*this); - } +public: + _LIBCPP_INLINE_VISIBILITY + ~unique_ptr() { reset(); } - _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u) - : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {} + _LIBCPP_INLINE_VISIBILITY + unique_ptr& operator=(nullptr_t) _NOEXCEPT { + reset(); + return *this; + } - _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u) - { - reset(__u->release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); - return *this; - } + _LIBCPP_INLINE_VISIBILITY + typename add_lvalue_reference<_Tp>::type + operator[](size_t __i) const { + return __ptr_.first()[__i]; + } + _LIBCPP_INLINE_VISIBILITY + pointer get() const _NOEXCEPT { + return __ptr_.first(); + } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();} + _LIBCPP_INLINE_VISIBILITY + deleter_type& get_deleter() _NOEXCEPT { + return __ptr_.second(); + } - _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT - { - reset(); - return *this; - } + _LIBCPP_INLINE_VISIBILITY + const deleter_type& get_deleter() const _NOEXCEPT { + return __ptr_.second(); + } + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { + return __ptr_.first() != nullptr; + } - _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const - {return __ptr_.first()[__i];} - _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();} - _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT - {return __ptr_.second();} - _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT - {return __ptr_.second();} - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT - {return __ptr_.first() != nullptr;} + _LIBCPP_INLINE_VISIBILITY + pointer release() _NOEXCEPT { + pointer __t = __ptr_.first(); + __ptr_.first() = pointer(); + return __t; + } - _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT - { - pointer __t = __ptr_.first(); - __ptr_.first() = pointer(); - return __t; - } + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + _CheckArrayPointerConversion<_Pp>::value + >::type + reset(_Pp __p) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = __p; + if (__tmp) + __ptr_.second()(__tmp); + } - template <class _Pp> - _LIBCPP_INLINE_VISIBILITY - typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type - reset(_Pp __p) _NOEXCEPT - { - pointer __tmp = __ptr_.first(); - __ptr_.first() = __p; - if (__tmp) - __ptr_.second()(__tmp); - } - _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT - { - pointer __tmp = __ptr_.first(); - __ptr_.first() = nullptr; - if (__tmp) - __ptr_.second()(__tmp); - } + _LIBCPP_INLINE_VISIBILITY + void reset(nullptr_t = nullptr) _NOEXCEPT { + pointer __tmp = __ptr_.first(); + __ptr_.first() = nullptr; + if (__tmp) + __ptr_.second()(__tmp); + } - _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);} -private: + _LIBCPP_INLINE_VISIBILITY + void swap(unique_ptr& __u) _NOEXCEPT { + __ptr_.swap(__u.__ptr_); + } -#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Up> - explicit unique_ptr(_Up); - template <class _Up> - unique_ptr(_Up __u, - typename conditional< - is_reference<deleter_type>::value, - deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type, - typename enable_if - < - is_convertible<_Up, pointer>::value, - __nat - >::type = __nat()); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }; template <class _Tp, class _Dp> @@ -3165,353 +3093,18 @@ template<class _Tp, class... _Args> #endif // _LIBCPP_STD_VER > 11 -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. -template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> -struct __murmur2_or_cityhash; - -template <class _Size> -struct __murmur2_or_cityhash<_Size, 32> -{ - _Size operator()(const void* __key, _Size __len); -}; - -// murmur2 -template <class _Size> -_Size -__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -{ - const _Size __m = 0x5bd1e995; - const _Size __r = 24; - _Size __h = __len; - const unsigned char* __data = static_cast<const unsigned char*>(__key); - for (; __len >= 4; __data += 4, __len -= 4) - { - _Size __k = __loadword<_Size>(__data); - __k *= __m; - __k ^= __k >> __r; - __k *= __m; - __h *= __m; - __h ^= __k; - } - switch (__len) - { - case 3: - __h ^= __data[2] << 16; - case 2: - __h ^= __data[1] << 8; - case 1: - __h ^= __data[0]; - __h *= __m; - } - __h ^= __h >> 13; - __h *= __m; - __h ^= __h >> 15; - return __h; -} - -template <class _Size> -struct __murmur2_or_cityhash<_Size, 64> -{ - _Size operator()(const void* __key, _Size __len); - - private: - // Some primes between 2^63 and 2^64. - static const _Size __k0 = 0xc3a5c85c97cb3127ULL; - static const _Size __k1 = 0xb492b66fbe98f273ULL; - static const _Size __k2 = 0x9ae16a3b2f90404fULL; - static const _Size __k3 = 0xc949d7c7509e6557ULL; - - static _Size __rotate(_Size __val, int __shift) { - return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); - } - - static _Size __rotate_by_at_least_1(_Size __val, int __shift) { - return (__val >> __shift) | (__val << (64 - __shift)); - } - - static _Size __shift_mix(_Size __val) { - return __val ^ (__val >> 47); - } - - static _Size __hash_len_16(_Size __u, _Size __v) { - const _Size __mul = 0x9ddfea08eb382d69ULL; - _Size __a = (__u ^ __v) * __mul; - __a ^= (__a >> 47); - _Size __b = (__v ^ __a) * __mul; - __b ^= (__b >> 47); - __b *= __mul; - return __b; - } - - static _Size __hash_len_0_to_16(const char* __s, _Size __len) { - if (__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 = __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) { - const unsigned char __a = __s[0]; - const unsigned char __b = __s[__len >> 1]; - const unsigned char __c = __s[__len - 1]; - const uint32_t __y = static_cast<uint32_t>(__a) + - (static_cast<uint32_t>(__b) << 8); - const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); - return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; - } - return __k2; - } - - static _Size __hash_len_17_to_32(const char *__s, _Size __len) { - 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); - } - - // Return a 16-byte hash for 48 bytes. Quick and dirty. - // Callers do best to use "random-looking" values for a and b. - static pair<_Size, _Size> __weak_hash_len_32_with_seeds( - _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) { - __a += __w; - __b = __rotate(__b + __a + __z, 21); - const _Size __c = __a; - __a += __x; - __a += __y; - __b += __rotate(__a, 44); - return pair<_Size, _Size>(__a + __z, __b + __c); - } - - // 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(__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 = __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 += __loadword<_Size>(__s + 8); - __c += __rotate(__a, 7); - __a += __loadword<_Size>(__s + 16); - _Size __vf = __a + __z; - _Size __vs = __b + __rotate(__a, 31) + __c; - __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 += __loadword<_Size>(__s + __len - 24); - __c += __rotate(__a, 7); - __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); - return __shift_mix(__r * __k0 + __vs) * __k2; - } -}; - -// cityhash64 -template <class _Size> -_Size -__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -{ - const char* __s = static_cast<const char*>(__key); - if (__len <= 32) { - if (__len <= 16) { - return __hash_len_0_to_16(__s, __len); - } else { - return __hash_len_17_to_32(__s, __len); - } - } else if (__len <= 64) { - return __hash_len_33_to_64(__s, __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 = __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 + __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 + __loadword<_Size>(__s + 8), 37) * __k1; - __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; - __x ^= __w.second; - __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 + __loadword<_Size>(__s + 16)); - std::swap(__z, __x); - __s += 64; - __len -= 64; - } while (__len != 0); - return __hash_len_16( - __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, - __hash_len_16(__v.second, __w.second) + __x); -} - -template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> -struct __scalar_hash; - -template <class _Tp> -struct __scalar_hash<_Tp, 0> - : public unary_function<_Tp, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - union - { - _Tp __t; - size_t __a; - } __u; - __u.__a = 0; - __u.__t = __v; - return __u.__a; - } -}; - -template <class _Tp> -struct __scalar_hash<_Tp, 1> - : public unary_function<_Tp, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - union - { - _Tp __t; - size_t __a; - } __u; - __u.__t = __v; - return __u.__a; - } -}; - -template <class _Tp> -struct __scalar_hash<_Tp, 2> - : public unary_function<_Tp, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - union - { - _Tp __t; - struct - { - size_t __a; - size_t __b; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); - } -}; - -template <class _Tp> -struct __scalar_hash<_Tp, 3> - : public unary_function<_Tp, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - union - { - _Tp __t; - struct - { - size_t __a; - size_t __b; - size_t __c; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); - } -}; - -template <class _Tp> -struct __scalar_hash<_Tp, 4> - : public unary_function<_Tp, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp __v) const _NOEXCEPT - { - union - { - _Tp __t; - struct - { - size_t __a; - size_t __b; - size_t __c; - size_t __d; - } __s; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); - } -}; - -template<class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*> - : public unary_function<_Tp*, size_t> -{ - _LIBCPP_INLINE_VISIBILITY - size_t operator()(_Tp* __v) const _NOEXCEPT - { - union - { - _Tp* __t; - size_t __a; - } __u; - __u.__t = __v; - return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); - } -}; - template <class _Tp, class _Dp> -struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> > +#ifdef _LIBCPP_CXX03_LANG +struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > +#else +struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< + unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>> +#endif { typedef unique_ptr<_Tp, _Dp> argument_type; typedef size_t result_type; _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type& __ptr) const _NOEXCEPT + result_type operator()(const argument_type& __ptr) const { typedef typename argument_type::pointer pointer; return hash<pointer>()(__ptr.get()); @@ -3521,28 +3114,28 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> > struct __destruct_n { private: - size_t size; + size_t __size_; template <class _Tp> _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT - {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();} + {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} template <class _Tp> _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT - {++size;} + {++__size_;} _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT - {size = __s;} + {__size_ = __s;} _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT {} public: _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT - : size(__s) {} + : __size_(__s) {} template <class _Tp> _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT @@ -3671,6 +3264,181 @@ uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) return __f; } +#if _LIBCPP_STD_VER > 14 + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +void destroy_at(_Tp* __loc) { + _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); + __loc->~_Tp(); +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void destroy(_ForwardIterator __first, _ForwardIterator __last) { + for (; __first != __last; ++__first) + _VSTD::destroy_at(_VSTD::addressof(*__first)); +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) { + for (; __n > 0; (void)++__first, --__n) + _VSTD::destroy_at(_VSTD::addressof(*__first)); + return __first; +} + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new((void*)_VSTD::addressof(*__idx)) _Vt; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; (void)++__idx, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt; + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _ForwardIterator> +inline _LIBCPP_INLINE_VISIBILITY +void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __idx != __last; ++__idx) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + +template <class _ForwardIterator, class _Size> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) { + using _Vt = typename iterator_traits<_ForwardIterator>::value_type; + auto __idx = __first; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; (void)++__idx, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first, __idx); + throw; + } +#endif +} + + +template <class _InputIt, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __first != __last; (void)++__idx, ++__first) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); + return __idx; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + +template <class _InputIt, class _Size, class _ForwardIt> +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIt, _ForwardIt> +uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { + using _Vt = typename iterator_traits<_ForwardIt>::value_type; + auto __idx = __first_res; +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + for (; __n > 0; ++__idx, (void)++__first, --__n) + ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first)); + return {__first, __idx}; +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + _VSTD::destroy(__first_res, __idx); + throw; + } +#endif +} + + +#endif // _LIBCPP_STD_VER > 14 + +// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) +// should be sufficient for thread safety. +// See https://bugs.llvm.org/show_bug.cgi?id=22803 +#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \ + && defined(__ATOMIC_RELAXED) \ + && defined(__ATOMIC_ACQ_REL) +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407 +# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _Tp +__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT +{ +#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) + return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED); +#else + return __t += 1; +#endif +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _Tp +__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT +{ +#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS) + return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL); +#else + return __t -= 1; +#endif +} + class _LIBCPP_EXCEPTION_ABI bad_weak_ptr : public std::exception { @@ -3679,7 +3447,17 @@ public: virtual const char* what() const _NOEXCEPT; }; -template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr; +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_bad_weak_ptr() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_weak_ptr(); +#else + _VSTD::abort(); +#endif +} + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr; class _LIBCPP_TYPE_VIS __shared_count { @@ -3697,8 +3475,24 @@ public: explicit __shared_count(long __refs = 0) _NOEXCEPT : __shared_owners_(__refs) {} +#if defined(_LIBCPP_BUILDING_MEMORY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) void __add_shared() _NOEXCEPT; bool __release_shared() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + void __add_shared() _NOEXCEPT { + __libcpp_atomic_refcount_increment(__shared_owners_); + } + _LIBCPP_INLINE_VISIBILITY + bool __release_shared() _NOEXCEPT { + if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { + __on_zero_shared(); + return true; + } + return false; + } +#endif _LIBCPP_INLINE_VISIBILITY long use_count() const _NOEXCEPT { return __libcpp_relaxed_load(&__shared_owners_) + 1; @@ -3719,9 +3513,26 @@ protected: virtual ~__shared_weak_count(); public: +#if defined(_LIBCPP_BUILDING_MEMORY) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) void __add_shared() _NOEXCEPT; void __add_weak() _NOEXCEPT; void __release_shared() _NOEXCEPT; +#else + _LIBCPP_INLINE_VISIBILITY + void __add_shared() _NOEXCEPT { + __shared_count::__add_shared(); + } + _LIBCPP_INLINE_VISIBILITY + void __add_weak() _NOEXCEPT { + __libcpp_atomic_refcount_increment(__shared_weak_owners_); + } + _LIBCPP_INLINE_VISIBILITY + void __release_shared() _NOEXCEPT { + if (__shared_count::__release_shared()) + __release_weak(); + } +#endif void __release_weak() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY long use_count() const _NOEXCEPT {return __shared_count::use_count();} @@ -3763,7 +3574,7 @@ template <class _Tp, class _Dp, class _Alloc> const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT { - return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0; + return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr; } #endif // _LIBCPP_NO_RTTI @@ -3857,13 +3668,26 @@ __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT __a.deallocate(_PTraits::pointer_to(*this), 1); } -template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this; +struct __shared_ptr_dummy_rebind_allocator_type; +template <> +class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> +{ +public: + template <class _Other> + struct rebind + { + typedef allocator<_Other> other; + }; +}; + +template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY shared_ptr +class _LIBCPP_TEMPLATE_VIS shared_ptr { public: typedef _Tp element_type; + #if _LIBCPP_STD_VER > 14 typedef weak_ptr<_Tp> weak_type; #endif @@ -3894,17 +3718,18 @@ public: template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr&& __r) _NOEXCEPT; template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()) + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()) _NOEXCEPT; #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat()); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r, @@ -3914,6 +3739,7 @@ public: shared_ptr(auto_ptr<_Yp> __r, typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat()); #endif +#endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&, @@ -3977,6 +3803,7 @@ public: >::type _LIBCPP_INLINE_VISIBILITY operator=(shared_ptr<_Yp>&& __r); +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template<class _Yp> _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -3986,7 +3813,9 @@ public: shared_ptr >::type& operator=(auto_ptr<_Yp>&& __r); +#endif #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template<class _Yp> _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -3997,6 +3826,7 @@ public: >::type operator=(auto_ptr<_Yp> __r); #endif +#endif template <class _Yp, class _Dp> typename enable_if < @@ -4056,11 +3886,11 @@ public: _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;} template <class _Up> _LIBCPP_INLINE_VISIBILITY - bool owner_before(shared_ptr<_Up> const& __p) const + bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT {return __cntrl_ < __p.__cntrl_;} template <class _Up> _LIBCPP_INLINE_VISIBILITY - bool owner_before(weak_ptr<_Up> const& __p) const + bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT {return __cntrl_ < __p.__cntrl_;} _LIBCPP_INLINE_VISIBILITY bool @@ -4071,7 +3901,9 @@ public: template <class _Dp> _LIBCPP_INLINE_VISIBILITY _Dp* __get_deleter() const _NOEXCEPT - {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);} + {return static_cast<_Dp*>(__cntrl_ + ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) + : nullptr);} #endif // _LIBCPP_NO_RTTI #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -4118,10 +3950,24 @@ public: #endif // _LIBCPP_HAS_NO_VARIADICS private: + template <class _Yp, bool = is_function<_Yp>::value> + struct __shared_ptr_default_allocator + { + typedef allocator<_Yp> type; + }; + + template <class _Yp> + struct __shared_ptr_default_allocator<_Yp, true> + { + typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type; + }; template <class _Yp, class _OrigPtr> _LIBCPP_INLINE_VISIBILITY - void + typename enable_if<is_convertible<_OrigPtr*, + const enable_shared_from_this<_Yp>* + >::value, + void>::type __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT { @@ -4133,13 +3979,13 @@ private: } } - _LIBCPP_INLINE_VISIBILITY - void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {} - template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; - template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; }; + template<class _Tp> inline _LIBCPP_CONSTEXPR @@ -4165,8 +4011,9 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p, : __ptr_(__p) { unique_ptr<_Yp> __hold(__p); - typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>()); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT()); __hold.release(); __enable_weak_this(__p, __p); } @@ -4181,8 +4028,9 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, try { #endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>()); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); __enable_weak_this(__p, __p); #ifndef _LIBCPP_NO_EXCEPTIONS } @@ -4203,8 +4051,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d) try { #endif // _LIBCPP_NO_EXCEPTIONS - typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>()); + typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT; + typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__p, __d, _AllocT()); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -4296,7 +4145,7 @@ template<class _Tp> template<class _Yp> inline shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) @@ -4321,7 +4170,7 @@ template<class _Tp> template<class _Yp> inline shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) @@ -4332,6 +4181,7 @@ shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template<class _Tp> template<class _Yp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -4347,6 +4197,7 @@ shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r, __enable_weak_this(__r.get(), __r.get()); __r.release(); } +#endif template<class _Tp> template <class _Yp, class _Dp> @@ -4370,8 +4221,9 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, else #endif { - typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; + typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); @@ -4399,10 +4251,11 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, else #endif { + typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT; typedef __shared_ptr_pointer<_Yp*, reference_wrapper<typename remove_reference<_Dp>::type>, - allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); + _AllocT > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); @@ -4415,6 +4268,7 @@ template<class ..._Args> shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_Args&& ...__args) { + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _A2; typedef __allocator_destructor<_A2> _D2; @@ -4433,6 +4287,7 @@ template<class _Alloc, class ..._Args> shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) { + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; @@ -4453,6 +4308,7 @@ template<class _Tp> shared_ptr<_Tp> shared_ptr<_Tp>::make_shared() { + static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4471,6 +4327,7 @@ template<class _A0> shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0) { + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4489,6 +4346,7 @@ template<class _A0, class _A1> shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) { + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4507,6 +4365,7 @@ template<class _A0, class _A1, class _A2> shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) { + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4525,6 +4384,7 @@ template<class _Alloc> shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) { + static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4544,6 +4404,7 @@ template<class _Alloc, class _A0> shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) { + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4563,6 +4424,7 @@ template<class _Alloc, class _A0, class _A1> shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) { + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4582,6 +4444,7 @@ template<class _Alloc, class _A0, class _A1, class _A2> shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) { + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4619,7 +4482,7 @@ template<class _Yp> inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT @@ -4644,7 +4507,7 @@ template<class _Yp> inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) @@ -4653,13 +4516,14 @@ shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) return *this; } +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template<class _Tp> template<class _Yp> inline typename enable_if < !is_array<_Yp>::value && - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp> >::type& shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) @@ -4667,6 +4531,7 @@ shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r) shared_ptr(_VSTD::move(__r)).swap(*this); return *this; } +#endif template<class _Tp> template <class _Yp, class _Dp> @@ -4674,7 +4539,8 @@ inline typename enable_if < !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, + typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) @@ -4685,13 +4551,14 @@ shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r) #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template<class _Tp> template<class _Yp> inline _LIBCPP_INLINE_VISIBILITY typename enable_if < !is_array<_Yp>::value && - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) @@ -4699,6 +4566,7 @@ shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r) shared_ptr(__r).swap(*this); return *this; } +#endif template<class _Tp> template <class _Yp, class _Dp> @@ -4706,7 +4574,8 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if < !is_array<_Yp>::value && - is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value, + is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, + typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r) @@ -4739,7 +4608,7 @@ template<class _Yp> inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p) @@ -4752,7 +4621,7 @@ template<class _Yp, class _Dp> inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) @@ -4765,7 +4634,7 @@ template<class _Yp, class _Dp, class _Alloc> inline typename enable_if < - is_convertible<_Yp*, _Tp*>::value, + is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) @@ -5070,7 +4939,7 @@ get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT #endif // _LIBCPP_NO_RTTI template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY weak_ptr +class _LIBCPP_TEMPLATE_VIS weak_ptr { public: typedef _Tp element_type; @@ -5148,15 +5017,15 @@ public: shared_ptr<_Tp> lock() const _NOEXCEPT; template<class _Up> _LIBCPP_INLINE_VISIBILITY - bool owner_before(const shared_ptr<_Up>& __r) const + bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT {return __cntrl_ < __r.__cntrl_;} template<class _Up> _LIBCPP_INLINE_VISIBILITY - bool owner_before(const weak_ptr<_Up>& __r) const + bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT {return __cntrl_ < __r.__cntrl_;} - template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; - template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; + template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr; }; template<class _Tp> @@ -5330,16 +5199,12 @@ weak_ptr<_Tp>::reset() _NOEXCEPT template<class _Tp> template<class _Yp> shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r, - typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type) + typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type) : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) { if (__cntrl_ == 0) -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_weak_ptr(); -#else - assert(!"bad_weak_ptr"); -#endif + __throw_bad_weak_ptr(); } template<class _Tp> @@ -5360,63 +5225,63 @@ template <class _Tp> struct owner_less; #endif template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> > +struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> { typedef bool result_type; _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const + bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const + bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> > +struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> { typedef bool result_type; _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} _LIBCPP_INLINE_VISIBILITY - bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const + bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} }; #if _LIBCPP_STD_VER > 14 template <> -struct _LIBCPP_TYPE_VIS_ONLY owner_less<void> +struct _LIBCPP_TEMPLATE_VIS owner_less<void> { template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY - bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const + bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY - bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const + bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY - bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT {return __x.owner_before(__y);} typedef void is_transparent; }; #endif template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this +class _LIBCPP_TEMPLATE_VIS enable_shared_from_this { mutable weak_ptr<_Tp> __weak_this_; protected: @@ -5451,10 +5316,11 @@ public: }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> > +struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > { typedef shared_ptr<_Tp> argument_type; typedef size_t result_type; + _LIBCPP_INLINE_VISIBILITY result_type operator()(const argument_type& __ptr) const _NOEXCEPT { @@ -5485,7 +5351,8 @@ private: friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); }; -_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*); +_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +__sp_mut& __get_sp_mut(const void*); template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY @@ -5496,6 +5363,7 @@ atomic_is_lock_free(const shared_ptr<_Tp>*) } template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR shared_ptr<_Tp> atomic_load(const shared_ptr<_Tp>* __p) { @@ -5505,9 +5373,10 @@ atomic_load(const shared_ptr<_Tp>* __p) __m.unlock(); return __q; } - + template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR shared_ptr<_Tp> atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) { @@ -5515,6 +5384,7 @@ atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) } template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR void atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { @@ -5526,6 +5396,7 @@ atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR void atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) { @@ -5533,6 +5404,7 @@ atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) } template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR shared_ptr<_Tp> atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { @@ -5542,9 +5414,10 @@ atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) __m.unlock(); return __r; } - + template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR shared_ptr<_Tp> atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) { @@ -5552,6 +5425,7 @@ atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order } template <class _Tp> +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR bool atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) { @@ -5573,6 +5447,7 @@ atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, share template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR bool atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) { @@ -5581,6 +5456,7 @@ atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR bool atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w, memory_order, memory_order) @@ -5590,6 +5466,7 @@ atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* _ template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR bool atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w, memory_order, memory_order) @@ -5600,6 +5477,15 @@ atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) //enum class +#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) +# ifndef _LIBCPP_CXX03_LANG +enum class pointer_safety : unsigned char { + relaxed, + preferred, + strict +}; +# endif +#else struct _LIBCPP_TYPE_VIS pointer_safety { enum __lx @@ -5612,15 +5498,32 @@ struct _LIBCPP_TYPE_VIS pointer_safety __lx __v_; _LIBCPP_INLINE_VISIBILITY + pointer_safety() : __v_() {} + + _LIBCPP_INLINE_VISIBILITY pointer_safety(__lx __v) : __v_(__v) {} _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} }; +#endif + +#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \ + defined(_LIBCPP_BUILDING_MEMORY) +_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; +#else +// This function is only offered in C++03 under ABI v1. +# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG) +inline _LIBCPP_INLINE_VISIBILITY +pointer_safety get_pointer_safety() _NOEXCEPT { + return pointer_safety::relaxed; +} +# endif +#endif + _LIBCPP_FUNC_VIS void declare_reachable(void* __p); _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n); _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n); -_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT; _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p); template <class _Tp> @@ -5643,7 +5546,7 @@ void __swap_allocator(_Alloc & __a1, _Alloc & __a2) _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) #endif { - __swap_allocator(__a1, __a2, + __swap_allocator(__a1, __a2, integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); } @@ -5665,7 +5568,7 @@ inline _LIBCPP_INLINE_VISIBILITY void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > -struct __noexcept_move_assign_container : public integral_constant<bool, +struct __noexcept_move_assign_container : public integral_constant<bool, _Traits::propagate_on_container_move_assignment::value #if _LIBCPP_STD_VER > 14 || _Traits::is_always_equal::value @@ -5679,21 +5582,23 @@ struct __noexcept_move_assign_container : public integral_constant<bool, template <class _Tp, class _Alloc> struct __temp_value { typedef allocator_traits<_Alloc> _Traits; - + typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v; _Alloc &__a; _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } _Tp & get() { return *__addr(); } - + template<class... _Args> __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); } - + ~__temp_value() { _Traits::destroy(__a, __addr()); } }; #endif _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_MEMORY diff --git a/lib/libcxx/include/module.modulemap b/lib/libcxx/include/module.modulemap index 3fb7428411d..3194b5c9f2a 100644 --- a/lib/libcxx/include/module.modulemap +++ b/lib/libcxx/include/module.modulemap @@ -1,13 +1,224 @@ +// define the module for __config outside of the top level 'std' module +// since __config may be included from C headers which may create an +// include cycle. +module std_config [system] [extern_c] { + header "__config" +} + module std [system] { + export std_config // FIXME: The standard does not require that each of these submodules // re-exports its imported modules. We should provide an alternative form of // export that issues a warning if a name from the submodule is used, and // use that to provide a 'strict mode' for libc++. + + // Deprecated C-compatibility headers. These can all be included from within + // an 'extern "C"' context. + module depr [extern_c] { + // <assert.h> provided by C library. + module ctype_h { + header "ctype.h" + export * + } + module errno_h { + header "errno.h" + export * + } + // <fenv.h> provided by C library. + // <float.h> provided by compiler or C library. + module inttypes_h { + header "inttypes.h" + export stdint_h + export * + } + // <iso646.h> provided by compiler. + // <limits.h> provided by compiler or C library. + module locale_h { + header "locale.h" + export * + } + module math_h { + header "math.h" + export * + } + module setjmp_h { + header "setjmp.h" + export * + } + // FIXME: <stdalign.h> is missing. + // <signal.h> provided by C library. + // <stdarg.h> provided by compiler. + // <stdbool.h> provided by compiler. + module stddef_h { + // <stddef.h>'s __need_* macros require textual inclusion. + textual header "stddef.h" + } + module stdint_h { + header "stdint.h" + export * + // FIXME: This module only exists on OS X and for some reason the + // wildcard above doesn't export it. + export Darwin.C.stdint + } + module stdio_h { + // <stdio.h>'s __need_* macros require textual inclusion. + textual header "stdio.h" + export * + export Darwin.C.stdio + } + module stdlib_h { + // <stdlib.h>'s __need_* macros require textual inclusion. + textual header "stdlib.h" + export * + } + module string_h { + header "string.h" + export * + } + // FIXME: <uchar.h> is missing. + // <time.h> provided by C library. + module wchar_h { + // <wchar.h>'s __need_* macros require textual inclusion. + textual header "wchar.h" + export * + } + module wctype_h { + header "wctype.h" + export * + } + } + + // <complex.h> and <tgmath.h> are not C headers in any real sense, do not + // allow their use in extern "C" contexts. + module complex_h { + header "complex.h" + export ccomplex + export * + } + module tgmath_h { + header "tgmath.h" + export ccomplex + export cmath + export * + } + + // C compatibility headers. + module compat { + module cassert { + // <cassert>'s use of NDEBUG requires textual inclusion. + textual header "cassert" + } + module ccomplex { + header "ccomplex" + export complex + export * + } + module cctype { + header "cctype" + export * + } + module cerrno { + header "cerrno" + export * + } + module cfenv { + header "cfenv" + export * + } + module cfloat { + header "cfloat" + export * + } + module cinttypes { + header "cinttypes" + export cstdint + export * + } + module ciso646 { + header "ciso646" + export * + } + module climits { + header "climits" + export * + } + module clocale { + header "clocale" + export * + } + module cmath { + header "cmath" + export * + } + module csetjmp { + header "csetjmp" + export * + } + module csignal { + header "csignal" + export * + } + // FIXME: <cstdalign> is missing. + module cstdarg { + header "cstdarg" + export * + } + module cstdbool { + header "cstdbool" + export * + } + module cstddef { + header "cstddef" + export * + } + module cstdint { + header "cstdint" + export depr.stdint_h + export * + } + module cstdio { + header "cstdio" + export * + } + module cstdlib { + header "cstdlib" + export * + } + module cstring { + header "cstring" + export * + } + module ctgmath { + header "ctgmath" + export ccomplex + export cmath + export * + } + module ctime { + header "ctime" + export * + } + // FIXME: <cuchar> is missing. + module cwchar { + header "cwchar" + export depr.stdio_h + export * + } + module cwctype { + header "cwctype" + export * + } + } + module algorithm { header "algorithm" export initializer_list export * } + module any { + header "any" + export * + } module array { header "array" export initializer_list @@ -16,7 +227,6 @@ module std [system] { module atomic { header "atomic" export * - requires cplusplus11 } module bitset { header "bitset" @@ -25,118 +235,10 @@ module std [system] { export * } // No submodule for cassert. It fundamentally needs repeated, textual inclusion. - module ccomplex { - header "ccomplex" - export complex - export * - } - module cctype { - header "cctype" - export * - } - module cerrno { - header "cerrno" -/* - export_macros ECONNREFUSED, EIO, ENODEV, ENOTEMPTY, ERANGE, - E2BIG, ECONNRESET, EISCONN, ENOENT, ENOTRECOVERABLE, EROFS, - EACCES, EDEADLK, EISDIR, ENOEXEC, ENOTSOCK, ESPIPE, - EADDRINUSE, EDESTADDRREQ, ELOOP, ENOLCK, ENOTSUP, ESRCH, - EADDRNOTAVAIL, EDOM, EMFILE, ENOLINK, ENOTTY, ETIME, - EAFNOSUPPORT, EEXIST, EMLINK, ENOMEM, ENXIO, ETIMEDOUT, - EAGAIN, EFAULT, EMSGSIZE, ENOMSG, EOPNOTSUPP, ETXTBSY, - EALREADY, EFBIG, ENAMETOOLONG, ENOPROTOOPT, EOVERFLOW, EWOULDBLOCK, - EBADF, EHOSTUNREACH, ENETDOWN, ENOSPC, EOWNERDEAD, EXDEV, - EBADMSG, EIDRM, ENETRESET, ENOSR, EPERM, errno, - EBUSY, EILSEQ, ENETUNREACH, ENOSTR, EPIPE, - ECANCELED, EINPROGRESS, ENFILE, ENOSYS, EPROTO, - ECHILD, EINTR, ENOBUFS, ENOTCONN, EPROTONOSUPPORT, - ECONNABORTED, EINVAL, ENODATA, ENOTDIR, EPROTOTYPE -*/ - export * - } - module cfenv { - header "cfenv" -/* - export_macros FE_ALL_EXCEPT, FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, - FE_UNDERFLOW, FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, - FE_DFL_ENV -*/ - export * - } - module cfloat { - header "cfloat" -/* - export_macros FLT_EVAL_METHOD, FLT_RADIX, FLT_ROUNDS, - FLT_DIG, FLT_EPSILON, FLT_MANT_DIG, - FLT_MAX, FLT_MAX_10_EXP, FLT_MAX_EXP, - FLT_MIN, FLT_MIN_10_EXP, FLT_MIN_EXP, - DBL_DIG, DBL_EPSILON, DBL_MANT_DIG, - DBL_MAX, DBL_MAX_10_EXP, DBL_MAX_EXP, - DBL_MIN, DBL_MIN_10_EXP, DBL_MIN_EXP, - LDBL_DIG, LDBL_EPSILON, LDBL_MANT_DIG, - LDBL_MAX, LDBL_MAX_10_EXP, LDBL_MAX_EXP, - LDBL_MIN, LDBL_MIN_10_EXP, LDBL_MIN_EXP -*/ - export * - } module chrono { header "chrono" export * } - module cinttypes { - header "cinttypes" - export cstdint -/* - export_macros - PRId8, PRId16, PRId32, PRId64, PRIdFAST8, PRIdFAST16, PRIdFAST32, PRIdFAST64, PRIdLEAST8, PRIdLEAST16, PRIdLEAST32, PRIdLEAST64, PRIdMAX, PRIdPTR, - PRIi8, PRIi16, PRIi32, PRIi64, PRIiFAST8, PRIiFAST16, PRIiFAST32, PRIiFAST64, PRIiLEAST8, PRIiLEAST16, PRIiLEAST32, PRIiLEAST64, PRIiMAX, PRIiPTR, - PRIo8, PRIo16, PRIo32, PRIo64, PRIoFAST8, PRIoFAST16, PRIoFAST32, PRIoFAST64, PRIoLEAST8, PRIoLEAST16, PRIoLEAST32, PRIoLEAST64, PRIoMAX, PRIoPTR, - PRIu8, PRIu16, PRIu32, PRIu64, PRIuFAST8, PRIuFAST16, PRIuFAST32, PRIuFAST64, PRIuLEAST8, PRIuLEAST16, PRIuLEAST32, PRIuLEAST64, PRIuMAX, PRIuPTR, - PRIx8, PRIx16, PRIx32, PRIx64, PRIxFAST8, PRIxFAST16, PRIxFAST32, PRIxFAST64, PRIxLEAST8, PRIxLEAST16, PRIxLEAST32, PRIxLEAST64, PRIxMAX, PRIxPTR, - PRIX8, PRIX16, PRIX32, PRIX64, PRIXFAST8, PRIXFAST16, PRIXFAST32, PRIXFAST64, PRIXLEAST8, PRIXLEAST16, PRIXLEAST32, PRIXLEAST64, PRIXMAX, PRIXPTR, - SCNd8, SCNd16, SCNd32, SCNd64, SCNdFAST8, SCNdFAST16, SCNdFAST32, SCNdFAST64, SCNdLEAST8, SCNdLEAST16, SCNdLEAST32, SCNdLEAST64, SCNdMAX, SCNdPTR, - SCNi8, SCNi16, SCNi32, SCNi64, SCNiFAST8, SCNiFAST16, SCNiFAST32, SCNiFAST64, SCNiLEAST8, SCNiLEAST16, SCNiLEAST32, SCNiLEAST64, SCNiMAX, SCNiPTR, - SCNo8, SCNo16, SCNo32, SCNo64, SCNoFAST8, SCNoFAST16, SCNoFAST32, SCNoFAST64, SCNoLEAST8, SCNoLEAST16, SCNoLEAST32, SCNoLEAST64, SCNoMAX, SCNoPTR, - SCNu8, SCNu16, SCNu32, SCNu64, SCNuFAST8, SCNuFAST16, SCNuFAST32, SCNuFAST64, SCNuLEAST8, SCNuLEAST16, SCNuLEAST32, SCNuLEAST64, SCNuMAX, SCNuPTR, - SCNx8, SCNx16, SCNx32, SCNx64, SCNxFAST8, SCNxFAST16, SCNxFAST32, SCNxFAST64, SCNxLEAST8, SCNxLEAST16, SCNxLEAST32, SCNxLEAST64, SCNxMAX, SCNxPTR, - SCNX8, SCNX16, SCNX32, SCNX64, SCNXFAST8, SCNXFAST16, SCNXFAST32, SCNXFAST64, SCNXLEAST8, SCNXLEAST16, SCNXLEAST32, SCNXLEAST64, SCNXMAX, SCNXPTR -*/ - export * - } - module ciso646 { - header "ciso646" - export * - } - module climits { - header "climits" -/* - export_macros CHAR_BIT, CHAR_MIN, CHAR_MAX, - SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, - SHRT_MIN, SHRT_MAX, USHRT_MAX, - INT_MIN, INT_MAX, UINT_MAX, - LONG_MIN, LONG_MAX, ULONG_MAX, - LLONG_MIN, LLONG_MAX, ULLONG_MAX, - MB_LEN_MAX -*/ - export * - } - module clocale { - header "clocale" -/* - export_macros LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, NULL -*/ - export * - } - module cmath { - header "cmath" -/* - export_macros FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL, FP_ILOGBO, FP_ILOGBNAN, - FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, - HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY, NAN, - MATH_ERRNO, MATH_ERREXCEPT, math_errhandling -*/ - export * - } module codecvt { header "codecvt" export * @@ -149,108 +251,6 @@ module std [system] { header "condition_variable" export * } - module csetjmp { - header "csetjmp" -/* - export_macros setjmp -*/ - export * - } - module csignal { - header "csignal" -/* - export_macros SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, - SIG_DFL, SIG_IGN, SIG_ERR -*/ - export * - } - module cstdarg { - header "cstdarg" -/* - export_macros va_arg, va_start, va_end, va_copy -*/ - export * - } - module cstdbool { - header "cstdbool" -/* - export_macros __bool_true_false_are_defined -*/ - export * - } - module cstddef { - header "cstddef" -/* - export_macros NULL, offsetof -*/ - export * - } - module cstdint { - header "cstdint" -/* - export_macros - INT_8_MIN, INT_8_MAX, UINT_8_MAX, INT_16_MIN, INT_16_MAX, UINT_16_MAX, - INT_32_MIN, INT_32_MAX, UINT_32_MAX, INT_64_MIN, INT_64_MAX, UINT_64_MAX, - INT_FAST8_MIN, INT_FAST8_MAX, UINT_FAST8_MAX, INT_FAST16_MIN, INT_FAST16_MAX, UINT_FAST16_MAX, - INT_FAST32_MIN, INT_FAST32_MAX, UINT_FAST32_MAX, INT_FAST64_MIN, INT_FAST64_MAX, UINT_FAST64_MAX, - INT_LEAST8_MIN, INT_LEAST8_MAX, UINT_LEAST8_MAX, INT_LEAST16_MIN, INT_LEAST16_MAX, UINT_LEAST16_MAX, - INT_LEAST32_MIN, INT_LEAST32_MAX, UINT_LEAST32_MAX, INT_LEAST64_MIN, INT_LEAST64_MAX, UINT_LEAST64_MAX, - INT_MAX_MIN, INT_MAX_MAX, UINT_MAX_MAX, INT_PTR_MIN, INT_PTR_MAX, UINT_PTR_MAX, - PTRDIFF_MIN, PTRDIFF_MAX, SIG_ATOMIC_MIN, SIG_ATOMIC_MAX, WCHAR_MIN, WCHAR_MAX, WINT_MIN, WINT_MAX, - SIZE_MAX -*/ - export * - } - module cstdio { - header "cstdio" -/* - export_macros BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_tmpnam, NULL, - SEEK_CUR, SEEK_END, SEEK_SET, TMP_MAX, _IOFBF, _IOLBF, - stdin, stdout, stderr -*/ - export * - } - module cstdlib { - header "cstdlib" -/* - export_macros RAND_MAX -*/ - export * - } - module cstring { - header "cstring" -/* - export_macros NULL -*/ - export * - } - module ctgmath { - header "ctgmath" - export ccomplex - export cmath - export * - } - module ctime { - header "ctime" -/* - export_macros NULL, CLOCKS_PER_SEC -*/ - export * - } - module cwchar { - header "cwchar" -/* - export_macros NULL, WCHAR_MAX, WCHAR_MIN, WEOF -*/ - export * - } - module cwctype { - header "cwctype" -/* - export_macros WEOF -*/ - export * - } module deque { header "deque" export initializer_list @@ -345,6 +345,10 @@ module std [system] { header "numeric" export * } + module optional { + header "optional" + export * + } module ostream { header "ostream" // FIXME: should re-export ios, streambuf? @@ -399,11 +403,19 @@ module std [system] { module string { header "string" export initializer_list + export string_view + export __string + export * + } + module string_view { + header "string_view" + export initializer_list + export __string export * } module strstream { header "strstream" - requires !cplusplus11 + export * } module system_error { header "system_error" @@ -449,17 +461,16 @@ module std [system] { export initializer_list export * } + module variant { + header "variant" + export * + } module vector { header "vector" export initializer_list export * } - // FIXME: We don't have modules for the <foo.h> headers, because they might - // be included from the C library's headers, and that would create a #include - // cycle. For the same reason, we don't have a module for __config. - //module __config { header "__config" export * } - // FIXME: These should be private. module __bit_reference { header "__bit_reference" export * } module __debug { header "__debug" export * } @@ -470,8 +481,131 @@ module std [system] { module __split_buffer { header "__split_buffer" export * } module __sso_allocator { header "__sso_allocator" export * } module __std_stream { header "__std_stream" export * } + module __string { header "__string" export * } module __tree { header "__tree" export * } module __tuple { header "__tuple" export * } - module __undef_min_max { header "__undef_min_max" export * } - module __undef___deallocate { header "__undef___deallocate" export * } + module __undef_macros { header "__undef_macros" export * } + + module experimental { + requires cplusplus11 + + module algorithm { + header "experimental/algorithm" + export * + } + module any { + header "experimental/any" + export * + } + module chrono { + header "experimental/chrono" + export * + } + module coroutine { + requires coroutines + header "experimental/coroutine" + export * + } + module deque { + header "experimental/deque" + export * + } + module dynarray { + header "experimental/dynarray" + export * + } + module filesystem { + header "experimental/filesystem" + export * + } + module forward_list { + header "experimental/forward_list" + export * + } + module functional { + header "experimental/functional" + export * + } + module iterator { + header "experimental/iterator" + export * + } + module list { + header "experimental/list" + export * + } + module map { + header "experimental/map" + export * + } + module memory_resource { + header "experimental/memory_resource" + export * + } + module numeric { + header "experimental/numeric" + export * + } + module optional { + header "experimental/optional" + export * + } + module propagate_const { + header "experimental/propagate_const" + export * + } + module ratio { + header "experimental/ratio" + export * + } + module regex { + header "experimental/regex" + export * + } + module set { + header "experimental/set" + export * + } + module string { + header "experimental/string" + export * + } + module string_view { + header "experimental/string_view" + export * + } + module system_error { + header "experimental/system_error" + export * + } + module tuple { + header "experimental/tuple" + export * + } + module type_traits { + header "experimental/type_traits" + export * + } + module unordered_map { + header "experimental/unordered_map" + export * + } + module unordered_set { + header "experimental/unordered_set" + export * + } + module utility { + header "experimental/utility" + export * + } + module vector { + header "experimental/vector" + export * + } + // FIXME these should be private + module __memory { + header "experimental/__memory" + export * + } + } // end experimental } diff --git a/lib/libcxx/include/mutex b/lib/libcxx/include/mutex index c047cf943e8..52e39b0fb1f 100644 --- a/lib/libcxx/include/mutex +++ b/lib/libcxx/include/mutex @@ -91,9 +91,9 @@ struct defer_lock_t {}; struct try_to_lock_t {}; struct adopt_lock_t {}; -constexpr defer_lock_t defer_lock{}; -constexpr try_to_lock_t try_to_lock{}; -constexpr adopt_lock_t adopt_lock{}; +inline constexpr defer_lock_t defer_lock{}; +inline constexpr try_to_lock_t try_to_lock{}; +inline constexpr adopt_lock_t adopt_lock{}; template <class Mutex> class lock_guard @@ -109,15 +109,17 @@ public: lock_guard& operator=(lock_guard const&) = delete; }; -template <class... MutexTypes> // Variadic lock_guard only provided in ABI V2. -class lock_guard +template <class... MutexTypes> +class scoped_lock // C++17 { public: - explicit lock_guard(MutexTypes&... m); - lock_guard(MutexTypes&... m, adopt_lock_t); - ~lock_guard(); - lock_guard(lock_guard const&) = delete; - lock_guard& operator=(lock_guard const&) = delete; + using mutex_type = Mutex; // If MutexTypes... consists of the single type Mutex + + explicit scoped_lock(MutexTypes&... m); + scoped_lock(adopt_lock_t, MutexTypes&... m); + ~scoped_lock(); + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; private: tuple<MutexTypes&...> pm; // exposition only }; @@ -189,24 +191,26 @@ template<class Callable, class ...Args> #include <__mutex_base> #include <functional> #include <memory> -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG #include <tuple> #endif #include <__threading_support> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_THREADS class _LIBCPP_TYPE_VIS recursive_mutex { - __libcpp_mutex_t __m_; + __libcpp_recursive_mutex_t __m_; public: recursive_mutex(); @@ -221,7 +225,8 @@ public: bool try_lock() _NOEXCEPT; void unlock() _NOEXCEPT; - typedef __libcpp_mutex_t* native_handle_type; + typedef __libcpp_recursive_mutex_t* native_handle_type; + _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;} }; @@ -247,6 +252,7 @@ public: bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {return try_lock_until(chrono::steady_clock::now() + __d);} template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); void unlock() _NOEXCEPT; }; @@ -290,6 +296,7 @@ public: bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {return try_lock_until(chrono::steady_clock::now() + __d);} template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); void unlock() _NOEXCEPT; }; @@ -338,7 +345,7 @@ try_lock(_L0& __l0, _L1& __l1) return 0; } -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _L0, class _L1, class _L2, class... _L3> int @@ -357,7 +364,7 @@ try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) return __r; } -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG template <class _L0, class _L1> void @@ -386,7 +393,7 @@ lock(_L0& __l0, _L1& __l1) } } -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _L0, class _L1, class _L2, class ..._L3> void @@ -461,19 +468,96 @@ void __unlock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) { _VSTD::__unlock(__l2, __l3...); } -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 14 +template <class ..._Mutexes> +class _LIBCPP_TEMPLATE_VIS scoped_lock; + +template <> +class _LIBCPP_TEMPLATE_VIS scoped_lock<> { +public: + explicit scoped_lock() {} + ~scoped_lock() = default; + + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(adopt_lock_t) {} + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; +}; + +template <class _Mutex> +class _LIBCPP_TEMPLATE_VIS scoped_lock<_Mutex> { +public: + typedef _Mutex mutex_type; +private: + mutex_type& __m_; +public: + explicit scoped_lock(mutex_type & __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m)) + : __m_(__m) {__m_.lock();} + + ~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();} + + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(adopt_lock_t, mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m)) + : __m_(__m) {} + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; +}; + +template <class ..._MArgs> +class _LIBCPP_TEMPLATE_VIS scoped_lock +{ + static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required"); + typedef tuple<_MArgs&...> _MutexTuple; + +public: + _LIBCPP_INLINE_VISIBILITY + explicit scoped_lock(_MArgs&... __margs) + : __t_(__margs...) + { + _VSTD::lock(__margs...); + } + + _LIBCPP_INLINE_VISIBILITY + scoped_lock(adopt_lock_t, _MArgs&... __margs) + : __t_(__margs...) + { + } + + _LIBCPP_INLINE_VISIBILITY + ~scoped_lock() { + typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices; + __unlock_unpack(_Indices{}, __t_); + } + + scoped_lock(scoped_lock const&) = delete; + scoped_lock& operator=(scoped_lock const&) = delete; + +private: + template <size_t ..._Indx> + _LIBCPP_INLINE_VISIBILITY + static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) { + _VSTD::__unlock(_VSTD::get<_Indx>(__mt)...); + } + + _MutexTuple __t_; +}; +#endif // _LIBCPP_STD_VER > 14 #endif // !_LIBCPP_HAS_NO_THREADS -struct _LIBCPP_TYPE_VIS_ONLY once_flag; +struct _LIBCPP_TEMPLATE_VIS once_flag; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template<class _Callable, class... _Args> _LIBCPP_INLINE_VISIBILITY void call_once(once_flag&, _Callable&&, _Args&&...); -#else // _LIBCPP_HAS_NO_VARIADICS +#else // _LIBCPP_CXX03_LANG template<class _Callable> _LIBCPP_INLINE_VISIBILITY @@ -483,9 +567,9 @@ template<class _Callable> _LIBCPP_INLINE_VISIBILITY void call_once(once_flag&, const _Callable&); -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG -struct _LIBCPP_TYPE_VIS_ONLY once_flag +struct _LIBCPP_TEMPLATE_VIS once_flag { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR @@ -497,11 +581,11 @@ private: unsigned long __state_; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template<class _Callable, class... _Args> friend void call_once(once_flag&, _Callable&&, _Args&&...); -#else // _LIBCPP_HAS_NO_VARIADICS +#else // _LIBCPP_CXX03_LANG template<class _Callable> friend void call_once(once_flag&, _Callable&); @@ -509,10 +593,10 @@ private: template<class _Callable> friend void call_once(once_flag&, const _Callable&); -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_CXX03_LANG }; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _Fp> class __call_once_param @@ -567,14 +651,14 @@ __call_once_proxy(void* __vp) _LIBCPP_FUNC_VIS void __call_once(volatile unsigned long&, void*, void(*)(void*)); -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template<class _Callable, class... _Args> inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) { - if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) { typedef tuple<_Callable&&, _Args&&...> _Gp; _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); @@ -583,14 +667,14 @@ call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) } } -#else // _LIBCPP_HAS_NO_VARIADICS +#else // _LIBCPP_CXX03_LANG template<class _Callable> inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable& __func) { - if (__libcpp_relaxed_load(&__flag.__state_) != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) { __call_once_param<_Callable> __p(__func); __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); @@ -602,72 +686,17 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, const _Callable& __func) { - if (__flag.__state_ != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) { __call_once_param<const _Callable> __p(__func); __call_once(__flag.__state_, &__p, &__call_once_proxy<const _Callable>); } } -#endif // _LIBCPP_HAS_NO_VARIADICS - - -#if defined(_LIBCPP_ABI_VARIADIC_LOCK_GUARD) \ - && !defined(_LIBCPP_CXX03_LANG) -template <> -class _LIBCPP_TYPE_VIS_ONLY lock_guard<> { -public: - explicit lock_guard() {} - ~lock_guard() = default; - - _LIBCPP_INLINE_VISIBILITY - explicit lock_guard(adopt_lock_t) {} - - lock_guard(lock_guard const&) = delete; - lock_guard& operator=(lock_guard const&) = delete; -}; - -template <class ..._MArgs> -class _LIBCPP_TYPE_VIS_ONLY lock_guard -{ - static_assert(sizeof...(_MArgs) >= 2, "At least 2 lock types required"); - typedef tuple<_MArgs&...> _MutexTuple; - -public: - _LIBCPP_INLINE_VISIBILITY - explicit lock_guard(_MArgs&... __margs) - : __t_(__margs...) - { - _VSTD::lock(__margs...); - } - - _LIBCPP_INLINE_VISIBILITY - lock_guard(_MArgs&... __margs, adopt_lock_t) - : __t_(__margs...) - { - } - - _LIBCPP_INLINE_VISIBILITY - ~lock_guard() { - typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices; - __unlock_unpack(_Indices{}, __t_); - } - - lock_guard(lock_guard const&) = delete; - lock_guard& operator=(lock_guard const&) = delete; - -private: - template <size_t ..._Indx> - _LIBCPP_INLINE_VISIBILITY - static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) { - _VSTD::__unlock(_VSTD::get<_Indx>(__mt)...); - } - - _MutexTuple __t_; -}; - -#endif // _LIBCPP_ABI_VARIADIC_LOCK_GUARD +#endif // _LIBCPP_CXX03_LANG _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_MUTEX diff --git a/lib/libcxx/include/new b/lib/libcxx/include/new index d2b2ae648b4..4e527501b1e 100644 --- a/lib/libcxx/include/new +++ b/lib/libcxx/include/new @@ -27,40 +27,61 @@ public: virtual const char* what() const noexcept; }; -class bad_array_length : public bad_alloc // C++14 +class bad_array_length : public bad_alloc // FIXME: Not part of C++ { public: bad_array_length() noexcept; }; -class bad_array_new_length : public bad_alloc +class bad_array_new_length : public bad_alloc // C++14 { public: bad_array_new_length() noexcept; }; +enum class align_val_t : size_t {}; // C++17 struct nothrow_t {}; extern const nothrow_t nothrow; typedef void (*new_handler)(); new_handler set_new_handler(new_handler new_p) noexcept; new_handler get_new_handler() noexcept; +// 21.6.4, pointer optimization barrier +template <class T> constexpr T* launder(T* p) noexcept; // C++17 } // std -void* operator new(std::size_t size); // replaceable -void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable +void* operator new(std::size_t size); // replaceable, nodiscard in C++2a +void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a +void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a +void* operator new(std::size_t size, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a void operator delete(void* ptr) noexcept; // replaceable void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 +void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete(void* ptr, std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17 void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable - -void* operator new[](std::size_t size); // replaceable -void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable +void operator delete(void* ptr, std:align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17 + +void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a +void* operator new[](std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a +void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a +void* operator new[](std::size_t size, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a void operator delete[](void* ptr) noexcept; // replaceable void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 +void operator delete[](void* ptr, + std::align_val_t alignment) noexcept; // replaceable, C++17 +void operator delete[](void* ptr, std::size_t size, + std::align_val_t alignment) noexcept; // replaceable, C++17 void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable +void operator delete[](void* ptr, std::align_val_t alignment, + const std::nothrow_t&) noexcept; // replaceable, C++17 -void* operator new (std::size_t size, void* ptr) noexcept; -void* operator new[](std::size_t size, void* ptr) noexcept; +void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a +void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a void operator delete (void* ptr, void*) noexcept; void operator delete[](void* ptr, void*) noexcept; @@ -69,16 +90,36 @@ void operator delete[](void* ptr, void*) noexcept; #include <__config> #include <exception> #include <cstddef> +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif -#include <__undef___deallocate> +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#include <new.h> +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +#if !(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ + (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309)) +# define _LIBCPP_HAS_NO_SIZED_DEALLOCATION +#endif + +#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \ + (!(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER > 14 || \ + (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606))) +# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +#endif + namespace std // purposefully not using versioning namespace { +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) +struct _LIBCPP_TYPE_VIS nothrow_t {}; +extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; + class _LIBCPP_EXCEPTION_ABI bad_alloc : public exception { @@ -97,11 +138,18 @@ public: virtual const char* what() const _NOEXCEPT; }; -#if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) +typedef void (*new_handler)(); +_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; +_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; -class _LIBCPP_EXCEPTION_ABI bad_array_length - : public bad_alloc -{ +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME + +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec + +#if defined(_LIBCPP_BUILDING_LIBRARY) || (_LIBCPP_STD_VER > 11) + +class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH + bad_array_length : public bad_alloc { public: bad_array_length() _NOEXCEPT; virtual ~bad_array_length() _NOEXCEPT; @@ -112,53 +160,65 @@ public: #endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) -_LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec - -struct _LIBCPP_TYPE_VIS nothrow_t {}; -extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; -typedef void (*new_handler)(); -_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; -_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; +#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || _LIBCPP_STD_VER > 14 +#ifndef _LIBCPP_CXX03_LANG +enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; +#else +enum align_val_t { __zero = 0, __max = (size_t)-1 }; +#endif +#endif } // std -#if defined(_WIN32) && !defined(cxx_EXPORTS) -# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS_ONLY +#if defined(_LIBCPP_CXX03_LANG) +#define _THROW_BAD_ALLOC throw(std::bad_alloc) #else -# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS +#define _THROW_BAD_ALLOC +#endif + +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) + +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; #endif -_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz) -#if !__has_feature(cxx_noexcept) - throw(std::bad_alloc) +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; #endif -; -_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; -_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p) _NOEXCEPT; -_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; -#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ - (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309) -_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; + +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; #endif -_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz) -#if !__has_feature(cxx_noexcept) - throw(std::bad_alloc) +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; +_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; +#ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION +_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; #endif -; -_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; -_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p) _NOEXCEPT; -_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; -#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ - (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309) -_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; #endif -inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} -inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME + _LIBCPP_BEGIN_NAMESPACE_STD inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) { @@ -169,7 +229,7 @@ inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) { #endif } -inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) { +inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void *__ptr) { #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE ::operator delete(__ptr); #else @@ -177,6 +237,44 @@ inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) { #endif } +#ifdef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +#ifndef _LIBCPP_NO_EXCEPTIONS +_LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH +#endif +void __throw_bad_array_length() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_array_length(); +#else + _VSTD::abort(); +#endif +} +#endif + +template <class _Tp> +_LIBCPP_NODISCARD_AFTER_CXX17 inline +_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT +{ + static_assert (!(is_function<_Tp>::value), "can't launder functions" ); + static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" ); +#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER + return __builtin_launder(__p); +#else + return __p; +#endif +} + + +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp* launder(_Tp* __p) noexcept +{ + return _VSTD::__launder(__p); +} +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_NEW diff --git a/lib/libcxx/include/numeric b/lib/libcxx/include/numeric index 21c3781ab6a..1b7d97c5be0 100644 --- a/lib/libcxx/include/numeric +++ b/lib/libcxx/include/numeric @@ -25,6 +25,18 @@ template <class InputIterator, class T, class BinaryOperation> T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); +template<class InputIterator> + typename iterator_traits<InputIterator>::value_type + reduce(InputIterator first, InputIterator last); // C++17 + +template<class InputIterator, class T> + T + reduce(InputIterator first, InputIterator last, T init); // C++17 + +template<class InputIterator, class T, class BinaryOperation> + T + reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 + template <class InputIterator1, class InputIterator2, class T> T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); @@ -34,6 +46,23 @@ template <class InputIterator1, class InputIterator2, class T, class BinaryOpera inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); + +template<class InputIterator1, class InputIterator2, class T> + T + transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init); // C++17 + +template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> + T + transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init, + BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17 + +template<class InputIterator, class T, class BinaryOperation, class UnaryOperation> + T + transform_reduce(InputIterator first, InputIterator last, T init, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + template <class InputIterator, class OutputIterator> OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result); @@ -42,6 +71,52 @@ template <class InputIterator, class OutputIterator, class BinaryOperation> OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); +template<class InputIterator, class OutputIterator, class T> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init); // C++17 + +template<class InputIterator, class OutputIterator, class T, class BinaryOperation> + OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, BinaryOperation binary_op); // C++17 + +template<class InputIterator, class OutputIterator> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 + +template<class InputIterator, class OutputIterator, class BinaryOperation> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op); // C++17 + +template<class InputIterator, class OutputIterator, class BinaryOperation, class T> + OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op, T init); // C++17 + +template<class InputIterator, class OutputIterator, class T, + class BinaryOperation, class UnaryOperation> + OutputIterator + transform_exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + +template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation> + OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op); // C++17 + +template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation, class T> + OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op, + T init); // C++17 + template <class InputIterator, class OutputIterator> OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); @@ -53,17 +128,28 @@ template <class InputIterator, class OutputIterator, class BinaryOperation> template <class ForwardIterator, class T> void iota(ForwardIterator first, ForwardIterator last, T value); +template <class M, class N> + constexpr common_type_t<M,N> gcd(M m, N n); // C++17 + +template <class M, class N> + constexpr common_type_t<M,N> lcm(M m, N n); // C++17 + } // std */ #include <__config> #include <iterator> +#include <limits> // for numeric_limits +#include <functional> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD template <class _InputIterator, class _Tp> @@ -86,6 +172,35 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOpe return __init; } +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) +{ + for (; __first != __last; ++__first) + __init = __b(__init, *__first); + return __init; +} + +template <class _InputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>()); +} + +template <class _InputIterator> +inline _LIBCPP_INLINE_VISIBILITY +typename iterator_traits<_InputIterator>::value_type +reduce(_InputIterator __first, _InputIterator __last) +{ + return _VSTD::reduce(__first, __last, + typename iterator_traits<_InputIterator>::value_type{}); +} +#endif + template <class _InputIterator1, class _InputIterator2, class _Tp> inline _LIBCPP_INLINE_VISIBILITY _Tp @@ -107,6 +222,41 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 return __init; } +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator __first, _InputIterator __last, + _Tp __init, _BinaryOp __b, _UnaryOp __u) +{ + for (; __first != __last; ++__first) + __init = __b(__init, __u(*__first)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, + class _Tp, class _BinaryOp1, class _BinaryOp2> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + __init = __b1(__init, __b2(*__first1, *__first2)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp +transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init) +{ + return _VSTD::transform_reduce(__first1, __last1, __first2, __init, + _VSTD::plus<>(), _VSTD::multiplies<>()); +} +#endif + template <class _InputIterator, class _OutputIterator> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator @@ -144,6 +294,117 @@ partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __res return __result; } +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, _BinaryOp __b) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, *__first); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init) +{ + return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>()); +} + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) { + __init = __b(__init, *__first); + *__result = __init; + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b) +{ + if (__first != __last) { + typename std::iterator_traits<_InputIterator>::value_type __init = *__first; + *__result++ = __init; + if (++__first != __last) + return _VSTD::inclusive_scan(__first, __last, __result, __b, __init); + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator> +_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result) +{ + return _VSTD::inclusive_scan(__first, __last, __result, std::plus<>()); +} + +template <class _InputIterator, class _OutputIterator, class _Tp, + class _BinaryOp, class _UnaryOp> +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform_exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, + _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, __u(*__first)); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) { + __init = __b(__init, __u(*__first)); + *__result = __init; + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp> +_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) { + typename std::iterator_traits<_InputIterator>::value_type __init = __u(*__first); + *__result++ = __init; + if (++__first != __last) + return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init); + } + + return __result; +} +#endif + template <class _InputIterator, class _OutputIterator> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator @@ -192,6 +453,74 @@ iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) *__first = __value_; } + +#if _LIBCPP_STD_VER > 14 +template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __abs; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, true> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept + { + if (__t >= 0) return __t; + if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t); + return -__t; + } +}; + +template <typename _Result, typename _Source> +struct __abs<_Result, _Source, false> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept { return __t; } +}; + + +template<class _Tp> +_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN +_Tp __gcd(_Tp __m, _Tp __n) +{ + static_assert((!is_signed<_Tp>::value), ""); + return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n); +} + + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +gcd(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" ); + using _Rp = common_type_t<_Tp,_Up>; + using _Wp = make_unsigned_t<_Rp>; + return static_cast<_Rp>(_VSTD::__gcd( + static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)), + static_cast<_Wp>(__abs<_Rp, _Up>()(__n)))); +} + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +lcm(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" ); + if (__m == 0 || __n == 0) + return 0; + + using _Rp = common_type_t<_Tp,_Up>; + _Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n); + _Rp __val2 = __abs<_Rp, _Up>()(__n); + _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); + return __val1 * __val2; +} + +#endif /* _LIBCPP_STD_VER > 14 */ + _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_NUMERIC diff --git a/lib/libcxx/include/optional b/lib/libcxx/include/optional new file mode 100644 index 00000000000..88fd6b5aba2 --- /dev/null +++ b/lib/libcxx/include/optional @@ -0,0 +1,1399 @@ +// -*- C++ -*- +//===-------------------------- optional ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_OPTIONAL +#define _LIBCPP_OPTIONAL + +/* + optional synopsis + +// C++1z + +namespace std { + // 23.6.3, optional for object types + template <class T> class optional; + + // 23.6.4, no-value state indicator + struct nullopt_t{see below }; + inline constexpr nullopt_t nullopt(unspecified ); + + // 23.6.5, class bad_optional_access + class bad_optional_access; + + // 23.6.6, relational operators + template <class T, class U> + constexpr bool operator==(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator!=(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator<(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator>(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator<=(const optional<T>&, const optional<U>&); + template <class T, class U> + constexpr bool operator>=(const optional<T>&, const optional<U>&); + + // 23.6.7 comparison with nullopt + template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept; + template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept; + template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept; + + // 23.6.8, comparison with T + template <class T, class U> constexpr bool operator==(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator==(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator!=(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator<(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator<(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator<=(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator>(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator>(const T&, const optional<U>&); + template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&); + template <class T, class U> constexpr bool operator>=(const T&, const optional<U>&); + + // 23.6.9, specialized algorithms + template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below ); + template <class T> constexpr optional<see below > make_optional(T&&); + template <class T, class... Args> + constexpr optional<T> make_optional(Args&&... args); + template <class T, class U, class... Args> + constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args); + + // 23.6.10, hash support + template <class T> struct hash; + template <class T> struct hash<optional<T>>; + + template <class T> class optional { + public: + using value_type = T; + + // 23.6.3.1, constructors + constexpr optional() noexcept; + constexpr optional(nullopt_t) noexcept; + optional(const optional &); + optional(optional &&) noexcept(see below); + template <class... Args> constexpr explicit optional(in_place_t, Args &&...); + template <class U, class... Args> + constexpr explicit optional(in_place_t, initializer_list<U>, Args &&...); + template <class U = T> + constexpr EXPLICIT optional(U &&); + template <class U> + constexpr EXPLICIT optional(const optional<U> &); + template <class U> + constexpr EXPLICIT optional(optional<U> &&); + + // 23.6.3.2, destructor + ~optional(); + + // 23.6.3.3, assignment + optional &operator=(nullopt_t) noexcept; + optional &operator=(const optional &); + optional &operator=(optional &&) noexcept(see below ); + template <class U = T> optional &operator=(U &&); + template <class U> optional &operator=(const optional<U> &); + template <class U> optional &operator=(optional<U> &&); + template <class... Args> T& emplace(Args &&...); + template <class U, class... Args> + T& emplace(initializer_list<U>, Args &&...); + + // 23.6.3.4, swap + void swap(optional &) noexcept(see below ); + + // 23.6.3.5, observers + constexpr T const *operator->() const; + constexpr T *operator->(); + constexpr T const &operator*() const &; + constexpr T &operator*() &; + constexpr T &&operator*() &&; + constexpr const T &&operator*() const &&; + constexpr explicit operator bool() const noexcept; + constexpr bool has_value() const noexcept; + constexpr T const &value() const &; + constexpr T &value() &; + constexpr T &&value() &&; + constexpr const T &&value() const &&; + template <class U> constexpr T value_or(U &&) const &; + template <class U> constexpr T value_or(U &&) &&; + + // 23.6.3.6, modifiers + void reset() noexcept; + + private: + T *val; // exposition only + }; +} // namespace std + +*/ + +#include <__config> +#include <__debug> +#include <__functional_base> +#include <functional> +#include <initializer_list> +#include <new> +#include <stdexcept> +#include <type_traits> +#include <utility> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +namespace std // purposefully not using versioning namespace +{ + +class _LIBCPP_EXCEPTION_ABI bad_optional_access + : public exception +{ +public: + // Get the key function ~bad_optional_access() into the dylib + virtual ~bad_optional_access() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; +}; + +} // std + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +_LIBCPP_NORETURN +inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_optional_access() { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_optional_access(); +#else + _VSTD::abort(); +#endif +} + +struct nullopt_t +{ + struct __secret_tag { _LIBCPP_INLINE_VISIBILITY explicit __secret_tag() = default; }; + _LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} +}; + +_LIBCPP_INLINE_VAR constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; + +template <class _Tp, bool = is_trivially_destructible<_Tp>::value> +struct __optional_destruct_base; + +template <class _Tp> +struct __optional_destruct_base<_Tp, false> +{ + typedef _Tp value_type; + static_assert(is_object_v<value_type>, + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + value_type __val_; + }; + bool __engaged_; + + _LIBCPP_INLINE_VISIBILITY + ~__optional_destruct_base() + { + if (__engaged_) + __val_.~value_type(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_destruct_base() noexcept + : __null_state_(), + __engaged_(false) {} + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept + { + if (__engaged_) + { + __val_.~value_type(); + __engaged_ = false; + } + } +}; + +template <class _Tp> +struct __optional_destruct_base<_Tp, true> +{ + typedef _Tp value_type; + static_assert(is_object_v<value_type>, + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + value_type __val_; + }; + bool __engaged_; + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_destruct_base() noexcept + : __null_state_(), + __engaged_(false) {} + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_VSTD::forward<_Args>(__args)...), + __engaged_(true) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept + { + if (__engaged_) + { + __engaged_ = false; + } + } +}; + +template <class _Tp, bool = is_reference<_Tp>::value> +struct __optional_storage_base : __optional_destruct_base<_Tp> +{ + using __base = __optional_destruct_base<_Tp>; + using value_type = _Tp; + using __base::__base; + + _LIBCPP_INLINE_VISIBILITY + constexpr bool has_value() const noexcept + { + return this->__engaged_; + } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type& __get() & noexcept + { + return this->__val_; + } + _LIBCPP_INLINE_VISIBILITY + constexpr const value_type& __get() const& noexcept + { + return this->__val_; + } + _LIBCPP_INLINE_VISIBILITY + constexpr value_type&& __get() && noexcept + { + return _VSTD::move(this->__val_); + } + _LIBCPP_INLINE_VISIBILITY + constexpr const value_type&& __get() const&& noexcept + { + return _VSTD::move(this->__val_); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + void __construct(_Args&&... __args) + { + _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); + ::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); + this->__engaged_ = true; + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __construct_from(_That&& __opt) + { + if (__opt.has_value()) + __construct(_VSTD::forward<_That>(__opt).__get()); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __assign_from(_That&& __opt) + { + if (this->__engaged_ == __opt.has_value()) + { + if (this->__engaged_) + this->__val_ = _VSTD::forward<_That>(__opt).__get(); + } + else + { + if (this->__engaged_) + this->reset(); + else + __construct(_VSTD::forward<_That>(__opt).__get()); + } + } +}; + +// optional<T&> is currently required ill-formed, however it may to be in the +// future. For this reason it has already been implemented to ensure we can +// make the change in an ABI compatible manner. +template <class _Tp> +struct __optional_storage_base<_Tp, true> +{ + using value_type = _Tp; + using __raw_type = remove_reference_t<_Tp>; + __raw_type* __value_; + + template <class _Up> + static constexpr bool __can_bind_reference() { + using _RawUp = typename remove_reference<_Up>::type; + using _UpPtr = _RawUp*; + using _RawTp = typename remove_reference<_Tp>::type; + using _TpPtr = _RawTp*; + using _CheckLValueArg = integral_constant<bool, + (is_lvalue_reference<_Up>::value && is_convertible<_UpPtr, _TpPtr>::value) + || is_same<_RawUp, reference_wrapper<_RawTp>>::value + || is_same<_RawUp, reference_wrapper<typename remove_const<_RawTp>::type>>::value + >; + return (is_lvalue_reference<_Tp>::value && _CheckLValueArg::value) + || (is_rvalue_reference<_Tp>::value && !is_lvalue_reference<_Up>::value && + is_convertible<_UpPtr, _TpPtr>::value); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr __optional_storage_base() noexcept + : __value_(nullptr) {} + + template <class _UArg> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit __optional_storage_base(in_place_t, _UArg&& __uarg) + : __value_(_VSTD::addressof(__uarg)) + { + static_assert(__can_bind_reference<_UArg>(), + "Attempted to construct a reference element in tuple from a " + "possible temporary"); + } + + _LIBCPP_INLINE_VISIBILITY + void reset() noexcept { __value_ = nullptr; } + + _LIBCPP_INLINE_VISIBILITY + constexpr bool has_value() const noexcept + { return __value_ != nullptr; } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type& __get() const& noexcept + { return *__value_; } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type&& __get() const&& noexcept + { return _VSTD::forward<value_type>(*__value_); } + + template <class _UArg> + _LIBCPP_INLINE_VISIBILITY + void __construct(_UArg&& __val) + { + _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); + static_assert(__can_bind_reference<_UArg>(), + "Attempted to construct a reference element in tuple from a " + "possible temporary"); + __value_ = _VSTD::addressof(__val); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __construct_from(_That&& __opt) + { + if (__opt.has_value()) + __construct(_VSTD::forward<_That>(__opt).__get()); + } + + template <class _That> + _LIBCPP_INLINE_VISIBILITY + void __assign_from(_That&& __opt) + { + if (has_value() == __opt.has_value()) + { + if (has_value()) + *__value_ = _VSTD::forward<_That>(__opt).__get(); + } + else + { + if (has_value()) + reset(); + else + __construct(_VSTD::forward<_That>(__opt).__get()); + } + } +}; + +template <class _Tp, bool = is_trivially_copy_constructible<_Tp>::value> +struct __optional_copy_base : __optional_storage_base<_Tp> +{ + using __optional_storage_base<_Tp>::__optional_storage_base; +}; + +template <class _Tp> +struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp> +{ + using __optional_storage_base<_Tp>::__optional_storage_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base() = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base(const __optional_copy_base& __opt) + { + this->__construct_from(__opt); + } + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base(__optional_copy_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(const __optional_copy_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(__optional_copy_base&&) = default; +}; + +template <class _Tp, bool = is_trivially_move_constructible<_Tp>::value> +struct __optional_move_base : __optional_copy_base<_Tp> +{ + using __optional_copy_base<_Tp>::__optional_copy_base; +}; + +template <class _Tp> +struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_base<_Tp>::__optional_copy_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(const __optional_move_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(__optional_move_base&& __opt) + noexcept(is_nothrow_move_constructible_v<value_type>) + { + this->__construct_from(_VSTD::move(__opt)); + } + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base& operator=(const __optional_move_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base& operator=(__optional_move_base&&) = default; +}; + +template <class _Tp, bool = + is_trivially_destructible<_Tp>::value && + is_trivially_copy_constructible<_Tp>::value && + is_trivially_copy_assignable<_Tp>::value> +struct __optional_copy_assign_base : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; +}; + +template <class _Tp> +struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(const __optional_copy_assign_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(__optional_copy_assign_base&&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt) + { + this->__assign_from(__opt); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; +}; + +template <class _Tp, bool = + is_trivially_destructible<_Tp>::value && + is_trivially_move_constructible<_Tp>::value && + is_trivially_move_assignable<_Tp>::value> +struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> +{ + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; +}; + +template <class _Tp> +struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(__optional_move_assign_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(__optional_move_assign_base&& __opt) + noexcept(is_nothrow_move_assignable_v<value_type> && + is_nothrow_move_constructible_v<value_type>) + { + this->__assign_from(_VSTD::move(__opt)); + return *this; + } +}; + +template <class _Tp> +using __optional_sfinae_ctor_base_t = __sfinae_ctor_base< + is_copy_constructible<_Tp>::value, + is_move_constructible<_Tp>::value +>; + +template <class _Tp> +using __optional_sfinae_assign_base_t = __sfinae_assign_base< + (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), + (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) +>; + +template <class _Tp> +class optional + : private __optional_move_assign_base<_Tp> + , private __optional_sfinae_ctor_base_t<_Tp> + , private __optional_sfinae_assign_base_t<_Tp> +{ + using __base = __optional_move_assign_base<_Tp>; +public: + using value_type = _Tp; + +private: + // Disable the reference extension using this static assert. + static_assert(!is_same_v<value_type, in_place_t>, + "instantiation of optional with in_place_t is ill-formed"); + static_assert(!is_same_v<__uncvref_t<value_type>, nullopt_t>, + "instantiation of optional with nullopt_t is ill-formed"); + static_assert(!is_reference_v<value_type>, + "instantiation of optional with a reference type is ill-formed"); + static_assert(is_destructible_v<value_type>, + "instantiation of optional with a non-destructible type is ill-formed"); + + // LWG2756: conditionally explicit conversion from _Up + struct _CheckOptionalArgsConstructor { + template <class _Up> + static constexpr bool __enable_implicit() { + return is_constructible_v<_Tp, _Up&&> && + is_convertible_v<_Up&&, _Tp>; + } + + template <class _Up> + static constexpr bool __enable_explicit() { + return is_constructible_v<_Tp, _Up&&> && + !is_convertible_v<_Up&&, _Tp>; + } + }; + template <class _Up> + using _CheckOptionalArgsCtor = conditional_t< + !is_same_v<decay_t<_Up>, in_place_t> && + !is_same_v<decay_t<_Up>, optional>, + _CheckOptionalArgsConstructor, + __check_tuple_constructor_fail + >; + template <class _QualUp> + struct _CheckOptionalLikeConstructor { + template <class _Up, class _Opt = optional<_Up>> + using __check_constructible_from_opt = __lazy_or< + is_constructible<_Tp, _Opt&>, + is_constructible<_Tp, _Opt const&>, + is_constructible<_Tp, _Opt&&>, + is_constructible<_Tp, _Opt const&&>, + is_convertible<_Opt&, _Tp>, + is_convertible<_Opt const&, _Tp>, + is_convertible<_Opt&&, _Tp>, + is_convertible<_Opt const&&, _Tp> + >; + template <class _Up, class _Opt = optional<_Up>> + using __check_assignable_from_opt = __lazy_or< + is_assignable<_Tp&, _Opt&>, + is_assignable<_Tp&, _Opt const&>, + is_assignable<_Tp&, _Opt&&>, + is_assignable<_Tp&, _Opt const&&> + >; + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_implicit() { + return is_convertible<_QUp, _Tp>::value && + !__check_constructible_from_opt<_Up>::value; + } + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_explicit() { + return !is_convertible<_QUp, _Tp>::value && + !__check_constructible_from_opt<_Up>::value; + } + template <class _Up, class _QUp = _QualUp> + static constexpr bool __enable_assign() { + // Construction and assignability of _Qup to _Tp has already been + // checked. + return !__check_constructible_from_opt<_Up>::value && + !__check_assignable_from_opt<_Up>::value; + } + }; + + template <class _Up, class _QualUp> + using _CheckOptionalLikeCtor = conditional_t< + __lazy_and< + __lazy_not<is_same<_Up, _Tp>>, + is_constructible<_Tp, _QualUp> + >::value, + _CheckOptionalLikeConstructor<_QualUp>, + __check_tuple_constructor_fail + >; + template <class _Up, class _QualUp> + using _CheckOptionalLikeAssign = conditional_t< + __lazy_and< + __lazy_not<is_same<_Up, _Tp>>, + is_constructible<_Tp, _QualUp>, + is_assignable<_Tp&, _QualUp> + >::value, + _CheckOptionalLikeConstructor<_QualUp>, + __check_tuple_constructor_fail + >; +public: + + _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {} + _LIBCPP_INLINE_VISIBILITY constexpr optional(const optional&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default; + _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} + + template <class... _Args, class = enable_if_t< + is_constructible_v<value_type, _Args...>> + > + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(in_place_t, _Args&&... __args) + : __base(in_place, _VSTD::forward<_Args>(__args)...) {} + + template <class _Up, class... _Args, class = enable_if_t< + is_constructible_v<value_type, initializer_list<_Up>&, _Args...>> + > + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {} + + template <class _Up = value_type, enable_if_t< + _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + constexpr optional(_Up&& __v) + : __base(in_place, _VSTD::forward<_Up>(__v)) {} + + template <class _Up, enable_if_t< + _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + constexpr explicit optional(_Up&& __v) + : __base(in_place, _VSTD::forward<_Up>(__v)) {} + + // LWG2756: conditionally explicit conversion from const optional<_Up>& + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + explicit optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } + + // LWG2756: conditionally explicit conversion from optional<_Up>&& + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional(optional<_Up>&& __v) + { + this->__construct_from(_VSTD::move(__v)); + } + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + explicit optional(optional<_Up>&& __v) + { + this->__construct_from(_VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + optional& operator=(nullopt_t) noexcept + { + reset(); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY optional& operator=(const optional&) = default; + _LIBCPP_INLINE_VISIBILITY optional& operator=(optional&&) = default; + + // LWG2756 + template <class _Up = value_type, + class = enable_if_t + <__lazy_and< + integral_constant<bool, + !is_same_v<decay_t<_Up>, optional> && + !(is_same_v<_Up, value_type> && is_scalar_v<value_type>) + >, + is_constructible<value_type, _Up>, + is_assignable<value_type&, _Up> + >::value> + > + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(_Up&& __v) + { + if (this->has_value()) + this->__get() = _VSTD::forward<_Up>(__v); + else + this->__construct(_VSTD::forward<_Up>(__v)); + return *this; + } + + // LWG2756 + template <class _Up, enable_if_t< + _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(const optional<_Up>& __v) + { + this->__assign_from(__v); + return *this; + } + + // LWG2756 + template <class _Up, enable_if_t< + _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>() + , int> = 0> + _LIBCPP_INLINE_VISIBILITY + optional& + operator=(optional<_Up>&& __v) + { + this->__assign_from(_VSTD::move(__v)); + return *this; + } + + template <class... _Args, + class = enable_if_t + < + is_constructible_v<value_type, _Args...> + > + > + _LIBCPP_INLINE_VISIBILITY + _Tp & + emplace(_Args&&... __args) + { + reset(); + this->__construct(_VSTD::forward<_Args>(__args)...); + return this->__get(); + } + + template <class _Up, class... _Args, + class = enable_if_t + < + is_constructible_v<value_type, initializer_list<_Up>&, _Args...> + > + > + _LIBCPP_INLINE_VISIBILITY + _Tp & + emplace(initializer_list<_Up> __il, _Args&&... __args) + { + reset(); + this->__construct(__il, _VSTD::forward<_Args>(__args)...); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + void swap(optional& __opt) + noexcept(is_nothrow_move_constructible_v<value_type> && + is_nothrow_swappable_v<value_type>) + { + if (this->has_value() == __opt.has_value()) + { + using _VSTD::swap; + if (this->has_value()) + swap(this->__get(), __opt.__get()); + } + else + { + if (this->has_value()) + { + __opt.__construct(_VSTD::move(this->__get())); + reset(); + } + else + { + this->__construct(_VSTD::move(__opt.__get())); + __opt.reset(); + } + } + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + add_pointer_t<value_type const> + operator->() const + { + _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + return _VSTD::addressof(this->__get()); +#else + return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + add_pointer_t<value_type> + operator->() + { + _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF + return _VSTD::addressof(this->__get()); +#else + return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get()); +#endif + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + const value_type& + operator*() const& + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + value_type& + operator*() & + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + value_type&& + operator*() && + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr + const value_type&& + operator*() const&& + { + _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr explicit operator bool() const noexcept { return has_value(); } + + using __base::has_value; + using __base::__get; + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type const& value() const& + { + if (!this->has_value()) + __throw_bad_optional_access(); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type& value() & + { + if (!this->has_value()) + __throw_bad_optional_access(); + return this->__get(); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type&& value() && + { + if (!this->has_value()) + __throw_bad_optional_access(); + return _VSTD::move(this->__get()); + } + + _LIBCPP_INLINE_VISIBILITY + constexpr value_type const&& value() const&& + { + if (!this->has_value()) + __throw_bad_optional_access(); + return _VSTD::move(this->__get()); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + constexpr value_type value_or(_Up&& __v) const& + { + static_assert(is_copy_constructible_v<value_type>, + "optional<T>::value_or: T must be copy constructible"); + static_assert(is_convertible_v<_Up, value_type>, + "optional<T>::value_or: U must be convertible to T"); + return this->has_value() ? this->__get() : + static_cast<value_type>(_VSTD::forward<_Up>(__v)); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + constexpr value_type value_or(_Up&& __v) && + { + static_assert(is_move_constructible_v<value_type>, + "optional<T>::value_or: T must be move constructible"); + static_assert(is_convertible_v<_Up, value_type>, + "optional<T>::value_or: U must be convertible to T"); + return this->has_value() ? _VSTD::move(this->__get()) : + static_cast<value_type>(_VSTD::forward<_Up>(__v)); + } + + using __base::reset; + +private: + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static _Up* + __operator_arrow(true_type, _Up& __x) + { + return _VSTD::addressof(__x); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static constexpr _Up* + __operator_arrow(false_type, _Up& __x) + { + return &__x; + } +}; + +// Comparisons between optionals +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (static_cast<bool>(__x) != static_cast<bool>(__y)) + return false; + if (!static_cast<bool>(__x)) + return true; + return *__x == *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (static_cast<bool>(__x) != static_cast<bool>(__y)) + return true; + if (!static_cast<bool>(__x)) + return false; + return *__x != *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__y)) + return false; + if (!static_cast<bool>(__x)) + return true; + return *__x < *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__x)) + return false; + if (!static_cast<bool>(__y)) + return true; + return *__x > *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__x)) + return true; + if (!static_cast<bool>(__y)) + return false; + return *__x <= *__y; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) +{ + if (!static_cast<bool>(__y)) + return true; + if (!static_cast<bool>(__x)) + return false; + return *__x >= *__y; +} + +// Comparisons with nullopt +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator==(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator==(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator!=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator!=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<(const optional<_Tp>&, nullopt_t) noexcept +{ + return false; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return !static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator<=(nullopt_t, const optional<_Tp>&) noexcept +{ + return true; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast<bool>(__x); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>(nullopt_t, const optional<_Tp>&) noexcept +{ + return false; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>=(const optional<_Tp>&, nullopt_t) noexcept +{ + return true; +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +bool +operator>=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return !static_cast<bool>(__x); +} + +// Comparisons with T +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x == __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator==(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v == *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x != __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator!=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v != *__x : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x < __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v < *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x <= __v : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator<=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v <= *__x : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x > __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v > *__x : true; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const optional<_Tp>& __x, const _Up& __v) +{ + return static_cast<bool>(__x) ? *__x >= __v : false; +} + +template <class _Tp, class _Up> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t< + is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= + _VSTD::declval<const _Up&>()), bool>, + bool +> +operator>=(const _Tp& __v, const optional<_Up>& __x) +{ + return static_cast<bool>(__x) ? __v >= *__x : true; +} + + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +enable_if_t< + is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, + void +> +swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<decay_t<_Tp>> make_optional(_Tp&& __v) +{ + return optional<decay_t<_Tp>>(_VSTD::forward<_Tp>(__v)); +} + +template <class _Tp, class... _Args> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<_Tp> make_optional(_Args&&... __args) +{ + return optional<_Tp>(in_place, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp, class _Up, class... _Args> +_LIBCPP_INLINE_VISIBILITY constexpr +optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) +{ + return optional<_Tp>(in_place, __il, _VSTD::forward<_Args>(__args)...); +} + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash< + __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> +> +{ + typedef optional<_Tp> argument_type; + typedef size_t result_type; + + _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __opt) const + { + return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0; + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_OPTIONAL diff --git a/lib/libcxx/include/ostream b/lib/libcxx/include/ostream index f55fd40856e..f3250a7080d 100644 --- a/lib/libcxx/include/ostream +++ b/lib/libcxx/include/ostream @@ -148,7 +148,7 @@ template <class charT, class traits, class T> _LIBCPP_BEGIN_NAMESPACE_STD template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_ostream +class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Traits> { public: @@ -160,22 +160,24 @@ public: typedef typename traits_type::off_type off_type; // 27.7.2.2 Constructor/destructor: - explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) + { this->init(__sb); } virtual ~basic_ostream(); protected: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_ostream(basic_ostream&& __rhs); -#endif // 27.7.2.3 Assign/swap -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY + inline _LIBCPP_INLINE_VISIBILITY basic_ostream& operator=(basic_ostream&& __rhs); #endif - void swap(basic_ostream& __rhs); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void swap(basic_ostream& __rhs) + { basic_ios<char_type, traits_type>::swap(__rhs); } -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG basic_ostream (const basic_ostream& __rhs) = delete; basic_ostream& operator=(const basic_ostream& __rhs) = delete; #else @@ -185,13 +187,22 @@ protected: public: // 27.7.2.4 Prefix/suffix: - class _LIBCPP_TYPE_VIS_ONLY sentry; + class _LIBCPP_TEMPLATE_VIS sentry; // 27.7.2.6 Formatted output: - basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) + { return __pf(*this); } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_ostream& operator<<(basic_ios<char_type, traits_type>& - (*__pf)(basic_ios<char_type,traits_type>&)); - basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)); + (*__pf)(basic_ios<char_type,traits_type>&)) + { __pf(*this); return *this; } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) + { __pf(*this); return *this; } + basic_ostream& operator<<(bool __n); basic_ostream& operator<<(short __n); basic_ostream& operator<<(unsigned short __n); @@ -213,8 +224,11 @@ public: basic_ostream& flush(); // 27.7.2.5 seeks: + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY pos_type tellp(); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_ostream& seekp(pos_type __pos); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); protected: @@ -223,7 +237,7 @@ protected: }; template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry +class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry { bool __ok_; basic_ostream<_CharT, _Traits>& __os_; @@ -274,24 +288,15 @@ basic_ostream<_CharT, _Traits>::sentry::~sentry() } } -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb) -{ - this->init(__sb); -} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) { this->move(__rhs); } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) { @@ -299,7 +304,7 @@ basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits> basic_ostream<_CharT, _Traits>::~basic_ostream() @@ -307,41 +312,6 @@ basic_ostream<_CharT, _Traits>::~basic_ostream() } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs) -{ - basic_ios<char_type, traits_type>::swap(__rhs); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_ostream<_CharT, _Traits>& -basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&)) -{ - return __pf(*this); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_ostream<_CharT, _Traits>& -basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>& - (*__pf)(basic_ios<char_type,traits_type>&)) -{ - __pf(*this); - return *this; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_ostream<_CharT, _Traits>& -basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&)) -{ - __pf(*this); - return *this; -} - -template <class _CharT, class _Traits> basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) { @@ -989,7 +959,6 @@ basic_ostream<_CharT, _Traits>::flush() } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY typename basic_ostream<_CharT, _Traits>::pos_type basic_ostream<_CharT, _Traits>::tellp() { @@ -999,7 +968,6 @@ basic_ostream<_CharT, _Traits>::tellp() } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) { @@ -1013,7 +981,6 @@ basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) { @@ -1054,7 +1021,7 @@ flush(basic_ostream<_CharT, _Traits>& __os) return __os; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Stream, class _Tp> inline _LIBCPP_INLINE_VISIBILITY @@ -1070,7 +1037,7 @@ operator<<(_Stream&& __os, const _Tp& __x) return _VSTD::move(__os); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> basic_ostream<_CharT, _Traits>& @@ -1080,6 +1047,14 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, return _VSTD::__put_character_sequence(__os, __str.data(), __str.size()); } +template<class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const basic_string_view<_CharT, _Traits> __sv) +{ + return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size()); +} + template <class _CharT, class _Traits> inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& @@ -1096,6 +1071,20 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) return __os << __p.get(); } +#ifndef _LIBCPP_HAS_NO_DECLTYPE +template<class _CharT, class _Traits, class _Yp, class _Dp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same<void, typename __void_t<decltype(declval<basic_ostream<_CharT, _Traits>&>() << declval<_Yp>())>::type>::value, + basic_ostream<_CharT, _Traits>& +>::type +operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) +{ + return __os << __p.get(); +} +#endif + template <class _CharT, class _Traits, size_t _Size> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) @@ -1105,8 +1094,10 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) use_facet<ctype<_CharT> >(__os.getloc()).widen('1')); } -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>) +#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>) +#endif _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/queue b/lib/libcxx/include/queue index c657b52f803..670fbb722ee 100644 --- a/lib/libcxx/include/queue +++ b/lib/libcxx/include/queue @@ -63,7 +63,7 @@ public: void push(const value_type& v); void push(value_type&& v); - template <class... Args> void emplace(Args&&... args); + template <class... Args> reference emplace(Args&&... args); // reference in C++17 void pop(); void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>) @@ -178,7 +178,7 @@ template <class T, class Container, class Compare> _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY queue; +template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue; template <class _Tp, class _Container> _LIBCPP_INLINE_VISIBILITY @@ -191,7 +191,7 @@ bool operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); template <class _Tp, class _Container /*= deque<_Tp>*/> -class _LIBCPP_TYPE_VIS_ONLY queue +class _LIBCPP_TEMPLATE_VIS queue { public: typedef _Container container_type; @@ -213,29 +213,27 @@ public: _LIBCPP_INLINE_VISIBILITY queue(const queue& __q) : c(__q.c) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + queue& operator=(const queue& __q) {c = __q.c; return *this;} + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY queue(queue&& __q) _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) : c(_VSTD::move(__q.c)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY - queue& operator=(const queue& __q) {c = __q.c; return *this;} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY queue& operator=(queue&& __q) _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) {c = _VSTD::move(__q.c); return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit queue(const container_type& __c) : c(__c) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit queue(const _Alloc& __a, @@ -254,7 +252,7 @@ public: typename enable_if<uses_allocator<container_type, _Alloc>::value>::type* = 0) : c(__c, __a) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Alloc> _LIBCPP_INLINE_VISIBILITY queue(container_type&& __c, const _Alloc& __a, @@ -268,9 +266,9 @@ public: _Alloc>::value>::type* = 0) : c(_VSTD::move(__q.c), __a) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} @@ -286,16 +284,19 @@ public: _LIBCPP_INLINE_VISIBILITY void push(const value_type& __v) {c.push_back(__v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} -#ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args> _LIBCPP_INLINE_VISIBILITY - void emplace(_Args&&... __args) - {c.emplace_back(_VSTD::forward<_Args>(__args)...);} -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER > 14 + reference emplace(_Args&&... __args) + { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#else + void emplace(_Args&&... __args) + { c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#endif +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void pop() {c.pop_front();} @@ -381,14 +382,14 @@ swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) } template <class _Tp, class _Container, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<queue<_Tp, _Container>, _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> { }; template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> > -class _LIBCPP_TYPE_VIS_ONLY priority_queue +class _LIBCPP_TEMPLATE_VIS priority_queue { public: typedef _Container container_type; @@ -413,32 +414,30 @@ public: _LIBCPP_INLINE_VISIBILITY priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + priority_queue& operator=(const priority_queue& __q) + {c = __q.c; comp = __q.comp; return *this;} + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY priority_queue(priority_queue&& __q) _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value && is_nothrow_move_constructible<value_compare>::value) : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - - _LIBCPP_INLINE_VISIBILITY - priority_queue& operator=(const priority_queue& __q) - {c = __q.c; comp = __q.comp; return *this;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY priority_queue& operator=(priority_queue&& __q) _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value && is_nothrow_move_assignable<value_compare>::value) {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {} _LIBCPP_INLINE_VISIBILITY priority_queue(const value_compare& __comp, const container_type& __c); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit priority_queue(const value_compare& __comp, container_type&& __c); #endif @@ -450,12 +449,12 @@ public: _LIBCPP_INLINE_VISIBILITY priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _InputIter> _LIBCPP_INLINE_VISIBILITY priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit priority_queue(const _Alloc& __a, @@ -477,7 +476,7 @@ public: priority_queue(const priority_queue& __q, const _Alloc& __a, typename enable_if<uses_allocator<container_type, _Alloc>::value>::type* = 0); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Alloc> _LIBCPP_INLINE_VISIBILITY priority_queue(const value_compare& __comp, container_type&& __c, @@ -489,9 +488,9 @@ public: priority_queue(priority_queue&& __q, const _Alloc& __a, typename enable_if<uses_allocator<container_type, _Alloc>::value>::type* = 0); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} @@ -500,13 +499,13 @@ public: _LIBCPP_INLINE_VISIBILITY void push(const value_type& __v); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push(value_type&& __v); -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class... _Args> _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args); -#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + void emplace(_Args&&... __args); +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void pop(); @@ -526,7 +525,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp _VSTD::make_heap(c.begin(), c.end(), comp); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> inline @@ -538,7 +537,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& _ _VSTD::make_heap(c.begin(), c.end(), comp); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> template <class _InputIter> @@ -564,7 +563,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input _VSTD::make_heap(c.begin(), c.end(), comp); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> template <class _InputIter> @@ -579,7 +578,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _Input _VSTD::make_heap(c.begin(), c.end(), comp); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> template <class _Alloc> @@ -630,7 +629,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& _VSTD::make_heap(c.begin(), c.end(), comp); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> template <class _Alloc> @@ -659,7 +658,7 @@ priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, _VSTD::make_heap(c.begin(), c.end(), comp); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> inline @@ -670,7 +669,7 @@ priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) _VSTD::push_heap(c.begin(), c.end(), comp); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> inline @@ -681,8 +680,6 @@ priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) _VSTD::push_heap(c.begin(), c.end(), comp); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Container, class _Compare> template <class... _Args> inline @@ -693,8 +690,7 @@ priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) _VSTD::push_heap(c.begin(), c.end(), comp); } -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Container, class _Compare> inline @@ -732,7 +728,7 @@ swap(priority_queue<_Tp, _Container, _Compare>& __x, } template <class _Tp, class _Container, class _Compare, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> : public uses_allocator<_Container, _Alloc> { }; diff --git a/lib/libcxx/include/random b/lib/libcxx/include/random index 794bf7b3fd1..9073a5285b1 100644 --- a/lib/libcxx/include/random +++ b/lib/libcxx/include/random @@ -1646,12 +1646,14 @@ class piecewise_linear_distribution #include <istream> #include <ostream> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // __is_seed_sequence @@ -1813,7 +1815,7 @@ struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> }; template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> -class _LIBCPP_TYPE_VIS_ONLY linear_congruential_engine; +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; template <class _CharT, class _Traits, class _Up, _Up _Ap, _Up _Cp, _Up _Np> @@ -1829,7 +1831,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> -class _LIBCPP_TYPE_VIS_ONLY linear_congruential_engine +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine { public: // types @@ -2011,49 +2013,49 @@ typedef minstd_rand default_random_engine; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> -class _LIBCPP_TYPE_VIS_ONLY mersenne_twister_engine; +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; -template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> bool -operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); -template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> _LIBCPP_INLINE_VISIBILITY bool -operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> -class _LIBCPP_TYPE_VIS_ONLY mersenne_twister_engine +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine { public: // types @@ -2129,44 +2131,44 @@ public: _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} - template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> friend bool - operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); - template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> friend bool - operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x); private: @@ -2306,6 +2308,7 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, void mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::seed(result_type __sd) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2 __x_[0] = __sd & _Max; for (size_t __i = 1; __i < __n; ++__i) @@ -2384,13 +2387,13 @@ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, return __z ^ __rshift<__l>(__z); } -template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> bool -operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) { if (__x.__i_ == __y.__i_) @@ -2428,26 +2431,26 @@ operator==(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, __x.__x_ + (_Np - (__y.__i_ + __j))); } -template <class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> inline _LIBCPP_INLINE_VISIBILITY bool -operator!=(const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __y) { return !(__x == __y); } template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); @@ -2463,17 +2466,17 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, } template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, - _UI _Ap, size_t _Up, _UI _Dp, size_t _Sp, - _UI _Bp, size_t _Tp, _UI _Cp, size_t _Lp, _UI _Fp> + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - mersenne_twister_engine<_UI, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, _Bp, _Tp, _Cp, _Lp, _Fp>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); - _UI __t[_Np]; + _UInt __t[_Np]; for (size_t __i = 0; __i < _Np; ++__i) __is >> __t[__i]; if (!__is.fail()) @@ -2499,35 +2502,35 @@ typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, // subtract_with_carry_engine template<class _UIntType, size_t __w, size_t __s, size_t __r> -class _LIBCPP_TYPE_VIS_ONLY subtract_with_carry_engine; +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; -template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> bool operator==( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); -template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> _LIBCPP_INLINE_VISIBILITY bool operator!=( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template<class _UIntType, size_t __w, size_t __s, size_t __r> -class _LIBCPP_TYPE_VIS_ONLY subtract_with_carry_engine +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine { public: // types @@ -2586,33 +2589,33 @@ public: _LIBCPP_INLINE_VISIBILITY void discard(unsigned long long __z) {for (; __z; --__z) operator()();} - template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> friend bool operator==( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); - template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> friend bool operator!=( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x); + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); private: @@ -2711,11 +2714,11 @@ subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() return __xr; } -template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> bool operator==( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y) + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) { if (__x.__c_ != __y.__c_) return false; @@ -2754,21 +2757,21 @@ operator==( __x.__x_ + (_Rp - (__y.__i_ + __j))); } -template<class _UI, size_t _Wp, size_t _Sp, size_t _Rp> +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> inline _LIBCPP_INLINE_VISIBILITY bool operator!=( - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __y) + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) { return !(__x == __y); } template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x) + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__os); __os.flags(ios_base::dec | ios_base::left); @@ -2784,14 +2787,14 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, } template <class _CharT, class _Traits, - class _UI, size_t _Wp, size_t _Sp, size_t _Rp> + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_engine<_UI, _Wp, _Sp, _Rp>& __x) + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) { __save_flags<_CharT, _Traits> __lx(__is); __is.flags(ios_base::dec | ios_base::skipws); - _UI __t[_Rp+1]; + _UInt __t[_Rp+1]; for (size_t __i = 0; __i < _Rp+1; ++__i) __is >> __t[__i]; if (!__is.fail()) @@ -2810,13 +2813,14 @@ typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; // discard_block_engine template<class _Engine, size_t __p, size_t __r> -class _LIBCPP_TYPE_VIS_ONLY discard_block_engine +class _LIBCPP_TEMPLATE_VIS discard_block_engine { _Engine __e_; int __n_; static_assert( 0 < __r, "discard_block_engine invalid parameters"); static_assert(__r <= __p, "discard_block_engine invalid parameters"); + static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); public: // types typedef typename _Engine::result_type result_type; @@ -2825,7 +2829,7 @@ public: static _LIBCPP_CONSTEXPR const size_t block_size = __p; static _LIBCPP_CONSTEXPR const size_t used_block = __r; -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG static const result_type _Min = _Engine::_Min; static const result_type _Max = _Engine::_Max; #else @@ -2844,11 +2848,11 @@ public: _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(const _Engine& __e) : __e_(__e), __n_(0) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(_Engine&& __e) : __e_(_VSTD::move(__e)), __n_(0) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} template<class _Sseq> @@ -2918,7 +2922,7 @@ template<class _Engine, size_t __p, size_t __r> typename discard_block_engine<_Engine, __p, __r>::result_type discard_block_engine<_Engine, __p, __r>::operator()() { - if (__n_ >= __r) + if (__n_ >= static_cast<int>(__r)) { __e_.discard(__p - __r); __n_ = 0; @@ -2983,15 +2987,15 @@ typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; // independent_bits_engine template<class _Engine, size_t __w, class _UIntType> -class _LIBCPP_TYPE_VIS_ONLY independent_bits_engine +class _LIBCPP_TEMPLATE_VIS independent_bits_engine { - template <class _UI, _UI _R0, size_t _Wp, size_t _Mp> + template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> class __get_n { - static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UI>::digits; + static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; - static _LIBCPP_CONSTEXPR const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; + static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; public: static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; }; @@ -3013,7 +3017,7 @@ private: result_type, _Engine_result_type >::type _Working_result_type; -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + _Working_result_type(1); #else @@ -3054,11 +3058,11 @@ public: _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(const _Engine& __e) : __e_(__e) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(_Engine&& __e) : __e_(_VSTD::move(__e)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} template<class _Sseq> @@ -3090,33 +3094,33 @@ public: _LIBCPP_INLINE_VISIBILITY const _Engine& base() const _NOEXCEPT {return __e_;} - template<class _Eng, size_t _Wp, class _UI> + template<class _Eng, size_t _Wp, class _UInt> friend bool operator==( - const independent_bits_engine<_Eng, _Wp, _UI>& __x, - const independent_bits_engine<_Eng, _Wp, _UI>& __y); + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); - template<class _Eng, size_t _Wp, class _UI> + template<class _Eng, size_t _Wp, class _UInt> friend bool operator!=( - const independent_bits_engine<_Eng, _Wp, _UI>& __x, - const independent_bits_engine<_Eng, _Wp, _UI>& __y); + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); template <class _CharT, class _Traits, - class _Eng, size_t _Wp, class _UI> + class _Eng, size_t _Wp, class _UInt> friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const independent_bits_engine<_Eng, _Wp, _UI>& __x); + const independent_bits_engine<_Eng, _Wp, _UInt>& __x); template <class _CharT, class _Traits, - class _Eng, size_t _Wp, class _UI> + class _Eng, size_t _Wp, class _UInt> friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - independent_bits_engine<_Eng, _Wp, _UI>& __x); + independent_bits_engine<_Eng, _Wp, _UInt>& __x); private: _LIBCPP_INLINE_VISIBILITY @@ -3178,40 +3182,40 @@ independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) return _Sp; } -template<class _Eng, size_t _Wp, class _UI> +template<class _Eng, size_t _Wp, class _UInt> inline _LIBCPP_INLINE_VISIBILITY bool operator==( - const independent_bits_engine<_Eng, _Wp, _UI>& __x, - const independent_bits_engine<_Eng, _Wp, _UI>& __y) + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) { return __x.base() == __y.base(); } -template<class _Eng, size_t _Wp, class _UI> +template<class _Eng, size_t _Wp, class _UInt> inline _LIBCPP_INLINE_VISIBILITY bool operator!=( - const independent_bits_engine<_Eng, _Wp, _UI>& __x, - const independent_bits_engine<_Eng, _Wp, _UI>& __y) + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) { return !(__x == __y); } template <class _CharT, class _Traits, - class _Eng, size_t _Wp, class _UI> + class _Eng, size_t _Wp, class _UInt> basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const independent_bits_engine<_Eng, _Wp, _UI>& __x) + const independent_bits_engine<_Eng, _Wp, _UInt>& __x) { return __os << __x.base(); } template <class _CharT, class _Traits, - class _Eng, size_t _Wp, class _UI> + class _Eng, size_t _Wp, class _UInt> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, - independent_bits_engine<_Eng, _Wp, _UI>& __x) + independent_bits_engine<_Eng, _Wp, _UInt>& __x) { _Eng __e; __is >> __e; @@ -3247,7 +3251,7 @@ public: }; template<class _Engine, size_t __k> -class _LIBCPP_TYPE_VIS_ONLY shuffle_order_engine +class _LIBCPP_TEMPLATE_VIS shuffle_order_engine { static_assert(0 < __k, "shuffle_order_engine invalid parameters"); public: @@ -3263,7 +3267,7 @@ public: // engine characteristics static _LIBCPP_CONSTEXPR const size_t table_size = __k; -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG static const result_type _Min = _Engine::_Min; static const result_type _Max = _Engine::_Max; #else @@ -3284,11 +3288,11 @@ public: _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(const _Engine& __e) : __e_(__e) {__init();} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(_Engine&& __e) : __e_(_VSTD::move(__e)) {__init();} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} template<class _Sseq> @@ -3510,7 +3514,7 @@ private: // seed_seq -class _LIBCPP_TYPE_VIS_ONLY seed_seq +class _LIBCPP_TEMPLATE_VIS seed_seq { public: // types @@ -3525,11 +3529,11 @@ public: // constructors _LIBCPP_INLINE_VISIBILITY seed_seq() _NOEXCEPT {} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _Tp> _LIBCPP_INLINE_VISIBILITY seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _InputIterator> _LIBCPP_INLINE_VISIBILITY @@ -3636,7 +3640,7 @@ generate_canonical(_URNG& __g) { const size_t _Dt = numeric_limits<_RealType>::digits; const size_t __b = _Dt < __bits ? _Dt : __bits; -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; #else const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; @@ -3687,13 +3691,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // uniform_real_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY uniform_real_distribution +class _LIBCPP_TEMPLATE_VIS uniform_real_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; @@ -3808,13 +3812,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // bernoulli_distribution -class _LIBCPP_TYPE_VIS_ONLY bernoulli_distribution +class _LIBCPP_TEMPLATE_VIS bernoulli_distribution { public: // types typedef bool result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { double __p_; public: @@ -3917,13 +3921,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) // binomial_distribution template<class _IntType = int> -class _LIBCPP_TYPE_VIS_ONLY binomial_distribution +class _LIBCPP_TEMPLATE_VIS binomial_distribution { public: // types typedef _IntType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __t_; double __p_; @@ -3996,16 +4000,30 @@ public: {return !(__x == __y);} }; +#ifndef _LIBCPP_MSVCRT +extern "C" double lgamma_r(double, int *); +#endif + +inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { +#if defined(_LIBCPP_MSVCRT) + return lgamma(__d); +#else + int __sign; + return lgamma_r(__d, &__sign); +#endif +} + template<class _IntType> -binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) +binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) : __t_(__t), __p_(__p) { if (0 < __p_ && __p_ < 1) { __r0_ = static_cast<result_type>((__t_ + 1) * __p_); - __pr_ = _VSTD::exp(_VSTD::lgamma(__t_ + 1.) - _VSTD::lgamma(__r0_ + 1.) - - _VSTD::lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + - (__t_ - __r0_) * _VSTD::log(1 - __p_)); + __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - + __libcpp_lgamma(__r0_ + 1.) - + __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + + (__t_ - __r0_) * _VSTD::log(1 - __p_)); __odds_ratio_ = __p_ / (1 - __p_); } } @@ -4085,13 +4103,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // exponential_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY exponential_distribution +class _LIBCPP_TEMPLATE_VIS exponential_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __lambda_; public: @@ -4200,13 +4218,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // normal_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY normal_distribution +class _LIBCPP_TEMPLATE_VIS normal_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __mean_; result_type __stddev_; @@ -4368,13 +4386,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // lognormal_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY lognormal_distribution +class _LIBCPP_TEMPLATE_VIS lognormal_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { normal_distribution<result_type> __nd_; public: @@ -4493,13 +4511,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // poisson_distribution template<class _IntType = int> -class _LIBCPP_TYPE_VIS_ONLY poisson_distribution +class _LIBCPP_TEMPLATE_VIS poisson_distribution { public: // types typedef _IntType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { double __mean_; double __s_; @@ -4724,13 +4742,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // weibull_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY weibull_distribution +class _LIBCPP_TEMPLATE_VIS weibull_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; @@ -4838,13 +4856,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, } template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY extreme_value_distribution +class _LIBCPP_TEMPLATE_VIS extreme_value_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; @@ -4959,13 +4977,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // gamma_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY gamma_distribution +class _LIBCPP_TEMPLATE_VIS gamma_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __alpha_; result_type __beta_; @@ -5131,13 +5149,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // negative_binomial_distribution template<class _IntType = int> -class _LIBCPP_TYPE_VIS_ONLY negative_binomial_distribution +class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution { public: // types typedef _IntType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __k_; double __p_; @@ -5266,13 +5284,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // geometric_distribution template<class _IntType = int> -class _LIBCPP_TYPE_VIS_ONLY geometric_distribution +class _LIBCPP_TEMPLATE_VIS geometric_distribution { public: // types typedef _IntType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { double __p_; public: @@ -5368,13 +5386,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // chi_squared_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY chi_squared_distribution +class _LIBCPP_TEMPLATE_VIS chi_squared_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __n_; public: @@ -5474,13 +5492,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // cauchy_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY cauchy_distribution +class _LIBCPP_TEMPLATE_VIS cauchy_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __a_; result_type __b_; @@ -5597,13 +5615,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // fisher_f_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY fisher_f_distribution +class _LIBCPP_TEMPLATE_VIS fisher_f_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __m_; result_type __n_; @@ -5719,13 +5737,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // student_t_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY student_t_distribution +class _LIBCPP_TEMPLATE_VIS student_t_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { result_type __n_; public: @@ -5832,13 +5850,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // discrete_distribution template<class _IntType = int> -class _LIBCPP_TYPE_VIS_ONLY discrete_distribution +class _LIBCPP_TEMPLATE_VIS discrete_distribution { public: // types typedef _IntType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { vector<double> __p_; public: @@ -5850,11 +5868,11 @@ public: _LIBCPP_INLINE_VISIBILITY param_type(_InputIterator __f, _InputIterator __l) : __p_(__f, __l) {__init();} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY param_type(initializer_list<double> __wl) : __p_(__wl.begin(), __wl.end()) {__init();} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> param_type(size_t __nw, double __xmin, double __xmax, _UnaryOperation __fw); @@ -5897,11 +5915,11 @@ public: _LIBCPP_INLINE_VISIBILITY discrete_distribution(_InputIterator __f, _InputIterator __l) : __p_(__f, __l) {} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY discrete_distribution(initializer_list<double> __wl) : __p_(__wl) {} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> _LIBCPP_INLINE_VISIBILITY discrete_distribution(size_t __nw, double __xmin, double __xmax, @@ -6060,13 +6078,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // piecewise_constant_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY piecewise_constant_distribution +class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { vector<result_type> __b_; vector<result_type> __densities_; @@ -6078,10 +6096,10 @@ public: template<class _InputIteratorB, class _InputIteratorW> param_type(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _UnaryOperation> param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> param_type(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw); @@ -6131,13 +6149,13 @@ public: _InputIteratorW __fW) : __p_(__fB, __lB, __fW) {} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _UnaryOperation> _LIBCPP_INLINE_VISIBILITY piecewise_constant_distribution(initializer_list<result_type> __bl, _UnaryOperation __fw) : __p_(__bl, __fw) {} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> _LIBCPP_INLINE_VISIBILITY @@ -6267,7 +6285,7 @@ piecewise_constant_distribution<_RealType>::param_type::param_type( } } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _RealType> template<class _UnaryOperation> @@ -6292,7 +6310,7 @@ piecewise_constant_distribution<_RealType>::param_type::param_type( } } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _RealType> template<class _UnaryOperation> @@ -6383,13 +6401,13 @@ operator>>(basic_istream<_CharT, _Traits>& __is, // piecewise_linear_distribution template<class _RealType = double> -class _LIBCPP_TYPE_VIS_ONLY piecewise_linear_distribution +class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution { public: // types typedef _RealType result_type; - class _LIBCPP_TYPE_VIS_ONLY param_type + class _LIBCPP_TEMPLATE_VIS param_type { vector<result_type> __b_; vector<result_type> __densities_; @@ -6401,10 +6419,10 @@ public: template<class _InputIteratorB, class _InputIteratorW> param_type(_InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _UnaryOperation> param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> param_type(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw); @@ -6454,13 +6472,13 @@ public: _InputIteratorW __fW) : __p_(__fB, __lB, __fW) {} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _UnaryOperation> _LIBCPP_INLINE_VISIBILITY piecewise_linear_distribution(initializer_list<result_type> __bl, _UnaryOperation __fw) : __p_(__bl, __fw) {} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _UnaryOperation> _LIBCPP_INLINE_VISIBILITY @@ -6594,7 +6612,7 @@ piecewise_linear_distribution<_RealType>::param_type::param_type( } } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template<class _RealType> template<class _UnaryOperation> @@ -6619,7 +6637,7 @@ piecewise_linear_distribution<_RealType>::param_type::param_type( } } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template<class _RealType> template<class _UnaryOperation> @@ -6721,4 +6739,6 @@ operator>>(basic_istream<_CharT, _Traits>& __is, _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_RANDOM diff --git a/lib/libcxx/include/ratio b/lib/libcxx/include/ratio index 8f708ce478d..7ee5ec24517 100644 --- a/lib/libcxx/include/ratio +++ b/lib/libcxx/include/ratio @@ -63,17 +63,17 @@ typedef ratio< 1000000000000000000000, 1> zetta; // not supported typedef ratio<1000000000000000000000000, 1> yotta; // not supported // 20.11.5, ratio comparison - template <class R1, class R2> constexpr bool ratio_equal_v + template <class R1, class R2> inline constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value; // C++17 - template <class R1, class R2> constexpr bool ratio_not_equal_v + template <class R1, class R2> inline constexpr bool ratio_not_equal_v = ratio_not_equal<R1, R2>::value; // C++17 - template <class R1, class R2> constexpr bool ratio_less_v + template <class R1, class R2> inline constexpr bool ratio_less_v = ratio_less<R1, R2>::value; // C++17 - template <class R1, class R2> constexpr bool ratio_less_equal_v + template <class R1, class R2> inline constexpr bool ratio_less_equal_v = ratio_less_equal<R1, R2>::value; // C++17 - template <class R1, class R2> constexpr bool ratio_greater_v + template <class R1, class R2> inline constexpr bool ratio_greater_v = ratio_greater<R1, R2>::value; // C++17 - template <class R1, class R2> constexpr bool ratio_greater_equal_v + template <class R1, class R2> inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<R1, R2>::value; // C++17 } */ @@ -83,12 +83,14 @@ typedef ratio<1000000000000000000000000, 1> yotta; // not supported #include <climits> #include <type_traits> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // __static_gcd @@ -244,7 +246,7 @@ public: }; template <intmax_t _Num, intmax_t _Den = 1> -class _LIBCPP_TYPE_VIS_ONLY ratio +class _LIBCPP_TEMPLATE_VIS ratio { static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range"); static_assert(_Den != 0, "ratio divide by 0"); @@ -300,18 +302,18 @@ public: >::type type; }; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _R1, class _R2> using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type; -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else // _LIBCPP_CXX03_LANG template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_multiply +struct _LIBCPP_TEMPLATE_VIS ratio_multiply : public __ratio_multiply<_R1, _R2>::type {}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG template <class _R1, class _R2> struct __ratio_divide @@ -327,18 +329,18 @@ public: >::type type; }; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _R1, class _R2> using ratio_divide = typename __ratio_divide<_R1, _R2>::type; -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else // _LIBCPP_CXX03_LANG template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_divide +struct _LIBCPP_TEMPLATE_VIS ratio_divide : public __ratio_divide<_R1, _R2>::type {}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG template <class _R1, class _R2> struct __ratio_add @@ -362,18 +364,18 @@ public: >::type type; }; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _R1, class _R2> using ratio_add = typename __ratio_add<_R1, _R2>::type; -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else // _LIBCPP_CXX03_LANG template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_add +struct _LIBCPP_TEMPLATE_VIS ratio_add : public __ratio_add<_R1, _R2>::type {}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG template <class _R1, class _R2> struct __ratio_subtract @@ -397,27 +399,27 @@ public: >::type type; }; -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG template <class _R1, class _R2> using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type; -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else // _LIBCPP_CXX03_LANG template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_subtract +struct _LIBCPP_TEMPLATE_VIS ratio_subtract : public __ratio_subtract<_R1, _R2>::type {}; -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif // _LIBCPP_CXX03_LANG // ratio_equal template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_equal +struct _LIBCPP_TEMPLATE_VIS ratio_equal : public _LIBCPP_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {}; template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_not_equal +struct _LIBCPP_TEMPLATE_VIS ratio_not_equal : public _LIBCPP_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {}; // ratio_less @@ -476,19 +478,19 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL> }; template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_less +struct _LIBCPP_TEMPLATE_VIS ratio_less : public _LIBCPP_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {}; template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_less_equal +struct _LIBCPP_TEMPLATE_VIS ratio_less_equal : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {}; template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_greater +struct _LIBCPP_TEMPLATE_VIS ratio_greater : public _LIBCPP_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {}; template <class _R1, class _R2> -struct _LIBCPP_TYPE_VIS_ONLY ratio_greater_equal +struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal : public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {}; template <class _R1, class _R2> @@ -499,25 +501,33 @@ struct __ratio_gcd }; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_equal_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_equal_v = ratio_equal<_R1, _R2>::value; -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_not_equal_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value; -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_v = ratio_less<_R1, _R2>::value; -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_equal_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value; -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_v = ratio_greater<_R1, _R2>::value; -template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_equal_v +template <class _R1, class _R2> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value; #endif _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_RATIO diff --git a/lib/libcxx/include/regex b/lib/libcxx/include/regex index 1139d8fb2a9..ff84b2738b7 100644 --- a/lib/libcxx/include/regex +++ b/lib/libcxx/include/regex @@ -127,6 +127,8 @@ class basic_regex public: // types: typedef charT value_type; + typedef traits traits_type; + typedef typename traits::string_type string_type; typedef regex_constants::syntax_option_type flag_type; typedef typename traits::locale_type locale_type; @@ -145,7 +147,7 @@ public: // construct/copy/destroy: basic_regex(); explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); - basic_regex(const charT* p, size_t len, flag_type f); + basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); basic_regex(const basic_regex&); basic_regex(basic_regex&&) noexcept; template <class ST, class SA> @@ -762,14 +764,17 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; #include <memory> #include <vector> #include <deque> -#include <cassert> - -#include <__undef_min_max> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 + _LIBCPP_BEGIN_NAMESPACE_STD namespace regex_constants @@ -864,7 +869,8 @@ enum match_flag_type format_sed = 1 << 8, format_no_copy = 1 << 9, format_first_only = 1 << 10, - __no_update_pos = 1 << 11 + __no_update_pos = 1 << 11, + __full_match = 1 << 12 }; inline _LIBCPP_INLINE_VISIBILITY @@ -957,18 +963,18 @@ public: }; template <regex_constants::error_type _Ev> -_LIBCPP_ALWAYS_INLINE +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE void __throw_regex_error() { #ifndef _LIBCPP_NO_EXCEPTIONS throw regex_error(_Ev); #else - assert(!"regex_error"); + _VSTD::abort(); #endif } template <class _CharT> -struct _LIBCPP_TYPE_VIS_ONLY regex_traits +struct _LIBCPP_TEMPLATE_VIS regex_traits { public: typedef _CharT char_type; @@ -1285,11 +1291,11 @@ regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const template <class _CharT> class __node; -template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match; +template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; template <class _BidirectionalIterator, class _Allocator = allocator<sub_match<_BidirectionalIterator> > > -class _LIBCPP_TYPE_VIS_ONLY match_results; +class _LIBCPP_TEMPLATE_VIS match_results; template <class _CharT> struct __state @@ -2403,17 +2409,28 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const goto __exit; } } - if (!__neg_chars_.empty()) + // set of "__found" chars = + // union(complement(union(__neg_chars_, __neg_mask_)), + // other cases...) + // + // __neg_chars_ and __neg_mask_'d better be handled together, as there + // are no short circuit opportunities. + // + // In addition, when __neg_mask_/__neg_chars_ is empty, they should be + // treated as all ones/all chars. { - for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) - { - if (__ch == __neg_chars_[__i]) - goto __is_neg_char; - } + const bool __in_neg_mask = (__neg_mask_ == 0) || + __traits_.isctype(__ch, __neg_mask_); + const bool __in_neg_chars = + __neg_chars_.empty() || + std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != + __neg_chars_.end(); + if (!(__in_neg_mask || __in_neg_chars)) + { __found = true; goto __exit; + } } -__is_neg_char: if (!__ranges_.empty()) { string_type __s2 = __collate_ ? @@ -2445,11 +2462,6 @@ __is_neg_char: __found = true; goto __exit; } - if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) - { - __found = true; - goto __exit; - } } else __found = __negate_; // force reject @@ -2470,11 +2482,13 @@ __exit: template <class _CharT, class _Traits> class __lookahead; template <class _CharT, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY basic_regex +class _LIBCPP_TEMPLATE_VIS basic_regex { public: // types: typedef _CharT value_type; + typedef _Traits traits_type; + typedef typename _Traits::string_type string_type; typedef regex_constants::syntax_option_type flag_type; typedef typename _Traits::locale_type locale_type; @@ -2515,7 +2529,7 @@ public: __end_(0) {__parse(__p, __p + __traits_.length(__p));} _LIBCPP_INLINE_VISIBILITY - basic_regex(const value_type* __p, size_t __len, flag_type __f) + basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) {__parse(__p, __p + __len);} @@ -2535,14 +2549,14 @@ public: : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) {__parse(__first, __last);} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) {__parse(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // ~basic_regex() = default; @@ -2551,11 +2565,11 @@ public: _LIBCPP_INLINE_VISIBILITY basic_regex& operator=(const value_type* __p) {return assign(__p);} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex& operator=(initializer_list<value_type> __il) {return assign(__il);} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _ST, class _SA> _LIBCPP_INLINE_VISIBILITY basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) @@ -2565,7 +2579,7 @@ public: _LIBCPP_INLINE_VISIBILITY basic_regex& assign(const basic_regex& __that) {return *this = __that;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex& assign(basic_regex&& __that) _NOEXCEPT {return *this = _VSTD::move(__that);} @@ -2622,14 +2636,14 @@ public: return assign(basic_regex(__first, __last, __f)); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex& assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {return assign(__il.begin(), __il.end(), __f);} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // const operations: _LIBCPP_INLINE_VISIBILITY @@ -2981,10 +2995,12 @@ __lookahead<_CharT, _Traits>::__exec(__state& __s) const { match_results<const _CharT*> __m; __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); - bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, - __m, - __s.__flags_ | regex_constants::match_continuous, - __s.__at_first_ && __s.__current_ == __s.__first_); + bool __matched = __exp_.__match_at_start_ecma( + __s.__current_, __s.__last_, + __m, + (__s.__flags_ | regex_constants::match_continuous) & + ~regex_constants::__full_match, + __s.__at_first_ && __s.__current_ == __s.__first_); if (__matched != __invert_) { __s.__do_ = __state::__accept_but_not_consume; @@ -3951,7 +3967,6 @@ basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first if (__temp == __last) __throw_regex_error<regex_constants::error_brack>(); // [__first, __temp) contains all text in [= ... =] - typedef typename _Traits::string_type string_type; string_type __collate_name = __traits_.lookup_collatename(__first, __temp); if (__collate_name.empty()) @@ -4049,6 +4064,8 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; ++__first) { + if (__c >= std::numeric_limits<int>::max() / 10) + __throw_regex_error<regex_constants::error_badbrace>(); __c *= 10; __c += __val; } @@ -4308,9 +4325,14 @@ basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, else if ('1' <= *__first && *__first <= '9') { unsigned __v = *__first - '0'; - for (++__first; '0' <= *__first && *__first <= '9'; ++__first) + for (++__first; + __first != __last && '0' <= *__first && *__first <= '9'; ++__first) + { + if (__v >= std::numeric_limits<unsigned>::max() / 10) + __throw_regex_error<regex_constants::error_backref>(); __v = 10 * __v + *__first - '0'; - if (__v > mark_count()) + } + if (__v == 0 || __v > mark_count()) __throw_regex_error<regex_constants::error_backref>(); __push_back_ref(__v); } @@ -4758,7 +4780,7 @@ typedef basic_regex<wchar_t> wregex; // sub_match template <class _BidirectionalIterator> -class _LIBCPP_TYPE_VIS_ONLY sub_match +class _LIBCPP_TEMPLATE_VIS sub_match : public pair<_BidirectionalIterator, _BidirectionalIterator> { public: @@ -5181,7 +5203,7 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) } template <class _BidirectionalIterator, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY match_results +class _LIBCPP_TEMPLATE_VIS match_results { public: typedef _Allocator allocator_type; @@ -5218,11 +5240,11 @@ public: // size: _LIBCPP_INLINE_VISIBILITY - size_type size() const {return __matches_.size();} + size_type size() const _NOEXCEPT {return __matches_.size();} _LIBCPP_INLINE_VISIBILITY - size_type max_size() const {return __matches_.max_size();} - _LIBCPP_INLINE_VISIBILITY - bool empty() const {return size() == 0;} + size_type max_size() const _NOEXCEPT {return __matches_.max_size();} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} // element access: _LIBCPP_INLINE_VISIBILITY @@ -5255,15 +5277,15 @@ public: // format: template <class _OutputIter> _OutputIter - format(_OutputIter __out, const char_type* __fmt_first, + format(_OutputIter __output_iter, const char_type* __fmt_first, const char_type* __fmt_last, regex_constants::match_flag_type __flags = regex_constants::format_default) const; template <class _OutputIter, class _ST, class _SA> _LIBCPP_INLINE_VISIBILITY _OutputIter - format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, + format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, regex_constants::match_flag_type __flags = regex_constants::format_default) const - {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} + {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} template <class _ST, class _SA> _LIBCPP_INLINE_VISIBILITY basic_string<char_type, _ST, _SA> @@ -5375,7 +5397,7 @@ match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, template <class _BidirectionalIterator, class _Allocator> template <class _OutputIter> _OutputIter -match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, +match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, const char_type* __fmt_first, const char_type* __fmt_last, regex_constants::match_flag_type __flags) const { @@ -5384,27 +5406,27 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, for (; __fmt_first != __fmt_last; ++__fmt_first) { if (*__fmt_first == '&') - __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, - __out); + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) { ++__fmt_first; if ('0' <= *__fmt_first && *__fmt_first <= '9') { size_t __i = *__fmt_first - '0'; - __out = _VSTD::copy((*this)[__i].first, - (*this)[__i].second, __out); + __output_iter = _VSTD::copy((*this)[__i].first, + (*this)[__i].second, __output_iter); } else { - *__out = *__fmt_first; - ++__out; + *__output_iter = *__fmt_first; + ++__output_iter; } } else { - *__out = *__fmt_first; - ++__out; + *__output_iter = *__fmt_first; + ++__output_iter; } } } @@ -5417,52 +5439,54 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, switch (__fmt_first[1]) { case '$': - *__out = *++__fmt_first; - ++__out; + *__output_iter = *++__fmt_first; + ++__output_iter; break; case '&': ++__fmt_first; - __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, - __out); + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); break; case '`': ++__fmt_first; - __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); + __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); break; case '\'': ++__fmt_first; - __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); + __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); break; default: if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') { ++__fmt_first; - size_t __i = *__fmt_first - '0'; + size_t __idx = *__fmt_first - '0'; if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') { ++__fmt_first; - __i = 10 * __i + *__fmt_first - '0'; + if (__idx >= std::numeric_limits<size_t>::max() / 10) + __throw_regex_error<regex_constants::error_escape>(); + __idx = 10 * __idx + *__fmt_first - '0'; } - __out = _VSTD::copy((*this)[__i].first, - (*this)[__i].second, __out); + __output_iter = _VSTD::copy((*this)[__idx].first, + (*this)[__idx].second, __output_iter); } else { - *__out = *__fmt_first; - ++__out; + *__output_iter = *__fmt_first; + ++__output_iter; } break; } } else { - *__out = *__fmt_first; - ++__out; + *__output_iter = *__fmt_first; + ++__output_iter; } } } - return __out; + return __output_iter; } template <class _BidirectionalIterator, class _Allocator> @@ -5544,14 +5568,32 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma( __states.back().__node_ = __st; __states.back().__flags_ = __flags; __states.back().__at_first_ = __at_first; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); switch (__s.__do_) { case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } __m.__matches_[0].first = __first; __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); __m.__matches_[0].matched = true; @@ -5607,14 +5649,32 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( __states.back().__flags_ = __flags; __states.back().__at_first_ = __at_first; bool __matched = false; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); switch (__s.__do_) { case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } if (!__matched || __highest_j < __s.__current_ - __s.__first_) __highest_j = __s.__current_ - __s.__first_; __matched = true; @@ -5692,14 +5752,32 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( __states.back().__at_first_ = __at_first; const _CharT* __current = __first; bool __matched = false; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error<regex_constants::error_complexity>(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); switch (__s.__do_) { case __state::__end_state: + if ((__flags & regex_constants::match_not_null) && + __s.__current_ == __first) + { + __states.pop_back(); + break; + } + if ((__flags & regex_constants::__full_match) && + __s.__current_ != __last) + { + __states.pop_back(); + break; + } if (!__matched || __highest_j < __s.__current_ - __s.__first_) { __highest_j = __s.__current_ - __s.__first_; @@ -5930,8 +6008,10 @@ regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, regex_constants::match_flag_type __flags = regex_constants::match_default) { - bool __r = _VSTD::regex_search(__first, __last, __m, __e, - __flags | regex_constants::match_continuous); + bool __r = _VSTD::regex_search( + __first, __last, __m, __e, + __flags | regex_constants::match_continuous | + regex_constants::__full_match); if (__r) { __r = !__m.suffix().matched; @@ -6007,7 +6087,7 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s, template <class _BidirectionalIterator, class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY regex_iterator +class _LIBCPP_TEMPLATE_VIS regex_iterator { public: typedef basic_regex<_CharT, _Traits> regex_type; @@ -6096,7 +6176,7 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() { __flags_ |= regex_constants::__no_update_pos; _BidirectionalIterator __start = __match_[0].second; - if (__match_.empty()) + if (__match_[0].first == __match_[0].second) { if (__start == __end_) { @@ -6126,7 +6206,7 @@ typedef regex_iterator<wstring::const_iterator> wsregex_iterator; template <class _BidirectionalIterator, class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, class _Traits = regex_traits<_CharT> > -class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator +class _LIBCPP_TEMPLATE_VIS regex_token_iterator { public: typedef basic_regex<_CharT, _Traits> regex_type; @@ -6142,7 +6222,7 @@ private: _Position __position_; const value_type* __result_; value_type __suffix_; - ptrdiff_t _N_; + ptrdiff_t __n_; vector<int> __subs_; public: @@ -6169,7 +6249,7 @@ public: regex_constants::match_default) = delete; #endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, const regex_type& __re, initializer_list<int> __submatches, @@ -6183,7 +6263,7 @@ public: regex_constants::match_flag_type __m = regex_constants::match_default) = delete; #endif -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <size_t _Np> regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, @@ -6225,10 +6305,10 @@ public: private: void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); void __establish_result () { - if (__subs_[_N_] == -1) + if (__subs_[__n_] == -1) __result_ = &__position_->prefix(); else - __result_ = &(*__position_)[__subs_[_N_]]; + __result_ = &(*__position_)[__subs_[__n_]]; } }; @@ -6237,7 +6317,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: regex_token_iterator() : __result_(nullptr), __suffix_(), - _N_(0) + __n_(0) { } @@ -6248,7 +6328,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: { if (__position_ != _Position()) __establish_result (); - else if (__subs_[_N_] == -1) + else if (__subs_[__n_] == -1) { __suffix_.matched = true; __suffix_.first = __a; @@ -6265,7 +6345,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: const regex_type& __re, int __submatch, regex_constants::match_flag_type __m) : __position_(__a, __b, __re, __m), - _N_(0), + __n_(0), __subs_(1, __submatch) { __init(__a, __b); @@ -6277,13 +6357,13 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: const regex_type& __re, const vector<int>& __submatches, regex_constants::match_flag_type __m) : __position_(__a, __b, __re, __m), - _N_(0), + __n_(0), __subs_(__submatches) { __init(__a, __b); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _BidirectionalIterator, class _CharT, class _Traits> regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: @@ -6292,13 +6372,13 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: initializer_list<int> __submatches, regex_constants::match_flag_type __m) : __position_(__a, __b, __re, __m), - _N_(0), + __n_(0), __subs_(__submatches) { __init(__a, __b); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _BidirectionalIterator, class _CharT, class _Traits> template <size_t _Np> @@ -6308,7 +6388,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: const int (&__submatches)[_Np], regex_constants::match_flag_type __m) : __position_(__a, __b, __re, __m), - _N_(0), + __n_(0), __subs_(__submatches, __submatches + _Np) { __init(__a, __b); @@ -6320,7 +6400,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: : __position_(__x.__position_), __result_(__x.__result_), __suffix_(__x.__suffix_), - _N_(__x._N_), + __n_(__x.__n_), __subs_(__x.__subs_) { if (__x.__result_ == &__x.__suffix_) @@ -6342,7 +6422,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: else __result_ = __x.__result_; __suffix_ = __x.__suffix_; - _N_ = __x._N_; + __n_ = __x.__n_; __subs_ = __x.__subs_; if ( __result_ != nullptr && __result_ != &__suffix_ ) @@ -6365,7 +6445,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: return false; if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) return false; - return __position_ == __x.__position_ && _N_ == __x._N_ && + return __position_ == __x.__position_ && __n_ == __x.__n_ && __subs_ == __x.__subs_; } @@ -6376,14 +6456,14 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() _Position __prev = __position_; if (__result_ == &__suffix_) __result_ = nullptr; - else if (_N_ + 1 < __subs_.size()) + else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) { - ++_N_; + ++__n_; __establish_result(); } else { - _N_ = 0; + __n_ = 0; ++__position_; if (__position_ != _Position()) __establish_result(); @@ -6414,7 +6494,7 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT> _OutputIterator -regex_replace(_OutputIterator __out, +regex_replace(_OutputIterator __output_iter, _BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, regex_constants::match_flag_type __flags = regex_constants::match_default) @@ -6425,7 +6505,7 @@ regex_replace(_OutputIterator __out, if (__i == __eof) { if (!(__flags & regex_constants::format_no_copy)) - __out = _VSTD::copy(__first, __last, __out); + __output_iter = _VSTD::copy(__first, __last, __output_iter); } else { @@ -6433,29 +6513,29 @@ regex_replace(_OutputIterator __out, for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) { if (!(__flags & regex_constants::format_no_copy)) - __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); - __out = __i->format(__out, __fmt, __fmt + __len, __flags); + __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); + __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); __lm = __i->suffix(); if (__flags & regex_constants::format_first_only) break; } if (!(__flags & regex_constants::format_no_copy)) - __out = _VSTD::copy(__lm.first, __lm.second, __out); + __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); } - return __out; + return __output_iter; } template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT, class _ST, class _SA> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator -regex_replace(_OutputIterator __out, +regex_replace(_OutputIterator __output_iter, _BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, const basic_string<_CharT, _ST, _SA>& __fmt, regex_constants::match_flag_type __flags = regex_constants::match_default) { - return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); + return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags); } template <class _Traits, class _CharT, class _ST, class _SA, class _FST, @@ -6518,4 +6598,6 @@ regex_replace(const _CharT* __s, _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_REGEX diff --git a/lib/libcxx/include/scoped_allocator b/lib/libcxx/include/scoped_allocator index 9436dac9c19..4760d946def 100644 --- a/lib/libcxx/include/scoped_allocator +++ b/lib/libcxx/include/scoped_allocator @@ -68,8 +68,8 @@ public: outer_allocator_type& outer_allocator() noexcept; const outer_allocator_type& outer_allocator() const noexcept; - pointer allocate(size_type n); - pointer allocate(size_type n, const_void_pointer hint); + pointer allocate(size_type n); // [[nodiscard]] in C++20 + pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 void deallocate(pointer p, size_type n) noexcept; size_type max_size() const; @@ -115,7 +115,7 @@ template <class OuterA1, class OuterA2, class... InnerAllocs> _LIBCPP_BEGIN_NAMESPACE_STD -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) +#if !defined(_LIBCPP_CXX03_LANG) // scoped_allocator_adaptor @@ -384,7 +384,7 @@ struct __outermost<_Alloc, true> }; template <class _OuterAlloc, class... _InnerAllocs> -class _LIBCPP_TYPE_VIS_ONLY scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> +class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> { typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base; @@ -477,11 +477,11 @@ public: const outer_allocator_type& outer_allocator() const _NOEXCEPT {return base::outer_allocator();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n) {return allocator_traits<outer_allocator_type>:: allocate(outer_allocator(), __n);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, const_void_pointer __hint) {return allocator_traits<outer_allocator_type>:: allocate(outer_allocator(), __n, __hint);} @@ -498,8 +498,58 @@ public: template <class _Tp, class... _Args> _LIBCPP_INLINE_VISIBILITY void construct(_Tp* __p, _Args&& ...__args) - {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(), + {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), __p, _VSTD::forward<_Args>(__args)...);} + + template <class _T1, class _T2, class... _Args1, class... _Args2> + void construct(pair<_T1, _T2>* __p, piecewise_construct_t, + tuple<_Args1...> __x, tuple<_Args2...> __y) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct( + _OM()(outer_allocator()), __p, piecewise_construct + , __transform_tuple( + typename __uses_alloc_ctor< + _T1, inner_allocator_type&, _Args1... + >::type() + , _VSTD::move(__x) + , typename __make_tuple_indices<sizeof...(_Args1)>::type{} + ) + , __transform_tuple( + typename __uses_alloc_ctor< + _T2, inner_allocator_type&, _Args2... + >::type() + , _VSTD::move(__y) + , typename __make_tuple_indices<sizeof...(_Args2)>::type{} + ) + ); + } + + template <class _T1, class _T2> + void construct(pair<_T1, _T2>* __p) + { construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y))); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(__x.first), + _VSTD::forward_as_tuple(__x.second)); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second))); + } + template <class _Tp> _LIBCPP_INLINE_VISIBILITY void destroy(_Tp* __p) @@ -515,6 +565,7 @@ public: private: + template <class _OuterA2, class = typename enable_if< is_constructible<outer_allocator_type, _OuterA2>::value @@ -545,9 +596,7 @@ private: allocator_traits<typename _OM::type>::construct ( _OM()(outer_allocator()), - __p, - allocator_arg, - inner_allocator(), + __p, allocator_arg, inner_allocator(), _VSTD::forward<_Args>(__args)... ); } @@ -566,6 +615,36 @@ private: ); } + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&...> + __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, + __tuple_indices<_Idx...>) + { + return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> + __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>; + return _Tup(allocator_arg, inner_allocator(), + _VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&..., inner_allocator_type&> + __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<_Args&&..., inner_allocator_type&>; + return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator()); + } + template <class...> friend class __scoped_allocator_storage; }; @@ -597,7 +676,7 @@ operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, return !(__a == __b); } -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) +#endif // !defined(_LIBCPP_CXX03_LANG) _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/set b/lib/libcxx/include/set index ac69e085241..b4c6b2ef8c5 100644 --- a/lib/libcxx/include/set +++ b/lib/libcxx/include/set @@ -397,7 +397,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> > -class _LIBCPP_TYPE_VIS_ONLY set +class _LIBCPP_TEMPLATE_VIS set { public: // types: @@ -486,12 +486,12 @@ public: return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY set(set&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __tree_(_VSTD::move(__s.__tree_)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit set(const allocator_type& __a) @@ -504,11 +504,9 @@ public: insert(__s.begin(), __s.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG set(set&& __s, const allocator_type& __a); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY set(initializer_list<value_type> __il, const value_compare& __comp = value_compare()) : __tree_(__comp) @@ -536,9 +534,7 @@ public: __tree_.__assign_unique(__il.begin(), __il.end()); return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY set& operator=(set&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) @@ -546,7 +542,7 @@ public: __tree_ = _VSTD::move(__s.__tree_); return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} @@ -579,7 +575,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -587,7 +583,7 @@ public: size_type max_size() const _NOEXCEPT {return __tree_.max_size();} // modifiers: -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#ifndef _LIBCPP_CXX03_LANG template <class... _Args> _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> emplace(_Args&&... __args) @@ -596,23 +592,15 @@ public: _LIBCPP_INLINE_VISIBILITY iterator emplace_hint(const_iterator __p, _Args&&... __args) {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);} -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY pair<iterator,bool> insert(const value_type& __v) {return __tree_.__insert_unique(__v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - pair<iterator,bool> insert(value_type&& __v) - {return __tree_.__insert_unique(_VSTD::move(__v));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, const value_type& __v) {return __tree_.__insert_unique(__p, __v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - iterator insert(const_iterator __p, value_type&& __v) - {return __tree_.__insert_unique(__p, _VSTD::move(__v));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __f, _InputIterator __l) @@ -621,11 +609,19 @@ public: __tree_.__insert_unique(__e, *__f); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair<iterator,bool> insert(value_type&& __v) + {return __tree_.__insert_unique(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_unique(__p, _VSTD::move(__v));} + _LIBCPP_INLINE_VISIBILITY void insert(initializer_list<value_type> __il) {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p);} @@ -672,7 +668,7 @@ public: template <typename _K2> _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type - count(const _K2& __k) {return __tree_.__count_unique(__k);} + count(const _K2& __k) const {return __tree_.__count_unique(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) @@ -727,7 +723,7 @@ public: #endif }; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) @@ -741,7 +737,7 @@ set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -810,7 +806,7 @@ swap(set<_Key, _Compare, _Allocator>& __x, template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> > -class _LIBCPP_TYPE_VIS_ONLY multiset +class _LIBCPP_TEMPLATE_VIS multiset { public: // types: @@ -901,12 +897,14 @@ public: return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY multiset(multiset&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __tree_(_VSTD::move(__s.__tree_)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + multiset(multiset&& __s, const allocator_type& __a); +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit multiset(const allocator_type& __a) : __tree_(__a) {} @@ -916,11 +914,8 @@ public: { insert(__s.begin(), __s.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - multiset(multiset&& __s, const allocator_type& __a); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare()) : __tree_(__comp) @@ -948,9 +943,7 @@ public: __tree_.__assign_multi(__il.begin(), __il.end()); return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY multiset& operator=(multiset&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) @@ -958,7 +951,7 @@ public: __tree_ = _VSTD::move(__s.__tree_); return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} @@ -991,7 +984,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -999,7 +992,7 @@ public: size_type max_size() const _NOEXCEPT {return __tree_.max_size();} // modifiers: -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#ifndef _LIBCPP_CXX03_LANG template <class... _Args> _LIBCPP_INLINE_VISIBILITY iterator emplace(_Args&&... __args) @@ -1008,23 +1001,15 @@ public: _LIBCPP_INLINE_VISIBILITY iterator emplace_hint(const_iterator __p, _Args&&... __args) {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - iterator insert(value_type&& __v) - {return __tree_.__insert_multi(_VSTD::move(__v));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, const value_type& __v) {return __tree_.__insert_multi(__p, __v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY - iterator insert(const_iterator __p, value_type&& __v) - {return __tree_.__insert_multi(_VSTD::move(__v));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __f, _InputIterator __l) @@ -1033,11 +1018,19 @@ public: __tree_.__insert_multi(__e, *__f); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + iterator insert(value_type&& __v) + {return __tree_.__insert_multi(_VSTD::move(__v));} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, value_type&& __v) + {return __tree_.__insert_multi(__p, _VSTD::move(__v));} + _LIBCPP_INLINE_VISIBILITY void insert(initializer_list<value_type> __il) {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p);} @@ -1140,7 +1133,7 @@ public: #endif }; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a) @@ -1154,7 +1147,7 @@ multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_t } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY diff --git a/lib/libcxx/include/shared_mutex b/lib/libcxx/include/shared_mutex index 923fe07ab38..9cb81528cd9 100644 --- a/lib/libcxx/include/shared_mutex +++ b/lib/libcxx/include/shared_mutex @@ -125,12 +125,14 @@ template <class Mutex> #include <__config> +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + #if _LIBCPP_STD_VER > 11 || defined(_LIBCPP_BUILDING_SHARED_MUTEX) #include <__mutex_base> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -141,7 +143,7 @@ template <class Mutex> _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_TYPE_VIS __shared_mutex_base +struct _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX __shared_mutex_base { mutex __mut_; condition_variable __gate1_; @@ -173,11 +175,11 @@ struct _LIBCPP_TYPE_VIS __shared_mutex_base #if _LIBCPP_STD_VER > 14 -class _LIBCPP_TYPE_VIS shared_mutex +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex { - __shared_mutex_base __base; + __shared_mutex_base __base; public: - shared_mutex() : __base() {} + _LIBCPP_INLINE_VISIBILITY shared_mutex() : __base() {} _LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default; shared_mutex(const shared_mutex&) = delete; @@ -199,9 +201,9 @@ public: #endif -class _LIBCPP_TYPE_VIS shared_timed_mutex +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex { - __shared_mutex_base __base; + __shared_mutex_base __base; public: shared_timed_mutex(); _LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default; @@ -220,6 +222,7 @@ public: return try_lock_until(chrono::steady_clock::now() + __rel_time); } template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time); void unlock(); @@ -235,6 +238,7 @@ public: return try_lock_shared_until(chrono::steady_clock::now() + __rel_time); } template <class _Clock, class _Duration> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time); void unlock_shared(); @@ -498,4 +502,6 @@ _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER > 11 +_LIBCPP_POP_MACROS + #endif // _LIBCPP_SHARED_MUTEX diff --git a/lib/libcxx/include/sstream b/lib/libcxx/include/sstream index 27ae78f9d45..b01f47b6872 100644 --- a/lib/libcxx/include/sstream +++ b/lib/libcxx/include/sstream @@ -175,18 +175,20 @@ typedef basic_stringstream<wchar_t> wstringstream; #include <istream> #include <string> -#include <__undef_min_max> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // basic_stringbuf template <class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY basic_stringbuf +class _LIBCPP_TEMPLATE_VIS basic_stringbuf : public basic_streambuf<_CharT, _Traits> { public: @@ -207,15 +209,15 @@ private: public: // 27.8.1.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY explicit basic_stringbuf(const string_type& __s, ios_base::openmode __wch = ios_base::in | ios_base::out); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG basic_stringbuf(basic_stringbuf&& __rhs); -#endif // 27.8.1.2 Assign and swap: -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES basic_stringbuf& operator=(basic_stringbuf&& __rhs); #endif void swap(basic_stringbuf& __rhs); @@ -231,30 +233,29 @@ protected: virtual int_type overflow (int_type __c = traits_type::eof()); virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY virtual pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out); }; template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch) : __hm_(0), __mode_(__wch) { - str(string_type()); } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s, ios_base::openmode __wch) - : __hm_(0), + : __str_(__s.get_allocator()), + __hm_(0), __mode_(__wch) { str(__s); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) @@ -287,7 +288,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } __hm_ = __hm == -1 ? nullptr : __p + __hm; __p = const_cast<char_type*>(__rhs.__str_.data()); @@ -330,7 +331,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } else this->setp(nullptr, nullptr); @@ -345,7 +346,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> void @@ -401,7 +402,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) if (__rbout != -1) { this->setp(__p + __rbout, __p + __reout); - this->pbump(__rnout); + this->__pbump(__rnout); } else this->setp(nullptr, nullptr); @@ -414,7 +415,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) if (__lbout != -1) { __rhs.setp(__p + __lbout, __p + __leout); - __rhs.pbump(__lnout); + __rhs.__pbump(__lnout); } else __rhs.setp(nullptr, nullptr); @@ -469,7 +470,15 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) this->setp(const_cast<char_type*>(__str_.data()), const_cast<char_type*>(__str_.data()) + __str_.size()); if (__mode_ & (ios_base::app | ios_base::ate)) - this->pbump(__sz); + { + while (__sz > INT_MAX) + { + this->pbump(INT_MAX); + __sz -= INT_MAX; + } + if (__sz > 0) + this->pbump(__sz); + } } } @@ -534,7 +543,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) __str_.resize(__str_.capacity()); char_type* __p = const_cast<char_type*>(__str_.data()); this->setp(__p, __p + __str_.size()); - this->pbump(__nout); + this->__pbump(__nout); __hm_ = this->pbase() + __hm; #ifndef _LIBCPP_NO_EXCEPTIONS } @@ -568,6 +577,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur) return pos_type(-1); + const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); off_type __noff; switch (__way) { @@ -581,13 +591,13 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, __noff = this->pptr() - this->pbase(); break; case ios_base::end: - __noff = __hm_ - __str_.data(); + __noff = __hm; break; default: return pos_type(-1); } __noff += __off; - if (__noff < 0 || __hm_ - __str_.data() < __noff) + if (__noff < 0 || __hm < __noff) return pos_type(-1); if (__noff != 0) { @@ -607,7 +617,6 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp, ios_base::openmode __wch) @@ -618,7 +627,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp, // basic_istringstream template <class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY basic_istringstream +class _LIBCPP_TEMPLATE_VIS basic_istringstream : public basic_istream<_CharT, _Traits> { public: @@ -636,25 +645,31 @@ private: public: // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY explicit basic_istringstream(ios_base::openmode __wch = ios_base::in); + inline _LIBCPP_INLINE_VISIBILITY explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_istringstream(basic_istringstream&& __rhs); // 27.8.2.2 Assign and swap: basic_istringstream& operator=(basic_istringstream&& __rhs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY void swap(basic_istringstream& __rhs); // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s); }; template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch) : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) @@ -662,7 +677,6 @@ basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base:: } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s, ios_base::openmode __wch) : basic_istream<_CharT, _Traits>(&__sb_), @@ -670,10 +684,9 @@ basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const stri { } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) @@ -690,12 +703,10 @@ basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream& return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs) +void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs) { basic_istream<char_type, traits_type>::swap(__rhs); __sb_.swap(__rhs.__sb_); @@ -711,7 +722,6 @@ swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<_CharT, _Traits, _Allocator>* basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const { @@ -719,7 +729,6 @@ basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> basic_istringstream<_CharT, _Traits, _Allocator>::str() const { @@ -727,9 +736,7 @@ basic_istringstream<_CharT, _Traits, _Allocator>::str() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) +void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) { __sb_.str(__s); } @@ -737,7 +744,7 @@ basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) // basic_ostringstream template <class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY basic_ostringstream +class _LIBCPP_TEMPLATE_VIS basic_ostringstream : public basic_ostream<_CharT, _Traits> { public: @@ -755,25 +762,31 @@ private: public: // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_ostringstream(basic_ostringstream&& __rhs); // 27.8.2.2 Assign and swap: basic_ostringstream& operator=(basic_ostringstream&& __rhs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY void swap(basic_ostringstream& __rhs); // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s); }; template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch) : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) @@ -781,7 +794,6 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base:: } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s, ios_base::openmode __wch) : basic_ostream<_CharT, _Traits>(&__sb_), @@ -789,10 +801,9 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const stri { } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs) : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) @@ -809,10 +820,9 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream& return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY void basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs) { @@ -830,7 +840,6 @@ swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<_CharT, _Traits, _Allocator>* basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const { @@ -838,7 +847,6 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> basic_ostringstream<_CharT, _Traits, _Allocator>::str() const { @@ -846,7 +854,6 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::str() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY void basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) { @@ -856,7 +863,7 @@ basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) // basic_stringstream template <class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY basic_stringstream +class _LIBCPP_TEMPLATE_VIS basic_stringstream : public basic_iostream<_CharT, _Traits> { public: @@ -874,25 +881,31 @@ private: public: // 27.8.2.1 Constructors: + inline _LIBCPP_INLINE_VISIBILITY explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out); + inline _LIBCPP_INLINE_VISIBILITY explicit basic_stringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in | ios_base::out); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY basic_stringstream(basic_stringstream&& __rhs); // 27.8.2.2 Assign and swap: basic_stringstream& operator=(basic_stringstream&& __rhs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG + inline _LIBCPP_INLINE_VISIBILITY void swap(basic_stringstream& __rhs); // 27.8.2.3 Members: + inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; + inline _LIBCPP_INLINE_VISIBILITY string_type str() const; + inline _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s); }; template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch) : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) @@ -900,7 +913,6 @@ basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::op } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s, ios_base::openmode __wch) : basic_iostream<_CharT, _Traits>(&__sb_), @@ -908,10 +920,9 @@ basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string { } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs) : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) @@ -928,10 +939,9 @@ basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY void basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs) { @@ -949,7 +959,6 @@ swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_stringbuf<_CharT, _Traits, _Allocator>* basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const { @@ -957,7 +966,6 @@ basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> basic_stringstream<_CharT, _Traits, _Allocator>::str() const { @@ -965,7 +973,6 @@ basic_stringstream<_CharT, _Traits, _Allocator>::str() const } template <class _CharT, class _Traits, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY void basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) { @@ -974,4 +981,6 @@ basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_SSTREAM diff --git a/lib/libcxx/include/stack b/lib/libcxx/include/stack index 48b3b0d16ec..0cb4c6ca925 100644 --- a/lib/libcxx/include/stack +++ b/lib/libcxx/include/stack @@ -55,7 +55,7 @@ public: void push(const value_type& x); void push(value_type&& x); - template <class... Args> void emplace(Args&&... args); + template <class... Args> reference emplace(Args&&... args); // reference in C++17 void pop(); void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>) @@ -91,7 +91,7 @@ template <class T, class Container> _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY stack; +template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS stack; template <class _Tp, class _Container> _LIBCPP_INLINE_VISIBILITY @@ -104,7 +104,7 @@ bool operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); template <class _Tp, class _Container /*= deque<_Tp>*/> -class _LIBCPP_TYPE_VIS_ONLY stack +class _LIBCPP_TEMPLATE_VIS stack { public: typedef _Container container_type; @@ -126,29 +126,28 @@ public: _LIBCPP_INLINE_VISIBILITY stack(const stack& __q) : c(__q.c) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + stack& operator=(const stack& __q) {c = __q.c; return *this;} + + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY stack(stack&& __q) _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) : c(_VSTD::move(__q.c)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY - stack& operator=(const stack& __q) {c = __q.c; return *this;} - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY stack& operator=(stack&& __q) _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) {c = _VSTD::move(__q.c); return *this;} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY - explicit stack(const container_type& __c) : c(__c) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + explicit stack(const container_type& __c) : c(__c) {} + template <class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit stack(const _Alloc& __a, @@ -167,7 +166,7 @@ public: typename enable_if<uses_allocator<container_type, _Alloc>::value>::type* = 0) : c(__s.c, __a) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Alloc> _LIBCPP_INLINE_VISIBILITY stack(container_type&& __c, const _Alloc& __a, @@ -180,9 +179,9 @@ public: typename enable_if<uses_allocator<container_type, _Alloc>::value>::type* = 0) : c(_VSTD::move(__s.c), __a) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} @@ -193,16 +192,21 @@ public: _LIBCPP_INLINE_VISIBILITY void push(const value_type& __v) {c.push_back(__v);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} -#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> _LIBCPP_INLINE_VISIBILITY - void emplace(_Args&&... __args) - {c.emplace_back(_VSTD::forward<_Args>(__args)...);} -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER > 14 + reference emplace(_Args&&... __args) + { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#else + void emplace(_Args&&... __args) + { c.emplace_back(_VSTD::forward<_Args>(__args)...);} +#endif +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY void pop() {c.pop_back();} @@ -286,7 +290,7 @@ swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) } template <class _Tp, class _Container, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<stack<_Tp, _Container>, _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> { }; diff --git a/lib/libcxx/include/stddef.h b/lib/libcxx/include/stddef.h index 8841bbea297..faf8552d8ce 100644 --- a/lib/libcxx/include/stddef.h +++ b/lib/libcxx/include/stddef.h @@ -53,7 +53,8 @@ using std::nullptr_t; } // Re-use the compiler's <stddef.h> max_align_t where possible. -#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) +#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && \ + !defined(__DEFINED_max_align_t) typedef long double max_align_t; #endif diff --git a/lib/libcxx/include/stdexcept b/lib/libcxx/include/stdexcept index 4218b1398d8..95a96cc0767 100644 --- a/lib/libcxx/include/stdexcept +++ b/lib/libcxx/include/stdexcept @@ -45,22 +45,31 @@ public: #include <__config> #include <exception> #include <iosfwd> // for string forward decl +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -#ifndef _LIBCPP___REFSTRING _LIBCPP_BEGIN_NAMESPACE_STD -class _LIBCPP_HIDDEN __libcpp_refstring { -#ifdef __clang__ - const char *__imp_ __attribute__((__unused__)); // only clang emits a warning -#else - const char *__imp_; -#endif + +class _LIBCPP_HIDDEN __libcpp_refstring +{ + const char* __imp_; + + bool __uses_refcount() const; +public: + explicit __libcpp_refstring(const char* __msg); + __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT; + __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT; + ~__libcpp_refstring(); + + const char* c_str() const _NOEXCEPT {return __imp_;} }; + _LIBCPP_END_NAMESPACE_STD -#endif namespace std // purposefully not using versioning namespace { @@ -171,4 +180,99 @@ public: } // std +_LIBCPP_BEGIN_NAMESPACE_STD + +// in the dylib +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_logic_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw logic_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_domain_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw domain_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_invalid_argument(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw invalid_argument(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_length_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw length_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_out_of_range(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_range_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw range_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_overflow_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw overflow_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_underflow_error(const char*__msg) +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw underflow_error(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + +_LIBCPP_END_NAMESPACE_STD + #endif // _LIBCPP_STDEXCEPT diff --git a/lib/libcxx/include/stdint.h b/lib/libcxx/include/stdint.h new file mode 100644 index 00000000000..468f6cd97c2 --- /dev/null +++ b/lib/libcxx/include/stdint.h @@ -0,0 +1,121 @@ +// -*- C++ -*- +//===---------------------------- stdint.h --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STDINT_H +#define _LIBCPP_STDINT_H + +/* + stdint.h synopsis + +Macros: + + INT8_MIN + INT16_MIN + INT32_MIN + INT64_MIN + + INT8_MAX + INT16_MAX + INT32_MAX + INT64_MAX + + UINT8_MAX + UINT16_MAX + UINT32_MAX + UINT64_MAX + + INT_LEAST8_MIN + INT_LEAST16_MIN + INT_LEAST32_MIN + INT_LEAST64_MIN + + INT_LEAST8_MAX + INT_LEAST16_MAX + INT_LEAST32_MAX + INT_LEAST64_MAX + + UINT_LEAST8_MAX + UINT_LEAST16_MAX + UINT_LEAST32_MAX + UINT_LEAST64_MAX + + INT_FAST8_MIN + INT_FAST16_MIN + INT_FAST32_MIN + INT_FAST64_MIN + + INT_FAST8_MAX + INT_FAST16_MAX + INT_FAST32_MAX + INT_FAST64_MAX + + UINT_FAST8_MAX + UINT_FAST16_MAX + UINT_FAST32_MAX + UINT_FAST64_MAX + + INTPTR_MIN + INTPTR_MAX + UINTPTR_MAX + + INTMAX_MIN + INTMAX_MAX + + UINTMAX_MAX + + PTRDIFF_MIN + PTRDIFF_MAX + + SIG_ATOMIC_MIN + SIG_ATOMIC_MAX + + SIZE_MAX + + WCHAR_MIN + WCHAR_MAX + + WINT_MIN + WINT_MAX + + INT8_C(value) + INT16_C(value) + INT32_C(value) + INT64_C(value) + + UINT8_C(value) + UINT16_C(value) + UINT32_C(value) + UINT64_C(value) + + INTMAX_C(value) + UINTMAX_C(value) + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed + for C++11 unless __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS + are defined +*/ +#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS) +# define __STDC_LIMIT_MACROS +#endif +#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +# define __STDC_CONSTANT_MACROS +#endif + +#include_next <stdint.h> + +#endif // _LIBCPP_STDINT_H diff --git a/lib/libcxx/include/stdlib.h b/lib/libcxx/include/stdlib.h index 12fd676a15f..f11c5e76226 100644 --- a/lib/libcxx/include/stdlib.h +++ b/lib/libcxx/include/stdlib.h @@ -97,10 +97,6 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 extern "C++" { -#ifdef _LIBCPP_MSVCRT -#include "support/win32/locale_win32.h" -#endif // _LIBCPP_MSVCRT - #undef abs #undef div #undef labs diff --git a/lib/libcxx/include/streambuf b/lib/libcxx/include/streambuf index 7544aaf179b..ea64f578045 100644 --- a/lib/libcxx/include/streambuf +++ b/lib/libcxx/include/streambuf @@ -116,10 +116,13 @@ protected: #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD template <class _CharT, class _Traits> -class _LIBCPP_TYPE_VIS_ONLY basic_streambuf +class _LIBCPP_TEMPLATE_VIS basic_streambuf { public: // types: @@ -132,32 +135,96 @@ public: virtual ~basic_streambuf(); // 27.6.2.2.1 locales: - locale pubimbue(const locale& __loc); - locale getloc() const; + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + locale pubimbue(const locale& __loc) { + imbue(__loc); + locale __r = __loc_; + __loc_ = __loc; + return __r; + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + locale getloc() const { return __loc_; } // 27.6.2.2.2 buffer and positioning: - basic_streambuf* pubsetbuf(char_type* __s, streamsize __n); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) + { return setbuf(__s, __n); } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY pos_type pubseekoff(off_type __off, ios_base::seekdir __way, - ios_base::openmode __which = ios_base::in | ios_base::out); + ios_base::openmode __which = ios_base::in | ios_base::out) + { return seekoff(__off, __way, __which); } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY pos_type pubseekpos(pos_type __sp, - ios_base::openmode __which = ios_base::in | ios_base::out); - int pubsync(); + ios_base::openmode __which = ios_base::in | ios_base::out) + { return seekpos(__sp, __which); } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int pubsync() { return sync(); } // Get and put areas: // 27.6.2.2.3 Get area: - streamsize in_avail(); - int_type snextc(); - int_type sbumpc(); - int_type sgetc(); - streamsize sgetn(char_type* __s, streamsize __n); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + streamsize in_avail() { + if (__ninp_ < __einp_) + return static_cast<streamsize>(__einp_ - __ninp_); + return showmanyc(); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type snextc() { + if (sbumpc() == traits_type::eof()) + return traits_type::eof(); + return sgetc(); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type sbumpc() { + if (__ninp_ == __einp_) + return uflow(); + return traits_type::to_int_type(*__ninp_++); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type sgetc() { + if (__ninp_ == __einp_) + return underflow(); + return traits_type::to_int_type(*__ninp_); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + streamsize sgetn(char_type* __s, streamsize __n) + { return xsgetn(__s, __n); } // 27.6.2.2.4 Putback: - int_type sputbackc(char_type __c); - int_type sungetc(); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type sputbackc(char_type __c) { + if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1])) + return pbackfail(traits_type::to_int_type(__c)); + return traits_type::to_int_type(*--__ninp_); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type sungetc() { + if (__binp_ == __ninp_) + return pbackfail(); + return traits_type::to_int_type(*--__ninp_); + } // 27.6.2.2.5 Put area: - int_type sputc(char_type __c); - streamsize sputn(const char_type* __s, streamsize __n); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + int_type sputc(char_type __c) { + if (__nout_ == __eout_) + return overflow(traits_type::to_int_type(__c)); + *__nout_++ = __c; + return traits_type::to_int_type(__c); + } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + streamsize sputn(const char_type* __s, streamsize __n) + { return xsputn(__s, __n); } protected: basic_streambuf(); @@ -169,15 +236,33 @@ protected: _LIBCPP_ALWAYS_INLINE char_type* eback() const {return __binp_;} _LIBCPP_ALWAYS_INLINE char_type* gptr() const {return __ninp_;} _LIBCPP_ALWAYS_INLINE char_type* egptr() const {return __einp_;} - void gbump(int __n); - void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend); + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void gbump(int __n) { __ninp_ += __n; } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) { + __binp_ = __gbeg; + __ninp_ = __gnext; + __einp_ = __gend; + } // 27.6.2.3.3 Put area: _LIBCPP_ALWAYS_INLINE char_type* pbase() const {return __bout_;} _LIBCPP_ALWAYS_INLINE char_type* pptr() const {return __nout_;} _LIBCPP_ALWAYS_INLINE char_type* epptr() const {return __eout_;} - void pbump(int __n); - void setp(char_type* __pbeg, char_type* __pend); + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void pbump(int __n) { __nout_ += __n; } + + _LIBCPP_ALWAYS_INLINE + void __pbump(streamsize __n) { __nout_ += __n; } + + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + void setp(char_type* __pbeg, char_type* __pend) { + __bout_ = __nout_ = __pbeg; + __eout_ = __pend; + } // 27.6.2.4 virtual functions: // 27.6.2.4.1 Locales: @@ -220,147 +305,6 @@ basic_streambuf<_CharT, _Traits>::~basic_streambuf() } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -locale -basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) -{ - imbue(__loc); - locale __r = __loc_; - __loc_ = __loc; - return __r; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -locale -basic_streambuf<_CharT, _Traits>::getloc() const -{ - return __loc_; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -basic_streambuf<_CharT, _Traits>* -basic_streambuf<_CharT, _Traits>::pubsetbuf(char_type* __s, streamsize __n) -{ - return setbuf(__s, __n); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::pos_type -basic_streambuf<_CharT, _Traits>::pubseekoff(off_type __off, - ios_base::seekdir __way, - ios_base::openmode __which) -{ - return seekoff(__off, __way, __which); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::pos_type -basic_streambuf<_CharT, _Traits>::pubseekpos(pos_type __sp, - ios_base::openmode __which) -{ - return seekpos(__sp, __which); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -int -basic_streambuf<_CharT, _Traits>::pubsync() -{ - return sync(); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -streamsize -basic_streambuf<_CharT, _Traits>::in_avail() -{ - if (__ninp_ < __einp_) - return static_cast<streamsize>(__einp_ - __ninp_); - return showmanyc(); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::snextc() -{ - if (sbumpc() == traits_type::eof()) - return traits_type::eof(); - return sgetc(); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::sbumpc() -{ - if (__ninp_ == __einp_) - return uflow(); - return traits_type::to_int_type(*__ninp_++); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::sgetc() -{ - if (__ninp_ == __einp_) - return underflow(); - return traits_type::to_int_type(*__ninp_); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -streamsize -basic_streambuf<_CharT, _Traits>::sgetn(char_type* __s, streamsize __n) -{ - return xsgetn(__s, __n); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::sputbackc(char_type __c) -{ - if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1])) - return pbackfail(traits_type::to_int_type(__c)); - return traits_type::to_int_type(*--__ninp_); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::sungetc() -{ - if (__binp_ == __ninp_) - return pbackfail(); - return traits_type::to_int_type(*--__ninp_); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -typename basic_streambuf<_CharT, _Traits>::int_type -basic_streambuf<_CharT, _Traits>::sputc(char_type __c) -{ - if (__nout_ == __eout_) - return overflow(traits_type::to_int_type(__c)); - *__nout_++ = __c; - return traits_type::to_int_type(__c); -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -streamsize -basic_streambuf<_CharT, _Traits>::sputn(const char_type* __s, streamsize __n) -{ - return xsputn(__s, __n); -} - -template <class _CharT, class _Traits> basic_streambuf<_CharT, _Traits>::basic_streambuf() : __binp_(0), __ninp_(0), @@ -411,42 +355,6 @@ basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) } template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_streambuf<_CharT, _Traits>::gbump(int __n) -{ - __ninp_ += __n; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_streambuf<_CharT, _Traits>::setg(char_type* __gbeg, char_type* __gnext, - char_type* __gend) -{ - __binp_ = __gbeg; - __ninp_ = __gnext; - __einp_ = __gend; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_streambuf<_CharT, _Traits>::pbump(int __n) -{ - __nout_ += __n; -} - -template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY -void -basic_streambuf<_CharT, _Traits>::setp(char_type* __pbeg, char_type* __pend) -{ - __bout_ = __nout_ = __pbeg; - __eout_ = __pend; -} - -template <class _CharT, class _Traits> void basic_streambuf<_CharT, _Traits>::imbue(const locale&) { @@ -499,7 +407,8 @@ basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) { if (__ninp_ < __einp_) { - const streamsize __len = _VSTD::min(__einp_ - __ninp_, __n - __i); + const streamsize __len = _VSTD::min(static_cast<streamsize>(INT_MAX), + _VSTD::min(__einp_ - __ninp_, __n - __i)); traits_type::copy(__s, __ninp_, __len); __s += __len; __i += __len; @@ -574,12 +483,16 @@ basic_streambuf<_CharT, _Traits>::overflow(int_type) return traits_type::eof(); } -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf<char>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf<wchar_t>) +#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios<char>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios<wchar_t>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>) +#endif _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_STEAMBUF diff --git a/lib/libcxx/include/string b/lib/libcxx/include/string index 786735f970f..f5d548965aa 100644 --- a/lib/libcxx/include/string +++ b/lib/libcxx/include/string @@ -101,7 +101,10 @@ public: basic_string(const basic_string& str, size_type pos, const allocator_type& a = allocator_type()); basic_string(const basic_string& str, size_type pos, size_type n, - const Allocator& a = Allocator()); + const Allocator& a = Allocator()); + template<class T> + basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17 + explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator()); 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()); @@ -114,7 +117,10 @@ public: ~basic_string(); + operator basic_string_view<charT, traits>() const noexcept; + basic_string& operator=(const basic_string& str); + basic_string& operator=(basic_string_view<charT, traits> sv); basic_string& operator=(basic_string&& str) noexcept( allocator_type::propagate_on_container_move_assignment::value || @@ -158,12 +164,16 @@ public: reference at(size_type n); basic_string& operator+=(const basic_string& str); + basic_string& operator+=(basic_string_view<charT, traits> sv); 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(basic_string_view<charT, traits> sv); basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14 + template <class T> + basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17 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); @@ -179,8 +189,11 @@ public: const_reference back() const; basic_string& assign(const basic_string& str); + basic_string& assign(basic_string_view<charT, traits> sv); basic_string& assign(basic_string&& str); basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14 + template <class T> + basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17 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); @@ -189,8 +202,11 @@ public: basic_string& assign(initializer_list<value_type>); basic_string& insert(size_type pos1, const basic_string& str); + basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv); basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n); + template <class T> + basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14 basic_string& insert(size_type pos, const value_type* s); basic_string& insert(size_type pos, size_type n, value_type c); @@ -205,12 +221,17 @@ public: iterator erase(const_iterator first, const_iterator last); basic_string& replace(size_type pos1, size_type n1, const basic_string& str); + basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv); basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2=npos); // C++14 + template <class T> + basic_string& replace(size_type pos1, size_type n1, const T& t, + size_type pos2, size_type n); // C++17 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, basic_string_view<charT, traits> sv); 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); @@ -232,43 +253,61 @@ public: allocator_type get_allocator() const noexcept; size_type find(const basic_string& str, size_type pos = 0) const noexcept; + size_type find(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv, 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(basic_string_view<charT, traits> sv) const noexcept; int compare(size_type pos1, size_type n1, const basic_string& str) const; + int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const; int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2=npos) const; // C++14 + template <class T> + int compare(size_type pos1, size_type n1, const T& t, + size_type pos2, size_type n2=npos) const; // C++17 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 starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a + bool starts_with(charT c) const noexcept; // C++2a + bool starts_with(const charT* s) const; // C++2a + bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a + bool ends_with(charT c) const noexcept; // C++2a + bool ends_with(const charT* s) const; // C++2a + bool __invariants() const; }; @@ -435,6 +474,7 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1 */ #include <__config> +#include <string_view> #include <iosfwd> #include <cstring> #include <cstdio> // For EOF. @@ -450,11 +490,6 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS #include <cstdint> #endif -#if defined(_LIBCPP_NO_EXCEPTIONS) -#include <cassert> -#endif - -#include <__undef_min_max> #include <__debug> @@ -462,12 +497,16 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1 #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // fpos template <class _StateT> -class _LIBCPP_TYPE_VIS_ONLY fpos +class _LIBCPP_TEMPLATE_VIS fpos { private: _StateT __st_; @@ -501,647 +540,6 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {return streamoff(__x) != streamoff(__y);} -// char_traits - -template <class _CharT> -struct _LIBCPP_TYPE_VIS_ONLY char_traits -{ - typedef _CharT char_type; - typedef int int_type; - typedef streamoff off_type; - typedef streampos pos_type; - typedef mbstate_t state_type; - - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} - static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 < __c2;} - - static int compare(const char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s); - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); - static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* assign(char_type* __s, size_t __n, char_type __a); - - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT - {return eq_int_type(__c, eof()) ? ~eof() : __c;} - static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT - {return char_type(__c);} - static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT - {return int_type(__c);} - static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(EOF);} -}; - -template <class _CharT> -int -char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) -{ - for (; __n; --__n, ++__s1, ++__s2) - { - if (lt(*__s1, *__s2)) - return -1; - if (lt(*__s2, *__s1)) - return 1; - } - return 0; -} - -template <class _CharT> -inline -size_t -char_traits<_CharT>::length(const char_type* __s) -{ - size_t __len = 0; - for (; !eq(*__s, char_type(0)); ++__s) - ++__len; - return __len; -} - -template <class _CharT> -inline -const _CharT* -char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) -{ - for (; __n; --__n) - { - if (eq(*__s, __a)) - return __s; - ++__s; - } - return 0; -} - -template <class _CharT> -_CharT* -char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) -{ - char_type* __r = __s1; - if (__s1 < __s2) - { - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - } - else if (__s2 < __s1) - { - __s1 += __n; - __s2 += __n; - for (; __n; --__n) - assign(*--__s1, *--__s2); - } - return __r; -} - -template <class _CharT> -inline -_CharT* -char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) -{ - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - char_type* __r = __s1; - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - return __r; -} - -template <class _CharT> -inline -_CharT* -char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) -{ - char_type* __r = __s; - for (; __n; --__n, ++__s) - assign(*__s, __a); - return __r; -} - -// char_traits<char> - -template <> -struct _LIBCPP_TYPE_VIS_ONLY char_traits<char> -{ - typedef char char_type; - typedef int int_type; - typedef streamoff off_type; - typedef streampos pos_type; - typedef mbstate_t state_type; - - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} - static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT - {return (unsigned char)__c1 < (unsigned char)__c2;} - - static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n) - {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);} - static inline size_t length(const char_type* __s) {return strlen(__s);} - static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a) - {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);} - static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) - {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);} - static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) - { - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n); - } - static inline char_type* assign(char_type* __s, size_t __n, char_type __a) - {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);} - - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT - {return eq_int_type(__c, eof()) ? ~eof() : __c;} - static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT - {return char_type(__c);} - static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT - {return int_type((unsigned char)__c);} - static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(EOF);} -}; - -// char_traits<wchar_t> - -template <> -struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t> -{ - typedef wchar_t char_type; - typedef wint_t int_type; - typedef streamoff off_type; - typedef streampos pos_type; - typedef mbstate_t state_type; - - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} - static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 < __c2;} - - static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n) - {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);} - static inline size_t length(const char_type* __s) - {return wcslen(__s);} - static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a) - {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);} - static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) - {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);} - static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) - { - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n); - } - static inline char_type* assign(char_type* __s, size_t __n, char_type __a) - {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);} - - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT - {return eq_int_type(__c, eof()) ? ~eof() : __c;} - static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT - {return char_type(__c);} - static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT - {return int_type(__c);} - static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(WEOF);} -}; - -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS - -template <> -struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t> -{ - typedef char16_t char_type; - typedef uint_least16_t int_type; - typedef streamoff off_type; - typedef u16streampos pos_type; - typedef mbstate_t state_type; - - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} - static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 < __c2;} - - _LIBCPP_INLINE_VISIBILITY - static int compare(const char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s); - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); - _LIBCPP_INLINE_VISIBILITY - static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* assign(char_type* __s, size_t __n, char_type __a); - - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT - {return eq_int_type(__c, eof()) ? ~eof() : __c;} - static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT - {return char_type(__c);} - static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT - {return int_type(__c);} - static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(0xFFFF);} -}; - -inline -int -char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) -{ - for (; __n; --__n, ++__s1, ++__s2) - { - if (lt(*__s1, *__s2)) - return -1; - if (lt(*__s2, *__s1)) - return 1; - } - return 0; -} - -inline -size_t -char_traits<char16_t>::length(const char_type* __s) -{ - size_t __len = 0; - for (; !eq(*__s, char_type(0)); ++__s) - ++__len; - return __len; -} - -inline -const char16_t* -char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) -{ - for (; __n; --__n) - { - if (eq(*__s, __a)) - return __s; - ++__s; - } - return 0; -} - -inline -char16_t* -char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) -{ - char_type* __r = __s1; - if (__s1 < __s2) - { - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - } - else if (__s2 < __s1) - { - __s1 += __n; - __s2 += __n; - for (; __n; --__n) - assign(*--__s1, *--__s2); - } - return __r; -} - -inline -char16_t* -char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) -{ - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - char_type* __r = __s1; - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - return __r; -} - -inline -char16_t* -char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) -{ - char_type* __r = __s; - for (; __n; --__n, ++__s) - assign(*__s, __a); - return __r; -} - -template <> -struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t> -{ - typedef char32_t char_type; - typedef uint_least32_t int_type; - typedef streamoff off_type; - typedef u32streampos pos_type; - typedef mbstate_t state_type; - - static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT - {__c1 = __c2;} - static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT - {return __c1 < __c2;} - - _LIBCPP_INLINE_VISIBILITY - static int compare(const char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static size_t length(const char_type* __s); - _LIBCPP_INLINE_VISIBILITY - static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); - _LIBCPP_INLINE_VISIBILITY - static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); - _LIBCPP_INLINE_VISIBILITY - static char_type* assign(char_type* __s, size_t __n, char_type __a); - - static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT - {return eq_int_type(__c, eof()) ? ~eof() : __c;} - static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT - {return char_type(__c);} - static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT - {return int_type(__c);} - static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT - {return __c1 == __c2;} - static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(0xFFFFFFFF);} -}; - -inline -int -char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) -{ - for (; __n; --__n, ++__s1, ++__s2) - { - if (lt(*__s1, *__s2)) - return -1; - if (lt(*__s2, *__s1)) - return 1; - } - return 0; -} - -inline -size_t -char_traits<char32_t>::length(const char_type* __s) -{ - size_t __len = 0; - for (; !eq(*__s, char_type(0)); ++__s) - ++__len; - return __len; -} - -inline -const char32_t* -char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) -{ - for (; __n; --__n) - { - if (eq(*__s, __a)) - return __s; - ++__s; - } - return 0; -} - -inline -char32_t* -char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) -{ - char_type* __r = __s1; - if (__s1 < __s2) - { - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - } - else if (__s2 < __s1) - { - __s1 += __n; - __s2 += __n; - for (; __n; --__n) - assign(*--__s1, *--__s2); - } - return __r; -} - -inline -char32_t* -char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) -{ - _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); - char_type* __r = __s1; - for (; __n; --__n, ++__s1, ++__s2) - assign(*__s1, *__s2); - return __r; -} - -inline -char32_t* -char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) -{ - char_type* __r = __s; - for (; __n; --__n, ++__s) - assign(*__s, __a); - return __r; -} - -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - -// helper fns for basic_string - -// __str_find -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find(const _CharT *__p, _SizeT __sz, - _CharT __c, _SizeT __pos) _NOEXCEPT -{ - if (__pos >= __sz) - return __npos; - const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c); - if (__r == 0) - return __npos; - return static_cast<_SizeT>(__r - __p); -} - -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT -{ - if (__pos > __sz || __sz - __pos < __n) - return __npos; - if (__n == 0) - return __pos; - const _CharT* __r = - _VSTD::__search(__p + __pos, __p + __sz, - __s, __s + __n, _Traits::eq, - random_access_iterator_tag(), random_access_iterator_tag()).first; - if (__r == __p + __sz) - return __npos; - return static_cast<_SizeT>(__r - __p); -} - - -// __str_rfind - -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_rfind(const _CharT *__p, _SizeT __sz, - _CharT __c, _SizeT __pos) _NOEXCEPT -{ - if (__sz < 1) - return __npos; - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - for (const _CharT* __ps = __p + __pos; __ps != __p;) - { - if (_Traits::eq(*--__ps, __c)) - return static_cast<_SizeT>(__ps - __p); - } - return __npos; -} - -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_rfind(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT -{ - __pos = _VSTD::min(__pos, __sz); - if (__n < __sz - __pos) - __pos += __n; - else - __pos = __sz; - const _CharT* __r = _VSTD::__find_end( - __p, __p + __pos, __s, __s + __n, _Traits::eq, - random_access_iterator_tag(), random_access_iterator_tag()); - if (__n > 0 && __r == __p + __pos) - return __npos; - return static_cast<_SizeT>(__r - __p); -} - -// __str_find_first_of -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_first_of(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT -{ - if (__pos >= __sz || __n == 0) - return __npos; - const _CharT* __r = _VSTD::__find_first_of_ce - (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); - if (__r == __p + __sz) - return __npos; - return static_cast<_SizeT>(__r - __p); -} - - -// __str_find_last_of -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_last_of(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT - { - if (__n != 0) - { - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - for (const _CharT* __ps = __p + __pos; __ps != __p;) - { - const _CharT* __r = _Traits::find(__s, __n, *--__ps); - if (__r) - return static_cast<_SizeT>(__ps - __p); - } - } - return __npos; -} - - -// __str_find_first_not_of -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_first_not_of(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT -{ - if (__pos < __sz) - { - const _CharT* __pe = __p + __sz; - for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) - if (_Traits::find(__s, __n, *__ps) == 0) - return static_cast<_SizeT>(__ps - __p); - } - return __npos; -} - - -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_first_not_of(const _CharT *__p, _SizeT __sz, - _CharT __c, _SizeT __pos) _NOEXCEPT -{ - if (__pos < __sz) - { - const _CharT* __pe = __p + __sz; - for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) - if (!_Traits::eq(*__ps, __c)) - return static_cast<_SizeT>(__ps - __p); - } - return __npos; -} - - -// __str_find_last_not_of -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_last_not_of(const _CharT *__p, _SizeT __sz, - const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT -{ - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - for (const _CharT* __ps = __p + __pos; __ps != __p;) - if (_Traits::find(__s, __n, *--__ps) == 0) - return static_cast<_SizeT>(__ps - __p); - return __npos; -} - - -template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> -inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -__str_find_last_not_of(const _CharT *__p, _SizeT __sz, - _CharT __c, _SizeT __pos) _NOEXCEPT -{ - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - for (const _CharT* __ps = __p + __pos; __ps != __p;) - if (!_Traits::eq(*--__ps, __c)) - return static_cast<_SizeT>(__ps - __p); - return __npos; -} - -template<class _Ptr> -size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e) -{ - typedef typename iterator_traits<_Ptr>::value_type value_type; - return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type)); -} - // basic_string template<class _CharT, class _Traits, class _Allocator> @@ -1165,44 +563,31 @@ template<class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) + template <bool> -class _LIBCPP_TYPE_VIS_ONLY __basic_string_common +class _LIBCPP_TEMPLATE_VIS __basic_string_common { protected: - void __throw_length_error() const; - void __throw_out_of_range() const; + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; }; template <bool __b> void __basic_string_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("basic_string"); -#else - assert(!"basic_string length_error"); -#endif + _VSTD::__throw_length_error("basic_string"); } template <bool __b> void __basic_string_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("basic_string"); -#else - assert(!"basic_string out_of_range"); -#endif + _VSTD::__throw_out_of_range("basic_string"); } -#ifdef _LIBCPP_MSVC -#pragma warning( push ) -#pragma warning( disable: 4231 ) -#endif // _LIBCPP_MSVC -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>) #ifdef _LIBCPP_NO_EXCEPTIONS template <class _Iter> @@ -1228,6 +613,11 @@ template <class _Iter> struct __libcpp_string_gets_noexcept_iterator : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {}; +template <class _CharT, class _Traits, class _Tp> +struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT( + ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && + !is_convertible<const _Tp&, const _CharT*>::value)) {}; + #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template <class _CharT, size_t = sizeof(_CharT)> @@ -1244,13 +634,14 @@ struct __padding<_CharT, 1> #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template<class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY basic_string +class _LIBCPP_TEMPLATE_VIS basic_string : private __basic_string_common<true> { public: typedef basic_string __self; + typedef basic_string_view<_CharT, _Traits> __self_view; typedef _Traits traits_type; - typedef typename traits_type::char_type value_type; + typedef _CharT value_type; typedef _Allocator allocator_type; typedef allocator_traits<allocator_type> __alloc_traits; typedef typename __alloc_traits::size_type size_type; @@ -1261,7 +652,7 @@ public: typedef typename __alloc_traits::const_pointer const_pointer; static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD"); - static_assert((is_same<_CharT, value_type>::value), + static_assert((is_same<_CharT, typename traits_type::char_type>::value), "traits_type::char_type must be the same type as CharT"); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -1286,12 +677,12 @@ private: size_type __cap_; }; -#if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; +#ifdef _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? @@ -1316,12 +707,12 @@ private: pointer __data_; }; -#if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; +#ifdef _LIBCPP_BIG_ENDIAN + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? @@ -1376,7 +767,7 @@ public: basic_string(const basic_string& __str); basic_string(const basic_string& __str, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str) #if _LIBCPP_STD_VER <= 14 @@ -1387,50 +778,66 @@ 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 value_type* __s); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, const allocator_type& __a); + basic_string(const _CharT* __s, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n); + basic_string(const _CharT* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n, const allocator_type& __a); + basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c); + basic_string(size_type __n, _CharT __c); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c, const allocator_type& __a); + basic_string(size_type __n, _CharT __c, const _Allocator& __a); basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); _LIBCPP_INLINE_VISIBILITY basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); + template<class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string(const _Tp& __t, size_type __pos, size_type __n, + const allocator_type& __a = allocator_type(), + typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0); + _LIBCPP_INLINE_VISIBILITY explicit + basic_string(__self_view __sv); + _LIBCPP_INLINE_VISIBILITY + basic_string(__self_view __sv, const _Allocator& __a); template<class _InputIterator> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last); template<class _InputIterator> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list<value_type> __il); + basic_string(initializer_list<_CharT> __il); _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + basic_string(initializer_list<_CharT> __il, const _Allocator& __a); +#endif // _LIBCPP_CXX03_LANG - ~basic_string(); + inline ~basic_string(); + + _LIBCPP_INLINE_VISIBILITY + operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } basic_string& operator=(const basic_string& __str); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_CXX03_LANG + template <class = void> +#endif + _LIBCPP_INLINE_VISIBILITY + basic_string& operator=(__self_view __sv) {return assign(__sv);} +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator=(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); + _LIBCPP_INLINE_VISIBILITY + basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} #endif _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 - basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY @@ -1496,52 +903,78 @@ public: void resize(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} - void reserve(size_type res_arg = 0); + void reserve(size_type __res_arg = 0); _LIBCPP_INLINE_VISIBILITY void shrink_to_fit() _NOEXCEPT {reserve();} _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} - _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const; - _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos); + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT; const_reference at(size_type __n) const; 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 value_type* __s) {return append(__s);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);} + _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 +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& append(const basic_string& __str); + _LIBCPP_INLINE_VISIBILITY + basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); } basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + append(const _Tp& __t, size_type __pos, size_type __n=npos); 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 _ForwardIterator> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, basic_string& >::type - append(_InputIterator __first, _InputIterator __last); + _LIBCPP_INLINE_VISIBILITY + append(_InputIterator __first, _InputIterator __last) { + const basic_string __temp (__first, __last, __alloc()); + append(__temp.data(), __temp.size()); + return *this; + } template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string& >::type - append(_ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + append(_ForwardIterator __first, _ForwardIterator __last) { + return __append_forward_unsafe(__first, __last); + } + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG void push_back(value_type __c); _LIBCPP_INLINE_VISIBILITY @@ -1552,19 +985,30 @@ public: _LIBCPP_INLINE_VISIBILITY const_reference back() const; _LIBCPP_INLINE_VISIBILITY + basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); } + _LIBCPP_INLINE_VISIBILITY basic_string& assign(const basic_string& __str) { return *this = __str; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - basic_string& assign(basic_string&& str) + basic_string& assign(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) - {*this = _VSTD::move(str); return *this;} + {*this = _VSTD::move(__str); return *this;} #endif basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + assign(const _Tp & __t, size_type __pos, size_type __n=npos); 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 + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, @@ -1572,20 +1016,31 @@ public: >::type assign(_InputIterator __first, _InputIterator __last); template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string& >::type assign(_ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& insert(size_type __pos1, const basic_string& __str); + _LIBCPP_INLINE_VISIBILITY + basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); } + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); basic_string& insert(size_type __pos, const value_type* __s, size_type __n); basic_string& insert(size_type __pos, const value_type* __s); @@ -1594,7 +1049,8 @@ public: _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, size_type __n, value_type __c); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, @@ -1602,18 +1058,19 @@ public: >::type insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, iterator >::type insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, initializer_list<value_type> __il) {return insert(__pos, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG basic_string& erase(size_type __pos = 0, size_type __n = npos); _LIBCPP_INLINE_VISIBILITY @@ -1623,30 +1080,43 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); + _LIBCPP_INLINE_VISIBILITY + basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); } basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); + template <class _Tp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string& + >::type + replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); 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, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); } + _LIBCPP_INLINE_VISIBILITY 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 value_type* __s); _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_input_iterator<_InputIterator>::value, basic_string& >::type replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) {return replace(__i1, __i2, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; _LIBCPP_INLINE_VISIBILITY @@ -1655,9 +1125,9 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT; + _NOEXCEPT_DEBUG; #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -1665,7 +1135,7 @@ public: const value_type* c_str() const _NOEXCEPT {return data();} _LIBCPP_INLINE_VISIBILITY const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} -#if _LIBCPP_STD_VER > 14 +#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) _LIBCPP_INLINE_VISIBILITY value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} #endif @@ -1675,6 +1145,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; @@ -1682,6 +1154,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT; size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; @@ -1689,6 +1163,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(__self_view __sv, size_type __pos = 0) 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 value_type* __s, size_type __pos = 0) const _NOEXCEPT; @@ -1697,6 +1173,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(__self_view __sv, size_type __pos = npos) 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 value_type* __s, size_type __pos = npos) const _NOEXCEPT; @@ -1705,6 +1183,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(__self_view __sv, size_type __pos = 0) 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 value_type* __s, size_type __pos = 0) const _NOEXCEPT; @@ -1713,6 +1193,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(__self_view __sv, size_type __pos = npos) 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 value_type* __s, size_type __pos = npos) const _NOEXCEPT; @@ -1722,12 +1204,50 @@ public: _LIBCPP_INLINE_VISIBILITY int compare(const basic_string& __str) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY + int compare(__self_view __sv) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, __self_view __sv) const; + _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=npos) const; + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int + >::type + compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) 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; +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).starts_with(__sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(__self_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).ends_with( __sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(__self_view(__s)); } +#endif + _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY @@ -1755,7 +1275,7 @@ private: _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} # else {__r_.first().__s.__size_ = (unsigned char)(__s);} @@ -1763,7 +1283,7 @@ private: _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_ >> 1;} # else {return __r_.first().__s.__size_;} @@ -1773,7 +1293,7 @@ private: _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s);} # else {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} @@ -1781,7 +1301,7 @@ private: _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_;} # else {return __r_.first().__s.__size_ >> 1;} @@ -1847,11 +1367,15 @@ private: __align_it<sizeof(value_type) < __alignment ? __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} + inline void __init(const value_type* __s, size_type __sz, size_type __reserve); + inline void __init(const value_type* __s, size_type __sz); + inline void __init(size_type __n, value_type __c); template <class _InputIterator> + inline typename enable_if < __is_exactly_input_iterator<_InputIterator>::value, @@ -1860,6 +1384,7 @@ private: __init(_InputIterator __first, _InputIterator __last); template <class _ForwardIterator> + inline typename enable_if < __is_forward_iterator<_ForwardIterator>::value, @@ -1884,19 +1409,35 @@ private: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str, true_type) { - if (__alloc() != __str.__alloc()) + if (__alloc() == __str.__alloc()) + __alloc() = __str.__alloc(); + else { - clear(); - shrink_to_fit(); + if (!__str.__is_long()) + { + clear(); + shrink_to_fit(); + __alloc() = __str.__alloc(); + } + else + { + allocator_type __a = __str.__alloc(); + pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap()); + clear(); + shrink_to_fit(); + __alloc() = _VSTD::move(__a); + __set_long_pointer(__p); + __set_long_cap(__str.__get_long_cap()); + __set_long_size(__str.size()); + } } - __alloc() = __str.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void __move_assign(basic_string& __str, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value); @@ -1999,7 +1540,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __ #else _NOEXCEPT #endif -: __r_(__a) +: __r_(__second_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); @@ -2008,8 +1549,9 @@ 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 value_type* __s, size_type __sz, size_type __reserve) +void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, + size_type __sz, + size_type __reserve) { if (__reserve > max_size()) this->__throw_length_error(); @@ -2057,7 +1599,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); @@ -2068,8 +1610,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) + : __r_(__second_tag(), __a) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); @@ -2080,7 +1622,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, c template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); @@ -2091,8 +1633,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, s template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) + : __r_(__second_tag(), __a) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); @@ -2103,7 +1645,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, s template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) - : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc())) + : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; @@ -2115,8 +1657,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st } template <class _CharT, class _Traits, class _Allocator> -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const basic_string& __str, const allocator_type& __a) + : __r_(__second_tag(), __a) { if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; @@ -2127,7 +1670,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st #endif } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -2150,7 +1693,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) - : __r_(__a) + : __r_(__second_tag(), __a) { if (__str.__is_long() && __a != __str.__alloc()) // copy, not move __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); @@ -2166,7 +1709,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> void @@ -2194,7 +1737,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -2204,8 +1747,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) + : __r_(__second_tag(), __a) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -2214,9 +1757,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ } template <class _CharT, class _Traits, class _Allocator> -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, + size_type __pos, size_type __n, + const _Allocator& __a) + : __r_(__second_tag(), __a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) @@ -2230,8 +1774,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a) - : __r_(__a) + const _Allocator& __a) + : __r_(__second_tag(), __a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) @@ -2243,6 +1787,41 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a, + typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *) + : __r_(__second_tag(), __a) +{ + __self_view __sv = __self_view(__t).substr(__pos, __n); + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv) +{ + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a) + : __r_(__second_tag(), __a) +{ + __init(__sv.data(), __sv.size()); +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif +} + +template <class _CharT, class _Traits, class _Allocator> template <class _InputIterator> typename enable_if < @@ -2316,7 +1895,7 @@ template<class _InputIterator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) - : __r_(__a) + : __r_(__second_tag(), __a) { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -2324,11 +1903,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, #endif } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -2338,8 +1918,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_t template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a) - : __r_(__a) + +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il, const _Allocator& __a) + : __r_(__second_tag(), __a) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -2347,7 +1929,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_t #endif } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::~basic_string() @@ -2496,7 +2078,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -2550,7 +2132,7 @@ typename enable_if >::type basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { - basic_string __temp(__first, __last, __alloc()); + const basic_string __temp(__first, __last, __alloc()); assign(__temp.data(), __temp.size()); return *this; } @@ -2593,6 +2175,23 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) +{ + __self_view __sv = __t; + size_type __sz = __sv.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + + +template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) { @@ -2681,43 +2280,48 @@ basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) traits_type::assign(*++__p, value_type()); } -template <class _CharT, class _Traits, class _Allocator> -template<class _InputIterator> -typename enable_if -< - __is_exactly_input_iterator<_InputIterator>::value - || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, - basic_string<_CharT, _Traits, _Allocator>& ->::type -basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last) +template <class _Tp> +bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last) { - basic_string __temp (__first, __last, __alloc()); - append(__temp.data(), __temp.size()); - return *this; + return __first <= __p && __p < __last; +} + +template <class _Tp1, class _Tp2> +bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*) +{ + return false; } template <class _CharT, class _Traits, class _Allocator> template<class _ForwardIterator> -typename enable_if -< - __is_forward_iterator<_ForwardIterator>::value - && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, - basic_string<_CharT, _Traits, _Allocator>& ->::type -basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last) +basic_string<_CharT, _Traits, _Allocator>& +basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe( + _ForwardIterator __first, _ForwardIterator __last) { + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "function requires a ForwardIterator"); size_type __sz = size(); size_type __cap = capacity(); size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) { - if (__cap - __sz < __n) - __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); - pointer __p = __get_pointer() + __sz; - for (; __first != __last; ++__p, ++__first) - traits_type::assign(*__p, *__first); - traits_type::assign(*__p, value_type()); - __set_size(__sz + __n); + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_ref = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size())) + { + const basic_string __temp (__first, __last, __alloc()); + append(__temp.data(), __temp.size()); + } + else + { + if (__cap - __sz < __n) + __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); + pointer __p = __get_pointer() + __sz; + for (; __first != __last; ++__p, ++__first) + traits_type::assign(*__p, *__first); + traits_type::assign(*__p, value_type()); + __set_size(__sz + __n); + } } return *this; } @@ -2741,6 +2345,22 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> + typename enable_if + < + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& + >::type +basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n) +{ + __self_view __sv = __t; + size_type __sz = __sv.size(); + if (__pos > __sz) + this->__throw_out_of_range(); + return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); +} + +template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) { @@ -2828,7 +2448,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIt "string::insert(iterator, range) called with an iterator not" " referring to this string"); #endif - basic_string __temp(__first, __last, __alloc()); + const basic_string __temp(__first, __last, __alloc()); return insert(__pos, __temp.data(), __temp.data() + __temp.size()); } @@ -2848,11 +2468,19 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward " referring to this string"); #endif size_type __ip = static_cast<size_type>(__pos - begin()); - size_type __sz = size(); - size_type __cap = capacity(); size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) { + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_char = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size())) + { + const basic_string __temp(__first, __last, __alloc()); + return insert(__pos, __temp.data(), __temp.data() + __temp.size()); + } + + size_type __sz = size(); + size_type __cap = capacity(); value_type* __p; if (__cap - __sz >= __n) { @@ -2895,6 +2523,23 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_ } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, + size_type __pos2, size_type __n) +{ + __self_view __sv = __t; + size_type __str_sz = __sv.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); +} + +template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) { @@ -2948,6 +2593,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 value_type* __s, size_type __n2) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); size_type __sz = size(); @@ -2987,6 +2633,8 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ } traits_type::move(__p + __pos, __s, __n2); __finish: +// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow, +// but this is a safe operation, so we disable the check. __sz += __n2 - __n1; __set_size(__sz); __invalidate_iterators_past(__sz); @@ -3000,6 +2648,7 @@ __finish: template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { size_type __sz = size(); if (__pos > __sz) @@ -3040,7 +2689,7 @@ typename enable_if basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2) { - basic_string __temp(__j1, __j2, __alloc()); + const basic_string __temp(__j1, __j2, __alloc()); return this->replace(__i1, __i2, __temp); } @@ -3064,6 +2713,23 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _ } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& +>::type +basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, + size_type __pos2, size_type __n2) +{ + __self_view __sv = __t; + size_type __str_sz = __sv.size(); + if (__pos2 > __str_sz) + this->__throw_out_of_range(); + return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); +} + +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 value_type* __s) { @@ -3238,7 +2904,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT { size_type __m = __alloc_traits::max_size(__alloc()); -#if _LIBCPP_BIG_ENDIAN +#ifdef _LIBCPP_BIG_ENDIAN return (__m <= ~__long_mask ? __m : __m/2) - __alignment; #else return __m - __alignment; @@ -3311,7 +2977,7 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::const_reference -basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const +basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); return *(data() + __pos); @@ -3320,7 +2986,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::reference -basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) +basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT { _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); return *(__get_pointer() + __pos); @@ -3405,9 +3071,9 @@ inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT + _NOEXCEPT_DEBUG #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { @@ -3418,6 +3084,10 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) __get_db()->__invalidate_all(&__str); __get_db()->swap(this, &__str); #endif + _LIBCPP_ASSERT( + __alloc_traits::propagate_on_container_swap::value || + __alloc_traits::is_always_equal::value || + __alloc() == __str.__alloc(), "swapping non-equal allocators"); _VSTD::swap(__r_.first(), __str.__r_.first()); __swap_allocator(__alloc(), __str.__alloc()); } @@ -3440,7 +3110,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); - return _VSTD::__str_find<value_type, size_type, traits_type, npos> + return __str_find<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3450,18 +3120,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find<value_type, size_type, traits_type, npos> + return __str_find<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); - return _VSTD::__str_find<value_type, size_type, traits_type, npos> + return __str_find<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3470,7 +3150,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find<value_type, size_type, traits_type, npos> + return __str_find<value_type, size_type, traits_type, npos> (data(), size(), __c, __pos); } @@ -3483,7 +3163,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); - return _VSTD::__str_rfind<value_type, size_type, traits_type, npos> + return __str_rfind<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3493,18 +3173,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_rfind<value_type, size_type, traits_type, npos> + return __str_rfind<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); - return _VSTD::__str_rfind<value_type, size_type, traits_type, npos> + return __str_rfind<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3513,7 +3203,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_rfind<value_type, size_type, traits_type, npos> + return __str_rfind<value_type, size_type, traits_type, npos> (data(), size(), __c, __pos); } @@ -3526,7 +3216,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); - return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos> + return __str_find_first_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3536,18 +3226,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos> + return __str_find_first_of<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); - return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos> + return __str_find_first_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3569,7 +3269,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); - return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos> + return __str_find_last_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3579,18 +3279,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos> + return __str_find_last_of<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); - return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos> + return __str_find_last_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3612,7 +3322,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); - return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos> + return __str_find_first_not_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3622,18 +3332,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos> + return __str_find_first_not_of<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); - return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos> + return __str_find_first_not_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3643,7 +3363,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos> + return __str_find_first_not_of<value_type, size_type, traits_type, npos> (data(), size(), __c, __pos); } @@ -3656,7 +3376,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); - return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos> + return __str_find_last_not_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, __n); } @@ -3666,18 +3386,28 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos> + return __str_find_last_not_of<value_type, size_type, traits_type, npos> (data(), size(), __str.data(), __pos, __str.size()); } template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type +basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv, + size_type __pos) const _NOEXCEPT +{ + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __sv.data(), __pos, __sv.size()); +} + +template<class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); - return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos> + return __str_find_last_not_of<value_type, size_type, traits_type, npos> (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3687,7 +3417,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos> + return __str_find_last_not_of<value_type, size_type, traits_type, npos> (data(), size(), __c, __pos); } @@ -3696,11 +3426,11 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY int -basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT +basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT { size_t __lhs_sz = size(); - size_t __rhs_sz = __str.size(); - int __result = traits_type::compare(data(), __str.data(), + size_t __rhs_sz = __sv.size(); + int __result = traits_type::compare(data(), __sv.data(), _VSTD::min(__lhs_sz, __rhs_sz)); if (__result != 0) return __result; @@ -3714,6 +3444,47 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) co template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY int +basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT +{ + return compare(__self_view(__str)); +} + +template <class _CharT, class _Traits, class _Allocator> +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const value_type* __s, + size_type __n2) const +{ + _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); + size_type __sz = size(); + if (__pos1 > __sz || __n2 == npos) + this->__throw_out_of_range(); + size_type __rlen = _VSTD::min(__n1, __sz - __pos1); + int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); + if (__r == 0) + { + if (__rlen < __n2) + __r = -1; + else if (__rlen > __n2) + __r = 1; + } + return __r; +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +int +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + __self_view __sv) const +{ + return compare(__pos1, __n1, __sv.data(), __sv.size()); +} + +template <class _CharT, class _Traits, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str) const @@ -3722,6 +3493,23 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, } template <class _CharT, class _Traits, class _Allocator> +template <class _Tp> +typename enable_if +< + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int +>::type +basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, + size_type __n1, + const _Tp& __t, + size_type __pos2, + size_type __n2) const +{ + __self_view __sv = __t; + return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); +} + +template <class _CharT, class _Traits, class _Allocator> int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, @@ -3729,11 +3517,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __pos2, size_type __n2) const { - size_type __sz = __str.size(); - if (__pos2 > __sz) - this->__throw_out_of_range(); - return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, - __sz - __pos2)); + return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); } template <class _CharT, class _Traits, class _Allocator> @@ -3754,29 +3538,6 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, return compare(__pos1, __n1, __s, traits_type::length(__s)); } -template <class _CharT, class _Traits, class _Allocator> -int -basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, - size_type __n1, - const value_type* __s, - size_type __n2) const -{ - _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); - size_type __sz = size(); - if (__pos1 > __sz || __n2 == npos) - this->__throw_out_of_range(); - size_type __rlen = _VSTD::min(__n1, __sz - __pos1); - int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); - if (__r == 0) - { - if (__rlen < __n2) - __r = -1; - else if (__rlen > __n2) - __r = 1; - } - return __r; -} - // __invariants template<class _CharT, class _Traits, class _Allocator> @@ -3854,8 +3615,6 @@ operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; } -// operator!= - template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY bool @@ -4060,7 +3819,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) return __r; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -4120,7 +3879,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) return _VSTD::move(__lhs); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG // swap @@ -4186,7 +3945,7 @@ template<class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::npos; template<class _CharT, class _Traits, class _Allocator> -struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> > +struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> > : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t> { size_t @@ -4222,7 +3981,7 @@ basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -4236,7 +3995,7 @@ basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -4274,6 +4033,9 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* #endif // _LIBCPP_DEBUG_LEVEL >= 2 +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>) +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>) + #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals @@ -4307,10 +4069,8 @@ inline namespace literals } #endif -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>) -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>) -_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) - _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_STRING diff --git a/lib/libcxx/include/string_view b/lib/libcxx/include/string_view new file mode 100644 index 00000000000..72cf816e8d5 --- /dev/null +++ b/lib/libcxx/include/string_view @@ -0,0 +1,825 @@ +// -*- C++ -*- +//===------------------------ string_view ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STRING_VIEW +#define _LIBCPP_STRING_VIEW + +/* +string_view synopsis + +namespace std { + + // 7.2, Class template basic_string_view + template<class charT, class traits = char_traits<charT>> + class basic_string_view; + + // 7.9, basic_string_view non-member comparison functions + template<class charT, class traits> + constexpr bool operator==(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator!=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator< (basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator> (basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator<=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + template<class charT, class traits> + constexpr bool operator>=(basic_string_view<charT, traits> x, + basic_string_view<charT, traits> y) noexcept; + // see below, sufficient additional overloads of comparison functions + + // 7.10, Inserters and extractors + template<class charT, class traits> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, + basic_string_view<charT, traits> str); + + // basic_string_view typedef names + typedef basic_string_view<char> string_view; + typedef basic_string_view<char16_t> u16string_view; + typedef basic_string_view<char32_t> u32string_view; + typedef basic_string_view<wchar_t> wstring_view; + + template<class charT, class traits = char_traits<charT>> + class basic_string_view { + public: + // types + typedef traits traits_type; + typedef charT value_type; + typedef charT* pointer; + typedef const charT* const_pointer; + typedef charT& reference; + typedef const charT& const_reference; + typedef implementation-defined const_iterator; + typedef const_iterator iterator; + typedef reverse_iterator<const_iterator> const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static constexpr size_type npos = size_type(-1); + + // 7.3, basic_string_view constructors and assignment operators + constexpr basic_string_view() noexcept; + constexpr basic_string_view(const basic_string_view&) noexcept = default; + basic_string_view& operator=(const basic_string_view&) noexcept = default; + template<class Allocator> + constexpr basic_string_view(const charT* str); + constexpr basic_string_view(const charT* str, size_type len); + + // 7.4, basic_string_view iterator support + constexpr const_iterator begin() const noexcept; + constexpr const_iterator end() const noexcept; + constexpr const_iterator cbegin() const noexcept; + constexpr const_iterator cend() const noexcept; + const_reverse_iterator rbegin() const noexcept; + const_reverse_iterator rend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + // 7.5, basic_string_view capacity + constexpr size_type size() const noexcept; + constexpr size_type length() const noexcept; + constexpr size_type max_size() const noexcept; + constexpr bool empty() const noexcept; + + // 7.6, basic_string_view element access + constexpr const_reference operator[](size_type pos) const; + constexpr const_reference at(size_type pos) const; + constexpr const_reference front() const; + constexpr const_reference back() const; + constexpr const_pointer data() const noexcept; + + // 7.7, basic_string_view modifiers + constexpr void remove_prefix(size_type n); + constexpr void remove_suffix(size_type n); + constexpr void swap(basic_string_view& s) noexcept; + + size_type copy(charT* s, size_type n, size_type pos = 0) const; + + constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; + constexpr int compare(basic_string_view s) const noexcept; + constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; + constexpr int compare(size_type pos1, size_type n1, + basic_string_view s, size_type pos2, size_type n2) const; + constexpr int compare(const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, + const charT* s, size_type n2) const; + constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find(charT c, size_type pos = 0) const noexcept; + constexpr size_type find(const charT* s, size_type pos, size_type n) const; + constexpr size_type find(const charT* s, size_type pos = 0) const; + constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; + constexpr size_type rfind(const charT* s, size_type pos, size_type n) const; + constexpr size_type rfind(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_of(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + + constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a + constexpr bool starts_with(charT c) const noexcept; // C++2a + constexpr bool starts_with(const charT* s) const; // C++2a + constexpr bool ends_with(basic_string_view s) const noexcept; // C++2a + constexpr bool ends_with(charT c) const noexcept; // C++2a + constexpr bool ends_with(const charT* s) const; // C++2a + + private: + const_pointer data_; // exposition only + size_type size_; // exposition only + }; + + // 7.11, Hash support + template <class T> struct hash; + template <> struct hash<string_view>; + template <> struct hash<u16string_view>; + template <> struct hash<u32string_view>; + template <> struct hash<wstring_view>; + + constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; + constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; + constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; + constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; + +} // namespace std + + +*/ + +#include <__config> +#include <__string> +#include <algorithm> +#include <iterator> +#include <limits> +#include <stdexcept> +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _CharT, class _Traits = char_traits<_CharT> > +class _LIBCPP_TEMPLATE_VIS basic_string_view { +public: + // types + typedef _Traits traits_type; + typedef _CharT value_type; + typedef _CharT* pointer; + typedef const _CharT* const_pointer; + typedef _CharT& reference; + typedef const _CharT& const_reference; + typedef const_pointer const_iterator; // See [string.view.iterators] + typedef const_iterator iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); + + static_assert(is_pod<value_type>::value, "Character type of basic_string_view must be a POD"); + static_assert((is_same<_CharT, typename traits_type::char_type>::value), + "traits_type::char_type must be the same type as CharT"); + + // [string.view.cons], construct/copy + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const basic_string_view&) _NOEXCEPT = default; + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT + : __data(__s), __size(__len) + { +// #if _LIBCPP_STD_VER > 11 +// _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); +// #endif + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s) + : __data(__s), __size(_Traits::length(__s)) {} + + // [string.view.iterators], iterators + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT { return cbegin(); } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT { return cend(); } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT { return __data; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT { return __data + __size; } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + + // [string.view.capacity], capacity + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT { return __size; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type length() const _NOEXCEPT { return __size; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool empty() const _NOEXCEPT { return __size == 0; } + + // [string.view.access], element access + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference at(size_type __pos) const + { + return __pos >= size() + ? (__throw_out_of_range("string_view::at"), __data[0]) + : __data[__pos]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference front() const + { + return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference back() const + { + return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_pointer data() const _NOEXCEPT { return __data; } + + // [string.view.modifiers], modifiers: + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_prefix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); + __data += __n; + __size -= __n; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_suffix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); + __size -= __n; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void swap(basic_string_view& __other) _NOEXCEPT + { + const value_type *__p = __data; + __data = __other.__data; + __other.__data = __p; + + size_type __sz = __size; + __size = __other.__size; + __other.__size = __sz; + } + + _LIBCPP_INLINE_VISIBILITY + size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const + { + if (__pos > size()) + __throw_out_of_range("string_view::copy"); + size_type __rlen = _VSTD::min(__n, size() - __pos); + _Traits::copy(__s, data() + __pos, __rlen); + return __rlen; + } + + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view substr(size_type __pos = 0, size_type __n = npos) const + { + return __pos > size() + ? (__throw_out_of_range("string_view::substr"), basic_string_view()) + : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT + { + size_type __rlen = _VSTD::min( size(), __sv.size()); + int __retval = _Traits::compare(data(), __sv.data(), __rlen); + if ( __retval == 0 ) // first __rlen chars matched + __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); + return __retval; + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const + { + return substr(__pos1, __n1).compare(__sv); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare( size_type __pos1, size_type __n1, + basic_string_view __sv, size_type __pos2, size_type __n2) const + { + return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(const _CharT* __s) const _NOEXCEPT + { + return compare(basic_string_view(__s)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s)); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); + } + + // find + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos = 0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); + return __str_find<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // rfind + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { return find(__c, __pos); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { return rfind(__c, __pos); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT + { + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT + { + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __c, __pos); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of<value_type, size_type, traits_type, npos> + (data(), size(), __s, __pos, traits_type::length(__s)); + } + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(basic_string_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(basic_string_view(__s)); } +#endif + +private: + const value_type* __data; + size_type __size; +}; + + +// [string.view.comparison] +// operator == +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(basic_string_view<_CharT, _Traits> __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; +} + + +// operator != +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; +} + + +// operator < +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) < 0; +} + + +// operator > +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) > 0; +} + + +// operator <= +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) <= 0; +} + + +// operator >= +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(basic_string_view<_CharT, _Traits> __lhs, + typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + +template<class _CharT, class _Traits> +_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT +{ + return __lhs.compare(__rhs) >= 0; +} + +typedef basic_string_view<char> string_view; +typedef basic_string_view<char16_t> u16string_view; +typedef basic_string_view<char32_t> u32string_view; +typedef basic_string_view<wchar_t> wstring_view; + +// [string.view.hash] +template<class _CharT, class _Traits> +struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, _Traits> > + : public unary_function<basic_string_view<_CharT, _Traits>, size_t> +{ + size_t operator()(const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT; +}; + +template<class _CharT, class _Traits> +size_t +hash<basic_string_view<_CharT, _Traits> >::operator()( + const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT +{ + return __do_string_hash(__val.data(), __val.data() + __val.size()); +} + + +#if _LIBCPP_STD_VER > 11 +inline namespace literals +{ + inline namespace string_view_literals + { + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<wchar_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char16_t> (__str, __len); + } + + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT + { + return basic_string_view<char32_t> (__str, __len); + } + } +} +#endif +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_STRING_VIEW diff --git a/lib/libcxx/include/strstream b/lib/libcxx/include/strstream index 81eef2ab484..b00b9d830df 100644 --- a/lib/libcxx/include/strstream +++ b/lib/libcxx/include/strstream @@ -151,12 +151,12 @@ public: strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0); strstreambuf(const unsigned char* __gnext, streamsize __n); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY strstreambuf(strstreambuf&& __rhs); _LIBCPP_INLINE_VISIBILITY strstreambuf& operator=(strstreambuf&& __rhs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG virtual ~strstreambuf(); @@ -191,7 +191,7 @@ private: void __init(char* __gnext, streamsize __n, char* __pbeg); }; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG inline _LIBCPP_INLINE_VISIBILITY strstreambuf::strstreambuf(strstreambuf&& __rhs) @@ -226,7 +226,7 @@ strstreambuf::operator=(strstreambuf&& __rhs) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG class _LIBCPP_TYPE_VIS istrstream : public istream @@ -245,7 +245,7 @@ public: istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY istrstream(istrstream&& __rhs) : istream(_VSTD::move(__rhs)), @@ -261,7 +261,7 @@ public: __sb_ = _VSTD::move(__rhs.__sb_); return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG virtual ~istrstream(); @@ -294,7 +294,7 @@ public: __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY ostrstream(ostrstream&& __rhs) : ostream(_VSTD::move(__rhs)), @@ -310,7 +310,7 @@ public: __sb_ = _VSTD::move(__rhs.__sb_); return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG virtual ~ostrstream(); @@ -354,7 +354,7 @@ public: __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY strstream(strstream&& __rhs) : iostream(_VSTD::move(__rhs)), @@ -370,7 +370,7 @@ public: __sb_ = _VSTD::move(__rhs.__sb_); return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG virtual ~strstream(); diff --git a/lib/libcxx/include/support/android/locale_bionic.h b/lib/libcxx/include/support/android/locale_bionic.h index 1365563ee48..482e2343358 100644 --- a/lib/libcxx/include/support/android/locale_bionic.h +++ b/lib/libcxx/include/support/android/locale_bionic.h @@ -11,7 +11,7 @@ #ifndef _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H #define _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H -#if defined(__ANDROID__) +#if defined(__BIONIC__) #ifdef __cplusplus extern "C" { @@ -27,5 +27,5 @@ extern "C" { #include <support/xlocale/__posix_l_fallback.h> #include <support/xlocale/__strtonum_fallback.h> -#endif // defined(__ANDROID__) +#endif // defined(__BIONIC__) #endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H diff --git a/lib/libcxx/include/support/fuchsia/xlocale.h b/lib/libcxx/include/support/fuchsia/xlocale.h new file mode 100644 index 00000000000..1de2fca28e2 --- /dev/null +++ b/lib/libcxx/include/support/fuchsia/xlocale.h @@ -0,0 +1,23 @@ +// -*- C++ -*- +//===------------------- support/fuchsia/xlocale.h ------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H +#define _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H + +#if defined(__Fuchsia__) + +#include <cstdlib> +#include <cwchar> +#include <support/xlocale/__posix_l_fallback.h> +#include <support/xlocale/__strtonum_fallback.h> + +#endif // defined(__Fuchsia__) + +#endif // _LIBCPP_SUPPORT_FUCHSIA_XLOCALE_H diff --git a/lib/libcxx/include/support/win32/limits_msvc_win32.h b/lib/libcxx/include/support/win32/limits_msvc_win32.h new file mode 100644 index 00000000000..1ab2e0b6dc1 --- /dev/null +++ b/lib/libcxx/include/support/win32/limits_msvc_win32.h @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===------------------ support/win32/limits_msvc_win32.h -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H +#define _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H + +#if !defined(_LIBCPP_MSVCRT) +#error "This header complements the Microsoft C Runtime library, and should not be included otherwise." +#endif +#if defined(__clang__) +#error "This header should only be included when using Microsofts C1XX frontend" +#endif + +#include <limits.h> // CHAR_BIT +#include <float.h> // limit constants +#include <math.h> // HUGE_VAL +#include <ymath.h> // internal MSVC header providing the needed functionality + +#define __CHAR_BIT__ CHAR_BIT + +#define __FLT_MANT_DIG__ FLT_MANT_DIG +#define __FLT_DIG__ FLT_DIG +#define __FLT_RADIX__ FLT_RADIX +#define __FLT_MIN_EXP__ FLT_MIN_EXP +#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP +#define __FLT_MAX_EXP__ FLT_MAX_EXP +#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP +#define __FLT_MIN__ FLT_MIN +#define __FLT_MAX__ FLT_MAX +#define __FLT_EPSILON__ FLT_EPSILON +// predefined by MinGW GCC +#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F + +#define __DBL_MANT_DIG__ DBL_MANT_DIG +#define __DBL_DIG__ DBL_DIG +#define __DBL_RADIX__ DBL_RADIX +#define __DBL_MIN_EXP__ DBL_MIN_EXP +#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP +#define __DBL_MAX_EXP__ DBL_MAX_EXP +#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP +#define __DBL_MIN__ DBL_MIN +#define __DBL_MAX__ DBL_MAX +#define __DBL_EPSILON__ DBL_EPSILON +// predefined by MinGW GCC +#define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L) + +#define __LDBL_MANT_DIG__ LDBL_MANT_DIG +#define __LDBL_DIG__ LDBL_DIG +#define __LDBL_RADIX__ LDBL_RADIX +#define __LDBL_MIN_EXP__ LDBL_MIN_EXP +#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP +#define __LDBL_MAX_EXP__ LDBL_MAX_EXP +#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP +#define __LDBL_MIN__ LDBL_MIN +#define __LDBL_MAX__ LDBL_MAX +#define __LDBL_EPSILON__ LDBL_EPSILON +// predefined by MinGW GCC +#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L + +// __builtin replacements/workarounds +#define __builtin_huge_vall() _LInf._Long_double +#define __builtin_nanl(__dummmy) _LNan._Long_double +#define __builtin_nansl(__dummy) _LSnan._Long_double + +#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H diff --git a/lib/libcxx/include/support/win32/locale_win32.h b/lib/libcxx/include/support/win32/locale_win32.h index 7f3710ecc18..aebfff22ecf 100644 --- a/lib/libcxx/include/support/win32/locale_win32.h +++ b/lib/libcxx/include/support/win32/locale_win32.h @@ -11,13 +11,96 @@ #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H -// ctype mask table defined in msvcrt.dll -extern "C" unsigned short __declspec(dllimport) _ctype[]; - -#include "support/win32/support.h" -#include "support/win32/locale_mgmt_win32.h" +#include <__config> #include <stdio.h> -#include <memory> +#include <xlocinfo.h> // _locale_t +#include <__nullptr> + +#define LC_COLLATE_MASK _M_COLLATE +#define LC_CTYPE_MASK _M_CTYPE +#define LC_MONETARY_MASK _M_MONETARY +#define LC_NUMERIC_MASK _M_NUMERIC +#define LC_TIME_MASK _M_TIME +#define LC_MESSAGES_MASK _M_MESSAGES +#define LC_ALL_MASK ( LC_COLLATE_MASK \ + | LC_CTYPE_MASK \ + | LC_MESSAGES_MASK \ + | LC_MONETARY_MASK \ + | LC_NUMERIC_MASK \ + | LC_TIME_MASK ) + +class locale_t { +public: + locale_t() + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(std::nullptr_t) + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(_locale_t __locale, const char* __locale_str) + : __locale(__locale), __locale_str(__locale_str) {} + + friend bool operator==(const locale_t& __left, const locale_t& __right) { + return __left.__locale == __right.__locale; + } + + friend bool operator==(const locale_t& __left, int __right) { + return __left.__locale == nullptr && __right == 0; + } + + friend bool operator==(const locale_t& __left, std::nullptr_t) { + return __left.__locale == nullptr; + } + + friend bool operator==(int __left, const locale_t& __right) { + return __left == 0 && nullptr == __right.__locale; + } + + friend bool operator==(std::nullptr_t, const locale_t& __right) { + return nullptr == __right.__locale; + } + + friend bool operator!=(const locale_t& __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, int __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { + return !(__left == __right); + } + + friend bool operator!=(int __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { + return !(__left == __right); + } + + operator bool() const { + return __locale != nullptr; + } + + const char* __get_locale() const { return __locale_str; } + + operator _locale_t() const { + return __locale; + } +private: + _locale_t __locale; + const char* __locale_str; +}; + +// Locale management functions +#define freelocale _free_locale +// FIXME: base currently unused. Needs manual work to construct the new locale +locale_t newlocale( int mask, const char * locale, locale_t base ); +// uselocale can't be implemented on Windows because Windows allows partial modification +// of thread-local locale and so _get_current_locale() returns a copy while uselocale does +// not create any copies. +// We can still implement raii even without uselocale though. + lconv *localeconv_l( locale_t loc ); size_t mbrlen_l( const char *__restrict s, size_t n, @@ -34,22 +117,21 @@ size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src, size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc); wint_t btowc_l( int c, locale_t loc ); int wctob_l( wint_t c, locale_t loc ); -typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; -typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; -inline _LIBCPP_ALWAYS_INLINE -decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) -{ - __locale_raii __current( uselocale(__l), uselocale ); - return MB_CUR_MAX; -} + +decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ); // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ #define mbtowc_l _mbtowc_l #define strtoll_l _strtoi64_l #define strtoull_l _strtoui64_l -// FIXME: current msvcrt does not know about long double -#define strtold_l _strtod_l - +#define strtod_l _strtod_l +#if defined(_LIBCPP_MSVCRT) +#define strtof_l _strtof_l +#define strtold_l _strtold_l +#else +float strtof_l(const char*, char**, locale_t); +long double strtold_l(const char*, char**, locale_t); +#endif inline _LIBCPP_INLINE_VISIBILITY int islower_l(int c, _locale_t loc) @@ -83,16 +165,18 @@ isupper_l(int c, _locale_t loc) #define iswxdigit_l _iswxdigit_l #define towupper_l _towupper_l #define towlower_l _towlower_l +#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 +#define strftime_l( __s, __l, __f, __tm, __loc ) strftime( __s, __l, __f, __tm ) +#else #define strftime_l _strftime_l +#endif #define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) -#define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) #define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ ) #define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ ) #define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) -int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...); -int asprintf_l( char **ret, locale_t loc, const char *format, ... ); -int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); - +_LIBCPP_FUNC_VIS int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...); +_LIBCPP_FUNC_VIS int asprintf_l( char **ret, locale_t loc, const char *format, ... ); +_LIBCPP_FUNC_VIS int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); // not-so-pressing FIXME: use locale to determine blank characters inline int isblank_l( int c, locale_t /*loc*/ ) @@ -104,10 +188,4 @@ inline int iswblank_l( wint_t c, locale_t /*loc*/ ) return ( c == L' ' || c == L'\t' ); } -#if defined(_LIBCPP_MSVCRT) -inline int isblank( int c, locale_t /*loc*/ ) -{ return ( c == ' ' || c == '\t' ); } -inline int iswblank( wint_t c, locale_t /*loc*/ ) -{ return ( c == L' ' || c == L'\t' ); } -#endif // _LIBCPP_MSVCRT #endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H diff --git a/lib/libcxx/include/support/xlocale/__posix_l_fallback.h b/lib/libcxx/include/support/xlocale/__posix_l_fallback.h index 8bf9567ffc2..c893a67313c 100644 --- a/lib/libcxx/include/support/xlocale/__posix_l_fallback.h +++ b/lib/libcxx/include/support/xlocale/__posix_l_fallback.h @@ -124,11 +124,11 @@ inline _LIBCPP_ALWAYS_INLINE int tolower_l(int c, locale_t) { return ::tolower(c); } -inline _LIBCPP_ALWAYS_INLINE int towupper_l(int c, locale_t) { +inline _LIBCPP_ALWAYS_INLINE wint_t towupper_l(wint_t c, locale_t) { return ::towupper(c); } -inline _LIBCPP_ALWAYS_INLINE int towlower_l(int c, locale_t) { +inline _LIBCPP_ALWAYS_INLINE wint_t towlower_l(wint_t c, locale_t) { return ::towlower(c); } diff --git a/lib/libcxx/include/system_error b/lib/libcxx/include/system_error index 134bb327403..c577edceee8 100644 --- a/lib/libcxx/include/system_error +++ b/lib/libcxx/include/system_error @@ -46,6 +46,12 @@ template <class T> struct is_error_code_enum template <class T> struct is_error_condition_enum : public false_type {}; +template <class _Tp> +inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17 + +template <class _Tp> +inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17 + class error_code { public: @@ -213,6 +219,7 @@ bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; template <> struct hash<std::error_code>; +template <> struct hash<std::error_condition>; } // std @@ -223,6 +230,7 @@ template <> struct hash<std::error_code>; #include <type_traits> #include <stdexcept> #include <__functional_base> +#include <string> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -233,15 +241,25 @@ _LIBCPP_BEGIN_NAMESPACE_STD // is_error_code_enum template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum +struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public false_type {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; +#endif + // is_error_condition_enum template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum : public false_type {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; +#endif + // Some error codes are not present on all platforms, so we provide equivalents // for them: @@ -346,12 +364,12 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc) _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc) template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc> +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> : true_type { }; #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS template <> -struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc::__lx> +struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> : true_type { }; #endif @@ -367,7 +385,8 @@ class _LIBCPP_TYPE_VIS error_category public: virtual ~error_category() _NOEXCEPT; -#ifdef _LIBCPP_BUILDING_SYSTEM_ERROR +#if defined(_LIBCPP_BUILDING_SYSTEM_ERROR) && \ + defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) error_category() _NOEXCEPT; #else _LIBCPP_ALWAYS_INLINE @@ -603,7 +622,7 @@ operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT {return !(__x == __y);} template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<error_code> +struct _LIBCPP_TEMPLATE_VIS hash<error_code> : public unary_function<error_code, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -613,6 +632,17 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<error_code> } }; +template <> +struct _LIBCPP_TEMPLATE_VIS hash<error_condition> + : public unary_function<error_condition, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(const error_condition& __ec) const _NOEXCEPT + { + return static_cast<size_t>(__ec.value()); + } +}; + // system_error class _LIBCPP_TYPE_VIS system_error @@ -635,7 +665,8 @@ private: static string __init(const error_code&, string); }; -_LIBCPP_FUNC_VIS void __throw_system_error(int ev, const char* what_arg); +_LIBCPP_NORETURN _LIBCPP_FUNC_VIS +void __throw_system_error(int ev, const char* what_arg); _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/thread b/lib/libcxx/include/thread index 022021c5add..1b8dca394aa 100644 --- a/lib/libcxx/include/thread +++ b/lib/libcxx/include/thread @@ -95,15 +95,19 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time); #include <system_error> #include <chrono> #include <__mutex_base> -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG #include <tuple> #endif #include <__threading_support> +#include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + #define __STDCPP_THREADS__ __cplusplus #ifdef _LIBCPP_HAS_NO_THREADS @@ -136,7 +140,7 @@ public: template <class _Tp> class __thread_specific_ptr { - __libcpp_tl_key __key_; + __libcpp_tls_key __key_; // Only __thread_local_data() may construct a __thread_specific_ptr // and only with _Tp == __thread_struct. @@ -147,24 +151,24 @@ class __thread_specific_ptr __thread_specific_ptr(const __thread_specific_ptr&); __thread_specific_ptr& operator=(const __thread_specific_ptr&); - static void __at_thread_exit(void*); + static void _LIBCPP_TLS_DESTRUCTOR_CC __at_thread_exit(void*); + public: typedef _Tp* pointer; ~__thread_specific_ptr(); _LIBCPP_INLINE_VISIBILITY - pointer get() const {return static_cast<_Tp*>(__libcpp_tl_get(__key_));} + pointer get() const {return static_cast<_Tp*>(__libcpp_tls_get(__key_));} _LIBCPP_INLINE_VISIBILITY pointer operator*() const {return *get();} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return get();} - pointer release(); - void reset(pointer __p = nullptr); + void set_pointer(pointer __p); }; template <class _Tp> -void +void _LIBCPP_TLS_DESTRUCTOR_CC __thread_specific_ptr<_Tp>::__at_thread_exit(void* __p) { delete static_cast<pointer>(__p); @@ -173,12 +177,10 @@ __thread_specific_ptr<_Tp>::__at_thread_exit(void* __p) template <class _Tp> __thread_specific_ptr<_Tp>::__thread_specific_ptr() { - int __ec = __libcpp_tl_create( - &__key_, - &__thread_specific_ptr::__at_thread_exit); - if (__ec) - __throw_system_error(__ec, - "__thread_specific_ptr construction failed"); + int __ec = + __libcpp_tls_create(&__key_, &__thread_specific_ptr::__at_thread_exit); + if (__ec) + __throw_system_error(__ec, "__thread_specific_ptr construction failed"); } template <class _Tp> @@ -191,21 +193,12 @@ __thread_specific_ptr<_Tp>::~__thread_specific_ptr() } template <class _Tp> -typename __thread_specific_ptr<_Tp>::pointer -__thread_specific_ptr<_Tp>::release() -{ - pointer __p = get(); - __libcpp_tl_set(__key_, nullptr); - return __p; -} - -template <class _Tp> void -__thread_specific_ptr<_Tp>::reset(pointer __p) +__thread_specific_ptr<_Tp>::set_pointer(pointer __p) { - pointer __p_old = get(); - __libcpp_tl_set(__key_, __p); - delete __p_old; + _LIBCPP_ASSERT(get() == nullptr, + "Attempting to overwrite thread local data"); + __libcpp_tls_set(__key_, __p); } class _LIBCPP_TYPE_VIS thread; @@ -220,7 +213,7 @@ _LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT; template<> struct hash<__thread_id>; -class _LIBCPP_TYPE_VIS_ONLY __thread_id +class _LIBCPP_TEMPLATE_VIS __thread_id { // FIXME: pthread_t is a pointer on Darwin but a long on Linux. // NULL is the no-thread value on Darwin. Someone needs to check @@ -263,15 +256,15 @@ private: friend __thread_id this_thread::get_id() _NOEXCEPT; friend class _LIBCPP_TYPE_VIS thread; - friend struct _LIBCPP_TYPE_VIS_ONLY hash<__thread_id>; + friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>; }; template<> -struct _LIBCPP_TYPE_VIS_ONLY hash<__thread_id> +struct _LIBCPP_TEMPLATE_VIS hash<__thread_id> : public unary_function<__thread_id, size_t> { _LIBCPP_INLINE_VISIBILITY - size_t operator()(__thread_id __v) const + size_t operator()(__thread_id __v) const _NOEXCEPT { return hash<__libcpp_thread_id>()(__v.__id_); } @@ -300,32 +293,35 @@ public: typedef __libcpp_thread_t native_handle_type; _LIBCPP_INLINE_VISIBILITY - thread() _NOEXCEPT : __t_(0) {} -#ifndef _LIBCPP_HAS_NO_VARIADICS + thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {} +#ifndef _LIBCPP_CXX03_LANG template <class _Fp, class ..._Args, class = typename enable_if < !is_same<typename decay<_Fp>::type, thread>::value >::type > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp&& __f, _Args&&... __args); -#else // _LIBCPP_HAS_NO_VARIADICS - template <class _Fp> explicit thread(_Fp __f); +#else // _LIBCPP_CXX03_LANG + template <class _Fp> + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + explicit thread(_Fp __f); #endif ~thread(); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = 0;} + thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = _LIBCPP_NULL_THREAD;} _LIBCPP_INLINE_VISIBILITY thread& operator=(thread&& __t) _NOEXCEPT; -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);} _LIBCPP_INLINE_VISIBILITY - bool joinable() const _NOEXCEPT {return __t_ != 0;} + bool joinable() const _NOEXCEPT {return !__libcpp_thread_isnull(&__t_);} void join(); void detach(); _LIBCPP_INLINE_VISIBILITY @@ -336,7 +332,7 @@ public: static unsigned hardware_concurrency() _NOEXCEPT; }; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class _TSp, class _Fp, class ..._Args, size_t ..._Indices> inline _LIBCPP_INLINE_VISIBILITY @@ -351,7 +347,7 @@ void* __thread_proxy(void* __vp) { // _Fp = std::tuple< unique_ptr<__thread_struct>, Functor, Args...> std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); - __thread_local_data().reset(_VSTD::get<0>(*__p).release()); + __thread_local_data().set_pointer(_VSTD::get<0>(*__p).release()); typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 2>::type _Index; __thread_execute(*__p, _Index()); return nullptr; @@ -376,7 +372,18 @@ thread::thread(_Fp&& __f, _Args&&... __args) __throw_system_error(__ec, "thread constructor failed"); } -#else // _LIBCPP_HAS_NO_VARIADICS +inline +thread& +thread::operator=(thread&& __t) _NOEXCEPT +{ + if (!__libcpp_thread_isnull(&__t_)) + terminate(); + __t_ = __t.__t_; + __t.__t_ = _LIBCPP_NULL_THREAD; + return *this; +} + +#else // _LIBCPP_CXX03_LANG template <class _Fp> struct __thread_invoke_pair { @@ -392,7 +399,7 @@ template <class _Fp> void* __thread_proxy_cxx03(void* __vp) { std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); - __thread_local_data().reset(__p->__tsp_.release()); + __thread_local_data().set_pointer(__p->__tsp_.release()); (__p->__fn_)(); return nullptr; } @@ -411,22 +418,7 @@ thread::thread(_Fp __f) __throw_system_error(__ec, "thread constructor failed"); } -#endif // _LIBCPP_HAS_NO_VARIADICS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - -inline -thread& -thread::operator=(thread&& __t) _NOEXCEPT -{ - if (__t_ != 0) - terminate(); - __t_ = __t.__t_; - __t.__t_ = 0; - return *this; -} - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG inline _LIBCPP_INLINE_VISIBILITY void swap(thread& __x, thread& __y) _NOEXCEPT {__x.swap(__y);} @@ -434,7 +426,7 @@ void swap(thread& __x, thread& __y) _NOEXCEPT {__x.swap(__y);} namespace this_thread { -_LIBCPP_FUNC_VIS void sleep_for(const chrono::nanoseconds& ns); +_LIBCPP_FUNC_VIS void sleep_for(const chrono::nanoseconds& __ns); template <class _Rep, class _Period> void @@ -487,4 +479,6 @@ _LIBCPP_END_NAMESPACE_STD #endif // !_LIBCPP_HAS_NO_THREADS +_LIBCPP_POP_MACROS + #endif // _LIBCPP_THREAD diff --git a/lib/libcxx/include/tuple b/lib/libcxx/include/tuple index 6805d8c7635..31578d1557a 100644 --- a/lib/libcxx/include/tuple +++ b/lib/libcxx/include/tuple @@ -70,7 +70,7 @@ public: void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); }; -const unspecified ignore; +inline constexpr unspecified ignore; template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 @@ -87,7 +87,7 @@ template <class T, class Tuple> template <class T> class tuple_size; // undefined template <class... T> class tuple_size<tuple<T...>>; template <class T> - constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 + inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 template <size_t I, class T> class tuple_element; // undefined template <size_t I, class... T> class tuple_element<I, tuple<T...>>; template <size_t I, class T> @@ -148,29 +148,8 @@ template <class... Types> _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG -// tuple_size - -template <class ..._Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_size<tuple<_Tp...> > - : public integral_constant<size_t, sizeof...(_Tp)> -{ -}; - -// tuple_element - -template <size_t _Ip, class ..._Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> > -{ -public: - typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; -}; - -#if _LIBCPP_STD_VER > 11 -template <size_t _Ip, class ..._Tp> -using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; -#endif // __tuple_leaf @@ -190,33 +169,47 @@ void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) template <size_t _Ip, class _Hp, bool> class __tuple_leaf { - _Hp value; + _Hp __value_; + + template <class _Tp> + static constexpr bool __can_bind_reference() { + using _RawTp = typename remove_reference<_Tp>::type; + using _RawHp = typename remove_reference<_Hp>::type; + using _CheckLValueArg = integral_constant<bool, + is_lvalue_reference<_Tp>::value + || is_same<_RawTp, reference_wrapper<_RawHp>>::value + || is_same<_RawTp, reference_wrapper<typename remove_const<_RawHp>::type>>::value + >; + return !is_reference<_Hp>::value + || (is_lvalue_reference<_Hp>::value && _CheckLValueArg::value) + || (is_rvalue_reference<_Hp>::value && !is_lvalue_reference<_Tp>::value); + } __tuple_leaf& operator=(const __tuple_leaf&); public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() - _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value() + _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_() {static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");} template <class _Alloc> _LIBCPP_INLINE_VISIBILITY __tuple_leaf(integral_constant<int, 0>, const _Alloc&) - : value() + : __value_() {static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");} template <class _Alloc> _LIBCPP_INLINE_VISIBILITY __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) - : value(allocator_arg_t(), __a) + : __value_(allocator_arg_t(), __a) {static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");} template <class _Alloc> _LIBCPP_INLINE_VISIBILITY __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) - : value(__a) + : __value_(__a) {static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple");} @@ -230,60 +223,30 @@ public: > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) - : value(_VSTD::forward<_Tp>(__t)) - {static_assert(!is_reference<_Hp>::value || - (is_lvalue_reference<_Hp>::value && - (is_lvalue_reference<_Tp>::value || - is_same<typename remove_reference<_Tp>::type, - reference_wrapper< - typename remove_reference<_Hp>::type - > - >::value)) || - (is_rvalue_reference<_Hp>::value && - !is_lvalue_reference<_Tp>::value), + : __value_(_VSTD::forward<_Tp>(__t)) + {static_assert(__can_bind_reference<_Tp>(), "Attempted to construct a reference element in a tuple with an rvalue");} template <class _Tp, class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) - : value(_VSTD::forward<_Tp>(__t)) - {static_assert(!is_lvalue_reference<_Hp>::value || - (is_lvalue_reference<_Hp>::value && - (is_lvalue_reference<_Tp>::value || - is_same<typename remove_reference<_Tp>::type, - reference_wrapper< - typename remove_reference<_Hp>::type - > - >::value)), + : __value_(_VSTD::forward<_Tp>(__t)) + {static_assert(__can_bind_reference<_Tp>(), "Attempted to construct a reference element in a tuple with an rvalue");} template <class _Tp, class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) - : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) - {static_assert(!is_lvalue_reference<_Hp>::value || - (is_lvalue_reference<_Hp>::value && - (is_lvalue_reference<_Tp>::value || - is_same<typename remove_reference<_Tp>::type, - reference_wrapper< - typename remove_reference<_Hp>::type - > - >::value)), - "Attempted to construct a reference element in a tuple with an rvalue");} + : __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) + {static_assert(!is_reference<_Hp>::value, + "Attempted to uses-allocator construct a reference element in a tuple");} template <class _Tp, class _Alloc> _LIBCPP_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) - : value(_VSTD::forward<_Tp>(__t), __a) - {static_assert(!is_lvalue_reference<_Hp>::value || - (is_lvalue_reference<_Hp>::value && - (is_lvalue_reference<_Tp>::value || - is_same<typename remove_reference<_Tp>::type, - reference_wrapper< - typename remove_reference<_Hp>::type - > - >::value)), - "Attempted to construct a reference element in a tuple with an rvalue");} + : __value_(_VSTD::forward<_Tp>(__t), __a) + {static_assert(!is_reference<_Hp>::value, + "Attempted to uses-allocator construct a reference element in a tuple");} __tuple_leaf(const __tuple_leaf& __t) = default; __tuple_leaf(__tuple_leaf&& __t) = default; @@ -293,7 +256,7 @@ public: __tuple_leaf& operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) { - value = _VSTD::forward<_Tp>(__t); + __value_ = _VSTD::forward<_Tp>(__t); return *this; } @@ -304,8 +267,8 @@ public: return 0; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;} }; template <size_t _Ip, class _Hp> @@ -403,7 +366,7 @@ struct __all_default_constructible<__tuple_types<_Tp...>> template<class _Indx, class ..._Tp> struct __tuple_impl; template<size_t ..._Indx, class ..._Tp> -struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> +struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... { _LIBCPP_INLINE_VISIBILITY @@ -505,34 +468,20 @@ struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> } }; -template <bool _IsTuple, class _SizeTrait, size_t _Expected> -struct __tuple_like_with_size_imp : false_type {}; - -template <class _SizeTrait, size_t _Expected> -struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected> - : integral_constant<bool, _SizeTrait::value == _Expected> {}; -template <class _Tuple, size_t _ExpectedSize, - class _RawTuple = typename __uncvref<_Tuple>::type> -using __tuple_like_with_size = __tuple_like_with_size_imp< - __tuple_like<_RawTuple>::value, - tuple_size<_RawTuple>, _ExpectedSize - >; - - -struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { - template <class ...> - static constexpr bool __enable_explicit() { return false; } - template <class ...> - static constexpr bool __enable_implicit() { return false; } -}; template <class ..._Tp> -class _LIBCPP_TYPE_VIS_ONLY tuple +class _LIBCPP_TEMPLATE_VIS tuple { - typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base; + typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT; + + _BaseT __base_; - base base_; +#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION) + static constexpr bool _EnableImplicitReducedArityExtension = true; +#else + static constexpr bool _EnableImplicitReducedArityExtension = false; +#endif template <class ..._Args> struct _PackExpandsToThisTuple : false_type {}; @@ -548,6 +497,11 @@ class _LIBCPP_TYPE_VIS_ONLY tuple struct _CheckArgsConstructor<true, _Dummy> { template <class ..._Args> + static constexpr bool __enable_default() { + return __all<is_default_constructible<_Args>::value...>::value; + } + + template <class ..._Args> static constexpr bool __enable_explicit() { return __tuple_constructible< @@ -657,12 +611,15 @@ class _LIBCPP_TYPE_VIS_ONLY tuple public: template <bool _Dummy = true, class = typename enable_if< - __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value + _CheckArgsConstructor<_Dummy>::template __enable_default<_Tp...>() >::type> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR tuple() _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} + tuple(tuple const&) = default; + tuple(tuple&&) = default; + template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if< __lazy_and< is_same<allocator_arg_t, _AllocArgT>, @@ -671,7 +628,7 @@ public: >::type> _LIBCPP_INLINE_VISIBILITY tuple(_AllocArgT, _Alloc const& __a) - : base_(allocator_arg_t(), __a, + : __base_(allocator_arg_t(), __a, __tuple_indices<>(), __tuple_types<>(), typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), __tuple_types<_Tp...>()) {} @@ -681,13 +638,13 @@ public: < _CheckArgsConstructor< _Dummy - >::template __enable_implicit<_Tp...>(), + >::template __enable_implicit<_Tp const&...>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) - : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), + : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), typename __make_tuple_indices<0>::type(), typename __make_tuple_types<tuple, 0>::type(), @@ -699,13 +656,13 @@ public: < _CheckArgsConstructor< _Dummy - >::template __enable_explicit<_Tp...>(), + >::template __enable_explicit<_Tp const&...>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) - : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), + : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), typename __make_tuple_indices<0>::type(), typename __make_tuple_types<tuple, 0>::type(), @@ -717,13 +674,13 @@ public: < _CheckArgsConstructor< _Dummy - >::template __enable_implicit<_Tp...>(), + >::template __enable_implicit<_Tp const&...>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) - : base_(allocator_arg_t(), __a, + : __base_(allocator_arg_t(), __a, typename __make_tuple_indices<sizeof...(_Tp)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), typename __make_tuple_indices<0>::type(), @@ -736,14 +693,14 @@ public: < _CheckArgsConstructor< _Dummy - >::template __enable_explicit<_Tp...>(), + >::template __enable_explicit<_Tp const&...>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) - : base_(allocator_arg_t(), __a, + : __base_(allocator_arg_t(), __a, typename __make_tuple_indices<sizeof...(_Tp)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), typename __make_tuple_indices<0>::type(), @@ -752,11 +709,17 @@ public: ) {} template <class ..._Up, + bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value, typename enable_if < _CheckArgsConstructor< - sizeof...(_Up) <= sizeof...(_Tp) - && !_PackExpandsToThisTuple<_Up...>::value + sizeof...(_Up) == sizeof...(_Tp) + && !_PackIsTuple + >::template __enable_implicit<_Up...>() || + _CheckArgsConstructor< + _EnableImplicitReducedArityExtension + && sizeof...(_Up) < sizeof...(_Tp) + && !_PackIsTuple >::template __enable_implicit<_Up...>(), bool >::type = false @@ -764,7 +727,7 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Up&&... __u) _NOEXCEPT_(( - is_nothrow_constructible<base, + is_nothrow_constructible<_BaseT, typename __make_tuple_indices<sizeof...(_Up)>::type, typename __make_tuple_types<tuple, sizeof...(_Up)>::type, typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, @@ -772,7 +735,7 @@ public: _Up... >::value )) - : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), + : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), @@ -784,7 +747,12 @@ public: _CheckArgsConstructor< sizeof...(_Up) <= sizeof...(_Tp) && !_PackExpandsToThisTuple<_Up...>::value - >::template __enable_explicit<_Up...>(), + >::template __enable_explicit<_Up...>() || + _CheckArgsConstructor< + !_EnableImplicitReducedArityExtension + && sizeof...(_Up) < sizeof...(_Tp) + && !_PackExpandsToThisTuple<_Up...>::value + >::template __enable_implicit<_Up...>(), bool >::type = false > @@ -792,7 +760,7 @@ public: explicit tuple(_Up&&... __u) _NOEXCEPT_(( - is_nothrow_constructible<base, + is_nothrow_constructible<_BaseT, typename __make_tuple_indices<sizeof...(_Up)>::type, typename __make_tuple_types<tuple, sizeof...(_Up)>::type, typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type, @@ -800,7 +768,7 @@ public: _Up... >::value )) - : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), + : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), @@ -818,7 +786,7 @@ public: > _LIBCPP_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) - : base_(allocator_arg_t(), __a, + : __base_(allocator_arg_t(), __a, typename __make_tuple_indices<sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), @@ -838,7 +806,7 @@ public: _LIBCPP_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) - : base_(allocator_arg_t(), __a, + : __base_(allocator_arg_t(), __a, typename __make_tuple_indices<sizeof...(_Up)>::type(), typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), @@ -856,8 +824,8 @@ public: >::type = false > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) - : base_(_VSTD::forward<_Tuple>(__t)) {} + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) + : __base_(_VSTD::forward<_Tuple>(__t)) {} template <class _Tuple, typename enable_if @@ -871,8 +839,8 @@ public: > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit - tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value)) - : base_(_VSTD::forward<_Tuple>(__t)) {} + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) + : __base_(_VSTD::forward<_Tuple>(__t)) {} template <class _Alloc, class _Tuple, typename enable_if @@ -885,7 +853,7 @@ public: > _LIBCPP_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) - : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} template <class _Alloc, class _Tuple, typename enable_if @@ -899,7 +867,26 @@ public: _LIBCPP_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) - : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + : __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + + using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>; + using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>; + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t) + _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value)) + { + __base_.operator=(__t.__base_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t) + _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value)) + { + __base_.operator=(static_cast<_BaseT&&>(__t.__base_)); + return *this; + } template <class _Tuple, class = typename enable_if @@ -909,19 +896,19 @@ public: > _LIBCPP_INLINE_VISIBILITY tuple& - operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value)) + operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value)) { - base_.operator=(_VSTD::forward<_Tuple>(__t)); + __base_.operator=(_VSTD::forward<_Tuple>(__t)); return *this; } _LIBCPP_INLINE_VISIBILITY void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) - {base_.swap(__t.base_);} + {__base_.swap(__t.__base_);} }; template <> -class _LIBCPP_TYPE_VIS_ONLY tuple<> +class _LIBCPP_TEMPLATE_VIS tuple<> { public: _LIBCPP_INLINE_VISIBILITY @@ -942,6 +929,16 @@ public: void swap(tuple&) _NOEXCEPT {} }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +// NOTE: These are not yet standardized, but are required to simulate the +// implicit deduction guide that should be generated had libc++ declared the +// tuple-like constructors "correctly" +template <class _Alloc, class ..._Args> +tuple(allocator_arg_t, const _Alloc&, tuple<_Args...> const&) -> tuple<_Args...>; +template <class _Alloc, class ..._Args> +tuple(allocator_arg_t, const _Alloc&, tuple<_Args...>&&) -> tuple<_Args...>; +#endif + template <class ..._Tp> inline _LIBCPP_INLINE_VISIBILITY typename enable_if @@ -961,7 +958,7 @@ typename tuple_element<_Ip, tuple<_Tp...> >::type& get(tuple<_Tp...>& __t) _NOEXCEPT { typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; - return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); + return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get(); } template <size_t _Ip, class ..._Tp> @@ -970,7 +967,7 @@ const typename tuple_element<_Ip, tuple<_Tp...> >::type& get(const tuple<_Tp...>& __t) _NOEXCEPT { typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; - return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get(); + return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get(); } template <size_t _Ip, class ..._Tp> @@ -980,7 +977,7 @@ get(tuple<_Tp...>&& __t) _NOEXCEPT { typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<type&&>( - static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get()); + static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get()); } template <size_t _Ip, class ..._Tp> @@ -990,7 +987,7 @@ get(const tuple<_Tp...>&& __t) _NOEXCEPT { typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<const type&&>( - static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get()); + static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get()); } #if _LIBCPP_STD_VER > 11 @@ -1015,10 +1012,10 @@ constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { template <class _T1, class ..._Args> struct __find_exactly_one_checked { - static constexpr bool __matches[] = {is_same<_T1, _Args>::value...}; + static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; static constexpr size_t value = __find_detail::__find_idx(0, __matches); - static_assert (value != __not_found, "type not found in type list" ); - static_assert(value != __ambiguous,"type occurs more than once in type list"); + static_assert(value != __not_found, "type not found in type list" ); + static_assert(value != __ambiguous, "type occurs more than once in type list"); }; template <class _T1> @@ -1077,11 +1074,13 @@ template <class _Up> struct __ignore_t { template <class _Tp> - _LIBCPP_INLINE_VISIBILITY - const __ignore_t& operator=(_Tp&&) const {return *this;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + const __ignore_t& operator=(_Tp&&) const {return *this;} }; -namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); } +namespace { + _LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); +} template <class _Tp> struct __make_tuple_return_impl @@ -1353,7 +1352,7 @@ tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) } template <class ..._Tp, class _Alloc> -struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<tuple<_Tp...>, _Alloc> +struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> : true_type {}; template <class _T1, class _T2> @@ -1367,11 +1366,9 @@ pair<_T1, _T2>::pair(piecewise_construct_t, { } -#endif // _LIBCPP_HAS_NO_VARIADICS - #if _LIBCPP_STD_VER > 14 template <class _Tp> -constexpr size_t tuple_size_v = tuple_size<_Tp>::value; +_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value; #define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } @@ -1413,6 +1410,8 @@ _LIBCPP_NOEXCEPT_RETURN( #endif // _LIBCPP_STD_VER > 14 +#endif // !defined(_LIBCPP_CXX03_LANG) + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_TUPLE diff --git a/lib/libcxx/include/type_traits b/lib/libcxx/include/type_traits index 821a73c764d..eb443ee0abd 100644 --- a/lib/libcxx/include/type_traits +++ b/lib/libcxx/include/type_traits @@ -97,6 +97,7 @@ namespace std template <class T> struct is_polymorphic; template <class T> struct is_abstract; template <class T> struct is_final; // C++14 + template <class T> struct is_aggregate; // C++17 template <class T, class... Args> struct is_constructible; template <class T> struct is_default_constructible; @@ -131,30 +132,32 @@ namespace std template <class T> struct has_virtual_destructor; + template<class T> struct has_unique_object_representations; // C++17 + // Relationships between types: template <class T, class U> struct is_same; template <class Base, class Derived> struct is_base_of; template <class From, class To> struct is_convertible; - template <class, class R = void> struct is_callable; // not defined - template <class Fn, class... ArgTypes, class R> - struct is_callable<Fn(ArgTypes...), R>; + template <class Fn, class... ArgTypes> struct is_invocable; + template <class R, class Fn, class... ArgTypes> struct is_invocable_r; - template <class, class R = void> struct is_nothrow_callable; // not defined - template <class Fn, class... ArgTypes, class R> - struct is_nothrow_callable<Fn(ArgTypes...), R>; + template <class Fn, class... ArgTypes> struct is_nothrow_invocable; + template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r; // Alignment properties and transformations: template <class T> struct alignment_of; template <size_t Len, size_t Align = most_stringent_alignment_requirement> struct aligned_storage; template <size_t Len, class... Types> struct aligned_union; + template <class T> struct remove_cvref; // C++20 template <class T> struct decay; template <class... T> struct common_type; template <class T> struct underlying_type; template <class> class result_of; // undefined template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; + template <class Fn, class... ArgTypes> struct invoke_result; // C++17 // const-volatile modifications: template <class T> @@ -202,6 +205,8 @@ namespace std template <std::size_t Len, class... Types> using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14 template <class T> + using remove_cvref_t = typename remove_cvref<T>::type; // C++20 + 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 @@ -211,174 +216,184 @@ namespace std 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 + template <class T> + using result_of_t = typename result_of<T>::type; // C++14 + template <class Fn, class... ArgTypes> + using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17 template <class...> using void_t = void; // C++17 // See C++14 20.10.4.1, primary type categories - template <class T> constexpr bool is_void_v + template <class T> inline constexpr bool is_void_v = is_void<T>::value; // C++17 - template <class T> constexpr bool is_null_pointer_v + template <class T> inline constexpr bool is_null_pointer_v = is_null_pointer<T>::value; // C++17 - template <class T> constexpr bool is_integral_v + template <class T> inline constexpr bool is_integral_v = is_integral<T>::value; // C++17 - template <class T> constexpr bool is_floating_point_v + template <class T> inline constexpr bool is_floating_point_v = is_floating_point<T>::value; // C++17 - template <class T> constexpr bool is_array_v + template <class T> inline constexpr bool is_array_v = is_array<T>::value; // C++17 - template <class T> constexpr bool is_pointer_v + template <class T> inline constexpr bool is_pointer_v = is_pointer<T>::value; // C++17 - template <class T> constexpr bool is_lvalue_reference_v + template <class T> inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value; // C++17 - template <class T> constexpr bool is_rvalue_reference_v + template <class T> inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value; // C++17 - template <class T> constexpr bool is_member_object_pointer_v + template <class T> inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::value; // C++17 - template <class T> constexpr bool is_member_function_pointer_v + template <class T> inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value; // C++17 - template <class T> constexpr bool is_enum_v + template <class T> inline constexpr bool is_enum_v = is_enum<T>::value; // C++17 - template <class T> constexpr bool is_union_v + template <class T> inline constexpr bool is_union_v = is_union<T>::value; // C++17 - template <class T> constexpr bool is_class_v + template <class T> inline constexpr bool is_class_v = is_class<T>::value; // C++17 - template <class T> constexpr bool is_function_v + template <class T> inline constexpr bool is_function_v = is_function<T>::value; // C++17 // See C++14 20.10.4.2, composite type categories - template <class T> constexpr bool is_reference_v + template <class T> inline constexpr bool is_reference_v = is_reference<T>::value; // C++17 - template <class T> constexpr bool is_arithmetic_v + template <class T> inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value; // C++17 - template <class T> constexpr bool is_fundamental_v + template <class T> inline constexpr bool is_fundamental_v = is_fundamental<T>::value; // C++17 - template <class T> constexpr bool is_object_v + template <class T> inline constexpr bool is_object_v = is_object<T>::value; // C++17 - template <class T> constexpr bool is_scalar_v + template <class T> inline constexpr bool is_scalar_v = is_scalar<T>::value; // C++17 - template <class T> constexpr bool is_compound_v + template <class T> inline constexpr bool is_compound_v = is_compound<T>::value; // C++17 - template <class T> constexpr bool is_member_pointer_v + template <class T> inline constexpr bool is_member_pointer_v = is_member_pointer<T>::value; // C++17 // See C++14 20.10.4.3, type properties - template <class T> constexpr bool is_const_v + template <class T> inline constexpr bool is_const_v = is_const<T>::value; // C++17 - template <class T> constexpr bool is_volatile_v + template <class T> inline constexpr bool is_volatile_v = is_volatile<T>::value; // C++17 - template <class T> constexpr bool is_trivial_v + template <class T> inline constexpr bool is_trivial_v = is_trivial<T>::value; // C++17 - template <class T> constexpr bool is_trivially_copyable_v + template <class T> inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value; // C++17 - template <class T> constexpr bool is_standard_layout_v + template <class T> inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value; // C++17 - template <class T> constexpr bool is_pod_v + template <class T> inline constexpr bool is_pod_v = is_pod<T>::value; // C++17 - template <class T> constexpr bool is_literal_type_v + template <class T> inline constexpr bool is_literal_type_v = is_literal_type<T>::value; // C++17 - template <class T> constexpr bool is_empty_v + template <class T> inline constexpr bool is_empty_v = is_empty<T>::value; // C++17 - template <class T> constexpr bool is_polymorphic_v + template <class T> inline constexpr bool is_polymorphic_v = is_polymorphic<T>::value; // C++17 - template <class T> constexpr bool is_abstract_v + template <class T> inline constexpr bool is_abstract_v = is_abstract<T>::value; // C++17 - template <class T> constexpr bool is_final_v + template <class T> inline constexpr bool is_final_v = is_final<T>::value; // C++17 - template <class T> constexpr bool is_signed_v + template <class T> inline constexpr bool is_aggregate_v + = is_aggregate<T>::value; // C++17 + template <class T> inline constexpr bool is_signed_v = is_signed<T>::value; // C++17 - template <class T> constexpr bool is_unsigned_v + template <class T> inline constexpr bool is_unsigned_v = is_unsigned<T>::value; // C++17 - template <class T, class... Args> constexpr bool is_constructible_v + template <class T, class... Args> inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value; // C++17 - template <class T> constexpr bool is_default_constructible_v + template <class T> inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value; // C++17 - template <class T> constexpr bool is_copy_constructible_v + template <class T> inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value; // C++17 - template <class T> constexpr bool is_move_constructible_v + template <class T> inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value; // C++17 - template <class T, class U> constexpr bool is_assignable_v + template <class T, class U> inline constexpr bool is_assignable_v = is_assignable<T, U>::value; // C++17 - template <class T> constexpr bool is_copy_assignable_v + template <class T> inline constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value; // C++17 - template <class T> constexpr bool is_move_assignable_v + template <class T> inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value; // C++17 - template <class T, class U> constexpr bool is_swappable_with_v + template <class T, class U> inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value; // C++17 - template <class T> constexpr bool is_swappable_v + template <class T> inline constexpr bool is_swappable_v = is_swappable<T>::value; // C++17 - template <class T> constexpr bool is_destructible_v + template <class T> inline constexpr bool is_destructible_v = is_destructible<T>::value; // C++17 - template <class T, class... Args> constexpr bool is_trivially_constructible_v + template <class T, class... Args> inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value; // C++17 - template <class T> constexpr bool is_trivially_default_constructible_v + template <class T> inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value; // C++17 - template <class T> constexpr bool is_trivially_copy_constructible_v + template <class T> inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value; // C++17 - template <class T> constexpr bool is_trivially_move_constructible_v + template <class T> inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value; // C++17 - template <class T, class U> constexpr bool is_trivially_assignable_v + template <class T, class U> inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value; // C++17 - template <class T> constexpr bool is_trivially_copy_assignable_v + template <class T> inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<T>::value; // C++17 - template <class T> constexpr bool is_trivially_move_assignable_v + template <class T> inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value; // C++17 - template <class T> constexpr bool is_trivially_destructible_v + template <class T> inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value; // C++17 - template <class T, class... Args> constexpr bool is_nothrow_constructible_v + template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value; // C++17 - template <class T> constexpr bool is_nothrow_default_constructible_v + template <class T> inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value; // C++17 - template <class T> constexpr bool is_nothrow_copy_constructible_v + template <class T> inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<T>::value; // C++17 - template <class T> constexpr bool is_nothrow_move_constructible_v + template <class T> inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value; // C++17 - template <class T, class U> constexpr bool is_nothrow_assignable_v + template <class T, class U> inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value; // C++17 - template <class T> constexpr bool is_nothrow_copy_assignable_v + template <class T> inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value; // C++17 - template <class T> constexpr bool is_nothrow_move_assignable_v + template <class T> inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value; // C++17 - template <class T, class U> constexpr bool is_nothrow_swappable_with_v + template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value; // C++17 - template <class T> constexpr bool is_nothrow_swappable_v + template <class T> inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value; // C++17 - template <class T> constexpr bool is_nothrow_destructible_v + template <class T> inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value; // C++17 - template <class T> constexpr bool has_virtual_destructor_v + template <class T> inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value; // C++17 + template<class T> inline constexpr bool has_unique_object_representations_v // C++17 + = has_unique_object_representations<T>::value; // See C++14 20.10.5, type property queries - template <class T> constexpr size_t alignment_of_v + template <class T> inline constexpr size_t alignment_of_v = alignment_of<T>::value; // C++17 - template <class T> constexpr size_t rank_v + template <class T> inline constexpr size_t rank_v = rank<T>::value; // C++17 - template <class T, unsigned I = 0> constexpr size_t extent_v + template <class T, unsigned I = 0> inline constexpr size_t extent_v = extent<T, I>::value; // C++17 // See C++14 20.10.6, type relations - template <class T, class U> constexpr bool is_same_v + template <class T, class U> inline constexpr bool is_same_v = is_same<T, U>::value; // C++17 - template <class Base, class Derived> constexpr bool is_base_of_v + template <class Base, class Derived> inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value; // C++17 - template <class From, class To> constexpr bool is_convertible_v + template <class From, class To> inline constexpr bool is_convertible_v = is_convertible<From, To>::value; // C++17 - template <class T, class R = void> constexpr bool is_callable_v - = is_callable<T, R>::value; // C++17 - template <class T, class R = void> constexpr bool is_nothrow_callable_v - = is_nothrow_callable<T, R>::value; // C++17 + template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v + = is_invocable<Fn, ArgTypes...>::value; // C++17 + template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v + = is_invocable_r<R, Fn, ArgTypes...>::value; // C++17 + template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v + = is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17 + template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v + = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17 // [meta.logical], logical operator traits: template<class... B> struct conjunction; // C++17 template<class... B> - constexpr bool conjunction_v = conjunction<B...>::value; // C++17 + inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17 template<class... B> struct disjunction; // C++17 template<class... B> - constexpr bool disjunction_v = disjunction<B...>::value; // C++17 + inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17 template<class B> struct negation; // C++17 template<class B> - constexpr bool negation_v = negation<B>::value; // C++17 + inline constexpr bool negation_v = negation<B>::value; // C++17 } @@ -392,9 +407,9 @@ namespace std _LIBCPP_BEGIN_NAMESPACE_STD -template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair; -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash; +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; template <class> struct __void_t { typedef void type; }; @@ -403,29 +418,29 @@ template <class _Tp> struct __identity { typedef _Tp type; }; template <class _Tp, bool> -struct _LIBCPP_TYPE_VIS_ONLY __dependent_type : public _Tp {}; +struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {}; template <bool _Bp, class _If, class _Then> - struct _LIBCPP_TYPE_VIS_ONLY conditional {typedef _If type;}; + struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;}; template <class _If, class _Then> - struct _LIBCPP_TYPE_VIS_ONLY conditional<false, _If, _Then> {typedef _Then type;}; + struct _LIBCPP_TEMPLATE_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> struct _LIBCPP_TYPE_VIS_ONLY __lazy_enable_if {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;}; +template <bool, class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;}; -template <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS_ONLY enable_if {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY enable_if<true, _Tp> {typedef _Tp type;}; +template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_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 // addressof -#if __has_builtin(__builtin_addressof) +#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF template <class _Tp> inline _LIBCPP_CONSTEXPR_AFTER_CXX14 @@ -443,10 +458,11 @@ inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY _Tp* addressof(_Tp& __x) _NOEXCEPT { - return (_Tp*)&reinterpret_cast<const volatile char&>(__x); + return reinterpret_cast<_Tp *>( + const_cast<char *>(&reinterpret_cast<const volatile char &>(__x))); } -#endif // __has_builtin(__builtin_addressof) +#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) // Objective-C++ Automatic Reference Counting uses qualified pointers @@ -488,12 +504,16 @@ addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT } #endif +#if !defined(_LIBCPP_CXX03_LANG) +template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete; +#endif + struct __two {char __lx[2];}; // helper class: template <class _Tp, _Tp __v> -struct _LIBCPP_TYPE_VIS_ONLY integral_constant +struct _LIBCPP_TEMPLATE_VIS integral_constant { static _LIBCPP_CONSTEXPR const _Tp value = __v; typedef _Tp value_type; @@ -520,7 +540,7 @@ using bool_constant = integral_constant<bool, __b>; typedef _LIBCPP_BOOL_CONSTANT(true) true_type; typedef _LIBCPP_BOOL_CONSTANT(false) false_type; -#if !defined(_LIBCPP_HAS_NO_VARIADICS) +#if !defined(_LIBCPP_CXX03_LANG) // __lazy_and @@ -595,47 +615,49 @@ struct __or_<_B0, _B1, _B2, _Bn...> template<class _Tp> struct __not_ : conditional<_Tp::value, false_type, true_type>::type {}; -#endif // !defined(_LIBCPP_HAS_NO_VARIADICS) +#endif // !defined(_LIBCPP_CXX03_LANG) // is_const -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const<_Tp const> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_const_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v = is_const<_Tp>::value; #endif // is_volatile -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile<_Tp volatile> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_volatile_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v = is_volatile<_Tp>::value; #endif // remove_const -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const<const _Tp> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_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_ONLY remove_volatile {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_volatile<volatile _Tp> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_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_ONLY remove_cv +template <class _Tp> struct _LIBCPP_TEMPLATE_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; @@ -646,11 +668,12 @@ template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type; template <class _Tp> struct __libcpp_is_void : public false_type {}; template <> struct __libcpp_is_void<void> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void : public __libcpp_is_void<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_void_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v = is_void<_Tp>::value; #endif @@ -659,15 +682,16 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_void_v template <class _Tp> struct __is_nullptr_t_impl : public false_type {}; template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __is_nullptr_t +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 11 -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_null_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_null_pointer_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v = is_null_pointer<_Tp>::value; #endif #endif @@ -697,11 +721,12 @@ template <> struct __libcpp_is_integral<__int128_t> : public tr template <> struct __libcpp_is_integral<__uint128_t> : public true_type {}; #endif -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_integral_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v = is_integral<_Tp>::value; #endif @@ -712,25 +737,27 @@ template <> struct __libcpp_is_floating_point<float> : public tru template <> struct __libcpp_is_floating_point<double> : public true_type {}; template <> struct __libcpp_is_floating_point<long double> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_floating_point +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_floating_point_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v = is_floating_point<_Tp>::value; #endif // is_array -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[]> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]> : public true_type {}; -template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[_Np]> +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]> : public true_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_array_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v = is_array<_Tp>::value; #endif @@ -739,57 +766,62 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_array_v template <class _Tp> struct __libcpp_is_pointer : public false_type {}; template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_pointer_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v = is_pointer<_Tp>::value; #endif // is_reference -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference<_Tp&> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {}; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference<_Tp&&> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {}; #endif -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {}; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_reference_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v = is_reference<_Tp>::value; -template <class _Tp> _LIBCPP_CONSTEXPR bool is_lvalue_reference_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value; -template <class _Tp> _LIBCPP_CONSTEXPR bool is_rvalue_reference_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value; #endif // is_union #if __has_feature(is_union) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union : public integral_constant<bool, __is_union(_Tp)> {}; #else template <class _Tp> struct __libcpp_union : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union : public __libcpp_union<typename remove_cv<_Tp>::type> {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_union_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v = is_union<_Tp>::value; #endif @@ -797,7 +829,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_union_v #if __has_feature(is_class) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class : public integral_constant<bool, __is_class(_Tp)> {}; #else @@ -808,23 +840,25 @@ template <class _Tp> char __test(int _Tp::*); template <class _Tp> __two __test(...); } -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_class_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v = is_class<_Tp>::value; #endif // is_same -template <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS_ONLY is_same : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_same<_Tp, _Tp> : public true_type {}; +template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, class _Up> _LIBCPP_CONSTEXPR bool is_same_v +template <class _Tp, class _Up> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v = is_same<_Tp, _Up>::value; #endif @@ -850,11 +884,12 @@ struct __libcpp_is_function {}; template <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_function +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function : public __libcpp_is_function<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_function_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v = is_function<_Tp>::value; #endif @@ -877,11 +912,12 @@ template <class _Ret, class _Class> struct __libcpp_is_member_function_pointer<_Ret _Class::*> : public is_function<_Ret> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_function_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type>::type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_function_pointer_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; #endif @@ -890,22 +926,24 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_function_pointer_v template <class _Tp> struct __libcpp_is_member_pointer : public false_type {}; template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_pointer_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v = is_member_pointer<_Tp>::value; #endif // is_member_object_pointer -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer : public integral_constant<bool, is_member_pointer<_Tp>::value && !is_member_function_pointer<_Tp>::value> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_object_pointer_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; #endif @@ -913,12 +951,12 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_object_pointer_v #if __has_feature(is_enum) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum : public integral_constant<bool, __is_enum(_Tp)> {}; #else -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum : public integral_constant<bool, !is_void<_Tp>::value && !is_integral<_Tp>::value && !is_floating_point<_Tp>::value && @@ -933,69 +971,75 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_enum_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v = is_enum<_Tp>::value; #endif // is_arithmetic -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_arithmetic +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic : public integral_constant<bool, is_integral<_Tp>::value || is_floating_point<_Tp>::value> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_arithmetic_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v = is_arithmetic<_Tp>::value; #endif // is_fundamental -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_fundamental +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental : public integral_constant<bool, is_void<_Tp>::value || __is_nullptr_t<_Tp>::value || is_arithmetic<_Tp>::value> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_fundamental_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v = is_fundamental<_Tp>::value; #endif // is_scalar -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_scalar +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar : public integral_constant<bool, is_arithmetic<_Tp>::value || is_member_pointer<_Tp>::value || is_pointer<_Tp>::value || __is_nullptr_t<_Tp>::value || is_enum<_Tp>::value > {}; -template <> struct _LIBCPP_TYPE_VIS_ONLY is_scalar<nullptr_t> : public true_type {}; +template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_scalar_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v = is_scalar<_Tp>::value; #endif // is_object -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_object +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object : public integral_constant<bool, is_scalar<_Tp>::value || is_array<_Tp>::value || is_union<_Tp>::value || is_class<_Tp>::value > {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_object_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v = is_object<_Tp>::value; #endif // is_compound -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_compound +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound : public integral_constant<bool, !is_fundamental<_Tp>::value> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_compound_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v = is_compound<_Tp>::value; #endif @@ -1022,7 +1066,7 @@ struct __add_const {typedef _Tp type;}; template <class _Tp> struct __add_const<_Tp, false> {typedef const _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_const +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {typedef typename __add_const<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1039,7 +1083,7 @@ struct __add_volatile {typedef _Tp type;}; template <class _Tp> struct __add_volatile<_Tp, false> {typedef volatile _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_volatile +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {typedef typename __add_volatile<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1048,7 +1092,7 @@ template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; // add_cv -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_cv +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1057,10 +1101,10 @@ template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type; // remove_reference -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _Tp type;}; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&&> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _Tp type;}; #endif #if _LIBCPP_STD_VER > 11 @@ -1072,7 +1116,7 @@ template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>:: template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _Tp type; }; template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _Tp& type; }; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference {typedef typename __add_lvalue_reference_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1084,7 +1128,7 @@ template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_referenc template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _Tp type; }; template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _Tp&& type; }; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference {typedef typename __add_rvalue_reference_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1122,12 +1166,28 @@ struct __unconstref { typedef typename remove_const<typename remove_reference<_Tp>::type>::type type; }; +#ifndef _LIBCPP_CXX03_LANG +template <class _Tp> +using __uncvref_t = typename __uncvref<_Tp>::type; +#endif + // __is_same_uncvref template <class _Tp, class _Up> struct __is_same_uncvref : is_same<typename __uncvref<_Tp>::type, typename __uncvref<_Up>::type> {}; +#if _LIBCPP_STD_VER > 17 +// aligned_union - same as __uncvref +template <class _Tp> +struct remove_cvref { + using type = remove_cv_t<remove_reference_t<_Tp>>; +}; + +template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type; +#endif + + struct __any { __any(...); @@ -1135,11 +1195,11 @@ struct __any // remove_pointer -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp*> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* volatile> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const volatile> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_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; @@ -1155,7 +1215,7 @@ struct __add_pointer_impl template <class _Tp> struct __add_pointer_impl<_Tp, false> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_pointer +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer {typedef typename __add_pointer_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1175,10 +1235,11 @@ struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {}; template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __libcpp_is_signed<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_signed_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v = is_signed<_Tp>::value; #endif @@ -1195,52 +1256,55 @@ struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {}; template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __libcpp_is_unsigned<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_unsigned_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v = is_unsigned<_Tp>::value; #endif // rank -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank : public integral_constant<size_t, 0> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[]> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]> : public integral_constant<size_t, rank<_Tp>::value + 1> {}; -template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[_Np]> +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR size_t rank_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v = rank<_Tp>::value; #endif // extent -template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS_ONLY extent +template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent : public integral_constant<size_t, 0> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], 0> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0> : public integral_constant<size_t, 0> {}; -template <class _Tp, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], _Ip> +template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {}; -template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], 0> +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0> : public integral_constant<size_t, _Np> {}; -template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], _Ip> +template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, unsigned _Ip = 0> _LIBCPP_CONSTEXPR size_t extent_v +template <class _Tp, unsigned _Ip = 0> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v = extent<_Tp, _Ip>::value; #endif // remove_extent -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[]> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]> {typedef _Tp type;}; -template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[_Np]> +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]> {typedef _Tp type;}; #if _LIBCPP_STD_VER > 11 @@ -1249,11 +1313,11 @@ template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type; // remove_all_extents -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[]> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]> {typedef typename remove_all_extents<_Tp>::type type;}; -template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[_Np]> +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]> {typedef typename remove_all_extents<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 @@ -1262,11 +1326,13 @@ template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_T // decay -template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY decay -{ -private: - typedef typename remove_reference<_Tp>::type _Up; +template <class _Up, bool> +struct __decay { + typedef typename remove_cv<_Up>::type type; +}; + +template <class _Up> +struct __decay<_Up, true> { public: typedef typename conditional < @@ -1281,56 +1347,71 @@ public: >::type type; }; +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS decay +{ +private: + typedef typename remove_reference<_Tp>::type _Up; +public: + typedef typename __decay<_Up, __is_referenceable<_Up>::value>::type type; +}; + #if _LIBCPP_STD_VER > 11 template <class _Tp> using decay_t = typename decay<_Tp>::type; #endif // is_abstract -namespace __is_abstract_imp -{ -template <class _Tp> char __test(_Tp (*)[1]); -template <class _Tp> __two __test(...); -} - -template <class _Tp, bool = is_class<_Tp>::value> -struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {}; - -template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {}; - -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_abstract<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract + : public integral_constant<bool, __is_abstract(_Tp)> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_abstract_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v = is_abstract<_Tp>::value; #endif // is_final #if defined(_LIBCPP_HAS_IS_FINAL) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {}; #else -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_final : public false_type {}; #endif #if defined(_LIBCPP_HAS_IS_FINAL) && _LIBCPP_STD_VER > 11 -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_final : public integral_constant<bool, __is_final(_Tp)> {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_final_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_final_v = is_final<_Tp>::value; #endif +// is_aggregate +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v + = is_aggregate<_Tp>::value; +#endif + +#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + // is_base_of #ifdef _LIBCPP_HAS_IS_BASE_OF template <class _Bp, class _Dp> -struct _LIBCPP_TYPE_VIS_ONLY is_base_of +struct _LIBCPP_TEMPLATE_VIS is_base_of : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {}; #else // _LIBCPP_HAS_IS_BASE_OF @@ -1354,14 +1435,15 @@ template <class _Bp, class _Dp> __two __test(...); } template <class _Bp, class _Dp> -struct _LIBCPP_TYPE_VIS_ONLY is_base_of +struct _LIBCPP_TEMPLATE_VIS is_base_of : public integral_constant<bool, is_class<_Bp>::value && sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {}; #endif // _LIBCPP_HAS_IS_BASE_OF #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Bp, class _Dp> _LIBCPP_CONSTEXPR bool is_base_of_v +template <class _Bp, class _Dp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v = is_base_of<_Bp, _Dp>::value; #endif @@ -1369,7 +1451,7 @@ template <class _Bp, class _Dp> _LIBCPP_CONSTEXPR bool is_base_of_v #if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) -template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible_to(_T1, _T2) && !is_abstract<_T2>::value> {}; @@ -1441,7 +1523,7 @@ template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {}; template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {}; -template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible +template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible : public __is_convertible<_T1, _T2> { static const size_t __complete_check1 = __is_convertible_check<_T1>::__v; @@ -1451,7 +1533,8 @@ template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible #endif // __has_feature(is_convertible_to) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _From, class _To> _LIBCPP_CONSTEXPR bool is_convertible_v +template <class _From, class _To> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v = is_convertible<_From, _To>::value; #endif @@ -1460,7 +1543,7 @@ template <class _From, class _To> _LIBCPP_CONSTEXPR bool is_convertible_v #if __has_feature(is_empty) || (_GNUC_VER >= 407) template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_empty +struct _LIBCPP_TEMPLATE_VIS is_empty : public integral_constant<bool, __is_empty(_Tp)> {}; #else // __has_feature(is_empty) @@ -1482,21 +1565,22 @@ struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_empty : public __libcpp_empty<_Tp> {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {}; #endif // __has_feature(is_empty) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_empty_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_empty_v = is_empty<_Tp>::value; #endif // is_polymorphic -#if __has_feature(is_polymorphic) || defined(_LIBCPP_MSVC) +#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC) template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic +struct _LIBCPP_TEMPLATE_VIS is_polymorphic : public integral_constant<bool, __is_polymorphic(_Tp)> {}; #else @@ -1506,13 +1590,14 @@ template<typename _Tp> char &__is_polymorphic_impl( int>::type); template<typename _Tp> __two &__is_polymorphic_impl(...); -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {}; #endif // __has_feature(is_polymorphic) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_polymorphic_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v = is_polymorphic<_Tp>::value; #endif @@ -1520,28 +1605,46 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_polymorphic_v #if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor : public integral_constant<bool, __has_virtual_destructor(_Tp)> {}; #else -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor : public false_type {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool has_virtual_destructor_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v = has_virtual_destructor<_Tp>::value; #endif +// has_unique_object_representations + +#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations + : public integral_constant<bool, + __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v + = has_unique_object_representations<_Tp>::value; +#endif + +#endif + // alignment_of -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY alignment_of +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of : public integral_constant<size_t, __alignof__(_Tp)> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR size_t alignment_of_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t alignment_of_v = alignment_of<_Tp>::value; #endif @@ -1556,7 +1659,7 @@ struct __type_list struct __nat { -#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#ifndef _LIBCPP_CXX03_LANG __nat() = delete; __nat(const __nat&) = delete; __nat& operator=(const __nat&) = delete; @@ -1630,7 +1733,7 @@ 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, size_t _Align = __find_max_align<__all_types, _Len>::value> -struct _LIBCPP_TYPE_VIS_ONLY aligned_storage +struct _LIBCPP_TEMPLATE_VIS aligned_storage { typedef typename __find_pod<__all_types, _Align>::type _Aligner; static_assert(!is_void<_Aligner>::value, ""); @@ -1648,7 +1751,7 @@ template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::valu #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \ template <size_t _Len>\ -struct _LIBCPP_TYPE_VIS_ONLY aligned_storage<_Len, n>\ +struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\ {\ struct _ALIGNAS(n) type\ {\ @@ -1670,10 +1773,10 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000); -// MSDN says that MSVC does not support alignment beyond 8192 (=0x2000) -#if !defined(_LIBCPP_MSVC) +// PE/COFF does not support alignment beyond 8192 (=0x2000) +#if !defined(_LIBCPP_OBJECT_FORMAT_COFF) _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); -#endif // !_LIBCPP_MSVC +#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF) #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION @@ -1903,7 +2006,7 @@ template <> struct __make_signed<__uint128_t, true> {typedef __int128_t t #endif template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY make_signed +struct _LIBCPP_TEMPLATE_VIS make_signed { typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type; }; @@ -1936,7 +2039,7 @@ template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_ #endif template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY make_unsigned +struct _LIBCPP_TEMPLATE_VIS make_unsigned { typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type; }; @@ -1948,21 +2051,28 @@ template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type; #ifdef _LIBCPP_HAS_NO_VARIADICS template <class _Tp, class _Up = void, class _Vp = void> -struct _LIBCPP_TYPE_VIS_ONLY common_type +struct _LIBCPP_TEMPLATE_VIS common_type { public: typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp>::type type; }; +template <> +struct _LIBCPP_TEMPLATE_VIS common_type<void, void, void> +{ +public: + typedef void type; +}; + template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, void, void> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, void, void> { public: - typedef typename decay<_Tp>::type type; + typedef typename common_type<_Tp, _Tp>::type type; }; template <class _Tp, class _Up> -struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, void> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, void> { typedef typename decay<decltype( true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() @@ -1974,23 +2084,21 @@ struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, void> // bullet 1 - sizeof...(Tp) == 0 template <class ..._Tp> -struct _LIBCPP_TYPE_VIS_ONLY common_type {}; +struct _LIBCPP_TEMPLATE_VIS common_type {}; // bullet 2 - sizeof...(Tp) == 1 template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp> -{ - typedef typename decay<_Tp>::type type; -}; +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp> + : public common_type<_Tp, _Tp> {}; // bullet 3 - sizeof...(Tp) == 2 template <class _Tp, class _Up, class = void> -struct __common_type2 {}; +struct __common_type2_imp {}; template <class _Tp, class _Up> -struct __common_type2<_Tp, _Up, +struct __common_type2_imp<_Tp, _Up, typename __void_t<decltype( true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() )>::type> @@ -2000,8 +2108,18 @@ struct __common_type2<_Tp, _Up, )>::type type; }; +template <class _Tp, class _Up, + class _DTp = typename decay<_Tp>::type, + class _DUp = typename decay<_Up>::type> +using __common_type2 = + typename conditional< + is_same<_Tp, _DTp>::value && is_same<_Up, _DUp>::value, + __common_type2_imp<_Tp, _Up>, + common_type<_DTp, _DUp> + >::type; + template <class _Tp, class _Up> -struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up> : __common_type2<_Tp, _Up> {}; // bullet 4 - sizeof...(Tp) > 2 @@ -2011,17 +2129,25 @@ template <class ...Tp> struct __common_types; template <class, class = void> struct __common_type_impl {}; +template <class _Tp, class _Up> +struct __common_type_impl< + __common_types<_Tp, _Up>, + typename __void_t<typename common_type<_Tp, _Up>::type>::type> +{ + typedef typename common_type<_Tp, _Up>::type type; +}; + template <class _Tp, class _Up, class ..._Vp> struct __common_type_impl<__common_types<_Tp, _Up, _Vp...>, typename __void_t<typename common_type<_Tp, _Up>::type>::type> + : __common_type_impl< + __common_types<typename common_type<_Tp, _Up>::type, _Vp...> > { - typedef typename common_type< - typename common_type<_Tp, _Up>::type, _Vp... - >::type type; + }; template <class _Tp, class _Up, class ..._Vp> -struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, _Vp...> +struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, _Vp...> : __common_type_impl<__common_types<_Tp, _Up, _Vp...> > {}; #if _LIBCPP_STD_VER > 11 @@ -2036,26 +2162,15 @@ template<typename, typename _Tp> struct __select_2nd { typedef _Tp type; }; template <class _Tp, class _Arg> typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -__is_assignable_test(_Tp&&, _Arg&&); -#else -__is_assignable_test(_Tp, _Arg&); -#endif +__is_assignable_test(int); + +template <class, class> +false_type __is_assignable_test(...); -template <class _Arg> -false_type -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -__is_assignable_test(__any, _Arg&&); -#else -__is_assignable_test(__any, _Arg&); -#endif template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value> struct __is_assignable_imp - : public common_type - < - decltype(_VSTD::__is_assignable_test(declval<_Tp>(), declval<_Arg>())) - >::type {}; + : public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {}; template <class _Tp, class _Arg> struct __is_assignable_imp<_Tp, _Arg, true> @@ -2068,33 +2183,36 @@ struct is_assignable : public __is_assignable_imp<_Tp, _Arg> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_assignable_v +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v = is_assignable<_Tp, _Arg>::value; #endif // is_copy_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable : public is_assignable<typename add_lvalue_reference<_Tp>::type, typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v = is_copy_assignable<_Tp>::value; #endif // is_move_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_move_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_assignable<typename add_lvalue_reference<_Tp>::type, - const typename add_rvalue_reference<_Tp>::type> {}; + typename add_rvalue_reference<_Tp>::type> {}; #else : public is_copy_assignable<_Tp> {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v = is_move_assignable<_Tp>::value; #endif @@ -2157,7 +2275,8 @@ struct is_destructible<void> : public _VSTD::false_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_destructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v = is_destructible<_Tp>::value; #endif @@ -2166,7 +2285,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_destructible_v #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename remove_reference<_Tp>::type&& move(_Tp&& __t) _NOEXCEPT { @@ -2175,7 +2294,7 @@ move(_Tp&& __t) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&& forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT { @@ -2183,12 +2302,12 @@ forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&& forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT { static_assert(!is_lvalue_reference<_Tp>::value, - "Can not forward an rvalue as an lvalue."); + "can not forward an rvalue as an lvalue"); return static_cast<_Tp&&>(__t); } @@ -2852,7 +2971,7 @@ class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true> // _Fn must be member p // result_of template <class _Fn> -class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn()> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn()> : public __result_of<_Fn(), is_class<typename remove_reference<_Fn>::type>::value || is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, @@ -2862,7 +2981,7 @@ class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn()> }; template <class _Fn, class _A0> -class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0)> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0)> : public __result_of<_Fn(_A0), is_class<typename remove_reference<_Fn>::type>::value || is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, @@ -2872,7 +2991,7 @@ class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0)> }; template <class _Fn, class _A0, class _A1> -class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1)> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1)> : public __result_of<_Fn(_A0, _A1), is_class<typename remove_reference<_Fn>::type>::value || is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, @@ -2882,7 +3001,7 @@ class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1)> }; template <class _Fn, class _A0, class _A1, class _A2> -class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1, _A2)> +class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1, _A2)> : public __result_of<_Fn(_A0, _A1, _A2), is_class<typename remove_reference<_Fn>::type>::value || is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value, @@ -2900,135 +3019,132 @@ namespace __is_construct struct __nat {}; } -#if __has_feature(is_constructible) - -template <class _Tp, class ..._Args> -struct _LIBCPP_TYPE_VIS_ONLY is_constructible - : public integral_constant<bool, __is_constructible(_Tp, _Args...)> - {}; - -#else - -#ifndef _LIBCPP_HAS_NO_VARIADICS - -// main is_constructible test - -template <class _Tp, class ..._Args> -typename __select_2nd<decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...))), true_type>::type -__is_constructible_test(_Tp&&, _Args&& ...); +#if !defined(_LIBCPP_CXX03_LANG) && (!__has_feature(is_constructible) || \ + defined(_LIBCPP_TESTING_FALLBACK_IS_CONSTRUCTIBLE)) -template <class ..._Args> -false_type -__is_constructible_test(__any, _Args&& ...); +template <class _Tp, class... _Args> +struct __libcpp_is_constructible; + +template <class _To, class _From> +struct __is_invalid_base_to_derived_cast { + static_assert(is_reference<_To>::value, "Wrong specialization"); + using _RawFrom = __uncvref_t<_From>; + using _RawTo = __uncvref_t<_To>; + static const bool value = __lazy_and< + __lazy_not<is_same<_RawFrom, _RawTo>>, + is_base_of<_RawFrom, _RawTo>, + __lazy_not<__libcpp_is_constructible<_RawTo, _From>> + >::value; +}; + +template <class _To, class _From> +struct __is_invalid_lvalue_to_rvalue_cast : false_type { + static_assert(is_reference<_To>::value, "Wrong specialization"); +}; + +template <class _ToRef, class _FromRef> +struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> { + using _RawFrom = __uncvref_t<_FromRef>; + using _RawTo = __uncvref_t<_ToRef>; + static const bool value = __lazy_and< + __lazy_not<is_function<_RawTo>>, + __lazy_or< + is_same<_RawFrom, _RawTo>, + is_base_of<_RawTo, _RawFrom>> + >::value; +}; + +struct __is_constructible_helper +{ + template <class _To> + static void __eat(_To); + + // This overload is needed to work around a Clang bug that disallows + // static_cast<T&&>(e) for non-reference-compatible types. + // Example: static_cast<int&&>(declval<double>()); + // NOTE: The static_cast implementation below is required to support + // classes with explicit conversion operators. + template <class _To, class _From, + class = decltype(__eat<_To>(_VSTD::declval<_From>()))> + static true_type __test_cast(int); + + template <class _To, class _From, + class = decltype(static_cast<_To>(_VSTD::declval<_From>()))> + static integral_constant<bool, + !__is_invalid_base_to_derived_cast<_To, _From>::value && + !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value + > __test_cast(long); -template <bool, class _Tp, class... _Args> -struct __libcpp_is_constructible // false, _Tp is not a scalar - : public common_type - < - decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...)) - >::type - {}; + template <class, class> + static false_type __test_cast(...); -// function types are not constructible + template <class _Tp, class ..._Args, + class = decltype(_Tp(_VSTD::declval<_Args>()...))> + static true_type __test_nary(int); + template <class _Tp, class...> + static false_type __test_nary(...); -template <class _Rp, class... _A1, class... _A2> -struct __libcpp_is_constructible<false, _Rp(_A1...), _A2...> - : public false_type - {}; - -// handle scalars and reference types + template <class _Tp, class _A0, class = decltype(::new _Tp(_VSTD::declval<_A0>()))> + static is_destructible<_Tp> __test_unary(int); + template <class, class> + static false_type __test_unary(...); +}; -// Scalars are default constructible, references are not +template <class _Tp, bool = is_void<_Tp>::value> +struct __is_default_constructible + : decltype(__is_constructible_helper::__test_nary<_Tp>(0)) +{}; template <class _Tp> -struct __libcpp_is_constructible<true, _Tp> - : public is_scalar<_Tp> - {}; - -// Scalars and references are constructible from one arg if that arg is -// implicitly convertible to the scalar or reference. +struct __is_default_constructible<_Tp, true> : false_type {}; template <class _Tp> -struct __is_constructible_ref -{ - true_type static __lxx(_Tp); - false_type static __lxx(...); -}; - -template <class _Tp, class _A0> -struct __libcpp_is_constructible<true, _Tp, _A0> - : public common_type - < - decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>())) - >::type - {}; - -// Scalars and references are not constructible from multiple args. - -template <class _Tp, class _A0, class ..._Args> -struct __libcpp_is_constructible<true, _Tp, _A0, _Args...> - : public false_type - {}; - -// Treat scalars and reference types separately - -template <bool, class _Tp, class... _Args> -struct __is_constructible_void_check - : public __libcpp_is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value, - _Tp, _Args...> - {}; +struct __is_default_constructible<_Tp[], false> : false_type {}; -// If any of T or Args is void, is_constructible should be false +template <class _Tp, size_t _Nx> +struct __is_default_constructible<_Tp[_Nx], false> + : __is_default_constructible<typename remove_all_extents<_Tp>::type> {}; template <class _Tp, class... _Args> -struct __is_constructible_void_check<true, _Tp, _Args...> - : public false_type - {}; - -template <class ..._Args> struct __contains_void; - -template <> struct __contains_void<> : false_type {}; - -template <class _A0, class ..._Args> -struct __contains_void<_A0, _Args...> +struct __libcpp_is_constructible { - static const bool value = is_void<_A0>::value || - __contains_void<_Args...>::value; + static_assert(sizeof...(_Args) > 1, "Wrong specialization"); + typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0)) + type; }; -// is_constructible entry point - -template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_constructible - : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value - || is_abstract<_Tp>::value, - _Tp, _Args...> - {}; - -// Array types are default constructible if their element type -// is default constructible +template <class _Tp> +struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {}; -template <class _Ap, size_t _Np> -struct __libcpp_is_constructible<false, _Ap[_Np]> - : public is_constructible<typename remove_all_extents<_Ap>::type> - {}; +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp, _A0> + : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0)) +{}; -// Otherwise array types are not constructible by this syntax +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp&, _A0> + : public decltype(__is_constructible_helper:: + __test_cast<_Tp&, _A0>(0)) +{}; -template <class _Ap, size_t _Np, class ..._Args> -struct __libcpp_is_constructible<false, _Ap[_Np], _Args...> - : public false_type - {}; +template <class _Tp, class _A0> +struct __libcpp_is_constructible<_Tp&&, _A0> + : public decltype(__is_constructible_helper:: + __test_cast<_Tp&&, _A0>(0)) +{}; -// Incomplete array types are not constructible +#endif -template <class _Ap, class ..._Args> -struct __libcpp_is_constructible<false, _Ap[], _Args...> - : public false_type +#if __has_feature(is_constructible) +template <class _Tp, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {}; - -#else // _LIBCPP_HAS_NO_VARIADICS - +#elif !defined(_LIBCPP_CXX03_LANG) +template <class _Tp, class... _Args> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public __libcpp_is_constructible<_Tp, _Args...>::type {}; +#else // template <class T> struct is_constructible0; // main is_constructible0 test @@ -3056,6 +3172,14 @@ template <class _A0, class _A1> false_type __is_constructible2_test(__any, _A0&, _A1&); +template <class _Tp, class _A0, class _A1, class _A2> +decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), _VSTD::declval<_A2>()), true_type())) +__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&); + +template <class _A0, class _A1, class _A2> +false_type +__is_constructible3_test(__any, _A0&, _A1&, _A2&); + template <bool, class _Tp> struct __is_constructible0_imp // false, _Tp is not a scalar : public common_type @@ -3080,6 +3204,14 @@ struct __is_constructible2_imp // false, _Tp is not a scalar >::type {}; +template <bool, class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_imp // false, _Tp is not a scalar + : public common_type + < + decltype(__is_constructible3_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>(), declval<_A2>())) + >::type + {}; + // handle scalars and reference types // Scalars are default constructible, references are not @@ -3099,6 +3231,11 @@ struct __is_constructible2_imp<true, _Tp, _A0, _A1> : public false_type {}; +template <class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<true, _Tp, _A0, _A1, _A2> + : public false_type + {}; + // Treat scalars and reference types separately template <bool, class _Tp> @@ -3119,6 +3256,12 @@ struct __is_constructible2_void_check _Tp, _A0, _A1> {}; +template <bool, class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_void_check + : public __is_constructible3_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, + _Tp, _A0, _A1, _A2> + {}; + // If any of T or Args is void, is_constructible should be false template <class _Tp> @@ -3136,21 +3279,28 @@ struct __is_constructible2_void_check<true, _Tp, _A0, _A1> : public false_type {}; +template <class _Tp, class _A0, class _A1, class _A2> +struct __is_constructible3_void_check<true, _Tp, _A0, _A1, _A2> + : public false_type + {}; + // is_constructible entry point template <class _Tp, class _A0 = __is_construct::__nat, - class _A1 = __is_construct::__nat> -struct _LIBCPP_TYPE_VIS_ONLY is_constructible - : public __is_constructible2_void_check<is_void<_Tp>::value + class _A1 = __is_construct::__nat, + class _A2 = __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_constructible + : public __is_constructible3_void_check<is_void<_Tp>::value || is_abstract<_Tp>::value || is_function<_Tp>::value || is_void<_A0>::value - || is_void<_A1>::value, - _Tp, _A0, _A1> + || is_void<_A1>::value + || is_void<_A2>::value, + _Tp, _A0, _A1, _A2> {}; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> : public __is_constructible0_void_check<is_void<_Tp>::value || is_abstract<_Tp>::value || is_function<_Tp>::value, @@ -3158,7 +3308,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, __is_construct::__nat, __is_c {}; template <class _Tp, class _A0> -struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, _A0, __is_construct::__nat> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, __is_construct::__nat> : public __is_constructible1_void_check<is_void<_Tp>::value || is_abstract<_Tp>::value || is_function<_Tp>::value @@ -3166,6 +3316,16 @@ struct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, _A0, __is_construct::__nat> _Tp, _A0> {}; +template <class _Tp, class _A0, class _A1> +struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, _A1, __is_construct::__nat> + : public __is_constructible2_void_check<is_void<_Tp>::value + || is_abstract<_Tp>::value + || is_function<_Tp>::value + || is_void<_A0>::value + || is_void<_A1>::value, + _Tp, _A0, _A1> + {}; + // Array types are default constructible if their element type // is default constructible @@ -3184,6 +3344,11 @@ struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1> : public false_type {}; +template <class _Ap, size_t _Np, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<false, _Ap[_Np], _A0, _A1, _A2> + : public false_type + {}; + // Incomplete array types are not constructible template <class _Ap> @@ -3201,42 +3366,50 @@ struct __is_constructible2_imp<false, _Ap[], _A0, _A1> : public false_type {}; -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // __has_feature(is_constructible) +template <class _Ap, class _A0, class _A1, class _A2> +struct __is_constructible3_imp<false, _Ap[], _A0, _A1, _A2> + : public false_type + {}; + +#endif // __has_feature(is_constructible) + #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) -template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_constructible_v +template <class _Tp, class ..._Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v = is_constructible<_Tp, _Args...>::value; #endif // is_default_constructible template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_default_constructible +struct _LIBCPP_TEMPLATE_VIS is_default_constructible : public is_constructible<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_default_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v = is_default_constructible<_Tp>::value; #endif // is_copy_constructible template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible +struct _LIBCPP_TEMPLATE_VIS is_copy_constructible : public is_constructible<_Tp, typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v = is_copy_constructible<_Tp>::value; #endif // is_move_constructible template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_move_constructible +struct _LIBCPP_TEMPLATE_VIS is_move_constructible #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> #else @@ -3245,7 +3418,8 @@ struct _LIBCPP_TYPE_VIS_ONLY is_move_constructible {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v = is_move_constructible<_Tp>::value; #endif @@ -3256,7 +3430,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_constructible_v #if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)> { }; @@ -3264,13 +3438,13 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible #else // !__has_feature(is_trivially_constructible) template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible : false_type { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp> #if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403) : integral_constant<bool, __has_trivial_constructor(_Tp)> #else @@ -3281,22 +3455,22 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp> template <class _Tp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&&> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&> #else -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp> #endif : integral_constant<bool, is_scalar<_Tp>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&> : integral_constant<bool, is_scalar<_Tp>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&> : integral_constant<bool, is_scalar<_Tp>::value> { }; @@ -3307,7 +3481,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&> template <class _Tp, class _A0 = __is_construct::__nat, class _A1 = __is_construct::__nat> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible : false_type { }; @@ -3315,28 +3489,28 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible #if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> : integral_constant<bool, __is_trivially_constructible(_Tp)> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, __is_construct::__nat> : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, __is_construct::__nat> : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, __is_construct::__nat> : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)> { @@ -3345,28 +3519,28 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&, #else // !__has_feature(is_trivially_constructible) template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> : integral_constant<bool, is_scalar<_Tp>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, __is_construct::__nat> : integral_constant<bool, is_scalar<_Tp>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, __is_construct::__nat> : integral_constant<bool, is_scalar<_Tp>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, __is_construct::__nat> : integral_constant<bool, is_scalar<_Tp>::value> { @@ -3377,35 +3551,38 @@ struct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&, #endif // _LIBCPP_HAS_NO_VARIADICS #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) -template <class _Tp, class... _Args> _LIBCPP_CONSTEXPR bool is_trivially_constructible_v +template <class _Tp, class... _Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value; #endif // is_trivially_default_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_default_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible : public is_trivially_constructible<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v = is_trivially_default_constructible<_Tp>::value; #endif // is_trivially_copy_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value; #endif // is_trivially_move_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> #else @@ -3414,7 +3591,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructibl {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value; #endif @@ -3457,24 +3635,26 @@ struct is_trivially_assignable<_Tp&, _Tp&&> #endif // !__has_feature(is_trivially_assignable) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_trivially_assignable_v +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v = is_trivially_assignable<_Tp, _Arg>::value; #endif // is_trivially_copy_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value; #endif // is_trivially_move_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename add_rvalue_reference<_Tp>::type> @@ -3484,7 +3664,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value; #endif @@ -3492,7 +3673,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v #if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {}; #else @@ -3501,16 +3682,17 @@ template <class _Tp> struct __libcpp_trivial_destructor : public integral_constant<bool, is_scalar<_Tp>::value || is_reference<_Tp>::value> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible<_Tp[]> +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]> : public false_type {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_destructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value; #endif @@ -3518,7 +3700,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_destructible_v #if 0 template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))> { }; @@ -3553,13 +3735,13 @@ struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference }; template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...> { }; template <class _Tp, size_t _Ns> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp[_Ns]> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]> : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp> { }; @@ -3567,13 +3749,13 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp[_Ns]> #else // __has_feature(cxx_noexcept) template <class _Tp, class... _Args> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible : false_type { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp> #if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_constructor(_Tp)> #else @@ -3584,9 +3766,9 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp> template <class _Tp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&&> #else -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp> #endif #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> @@ -3597,7 +3779,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp> }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&> #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> #else @@ -3607,7 +3789,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&> }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&> #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> #else @@ -3622,13 +3804,13 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&> template <class _Tp, class _A0 = __is_construct::__nat, class _A1 = __is_construct::__nat> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible : false_type { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat, +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> #if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_constructor(_Tp)> @@ -3639,7 +3821,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp, +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp, __is_construct::__nat> #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> @@ -3650,7 +3832,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp, }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&, __is_construct::__nat> #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> @@ -3661,7 +3843,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&, }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&, +struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&, __is_construct::__nat> #if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_copy(_Tp)> @@ -3675,35 +3857,38 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&, #endif // __has_feature(is_nothrow_constructible) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) -template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v +template <class _Tp, class ..._Args> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value; #endif // is_nothrow_default_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible : public is_nothrow_constructible<_Tp> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value; #endif // is_nothrow_copy_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible : public is_nothrow_constructible<_Tp, typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value; #endif // is_nothrow_move_constructible -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> #else @@ -3712,7 +3897,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value; #endif @@ -3735,7 +3921,7 @@ struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg> }; template <class _Tp, class _Arg> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg> { }; @@ -3743,11 +3929,11 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable #else // __has_feature(cxx_noexcept) template <class _Tp, class _Arg> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable : public false_type {}; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp> #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; #else @@ -3755,7 +3941,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp> #endif template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp&> #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; #else @@ -3763,7 +3949,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&> #endif template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, const _Tp&> #if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; #else @@ -3785,24 +3971,26 @@ struct is_nothrow_assignable<_Tp&, _Tp&&> #endif // __has_feature(cxx_noexcept) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v +template <class _Tp, class _Arg> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value; #endif // is_nothrow_copy_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value; #endif // is_nothrow_move_assignable -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename add_rvalue_reference<_Tp>::type> @@ -3812,7 +4000,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value; #endif @@ -3835,19 +4024,19 @@ struct __libcpp_is_nothrow_destructible<true, _Tp> }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp> { }; template <class _Tp, size_t _Ns> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp[_Ns]> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]> : public is_nothrow_destructible<_Tp> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&> : public true_type { }; @@ -3855,7 +4044,7 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&&> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> : public true_type { }; @@ -3868,17 +4057,18 @@ template <class _Tp> struct __libcpp_nothrow_destructor : public integral_constant<bool, is_scalar<_Tp>::value || is_reference<_Tp>::value> {}; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {}; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp[]> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]> : public false_type {}; #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value; #endif @@ -3886,12 +4076,12 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v #if __has_feature(is_pod) || (_GNUC_VER >= 403) -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod : public integral_constant<bool, __is_pod(_Tp)> {}; #else -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value && is_trivially_copy_constructible<_Tp>::value && is_trivially_copy_assignable<_Tp>::value && @@ -3900,13 +4090,14 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_pod_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v = is_pod<_Tp>::value; #endif // is_literal_type; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type #ifdef _LIBCPP_IS_LITERAL : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)> #else @@ -3916,13 +4107,14 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_literal_type_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v = is_literal_type<_Tp>::value; #endif // is_standard_layout; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout #if __has_feature(is_standard_layout) || (_GNUC_VER >= 407) : public integral_constant<bool, __is_standard_layout(_Tp)> #else @@ -3931,13 +4123,14 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_standard_layout_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v = is_standard_layout<_Tp>::value; #endif // is_trivially_copyable; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable #if __has_feature(is_trivially_copyable) : public integral_constant<bool, __is_trivially_copyable(_Tp)> #elif _GNUC_VER >= 501 @@ -3948,13 +4141,14 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copyable_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value; #endif // is_trivial; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial #if __has_feature(is_trivial) || _GNUC_VER >= 407 : public integral_constant<bool, __is_trivial(_Tp)> #else @@ -3964,7 +4158,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivial_v +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v = is_trivial<_Tp>::value; #endif @@ -4303,8 +4498,8 @@ struct __invokable_r using _Result = decltype( _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)); - static const bool value = - conditional< + using type = + typename conditional< !is_same<_Result, __nat>::value, typename conditional< is_void<_Ret>::value, @@ -4312,7 +4507,8 @@ struct __invokable_r is_convertible<_Result, _Ret> >::type, false_type - >::type::value; + >::type; + static const bool value = type::value; }; template <class _Fp, class ..._Args> @@ -4351,6 +4547,13 @@ using __nothrow_invokable_r = >; template <class _Fp, class ..._Args> +using __nothrow_invokable = + __nothrow_invokable_r_imp< + __invokable<_Fp, _Args...>::value, + true, void, _Fp, _Args... + >; + +template <class _Fp, class ..._Args> struct __invoke_of : public enable_if< __invokable<_Fp, _Args...>::value, @@ -4361,7 +4564,7 @@ struct __invoke_of // result_of template <class _Fp, class ..._Args> -class _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)> +class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)> : public __invoke_of<_Fp, _Args...> { }; @@ -4372,30 +4575,52 @@ template <class _Tp> using result_of_t = typename result_of<_Tp>::type; #if _LIBCPP_STD_VER > 14 -// is_callable +// invoke_result + +template <class _Fn, class... _Args> +struct _LIBCPP_TEMPLATE_VIS invoke_result + : __invoke_of<_Fn, _Args...> +{ +}; + +template <class _Fn, class... _Args> +using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; -template <class _Fn, class _Ret = void> -struct _LIBCPP_TYPE_VIS_ONLY is_callable; +// is_invocable -template <class _Fn, class ..._Args, class _Ret> -struct _LIBCPP_TYPE_VIS_ONLY is_callable<_Fn(_Args...), _Ret> +template <class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_invocable + : integral_constant<bool, __invokable<_Fn, _Args...>::value> {}; + +template <class _Ret, class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_invocable_r : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {}; -template <class _Fn, class _Ret = void> -constexpr bool is_callable_v = is_callable<_Fn, _Ret>::value; +template <class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_invocable_v + = is_invocable<_Fn, _Args...>::value; -// is_nothrow_callable +template <class _Ret, class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v + = is_invocable_r<_Ret, _Fn, _Args...>::value; -template <class _Fn, class _Ret = void> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable; +// is_nothrow_invocable -template <class _Fn, class ..._Args, class _Ret> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable<_Fn(_Args...), _Ret> - : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> -{}; +template <class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable + : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {}; + +template <class _Ret, class _Fn, class ..._Args> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r + : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {}; -template <class _Fn, class _Ret = void> -constexpr bool is_nothrow_callable_v = is_nothrow_callable<_Fn, _Ret>::value; +template <class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v + = is_nothrow_invocable<_Fn, _Args...>::value; + +template <class _Ret, class _Fn, class ..._Args> +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v + = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value; #endif // _LIBCPP_STD_VER > 14 @@ -4406,7 +4631,7 @@ template <class _Tp> struct __is_nothrow_swappable; template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#ifndef _LIBCPP_CXX03_LANG typename enable_if < is_move_constructible<_Tp>::value && @@ -4499,13 +4724,13 @@ struct __is_nothrow_swappable #if _LIBCPP_STD_VER > 14 template <class _Tp, class _Up> -struct _LIBCPP_TYPE_VIS_ONLY is_swappable_with +struct _LIBCPP_TEMPLATE_VIS is_swappable_with : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_swappable +struct _LIBCPP_TEMPLATE_VIS is_swappable : public conditional< __is_referenceable<_Tp>::value, is_swappable_with< @@ -4517,13 +4742,13 @@ struct _LIBCPP_TYPE_VIS_ONLY is_swappable }; template <class _Tp, class _Up> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_swappable_with +struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value> { }; template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_swappable +struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable : public conditional< __is_referenceable<_Tp>::value, is_nothrow_swappable_with< @@ -4535,16 +4760,20 @@ struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_swappable }; template <class _Tp, class _Up> -constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value; +_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v + = is_swappable_with<_Tp, _Up>::value; template <class _Tp> -constexpr bool is_swappable_v = is_swappable<_Tp>::value; +_LIBCPP_INLINE_VAR constexpr bool is_swappable_v + = is_swappable<_Tp>::value; template <class _Tp, class _Up> -constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value; +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v + = is_nothrow_swappable_with<_Tp, _Up>::value; template <class _Tp> -constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value; +_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v + = is_nothrow_swappable<_Tp>::value; #endif // _LIBCPP_STD_VER > 14 @@ -4601,6 +4830,11 @@ long long __convert_to_integral(long long __val) { return __val; } inline _LIBCPP_INLINE_VISIBILITY unsigned long long __convert_to_integral(unsigned long long __val) {return __val; } +template<typename _Fp> +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if<is_floating_point<_Fp>::value, long long>::type + __convert_to_integral(_Fp __val) { return __val; } + #ifndef _LIBCPP_HAS_NO_INT128 inline _LIBCPP_INLINE_VISIBILITY __int128_t __convert_to_integral(__int128_t __val) { return __val; } @@ -4614,7 +4848,7 @@ inline _LIBCPP_INLINE_VISIBILITY typename __sfinae_underlying_type<_Tp>::__promoted_type __convert_to_integral(_Tp __val) { return __val; } -#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> struct __has_operator_addressof_member_imp @@ -4646,23 +4880,31 @@ struct __has_operator_addressof || __has_operator_addressof_free_imp<_Tp>::value> {}; -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 + +#define __cpp_lib_void_t 201411 template <class...> using void_t = void; # ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args> struct conjunction : __and_<_Args...> {}; -template<class... _Args> constexpr bool conjunction_v = conjunction<_Args...>::value; +template<class... _Args> +_LIBCPP_INLINE_VAR constexpr bool conjunction_v + = conjunction<_Args...>::value; template <class... _Args> struct disjunction : __or_<_Args...> {}; -template<class... _Args> constexpr bool disjunction_v = disjunction<_Args...>::value; +template<class... _Args> +_LIBCPP_INLINE_VAR constexpr bool disjunction_v + = disjunction<_Args...>::value; template <class _Tp> struct negation : __not_<_Tp> {}; -template<class _Tp> constexpr bool negation_v = negation<_Tp>::value; +template<class _Tp> +_LIBCPP_INLINE_VAR constexpr bool negation_v + = negation<_Tp>::value; # endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_STD_VER > 14 @@ -4701,4 +4943,35 @@ struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy> _LIBCPP_END_NAMESPACE_STD +#if _LIBCPP_STD_VER > 14 +// std::byte +namespace std // purposefully not versioned +{ +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator<<=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = __lhs << __shift; } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator<< (byte __lhs, _Integer __shift) noexcept + { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type & + operator>>=(byte& __lhs, _Integer __shift) noexcept + { return __lhs = __lhs >> __shift; } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, byte>::type + operator>> (byte __lhs, _Integer __shift) noexcept + { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); } + +template <class _Integer> + constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type + to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } + +} +#endif + #endif // _LIBCPP_TYPE_TRAITS diff --git a/lib/libcxx/include/typeindex b/lib/libcxx/include/typeindex index d4d6ca96ba4..0565ca913e3 100644 --- a/lib/libcxx/include/typeindex +++ b/lib/libcxx/include/typeindex @@ -55,7 +55,7 @@ struct hash<type_index> _LIBCPP_BEGIN_NAMESPACE_STD -class _LIBCPP_TYPE_VIS_ONLY type_index +class _LIBCPP_TEMPLATE_VIS type_index { const type_info* __t_; public: @@ -87,10 +87,10 @@ public: const char* name() const _NOEXCEPT {return __t_->name();} }; -template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; template <> -struct _LIBCPP_TYPE_VIS_ONLY hash<type_index> +struct _LIBCPP_TEMPLATE_VIS hash<type_index> : public unary_function<type_index, size_t> { _LIBCPP_INLINE_VISIBILITY diff --git a/lib/libcxx/include/typeinfo b/lib/libcxx/include/typeinfo index 14ef77b31c3..7e8d3990ed9 100644 --- a/lib/libcxx/include/typeinfo +++ b/lib/libcxx/include/typeinfo @@ -61,11 +61,22 @@ public: #include <exception> #include <cstddef> #include <cstdint> +#ifdef _LIBCPP_NO_EXCEPTIONS +#include <cstdlib> +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +#if !defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT) +#define _LIBCPP_HAS_NONUNIQUE_TYPEINFO +#else +#define _LIBCPP_HAS_UNIQUE_TYPEINFO +#endif +#endif + namespace std // purposefully not using versioning namespace { @@ -73,76 +84,119 @@ class _LIBCPP_EXCEPTION_ABI type_info { type_info& operator=(const type_info&); type_info(const type_info&); + +#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) + _LIBCPP_INLINE_VISIBILITY + int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT + { return __builtin_strcmp(name(), __arg.name()); } +#endif + +#if defined(_LIBCPP_ABI_MICROSOFT) + mutable struct { + const char *__undecorated_name; + const char __decorated_name[1]; + } __data; + + int __compare(const type_info &__rhs) const _NOEXCEPT; +#endif // _LIBCPP_ABI_MICROSOFT + protected: -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - const char* __type_name; -#else +#if !defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) // A const char* with the non-unique RTTI bit possibly set. uintptr_t __type_name; -#endif _LIBCPP_INLINE_VISIBILITY explicit type_info(const char* __n) -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - : __type_name(__n) {} + : __type_name(reinterpret_cast<uintptr_t>(__n)) {} #else - : __type_name(reinterpret_cast<uintptr_t>(__n)) {} + const char *__type_name; + + _LIBCPP_INLINE_VISIBILITY + explicit type_info(const char* __n) : __type_name(__n) {} #endif +#endif // ! _LIBCPP_ABI_MICROSOFT public: + _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE virtual ~type_info(); +#if defined(_LIBCPP_ABI_MICROSOFT) + const char *name() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY - const char* name() const _NOEXCEPT -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - {return __type_name;} + bool before(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) < 0; + } + + size_t hash_code() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) == 0; + } #else - {return reinterpret_cast<const char*>(__type_name & ~_LIBCPP_NONUNIQUE_RTTI_BIT);} -#endif +#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) + _LIBCPP_INLINE_VISIBILITY + const char* name() const _NOEXCEPT + { + return reinterpret_cast<const char*>(__type_name & + ~_LIBCPP_NONUNIQUE_RTTI_BIT); + } _LIBCPP_INLINE_VISIBILITY bool before(const type_info& __arg) const _NOEXCEPT -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - {return __type_name < __arg.__type_name;} -#else - {if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) - return __type_name < __arg.__type_name; - return __compare_nonunique_names(__arg) < 0;} -#endif + { + if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return __type_name < __arg.__type_name; + return __compare_nonunique_names(__arg) < 0; + } _LIBCPP_INLINE_VISIBILITY size_t hash_code() const _NOEXCEPT -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - {return *reinterpret_cast<const size_t*>(&__type_name);} -#else - {if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name; - const char *__ptr = name(); - size_t __hash = 5381; - while (unsigned char __c = static_cast<unsigned char>(*__ptr++)) - __hash = (__hash * 33) ^ __c; - return __hash;} -#endif + { + if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return __type_name; + + const char* __ptr = name(); + size_t __hash = 5381; + while (unsigned char __c = static_cast<unsigned char>(*__ptr++)) + __hash = (__hash * 33) ^ __c; + return __hash; + } _LIBCPP_INLINE_VISIBILITY bool operator==(const type_info& __arg) const _NOEXCEPT -#ifndef _LIBCPP_NONUNIQUE_RTTI_BIT - {return __type_name == __arg.__type_name;} + { + if (__type_name == __arg.__type_name) + return true; + + if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) + return false; + return __compare_nonunique_names(__arg) == 0; + } #else - {if (__type_name == __arg.__type_name) return true; - if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) - return false; - return __compare_nonunique_names(__arg) == 0;} -#endif _LIBCPP_INLINE_VISIBILITY - bool operator!=(const type_info& __arg) const _NOEXCEPT - {return !operator==(__arg);} + const char* name() const _NOEXCEPT + { return __type_name; } -#ifdef _LIBCPP_NONUNIQUE_RTTI_BIT - private: _LIBCPP_INLINE_VISIBILITY - int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT - {return __builtin_strcmp(name(), __arg.name());} + bool before(const type_info& __arg) const _NOEXCEPT + { return __type_name < __arg.__type_name; } + + _LIBCPP_INLINE_VISIBILITY + size_t hash_code() const _NOEXCEPT + { return reinterpret_cast<size_t>(__type_name); } + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT + { return __type_name == __arg.__type_name; } #endif +#endif // _LIBCPP_ABI_MICROSOFT + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const type_info& __arg) const _NOEXCEPT + { return !operator==(__arg); } }; class _LIBCPP_EXCEPTION_ABI bad_cast @@ -165,4 +219,16 @@ public: } // std +_LIBCPP_BEGIN_NAMESPACE_STD +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_bad_cast() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_cast(); +#else + _VSTD::abort(); +#endif +} +_LIBCPP_END_NAMESPACE_STD + #endif // __LIBCPP_TYPEINFO diff --git a/lib/libcxx/include/unordered_map b/lib/libcxx/include/unordered_map index 8d7edaf509c..725cb6af275 100644 --- a/lib/libcxx/include/unordered_map +++ b/lib/libcxx/include/unordered_map @@ -379,9 +379,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc> _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _Cp, class _Hash, - bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value - > +template <class _Key, class _Cp, class _Hash, bool _IsEmpty> class __unordered_map_hasher : private _Hash { @@ -406,7 +404,7 @@ public: _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) { using _VSTD::swap; - swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y)); + swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y)); } }; @@ -449,9 +447,7 @@ swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, __x.swap(__y); } -template <class _Key, class _Cp, class _Pred, - bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value - > +template <class _Key, class _Cp, class _Pred, bool _IsEmpty> class __unordered_map_equal : private _Pred { @@ -479,7 +475,7 @@ public: _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) { using _VSTD::swap; - swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y)); + swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y)); } }; @@ -551,7 +547,7 @@ public: __second_constructed(false) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) _NOEXCEPT @@ -561,7 +557,7 @@ public: { __x.__value_constructed = false; } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#else // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) : __na_(__x.__na_), @@ -570,7 +566,7 @@ public: { const_cast<bool&>(__x.__value_constructed) = false; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT @@ -641,7 +637,7 @@ private: #endif template <class _HashIterator> -class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator +class _LIBCPP_TEMPLATE_VIS __hash_map_iterator { _HashIterator __i_; @@ -682,15 +678,15 @@ public: bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; }; template <class _HashIterator> -class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator +class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator { _HashIterator __i_; @@ -736,15 +732,15 @@ public: bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {return __x.__i_ != __y.__i_;} - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; - template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; + template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; }; template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, class _Alloc = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY unordered_map +class _LIBCPP_TEMPLATE_VIS unordered_map { public: // types @@ -823,20 +819,18 @@ public: explicit unordered_map(const allocator_type& __a); unordered_map(const unordered_map& __u); unordered_map(const unordered_map& __u, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_map(unordered_map&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_map(unordered_map&& __u, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS unordered_map(initializer_list<value_type> __il); unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 11 _LIBCPP_INLINE_VISIBILITY unordered_map(size_type __n, const allocator_type& __a) @@ -879,21 +873,19 @@ public: #endif return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(unordered_map&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -922,6 +914,8 @@ public: _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__p); #endif return insert(__x).first; } @@ -930,13 +924,11 @@ public: _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void insert(initializer_list<value_type> __il) {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> insert(value_type&& __x) {return __table_.__insert_unique(_VSTD::move(__x));} @@ -946,6 +938,8 @@ public: _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__p); #endif return __table_.__insert_unique(_VSTD::move(__x)).first; } @@ -965,6 +959,8 @@ public: _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__p); #endif return insert(_VSTD::forward<_Pp>(__x)).first; } @@ -982,6 +978,8 @@ public: _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__p); #endif return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; } @@ -1012,11 +1010,13 @@ public: iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) { #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__h); #endif - return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first; + return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first; } template <class... _Args> @@ -1024,9 +1024,11 @@ public: iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) { #if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this, "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not" " referring to this unordered_map"); +#else + ((void)__h); #endif return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first; } @@ -1057,18 +1059,20 @@ public: template <class _Vp> _LIBCPP_INLINE_VISIBILITY - iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) + iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v) { + // FIXME: Add debug mode checking for the iterator input return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first; } template <class _Vp> _LIBCPP_INLINE_VISIBILITY - iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) + iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v) { + // FIXME: Add debug mode checking for the iterator input return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first; } -#endif +#endif // _LIBCPP_STD_VER > 14 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} @@ -1085,7 +1089,7 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(unordered_map& __u) _NOEXCEPT_(__is_nothrow_swappable<__table>::value) - {__table_.swap(__u.__table_);} + { __table_.swap(__u.__table_);} _LIBCPP_INLINE_VISIBILITY hasher hash_function() const @@ -1267,7 +1271,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( insert(__u.begin(), __u.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline @@ -1304,10 +1308,6 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( initializer_list<value_type> __il) @@ -1344,10 +1344,6 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( insert(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& @@ -1358,10 +1354,6 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& @@ -1372,22 +1364,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifdef _LIBCPP_CXX03_LANG -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_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_.__cc.first), __k); - __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); - __h.get_deleter().__second_constructed = true; - return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 -} -#endif +#endif // _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> template <class _InputIterator> @@ -1400,20 +1377,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, __table_.__insert_unique(*__first); } -#ifdef _LIBCPP_CXX03_LANG -template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> -_Tp& -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_with_key(__k); - pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); - __h.release(); - return __r.first->second; -} -#else +#ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> _Tp& @@ -1432,8 +1396,35 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) std::piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple()).first->__cc.second; } +#else // _LIBCPP_CXX03_LANG + +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_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_.__cc.first), __k); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); + __h.get_deleter().__second_constructed = true; + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 +} + +template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> +_Tp& +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_with_key(__k); + pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); + __h.release(); + return __r.first->second; +} -#endif // !_LIBCPP_CXX03_MODE +#endif // _LIBCPP_CXX03_MODE template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> _Tp& @@ -1499,7 +1490,7 @@ operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, class _Alloc = allocator<pair<const _Key, _Tp> > > -class _LIBCPP_TYPE_VIS_ONLY unordered_multimap +class _LIBCPP_TEMPLATE_VIS unordered_multimap { public: // types @@ -1576,13 +1567,11 @@ public: explicit unordered_multimap(const allocator_type& __a); unordered_multimap(const unordered_multimap& __u); unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_multimap(unordered_multimap&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS unordered_multimap(initializer_list<value_type> __il); unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf = hasher(), @@ -1590,7 +1579,7 @@ public: unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 11 _LIBCPP_INLINE_VISIBILITY unordered_multimap(size_type __n, const allocator_type& __a) @@ -1633,21 +1622,19 @@ public: #endif return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(unordered_multimap&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -1678,13 +1665,10 @@ public: _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void insert(initializer_list<value_type> __il) {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} @@ -1902,7 +1886,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( insert(__u.begin(), __u.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline @@ -1941,10 +1925,6 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( initializer_list<value_type> __il) @@ -1981,10 +1961,6 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( insert(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& @@ -1995,10 +1971,6 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multima return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& @@ -2009,7 +1981,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG diff --git a/lib/libcxx/include/unordered_set b/lib/libcxx/include/unordered_set index fb38b648a86..3ae024a45ee 100644 --- a/lib/libcxx/include/unordered_set +++ b/lib/libcxx/include/unordered_set @@ -333,7 +333,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> > -class _LIBCPP_TYPE_VIS_ONLY unordered_set +class _LIBCPP_TEMPLATE_VIS unordered_set { public: // types @@ -408,13 +408,11 @@ public: explicit unordered_set(const allocator_type& __a); unordered_set(const unordered_set& __u); unordered_set(const unordered_set& __u, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_set(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_set(unordered_set&& __u, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS unordered_set(initializer_list<value_type> __il); unordered_set(initializer_list<value_type> __il, size_type __n, const hasher& __hf = hasher(), @@ -432,7 +430,7 @@ public: const hasher& __hf, const allocator_type& __a) : unordered_set(__il, __n, __hf, key_equal(), __a) {} #endif -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // ~unordered_set() = default; _LIBCPP_INLINE_VISIBILITY unordered_set& operator=(const unordered_set& __u) @@ -440,21 +438,19 @@ public: __table_ = __u.__table_; return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_set& operator=(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY unordered_set& operator=(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -474,7 +470,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return __table_.end();} -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#ifndef _LIBCPP_CXX03_LANG template <class... _Args> _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> emplace(_Args&&... __args) @@ -493,51 +489,47 @@ public: iterator emplace_hint(const_iterator, _Args&&... __args) {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;} #endif -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) - _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> insert(const value_type& __x) - {return __table_.__insert_unique(__x);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY pair<iterator, bool> insert(value_type&& __x) {return __table_.__insert_unique(_VSTD::move(__x));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY #if _LIBCPP_DEBUG_LEVEL >= 2 - iterator insert(const_iterator __p, const value_type& __x) + iterator insert(const_iterator __p, value_type&& __x) { _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, - "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" + "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" " referring to this unordered_set"); - return insert(__x).first; + return insert(_VSTD::move(__x)).first; } #else - iterator insert(const_iterator, const value_type& __x) - {return insert(__x).first;} + iterator insert(const_iterator, value_type&& __x) + {return insert(_VSTD::move(__x)).first;} #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void insert(initializer_list<value_type> __il) + {insert(__il.begin(), __il.end());} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert(const value_type& __x) + {return __table_.__insert_unique(__x);} + _LIBCPP_INLINE_VISIBILITY #if _LIBCPP_DEBUG_LEVEL >= 2 - iterator insert(const_iterator __p, value_type&& __x) + iterator insert(const_iterator __p, const value_type& __x) { _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, - "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" + "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" " referring to this unordered_set"); - return insert(_VSTD::move(__x)).first; + return insert(__x).first; } #else - iterator insert(const_iterator, value_type&& __x) - {return insert(_VSTD::move(__x)).first;} + iterator insert(const_iterator, const value_type& __x) + {return insert(__x).first;} #endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __first, _InputIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - void insert(initializer_list<value_type> __il) - {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __table_.erase(__p);} @@ -717,7 +709,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( insert(__u.begin(), __u.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Value, class _Hash, class _Pred, class _Alloc> inline @@ -752,10 +744,6 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( initializer_list<value_type> __il) @@ -792,10 +780,6 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( insert(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Value, class _Hash, class _Pred, class _Alloc> inline unordered_set<_Value, _Hash, _Pred, _Alloc>& @@ -806,10 +790,6 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Value, class _Hash, class _Pred, class _Alloc> inline unordered_set<_Value, _Hash, _Pred, _Alloc>& @@ -820,7 +800,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Value, class _Hash, class _Pred, class _Alloc> template <class _InputIterator> @@ -873,7 +853,7 @@ operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> > -class _LIBCPP_TYPE_VIS_ONLY unordered_multiset +class _LIBCPP_TEMPLATE_VIS unordered_multiset { public: // types @@ -949,13 +929,11 @@ public: explicit unordered_multiset(const allocator_type& __a); unordered_multiset(const unordered_multiset& __u); unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_multiset(unordered_multiset&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS unordered_multiset(initializer_list<value_type> __il); unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf = hasher(), @@ -971,7 +949,7 @@ public: unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} #endif -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG // ~unordered_multiset() = default; _LIBCPP_INLINE_VISIBILITY unordered_multiset& operator=(const unordered_multiset& __u) @@ -979,20 +957,18 @@ public: __table_ = __u.__table_; return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY unordered_multiset& operator=(unordered_multiset&& __u) _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); -#endif -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS unordered_multiset& operator=(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -1012,7 +988,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return __table_.end();} -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#ifndef _LIBCPP_CXX03_LANG template <class... _Args> _LIBCPP_INLINE_VISIBILITY iterator emplace(_Args&&... __args) @@ -1021,29 +997,27 @@ public: _LIBCPP_INLINE_VISIBILITY iterator emplace_hint(const_iterator __p, _Args&&... __args) {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) - _LIBCPP_INLINE_VISIBILITY - iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} -#endif - _LIBCPP_INLINE_VISIBILITY - iterator insert(const_iterator __p, const value_type& __x) - {return __table_.__insert_multi(__p, __x);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, value_type&& __x) {return __table_.__insert_multi(__p, _VSTD::move(__x));} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _InputIterator> - _LIBCPP_INLINE_VISIBILITY - void insert(_InputIterator __first, _InputIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY void insert(initializer_list<value_type> __il) {insert(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} + + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __p, const value_type& __x) + {return __table_.__insert_multi(__p, __x);} + + template <class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + void insert(_InputIterator __first, _InputIterator __last); _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __table_.erase(__p);} @@ -1224,7 +1198,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( insert(__u.begin(), __u.end()); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Value, class _Hash, class _Pred, class _Alloc> inline @@ -1259,10 +1233,6 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( initializer_list<value_type> __il) @@ -1299,10 +1269,6 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( insert(__il.begin(), __il.end()); } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Value, class _Hash, class _Pred, class _Alloc> inline unordered_multiset<_Value, _Hash, _Pred, _Alloc>& @@ -1314,10 +1280,6 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Value, class _Hash, class _Pred, class _Alloc> inline unordered_multiset<_Value, _Hash, _Pred, _Alloc>& @@ -1328,7 +1290,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Value, class _Hash, class _Pred, class _Alloc> template <class _InputIterator> diff --git a/lib/libcxx/include/utility b/lib/libcxx/include/utility index 7b978ad3096..6fa2e15d144 100644 --- a/lib/libcxx/include/utility +++ b/lib/libcxx/include/utility @@ -99,7 +99,7 @@ void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); struct piecewise_construct_t { }; -constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); +inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); template <class T> class tuple_size; template <size_t I, class T> class tuple_element; @@ -171,6 +171,25 @@ template<class... T> template<class T, class U=T> T exchange(T& obj, U&& new_value); + +// 20.2.7, in-place construction // C++17 +struct in_place_t { + explicit in_place_t() = default; +}; +inline constexpr in_place_t in_place{}; +template <class T> + struct in_place_type_t { + explicit in_place_type_t() = default; + }; +template <class T> + inline constexpr in_place_type_t<T> in_place_type{}; +template <size_t I> + struct in_place_index_t { + explicit in_place_index_t() = default; + }; +template <size_t I> + inline constexpr in_place_index_t<I> in_place_index{}; + } // std */ @@ -179,6 +198,10 @@ template<class T, class U=T> #include <__tuple> #include <type_traits> #include <initializer_list> +#include <cstddef> +#include <cstring> +#include <cstdint> +#include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -249,14 +272,14 @@ swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::v template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG typename conditional < !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&, _Tp&& >::type -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#else // _LIBCPP_CXX03_LANG const _Tp& #endif move_if_noexcept(_Tp& __x) _NOEXCEPT @@ -269,15 +292,27 @@ template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { r template <class _Tp> void as_const(const _Tp&&) = delete; #endif -struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { }; -#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) +struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { }; +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_UTILITY) extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); #else -constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); +/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); +#endif + +#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) +struct __non_trivially_copyable_base { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + __non_trivially_copyable_base() _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {} +}; #endif template <class _T1, class _T2> -struct _LIBCPP_TYPE_VIS_ONLY pair +struct _LIBCPP_TEMPLATE_VIS pair +#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) +: private __non_trivially_copyable_base +#endif { typedef _T1 first_type; typedef _T2 second_type; @@ -285,56 +320,179 @@ struct _LIBCPP_TYPE_VIS_ONLY pair _T1 first; _T2 second; -#ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS - template <bool _Dummy = true, class = typename enable_if< - __dependent_type<is_default_constructible<_T1>, _Dummy>::value && - __dependent_type<is_default_constructible<_T2>, _Dummy>::value - >::type> +#if !defined(_LIBCPP_CXX03_LANG) + pair(pair const&) = default; + pair(pair&&) = default; +#else + // Use the implicitly declared copy constructor in C++03 #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair(const _T1& __x, const _T2& __y) - : first(__x), second(__y) {} - - template<class _U1, class _U2> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair(const pair<_U1, _U2>& __p -#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE - ,typename enable_if<is_convertible<const _U1&, _T1>::value && - is_convertible<const _U2&, _T2>::value>::type* = 0 -#endif - ) - : first(__p.first), second(__p.second) {} +#ifdef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair() : first(), second() {} -#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) _LIBCPP_INLINE_VISIBILITY - pair(const pair& __p) - _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && - is_nothrow_copy_constructible<second_type>::value) - : first(__p.first), - second(__p.second) - { - } + pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} -# ifndef _LIBCPP_CXX03_LANG + template <class _U1, class _U2> _LIBCPP_INLINE_VISIBILITY - pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && - is_nothrow_move_constructible<second_type>::value) - : first(_VSTD::forward<first_type>(__p.first)), - second(_VSTD::forward<second_type>(__p.second)) - { + pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} + + _LIBCPP_INLINE_VISIBILITY + pair& operator=(pair const& __p) { + first = __p.first; + second = __p.second; + return *this; } -# endif -#elif !defined(_LIBCPP_CXX03_LANG) - pair(pair const&) = default; - pair(pair&&) = default; #else - // Use the implicitly declared copy constructor in C++03 -#endif + template <bool _Val> + using _EnableB = typename enable_if<_Val, bool>::type; + + struct _CheckArgs { + template <class _U1, class _U2> + static constexpr bool __enable_default() { + return is_default_constructible<_U1>::value + && is_default_constructible<_U2>::value; + } + + template <class _U1, class _U2> + static constexpr bool __enable_explicit() { + return is_constructible<first_type, _U1>::value + && is_constructible<second_type, _U2>::value + && (!is_convertible<_U1, first_type>::value + || !is_convertible<_U2, second_type>::value); + } + + template <class _U1, class _U2> + static constexpr bool __enable_implicit() { + return is_constructible<first_type, _U1>::value + && is_constructible<second_type, _U2>::value + && is_convertible<_U1, first_type>::value + && is_convertible<_U2, second_type>::value; + } + }; + + template <bool _MaybeEnable> + using _CheckArgsDep = typename conditional< + _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; + + struct _CheckTupleLikeConstructor { + template <class _Tuple> + static constexpr bool __enable_implicit() { + return __tuple_convertible<_Tuple, pair>::value; + } + + template <class _Tuple> + static constexpr bool __enable_explicit() { + return __tuple_constructible<_Tuple, pair>::value + && !__tuple_convertible<_Tuple, pair>::value; + } + + template <class _Tuple> + static constexpr bool __enable_assign() { + return __tuple_assignable<_Tuple, pair>::value; + } + }; + + template <class _Tuple> + using _CheckTLC = typename conditional< + __tuple_like_with_size<_Tuple, 2>::value + && !is_same<typename decay<_Tuple>::type, pair>::value, + _CheckTupleLikeConstructor, + __check_tuple_constructor_fail + >::type; + + template<bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_default<_T1, _T2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + pair() : first(), second() {} + + template <bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_T1 const& __t1, _T2 const& __t2) + : first(__t1), second(__t2) {} + + template<bool _Dummy = true, _EnableB< + _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_T1 const& __t1, _T2 const& __t2) + : first(__t1), second(__t2) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_U1&& __u1, _U2&& __u2) + : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_U1&& __u1, _U2&& __u2) + : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(pair<_U1, _U2> const& __p) + : first(__p.first), second(__p.second) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(pair<_U1, _U2> const& __p) + : first(__p.first), second(__p.second) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_explicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(pair<_U1, _U2>&&__p) + : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} + + template<class _U1, class _U2, _EnableB< + _CheckArgs::template __enable_implicit<_U1, _U2>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(pair<_U1, _U2>&& __p) + : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} + + template<class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit pair(_Tuple&& __p) + : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), + second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} + + template<class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(_Tuple&& __p) + : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), + second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} + + template <class... _Args1, class... _Args2> + _LIBCPP_INLINE_VISIBILITY + pair(piecewise_construct_t __pc, + tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) + : pair(__pc, __first_args, __second_args, + typename __make_tuple_indices<sizeof...(_Args1)>::type(), + typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} _LIBCPP_INLINE_VISIBILITY - pair& operator=(const pair& __p) + pair& operator=(typename conditional< + is_copy_assignable<first_type>::value && + is_copy_assignable<second_type>::value, + pair, __nat>::type const& __p) _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && is_nothrow_copy_assignable<second_type>::value) { @@ -343,75 +501,30 @@ struct _LIBCPP_TYPE_VIS_ONLY pair return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - - template <class _U1, class _U2, - class = typename enable_if<is_convertible<_U1, first_type>::value && - is_convertible<_U2, second_type>::value>::type> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair(_U1&& __u1, _U2&& __u2) - : first(_VSTD::forward<_U1>(__u1)), - second(_VSTD::forward<_U2>(__u2)) - {} - - template<class _U1, class _U2> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair(pair<_U1, _U2>&& __p, - typename enable_if<is_convertible<_U1, _T1>::value && - is_convertible<_U2, _T2>::value>::type* = 0) - : first(_VSTD::forward<_U1>(__p.first)), - second(_VSTD::forward<_U2>(__p.second)) {} - - _LIBCPP_INLINE_VISIBILITY - pair& - operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && - is_nothrow_move_assignable<second_type>::value) + _LIBCPP_INLINE_VISIBILITY + pair& operator=(typename conditional< + is_move_assignable<first_type>::value && + is_move_assignable<second_type>::value, + pair, __nat>::type&& __p) + _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && + is_nothrow_move_assignable<second_type>::value) { first = _VSTD::forward<first_type>(__p.first); second = _VSTD::forward<second_type>(__p.second); return *this; } -#ifndef _LIBCPP_HAS_NO_VARIADICS - - template<class _Tuple, - class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair(_Tuple&& __p) - : first(_VSTD::forward<typename tuple_element<0, - typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))), - second(_VSTD::forward<typename tuple_element<1, - typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p))) - {} - - - - template <class... _Args1, class... _Args2> - _LIBCPP_INLINE_VISIBILITY - pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) - : pair(__pc, __first_args, __second_args, - typename __make_tuple_indices<sizeof...(_Args1)>::type(), - typename __make_tuple_indices<sizeof...(_Args2) >::type()) - {} - - template <class _Tuple, - class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> - _LIBCPP_INLINE_VISIBILITY - pair& - operator=(_Tuple&& __p) - { - typedef typename __make_tuple_types<_Tuple>::type _TupleRef; - typedef typename tuple_element<0, _TupleRef>::type _U0; - typedef typename tuple_element<1, _TupleRef>::type _U1; - first = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); - second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); - return *this; - } - -#endif // _LIBCPP_HAS_NO_VARIADICS + template <class _Tuple, _EnableB< + _CheckTLC<_Tuple>::template __enable_assign<_Tuple>() + > = false> + _LIBCPP_INLINE_VISIBILITY + pair& operator=(_Tuple&& __p) { + first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p)); + second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p)); + return *this; + } +#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && @@ -423,15 +536,20 @@ struct _LIBCPP_TYPE_VIS_ONLY pair } private: -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> _LIBCPP_INLINE_VISIBILITY pair(piecewise_construct_t, tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>); -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _T1, class _T2> +pair(_T1, _T2) -> pair<_T1, _T2>; +#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES + template <class _T1, class _T2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool @@ -495,8 +613,7 @@ swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) __x.swap(__y); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> struct __make_pair_return_impl @@ -525,7 +642,7 @@ make_pair(_T1&& __t1, _T2&& __t2) (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#else // _LIBCPP_CXX03_LANG template <class _T1, class _T2> inline _LIBCPP_INLINE_VISIBILITY @@ -535,21 +652,27 @@ make_pair(_T1 __x, _T2 __y) return pair<_T1, _T2>(__x, __y); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _T1, class _T2> - class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> > + class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {}; +template <size_t _Ip, class _T1, class _T2> +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > +{ + static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"); +}; + template <class _T1, class _T2> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> > +class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > { public: typedef _T1 type; }; template <class _T1, class _T2> -class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> > +class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > { public: typedef _T2 type; @@ -572,8 +695,7 @@ struct __get_pair<0> const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG template <class _T1, class _T2> static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -585,8 +707,7 @@ struct __get_pair<0> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG }; template <> @@ -604,8 +725,7 @@ struct __get_pair<1> const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG template <class _T1, class _T2> static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -617,8 +737,7 @@ struct __get_pair<1> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG }; template <size_t _Ip, class _T1, class _T2> @@ -637,8 +756,7 @@ get(const pair<_T1, _T2>& __p) _NOEXCEPT return __get_pair<_Ip>::get(__p); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - +#ifndef _LIBCPP_CXX03_LANG template <size_t _Ip, class _T1, class _T2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& @@ -654,8 +772,7 @@ get(const pair<_T1, _T2>&& __p) _NOEXCEPT { return __get_pair<_Ip>::get(_VSTD::move(__p)); } - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 11 template <class _T1, class _T2> @@ -719,7 +836,7 @@ constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT #if _LIBCPP_STD_VER > 11 template<class _Tp, _Tp... _Ip> -struct _LIBCPP_TYPE_VIS_ONLY integer_sequence +struct _LIBCPP_TEMPLATE_VIS integer_sequence { typedef _Tp value_type; static_assert( is_integral<_Tp>::value, @@ -782,6 +899,696 @@ _T1 exchange(_T1& __obj, _T2 && __new_value) } #endif // _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 14 + +struct _LIBCPP_TYPE_VIS in_place_t { + explicit in_place_t() = default; +}; +_LIBCPP_INLINE_VAR constexpr in_place_t in_place{}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS in_place_type_t { + explicit in_place_type_t() = default; +}; +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{}; + +template <size_t _Idx> +struct _LIBCPP_TYPE_VIS in_place_index_t { + explicit in_place_index_t() = default; +}; +template <size_t _Idx> +_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{}; + +template <class _Tp> struct __is_inplace_type_imp : false_type {}; +template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {}; + +template <class _Tp> +using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>; + +template <class _Tp> struct __is_inplace_index_imp : false_type {}; +template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {}; + +template <class _Tp> +using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>; + +#endif // _LIBCPP_STD_VER > 14 + +template <class _Arg, class _Result> +struct _LIBCPP_TEMPLATE_VIS unary_function +{ + typedef _Arg argument_type; + typedef _Result result_type; +}; + +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. +template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> +struct __murmur2_or_cityhash; + +template <class _Size> +struct __murmur2_or_cityhash<_Size, 32> +{ + inline _Size operator()(const void* __key, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; +}; + +// murmur2 +template <class _Size> +_Size +__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) +{ + const _Size __m = 0x5bd1e995; + const _Size __r = 24; + _Size __h = __len; + const unsigned char* __data = static_cast<const unsigned char*>(__key); + for (; __len >= 4; __data += 4, __len -= 4) + { + _Size __k = __loadword<_Size>(__data); + __k *= __m; + __k ^= __k >> __r; + __k *= __m; + __h *= __m; + __h ^= __k; + } + switch (__len) + { + case 3: + __h ^= __data[2] << 16; + case 2: + __h ^= __data[1] << 8; + case 1: + __h ^= __data[0]; + __h *= __m; + } + __h ^= __h >> 13; + __h *= __m; + __h ^= __h >> 15; + return __h; +} + +template <class _Size> +struct __murmur2_or_cityhash<_Size, 64> +{ + inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; + + private: + // Some primes between 2^63 and 2^64. + static const _Size __k0 = 0xc3a5c85c97cb3127ULL; + static const _Size __k1 = 0xb492b66fbe98f273ULL; + static const _Size __k2 = 0x9ae16a3b2f90404fULL; + static const _Size __k3 = 0xc949d7c7509e6557ULL; + + static _Size __rotate(_Size __val, int __shift) { + return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); + } + + static _Size __rotate_by_at_least_1(_Size __val, int __shift) { + return (__val >> __shift) | (__val << (64 - __shift)); + } + + static _Size __shift_mix(_Size __val) { + return __val ^ (__val >> 47); + } + + static _Size __hash_len_16(_Size __u, _Size __v) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + const _Size __mul = 0x9ddfea08eb382d69ULL; + _Size __a = (__u ^ __v) * __mul; + __a ^= (__a >> 47); + _Size __b = (__v ^ __a) * __mul; + __b ^= (__b >> 47); + __b *= __mul; + return __b; + } + + static _Size __hash_len_0_to_16(const char* __s, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + if (__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 = __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) { + const unsigned char __a = __s[0]; + const unsigned char __b = __s[__len >> 1]; + const unsigned char __c = __s[__len - 1]; + const uint32_t __y = static_cast<uint32_t>(__a) + + (static_cast<uint32_t>(__b) << 8); + const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); + return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; + } + return __k2; + } + + static _Size __hash_len_17_to_32(const char *__s, _Size __len) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + 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); + } + + // Return a 16-byte hash for 48 bytes. Quick and dirty. + // Callers do best to use "random-looking" values for a and b. + static pair<_Size, _Size> __weak_hash_len_32_with_seeds( + _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + __a += __w; + __b = __rotate(__b + __a + __z, 21); + const _Size __c = __a; + __a += __x; + __a += __y; + __b += __rotate(__a, 44); + return pair<_Size, _Size>(__a + __z, __b + __c); + } + + // 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) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + 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) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK + { + _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 += __loadword<_Size>(__s + 8); + __c += __rotate(__a, 7); + __a += __loadword<_Size>(__s + 16); + _Size __vf = __a + __z; + _Size __vs = __b + __rotate(__a, 31) + __c; + __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 += __loadword<_Size>(__s + __len - 24); + __c += __rotate(__a, 7); + __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); + return __shift_mix(__r * __k0 + __vs) * __k2; + } +}; + +// cityhash64 +template <class _Size> +_Size +__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) +{ + const char* __s = static_cast<const char*>(__key); + if (__len <= 32) { + if (__len <= 16) { + return __hash_len_0_to_16(__s, __len); + } else { + return __hash_len_17_to_32(__s, __len); + } + } else if (__len <= 64) { + return __hash_len_33_to_64(__s, __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 = __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 + __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 + __loadword<_Size>(__s + 8), 37) * __k1; + __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; + __x ^= __w.second; + __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 + __loadword<_Size>(__s + 16)); + std::swap(__z, __x); + __s += 64; + __len -= 64; + } while (__len != 0); + return __hash_len_16( + __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, + __hash_len_16(__v.second, __w.second) + __x); +} + +template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> +struct __scalar_hash; + +template <class _Tp> +struct __scalar_hash<_Tp, 0> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__a = 0; + __u.__t = __v; + return __u.__a; + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 1> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + size_t __a; + } __u; + __u.__t = __v; + return __u.__a; + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 2> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 3> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +template <class _Tp> +struct __scalar_hash<_Tp, 4> + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + union + { + _Tp __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + +struct _PairT { + size_t first; + size_t second; +}; + +_LIBCPP_INLINE_VISIBILITY +inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { + typedef __scalar_hash<_PairT> _HashT; + const _PairT __p = {__lhs, __rhs}; + return _HashT()(__p); +} + +template<class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> + : public unary_function<_Tp*, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp* __v) const _NOEXCEPT + { + union + { + _Tp* __t; + size_t __a; + } __u; + __u.__t = __v; + return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); + } +}; + + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<bool> + : public unary_function<bool, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char> + : public unary_function<char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<signed char> + : public unary_function<signed char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> + : public unary_function<unsigned char, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char16_t> + : public unary_function<char16_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<char32_t> + : public unary_function<char32_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<wchar_t> + : public unary_function<wchar_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<short> + : public unary_function<short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> + : public unary_function<unsigned short, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<int> + : public unary_function<int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> + : public unary_function<unsigned int, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long> + : public unary_function<long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> + : public unary_function<unsigned long, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long long> + : public __scalar_hash<long long> +{ +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> + : public __scalar_hash<unsigned long long> +{ +}; + +#ifndef _LIBCPP_HAS_NO_INT128 + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> + : public __scalar_hash<__int128_t> +{ +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> + : public __scalar_hash<__uint128_t> +{ +}; + +#endif + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<float> + : public __scalar_hash<float> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(float __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0) + return 0; + return __scalar_hash<float>::operator()(__v); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<double> + : public __scalar_hash<double> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0) + return 0; + return __scalar_hash<double>::operator()(__v); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<long double> + : public __scalar_hash<long double> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(long double __v) const _NOEXCEPT + { + // -0.0 and 0.0 should return same hash + if (__v == 0) + return 0; +#if defined(__i386__) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + size_t __c; + size_t __d; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__s.__c = 0; + __u.__s.__d = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; +#elif defined(__x86_64__) + // Zero out padding bits + union + { + long double __t; + struct + { + size_t __a; + size_t __b; + } __s; + } __u; + __u.__s.__a = 0; + __u.__s.__b = 0; + __u.__t = __v; + return __u.__s.__a ^ __u.__s.__b; +#else + return __scalar_hash<long double>::operator()(__v); +#endif + } +}; + +#if _LIBCPP_STD_VER > 11 + +template <class _Tp, bool = is_enum<_Tp>::value> +struct _LIBCPP_TEMPLATE_VIS __enum_hash + : public unary_function<_Tp, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(_Tp __v) const _NOEXCEPT + { + typedef typename underlying_type<_Tp>::type type; + return hash<type>{}(static_cast<type>(__v)); + } +}; +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { + __enum_hash() = delete; + __enum_hash(__enum_hash const&) = delete; + __enum_hash& operator=(__enum_hash const&) = delete; +}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> +{ +}; +#endif + +#if _LIBCPP_STD_VER > 14 + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> + : public unary_function<nullptr_t, size_t> +{ + _LIBCPP_INLINE_VISIBILITY + size_t operator()(nullptr_t) const _NOEXCEPT { + return 662607004ull; + } +}; +#endif + +#ifndef _LIBCPP_CXX03_LANG +template <class _Key, class _Hash> +using __check_hash_requirements = integral_constant<bool, + is_copy_constructible<_Hash>::value && + is_move_constructible<_Hash>::value && + __invokable_r<size_t, _Hash, _Key const&>::value +>; + +template <class _Key, class _Hash = std::hash<_Key> > +using __has_enabled_hash = integral_constant<bool, + __check_hash_requirements<_Key, _Hash>::value && + is_default_constructible<_Hash>::value +>; + +#if _LIBCPP_STD_VER > 14 +template <class _Type, class> +using __enable_hash_helper_imp = _Type; + +template <class _Type, class ..._Keys> +using __enable_hash_helper = __enable_hash_helper_imp<_Type, + typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type +>; +#else +template <class _Type, class ...> +using __enable_hash_helper = _Type; +#endif + +#endif // !_LIBCPP_CXX03_LANG + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_UTILITY diff --git a/lib/libcxx/include/valarray b/lib/libcxx/include/valarray index bde644e8719..ee61238a932 100644 --- a/lib/libcxx/include/valarray +++ b/lib/libcxx/include/valarray @@ -347,18 +347,19 @@ template <class T> unspecified2 end(const valarray<T>& v); #include <functional> #include <new> -#include <__undef_min_max> -#include <__undef___deallocate> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD -template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY valarray; +template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray; -class _LIBCPP_TYPE_VIS_ONLY slice +class _LIBCPP_TEMPLATE_VIS slice { size_t __start_; size_t __size_; @@ -383,11 +384,11 @@ public: _LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;} }; -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY slice_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array; class _LIBCPP_TYPE_VIS gslice; -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY gslice_array; -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY mask_array; -template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY indirect_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array; +template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array; template <class _Tp> _LIBCPP_INLINE_VISIBILITY @@ -673,7 +674,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} - template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; }; template <class _ValExpr> @@ -788,7 +789,7 @@ template<class _Tp> struct __is_val_expr<valarray<_Tp> > : true_type {}; template<class _Tp> -class _LIBCPP_TYPE_VIS_ONLY valarray +class _LIBCPP_TEMPLATE_VIS valarray { public: typedef _Tp value_type; @@ -802,36 +803,32 @@ public: // construct/destroy: _LIBCPP_INLINE_VISIBILITY valarray() : __begin_(0), __end_(0) {} - _LIBCPP_INLINE_VISIBILITY - inline explicit valarray(size_t __n); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + explicit valarray(size_t __n); _LIBCPP_INLINE_VISIBILITY valarray(const value_type& __x, size_t __n); valarray(const value_type* __p, size_t __n); valarray(const valarray& __v); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray(valarray&& __v) _NOEXCEPT; -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS valarray(initializer_list<value_type> __il); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG valarray(const slice_array<value_type>& __sa); valarray(const gslice_array<value_type>& __ga); valarray(const mask_array<value_type>& __ma); valarray(const indirect_array<value_type>& __ia); - inline _LIBCPP_INLINE_VISIBILITY + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY ~valarray(); // assignment: valarray& operator=(const valarray& __v); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray& operator=(valarray&& __v) _NOEXCEPT; -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS _LIBCPP_INLINE_VISIBILITY valarray& operator=(initializer_list<value_type>); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY valarray& operator=(const value_type& __x); _LIBCPP_INLINE_VISIBILITY @@ -862,32 +859,32 @@ public: __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const; _LIBCPP_INLINE_VISIBILITY gslice_array<value_type> operator[](const gslice& __gs); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const; _LIBCPP_INLINE_VISIBILITY gslice_array<value_type> operator[](gslice&& __gs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const; _LIBCPP_INLINE_VISIBILITY mask_array<value_type> operator[](const valarray<bool>& __vb); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const; _LIBCPP_INLINE_VISIBILITY mask_array<value_type> operator[](valarray<bool>&& __vb); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const; _LIBCPP_INLINE_VISIBILITY indirect_array<value_type> operator[](const valarray<size_t>& __vs); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const; _LIBCPP_INLINE_VISIBILITY indirect_array<value_type> operator[](valarray<size_t>&& __vs); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG // unary operators: valarray operator+() const; @@ -1028,12 +1025,12 @@ public: void resize(size_t __n, value_type __x = value_type()); private: - template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY slice_array; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY gslice_array; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY mask_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; + template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array; template <class> friend class __mask_expr; - template <class> friend class _LIBCPP_TYPE_VIS_ONLY indirect_array; + template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array; template <class> friend class __indirect_expr; template <class> friend class __val_expr; @@ -1147,7 +1144,7 @@ struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > // slice_array template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY slice_array +class _LIBCPP_TEMPLATE_VIS slice_array { public: typedef _Tp value_type; @@ -1481,7 +1478,7 @@ public: __stride_(__stride) {__init(__start);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY gslice(size_t __start, const valarray<size_t>& __size, @@ -1504,7 +1501,7 @@ public: __stride_(move(__stride)) {__init(__start);} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG // gslice(const gslice&) = default; // gslice(gslice&&) = default; @@ -1531,7 +1528,7 @@ private: // gslice_array template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY gslice_array +class _LIBCPP_TEMPLATE_VIS gslice_array { public: typedef _Tp value_type; @@ -1657,12 +1654,12 @@ private: __1d_(__gs.__1d_) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG gslice_array(gslice&& __gs, const valarray<value_type>& __v) : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(move(__gs.__1d_)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class> friend class valarray; }; @@ -1869,7 +1866,7 @@ gslice_array<_Tp>::operator=(const value_type& __x) const // mask_array template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY mask_array +class _LIBCPP_TEMPLATE_VIS mask_array { public: typedef _Tp value_type; @@ -2227,7 +2224,7 @@ public: // indirect_array template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY indirect_array +class _LIBCPP_TEMPLATE_VIS indirect_array { public: typedef _Tp value_type; @@ -2354,7 +2351,7 @@ private: __1d_(__ia) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v) @@ -2362,7 +2359,7 @@ private: __1d_(move(__ia)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class> friend class valarray; }; @@ -2573,7 +2570,7 @@ private: __1d_(__ia) {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e) @@ -2581,7 +2578,7 @@ private: __1d_(move(__ia)) {} -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG public: _LIBCPP_INLINE_VISIBILITY @@ -2591,7 +2588,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_t size() const {return __1d_.size();} - template <class> friend class _LIBCPP_TYPE_VIS_ONLY valarray; + template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; }; template<class _ValExpr> @@ -2815,7 +2812,7 @@ valarray<_Tp>::valarray(const valarray& __v) } } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -2826,10 +2823,6 @@ valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT __v.__begin_ = __v.__end_ = nullptr; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp> valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(0), @@ -2856,7 +2849,7 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il) } } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Tp> valarray<_Tp>::valarray(const slice_array<value_type>& __sa) @@ -2991,7 +2984,7 @@ valarray<_Tp>::operator=(const valarray& __v) return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3006,10 +2999,6 @@ valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT return *this; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp> inline valarray<_Tp>& @@ -3021,7 +3010,7 @@ valarray<_Tp>::operator=(initializer_list<value_type> __il) return *this; } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3133,7 +3122,7 @@ valarray<_Tp>::operator[](const gslice& __gs) return gslice_array<value_type>(__gs, *this); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3151,7 +3140,7 @@ valarray<_Tp>::operator[](gslice&& __gs) return gslice_array<value_type>(move(__gs), *this); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3169,7 +3158,7 @@ valarray<_Tp>::operator[](const valarray<bool>& __vb) return mask_array<value_type>(__vb, *this); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3187,7 +3176,7 @@ valarray<_Tp>::operator[](valarray<bool>&& __vb) return mask_array<value_type>(move(__vb), *this); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3205,7 +3194,7 @@ valarray<_Tp>::operator[](const valarray<size_t>& __vs) return indirect_array<value_type>(__vs, *this); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp> inline @@ -3223,7 +3212,7 @@ valarray<_Tp>::operator[](valarray<size_t>&& __vs) return indirect_array<value_type>(move(__vs), *this); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _Tp> valarray<_Tp> @@ -3697,7 +3686,7 @@ valarray<_Tp>::resize(size_t __n, value_type __x) { while (__end_ != __begin_) (--__end_)->~value_type(); - _VSTD::__deallocate(__begin_); + _VSTD::__libcpp_deallocate(__begin_); __begin_ = __end_ = nullptr; } if (__n) @@ -4878,4 +4867,6 @@ end(const valarray<_Tp>& __v) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_VALARRAY diff --git a/lib/libcxx/include/variant b/lib/libcxx/include/variant new file mode 100644 index 00000000000..987b8a7982d --- /dev/null +++ b/lib/libcxx/include/variant @@ -0,0 +1,1594 @@ +// -*- C++ -*- +//===------------------------------ variant -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VARIANT +#define _LIBCPP_VARIANT + +/* + variant synopsis + +namespace std { + + // 20.7.2, class template variant + template <class... Types> + class variant { + public: + + // 20.7.2.1, constructors + constexpr variant() noexcept(see below); + variant(const variant&); + variant(variant&&) noexcept(see below); + + template <class T> constexpr variant(T&&) noexcept(see below); + + template <class T, class... Args> + constexpr explicit variant(in_place_type_t<T>, Args&&...); + + template <class T, class U, class... Args> + constexpr explicit variant( + in_place_type_t<T>, initializer_list<U>, Args&&...); + + template <size_t I, class... Args> + constexpr explicit variant(in_place_index_t<I>, Args&&...); + + template <size_t I, class U, class... Args> + constexpr explicit variant( + in_place_index_t<I>, initializer_list<U>, Args&&...); + + // 20.7.2.2, destructor + ~variant(); + + // 20.7.2.3, assignment + variant& operator=(const variant&); + variant& operator=(variant&&) noexcept(see below); + + template <class T> variant& operator=(T&&) noexcept(see below); + + // 20.7.2.4, modifiers + template <class T, class... Args> + T& emplace(Args&&...); + + template <class T, class U, class... Args> + T& emplace(initializer_list<U>, Args&&...); + + template <size_t I, class... Args> + variant_alternative_t<I, variant>& emplace(Args&&...); + + template <size_t I, class U, class... Args> + variant_alternative_t<I, variant>& emplace(initializer_list<U>, Args&&...); + + // 20.7.2.5, value status + constexpr bool valueless_by_exception() const noexcept; + constexpr size_t index() const noexcept; + + // 20.7.2.6, swap + void swap(variant&) noexcept(see below); + }; + + // 20.7.3, variant helper classes + template <class T> struct variant_size; // undefined + + template <class T> + inline constexpr size_t variant_size_v = variant_size<T>::value; + + template <class T> struct variant_size<const T>; + template <class T> struct variant_size<volatile T>; + template <class T> struct variant_size<const volatile T>; + + template <class... Types> + struct variant_size<variant<Types...>>; + + template <size_t I, class T> struct variant_alternative; // undefined + + template <size_t I, class T> + using variant_alternative_t = typename variant_alternative<I, T>::type; + + template <size_t I, class T> struct variant_alternative<I, const T>; + template <size_t I, class T> struct variant_alternative<I, volatile T>; + template <size_t I, class T> struct variant_alternative<I, const volatile T>; + + template <size_t I, class... Types> + struct variant_alternative<I, variant<Types...>>; + + inline constexpr size_t variant_npos = -1; + + // 20.7.4, value access + template <class T, class... Types> + constexpr bool holds_alternative(const variant<Types...>&) noexcept; + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>>& + get(variant<Types...>&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>>&& + get(variant<Types...>&&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>> const& + get(const variant<Types...>&); + + template <size_t I, class... Types> + constexpr variant_alternative_t<I, variant<Types...>> const&& + get(const variant<Types...>&&); + + template <class T, class... Types> + constexpr T& get(variant<Types...>&); + + template <class T, class... Types> + constexpr T&& get(variant<Types...>&&); + + template <class T, class... Types> + constexpr const T& get(const variant<Types...>&); + + template <class T, class... Types> + constexpr const T&& get(const variant<Types...>&&); + + template <size_t I, class... Types> + constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>> + get_if(variant<Types...>*) noexcept; + + template <size_t I, class... Types> + constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>> + get_if(const variant<Types...>*) noexcept; + + template <class T, class... Types> + constexpr add_pointer_t<T> + get_if(variant<Types...>*) noexcept; + + template <class T, class... Types> + constexpr add_pointer_t<const T> + get_if(const variant<Types...>*) noexcept; + + // 20.7.5, relational operators + template <class... Types> + constexpr bool operator==(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator<(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator>(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&); + + template <class... Types> + constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&); + + // 20.7.6, visitation + template <class Visitor, class... Variants> + constexpr see below visit(Visitor&&, Variants&&...); + + // 20.7.7, class monostate + struct monostate; + + // 20.7.8, monostate relational operators + constexpr bool operator<(monostate, monostate) noexcept; + constexpr bool operator>(monostate, monostate) noexcept; + constexpr bool operator<=(monostate, monostate) noexcept; + constexpr bool operator>=(monostate, monostate) noexcept; + constexpr bool operator==(monostate, monostate) noexcept; + constexpr bool operator!=(monostate, monostate) noexcept; + + // 20.7.9, specialized algorithms + template <class... Types> + void swap(variant<Types...>&, variant<Types...>&) noexcept(see below); + + // 20.7.10, class bad_variant_access + class bad_variant_access; + + // 20.7.11, hash support + template <class T> struct hash; + template <class... Types> struct hash<variant<Types...>>; + template <> struct hash<monostate>; + +} // namespace std + +*/ + +#include <__config> +#include <__tuple> +#include <array> +#include <exception> +#include <functional> +#include <initializer_list> +#include <new> +#include <tuple> +#include <type_traits> +#include <utility> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +namespace std { // explicitly not using versioning namespace + +class _LIBCPP_EXCEPTION_ABI bad_variant_access : public exception { +public: + virtual const char* what() const _NOEXCEPT; +}; + +} // namespace std + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_NORETURN +inline _LIBCPP_INLINE_VISIBILITY +void __throw_bad_variant_access() { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_variant_access(); +#else + _VSTD::abort(); +#endif +} + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS variant; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size; + +template <class _Tp> +_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {}; + +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp> + : variant_size<_Tp> {}; + +template <class... _Types> +struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>> + : integral_constant<size_t, sizeof...(_Types)> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative; + +template <size_t _Ip, class _Tp> +using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> + : add_const<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp> + : add_volatile<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class _Tp> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> + : add_cv<variant_alternative_t<_Ip, _Tp>> {}; + +template <size_t _Ip, class... _Types> +struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> { + static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>"); + using type = __type_pack_element<_Ip, _Types...>; +}; + +_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1); + +constexpr int __choose_index_type(unsigned int __num_elem) { + if (__num_elem < std::numeric_limits<unsigned char>::max()) + return 0; + if (__num_elem < std::numeric_limits<unsigned short>::max()) + return 1; + return 2; +} + +template <size_t _NumAlts> +using __variant_index_t = +#ifndef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION + unsigned int; +#else + std::tuple_element_t< + __choose_index_type(_NumAlts), + std::tuple<unsigned char, unsigned short, unsigned int> + >; +#endif + +template <class _IndexType> +constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1); + +namespace __find_detail { + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_index() { + constexpr bool __matches[] = {is_same_v<_Tp, _Types>...}; + size_t __result = __not_found; + for (size_t __i = 0; __i < sizeof...(_Types); ++__i) { + if (__matches[__i]) { + if (__result != __not_found) { + return __ambiguous; + } + __result = __i; + } + } + return __result; +} + +template <size_t _Index> +struct __find_unambiguous_index_sfinae_impl + : integral_constant<size_t, _Index> {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__not_found> {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__ambiguous> {}; + +template <class _Tp, class... _Types> +struct __find_unambiguous_index_sfinae + : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {}; + +} // namespace __find_detail + +namespace __variant_detail { + +struct __valueless_t {}; + +enum class _Trait { _TriviallyAvailable, _Available, _Unavailable }; + +template <typename _Tp, + template <typename> class _IsTriviallyAvailable, + template <typename> class _IsAvailable> +constexpr _Trait __trait = + _IsTriviallyAvailable<_Tp>::value + ? _Trait::_TriviallyAvailable + : _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Trait __common_trait(initializer_list<_Trait> __traits) { + _Trait __result = _Trait::_TriviallyAvailable; + for (_Trait __t : __traits) { + if (static_cast<int>(__t) > static_cast<int>(__result)) { + __result = __t; + } + } + return __result; +} + +template <typename... _Types> +struct __traits { + static constexpr _Trait __copy_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_copy_constructible, + is_copy_constructible>...}); + + static constexpr _Trait __move_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_move_constructible, + is_move_constructible>...}); + + static constexpr _Trait __copy_assignable_trait = __common_trait( + {__copy_constructible_trait, + __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...}); + + static constexpr _Trait __move_assignable_trait = __common_trait( + {__move_constructible_trait, + __trait<_Types, is_trivially_move_assignable, is_move_assignable>...}); + + static constexpr _Trait __destructible_trait = __common_trait( + {__trait<_Types, is_trivially_destructible, is_destructible>...}); +}; + +namespace __access { + +struct __union { + template <class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) { + return _VSTD::forward<_Vp>(__v).__head; + } + + template <class _Vp, size_t _Ip> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) { + return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>); + } +}; + +struct __base { + template <size_t _Ip, class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data, + in_place_index<_Ip>); + } +}; + +struct __variant { + template <size_t _Ip, class _Vp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl); + } +}; + +} // namespace __access + +namespace __visitation { + +struct __base { + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + constexpr auto __fdiagonal = + __make_fdiagonal<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + constexpr auto __fmatrix = + __make_fmatrix<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + return __at(__fmatrix, __vs.index()...)( + _VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + +private: + template <class _Tp> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr const _Tp& __at(const _Tp& __elem) { return __elem; } + + template <class _Tp, size_t _Np, typename... _Indices> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __at(const array<_Tp, _Np>& __elems, + size_t __index, _Indices... __indices) { + return __at(__elems[__index], __indices...); + } + + template <class _Fp, class... _Fs> + static constexpr void __std_visit_visitor_return_type_check() { + static_assert( + __all<is_same_v<_Fp, _Fs>...>::value, + "`std::visit` requires the visitor to have a single return type."); + } + + template <class... _Fs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_farray(_Fs&&... __fs) { + __std_visit_visitor_return_type_check<decay_t<_Fs>...>(); + using __result = array<common_type_t<decay_t<_Fs>...>, sizeof...(_Fs)>; + return __result{{_VSTD::forward<_Fs>(__fs)...}}; + } + + template <std::size_t... _Is> + struct __dispatcher { + template <class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) { + return __invoke_constexpr( + static_cast<_Fp>(__f), + __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...); + } + }; + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_dispatch(index_sequence<_Is...>) { + return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; + } + + template <size_t _Ip, class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl() { + return __make_dispatch<_Fp, _Vs...>( + index_sequence<(__identity<_Vs>{}, _Ip)...>{}); + } + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) { + return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...); + } + + template <class _Fp, class _Vp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal() { + constexpr size_t _Np = decay_t<_Vp>::__size(); + static_assert(__all<(_Np == decay_t<_Vs>::__size())...>::value); + return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{}); + } + + template <class _Fp, class... _Vs, size_t... _Is> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) { + return __make_dispatch<_Fp, _Vs...>(__is); + } + + template <class _Fp, class... _Vs, size_t... _Is, size_t... _Js, class... _Ls> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>, + index_sequence<_Js...>, + _Ls... __ls) { + return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<_Is..., _Js>{}, __ls...)...); + } + + template <class _Fp, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix() { + return __make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<>{}, make_index_sequence<decay_t<_Vs>::__size()>{}...); + } +}; + +struct __variant { + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __base::__visit_alt_at(__index, + _VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __visit_alt_at( + __index, + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + + template <class _Visitor, class... _Vs> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_value(_Visitor&& __visitor, + _Vs&&... __vs) { + return __visit_alt( + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + +private: + template <class _Visitor, class... _Values> + static constexpr void __std_visit_exhaustive_visitor_check() { + static_assert(is_invocable_v<_Visitor, _Values...>, + "`std::visit` requires the visitor to be exhaustive."); + } + + template <class _Visitor> + struct __value_visitor { + template <class... _Alts> + inline _LIBCPP_INLINE_VISIBILITY + constexpr decltype(auto) operator()(_Alts&&... __alts) const { + __std_visit_exhaustive_visitor_check< + _Visitor, + decltype((_VSTD::forward<_Alts>(__alts).__value))...>(); + return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Alts>(__alts).__value...); + } + _Visitor&& __visitor; + }; + + template <class _Visitor> + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_value_visitor(_Visitor&& __visitor) { + return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)}; + } +}; + +} // namespace __visitation + +template <size_t _Index, class _Tp> +struct _LIBCPP_TEMPLATE_VIS __alt { + using __value_type = _Tp; + + template <class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __alt(in_place_t, _Args&&... __args) + : __value(_VSTD::forward<_Args>(__args)...) {} + + __value_type __value; +}; + +template <_Trait _DestructibleTrait, size_t _Index, class... _Types> +union _LIBCPP_TEMPLATE_VIS __union; + +template <_Trait _DestructibleTrait, size_t _Index> +union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {}; + +#define _LIBCPP_VARIANT_UNION(destructible_trait, destructor) \ + template <size_t _Index, class _Tp, class... _Types> \ + union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, \ + _Index, \ + _Tp, \ + _Types...> { \ + public: \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \ + \ + template <class... _Args> \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \ + : __head(in_place, _VSTD::forward<_Args>(__args)...) {} \ + \ + template <size_t _Ip, class... _Args> \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \ + : __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \ + \ + __union(const __union&) = default; \ + __union(__union&&) = default; \ + \ + destructor \ + \ + __union& operator=(const __union&) = default; \ + __union& operator=(__union&&) = default; \ + \ + private: \ + char __dummy; \ + __alt<_Index, _Tp> __head; \ + __union<destructible_trait, _Index + 1, _Types...> __tail; \ + \ + friend struct __access::__union; \ + } + +_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;); +_LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {}); +_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;); + +#undef _LIBCPP_VARIANT_UNION + +template <_Trait _DestructibleTrait, class... _Types> +class _LIBCPP_TEMPLATE_VIS __base { +public: + using __index_t = __variant_index_t<sizeof...(_Types)>; + + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(__valueless_t tag) noexcept + : __data(tag), __index(__variant_npos<__index_t>) {} + + template <size_t _Ip, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args) + : + __data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...), + __index(_Ip) {} + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return index() == variant_npos; + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { + return __index == __variant_npos<__index_t> ? variant_npos : __index; + } + +protected: + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + static constexpr size_t __size() { return sizeof...(_Types); } + + __union<_DestructibleTrait, 0, _Types...> __data; + __index_t __index; + + friend struct __access::__base; + friend struct __visitation::__base; +}; + +template <class _Traits, _Trait = _Traits::__destructible_trait> +class _LIBCPP_TEMPLATE_VIS __destructor; + +#define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \ + destructible_trait> \ + : public __base<destructible_trait, _Types...> { \ + using __base_type = __base<destructible_trait, _Types...>; \ + using __index_t = typename __base_type::__index_t; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __destructor(const __destructor&) = default; \ + __destructor(__destructor&&) = default; \ + destructor \ + __destructor& operator=(const __destructor&) = default; \ + __destructor& operator=(__destructor&&) = default; \ + \ + protected: \ + inline _LIBCPP_INLINE_VISIBILITY \ + destroy \ + } + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_TriviallyAvailable, + ~__destructor() = default;, + void __destroy() noexcept { this->__index = __variant_npos<__index_t>; }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Available, + ~__destructor() { __destroy(); }, + void __destroy() noexcept { + if (!this->valueless_by_exception()) { + __visitation::__base::__visit_alt( + [](auto& __alt) noexcept { + using __alt_type = decay_t<decltype(__alt)>; + __alt.~__alt_type(); + }, + *this); + } + this->__index = __variant_npos<__index_t>; + }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Unavailable, + ~__destructor() = delete;, + void __destroy() noexcept = delete;); + +#undef _LIBCPP_VARIANT_DESTRUCTOR + +template <class _Traits> +class _LIBCPP_TEMPLATE_VIS __constructor : public __destructor<_Traits> { + using __base_type = __destructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + +protected: + template <size_t _Ip, class _Tp, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + static _Tp& __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) { + ::new ((void*)_VSTD::addressof(__a)) + __alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...); + return __a.__value; + } + + template <class _Rhs> + inline _LIBCPP_INLINE_VISIBILITY + static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) { + __lhs.__destroy(); + if (!__rhs.valueless_by_exception()) { + __visitation::__base::__visit_alt_at( + __rhs.index(), + [](auto& __lhs_alt, auto&& __rhs_alt) { + __construct_alt( + __lhs_alt, + _VSTD::forward<decltype(__rhs_alt)>(__rhs_alt).__value); + }, + __lhs, _VSTD::forward<_Rhs>(__rhs)); + __lhs.__index = __rhs.index(); + } + } +}; + +template <class _Traits, _Trait = _Traits::__move_constructible_trait> +class _LIBCPP_TEMPLATE_VIS __move_constructor; + +#define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, \ + move_constructor) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, \ + move_constructible_trait> \ + : public __constructor<__traits<_Types...>> { \ + using __base_type = __constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_constructor(const __move_constructor&) = default; \ + move_constructor \ + ~__move_constructor() = default; \ + __move_constructor& operator=(const __move_constructor&) = default; \ + __move_constructor& operator=(__move_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __move_constructor(__move_constructor&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Available, + __move_constructor(__move_constructor&& __that) noexcept( + __all<is_nothrow_move_constructible_v<_Types>...>::value) + : __move_constructor(__valueless_t{}) { + this->__generic_construct(*this, _VSTD::move(__that)); + }); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Unavailable, + __move_constructor(__move_constructor&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR + +template <class _Traits, _Trait = _Traits::__copy_constructible_trait> +class _LIBCPP_TEMPLATE_VIS __copy_constructor; + +#define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, \ + copy_constructor) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, \ + copy_constructible_trait> \ + : public __move_constructor<__traits<_Types...>> { \ + using __base_type = __move_constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + copy_constructor \ + __copy_constructor(__copy_constructor&&) = default; \ + ~__copy_constructor() = default; \ + __copy_constructor& operator=(const __copy_constructor&) = default; \ + __copy_constructor& operator=(__copy_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __copy_constructor(const __copy_constructor& __that) = default;); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Available, + __copy_constructor(const __copy_constructor& __that) + : __copy_constructor(__valueless_t{}) { + this->__generic_construct(*this, __that); + }); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Unavailable, + __copy_constructor(const __copy_constructor&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR + +template <class _Traits> +class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> { + using __base_type = __copy_constructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template <size_t _Ip, class... _Args> + inline _LIBCPP_INLINE_VISIBILITY + auto& __emplace(_Args&&... __args) { + this->__destroy(); + auto& __res = this->__construct_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Args>(__args)...); + this->__index = _Ip; + return __res; + } + +protected: + template <size_t _Ip, class _Tp, class _Arg> + inline _LIBCPP_INLINE_VISIBILITY + void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) { + if (this->index() == _Ip) { + __a.__value = _VSTD::forward<_Arg>(__arg); + } else { + struct { + void operator()(true_type) const { + __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); + } + void operator()(false_type) const { + __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); + } + __assignment* __this; + _Arg&& __arg; + } __impl{this, _VSTD::forward<_Arg>(__arg)}; + __impl(bool_constant<is_nothrow_constructible_v<_Tp, _Arg> || + !is_nothrow_move_constructible_v<_Tp>>{}); + } + } + + template <class _That> + inline _LIBCPP_INLINE_VISIBILITY + void __generic_assign(_That&& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (__that.valueless_by_exception()) { + this->__destroy(); + } else { + __visitation::__base::__visit_alt_at( + __that.index(), + [this](auto& __this_alt, auto&& __that_alt) { + this->__assign_alt( + __this_alt, + _VSTD::forward<decltype(__that_alt)>(__that_alt).__value); + }, + *this, _VSTD::forward<_That>(__that)); + } + } +}; + +template <class _Traits, _Trait = _Traits::__move_assignable_trait> +class _LIBCPP_TEMPLATE_VIS __move_assignment; + +#define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, \ + move_assignment) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, \ + move_assignable_trait> \ + : public __assignment<__traits<_Types...>> { \ + using __base_type = __assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_assignment(const __move_assignment&) = default; \ + __move_assignment(__move_assignment&&) = default; \ + ~__move_assignment() = default; \ + __move_assignment& operator=(const __move_assignment&) = default; \ + move_assignment \ + } + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __move_assignment& operator=(__move_assignment&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Available, + __move_assignment& operator=(__move_assignment&& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_move_assignable_v<_Types>)...>::value) { + this->__generic_assign(_VSTD::move(__that)); + return *this; + }); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Unavailable, + __move_assignment& operator=(__move_assignment&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT + +template <class _Traits, _Trait = _Traits::__copy_assignable_trait> +class _LIBCPP_TEMPLATE_VIS __copy_assignment; + +#define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, \ + copy_assignment) \ + template <class... _Types> \ + class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, \ + copy_assignable_trait> \ + : public __move_assignment<__traits<_Types...>> { \ + using __base_type = __move_assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __copy_assignment(const __copy_assignment&) = default; \ + __copy_assignment(__copy_assignment&&) = default; \ + ~__copy_assignment() = default; \ + copy_assignment \ + __copy_assignment& operator=(__copy_assignment&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __copy_assignment& operator=(const __copy_assignment& __that) = default;); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Available, + __copy_assignment& operator=(const __copy_assignment& __that) { + this->__generic_assign(__that); + return *this; + }); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Unavailable, + __copy_assignment& operator=(const __copy_assignment&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_ASSIGNMENT + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS __impl + : public __copy_assignment<__traits<_Types...>> { + using __base_type = __copy_assignment<__traits<_Types...>>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template <size_t _Ip, class _Arg> + inline _LIBCPP_INLINE_VISIBILITY + void __assign(_Arg&& __arg) { + this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Arg>(__arg)); + } + + inline _LIBCPP_INLINE_VISIBILITY + void __swap(__impl& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (this->index() == __that.index()) { + __visitation::__base::__visit_alt_at( + this->index(), + [](auto& __this_alt, auto& __that_alt) { + using _VSTD::swap; + swap(__this_alt.__value, __that_alt.__value); + }, + *this, + __that); + } else { + __impl* __lhs = this; + __impl* __rhs = _VSTD::addressof(__that); + if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) { + _VSTD::swap(__lhs, __rhs); + } + __impl __tmp(_VSTD::move(*__rhs)); +#ifndef _LIBCPP_NO_EXCEPTIONS + // EXTENSION: When the move construction of `__lhs` into `__rhs` throws + // and `__tmp` is nothrow move constructible then we move `__tmp` back + // into `__rhs` and provide the strong exception safety guarentee. + try { + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); + } catch (...) { + if (__tmp.__move_nothrow()) { + this->__generic_construct(*__rhs, _VSTD::move(__tmp)); + } + throw; + } +#else + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); +#endif + this->__generic_construct(*__lhs, _VSTD::move(__tmp)); + } + } + +private: + inline _LIBCPP_INLINE_VISIBILITY + bool __move_nothrow() const { + constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...}; + return this->valueless_by_exception() || __results[this->index()]; + } +}; + +template <class... _Types> +struct __overload; + +template <> +struct __overload<> { void operator()() const; }; + +template <class _Tp, class... _Types> +struct __overload<_Tp, _Types...> : __overload<_Types...> { + using __overload<_Types...>::operator(); + __identity<_Tp> operator()(_Tp) const; +}; + +template <class _Tp, class... _Types> +using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; + +} // __variant_detail + +template <class... _Types> +class _LIBCPP_TEMPLATE_VIS variant + : private __sfinae_ctor_base< + __all<is_copy_constructible_v<_Types>...>::value, + __all<is_move_constructible_v<_Types>...>::value>, + private __sfinae_assign_base< + __all<(is_copy_constructible_v<_Types> && + is_copy_assignable_v<_Types>)...>::value, + __all<(is_move_constructible_v<_Types> && + is_move_assignable_v<_Types>)...>::value> { + static_assert(0 < sizeof...(_Types), + "variant must consist of at least one alternative."); + + static_assert(__all<!is_array_v<_Types>...>::value, + "variant can not have an array type as an alternative."); + + static_assert(__all<!is_reference_v<_Types>...>::value, + "variant can not have a reference type as an alternative."); + + static_assert(__all<!is_void_v<_Types>...>::value, + "variant can not have a void type as an alternative."); + + using __first_type = variant_alternative_t<0, variant>; + +public: + template <bool _Dummy = true, + enable_if_t<__dependent_type<is_default_constructible<__first_type>, + _Dummy>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>) + : __impl(in_place_index<0>) {} + + variant(const variant&) = default; + variant(variant&&) = default; + + template < + class _Arg, + enable_if_t<!is_same_v<decay_t<_Arg>, variant>, int> = 0, + enable_if_t<!__is_inplace_type<decay_t<_Arg>>::value, int> = 0, + enable_if_t<!__is_inplace_index<decay_t<_Arg>>::value, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Arg>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant(_Arg&& __arg) noexcept( + is_nothrow_constructible_v<_Tp, _Arg>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {} + + template <size_t _Ip, class... _Args, + class = enable_if_t<(_Ip < sizeof...(_Types)), int>, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_type_t<_Tp>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + ~variant() = default; + + variant& operator=(const variant&) = default; + variant& operator=(variant&&) = default; + + template < + class _Arg, + enable_if_t<!is_same_v<decay_t<_Arg>, variant>, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_assignable_v<_Tp&, _Arg> && is_constructible_v<_Tp, _Arg>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + variant& operator=(_Arg&& __arg) noexcept( + is_nothrow_assignable_v<_Tp&, _Arg> && + is_nothrow_constructible_v<_Tp, _Arg>) { + __impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg)); + return *this; + } + + template < + size_t _Ip, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... __args) { + return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { + return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(_Args&&... __args) { + return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { + return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return __impl.valueless_by_exception(); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { return __impl.index(); } + + template < + bool _Dummy = true, + enable_if_t< + __all<( + __dependent_type<is_move_constructible<_Types>, _Dummy>::value && + __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void swap(variant& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_swappable_v<_Types>)...>::value) { + __impl.__swap(__that.__impl); + } + +private: + __variant_detail::__impl<_Types...> __impl; + + friend struct __variant_detail::__access::__variant; + friend struct __variant_detail::__visitation::__variant; +}; + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept { + return __v.index() == _Ip; +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept { + return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <size_t _Ip, class _Vp> +inline _LIBCPP_INLINE_VISIBILITY +static constexpr auto&& __generic_get(_Vp&& __v) { + using __variant_detail::__access::__variant; + if (!__holds_alternative<_Ip>(__v)) { + __throw_bad_variant_access(); + } + return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value; +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr variant_alternative_t<_Ip, variant<_Types...>>& get( + variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get( + variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get( + const variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get( + const variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp& get(variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp&& get(variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr const _Tp& get(const variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr const _Tp&& get(const variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template <size_t _Ip, class _Vp> +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto* __generic_get_if(_Vp* __v) noexcept { + using __variant_detail::__access::__variant; + return __v && __holds_alternative<_Ip>(*__v) + ? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value) + : nullptr; +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<variant_alternative_t<_Ip, variant<_Types...>>> +get_if(variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get_if<_Ip>(__v); +} + +template <size_t _Ip, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<const variant_alternative_t<_Ip, variant<_Types...>>> +get_if(const variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>); + return __generic_get_if<_Ip>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<_Tp> +get_if(variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class _Tp, class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<const _Tp> +get_if(const variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return false; + if (__lhs.valueless_by_exception()) return true; + return __variant::__visit_value_at(__lhs.index(), equal_to<>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return true; + if (__lhs.valueless_by_exception()) return false; + return __variant::__visit_value_at( + __lhs.index(), not_equal_to<>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.valueless_by_exception()) return true; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), less<>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return false; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), greater<>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return true; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), less_equal<>{}, __lhs, __rhs); +} + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.valueless_by_exception()) return false; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), greater_equal<>{}, __lhs, __rhs); +} + +template <class _Visitor, class... _Vs> +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) { + using __variant_detail::__visitation::__variant; + bool __results[] = {__vs.valueless_by_exception()...}; + for (bool __result : __results) { + if (__result) { + __throw_bad_variant_access(); + } + } + return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs)...); +} + +struct _LIBCPP_TEMPLATE_VIS monostate {}; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(monostate, monostate) noexcept { return false; } + +template <class... _Types> +inline _LIBCPP_INLINE_VISIBILITY +auto swap(variant<_Types...>& __lhs, + variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) + -> decltype(__lhs.swap(__rhs)) { + __lhs.swap(__rhs); +} + +template <class... _Types> +struct _LIBCPP_TEMPLATE_VIS hash< + __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> { + using argument_type = variant<_Types...>; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __v) const { + using __variant_detail::__visitation::__variant; + size_t __res = + __v.valueless_by_exception() + ? 299792458 // Random value chosen by the universe upon creation + : __variant::__visit_alt( + [](const auto& __alt) { + using __alt_type = decay_t<decltype(__alt)>; + using __value_type = remove_const_t< + typename __alt_type::__value_type>; + return hash<__value_type>{}(__alt.__value); + }, + __v); + return __hash_combine(__res, hash<size_t>{}(__v.index())); + } +}; + +template <> +struct _LIBCPP_TEMPLATE_VIS hash<monostate> { + using argument_type = monostate; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type&) const _NOEXCEPT { + return 66740831; // return a fundamentally attractive random value. + } +}; + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_VARIANT diff --git a/lib/libcxx/include/vector b/lib/libcxx/include/vector index 021bbfb6643..54b1e8831d5 100644 --- a/lib/libcxx/include/vector +++ b/lib/libcxx/include/vector @@ -99,7 +99,7 @@ public: void push_back(const value_type& x); void push_back(value_type&& x); template <class... Args> - void emplace_back(Args&&... args); + reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); template <class... Args> iterator emplace(const_iterator position, Args&&... args); @@ -218,7 +218,7 @@ public: const_reference back() const; void push_back(const value_type& x); - template <class... Args> void emplace_back(Args&&... args); // C++14 + template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 @@ -275,14 +275,16 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) #include <__split_buffer> #include <__functional_base> -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD template <bool> @@ -290,40 +292,25 @@ class __vector_base_common { protected: _LIBCPP_ALWAYS_INLINE __vector_base_common() {} - void __throw_length_error() const; - void __throw_out_of_range() const; + _LIBCPP_NORETURN void __throw_length_error() const; + _LIBCPP_NORETURN void __throw_out_of_range() const; }; template <bool __b> void __vector_base_common<__b>::__throw_length_error() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw length_error("vector"); -#else - assert(!"vector length_error"); -#endif + _VSTD::__throw_length_error("vector"); } template <bool __b> void __vector_base_common<__b>::__throw_out_of_range() const { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw out_of_range("vector"); -#else - assert(!"vector out_of_range"); -#endif + _VSTD::__throw_out_of_range("vector"); } -#ifdef _LIBCPP_MSVC -#pragma warning( push ) -#pragma warning( disable: 4231 ) -#endif // _LIBCPP_MSVC -_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC +_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>) template <class _Tp, class _Allocator> class __vector_base @@ -421,8 +408,10 @@ inline _LIBCPP_INLINE_VISIBILITY void __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { - while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); + pointer __soon_to_be_end = __end_; + while (__new_last != __soon_to_be_end) + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end)); + __end_ = __new_last; } template <class _Tp, class _Allocator> @@ -455,7 +444,7 @@ __vector_base<_Tp, _Allocator>::~__vector_base() } template <class _Tp, class _Allocator /* = allocator<_Tp> */> -class _LIBCPP_TYPE_VIS_ONLY vector +class _LIBCPP_TEMPLATE_VIS vector : private __vector_base<_Tp, _Allocator> { private: @@ -533,12 +522,7 @@ public: is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - vector(initializer_list<value_type> __il); - _LIBCPP_INLINE_VISIBILITY - vector(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY ~vector() @@ -551,7 +535,14 @@ public: vector(const vector& __x, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector& operator=(const vector& __x); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il); + + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY vector(vector&& __x) #if _LIBCPP_STD_VER > 14 @@ -559,17 +550,18 @@ public: #else _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); #endif + _LIBCPP_INLINE_VISIBILITY vector(vector&& __x, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector& operator=(vector&& __x) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY vector& operator=(initializer_list<value_type> __il) {assign(__il.begin(), __il.end()); return *this;} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#endif // !_LIBCPP_CXX03_LANG template <class _InputIterator> typename enable_if @@ -594,11 +586,12 @@ public: assign(_ForwardIterator __first, _ForwardIterator __last); void assign(size_type __n, const_reference __u); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT @@ -641,7 +634,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return __base::capacity();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return this->__begin_ == this->__end_;} size_type max_size() const _NOEXCEPT; @@ -681,26 +674,42 @@ public: const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(this->__begin_);} +#ifdef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(const value_type& __x) { push_back(__x); } +#else + template <class _Arg> + _LIBCPP_INLINE_VISIBILITY + void __emplace_back(_Arg&& __arg) { + emplace_back(_VSTD::forward<_Arg>(__arg)); + } +#endif + _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); -#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> _LIBCPP_INLINE_VISIBILITY - void emplace_back(_Args&&... __args); -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_STD_VER > 14 + reference emplace_back(_Args&&... __args); +#else + void emplace_back(_Args&&... __args); +#endif +#endif // !_LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY void pop_back(); iterator insert(const_iterator __position, const_reference __x); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#ifndef _LIBCPP_CXX03_LANG iterator insert(const_iterator __position, value_type&& __x); -#ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args> iterator emplace(const_iterator __position, _Args&&... __args); -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG + iterator insert(const_iterator __position, size_type __n, const_reference __x); template <class _InputIterator> typename enable_if @@ -723,11 +732,12 @@ public: iterator >::type insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __position, initializer_list<value_type> __il) {return insert(__position, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); iterator erase(const_iterator __first, const_iterator __last); @@ -746,9 +756,9 @@ public: void swap(vector&) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT; + _NOEXCEPT_DEBUG; #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -765,6 +775,7 @@ public: private: _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); void allocate(size_type __n); void deallocate() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; @@ -794,65 +805,59 @@ private: _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(pointer __new_last) _NOEXCEPT { -#if _LIBCPP_DEBUG_LEVEL >= 2 - __c_node* __c = __get_db()->__find_c_and_lock(this); - for (__i_node** __p = __c->end_; __p != __c->beg_; ) - { - --__p; - const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->base() > __new_last) - { - (*__p)->__c_ = nullptr; - if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); - } - } - __get_db()->unlock(); -#endif + __invalidate_iterators_past(__new_last); size_type __old_size = size(); __base::__destruct_at_end(__new_last); __annotate_shrink(__old_size); } - template <class _Up> - void -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - __push_back_slow_path(_Up&& __x); -#else - __push_back_slow_path(_Up& __x); -#endif -#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) + +#ifndef _LIBCPP_CXX03_LANG + template <class _Up> void __push_back_slow_path(_Up&& __x); + template <class... _Args> - void - __emplace_back_slow_path(_Args&&... __args); + void __emplace_back_slow_path(_Args&&... __args); +#else + template <class _Up> void __push_back_slow_path(_Up& __x); #endif + // The following functions are no-ops outside of AddressSanitizer mode. // We call annotatations only for the default Allocator because other allocators // may not meet the AddressSanitizer alignment constraints. // See the documentation for __sanitizer_annotate_contiguous_container for more details. - void __annotate_contiguous_container - (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const - { #ifndef _LIBCPP_HAS_NO_ASAN + void __annotate_contiguous_container(const void *__beg, const void *__end, + const void *__old_mid, + const void *__new_mid) const + { + if (__beg && is_same<allocator_type, __default_allocator_type>::value) __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); -#endif } - - void __annotate_new(size_type __current_size) const - { +#else + _LIBCPP_INLINE_VISIBILITY + void __annotate_contiguous_container(const void*, const void*, const void*, + const void*) const {} +#endif + _LIBCPP_INLINE_VISIBILITY + void __annotate_new(size_type __current_size) const { __annotate_contiguous_container(data(), data() + capacity(), data() + capacity(), data() + __current_size); } - void __annotate_delete() const - { + + _LIBCPP_INLINE_VISIBILITY + void __annotate_delete() const { __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + capacity()); } + + _LIBCPP_INLINE_VISIBILITY void __annotate_increase(size_type __n) const { __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + size() + __n); } + + _LIBCPP_INLINE_VISIBILITY void __annotate_shrink(size_type __old_size) const { __annotate_contiguous_container(data(), data() + capacity(), @@ -877,8 +882,9 @@ private: }; #else struct __RAII_IncreaseAnnotator { - inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {} - inline void __done() {} + _LIBCPP_INLINE_VISIBILITY + __RAII_IncreaseAnnotator(const vector &, size_type = 1) {} + _LIBCPP_INLINE_VISIBILITY void __done() {} }; #endif @@ -949,7 +955,8 @@ template <class _Tp, class _Allocator> typename vector<_Tp, _Allocator>::size_type vector<_Tp, _Allocator>::max_size() const _NOEXCEPT { - return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always + return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), + numeric_limits<difference_type>::max()); } // Precondition: __new_size > capacity() @@ -1132,7 +1139,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, __get_db()->__insert_c(this); #endif for (; __first != __last; ++__first) - push_back(*__first); + __emplace_back(*__first); } template <class _Tp, class _Allocator> @@ -1149,7 +1156,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c __get_db()->__insert_c(this); #endif for (; __first != __last; ++__first) - push_back(*__first); + __emplace_back(*__first); } template <class _Tp, class _Allocator> @@ -1222,7 +1229,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) } } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -1269,8 +1276,6 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) } } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) @@ -1300,8 +1305,6 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat } } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>& @@ -1343,7 +1346,7 @@ vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -1373,7 +1376,7 @@ vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { clear(); for (; __first != __last; ++__first) - push_back(*__first); + __emplace_back(*__first); } template <class _Tp, class _Allocator> @@ -1411,6 +1414,7 @@ vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __las allocate(__recommend(__new_size)); __construct_at_end(__first, __last, __new_size); } + __invalidate_all_iterators(); } template <class _Tp, class _Allocator> @@ -1432,6 +1436,7 @@ vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) allocate(__recommend(static_cast<size_type>(__n))); __construct_at_end(__n, __u); } + __invalidate_all_iterators(); } template <class _Tp, class _Allocator> @@ -1563,7 +1568,7 @@ vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT template <class _Tp, class _Allocator> template <class _Up> void -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) #else vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) @@ -1594,7 +1599,7 @@ vector<_Tp, _Allocator>::push_back(const_reference __x) __push_back_slow_path(__x); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -1614,8 +1619,6 @@ vector<_Tp, _Allocator>::push_back(value_type&& __x) __push_back_slow_path(_VSTD::move(__x)); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Allocator> template <class... _Args> void @@ -1632,7 +1635,11 @@ vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) template <class _Tp, class _Allocator> template <class... _Args> inline +#if _LIBCPP_STD_VER > 14 +typename vector<_Tp, _Allocator>::reference +#else void +#endif vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) { if (this->__end_ < this->__end_cap()) @@ -1646,10 +1653,12 @@ vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) } else __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); +#if _LIBCPP_STD_VER > 14 + return this->back(); +#endif } -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> inline @@ -1674,8 +1683,9 @@ vector<_Tp, _Allocator>::erase(const_iterator __position) "vector::erase(iterator) called with a non-dereferenceable iterator"); 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)); + this->__invalidate_iterators_past(__p-1); + iterator __r = __make_iter(__p); return __r; } @@ -1687,12 +1697,17 @@ vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, "vector::erase(iterator, iterator) called with an iterator not" " referring to this vector"); + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, + "vector::erase(iterator, iterator) called with an iterator not" + " referring to this vector"); #endif _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); pointer __p = this->__begin_ + (__first - begin()); - iterator __r = __make_iter(__p); - if (__first != __last) + if (__first != __last) { this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); + this->__invalidate_iterators_past(__p - 1); + } + iterator __r = __make_iter(__p); return __r; } @@ -1748,7 +1763,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) return __make_iter(__p); } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> typename vector<_Tp, _Allocator>::iterator @@ -1787,8 +1802,6 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) return __make_iter(__p); } -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Tp, class _Allocator> template <class... _Args> typename vector<_Tp, _Allocator>::iterator @@ -1828,8 +1841,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) return __make_iter(__p); } -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG template <class _Tp, class _Allocator> typename vector<_Tp, _Allocator>::iterator @@ -2013,9 +2025,9 @@ template <class _Tp, class _Allocator> void vector<_Tp, _Allocator>::swap(vector& __x) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT + _NOEXCEPT_DEBUG #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { @@ -2026,7 +2038,7 @@ vector<_Tp, _Allocator>::swap(vector& __x) _VSTD::swap(this->__begin_, __x.__begin_); _VSTD::swap(this->__end_, __x.__end_); _VSTD::swap(this->__end_cap(), __x.__end_cap()); - __swap_allocator(this->__alloc(), __x.__alloc(), + __swap_allocator(this->__alloc(), __x.__alloc(), integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__x); @@ -2098,6 +2110,28 @@ vector<_Tp, _Allocator>::__invalidate_all_iterators() #endif // _LIBCPP_DEBUG_LEVEL >= 2 } + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#else + ((void)__new_last); +#endif +} + // vector<bool> template <class _Allocator> class vector<bool, _Allocator>; @@ -2111,7 +2145,7 @@ struct __has_storage_type<vector<bool, _Allocator> > }; template <class _Allocator> -class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator> +class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> : private __vector_base_common<true> { public: @@ -2199,12 +2233,11 @@ public: vector(const vector& __v); vector(const vector& __v, const allocator_type& __a); vector& operator=(const vector& __v); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_CXX03_LANG vector(initializer_list<value_type> __il); vector(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY vector(vector&& __v) #if _LIBCPP_STD_VER > 14 @@ -2216,12 +2249,12 @@ public: _LIBCPP_INLINE_VISIBILITY vector& operator=(vector&& __v) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY vector& operator=(initializer_list<value_type> __il) {assign(__il.begin(), __il.end()); return *this;} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#endif // !_LIBCPP_CXX03_LANG template <class _InputIterator> typename enable_if @@ -2240,11 +2273,12 @@ public: assign(_ForwardIterator __first, _ForwardIterator __last); void assign(size_type __n, const value_type& __x); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(this->__alloc());} @@ -2256,7 +2290,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __size_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __size_ == 0;} void reserve(size_type __n); @@ -2314,8 +2348,17 @@ public: void push_back(const value_type& __x); #if _LIBCPP_STD_VER > 11 template <class... _Args> - _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) - { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); } +#if _LIBCPP_STD_VER > 14 + _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) +#else + _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) +#endif + { + push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); +#if _LIBCPP_STD_VER > 14 + return this->back(); +#endif + } #endif _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} @@ -2344,11 +2387,12 @@ public: iterator >::type insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __position, initializer_list<value_type> __il) {return insert(__position, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); iterator erase(const_iterator __first, const_iterator __last); @@ -2360,7 +2404,7 @@ public: #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } @@ -2448,7 +2492,7 @@ private: friend class __bit_iterator<vector, false>; friend class __bit_iterator<vector, true>; friend struct __bit_array<vector>; - friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>; + friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; }; template <class _Allocator> @@ -2708,7 +2752,7 @@ vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __la } } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _Allocator> vector<bool, _Allocator>::vector(initializer_list<value_type> __il) @@ -2738,7 +2782,7 @@ vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const alloca } } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _Allocator> vector<bool, _Allocator>::~vector() @@ -2795,7 +2839,7 @@ vector<bool, _Allocator>::operator=(const vector& __v) return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -2870,7 +2914,7 @@ vector<bool, _Allocator>::__move_assign(vector& __c, true_type) __c.__cap() = __c.__size_ = 0; } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !_LIBCPP_CXX03_LANG template <class _Allocator> void @@ -2891,6 +2935,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) } _VSTD::fill_n(begin(), __n, __x); } + __invalidate_all_iterators(); } template <class _Allocator> @@ -2918,7 +2963,9 @@ typename enable_if vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) { clear(); - difference_type __n = _VSTD::distance(__first, __last); + difference_type __ns = _VSTD::distance(__first, __last); + _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); + const size_t __n = static_cast<size_type>(__ns); if (__n) { if (__n > capacity()) @@ -3097,7 +3144,9 @@ typename enable_if >::type vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) { - difference_type __n = _VSTD::distance(__first, __last); + const difference_type __n_signed = _VSTD::distance(__first, __last); + _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); + const size_type __n = static_cast<size_type>(__n_signed); iterator __r; size_type __c = capacity(); if (__n <= __c && size() <= __c - __n) @@ -3148,14 +3197,14 @@ vector<bool, _Allocator>::swap(vector& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else - _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { _VSTD::swap(this->__begin_, __x.__begin_); _VSTD::swap(this->__size_, __x.__size_); _VSTD::swap(this->__cap(), __x.__cap()); - __swap_allocator(this->__alloc(), __x.__alloc(), + __swap_allocator(this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); } @@ -3246,7 +3295,7 @@ vector<bool, _Allocator>::__hash_code() const _NOEXCEPT } template <class _Allocator> -struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> > +struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > : public unary_function<vector<bool, _Allocator>, size_t> { _LIBCPP_INLINE_VISIBILITY @@ -3314,4 +3363,6 @@ swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_VECTOR diff --git a/lib/libcxx/include/wchar.h b/lib/libcxx/include/wchar.h index c0c6ef754fb..f74fe6ddcff 100644 --- a/lib/libcxx/include/wchar.h +++ b/lib/libcxx/include/wchar.h @@ -125,6 +125,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, # if __GLIBC_PREREQ(2, 10) # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 # endif +#elif defined(_LIBCPP_MSVCRT) +# if defined(_CRT_CONST_CORRECT_OVERLOADS) +# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 +# endif #endif #if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) @@ -166,9 +170,12 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD } #endif -#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)) -extern "C++" { -#include <support/win32/support.h> // pull in *swprintf defines +#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE) +extern "C" { +size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, + size_t nmc, size_t len, mbstate_t *__restrict ps); +size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, + size_t nwc, size_t len, mbstate_t *__restrict ps); } // extern "C++" #endif // __cplusplus && _LIBCPP_MSVCRT |