Index: vendor/libc++/dist/docs/DesignDocs/VisibilityMacros.rst =================================================================== --- vendor/libc++/dist/docs/DesignDocs/VisibilityMacros.rst (revision 321189) +++ vendor/libc++/dist/docs/DesignDocs/VisibilityMacros.rst (revision 321190) @@ -1,162 +1,163 @@ ======================== Symbol Visibility Macros ======================== .. contents:: :local: Overview ======== Libc++ uses various "visibility" macros in order to provide a stable ABI in both the library and the headers. These macros work by changing the visibility and inlining characteristics of the symbols they are applied to. Visibility Macros ================= **_LIBCPP_HIDDEN** Mark a symbol as hidden so it will not be exported from shared libraries. **_LIBCPP_FUNC_VIS** Mark a symbol as being exported by the libc++ library. This attribute must be applied to the declaration of all functions exported by the libc++ dylib. **_LIBCPP_EXTERN_VIS** Mark a symbol as being exported by the libc++ library. This attribute may only be applied to objects defined in the libc++ library. On Windows this macro applies `dllimport`/`dllexport` to the symbol. On all other platforms this macro has no effect. **_LIBCPP_OVERRIDABLE_FUNC_VIS** Mark a symbol as being exported by the libc++ library, but allow it to be overridden locally. On non-Windows, this is equivalent to `_LIBCPP_FUNC_VIS`. This macro is applied to all `operator new` and `operator delete` overloads. **Windows Behavior**: Any symbol marked `dllimport` cannot be overridden locally, since `dllimport` indicates the symbol should be bound to a separate DLL. All `operator new` and `operator delete` overloads are required to be locally overridable, and therefore must not be marked `dllimport`. On Windows, this macro therefore expands to `__declspec(dllexport)` when building the library and has an empty definition otherwise. **_LIBCPP_INLINE_VISIBILITY** Mark a function as hidden and force inlining whenever possible. **_LIBCPP_ALWAYS_INLINE** A synonym for `_LIBCPP_INLINE_VISIBILITY` **_LIBCPP_TYPE_VIS** Mark a type's typeinfo, vtable and members as having default visibility. This attribute cannot be used on class templates. **_LIBCPP_TEMPLATE_VIS** Mark a type's typeinfo and vtable as having default visibility. This macro has no effect on the visibility of the type's member functions. **GCC Behavior**: GCC does not support Clang's `type_visibility(...)` attribute. With GCC the `visibility(...)` attribute is used and member functions are affected. **Windows Behavior**: DLLs do not support dllimport/export on class templates. The macro has an empty definition on this platform. **_LIBCPP_ENUM_VIS** Mark the typeinfo of an enum as having default visibility. This attribute should be applied to all enum declarations. **Windows Behavior**: DLLs do not support importing or exporting enumeration typeinfo. The macro has an empty definition on this platform. **GCC Behavior**: GCC un-hides the typeinfo for enumerations by default, even if `-fvisibility=hidden` is specified. Additionally applying a visibility attribute to an enum class results in a warning. The macro has an empty definition with GCC. **_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS** Mark the member functions, typeinfo, and vtable of the type named in a `_LIBCPP_EXTERN_TEMPLATE` declaration as being exported by the libc++ library. This attribute must be specified on all extern class template declarations. This macro is used to override the `_LIBCPP_TEMPLATE_VIS` attribute specified on the primary template and to export the member functions produced by the explicit instantiation in the dylib. **GCC Behavior**: GCC ignores visibility attributes applied the type in extern template declarations and applying an attribute results in a warning. However since `_LIBCPP_TEMPLATE_VIS` is the same as `__attribute__((visibility("default"))` the visibility is already correct. The macro has an empty definition with GCC. **Windows Behavior**: `extern template` and `dllexport` are fundamentally - incompatible *on a template class* on Windows; the former suppresses + incompatible *on a class template* on Windows; the former suppresses instantiation, while the latter forces it. Specifying both on the same - declaration makes the template class be instantiated, which is not desirable + declaration makes the class template be instantiated, which is not desirable inside headers. This macro therefore expands to `dllimport` outside of libc++ but nothing inside of it (rather than expanding to `dllexport`); instead, the explicit instantiations themselves are marked as exported. Note that this - applies *only* to extern template *classes*. Extern template *functions* obey + applies *only* to extern *class* templates. Extern *function* templates obey regular import/export semantics, and applying `dllexport` directly to the - extern template declaration is the correct thing to do for them. + extern template declaration (i.e. using `_LIBCPP_FUNC_VIS`) is the correct + thing to do for them. **_LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS** Mark the member functions, typeinfo, and vtable of an explicit instantiation of a class template as being exported by the libc++ library. This attribute - must be specified on all template class explicit instantiations. + must be specified on all class template explicit instantiations. It is only necessary to mark the explicit instantiation itself (as opposed to the extern template declaration) as exported on Windows, as discussed above. On all other platforms, this macro has an empty definition. **_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS** Mark a symbol as hidden so it will not be exported from shared libraries. This is intended specifically for method templates of either classes marked with `_LIBCPP_TYPE_VIS` or classes with an extern template instantiation declaration marked with `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS`. When building libc++ with hidden visibility, we want explicit template instantiations to export members, which is consistent with existing Windows behavior. We also want classes annotated with `_LIBCPP_TYPE_VIS` to export their members, which is again consistent with existing Windows behavior. Both these changes are necessary for clients to be able to link against a libc++ DSO built with hidden visibility without encountering missing symbols. An unfortunate side effect, however, is that method templates of classes either marked `_LIBCPP_TYPE_VIS` or with extern template instantiation declarations marked with `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS` also get default visibility when instantiated. These methods are often implicitly instantiated inside other libraries which use the libc++ headers, and will therefore end up being exported from those libraries, since those implicit instantiations will receive default visibility. This is not acceptable for libraries that wish to control their visibility, and led to PR30642. Consequently, all such problematic method templates are explicitly marked either hidden (via this macro) or inline, so that they don't leak into client libraries. The problematic methods were found by running `bad-visibility-finder `_ against the libc++ headers after making `_LIBCPP_TYPE_VIS` and `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS` expand to default visibility. **_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY** Mark a member function of a class template as visible and always inline. This macro should only be applied to member functions of class templates that are externally instantiated. It is important that these symbols are not marked as hidden as that will prevent the dylib definition from being found. This macro is used to maintain ABI compatibility for symbols that have been historically exported by the libc++ library but are now marked inline. **_LIBCPP_EXCEPTION_ABI** Mark the member functions, typeinfo, and vtable of the type as being exported by the libc++ library. This macro must be applied to all *exception types*. Exception types should be defined directly in namespace `std` and not the versioning namespace. This allows throwing and catching some exception types between libc++ and libstdc++. Links ===== * `[cfe-dev] Visibility in libc++ - 1 `_ * `[cfe-dev] Visibility in libc++ - 2 `_ * `[libcxx] Visibility fixes for Windows `_ Index: vendor/libc++/dist/include/__config =================================================================== --- vendor/libc++/dist/include/__config (revision 321189) +++ vendor/libc++/dist/include/__config (revision 321190) @@ -1,1249 +1,1247 @@ // -*- C++ -*- //===--------------------------- __config ---------------------------------===// // // 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_CONFIG #define _LIBCPP_CONFIG #if defined(_MSC_VER) && !defined(__clang__) #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #endif #endif #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #pragma GCC system_header #endif #ifdef __cplusplus #ifdef __GNUC__ #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) // The _GNUC_VER_NEW macro better represents the new GCC versioning scheme // introduced in GCC 5.0. #define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__) #else #define _GNUC_VER 0 #define _GNUC_VER_NEW 0 #endif #define _LIBCPP_VERSION 5000 #ifndef _LIBCPP_ABI_VERSION #define _LIBCPP_ABI_VERSION 1 #endif #if defined(__ELF__) #define _LIBCPP_OBJECT_FORMAT_ELF 1 #elif defined(__MACH__) #define _LIBCPP_OBJECT_FORMAT_MACHO 1 #elif defined(_WIN32) #define _LIBCPP_OBJECT_FORMAT_COFF 1 #else #error Unknown object file format #endif #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2 // Change short string representation so that string data starts at offset 0, // improving its alignment in some cases. #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT // Fix deque iterator type in order to support incomplete types. #define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE // Fix undefined behavior in how std::list stores it's linked nodes. #define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB // Fix undefined behavior in how __tree stores its end and parent nodes. #define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB // Fix undefined behavior in how __hash_table stores it's pointer types #define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB #define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE // Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr // provided under the alternate keyword __nullptr, which changes the mangling // of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. #define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR // Define the `pointer_safety` enum as a C++11 strongly typed enumeration // instead of as a class simulating an enum. If this option is enabled // `pointer_safety` and `get_pointer_safety()` will no longer be available // in C++03. #define _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE // Define a key function for `bad_function_call` in the library, to centralize // its vtable and typeinfo to libc++ rather than having all other libraries // using that class define their own copies. #define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION // Enable optimized version of __do_get_(un)signed which avoids redundant copies. #define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET #elif _LIBCPP_ABI_VERSION == 1 #if !defined(_LIBCPP_OBJECT_FORMAT_COFF) // Enable compiling copies of now inline methods into the dylib to support // applications compiled against older libraries. This is unnecessary with // COFF dllexport semantics, since dllexport forces a non-inline definition // of inline functions to be emitted anyway. Our own non-inline copy would // conflict with the dllexport-emitted copy, so we disable it. #define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS #endif // Feature macros for disabling pre ABI v1 features. All of these options // are deprecated. #if defined(__FreeBSD__) #define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR #endif #endif #ifdef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR #error "_LIBCPP_TRIVIAL_PAIR_COPY_CTOR" is no longer supported. \ use _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR instead #endif #define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y #define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) #define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) #if __cplusplus < 201103L #define _LIBCPP_CXX03_LANG #endif #ifndef __has_attribute #define __has_attribute(__x) 0 #endif #ifndef __has_builtin #define __has_builtin(__x) 0 #endif #ifndef __has_extension #define __has_extension(__x) 0 #endif #ifndef __has_feature #define __has_feature(__x) 0 #endif // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by // the compiler and '1' otherwise. #ifndef __is_identifier #define __is_identifier(__x) 1 #endif #ifndef __has_declspec_attribute #define __has_declspec_attribute(__x) 0 #endif #define __has_keyword(__x) !(__is_identifier(__x)) #ifdef __has_include #define __libcpp_has_include(__x) __has_include(__x) #else #define __libcpp_has_include(__x) 0 #endif #if defined(__clang__) #define _LIBCPP_COMPILER_CLANG # ifndef __apple_build_version__ # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) # endif #elif defined(__GNUC__) #define _LIBCPP_COMPILER_GCC #elif defined(_MSC_VER) #define _LIBCPP_COMPILER_MSVC #elif defined(__IBMCPP__) #define _LIBCPP_COMPILER_IBM #endif #ifndef _LIBCPP_CLANG_VER #define _LIBCPP_CLANG_VER 0 #endif // FIXME: ABI detection should be done via compiler builtin macros. This // is just a placeholder until Clang implements such macros. For now assume // that Windows compilers pretending to be MSVC++ target the microsoft ABI. #if defined(_WIN32) && defined(_MSC_VER) # define _LIBCPP_ABI_MICROSOFT #else # define _LIBCPP_ABI_ITANIUM #endif // Need to detect which libc we're using if we're on Linux. #if defined(__linux__) #include #if !defined(__GLIBC_PREREQ) #define __GLIBC_PREREQ(a, b) 0 #endif // !defined(__GLIBC_PREREQ) #endif // defined(__linux__) #ifdef __LITTLE_ENDIAN__ #if __LITTLE_ENDIAN__ #define _LIBCPP_LITTLE_ENDIAN 1 #define _LIBCPP_BIG_ENDIAN 0 #endif // __LITTLE_ENDIAN__ #endif // __LITTLE_ENDIAN__ #ifdef __BIG_ENDIAN__ #if __BIG_ENDIAN__ #define _LIBCPP_LITTLE_ENDIAN 0 #define _LIBCPP_BIG_ENDIAN 1 #endif // __BIG_ENDIAN__ #endif // __BIG_ENDIAN__ #ifdef __BYTE_ORDER__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define _LIBCPP_LITTLE_ENDIAN 1 #define _LIBCPP_BIG_ENDIAN 0 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define _LIBCPP_LITTLE_ENDIAN 0 #define _LIBCPP_BIG_ENDIAN 1 #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #endif // __BYTE_ORDER__ #ifdef __FreeBSD__ # include # if _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # else // _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 0 # define _LIBCPP_BIG_ENDIAN 1 # endif // _BYTE_ORDER == _LITTLE_ENDIAN # ifndef __LONG_LONG_SUPPORTED # define _LIBCPP_HAS_NO_LONG_LONG # endif // __LONG_LONG_SUPPORTED #endif // __FreeBSD__ #ifdef __NetBSD__ # include # if _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # else // _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 0 # define _LIBCPP_BIG_ENDIAN 1 # endif // _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_HAS_QUICK_EXIT #endif // __NetBSD__ #if defined(_WIN32) # define _LIBCPP_WIN32API # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # define _LIBCPP_SHORT_WCHAR 1 // Both MinGW and native MSVC provide a "MSVC"-like enviroment # define _LIBCPP_MSVCRT_LIKE -// If mingw not explicitly detected, assume using MS C runtime only. -# ifndef __MINGW32__ +// If mingw not explicitly detected, assume using MS C runtime only if +// a MS compatibility version is specified. +# if defined(_MSC_VER) && !defined(__MINGW32__) # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library # endif # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) # define _LIBCPP_HAS_BITSCAN64 # endif # if defined(_LIBCPP_MSVCRT) # define _LIBCPP_HAS_QUICK_EXIT # endif // Some CRT APIs are unavailable to store apps #if defined(WINAPI_FAMILY) #include #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \ (!defined(WINAPI_PARTITION_SYSTEM) || \ !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM)) #define _LIBCPP_WINDOWS_STORE_APP #endif #endif #endif // defined(_WIN32) #ifdef __sun__ # include # ifdef _LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # else # define _LIBCPP_LITTLE_ENDIAN 0 # define _LIBCPP_BIG_ENDIAN 1 # endif #endif // __sun__ #if defined(__CloudABI__) // Certain architectures provide arc4random(). Prefer using // arc4random() over /dev/{u,}random to make it possible to obtain // random data even when using sandboxing mechanisms such as chroots, // Capsicum, etc. # define _LIBCPP_USING_ARC4_RANDOM #elif defined(__native_client__) // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, // including accesses to the special files under /dev. C++11's // std::random_device is instead exposed through a NaCl syscall. # define _LIBCPP_USING_NACL_RANDOM #elif defined(_LIBCPP_WIN32API) # define _LIBCPP_USING_WIN32_RANDOM #else # define _LIBCPP_USING_DEV_RANDOM #endif #if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) # include # if __BYTE_ORDER == __LITTLE_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 # elif __BYTE_ORDER == __BIG_ENDIAN # define _LIBCPP_LITTLE_ENDIAN 0 # define _LIBCPP_BIG_ENDIAN 1 # else // __BYTE_ORDER == __BIG_ENDIAN # error unable to determine endian # endif #endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) #if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) #define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) #else #define _LIBCPP_NO_CFI #endif #if defined(_LIBCPP_COMPILER_CLANG) // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility. #if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \ (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) || \ defined(_LIBCPP_ALTERNATE_STRING_LAYOUT) #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT #endif #if __has_feature(cxx_alignas) # define _ALIGNAS_TYPE(x) alignas(x) # define _ALIGNAS(x) alignas(x) #else # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x)))) # define _ALIGNAS(x) __attribute__((__aligned__(x))) #endif #if __cplusplus < 201103L typedef __char16_t char16_t; typedef __char32_t char32_t; #endif #if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS) #define _LIBCPP_NO_EXCEPTIONS #endif #if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI) #define _LIBCPP_NO_RTTI #endif #if !(__has_feature(cxx_strong_enums)) #define _LIBCPP_HAS_NO_STRONG_ENUMS #endif #if !(__has_feature(cxx_decltype)) #define _LIBCPP_HAS_NO_DECLTYPE #endif #if __has_feature(cxx_attributes) # define _LIBCPP_NORETURN [[noreturn]] #else # define _LIBCPP_NORETURN __attribute__ ((noreturn)) #endif #if !(__has_feature(cxx_lambdas)) #define _LIBCPP_HAS_NO_LAMBDAS #endif #if !(__has_feature(cxx_nullptr)) # if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR) # define nullptr __nullptr # else # define _LIBCPP_HAS_NO_NULLPTR # endif #endif #if !(__has_feature(cxx_rvalue_references)) #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif #if !(__has_feature(cxx_auto_type)) #define _LIBCPP_HAS_NO_AUTO_TYPE #endif #if !(__has_feature(cxx_variadic_templates)) #define _LIBCPP_HAS_NO_VARIADICS #endif #if !(__has_feature(cxx_generalized_initializers)) #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif #if __has_feature(is_base_of) # define _LIBCPP_HAS_IS_BASE_OF #endif #if __has_feature(is_final) # define _LIBCPP_HAS_IS_FINAL #endif // Objective-C++ features (opt-in) #if __has_feature(objc_arc) #define _LIBCPP_HAS_OBJC_ARC #endif #if __has_feature(objc_arc_weak) #define _LIBCPP_HAS_OBJC_ARC_WEAK #endif #if !(__has_feature(cxx_constexpr)) #define _LIBCPP_HAS_NO_CONSTEXPR #endif #if !(__has_feature(cxx_relaxed_constexpr)) #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #endif #if !(__has_feature(cxx_variable_templates)) #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #endif #if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L #if defined(__FreeBSD__) #define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_C11_FEATURES #elif defined(__Fuchsia__) #define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_C11_FEATURES #elif defined(__linux__) #if !defined(_LIBCPP_HAS_MUSL_LIBC) #if __GLIBC_PREREQ(2, 15) || defined(__BIONIC__) #define _LIBCPP_HAS_QUICK_EXIT #endif #if __GLIBC_PREREQ(2, 17) #define _LIBCPP_HAS_C11_FEATURES #endif #else // defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_C11_FEATURES #endif #endif // __linux__ #endif #if !(__has_feature(cxx_noexcept)) #define _LIBCPP_HAS_NO_NOEXCEPT #endif #if __has_feature(underlying_type) # define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) #endif #if __has_feature(is_literal) # define _LIBCPP_IS_LITERAL(T) __is_literal(T) #endif // Inline namespaces are available in Clang regardless of C++ dialect. #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE { #define _LIBCPP_END_NAMESPACE_STD } } #define _VSTD std::_LIBCPP_NAMESPACE namespace std { inline namespace _LIBCPP_NAMESPACE { } } #if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer) #define _LIBCPP_HAS_NO_ASAN #endif // Allow for build-time disabling of unsigned integer sanitization #if !defined(_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize) #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) #endif #elif defined(_LIBCPP_COMPILER_GCC) #define _ALIGNAS(x) __attribute__((__aligned__(x))) #define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x)))) #define _LIBCPP_NORETURN __attribute__((noreturn)) #if _GNUC_VER >= 407 #define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) #define _LIBCPP_IS_LITERAL(T) __is_literal_type(T) #define _LIBCPP_HAS_IS_FINAL #endif #if defined(__GNUC__) && _GNUC_VER >= 403 # define _LIBCPP_HAS_IS_BASE_OF #endif #if !__EXCEPTIONS #define _LIBCPP_NO_EXCEPTIONS #endif // constexpr was added to GCC in 4.6. #if _GNUC_VER < 406 #define _LIBCPP_HAS_NO_CONSTEXPR // Can only use constexpr in c++11 mode. #elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L #define _LIBCPP_HAS_NO_CONSTEXPR #endif // Determine if GCC supports relaxed constexpr #if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #endif // GCC 5 will support variable templates #if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #endif #ifndef __GXX_EXPERIMENTAL_CXX0X__ #define _LIBCPP_HAS_NO_DECLTYPE #define _LIBCPP_HAS_NO_NULLPTR #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #define _LIBCPP_HAS_NO_STRONG_ENUMS #define _LIBCPP_HAS_NO_NOEXCEPT #else // __GXX_EXPERIMENTAL_CXX0X__ #if _GNUC_VER < 403 #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif #if _GNUC_VER < 404 #define _LIBCPP_HAS_NO_DECLTYPE #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif // _GNUC_VER < 404 #if _GNUC_VER < 406 #define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR #endif #endif // __GXX_EXPERIMENTAL_CXX0X__ #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_NAMESPACE { #define _LIBCPP_END_NAMESPACE_STD } } #define _VSTD std::_LIBCPP_NAMESPACE namespace std { inline namespace _LIBCPP_NAMESPACE { } } #if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__) #define _LIBCPP_HAS_NO_ASAN #endif #elif defined(_LIBCPP_COMPILER_MSVC) #define _LIBCPP_TOSTRING2(x) #x #define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) #define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x)) #if _MSC_VER < 1900 #error "MSVC versions prior to Visual Studio 2015 are not supported" #endif #define _LIBCPP_HAS_IS_BASE_OF #define _LIBCPP_HAS_NO_CONSTEXPR #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #if _MSC_VER <= 1800 #define _LIBCPP_HAS_NO_UNICODE_CHARS #endif #define _LIBCPP_HAS_NO_NOEXCEPT #define __alignof__ __alignof #define _LIBCPP_NORETURN __declspec(noreturn) #define _ALIGNAS(x) __declspec(align(x)) #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { #define _LIBCPP_END_NAMESPACE_STD } #define _VSTD std # define _LIBCPP_WEAK namespace std { } #define _LIBCPP_HAS_NO_ASAN #elif defined(_LIBCPP_COMPILER_IBM) #define _ALIGNAS(x) __attribute__((__aligned__(x))) #define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x)))) #define _ATTRIBUTE(x) __attribute__((x)) #define _LIBCPP_NORETURN __attribute__((noreturn)) #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_IS_BASE_OF #define _LIBCPP_HAS_IS_FINAL #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #if defined(_AIX) #define __MULTILOCALE_API #endif #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE { #define _LIBCPP_END_NAMESPACE_STD } } #define _VSTD std::_LIBCPP_NAMESPACE namespace std { inline namespace _LIBCPP_NAMESPACE { } } #define _LIBCPP_HAS_NO_ASAN #endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] #if defined(_LIBCPP_OBJECT_FORMAT_COFF) #if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # define _LIBCPP_DLL_VIS # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS # define _LIBCPP_OVERRIDABLE_FUNC_VIS #elif defined(_LIBCPP_BUILDING_LIBRARY) # define _LIBCPP_DLL_VIS __declspec(dllexport) # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS #else # define _LIBCPP_DLL_VIS __declspec(dllimport) # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS # define _LIBCPP_OVERRIDABLE_FUNC_VIS #endif #define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS #define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS #define _LIBCPP_EXTERN_VIS _LIBCPP_DLL_VIS #define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS #define _LIBCPP_HIDDEN #define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS #define _LIBCPP_TEMPLATE_VIS -#define _LIBCPP_FUNC_VIS_ONLY #define _LIBCPP_ENUM_VIS #if defined(_LIBCPP_COMPILER_MSVC) # define _LIBCPP_INLINE_VISIBILITY __forceinline # define _LIBCPP_ALWAYS_INLINE __forceinline # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __forceinline #else # define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) # define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__ ((__always_inline__)) #endif #endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) #ifndef _LIBCPP_HIDDEN #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) #define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) #else #define _LIBCPP_HIDDEN #endif #endif #ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) // The inline should be removed once PR32114 is resolved #define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN #else #define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS #endif #endif #ifndef _LIBCPP_FUNC_VIS #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) #define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default"))) #else #define _LIBCPP_FUNC_VIS #endif #endif #ifndef _LIBCPP_TYPE_VIS # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default"))) # else # define _LIBCPP_TYPE_VIS # endif #endif #ifndef _LIBCPP_TEMPLATE_VIS # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # if __has_attribute(__type_visibility__) # define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default"))) # else # define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default"))) # endif # else # define _LIBCPP_TEMPLATE_VIS # endif #endif -#ifndef _LIBCPP_FUNC_VIS_ONLY -# define _LIBCPP_FUNC_VIS_ONLY _LIBCPP_FUNC_VIS -#endif - #ifndef _LIBCPP_EXTERN_VIS # define _LIBCPP_EXTERN_VIS #endif #ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS #endif #ifndef _LIBCPP_EXCEPTION_ABI #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) #define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) #else #define _LIBCPP_EXCEPTION_ABI #endif #endif #ifndef _LIBCPP_ENUM_VIS # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) # define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default"))) # else # define _LIBCPP_ENUM_VIS # endif #endif #ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default"))) # else # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS # endif #endif #ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS #endif #ifndef _LIBCPP_INLINE_VISIBILITY #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) #define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) #else #define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) #endif #endif #ifndef _LIBCPP_ALWAYS_INLINE #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) #else #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) #endif #endif #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__((__visibility__("default"), __always_inline__)) # else # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__((__always_inline__)) # endif #endif #ifndef _LIBCPP_PREFERRED_OVERLOAD # if __has_attribute(__enable_if__) # define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, ""))) # endif #endif #ifndef _LIBCPP_HAS_NO_NOEXCEPT # define _NOEXCEPT noexcept # define _NOEXCEPT_(x) noexcept(x) #else # define _NOEXCEPT throw() # define _NOEXCEPT_(x) #endif #if defined(_LIBCPP_DEBUG_USE_EXCEPTIONS) # if !defined(_LIBCPP_DEBUG) # error cannot use _LIBCPP_DEBUG_USE_EXCEPTIONS unless _LIBCPP_DEBUG is defined # endif # define _NOEXCEPT_DEBUG noexcept(false) # define _NOEXCEPT_DEBUG_(x) noexcept(false) #else # define _NOEXCEPT_DEBUG _NOEXCEPT # define _NOEXCEPT_DEBUG_(x) _NOEXCEPT_(x) #endif #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS typedef unsigned short char16_t; typedef unsigned int char32_t; #endif // _LIBCPP_HAS_NO_UNICODE_CHARS #ifndef __SIZEOF_INT128__ #define _LIBCPP_HAS_NO_INT128 #endif #ifdef _LIBCPP_CXX03_LANG # if __has_extension(c_static_assert) # define static_assert(__b, __m) _Static_assert(__b, __m) # else extern "C++" { template struct __static_assert_test; template <> struct __static_assert_test {}; template struct __static_assert_check {}; } #define static_assert(__b, __m) \ typedef __static_assert_check)> \ _LIBCPP_CONCAT(__t, __LINE__) # endif // __has_extension(c_static_assert) #endif // _LIBCPP_CXX03_LANG #ifdef _LIBCPP_HAS_NO_DECLTYPE // GCC 4.6 provides __decltype in all standard modes. #if __has_keyword(__decltype) || _LIBCPP_CLANG_VER >= 304 || _GNUC_VER >= 406 # define decltype(__x) __decltype(__x) #else # define decltype(__x) __typeof__(__x) #endif #endif #ifdef _LIBCPP_HAS_NO_CONSTEXPR #define _LIBCPP_CONSTEXPR #else #define _LIBCPP_CONSTEXPR constexpr #endif #ifdef _LIBCPP_CXX03_LANG #define _LIBCPP_DEFAULT {} #else #define _LIBCPP_DEFAULT = default; #endif #ifdef _LIBCPP_CXX03_LANG #define _LIBCPP_EQUAL_DELETE #else #define _LIBCPP_EQUAL_DELETE = delete #endif #ifdef __GNUC__ #define _NOALIAS __attribute__((__malloc__)) #else #define _NOALIAS #endif #if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \ (!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions # define _LIBCPP_EXPLICIT explicit #else # define _LIBCPP_EXPLICIT #endif #if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) # define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE #endif #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS #define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ __lx __v_; \ _LIBCPP_ALWAYS_INLINE x(__lx __v) : __v_(__v) {} \ _LIBCPP_ALWAYS_INLINE explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \ }; #else // _LIBCPP_HAS_NO_STRONG_ENUMS #define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) #endif // _LIBCPP_HAS_NO_STRONG_ENUMS #ifdef _LIBCPP_DEBUG # if _LIBCPP_DEBUG == 0 # define _LIBCPP_DEBUG_LEVEL 1 # elif _LIBCPP_DEBUG == 1 # define _LIBCPP_DEBUG_LEVEL 2 # else # error Supported values for _LIBCPP_DEBUG are 0 and 1 # endif # if !defined(_LIBCPP_BUILDING_LIBRARY) # define _LIBCPP_EXTERN_TEMPLATE(...) # endif #endif #ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE #define _LIBCPP_EXTERN_TEMPLATE(...) #define _LIBCPP_EXTERN_TEMPLATE2(...) #endif #ifndef _LIBCPP_EXTERN_TEMPLATE #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; #endif #ifndef _LIBCPP_EXTERN_TEMPLATE2 #define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__; #endif #if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__) #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63) #endif #if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) || \ defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) // Most unix variants have catopen. These are the specific ones that don't. #if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) #define _LIBCPP_HAS_CATOPEN 1 #endif #endif #ifdef __FreeBSD__ #define _DECLARE_C99_LDBL_MATH 1 #endif #if defined(__APPLE__) # if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) # define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ # endif # if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) # if __MAC_OS_X_VERSION_MIN_REQUIRED < 1060 # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION # endif # endif #endif // defined(__APPLE__) #if defined(__APPLE__) || defined(__FreeBSD__) #define _LIBCPP_HAS_DEFAULTRUNELOCALE #endif #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) #define _LIBCPP_WCTYPE_IS_MASK #endif #ifndef _LIBCPP_STD_VER # if __cplusplus <= 201103L # define _LIBCPP_STD_VER 11 # elif __cplusplus <= 201402L # define _LIBCPP_STD_VER 14 +# elif __cplusplus <= 201703L +# define _LIBCPP_STD_VER 17 # else -# define _LIBCPP_STD_VER 16 // current year, or date of c++17 ratification +# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification # endif #endif // _LIBCPP_STD_VER #if _LIBCPP_STD_VER > 11 #define _LIBCPP_DEPRECATED [[deprecated]] #else #define _LIBCPP_DEPRECATED #endif #if _LIBCPP_STD_VER <= 11 #define _LIBCPP_EXPLICIT_AFTER_CXX11 #define _LIBCPP_DEPRECATED_AFTER_CXX11 #else #define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit #define _LIBCPP_DEPRECATED_AFTER_CXX11 [[deprecated]] #endif #if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) #define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr #else #define _LIBCPP_CONSTEXPR_AFTER_CXX11 #endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) #define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr #else #define _LIBCPP_CONSTEXPR_AFTER_CXX14 #endif // FIXME: Remove all usages of this macro once compilers catch up. #if !defined(__cpp_inline_variables) || (__cpp_inline_variables < 201606L) # define _LIBCPP_HAS_NO_INLINE_VARIABLES #endif #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES # define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x) #else # define _LIBCPP_EXPLICIT_MOVE(x) (x) #endif #ifndef _LIBCPP_HAS_NO_ASAN _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( const void *, const void *, const void *, const void *); #endif // Try to find out if RTTI is disabled. // g++ and cl.exe have RTTI on by default and define a macro when it is. // g++ only defines the macro in 4.3.2 and onwards. #if !defined(_LIBCPP_NO_RTTI) # if defined(__GNUC__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \ (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI) # define _LIBCPP_NO_RTTI # elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI) # define _LIBCPP_NO_RTTI # endif #endif #ifndef _LIBCPP_WEAK # define _LIBCPP_WEAK __attribute__((__weak__)) #endif // Thread API #if !defined(_LIBCPP_HAS_NO_THREADS) && \ !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) # if defined(__FreeBSD__) || \ defined(__Fuchsia__) || \ defined(__NetBSD__) || \ defined(__linux__) || \ defined(__APPLE__) || \ defined(__CloudABI__) || \ defined(__sun__) || \ (defined(__MINGW32__) && __libcpp_has_include()) # define _LIBCPP_HAS_THREAD_API_PTHREAD # elif defined(_LIBCPP_WIN32API) # define _LIBCPP_HAS_THREAD_API_WIN32 # else # error "No thread API" # endif // _LIBCPP_HAS_THREAD_API #endif // _LIBCPP_HAS_NO_THREADS #if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ _LIBCPP_HAS_NO_THREADS is not defined. #endif #if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ _LIBCPP_HAS_NO_THREADS is defined. #endif #if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ _LIBCPP_HAS_NO_THREADS is defined. #endif // Systems that use capability-based security (FreeBSD with Capsicum, // Nuxi CloudABI) may only provide local filesystem access (using *at()). // Functions like open(), rename(), unlink() and stat() should not be // used, as they attempt to access the global filesystem namespace. #ifdef __CloudABI__ #define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE #endif // CloudABI is intended for running networked services. Processes do not // have standard input and output channels. #ifdef __CloudABI__ #define _LIBCPP_HAS_NO_STDIN #define _LIBCPP_HAS_NO_STDOUT #endif #if defined(__BIONIC__) || defined(__CloudABI__) || \ defined(__Fuchsia__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE #endif // Thread-unsafe functions such as strtok() and localtime() // are not available. #ifdef __CloudABI__ #define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS #endif #if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) #define _LIBCPP_HAS_C_ATOMIC_IMP #elif _GNUC_VER > 407 #define _LIBCPP_HAS_GCC_ATOMIC_IMP #endif #if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)) \ || defined(_LIBCPP_HAS_NO_THREADS) #define _LIBCPP_HAS_NO_ATOMIC_HEADER #endif #ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK #endif #if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) #if defined(__clang__) && __has_attribute(acquire_capability) // Work around the attribute handling in clang. When both __declspec and // __attribute__ are present, the processing goes awry preventing the definition // of the types. #if !defined(_LIBCPP_OBJECT_FORMAT_COFF) #define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS #endif #endif #endif #if __has_attribute(require_constant_initialization) #define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__)) #else #define _LIBCPP_SAFE_STATIC #endif #if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700 # define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF #endif #if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) #if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION) #define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS #endif #endif #if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) # define _LIBCPP_DIAGNOSE_WARNING(...) \ __attribute__((diagnose_if(__VA_ARGS__, "warning"))) # define _LIBCPP_DIAGNOSE_ERROR(...) \ __attribute__((diagnose_if(__VA_ARGS__, "error"))) #else # define _LIBCPP_DIAGNOSE_WARNING(...) # define _LIBCPP_DIAGNOSE_ERROR(...) #endif #if __has_attribute(fallthough) || _GNUC_VER >= 700 // Use a function like macro to imply that it must be followed by a semicolon #define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) #else #define _LIBCPP_FALLTHROUGH() ((void)0) #endif #if defined(_LIBCPP_ABI_MICROSOFT) && \ (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) #else # define _LIBCPP_DECLSPEC_EMPTY_BASES #endif #if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) # define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR # define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS # define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE # define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS #endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES #if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611 # define _LIBCPP_HAS_NO_DEDUCTION_GUIDES #endif #if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001) # define _LIBCPP_HAS_NO_IS_AGGREGATE #endif #if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L # define _LIBCPP_HAS_NO_COROUTINES #endif // Decide whether to use availability macros. #if !defined(_LIBCPP_BUILDING_LIBRARY) && \ !defined(_LIBCPP_DISABLE_AVAILABILITY) && \ __has_feature(attribute_availability_with_strict) && \ __has_feature(attribute_availability_in_templates) #ifdef __APPLE__ #define _LIBCPP_USE_AVAILABILITY_APPLE #endif #endif // Define availability macros. #if defined(_LIBCPP_USE_AVAILABILITY_APPLE) #define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ __attribute__((availability(macosx,strict,introduced=10.12))) \ __attribute__((availability(ios,strict,introduced=10.0))) \ __attribute__((availability(tvos,strict,introduced=10.0))) \ __attribute__((availability(watchos,strict,introduced=3.0))) #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((unavailable)) #define _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH __attribute__((unavailable)) #define _LIBCPP_AVAILABILITY_BAD_ANY_CAST __attribute__((unavailable)) #define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS \ __attribute__((availability(macosx,strict,introduced=10.12))) \ __attribute__((availability(ios,strict,introduced=10.0))) \ __attribute__((availability(tvos,strict,introduced=10.0))) \ __attribute__((availability(watchos,strict,introduced=3.0))) #define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE \ __attribute__((availability(macosx,strict,introduced=10.12))) \ __attribute__((availability(ios,strict,introduced=10.0))) \ __attribute__((availability(tvos,strict,introduced=10.0))) \ __attribute__((availability(watchos,strict,introduced=3.0))) #define _LIBCPP_AVAILABILITY_FUTURE_ERROR \ __attribute__((availability(ios,strict,introduced=6.0))) #define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE \ __attribute__((availability(macosx,strict,introduced=10.9))) \ __attribute__((availability(ios,strict,introduced=7.0))) #define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY \ __attribute__((availability(macosx,strict,introduced=10.9))) \ __attribute__((availability(ios,strict,introduced=7.0))) #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \ __attribute__((availability(macosx,strict,introduced=10.9))) \ __attribute__((availability(ios,strict,introduced=7.0))) #else #define _LIBCPP_AVAILABILITY_SHARED_MUTEX #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS #define _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH #define _LIBCPP_AVAILABILITY_BAD_ANY_CAST #define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS #define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE #define _LIBCPP_AVAILABILITY_FUTURE_ERROR #define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE #define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR #endif // Define availability that depends on _LIBCPP_NO_EXCEPTIONS. #ifdef _LIBCPP_NO_EXCEPTIONS #define _LIBCPP_AVAILABILITY_DYNARRAY #define _LIBCPP_AVAILABILITY_FUTURE #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST #else #define _LIBCPP_AVAILABILITY_DYNARRAY _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH #define _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_AVAILABILITY_FUTURE_ERROR #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST \ _LIBCPP_AVAILABILITY_BAD_ANY_CAST #endif // Availability of stream API in the dylib got dropped and re-added. The // extern template should effectively be available at: // availability(macosx,introduced=10.9) // availability(ios,introduced=7.0) #if defined(_LIBCPP_USE_AVAILABILITY_APPLE) && \ ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 70000)) #define _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE #endif #if defined(_LIBCPP_COMPILER_IBM) #define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO #endif #if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO) # define _LIBCPP_PUSH_MACROS # define _LIBCPP_POP_MACROS #else // Don't warn about macro conflicts when we can restore them at the // end of the header. # ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS # define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS # endif # if defined(_LIBCPP_COMPILER_MSVC) # define _LIBCPP_PUSH_MACROS \ __pragma(push_macro("min")) \ __pragma(push_macro("max")) # define _LIBCPP_POP_MACROS \ __pragma(pop_macro("min")) \ __pragma(pop_macro("max")) # else # define _LIBCPP_PUSH_MACROS \ _Pragma("push_macro(\"min\")") \ _Pragma("push_macro(\"max\")") # define _LIBCPP_POP_MACROS \ _Pragma("pop_macro(\"min\")") \ _Pragma("pop_macro(\"max\")") # endif #endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO) #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: vendor/libc++/dist/include/algorithm =================================================================== --- vendor/libc++/dist/include/algorithm (revision 321189) +++ vendor/libc++/dist/include/algorithm (revision 321190) @@ -1,5911 +1,5904 @@ // -*- C++ -*- //===-------------------------- algorithm ---------------------------------===// // // 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_ALGORITHM #define _LIBCPP_ALGORITHM /* algorithm synopsis #include namespace std { template bool all_of(InputIterator first, InputIterator last, Predicate pred); template bool any_of(InputIterator first, InputIterator last, Predicate pred); template bool none_of(InputIterator first, InputIterator last, Predicate pred); template Function for_each(InputIterator first, InputIterator last, Function f); template InputIterator for_each_n(InputIterator first, Size n, Function f); // C++17 template InputIterator find(InputIterator first, InputIterator last, const T& value); template InputIterator find_if(InputIterator first, InputIterator last, Predicate pred); template InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred); template ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template ForwardIterator1 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template ForwardIterator1 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last); template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template typename iterator_traits::difference_type count(InputIterator first, InputIterator last, const T& value); template typename iterator_traits::difference_type count_if(InputIterator first, InputIterator last, Predicate pred); template pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); // **C++14** template pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); // **C++14** template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); // **C++14** template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); // **C++14** template bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); // **C++14** template bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); template bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); // **C++14** template ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); template ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred); template OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result); template OutputIterator copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); template OutputIterator copy_n(InputIterator first, Size n, OutputIterator result); template BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result); template ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template void iter_swap(ForwardIterator1 a, ForwardIterator2 b); template OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op); template OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation binary_op); template void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); template void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); template OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value); template OutputIterator replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); template void fill(ForwardIterator first, ForwardIterator last, const T& value); template OutputIterator fill_n(OutputIterator first, Size n, const T& value); template void generate(ForwardIterator first, ForwardIterator last, Generator gen); template OutputIterator generate_n(OutputIterator first, Size n, Generator gen); template ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T& value); template ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); template OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); template OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); template ForwardIterator unique(ForwardIterator first, ForwardIterator last); template ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result); template OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); template void reverse(BidirectionalIterator first, BidirectionalIterator last); template OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); template ForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); template OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); template void random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17 template void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17 template SampleIterator sample(PopulationIterator first, PopulationIterator last, SampleIterator out, Distance n, UniformRandomBitGenerator&& g); // C++17 template void shuffle(RandomAccessIterator first, RandomAccessIterator last, UniformRandomNumberGenerator&& g); template bool is_partitioned(InputIterator first, InputIterator last, Predicate pred); template ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred); template pair partition_copy(InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred); template ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); template ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); template bool is_sorted(ForwardIterator first, ForwardIterator last); template bool is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); template ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last); template ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); template void sort(RandomAccessIterator first, RandomAccessIterator last); template void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template void stable_sort(RandomAccessIterator first, RandomAccessIterator last); template void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); template void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); template RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last); template RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); template void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); template void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp); template ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value); template ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); template ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value); template ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); template pair equal_range(ForwardIterator first, ForwardIterator last, const T& value); template pair equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); template bool binary_search(ForwardIterator first, ForwardIterator last, const T& value); template bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); template OutputIterator merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template OutputIterator merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template void inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); template void inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); template bool includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template bool includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); template OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template void push_heap(RandomAccessIterator first, RandomAccessIterator last); template void push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template void pop_heap(RandomAccessIterator first, RandomAccessIterator last); template void pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template void make_heap(RandomAccessIterator first, RandomAccessIterator last); template void make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template void sort_heap(RandomAccessIterator first, RandomAccessIterator last); template void sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template bool is_heap(RandomAccessIterator first, RandomAccessiterator last); template bool is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); template RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessiterator last); template RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); template ForwardIterator min_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 template ForwardIterator min_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 template const T& min(const T& a, const T& b); // constexpr in C++14 template const T& min(const T& a, const T& b, Compare comp); // constexpr in C++14 template T min(initializer_list t); // constexpr in C++14 template T min(initializer_list t, Compare comp); // constexpr in C++14 template constexpr const T& clamp( const T& v, const T& lo, const T& hi ); // C++17 template constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ); // C++17 template ForwardIterator max_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 template ForwardIterator max_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 template const T& max(const T& a, const T& b); // constexpr in C++14 template const T& max(const T& a, const T& b, Compare comp); // constexpr in C++14 template T max(initializer_list t); // constexpr in C++14 template T max(initializer_list t, Compare comp); // constexpr in C++14 template pair minmax_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14 template pair minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14 template pair minmax(const T& a, const T& b); // constexpr in C++14 template pair minmax(const T& a, const T& b, Compare comp); // constexpr in C++14 template pair minmax(initializer_list t); // constexpr in C++14 template pair minmax(initializer_list t, Compare comp); // constexpr in C++14 template bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); template bool next_permutation(BidirectionalIterator first, BidirectionalIterator last); template bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); template bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last); template bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); } // std */ #include <__config> #include #include #include #include // needed to provide swap_ranges. #include #include #include #if defined(__IBMCPP__) #include "support/ibm/support.h" #endif #if defined(_LIBCPP_COMPILER_MSVC) #include #endif #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, but can't because: // * That only works with C++14 and later, and // * We haven't included here. template struct __equal_to { _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;} }; template struct __equal_to<_T1, _T1> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} }; template struct __equal_to { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} }; template struct __equal_to<_T1, const _T1> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} }; template struct __less { _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 bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;} }; template struct __less<_T1, _T1> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; template struct __less { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; template struct __less<_T1, const _T1> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} }; template class __negate { private: _Predicate __p_; public: _LIBCPP_INLINE_VISIBILITY __negate() {} _LIBCPP_INLINE_VISIBILITY explicit __negate(_Predicate __p) : __p_(__p) {} template _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x) {return !__p_(__x);} template _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);} }; #ifdef _LIBCPP_DEBUG template struct __debug_less { _Compare __comp_; __debug_less(_Compare& __c) : __comp_(__c) {} template bool operator()(const _Tp& __x, const _Up& __y) { bool __r = __comp_(__x, __y); if (__r) __do_compare_assert(0, __y, __x); return __r; } template 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 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) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__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, mask)) return where; return 32; #endif } inline _LIBCPP_INLINE_VISIBILITY unsigned long __ctz(unsigned long __x) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__builtin_ctzl(__x)); #else static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); return __ctz(static_cast(__x)); #endif } inline _LIBCPP_INLINE_VISIBILITY unsigned long long __ctz(unsigned long long __x) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__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, mask)) return static_cast(where); #else // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. // Scan the Low Word. if (_BitScanForward(&where, static_cast(mask))) return where; // Scan the High Word. if (_BitScanForward(&where, static_cast(mask >> 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) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__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, mask)) return 31 - where; return 32; // Undefined Behavior. #endif } inline _LIBCPP_INLINE_VISIBILITY unsigned long __clz(unsigned long __x) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__builtin_clzl (__x)); #else static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); return __clz(static_cast(__x)); #endif } inline _LIBCPP_INLINE_VISIBILITY unsigned long long __clz(unsigned long long __x) { #ifndef _LIBCPP_COMPILER_MSVC return static_cast(__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, mask)) return static_cast(63 - where); #else // Scan the high 32 bits. if (_BitScanReverse(&where, static_cast(mask >> 32))) return 63 - (where + 32); // Create a bit offset from the MSB. // Scan the low 32 bits. if (_BitScanReverse(&where, static_cast(mask))) 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 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 template inline _LIBCPP_INLINE_VISIBILITY bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) return false; return true; } // any_of template inline _LIBCPP_INLINE_VISIBILITY bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) return true; return false; } // none_of template inline _LIBCPP_INLINE_VISIBILITY bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) return false; return true; } // for_each template inline _LIBCPP_INLINE_VISIBILITY _Function for_each(_InputIterator __first, _InputIterator __last, _Function __f) { for (; __first != __last; ++__first) __f(*__first); return __f; } #if _LIBCPP_STD_VER > 14 // for_each_n template 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 inline _LIBCPP_INLINE_VISIBILITY _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) { for (; __first != __last; ++__first) if (*__first == __value_) break; return __first; } // find_if template inline _LIBCPP_INLINE_VISIBILITY _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) break; return __first; } // find_if_not template inline _LIBCPP_INLINE_VISIBILITY _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) break; return __first; } // find_end template _ForwardIterator1 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag) { // modeled after search algorithm _ForwardIterator1 __r = __last1; // __last1 is the "default" answer if (__first2 == __last2) return __r; while (true) { while (true) { if (__first1 == __last1) // if source exhausted return last correct answer return __r; // (or __last1 if never found) if (__pred(*__first1, *__first2)) break; ++__first1; } // *__first1 matches *__first2, now match elements after here _ForwardIterator1 __m1 = __first1; _ForwardIterator2 __m2 = __first2; while (true) { if (++__m2 == __last2) { // Pattern exhaused, record answer and search for another one __r = __first1; ++__first1; break; } if (++__m1 == __last1) // Source exhausted, return last answer return __r; if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first { ++__first1; break; } // else there is a match, check next elements } } } template _BidirectionalIterator1 __find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1, _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BinaryPredicate __pred, bidirectional_iterator_tag, bidirectional_iterator_tag) { // modeled after search algorithm (in reverse) if (__first2 == __last2) return __last1; // Everything matches an empty sequence _BidirectionalIterator1 __l1 = __last1; _BidirectionalIterator2 __l2 = __last2; --__l2; while (true) { // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks while (true) { if (__first1 == __l1) // return __last1 if no element matches *__first2 return __last1; if (__pred(*--__l1, *__l2)) break; } // *__l1 matches *__l2, now match elements before here _BidirectionalIterator1 __m1 = __l1; _BidirectionalIterator2 __m2 = __l2; while (true) { if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) return __m1; if (__m1 == __first1) // Otherwise if source exhaused, pattern not found return __last1; if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1 { break; } // else there is a match, check next elements } } } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1 __find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) { // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2; if (__len2 == 0) return __last1; typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1; if (__len1 < __len2) return __last1; const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here _RandomAccessIterator1 __l1 = __last1; _RandomAccessIterator2 __l2 = __last2; --__l2; while (true) { while (true) { if (__s == __l1) return __last1; if (__pred(*--__l1, *__l2)) break; } _RandomAccessIterator1 __m1 = __l1; _RandomAccessIterator2 __m2 = __l2; while (true) { if (__m2 == __first2) return __m1; // no need to check range on __m1 because __s guarantees we have enough source if (!__pred(*--__m1, *--__m2)) { break; } } } } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { return _VSTD::__find_end::type> (__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(), typename iterator_traits<_ForwardIterator2>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); } // find_first_of template _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1) for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) if (__pred(*__first1, *__j)) return __first1; return __last1; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred); } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); } // adjacent_find template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) { if (__pred(*__first, *__i)) return __first; __first = __i; } } return __last; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { typedef typename iterator_traits<_ForwardIterator>::value_type __v; return _VSTD::adjacent_find(__first, __last, __equal_to<__v>()); } // count template inline _LIBCPP_INLINE_VISIBILITY typename iterator_traits<_InputIterator>::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) { typename iterator_traits<_InputIterator>::difference_type __r(0); for (; __first != __last; ++__first) if (*__first == __value_) ++__r; return __r; } // count_if template inline _LIBCPP_INLINE_VISIBILITY typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { typename iterator_traits<_InputIterator>::difference_type __r(0); for (; __first != __last; ++__first) if (__pred(*__first)) ++__r; return __r; } // mismatch template inline _LIBCPP_INLINE_VISIBILITY pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) break; return pair<_InputIterator1, _InputIterator2>(__first1, __first2); } template inline _LIBCPP_INLINE_VISIBILITY pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } #if _LIBCPP_STD_VER > 11 template inline _LIBCPP_INLINE_VISIBILITY pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred) { for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) break; return pair<_InputIterator1, _InputIterator2>(__first1, __first2); } template inline _LIBCPP_INLINE_VISIBILITY pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); } #endif // equal template inline _LIBCPP_INLINE_VISIBILITY bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { for (; __first1 != __last1; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) return false; return true; } template inline _LIBCPP_INLINE_VISIBILITY bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } #if _LIBCPP_STD_VER > 11 template inline _LIBCPP_INLINE_VISIBILITY bool __equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred, input_iterator_tag, input_iterator_tag ) { for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) return false; return __first1 == __last1 && __first2 == __last2; } template inline _LIBCPP_INLINE_VISIBILITY bool __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag ) { if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) return false; return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2, typename add_lvalue_reference<_BinaryPredicate>::type> (__first1, __last1, __first2, __pred ); } template inline _LIBCPP_INLINE_VISIBILITY bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred ) { return _VSTD::__equal::type> (__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(), typename iterator_traits<_InputIterator2>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), typename iterator_traits<_InputIterator1>::iterator_category(), typename iterator_traits<_InputIterator2>::iterator_category()); } #endif // is_permutation template bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { // shorten sequences as much as possible by lopping of any equal parts for (; __first1 != __last1; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) goto __not_done; return true; __not_done: // __first1 != __last1 && *__first1 != *__first2 typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; _D1 __l1 = _VSTD::distance(__first1, __last1); if (__l1 == _D1(1)) return false; _ForwardIterator2 __last2 = _VSTD::next(__first2, __l1); // For each element in [f1, l1) see if there are the same number of // equal elements in [f2, l2) for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) { // Have we already counted the number of *__i in [f1, l1)? for (_ForwardIterator1 __j = __first1; __j != __i; ++__j) if (__pred(*__j, *__i)) goto __next_iter; { // Count number of *__i in [f2, l2) _D1 __c2 = 0; for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) if (__pred(*__i, *__j)) ++__c2; if (__c2 == 0) return false; // Count number of *__i in [__i, l1) (we can start with 1) _D1 __c1 = 1; for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) if (__pred(*__i, *__j)) ++__c1; if (__c1 != __c2) return false; } __next_iter:; } return true; } template inline _LIBCPP_INLINE_VISIBILITY bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } #if _LIBCPP_STD_VER > 11 template bool __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag ) { // shorten sequences as much as possible by lopping of any equal parts for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2) if (!__pred(*__first1, *__first2)) goto __not_done; return __first1 == __last1 && __first2 == __last2; __not_done: // __first1 != __last1 && __first2 != __last2 && *__first1 != *__first2 typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; _D1 __l1 = _VSTD::distance(__first1, __last1); typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2; _D2 __l2 = _VSTD::distance(__first2, __last2); if (__l1 != __l2) return false; // For each element in [f1, l1) see if there are the same number of // equal elements in [f2, l2) for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i) { // Have we already counted the number of *__i in [f1, l1)? for (_ForwardIterator1 __j = __first1; __j != __i; ++__j) if (__pred(*__j, *__i)) goto __next_iter; { // Count number of *__i in [f2, l2) _D1 __c2 = 0; for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) if (__pred(*__i, *__j)) ++__c2; if (__c2 == 0) return false; // Count number of *__i in [__i, l1) (we can start with 1) _D1 __c1 = 1; for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j) if (__pred(*__i, *__j)) ++__c1; if (__c1 != __c2) return false; } __next_iter:; } return true; } template bool __is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1, _RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag ) { if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2)) return false; return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2, typename add_lvalue_reference<_BinaryPredicate>::type> (__first1, __last1, __first2, __pred ); } template inline _LIBCPP_INLINE_VISIBILITY bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred ) { return _VSTD::__is_permutation::type> (__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(), typename iterator_traits<_ForwardIterator2>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; return _VSTD::__is_permutation(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), typename iterator_traits<_ForwardIterator1>::iterator_category(), typename iterator_traits<_ForwardIterator2>::iterator_category()); } #endif // search template pair<_ForwardIterator1, _ForwardIterator1> __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, forward_iterator_tag, forward_iterator_tag) { if (__first2 == __last2) return make_pair(__first1, __first1); // Everything matches an empty sequence while (true) { // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks while (true) { if (__first1 == __last1) // return __last1 if no element matches *__first2 return make_pair(__last1, __last1); if (__pred(*__first1, *__first2)) break; ++__first1; } // *__first1 matches *__first2, now match elements after here _ForwardIterator1 __m1 = __first1; _ForwardIterator2 __m2 = __first2; while (true) { if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) return make_pair(__first1, __m1); if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found return make_pair(__last1, __last1); if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 { ++__first1; break; } // else there is a match, check next elements } } } template _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_RandomAccessIterator1, _RandomAccessIterator1> __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag, random_access_iterator_tag) { typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern const _D2 __len2 = __last2 - __first2; if (__len2 == 0) return make_pair(__first1, __first1); const _D1 __len1 = __last1 - __first1; 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) { while (true) { if (__first1 == __s) return make_pair(__last1, __last1); if (__pred(*__first1, *__first2)) break; ++__first1; } _RandomAccessIterator1 __m1 = __first1; _RandomAccessIterator2 __m2 = __first2; while (true) { if (++__m2 == __last2) return make_pair(__first1, __first1 + __len2); ++__m1; // no need to check range on __m1 because __s guarantees we have enough source if (!__pred(*__m1, *__m2)) { ++__first1; break; } } } } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { return _VSTD::__search::type> (__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(), typename iterator_traits<_ForwardIterator2>::iterator_category()) .first; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { typedef typename iterator_traits<_ForwardIterator1>::value_type __v1; typedef typename iterator_traits<_ForwardIterator2>::value_type __v2; return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); } // search_n template _ForwardIterator __search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred, forward_iterator_tag) { if (__count <= 0) return __first; while (true) { // Find first element in sequence that matchs __value_, with a mininum of loop checks while (true) { if (__first == __last) // return __last if no element matches __value_ return __last; if (__pred(*__first, __value_)) break; ++__first; } // *__first matches __value_, now match elements after here _ForwardIterator __m = __first; _Size __c(0); while (true) { if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) return __first; if (++__m == __last) // Otherwise if source exhaused, pattern not found return __last; if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first { __first = __m; ++__first; break; } // else there is a match, check next elements } } } template _RandomAccessIterator __search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag) { if (__count <= 0) return __first; _Size __len = static_cast<_Size>(__last - __first); if (__len < __count) return __last; const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here while (true) { // Find first element in sequence that matchs __value_, with a mininum of loop checks while (true) { if (__first >= __s) // return __last if no element matches __value_ return __last; if (__pred(*__first, __value_)) break; ++__first; } // *__first matches __value_, now match elements after here _RandomAccessIterator __m = __first; _Size __c(0); while (true) { if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern) return __first; ++__m; // no need to check range on __m because __s guarantees we have enough source if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first { __first = __m; ++__first; break; } // else there is a match, check next elements } } } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) { return _VSTD::__search_n::type> (__first, __last, __convert_to_integral(__count), __value_, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_) { typedef typename iterator_traits<_ForwardIterator>::value_type __v; return _VSTD::search_n(__first, __last, __convert_to_integral(__count), __value_, __equal_to<__v, _Tp>()); } // copy template inline _LIBCPP_INLINE_VISIBILITY _Iter __unwrap_iter(_Iter __i) { return __i; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_trivially_copy_assignable<_Tp>::value, _Tp* >::type __unwrap_iter(move_iterator<_Tp*> __i) { return __i.base(); } #if _LIBCPP_DEBUG_LEVEL < 2 template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_trivially_copy_assignable<_Tp>::value, _Tp* >::type __unwrap_iter(__wrap_iter<_Tp*> __i) { return __i.base(); } #else template 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 inline _LIBCPP_INLINE_VISIBILITY _OutputIterator __copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { for (; __first != __last; ++__first, (void) ++__result) *__result = *__first; return __result; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_same::type, _Up>::value && is_trivially_copy_assignable<_Up>::value, _Up* >::type __copy(_Tp* __first, _Tp* __last, _Up* __result) { const size_t __n = static_cast(__last - __first); if (__n > 0) _VSTD::memmove(__result, __first, __n * sizeof(_Up)); return __result + __n; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); } // copy_backward template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator __copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { while (__first != __last) *--__result = *--__last; return __result; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_same::type, _Up>::value && is_trivially_copy_assignable<_Up>::value, _Up* >::type __copy_backward(_Tp* __first, _Tp* __last, _Up* __result) { const size_t __n = static_cast(__last - __first); if (__n > 0) { __result -= __n; _VSTD::memmove(__result, __first, __n * sizeof(_Up)); } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _BidirectionalIterator2 copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { return _VSTD::__copy_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); } // copy_if template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { for (; __first != __last; ++__first) { if (__pred(*__first)) { *__result = *__first; ++__result; } } return __result; } // copy_n template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_input_iterator<_InputIterator>::value && !__is_random_access_iterator<_InputIterator>::value, _OutputIterator >::type copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) { typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; _IntegralSize __n = __orig_n; if (__n > 0) { *__result = *__first; ++__result; for (--__n; __n > 0; --__n) { ++__first; *__result = *__first; ++__result; } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_random_access_iterator<_InputIterator>::value, _OutputIterator >::type copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) { typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; _IntegralSize __n = __orig_n; return _VSTD::copy(__first, __first + __n, __result); } // move template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator __move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { for (; __first != __last; ++__first, (void) ++__result) *__result = _VSTD::move(*__first); return __result; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_same::type, _Up>::value && is_trivially_copy_assignable<_Up>::value, _Up* >::type __move(_Tp* __first, _Tp* __last, _Up* __result) { const size_t __n = static_cast(__last - __first); if (__n > 0) _VSTD::memmove(__result, __first, __n * sizeof(_Up)); return __result + __n; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { return _VSTD::__move(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); } // move_backward template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator __move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { while (__first != __last) *--__result = _VSTD::move(*--__last); return __result; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_same::type, _Up>::value && is_trivially_copy_assignable<_Up>::value, _Up* >::type __move_backward(_Tp* __first, _Tp* __last, _Up* __result) { const size_t __n = static_cast(__last - __first); if (__n > 0) { __result -= __n; _VSTD::memmove(__result, __first, __n * sizeof(_Up)); } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _BidirectionalIterator2 move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { return _VSTD::__move_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); } // iter_swap // moved to for better swap / noexcept support // transform template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) { for (; __first != __last; ++__first, (void) ++__result) *__result = __op(*__first); return __result; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _OutputIterator __result, _BinaryOperation __binary_op) { for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result) *__result = __binary_op(*__first1, *__first2); return __result; } // replace template inline _LIBCPP_INLINE_VISIBILITY void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value) { for (; __first != __last; ++__first) if (*__first == __old_value) *__first = __new_value; } // replace_if template inline _LIBCPP_INLINE_VISIBILITY void replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value) { for (; __first != __last; ++__first) if (__pred(*__first)) *__first = __new_value; } // replace_copy template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __old_value, const _Tp& __new_value) { for (; __first != __last; ++__first, (void) ++__result) if (*__first == __old_value) *__result = __new_value; else *__result = *__first; return __result; } // replace_copy_if template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred, const _Tp& __new_value) { for (; __first != __last; ++__first, (void) ++__result) if (__pred(*__first)) *__result = __new_value; else *__result = *__first; return __result; } // fill_n template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { for (; __n > 0; ++__first, (void) --__n) *__first = __value_; return __first; } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && sizeof(_Tp) == 1 && !is_same<_Tp, bool>::value && is_integral<_Up>::value && sizeof(_Up) == 1, _Tp* >::type __fill_n(_Tp* __first, _Size __n,_Up __value_) { if (__n > 0) _VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n)); return __first + __n; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { return _VSTD::__fill_n(__first, __convert_to_integral(__n), __value_); } // fill template inline _LIBCPP_INLINE_VISIBILITY void __fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag) { for (; __first != __last; ++__first) *__first = __value_; } template inline _LIBCPP_INLINE_VISIBILITY void __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag) { _VSTD::fill_n(__first, __last - __first, __value_); } template inline _LIBCPP_INLINE_VISIBILITY void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category()); } // generate template inline _LIBCPP_INLINE_VISIBILITY void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { for (; __first != __last; ++__first) *__first = __gen(); } // generate_n template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; _IntegralSize __n = __orig_n; for (; __n > 0; ++__first, (void) --__n) *__first = __gen(); return __first; } // remove template _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { __first = _VSTD::find(__first, __last, __value_); if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) { if (!(*__i == __value_)) { *__first = _VSTD::move(*__i); ++__first; } } } return __first; } // remove_if template _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type> (__first, __last, __pred); if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) { if (!__pred(*__i)) { *__first = _VSTD::move(*__i); ++__first; } } } return __first; } // remove_copy template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_) { for (; __first != __last; ++__first) { if (!(*__first == __value_)) { *__result = *__first; ++__result; } } return __result; } // remove_copy_if template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { for (; __first != __last; ++__first) { if (!__pred(*__first)) { *__result = *__first; ++__result; } } return __result; } // unique template _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type> (__first, __last, __pred); if (__first != __last) { // ... a a ? ... // f i _ForwardIterator __i = __first; for (++__i; ++__i != __last;) if (!__pred(*__first, *__i)) *++__first = _VSTD::move(*__i); ++__first; } return __first; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { typedef typename iterator_traits<_ForwardIterator>::value_type __v; return _VSTD::unique(__first, __last, __equal_to<__v>()); } // unique_copy template _OutputIterator __unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred, input_iterator_tag, output_iterator_tag) { if (__first != __last) { typename iterator_traits<_InputIterator>::value_type __t(*__first); *__result = __t; ++__result; while (++__first != __last) { if (!__pred(__t, *__first)) { __t = *__first; *__result = __t; ++__result; } } } return __result; } template _OutputIterator __unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred, forward_iterator_tag, output_iterator_tag) { if (__first != __last) { _ForwardIterator __i = __first; *__result = *__i; ++__result; while (++__first != __last) { if (!__pred(*__i, *__first)) { *__result = *__first; ++__result; __i = __first; } } } return __result; } template _ForwardIterator __unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred, input_iterator_tag, forward_iterator_tag) { if (__first != __last) { *__result = *__first; while (++__first != __last) if (!__pred(*__result, *__first)) *++__result = *__first; ++__result; } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) { return _VSTD::__unique_copy::type> (__first, __last, __result, __pred, typename iterator_traits<_InputIterator>::iterator_category(), typename iterator_traits<_OutputIterator>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { typedef typename iterator_traits<_InputIterator>::value_type __v; return _VSTD::unique_copy(__first, __last, __result, __equal_to<__v>()); } // reverse template inline _LIBCPP_INLINE_VISIBILITY void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) { while (__first != __last) { if (__first == --__last) break; _VSTD::iter_swap(__first, __last); ++__first; } } template inline _LIBCPP_INLINE_VISIBILITY void __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) { if (__first != __last) for (; __first < --__last; ++__first) _VSTD::iter_swap(__first, __last); } template inline _LIBCPP_INLINE_VISIBILITY void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) { _VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category()); } // reverse_copy template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { for (; __first != __last; ++__result) *__result = *--__last; return __result; } // rotate template _ForwardIterator __rotate_left(_ForwardIterator __first, _ForwardIterator __last) { typedef typename iterator_traits<_ForwardIterator>::value_type value_type; value_type __tmp = _VSTD::move(*__first); _ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first); *__lm1 = _VSTD::move(__tmp); return __lm1; } template _BidirectionalIterator __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last) { typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; _BidirectionalIterator __lm1 = _VSTD::prev(__last); value_type __tmp = _VSTD::move(*__lm1); _BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last); *__first = _VSTD::move(__tmp); return __fp1; } template _ForwardIterator __rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { _ForwardIterator __i = __middle; while (true) { swap(*__first, *__i); ++__first; if (++__i == __last) break; if (__first == __middle) __middle = __i; } _ForwardIterator __r = __first; if (__first != __middle) { __i = __middle; while (true) { swap(*__first, *__i); ++__first; if (++__i == __last) { if (__first == __middle) break; __i = __middle; } else if (__first == __middle) __middle = __i; } } return __r; } template inline _LIBCPP_INLINE_VISIBILITY _Integral __algo_gcd(_Integral __x, _Integral __y) { do { _Integral __t = __x % __y; __x = __y; __y = __t; } while (__y); return __x; } template _RandomAccessIterator __rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; const difference_type __m1 = __middle - __first; const difference_type __m2 = __last - __middle; if (__m1 == __m2) { _VSTD::swap_ranges(__first, __middle, __middle); return __middle; } const difference_type __g = _VSTD::__algo_gcd(__m1, __m2); for (_RandomAccessIterator __p = __first + __g; __p != __first;) { value_type __t(_VSTD::move(*--__p)); _RandomAccessIterator __p1 = __p; _RandomAccessIterator __p2 = __p1 + __m1; do { *__p1 = _VSTD::move(*__p2); __p1 = __p2; const difference_type __d = __last - __p2; if (__m1 < __d) __p2 += __m1; else __p2 = __first + (__m1 - __d); } while (__p2 != __p); *__p1 = _VSTD::move(__t); } return __first + __m2; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _VSTD::forward_iterator_tag) { typedef typename _VSTD::iterator_traits<_ForwardIterator>::value_type value_type; if (_VSTD::is_trivially_move_assignable::value) { if (_VSTD::next(__first) == __middle) return _VSTD::__rotate_left(__first, __last); } return _VSTD::__rotate_forward(__first, __middle, __last); } template inline _LIBCPP_INLINE_VISIBILITY _BidirectionalIterator __rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _VSTD::bidirectional_iterator_tag) { typedef typename _VSTD::iterator_traits<_BidirectionalIterator>::value_type value_type; if (_VSTD::is_trivially_move_assignable::value) { if (_VSTD::next(__first) == __middle) return _VSTD::__rotate_left(__first, __last); if (_VSTD::next(__middle) == __last) return _VSTD::__rotate_right(__first, __last); } return _VSTD::__rotate_forward(__first, __middle, __last); } template inline _LIBCPP_INLINE_VISIBILITY _RandomAccessIterator __rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _VSTD::random_access_iterator_tag) { typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::value_type value_type; if (_VSTD::is_trivially_move_assignable::value) { if (_VSTD::next(__first) == __middle) return _VSTD::__rotate_left(__first, __last); if (_VSTD::next(__middle) == __last) return _VSTD::__rotate_right(__first, __last); return _VSTD::__rotate_gcd(__first, __middle, __last); } return _VSTD::__rotate_forward(__first, __middle, __last); } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) { if (__first == __middle) return __last; if (__middle == __last) return __first; return _VSTD::__rotate(__first, __middle, __last, typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category()); } // rotate_copy template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result) { return _VSTD::copy(__first, __middle, _VSTD::copy(__middle, __last, __result)); } // min_element template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) if (__comp(*__i, *__first)) __first = __i; } return __first; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::min_element(__first, __last, __less::value_type>()); } // min template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) { return __comp(__b, __a) ? __b : __a; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& min(const _Tp& __a, const _Tp& __b) { return _VSTD::min(__a, __b, __less<_Tp>()); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp min(initializer_list<_Tp> __t, _Compare __comp) { return *_VSTD::min_element(__t.begin(), __t.end(), __comp); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp min(initializer_list<_Tp> __t) { return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>()); } #endif // _LIBCPP_CXX03_LANG // max_element template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) if (__comp(*__first, *__i)) __first = __i; } return __first; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::max_element(__first, __last, __less::value_type>()); } // max template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) { return __comp(__a, __b) ? __b : __a; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& max(const _Tp& __a, const _Tp& __b) { return _VSTD::max(__a, __b, __less<_Tp>()); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp max(initializer_list<_Tp> __t, _Compare __comp) { return *_VSTD::max_element(__t.begin(), __t.end(), __comp); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp max(initializer_list<_Tp> __t) { return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>()); } #endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 // clamp template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp) { _LIBCPP_ASSERT(!__comp(__hi, __lo), "Bad bounds passed to std::clamp"); return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi) { return _VSTD::clamp(__v, __lo, __hi, __less<_Tp>()); } #endif // minmax_element template _LIBCPP_CONSTEXPR_AFTER_CXX11 std::pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first); if (__first != __last) { if (++__first != __last) { if (__comp(*__first, *__result.first)) __result.first = __first; else __result.second = __first; while (++__first != __last) { _ForwardIterator __i = __first; if (++__first == __last) { if (__comp(*__i, *__result.first)) __result.first = __i; else if (!__comp(*__i, *__result.second)) __result.second = __i; break; } else { if (__comp(*__first, *__i)) { if (__comp(*__first, *__result.first)) __result.first = __first; if (!__comp(*__i, *__result.second)) __result.second = __i; } else { if (__comp(*__i, *__result.first)) __result.first = __i; if (!__comp(*__first, *__result.second)) __result.second = __first; } } } } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 std::pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::minmax_element(__first, __last, __less::value_type>()); } // minmax template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) { return __comp(__b, __a) ? pair(__b, __a) : pair(__a, __b); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair minmax(const _Tp& __a, const _Tp& __b) { return _VSTD::minmax(__a, __b, __less<_Tp>()); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { typedef typename initializer_list<_Tp>::const_iterator _Iter; _Iter __first = __t.begin(); _Iter __last = __t.end(); std::pair<_Tp, _Tp> __result(*__first, *__first); ++__first; if (__t.size() % 2 == 0) { if (__comp(*__first, __result.first)) __result.first = *__first; else __result.second = *__first; ++__first; } while (__first != __last) { _Tp __prev = *__first++; if (__comp(*__first, __prev)) { if ( __comp(*__first, __result.first)) __result.first = *__first; if (!__comp(__prev, __result.second)) __result.second = __prev; } else { if ( __comp(__prev, __result.first)) __result.first = __prev; if (!__comp(*__first, __result.second)) __result.second = *__first; } __first++; } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t) { return _VSTD::minmax(__t, __less<_Tp>()); } #endif // _LIBCPP_CXX03_LANG // random_shuffle // __independent_bits_engine template struct __log2_imp { static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp : __log2_imp<_Xp, _Rp - 1>::value; }; template struct __log2_imp<_Xp, 0> { static const size_t value = 0; }; template struct __log2_imp<0, _Rp> { static const size_t value = _Rp + 1; }; template struct __log2 { static const size_t value = __log2_imp<_Xp, sizeof(_UIntType) * __CHAR_BIT__ - 1>::value; }; template class __independent_bits_engine { public: // types typedef _UIntType result_type; private: typedef typename _Engine::result_type _Engine_result_type; typedef typename conditional < sizeof(_Engine_result_type) <= sizeof(result_type), result_type, _Engine_result_type >::type _Working_result_type; _Engine& __e_; size_t __w_; size_t __w0_; size_t __n_; size_t __n0_; _Working_result_type __y0_; _Working_result_type __y1_; _Engine_result_type __mask0_; _Engine_result_type __mask1_; #ifdef _LIBCPP_CXX03_LANG static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + _Working_result_type(1); #else static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() + _Working_result_type(1); #endif static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; public: // constructors and seeding functions __independent_bits_engine(_Engine& __e, size_t __w); // generating functions result_type operator()() {return __eval(integral_constant());} private: result_type __eval(false_type); result_type __eval(true_type); }; template __independent_bits_engine<_Engine, _UIntType> ::__independent_bits_engine(_Engine& __e, size_t __w) : __e_(__e), __w_(__w) { __n_ = __w_ / __m + (__w_ % __m != 0); __w0_ = __w_ / __n_; if (_Rp == 0) __y0_ = _Rp; else if (__w0_ < _WDt) __y0_ = (_Rp >> __w0_) << __w0_; else __y0_ = 0; if (_Rp - __y0_ > __y0_ / __n_) { ++__n_; __w0_ = __w_ / __n_; if (__w0_ < _WDt) __y0_ = (_Rp >> __w0_) << __w0_; else __y0_ = 0; } __n0_ = __n_ - __w_ % __n_; if (__w0_ < _WDt - 1) __y1_ = (_Rp >> (__w0_ + 1)) << (__w0_ + 1); else __y1_ = 0; __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : _Engine_result_type(0); __mask1_ = __w0_ < _EDt - 1 ? _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) : _Engine_result_type(~0); } template inline _UIntType __independent_bits_engine<_Engine, _UIntType>::__eval(false_type) { return static_cast(__e_() & __mask0_); } template _UIntType __independent_bits_engine<_Engine, _UIntType>::__eval(true_type) { result_type _Sp = 0; for (size_t __k = 0; __k < __n0_; ++__k) { _Engine_result_type __u; do { __u = __e_() - _Engine::min(); } while (__u >= __y0_); if (__w0_ < _WDt) _Sp <<= __w0_; else _Sp = 0; _Sp += __u & __mask0_; } for (size_t __k = __n0_; __k < __n_; ++__k) { _Engine_result_type __u; do { __u = __e_() - _Engine::min(); } while (__u >= __y1_); if (__w0_ < _WDt - 1) _Sp <<= __w0_ + 1; else _Sp = 0; _Sp += __u & __mask1_; } return _Sp; } // uniform_int_distribution template class uniform_int_distribution { public: // types typedef _IntType result_type; class param_type { result_type __a_; result_type __b_; public: typedef uniform_int_distribution distribution_type; explicit param_type(result_type __a = 0, result_type __b = numeric_limits::max()) : __a_(__a), __b_(__b) {} result_type a() const {return __a_;} result_type b() const {return __b_;} friend bool operator==(const param_type& __x, const param_type& __y) {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} friend bool operator!=(const param_type& __x, const param_type& __y) {return !(__x == __y);} }; private: param_type __p_; public: // constructors and reset functions explicit uniform_int_distribution(result_type __a = 0, result_type __b = numeric_limits::max()) : __p_(param_type(__a, __b)) {} explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {} void reset() {} // generating functions template result_type operator()(_URNG& __g) {return (*this)(__g, __p_);} template result_type operator()(_URNG& __g, const param_type& __p); // property functions result_type a() const {return __p_.a();} result_type b() const {return __p_.b();} param_type param() const {return __p_;} void param(const param_type& __p) {__p_ = __p;} result_type min() const {return a();} result_type max() const {return b();} friend bool operator==(const uniform_int_distribution& __x, const uniform_int_distribution& __y) {return __x.__p_ == __y.__p_;} friend bool operator!=(const uniform_int_distribution& __x, const uniform_int_distribution& __y) {return !(__x == __y);} }; template template typename uniform_int_distribution<_IntType>::result_type uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) { typedef typename conditional::type _UIntType; const _UIntType _Rp = __p.b() - __p.a() + _UIntType(1); if (_Rp == 1) return __p.a(); const size_t _Dt = numeric_limits<_UIntType>::digits; typedef __independent_bits_engine<_URNG, _UIntType> _Eng; if (_Rp == 0) return static_cast(_Eng(__g, _Dt)()); size_t __w = _Dt - __clz(_Rp) - 1; if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) ++__w; _Eng __e(__g, __w); _UIntType __u; do { __u = __e(); } while (__u >= _Rp); return static_cast(__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(); class _LIBCPP_TYPE_VIS __rs_default { static unsigned __c_; __rs_default(); public: typedef uint_fast32_t result_type; static const result_type _Min = 0; static const result_type _Max = 0xFFFFFFFF; __rs_default(const __rs_default&); ~__rs_default(); result_type operator()(); static _LIBCPP_CONSTEXPR result_type min() {return _Min;} static _LIBCPP_CONSTEXPR result_type max() {return _Max;} friend _LIBCPP_FUNC_VIS __rs_default __rs_get(); }; _LIBCPP_FUNC_VIS __rs_default __rs_get(); template void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef uniform_int_distribution _Dp; typedef typename _Dp::param_type _Pp; difference_type __d = __last - __first; if (__d > 1) { _Dp __uid; __rs_default __g = __rs_get(); for (--__last, --__d; __first < __last; ++__first, --__d) { difference_type __i = __uid(__g, _Pp(0, __d)); if (__i != difference_type(0)) swap(*__first, *(__first + __i)); } } } template void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, #ifndef _LIBCPP_CXX03_LANG _RandomNumberGenerator&& __rand) #else _RandomNumberGenerator& __rand) #endif { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; difference_type __d = __last - __first; if (__d > 1) { for (--__last; __first < __last; ++__first, --__d) { difference_type __i = __rand(__d); swap(*__first, *(__first + __i)); } } } #endif template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __last, _SampleIterator __output, _Distance __n, _UniformRandomNumberGenerator & __g, input_iterator_tag) { _Distance __k = 0; for (; __first != __last && __k < __n; ++__first, (void)++__k) __output[__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[__r] = *__first; } return __output + _VSTD::min(__n, __k); } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __last, _SampleIterator __output, _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++ = *__first; --__n; } } return __output; } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, _PopulationIterator __last, _SampleIterator __output, _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, _CommonType(__n), __g, _PopCategory()); } #if _LIBCPP_STD_VER > 14 template inline _LIBCPP_INLINE_VISIBILITY _SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last, _SampleIterator __output, _Distance __n, _UniformRandomNumberGenerator&& __g) { return _VSTD::__sample(__first, __last, __output, __n, __g); } #endif // _LIBCPP_STD_VER > 14 template void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, #ifndef _LIBCPP_CXX03_LANG _UniformRandomNumberGenerator&& __g) #else _UniformRandomNumberGenerator& __g) #endif { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef uniform_int_distribution _Dp; typedef typename _Dp::param_type _Pp; difference_type __d = __last - __first; if (__d > 1) { _Dp __uid; for (--__last, --__d; __first < __last; ++__first, --__d) { difference_type __i = __uid(__g, _Pp(0, __d)); if (__i != difference_type(0)) swap(*__first, *(__first + __i)); } } } template bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) break; if ( __first == __last ) return true; ++__first; for (; __first != __last; ++__first) if (__pred(*__first)) return false; return true; } // partition template _ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { while (true) { if (__first == __last) return __first; if (!__pred(*__first)) break; ++__first; } for (_ForwardIterator __p = __first; ++__p != __last;) { if (__pred(*__p)) { swap(*__first, *__p); ++__first; } } return __first; } template _BidirectionalIterator __partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { while (true) { while (true) { if (__first == __last) return __first; if (!__pred(*__first)) break; ++__first; } do { if (__first == --__last) return __first; } while (!__pred(*__last)); swap(*__first, *__last); ++__first; } } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { return _VSTD::__partition::type> (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); } // partition_copy template pair<_OutputIterator1, _OutputIterator2> partition_copy(_InputIterator __first, _InputIterator __last, _OutputIterator1 __out_true, _OutputIterator2 __out_false, _Predicate __pred) { for (; __first != __last; ++__first) { if (__pred(*__first)) { *__out_true = *__first; ++__out_true; } else { *__out_false = *__first; ++__out_false; } } return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); } // partition_point template _ForwardIterator partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; difference_type __len = _VSTD::distance(__first, __last); while (__len != 0) { difference_type __l2 = __len / 2; _ForwardIterator __m = __first; _VSTD::advance(__m, __l2); if (__pred(*__m)) { __first = ++__m; __len -= __l2 + 1; } else __len = __l2; } return __first; } // stable_partition template _ForwardIterator __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, _Distance __len, _Pair __p, forward_iterator_tag __fit) { // *__first is known to be false // __len >= 1 if (__len == 1) return __first; if (__len == 2) { _ForwardIterator __m = __first; if (__pred(*++__m)) { swap(*__first, *__m); return __m; } return __first; } if (__len <= __p.second) { // The buffer is big enough to use typedef typename iterator_traits<_ForwardIterator>::value_type value_type; __destruct_n __d(0); unique_ptr __h(__p.first, __d); // Move the falses into the temporary buffer, and the trues to the front of the line // Update __first to always point to the end of the trues value_type* __t = __p.first; ::new(__t) value_type(_VSTD::move(*__first)); __d.__incr((value_type*)0); ++__t; _ForwardIterator __i = __first; while (++__i != __last) { if (__pred(*__i)) { *__first = _VSTD::move(*__i); ++__first; } else { ::new(__t) value_type(_VSTD::move(*__i)); __d.__incr((value_type*)0); ++__t; } } // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false __i = __first; for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; } // Else not enough buffer, do in place // __len >= 3 _ForwardIterator __m = __first; _Distance __len2 = __len / 2; // __len2 >= 2 _VSTD::advance(__m, __len2); // recurse on [__first, __m), *__first know to be false // F????????????????? // f m l typedef typename add_lvalue_reference<_Predicate>::type _PredRef; _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit); // TTTFFFFF?????????? // f ff m l // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true _ForwardIterator __m1 = __m; _ForwardIterator __second_false = __last; _Distance __len_half = __len - __len2; while (__pred(*__m1)) { if (++__m1 == __last) goto __second_half_done; --__len_half; } // TTTFFFFFTTTF?????? // f ff m m1 l __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit); __second_half_done: // TTTFFFFFTTTTTFFFFF // f ff m sf l return _VSTD::rotate(__first_false, __m, __second_false); // TTTTTTTTFFFFFFFFFF // | } struct __return_temporary_buffer { template _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} }; template _ForwardIterator __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment // Either prove all true and return __first or point to first false while (true) { if (__first == __last) return __first; if (!__pred(*__first)) break; ++__first; } // We now have a reduced range [__first, __last) // *__first is known to be false typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; typedef typename iterator_traits<_ForwardIterator>::value_type value_type; difference_type __len = _VSTD::distance(__first, __last); pair __p(0, 0); unique_ptr __h; if (__len >= __alloc_limit) { __p = _VSTD::get_temporary_buffer(__len); __h.reset(__p.first); } return __stable_partition::type> (__first, __last, __pred, __len, __p, forward_iterator_tag()); } template _BidirectionalIterator __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, _Distance __len, _Pair __p, bidirectional_iterator_tag __bit) { // *__first is known to be false // *__last is known to be true // __len >= 2 if (__len == 2) { swap(*__first, *__last); return __last; } if (__len == 3) { _BidirectionalIterator __m = __first; if (__pred(*++__m)) { swap(*__first, *__m); swap(*__m, *__last); return __last; } swap(*__m, *__last); swap(*__first, *__m); return __m; } if (__len <= __p.second) { // The buffer is big enough to use typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; __destruct_n __d(0); unique_ptr __h(__p.first, __d); // Move the falses into the temporary buffer, and the trues to the front of the line // Update __first to always point to the end of the trues value_type* __t = __p.first; ::new(__t) value_type(_VSTD::move(*__first)); __d.__incr((value_type*)0); ++__t; _BidirectionalIterator __i = __first; while (++__i != __last) { if (__pred(*__i)) { *__first = _VSTD::move(*__i); ++__first; } else { ::new(__t) value_type(_VSTD::move(*__i)); __d.__incr((value_type*)0); ++__t; } } // move *__last, known to be true *__first = _VSTD::move(*__i); __i = ++__first; // All trues now at start of range, all falses in buffer // Move falses back into range, but don't mess up __first which points to first false for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i) *__i = _VSTD::move(*__t2); // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer return __first; } // Else not enough buffer, do in place // __len >= 4 _BidirectionalIterator __m = __first; _Distance __len2 = __len / 2; // __len2 >= 2 _VSTD::advance(__m, __len2); // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false // F????????????????T // f m l _BidirectionalIterator __m1 = __m; _BidirectionalIterator __first_false = __first; _Distance __len_half = __len2; while (!__pred(*--__m1)) { if (__m1 == __first) goto __first_half_done; --__len_half; } // F???TFFF?????????T // f m1 m l typedef typename add_lvalue_reference<_Predicate>::type _PredRef; __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit); __first_half_done: // TTTFFFFF?????????T // f ff m l // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true __m1 = __m; _BidirectionalIterator __second_false = __last; ++__second_false; __len_half = __len - __len2; while (__pred(*__m1)) { if (++__m1 == __last) goto __second_half_done; --__len_half; } // TTTFFFFFTTTF?????T // f ff m m1 l __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit); __second_half_done: // TTTFFFFFTTTTTFFFFF // f ff m sf l return _VSTD::rotate(__first_false, __m, __second_false); // TTTTTTTTFFFFFFFFFF // | } template _BidirectionalIterator __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment // Either prove all true and return __first or point to first false while (true) { if (__first == __last) return __first; if (!__pred(*__first)) break; ++__first; } // __first points to first false, everything prior to __first is already set. // Either prove [__first, __last) is all false and return __first, or point __last to last true do { if (__first == --__last) return __first; } while (!__pred(*__last)); // We now have a reduced range [__first, __last] // *__first is known to be false // *__last is known to be true // __len >= 2 difference_type __len = _VSTD::distance(__first, __last) + 1; pair __p(0, 0); unique_ptr __h; if (__len >= __alloc_limit) { __p = _VSTD::get_temporary_buffer(__len); __h.reset(__p.first); } return __stable_partition::type> (__first, __last, __pred, __len, __p, bidirectional_iterator_tag()); } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { return __stable_partition::type> (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); } // is_sorted_until template _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first != __last) { _ForwardIterator __i = __first; while (++__i != __last) { if (__comp(*__i, *__first)) return __i; __first = __i; } } return __last; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::is_sorted_until(__first, __last, __less::value_type>()); } // is_sorted template inline _LIBCPP_INLINE_VISIBILITY bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { return _VSTD::is_sorted_until(__first, __last, __comp) == __last; } template inline _LIBCPP_INLINE_VISIBILITY bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { return _VSTD::is_sorted(__first, __last, __less::value_type>()); } // sort // stable, 2-3 compares, 0-2 swaps template unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) { unsigned __r = 0; if (!__c(*__y, *__x)) // if x <= y { if (!__c(*__z, *__y)) // if y <= z return __r; // x <= y && y <= z // x <= y && y > z swap(*__y, *__z); // x <= z && y < z __r = 1; if (__c(*__y, *__x)) // if x > y { swap(*__x, *__y); // x < y && y <= z __r = 2; } return __r; // x <= y && y < z } if (__c(*__z, *__y)) // x > y, if y > z { swap(*__x, *__z); // x < y && y < z __r = 1; return __r; } swap(*__x, *__y); // x > y && y <= z __r = 1; // x < y && x <= z if (__c(*__z, *__y)) // if y > z { swap(*__y, *__z); // x <= y && y < z __r = 2; } return __r; } // x <= y && y <= z // stable, 3-6 compares, 0-5 swaps template unsigned __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) { unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c); if (__c(*__x4, *__x3)) { swap(*__x3, *__x4); ++__r; if (__c(*__x3, *__x2)) { swap(*__x2, *__x3); ++__r; if (__c(*__x2, *__x1)) { swap(*__x1, *__x2); ++__r; } } } return __r; } // stable, 4-10 compares, 0-9 swaps template unsigned __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c) { unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c); if (__c(*__x5, *__x4)) { swap(*__x4, *__x5); ++__r; if (__c(*__x4, *__x3)) { swap(*__x3, *__x4); ++__r; if (__c(*__x3, *__x2)) { swap(*__x2, *__x3); ++__r; if (__c(*__x2, *__x1)) { swap(*__x1, *__x2); ++__r; } } } } return __r; } // Assumes size > 0 template void __selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) { _BirdirectionalIterator __lm1 = __last; for (--__lm1; __first != __lm1; ++__first) { _BirdirectionalIterator __i = _VSTD::min_element<_BirdirectionalIterator, typename add_lvalue_reference<_Compare>::type> (__first, __last, __comp); if (__i != __first) swap(*__first, *__i); } } template void __insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) { typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; if (__first != __last) { _BirdirectionalIterator __i = __first; for (++__i; __i != __last; ++__i) { _BirdirectionalIterator __j = __i; value_type __t(_VSTD::move(*__j)); for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) *__j = _VSTD::move(*__k); *__j = _VSTD::move(__t); } } } template void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; _RandomAccessIterator __j = __first+2; __sort3<_Compare>(__first, __first+1, __j, __comp); for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) { if (__comp(*__i, *__j)) { value_type __t(_VSTD::move(*__i)); _RandomAccessIterator __k = __j; __j = __i; do { *__j = _VSTD::move(*__k); __j = __k; } while (__j != __first && __comp(__t, *--__k)); *__j = _VSTD::move(__t); } __j = __i; } } template bool __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { switch (__last - __first) { case 0: case 1: return true; case 2: if (__comp(*--__last, *__first)) swap(*__first, *__last); return true; case 3: _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); return true; case 4: _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); return true; case 5: _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); return true; } typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; _RandomAccessIterator __j = __first+2; __sort3<_Compare>(__first, __first+1, __j, __comp); const unsigned __limit = 8; unsigned __count = 0; for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) { if (__comp(*__i, *__j)) { value_type __t(_VSTD::move(*__i)); _RandomAccessIterator __k = __j; __j = __i; do { *__j = _VSTD::move(*__k); __j = __k; } while (__j != __first && __comp(__t, *--__k)); *__j = _VSTD::move(__t); if (++__count == __limit) return ++__i == __last; } __j = __i; } return true; } template void __insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1, typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp) { typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; if (__first1 != __last1) { __destruct_n __d(0); unique_ptr __h(__first2, __d); value_type* __last2 = __first2; ::new(__last2) value_type(_VSTD::move(*__first1)); __d.__incr((value_type*)0); for (++__last2; ++__first1 != __last1; ++__last2) { value_type* __j2 = __last2; value_type* __i2 = __j2; if (__comp(*__first1, *--__i2)) { ::new(__j2) value_type(_VSTD::move(*__i2)); __d.__incr((value_type*)0); for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) *__j2 = _VSTD::move(*__i2); *__j2 = _VSTD::move(*__first1); } else { ::new(__j2) value_type(_VSTD::move(*__first1)); __d.__incr((value_type*)0); } } __h.release(); } } template void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { // _Compare is known to be a reference type typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; const difference_type __limit = is_trivially_copy_constructible::value && is_trivially_copy_assignable::value ? 30 : 6; while (true) { __restart: difference_type __len = __last - __first; switch (__len) { case 0: case 1: return; case 2: if (__comp(*--__last, *__first)) swap(*__first, *__last); return; case 3: _VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); return; case 4: _VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); return; case 5: _VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); return; } if (__len <= __limit) { _VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); return; } // __len > 5 _RandomAccessIterator __m = __first; _RandomAccessIterator __lm1 = __last; --__lm1; unsigned __n_swaps; { difference_type __delta; if (__len >= 1000) { __delta = __len/2; __m += __delta; __delta /= 2; __n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp); } else { __delta = __len/2; __m += __delta; __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); } } // *__m is median // partition [__first, __m) < *__m and *__m <= [__m, __last) // (this inhibits tossing elements equivalent to __m around unnecessarily) _RandomAccessIterator __i = __first; _RandomAccessIterator __j = __lm1; // j points beyond range to be tested, *__m is known to be <= *__lm1 // The search going up is known to be guarded but the search coming down isn't. // Prime the downward search with a guard. if (!__comp(*__i, *__m)) // if *__first == *__m { // *__first == *__m, *__first doesn't go in first part // manually guard downward moving __j against __i while (true) { if (__i == --__j) { // *__first == *__m, *__m <= all other elements // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) ++__i; // __first + 1 __j = __last; if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) { while (true) { if (__i == __j) return; // [__first, __last) all equivalent elements if (__comp(*__first, *__i)) { swap(*__i, *__j); ++__n_swaps; ++__i; break; } ++__i; } } // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 if (__i == __j) return; while (true) { while (!__comp(*__first, *__i)) ++__i; while (__comp(*__first, *--__j)) ; if (__i >= __j) break; swap(*__i, *__j); ++__n_swaps; ++__i; } // [__first, __i) == *__first and *__first < [__i, __last) // The first part is sorted, sort the secod part // _VSTD::__sort<_Compare>(__i, __last, __comp); __first = __i; goto __restart; } if (__comp(*__j, *__m)) { swap(*__i, *__j); ++__n_swaps; break; // found guard for downward moving __j, now use unguarded partition } } } // It is known that *__i < *__m ++__i; // j points beyond range to be tested, *__m is known to be <= *__lm1 // if not yet partitioned... if (__i < __j) { // known that *(__i - 1) < *__m // known that __i <= __m while (true) { // __m still guards upward moving __i while (__comp(*__i, *__m)) ++__i; // It is now known that a guard exists for downward moving __j while (!__comp(*--__j, *__m)) ; if (__i > __j) break; swap(*__i, *__j); ++__n_swaps; // It is known that __m != __j // If __m just moved, follow it if (__m == __i) __m = __j; ++__i; } } // [__first, __i) < *__m and *__m <= [__i, __last) if (__i != __m && __comp(*__m, *__i)) { swap(*__i, *__m); ++__n_swaps; } // [__first, __i) < *__i and *__i <= [__i+1, __last) // If we were given a perfect partition, see if insertion sort is quick... if (__n_swaps == 0) { bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) { if (__fs) return; __last = __i; continue; } else { if (__fs) { __first = ++__i; continue; } } } // sort smaller range with recursive call and larger with tail recursion elimination if (__i - __first < __last - __i) { _VSTD::__sort<_Compare>(__first, __i, __comp); // _VSTD::__sort<_Compare>(__i+1, __last, __comp); __first = ++__i; } else { _VSTD::__sort<_Compare>(__i+1, __last, __comp); // _VSTD::__sort<_Compare>(__first, __i, __comp); __last = __i; } } } // This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare template inline _LIBCPP_INLINE_VISIBILITY void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __sort<_Comp_ref>(__first, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __sort<_Comp_ref>(__first, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::sort(__first, __last, __less::value_type>()); } template inline _LIBCPP_INLINE_VISIBILITY void sort(_Tp** __first, _Tp** __last) { _VSTD::sort((size_t*)__first, (size_t*)__last, __less()); } template inline _LIBCPP_INLINE_VISIBILITY void sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) { _VSTD::sort(__first.base(), __last.base()); } template inline _LIBCPP_INLINE_VISIBILITY void sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) { typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; _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*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, signed char*>(signed char*, signed char*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, short*>(short*, short*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, int*>(int*, int*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, unsigned*>(unsigned*, unsigned*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, long*>(long*, long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, long long*>(long long*, long long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, float*>(float*, float*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, double*>(double*, double*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less&, long double*>(long double*, long double*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, char*>(char*, char*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, signed char*>(signed char*, signed char*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, short*>(short*, short*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, int*>(int*, int*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned*>(unsigned*, unsigned*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, long*>(long*, long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, long long*>(long long*, long long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, float*>(float*, float*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, double*>(double*, double*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, __less&)) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS unsigned __sort5<__less&, long double*>(long double*, long double*, long double*, long double*, long double*, __less&)) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC // lower_bound template _ForwardIterator __lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; difference_type __len = _VSTD::distance(__first, __last); while (__len != 0) { difference_type __l2 = __len / 2; _ForwardIterator __m = __first; _VSTD::advance(__m, __l2); if (__comp(*__m, __value_)) { __first = ++__m; __len -= __l2 + 1; } else __len = __l2; } return __first; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __lower_bound<_Comp_ref>(__first, __last, __value_, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { return _VSTD::lower_bound(__first, __last, __value_, __less::value_type, _Tp>()); } // upper_bound template _ForwardIterator __upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; difference_type __len = _VSTD::distance(__first, __last); while (__len != 0) { difference_type __l2 = __len / 2; _ForwardIterator __m = __first; _VSTD::advance(__m, __l2); if (__comp(__value_, *__m)) __len = __l2; else { __first = ++__m; __len -= __l2 + 1; } } return __first; } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __upper_bound<_Comp_ref>(__first, __last, __value_, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { return _VSTD::upper_bound(__first, __last, __value_, __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>()); } // equal_range template pair<_ForwardIterator, _ForwardIterator> __equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; difference_type __len = _VSTD::distance(__first, __last); while (__len != 0) { difference_type __l2 = __len / 2; _ForwardIterator __m = __first; _VSTD::advance(__m, __l2); if (__comp(*__m, __value_)) { __first = ++__m; __len -= __l2 + 1; } else if (__comp(__value_, *__m)) { __last = __m; __len = __l2; } else { _ForwardIterator __mp1 = __m; return pair<_ForwardIterator, _ForwardIterator> ( __lower_bound<_Compare>(__first, __m, __value_, __comp), __upper_bound<_Compare>(++__mp1, __last, __value_, __comp) ); } } return pair<_ForwardIterator, _ForwardIterator>(__first, __first); } template inline _LIBCPP_INLINE_VISIBILITY pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __equal_range<_Comp_ref>(__first, __last, __value_, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __equal_range<_Comp_ref>(__first, __last, __value_, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { return _VSTD::equal_range(__first, __last, __value_, __less::value_type, _Tp>()); } // binary_search template inline _LIBCPP_INLINE_VISIBILITY bool __binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { __first = __lower_bound<_Compare>(__first, __last, __value_, __comp); return __first != __last && !__comp(__value_, *__first); } template inline _LIBCPP_INLINE_VISIBILITY bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __binary_search<_Comp_ref>(__first, __last, __value_, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __binary_search<_Comp_ref>(__first, __last, __value_, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { return _VSTD::binary_search(__first, __last, __value_, __less::value_type, _Tp>()); } // merge template _OutputIterator __merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) return _VSTD::copy(__first1, __last1, __result); if (__comp(*__first2, *__first1)) { *__result = *__first2; ++__first2; } else { *__result = *__first1; ++__first1; } } return _VSTD::copy(__first2, __last2, __result); } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { typedef typename iterator_traits<_InputIterator1>::value_type __v1; typedef typename iterator_traits<_InputIterator2>::value_type __v2; return merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); } // inplace_merge template void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) { _VSTD::move(__first1, __last1, __result); return; } if (__comp(*__first2, *__first1)) { *__result = _VSTD::move(*__first2); ++__first2; } else { *__result = _VSTD::move(*__first1); ++__first1; } } // __first2 through __last2 are already in the right spot. } template void __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, typename iterator_traits<_BidirectionalIterator>::difference_type __len2, typename iterator_traits<_BidirectionalIterator>::value_type* __buff) { typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; __destruct_n __d(0); unique_ptr __h2(__buff, __d); if (__len1 <= __len2) { value_type* __p = __buff; for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p) ::new(__p) value_type(_VSTD::move(*__i)); __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); } else { value_type* __p = __buff; for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p) ::new(__p) value_type(_VSTD::move(*__i)); typedef reverse_iterator<_BidirectionalIterator> _RBi; typedef reverse_iterator _Rv; __half_inplace_merge(_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), __negate<_Compare>(__comp)); } } template void __inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, typename iterator_traits<_BidirectionalIterator>::difference_type __len2, typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size) { typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; while (true) { // if __middle == __last, we're done if (__len2 == 0) return; if (__len1 <= __buff_size || __len2 <= __buff_size) return __buffered_inplace_merge<_Compare> (__first, __middle, __last, __comp, __len1, __len2, __buff); // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 for (; true; ++__first, (void) --__len1) { if (__len1 == 0) return; if (__comp(*__middle, *__first)) break; } // __first < __middle < __last // *__first > *__middle // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that // all elements in: // [__first, __m1) <= [__middle, __m2) // [__middle, __m2) < [__m1, __middle) // [__m1, __middle) <= [__m2, __last) // and __m1 or __m2 is in the middle of its range _BidirectionalIterator __m1; // "median" of [__first, __middle) _BidirectionalIterator __m2; // "median" of [__middle, __last) difference_type __len11; // distance(__first, __m1) difference_type __len21; // distance(__middle, __m2) // binary search smaller range if (__len1 < __len2) { // __len >= 1, __len2 >= 2 __len21 = __len2 / 2; __m2 = __middle; _VSTD::advance(__m2, __len21); __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp); __len11 = _VSTD::distance(__first, __m1); } else { if (__len1 == 1) { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 // It is known *__first > *__middle swap(*__first, *__middle); return; } // __len1 >= 2, __len2 >= 1 __len11 = __len1 / 2; __m1 = __first; _VSTD::advance(__m1, __len11); __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp); __len21 = _VSTD::distance(__middle, __m2); } difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) difference_type __len22 = __len2 - __len21; // distance(__m2, __last) // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) // swap middle two partitions __middle = _VSTD::rotate(__m1, __middle, __m2); // __len12 and __len21 now have swapped meanings // merge smaller range with recurisve call and larger with tail recursion elimination if (__len11 + __len21 < __len12 + __len22) { __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); // __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); __first = __middle; __middle = __m2; __len1 = __len12; __len2 = __len22; } else { __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); // __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); __last = __middle; __middle = __m1; __len1 = __len11; __len2 = __len21; } } } template inline _LIBCPP_INLINE_VISIBILITY void inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) { typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; difference_type __len1 = _VSTD::distance(__first, __middle); difference_type __len2 = _VSTD::distance(__middle, __last); difference_type __buf_size = _VSTD::min(__len1, __len2); pair __buf = _VSTD::get_temporary_buffer(__buf_size); unique_ptr __h(__buf.first); #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __c, __len1, __len2, __buf.first, __buf.second); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, __buf.first, __buf.second); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) { _VSTD::inplace_merge(__first, __middle, __last, __less::value_type>()); } // stable_sort template void __merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) { typedef typename iterator_traits<_InputIterator1>::value_type value_type; __destruct_n __d(0); unique_ptr __h(__result, __d); for (; true; ++__result) { if (__first1 == __last1) { for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first2)); __h.release(); return; } if (__first2 == __last2) { for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0)) ::new (__result) value_type(_VSTD::move(*__first1)); __h.release(); return; } if (__comp(*__first2, *__first1)) { ::new (__result) value_type(_VSTD::move(*__first2)); __d.__incr((value_type*)0); ++__first2; } else { ::new (__result) value_type(_VSTD::move(*__first1)); __d.__incr((value_type*)0); ++__first1; } } } template void __merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) { for (; __first1 != __last1; ++__first1, ++__result) *__result = _VSTD::move(*__first1); return; } if (__comp(*__first2, *__first1)) { *__result = _VSTD::move(*__first2); ++__first2; } else { *__result = _VSTD::move(*__first1); ++__first1; } } for (; __first2 != __last2; ++__first2, ++__result) *__result = _VSTD::move(*__first2); } template void __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size); template void __stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; switch (__len) { case 0: return; case 1: ::new(__first2) value_type(_VSTD::move(*__first1)); return; case 2: __destruct_n __d(0); unique_ptr __h2(__first2, __d); if (__comp(*--__last1, *__first1)) { ::new(__first2) value_type(_VSTD::move(*__last1)); __d.__incr((value_type*)0); ++__first2; ::new(__first2) value_type(_VSTD::move(*__first1)); } else { ::new(__first2) value_type(_VSTD::move(*__first1)); __d.__incr((value_type*)0); ++__first2; ::new(__first2) value_type(_VSTD::move(*__last1)); } __h2.release(); return; } if (__len <= 8) { __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp); return; } typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; _RandomAccessIterator __m = __first1 + __l2; __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2); __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp); } template struct __stable_sort_switch { static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value; }; template void __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; switch (__len) { case 0: case 1: return; case 2: if (__comp(*--__last, *__first)) swap(*__first, *__last); return; } if (__len <= static_cast(__stable_sort_switch::value)) { __insertion_sort<_Compare>(__first, __last, __comp); return; } typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; _RandomAccessIterator __m = __first + __l2; if (__len <= __buff_size) { __destruct_n __d(0); unique_ptr __h2(__buff, __d); __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff); __d.__set(__l2, (value_type*)0); __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); __d.__set(__len, (value_type*)0); __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); // __merge<_Compare>(move_iterator(__buff), // move_iterator(__buff + __l2), // move_iterator<_RandomAccessIterator>(__buff + __l2), // move_iterator<_RandomAccessIterator>(__buff + __len), // __first, __comp); return; } __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size); __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); } template inline _LIBCPP_INLINE_VISIBILITY void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; difference_type __len = __last - __first; pair __buf(0, 0); unique_ptr __h; if (__len > static_cast(__stable_sort_switch::value)) { __buf = _VSTD::get_temporary_buffer(__len); __h.reset(__buf.first); } #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __stable_sort<_Comp_ref>(__first, __last, __c, __len, __buf.first, __buf.second); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::stable_sort(__first, __last, __less::value_type>()); } // is_heap_until template _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type; difference_type __len = __last - __first; difference_type __p = 0; difference_type __c = 1; _RandomAccessIterator __pp = __first; while (__c < __len) { _RandomAccessIterator __cp = __first + __c; if (__comp(*__pp, *__cp)) return __cp; ++__c; ++__cp; if (__c == __len) return __last; if (__comp(*__pp, *__cp)) return __cp; ++__p; ++__pp; __c = 2 * __p + 1; } return __last; } template inline _LIBCPP_INLINE_VISIBILITY _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { return _VSTD::is_heap_until(__first, __last, __less::value_type>()); } // is_heap template inline _LIBCPP_INLINE_VISIBILITY bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { return _VSTD::is_heap_until(__first, __last, __comp) == __last; } template inline _LIBCPP_INLINE_VISIBILITY bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { return _VSTD::is_heap(__first, __last, __less::value_type>()); } // push_heap template void __sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; if (__len > 1) { __len = (__len - 2) / 2; _RandomAccessIterator __ptr = __first + __len; if (__comp(*__ptr, *--__last)) { value_type __t(_VSTD::move(*__last)); do { *__last = _VSTD::move(*__ptr); __last = __ptr; if (__len == 0) break; __len = (__len - 1) / 2; __ptr = __first + __len; } while (__comp(*__ptr, __t)); *__last = _VSTD::move(__t); } } } template inline _LIBCPP_INLINE_VISIBILITY void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __sift_up<_Comp_ref>(__first, __last, __c, __last - __first); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __sift_up<_Comp_ref>(__first, __last, __comp, __last - __first); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::push_heap(__first, __last, __less::value_type>()); } // pop_heap template void __sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len, _RandomAccessIterator __start) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; // left-child of __start is at 2 * __start + 1 // right-child of __start is at 2 * __start + 2 difference_type __child = __start - __first; if (__len < 2 || (__len - 2) / 2 < __child) return; __child = 2 * __child + 1; _RandomAccessIterator __child_i = __first + __child; if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { // right-child exists and is greater than left-child ++__child_i; ++__child; } // check if we are in heap-order if (__comp(*__child_i, *__start)) // we are, __start is larger than it's largest child return; value_type __top(_VSTD::move(*__start)); do { // we are not in heap-order, swap the parent with it's largest child *__start = _VSTD::move(*__child_i); __start = __child_i; if ((__len - 2) / 2 < __child) break; // recompute the child based off of the updated parent __child = 2 * __child + 1; __child_i = __first + __child; if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) { // right-child exists and is greater than left-child ++__child_i; ++__child; } // check if we are in heap-order } while (!__comp(*__child_i, __top)); *__start = _VSTD::move(__top); } template inline _LIBCPP_INLINE_VISIBILITY void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, typename iterator_traits<_RandomAccessIterator>::difference_type __len) { if (__len > 1) { swap(*__first, *--__last); __sift_down<_Compare>(__first, __last, __comp, __len - 1, __first); } } template inline _LIBCPP_INLINE_VISIBILITY void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __pop_heap<_Comp_ref>(__first, __last, __c, __last - __first); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::pop_heap(__first, __last, __less::value_type>()); } // make_heap template void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; difference_type __n = __last - __first; if (__n > 1) { // start from the first parent, there is no need to consider children for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) { __sift_down<_Compare>(__first, __last, __comp, __n, __first + __start); } } } template inline _LIBCPP_INLINE_VISIBILITY void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __make_heap<_Comp_ref>(__first, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __make_heap<_Comp_ref>(__first, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::make_heap(__first, __last, __less::value_type>()); } // sort_heap template void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; for (difference_type __n = __last - __first; __n > 1; --__last, --__n) __pop_heap<_Compare>(__first, __last, __comp, __n); } template inline _LIBCPP_INLINE_VISIBILITY void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __sort_heap<_Comp_ref>(__first, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __sort_heap<_Comp_ref>(__first, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { _VSTD::sort_heap(__first, __last, __less::value_type>()); } // partial_sort template void __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) { __make_heap<_Compare>(__first, __middle, __comp); typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first; for (_RandomAccessIterator __i = __middle; __i != __last; ++__i) { if (__comp(*__i, *__first)) { swap(*__i, *__first); __sift_down<_Compare>(__first, __middle, __comp, __len, __first); } } __sort_heap<_Compare>(__first, __middle, __comp); } template inline _LIBCPP_INLINE_VISIBILITY void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __partial_sort<_Comp_ref>(__first, __middle, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __partial_sort<_Comp_ref>(__first, __middle, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) { _VSTD::partial_sort(__first, __middle, __last, __less::value_type>()); } // partial_sort_copy template _RandomAccessIterator __partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) { _RandomAccessIterator __r = __result_first; if (__r != __result_last) { for (; __first != __last && __r != __result_last; (void) ++__first, ++__r) *__r = *__first; __make_heap<_Compare>(__result_first, __r, __comp); typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first; for (; __first != __last; ++__first) if (__comp(*__first, *__result_first)) { *__result_first = *__first; __sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first); } __sort_heap<_Compare>(__result_first, __r, __comp); } return __r; } template inline _LIBCPP_INLINE_VISIBILITY _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last) { return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last, __less::value_type>()); } // nth_element template void __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { // _Compare is known to be a reference type typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; const difference_type __limit = 7; while (true) { __restart: if (__nth == __last) return; difference_type __len = __last - __first; switch (__len) { case 0: case 1: return; case 2: if (__comp(*--__last, *__first)) swap(*__first, *__last); return; case 3: { _RandomAccessIterator __m = __first; _VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp); return; } } if (__len <= __limit) { __selection_sort<_Compare>(__first, __last, __comp); return; } // __len > __limit >= 3 _RandomAccessIterator __m = __first + __len/2; _RandomAccessIterator __lm1 = __last; unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp); // *__m is median // partition [__first, __m) < *__m and *__m <= [__m, __last) // (this inhibits tossing elements equivalent to __m around unnecessarily) _RandomAccessIterator __i = __first; _RandomAccessIterator __j = __lm1; // j points beyond range to be tested, *__lm1 is known to be <= *__m // The search going up is known to be guarded but the search coming down isn't. // Prime the downward search with a guard. if (!__comp(*__i, *__m)) // if *__first == *__m { // *__first == *__m, *__first doesn't go in first part // manually guard downward moving __j against __i while (true) { if (__i == --__j) { // *__first == *__m, *__m <= all other elements // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) ++__i; // __first + 1 __j = __last; if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) { while (true) { if (__i == __j) return; // [__first, __last) all equivalent elements if (__comp(*__first, *__i)) { swap(*__i, *__j); ++__n_swaps; ++__i; break; } ++__i; } } // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 if (__i == __j) return; while (true) { while (!__comp(*__first, *__i)) ++__i; while (__comp(*__first, *--__j)) ; if (__i >= __j) break; swap(*__i, *__j); ++__n_swaps; ++__i; } // [__first, __i) == *__first and *__first < [__i, __last) // The first part is sorted, if (__nth < __i) return; // __nth_element the secod part // __nth_element<_Compare>(__i, __nth, __last, __comp); __first = __i; goto __restart; } if (__comp(*__j, *__m)) { swap(*__i, *__j); ++__n_swaps; break; // found guard for downward moving __j, now use unguarded partition } } } ++__i; // j points beyond range to be tested, *__lm1 is known to be <= *__m // if not yet partitioned... if (__i < __j) { // known that *(__i - 1) < *__m while (true) { // __m still guards upward moving __i while (__comp(*__i, *__m)) ++__i; // It is now known that a guard exists for downward moving __j while (!__comp(*--__j, *__m)) ; if (__i >= __j) break; swap(*__i, *__j); ++__n_swaps; // It is known that __m != __j // If __m just moved, follow it if (__m == __i) __m = __j; ++__i; } } // [__first, __i) < *__m and *__m <= [__i, __last) if (__i != __m && __comp(*__m, *__i)) { swap(*__i, *__m); ++__n_swaps; } // [__first, __i) < *__i and *__i <= [__i+1, __last) if (__nth == __i) return; if (__n_swaps == 0) { // We were given a perfectly partitioned sequence. Coincidence? if (__nth < __i) { // Check for [__first, __i) already sorted __j = __m = __first; while (++__j != __i) { if (__comp(*__j, *__m)) // not yet sorted, so sort goto not_sorted; __m = __j; } // [__first, __i) sorted return; } else { // Check for [__i, __last) already sorted __j = __m = __i; while (++__j != __last) { if (__comp(*__j, *__m)) // not yet sorted, so sort goto not_sorted; __m = __j; } // [__i, __last) sorted return; } } not_sorted: // __nth_element on range containing __nth if (__nth < __i) { // __nth_element<_Compare>(__first, __nth, __i, __comp); __last = __i; } else { // __nth_element<_Compare>(__i+1, __nth, __last, __comp); __first = ++__i; } } } template inline _LIBCPP_INLINE_VISIBILITY void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); __nth_element<_Comp_ref>(__first, __nth, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; __nth_element<_Comp_ref>(__first, __nth, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { _VSTD::nth_element(__first, __nth, __last, __less::value_type>()); } // includes template bool __includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { for (; __first2 != __last2; ++__first1) { if (__first1 == __last1 || __comp(*__first2, *__first1)) return false; if (!__comp(*__first1, *__first2)) ++__first2; } return true; } template inline _LIBCPP_INLINE_VISIBILITY bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return _VSTD::includes(__first1, __last1, __first2, __last2, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // set_union template _OutputIterator __set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) return _VSTD::copy(__first1, __last1, __result); if (__comp(*__first2, *__first1)) { *__result = *__first2; ++__first2; } else { *__result = *__first1; if (!__comp(*__first1, *__first2)) ++__first2; ++__first1; } } return _VSTD::copy(__first2, __last2, __result); } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { return _VSTD::set_union(__first1, __last1, __first2, __last2, __result, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // set_intersection template _OutputIterator __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { while (__first1 != __last1 && __first2 != __last2) { if (__comp(*__first1, *__first2)) ++__first1; else { if (!__comp(*__first2, *__first1)) { *__result = *__first1; ++__result; ++__first1; } ++__first2; } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // set_difference template _OutputIterator __set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { while (__first1 != __last1) { if (__first2 == __last2) return _VSTD::copy(__first1, __last1, __result); if (__comp(*__first1, *__first2)) { *__result = *__first1; ++__result; ++__first1; } else { if (!__comp(*__first2, *__first1)) ++__first1; ++__first2; } } return __result; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { return _VSTD::set_difference(__first1, __last1, __first2, __last2, __result, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // set_symmetric_difference template _OutputIterator __set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { while (__first1 != __last1) { if (__first2 == __last2) return _VSTD::copy(__first1, __last1, __result); if (__comp(*__first1, *__first2)) { *__result = *__first1; ++__result; ++__first1; } else { if (__comp(*__first2, *__first1)) { *__result = *__first2; ++__result; } else ++__first1; ++__first2; } } return _VSTD::copy(__first2, __last2, __result); } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { return _VSTD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // lexicographical_compare template bool __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { for (; __first2 != __last2; ++__first1, (void) ++__first2) { if (__first1 == __last1 || __comp(*__first1, *__first2)) return true; if (__comp(*__first2, *__first1)) return false; } return false; } template inline _LIBCPP_INLINE_VISIBILITY bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, __less::value_type, typename iterator_traits<_InputIterator2>::value_type>()); } // next_permutation template bool __next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { _BidirectionalIterator __i = __last; if (__first == __last || __first == --__i) return false; while (true) { _BidirectionalIterator __ip1 = __i; if (__comp(*--__i, *__ip1)) { _BidirectionalIterator __j = __last; while (!__comp(*__i, *--__j)) ; swap(*__i, *__j); _VSTD::reverse(__ip1, __last); return true; } if (__i == __first) { _VSTD::reverse(__first, __last); return false; } } } template inline _LIBCPP_INLINE_VISIBILITY bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __next_permutation<_Comp_ref>(__first, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __next_permutation<_Comp_ref>(__first, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { return _VSTD::next_permutation(__first, __last, __less::value_type>()); } // prev_permutation template bool __prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { _BidirectionalIterator __i = __last; if (__first == __last || __first == --__i) return false; while (true) { _BidirectionalIterator __ip1 = __i; if (__comp(*__ip1, *--__i)) { _BidirectionalIterator __j = __last; while (!__comp(*--__j, *__i)) ; swap(*__i, *__j); _VSTD::reverse(__ip1, __last); return true; } if (__i == __first) { _VSTD::reverse(__first, __last); return false; } } } template inline _LIBCPP_INLINE_VISIBILITY bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { #ifdef _LIBCPP_DEBUG typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; __debug_less<_Compare> __c(__comp); return __prev_permutation<_Comp_ref>(__first, __last, __c); #else // _LIBCPP_DEBUG typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; return __prev_permutation<_Comp_ref>(__first, __last, __comp); #endif // _LIBCPP_DEBUG } template inline _LIBCPP_INLINE_VISIBILITY bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) { return _VSTD::prev_permutation(__first, __last, __less::value_type>()); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_ALGORITHM Index: vendor/libc++/dist/include/string =================================================================== --- vendor/libc++/dist/include/string (revision 321189) +++ vendor/libc++/dist/include/string (revision 321190) @@ -1,4048 +1,4041 @@ // -*- 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 fpos { private: stateT st; public: fpos(streamoff = streamoff()); operator streamoff() const; stateT state() const; void state(stateT); fpos& operator+=(streamoff); fpos operator+ (streamoff) const; fpos& operator-=(streamoff); fpos operator- (streamoff) const; }; template streamoff operator-(const fpos& x, const fpos& y); template bool operator==(const fpos& x, const fpos& y); template bool operator!=(const fpos& x, const fpos& y); template struct char_traits { typedef charT char_type; typedef ... int_type; typedef streamoff off_type; typedef streampos pos_type; typedef mbstate_t state_type; static 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 int compare(const char_type* s1, const char_type* s2, size_t n); static size_t length(const char_type* s); 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); 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; template <> struct char_traits; template, class Allocator = allocator > class basic_string { public: // types: typedef traits traits_type; typedef typename traits_type::char_type value_type; typedef Allocator allocator_type; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::difference_type difference_type; typedef typename allocator_type::reference reference; typedef typename allocator_type::const_reference const_reference; typedef typename allocator_type::pointer pointer; typedef typename allocator_type::const_pointer const_pointer; typedef implementation-defined iterator; typedef implementation-defined const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; static const size_type npos = -1; basic_string() noexcept(is_nothrow_default_constructible::value); explicit basic_string(const allocator_type& a); basic_string(const basic_string& str); basic_string(basic_string&& str) noexcept(is_nothrow_move_constructible::value); 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()); template basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17 explicit basic_string(const basic_string_view 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()); template basic_string(InputIterator begin, InputIterator end, const allocator_type& a = allocator_type()); basic_string(initializer_list, const Allocator& = Allocator()); basic_string(const basic_string&, const Allocator&); basic_string(basic_string&&, const Allocator&); ~basic_string(); operator basic_string_view() const noexcept; basic_string& operator=(const basic_string& str); basic_string& operator=(basic_string_view sv); basic_string& operator=(basic_string&& str) noexcept( allocator_type::propagate_on_container_move_assignment::value || allocator_type::is_always_equal::value ); // C++17 basic_string& operator=(const value_type* s); basic_string& operator=(value_type c); basic_string& operator=(initializer_list); iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; size_type size() const noexcept; size_type length() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; void resize(size_type n, value_type c); void resize(size_type n); void reserve(size_type res_arg = 0); void shrink_to_fit(); void clear() noexcept; bool empty() const noexcept; const_reference operator[](size_type pos) const; reference operator[](size_type pos); const_reference at(size_type n) const; reference at(size_type n); basic_string& operator+=(const basic_string& str); basic_string& operator+=(basic_string_view sv); basic_string& operator+=(const value_type* s); basic_string& operator+=(value_type c); basic_string& operator+=(initializer_list); basic_string& append(const basic_string& str); basic_string& append(basic_string_view sv); basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14 template 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); template basic_string& append(InputIterator first, InputIterator last); basic_string& append(initializer_list); void push_back(value_type c); void pop_back(); reference front(); const_reference front() const; reference back(); const_reference back() const; basic_string& assign(const basic_string& str); basic_string& assign(basic_string_view sv); basic_string& assign(basic_string&& str); basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14 template 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); template basic_string& assign(InputIterator first, InputIterator last); basic_string& assign(initializer_list); basic_string& insert(size_type pos1, const basic_string& str); basic_string& insert(size_type pos1, basic_string_view sv); basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n); template 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); iterator insert(const_iterator p, value_type c); iterator insert(const_iterator p, size_type n, value_type c); template iterator insert(const_iterator p, InputIterator first, InputIterator last); iterator insert(const_iterator p, initializer_list); basic_string& erase(size_type pos = 0, size_type n = npos); iterator erase(const_iterator position); 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 sv); basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2=npos); // C++14 template 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 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); template basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); basic_string& replace(const_iterator i1, const_iterator i2, initializer_list); size_type copy(value_type* s, size_type n, size_type pos = 0) const; basic_string substr(size_type pos = 0, size_type n = npos) const; void swap(basic_string& str) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 const value_type* c_str() const noexcept; const value_type* data() const noexcept; value_type* data() noexcept; // C++17 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 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 ffind(basic_string_view sv, size_type pos = 0) 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 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 sv, size_type pos = 0) 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 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 sv, size_type pos = 0) 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 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 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 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 __invariants() const; }; template basic_string operator+(const basic_string& lhs, const basic_string& rhs); template basic_string operator+(const charT* lhs , const basic_string&rhs); template basic_string operator+(charT lhs, const basic_string& rhs); template basic_string operator+(const basic_string& lhs, const charT* rhs); template basic_string operator+(const basic_string& lhs, charT rhs); template bool operator==(const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator==(const charT* lhs, const basic_string& rhs) noexcept; template bool operator==(const basic_string& lhs, const charT* rhs) noexcept; template bool operator!=(const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator!=(const charT* lhs, const basic_string& rhs) noexcept; template bool operator!=(const basic_string& lhs, const charT* rhs) noexcept; template bool operator< (const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator< (const basic_string& lhs, const charT* rhs) noexcept; template bool operator< (const charT* lhs, const basic_string& rhs) noexcept; template bool operator> (const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator> (const basic_string& lhs, const charT* rhs) noexcept; template bool operator> (const charT* lhs, const basic_string& rhs) noexcept; template bool operator<=(const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator<=(const basic_string& lhs, const charT* rhs) noexcept; template bool operator<=(const charT* lhs, const basic_string& rhs) noexcept; template bool operator>=(const basic_string& lhs, const basic_string& rhs) noexcept; template bool operator>=(const basic_string& lhs, const charT* rhs) noexcept; template bool operator>=(const charT* lhs, const basic_string& rhs) noexcept; template void swap(basic_string& lhs, basic_string& rhs) noexcept(noexcept(lhs.swap(rhs))); template basic_istream& operator>>(basic_istream& is, basic_string& str); template basic_ostream& operator<<(basic_ostream& os, const basic_string& str); template basic_istream& getline(basic_istream& is, basic_string& str, charT delim); template basic_istream& getline(basic_istream& is, basic_string& str); typedef basic_string string; typedef basic_string wstring; typedef basic_string u16string; typedef basic_string u32string; int stoi (const string& str, size_t* idx = 0, int base = 10); long stol (const string& str, size_t* idx = 0, int base = 10); unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); long long stoll (const string& str, size_t* idx = 0, int base = 10); unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10); float stof (const string& str, size_t* idx = 0); double stod (const string& str, size_t* idx = 0); long double stold(const string& str, size_t* idx = 0); string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float val); string to_string(double val); string to_string(long double val); int stoi (const wstring& str, size_t* idx = 0, int base = 10); long stol (const wstring& str, size_t* idx = 0, int base = 10); unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); long long stoll (const wstring& str, size_t* idx = 0, int base = 10); unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10); float stof (const wstring& str, size_t* idx = 0); double stod (const wstring& str, size_t* idx = 0); long double stold(const wstring& str, size_t* idx = 0); wstring to_wstring(int val); wstring to_wstring(unsigned val); wstring to_wstring(long val); wstring to_wstring(unsigned long val); wstring to_wstring(long long val); wstring to_wstring(unsigned long long val); wstring to_wstring(float val); wstring to_wstring(double val); wstring to_wstring(long double val); template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; basic_string operator "" s( const char *str, size_t len ); // C++14 basic_string operator "" s( const wchar_t *str, size_t len ); // C++14 basic_string operator "" s( const char16_t *str, size_t len ); // C++14 basic_string operator "" s( const char32_t *str, size_t len ); // C++14 } // std */ #include <__config> #include #include #include #include // For EOF. #include #include #include #include #include #include #include #include #include <__functional_base> #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS #include #endif #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 // fpos template class _LIBCPP_TEMPLATE_VIS fpos { private: _StateT __st_; streamoff __off_; public: _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;} _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;} _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;} _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;} _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;} _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;} _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;} }; template inline _LIBCPP_INLINE_VISIBILITY streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {return streamoff(__x) - streamoff(__y);} template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {return streamoff(__x) == streamoff(__y);} template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {return streamoff(__x) != streamoff(__y);} // basic_string template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const basic_string<_CharT, _Traits, _Allocator>& __y); template basic_string<_CharT, _Traits, _Allocator> operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); template basic_string<_CharT, _Traits, _Allocator> operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); template class _LIBCPP_TEMPLATE_VIS __basic_string_common { protected: _LIBCPP_NORETURN void __throw_length_error() const; _LIBCPP_NORETURN void __throw_out_of_range() const; }; template void __basic_string_common<__b>::__throw_length_error() const { _VSTD::__throw_length_error("basic_string"); } template void __basic_string_common<__b>::__throw_out_of_range() const { _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_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC #ifdef _LIBCPP_NO_EXCEPTIONS template struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {}; #elif defined(_LIBCPP_HAS_NO_NOEXCEPT) template struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {}; #else template ::value> struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( noexcept(++(declval<_Iter&>())) && is_nothrow_assignable<_Iter&, _Iter>::value && noexcept(declval<_Iter>() == declval<_Iter>()) && noexcept(*declval<_Iter>()) )) {}; template struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; #endif template 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 struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT( ( is_convertible >::value && !is_convertible::value)) {}; #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template struct __padding { unsigned char __xx[sizeof(_CharT)-1]; }; template struct __padding<_CharT, 1> { }; #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template class _LIBCPP_TEMPLATE_VIS basic_string : private __basic_string_common { public: typedef basic_string __self; typedef basic_string_view<_CharT, _Traits> __self_view; typedef _Traits traits_type; typedef _CharT value_type; typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef value_type& reference; typedef const value_type& const_reference; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; static_assert(is_pod::value, "Character type of basic_string 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"); static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); #if defined(_LIBCPP_RAW_ITERATORS) typedef pointer iterator; typedef const_pointer const_iterator; #else // defined(_LIBCPP_RAW_ITERATORS) typedef __wrap_iter iterator; typedef __wrap_iter const_iterator; #endif // defined(_LIBCPP_RAW_ITERATORS) typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; private: #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT struct __long { pointer __data_; size_type __size_; size_type __cap_; }; #if _LIBCPP_BIG_ENDIAN static const size_type __short_mask = 0x01; static const size_type __long_mask = 0x1ul; #else // _LIBCPP_BIG_ENDIAN 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 ? (sizeof(__long) - 1)/sizeof(value_type) : 2}; struct __short { value_type __data_[__min_cap]; struct : __padding { unsigned char __size_; }; }; #else struct __long { size_type __cap_; size_type __size_; pointer __data_; }; #if _LIBCPP_BIG_ENDIAN static const size_type __short_mask = 0x80; static const size_type __long_mask = ~(size_type(~0) >> 1); #else // _LIBCPP_BIG_ENDIAN 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 ? (sizeof(__long) - 1)/sizeof(value_type) : 2}; struct __short { union { unsigned char __size_; value_type __lx; }; value_type __data_[__min_cap]; }; #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT union __ulx{__long __lx; __short __lxx;}; enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; struct __raw { size_type __words[__n_words]; }; struct __rep { union { __long __l; __short __s; __raw __r; }; }; __compressed_pair<__rep, allocator_type> __r_; public: static const size_type npos = -1; _LIBCPP_INLINE_VISIBILITY basic_string() _NOEXCEPT_(is_nothrow_default_constructible::value); _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value); #else _NOEXCEPT; #endif basic_string(const basic_string& __str); basic_string(const basic_string& __str, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_move_constructible::value); #else _NOEXCEPT; #endif _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str, const allocator_type& __a); #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s); _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY basic_string(size_type __n, _CharT __c); _LIBCPP_INLINE_VISIBILITY basic_string(size_type __n, _CharT __c, const _Allocator& __a); basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()); _LIBCPP_INLINE_VISIBILITY basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()); template _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 _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last); template _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string(initializer_list<_CharT> __il); _LIBCPP_INLINE_VISIBILITY basic_string(initializer_list<_CharT> __il, const _Allocator& __a); #endif // _LIBCPP_CXX03_LANG 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_CXX03_LANG template #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 __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); #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(this, __get_pointer());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return const_iterator(this, __get_pointer());} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(this, __get_pointer() + size());} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(this, __get_pointer() + size());} #else _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(__get_pointer());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return const_iterator(__get_pointer());} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(__get_pointer() + size());} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(__get_pointer() + size());} #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return begin();} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return end();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __is_long() ? __get_long_size() : __get_short_size();} _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return (__is_long() ? __get_long_cap() : static_cast(__min_cap)) - 1;} 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); _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_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+=(__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_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list __il) {return append(__il);} #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 _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 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); template _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 _LIBCPP_INLINE_VISIBILITY append(_InputIterator __first, _InputIterator __last) { const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); return *this; } template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string& >::type _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 __il) {return append(__il.begin(), __il.size());} #endif // _LIBCPP_CXX03_LANG void push_back(value_type __c); _LIBCPP_INLINE_VISIBILITY void pop_back(); _LIBCPP_INLINE_VISIBILITY reference front(); _LIBCPP_INLINE_VISIBILITY const_reference front() const; _LIBCPP_INLINE_VISIBILITY reference back(); _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_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& assign(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {*this = _VSTD::move(__str); return *this;} #endif basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); template _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 _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 assign(_InputIterator __first, _InputIterator __last); template _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_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& assign(initializer_list __il) {return assign(__il.begin(), __il.size());} #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 _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); basic_string& insert(size_type __pos, size_type __n, value_type __c); iterator insert(const_iterator __pos, value_type __c); _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, size_type __n, value_type __c); template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, iterator >::type insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); template _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_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, initializer_list __il) {return insert(__pos, __il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG basic_string& erase(size_type __pos = 0, size_type __n = npos); _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __pos); _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __first, const_iterator __last); _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 _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 _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_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list __il) {return replace(__i1, __i2, __il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; _LIBCPP_INLINE_VISIBILITY basic_string substr(size_type __pos = 0, size_type __n = npos) const; _LIBCPP_INLINE_VISIBILITY void swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT_DEBUG; #else _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value); #endif _LIBCPP_INLINE_VISIBILITY 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 _LIBCPP_INLINE_VISIBILITY value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} #endif _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return __alloc();} _LIBCPP_INLINE_VISIBILITY size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; _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; size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type rfind(__self_view __sv, size_type __pos = 0) 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; size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; _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; _LIBCPP_INLINE_VISIBILITY size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(__self_view __sv, size_type __pos = 0) 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; _LIBCPP_INLINE_VISIBILITY size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; _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; _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(__self_view __sv, size_type __pos = 0) 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; _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; _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 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; _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; bool __decrementable(const const_iterator* __i) const; bool __addable(const const_iterator* __i, ptrdiff_t __n) const; bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; #endif // _LIBCPP_DEBUG_LEVEL >= 2 private: _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() _NOEXCEPT {return __r_.second();} _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __r_.second();} #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT # if _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} # else {__r_.first().__s.__size_ = (unsigned char)(__s);} # endif _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT # if _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_ >> 1;} # else {return __r_.first().__s.__size_;} # endif #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT # if _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s);} # else {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} # endif _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT # if _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_;} # else {return __r_.first().__s.__size_ >> 1;} # endif #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_long_size(size_type __s) _NOEXCEPT {__r_.first().__l.__size_ = __s;} _LIBCPP_INLINE_VISIBILITY size_type __get_long_size() const _NOEXCEPT {return __r_.first().__l.__size_;} _LIBCPP_INLINE_VISIBILITY void __set_size(size_type __s) _NOEXCEPT {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} _LIBCPP_INLINE_VISIBILITY void __set_long_cap(size_type __s) _NOEXCEPT {__r_.first().__l.__cap_ = __long_mask | __s;} _LIBCPP_INLINE_VISIBILITY size_type __get_long_cap() const _NOEXCEPT {return __r_.first().__l.__cap_ & size_type(~__long_mask);} _LIBCPP_INLINE_VISIBILITY void __set_long_pointer(pointer __p) _NOEXCEPT {__r_.first().__l.__data_ = __p;} _LIBCPP_INLINE_VISIBILITY pointer __get_long_pointer() _NOEXCEPT {return __r_.first().__l.__data_;} _LIBCPP_INLINE_VISIBILITY const_pointer __get_long_pointer() const _NOEXCEPT {return __r_.first().__l.__data_;} _LIBCPP_INLINE_VISIBILITY pointer __get_short_pointer() _NOEXCEPT {return pointer_traits::pointer_to(__r_.first().__s.__data_[0]);} _LIBCPP_INLINE_VISIBILITY const_pointer __get_short_pointer() const _NOEXCEPT {return pointer_traits::pointer_to(__r_.first().__s.__data_[0]);} _LIBCPP_INLINE_VISIBILITY pointer __get_pointer() _NOEXCEPT {return __is_long() ? __get_long_pointer() : __get_short_pointer();} _LIBCPP_INLINE_VISIBILITY const_pointer __get_pointer() const _NOEXCEPT {return __is_long() ? __get_long_pointer() : __get_short_pointer();} _LIBCPP_INLINE_VISIBILITY void __zero() _NOEXCEPT { size_type (&__a)[__n_words] = __r_.first().__r.__words; for (unsigned __i = 0; __i < __n_words; ++__i) __a[__i] = 0; } template static _LIBCPP_INLINE_VISIBILITY size_type __align_it(size_type __s) _NOEXCEPT {return (__s + (__a-1)) & ~(__a-1);} enum {__alignment = 16}; static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s) _NOEXCEPT {return (__s < __min_cap ? static_cast(__min_cap) : __align_it (__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 inline typename enable_if < __is_exactly_input_iterator<_InputIterator>::value, void >::type __init(_InputIterator __first, _InputIterator __last); template inline typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type __init(_ForwardIterator __first, _ForwardIterator __last); void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, size_type __n_copy, size_type __n_del, size_type __n_add = 0); void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff); _LIBCPP_INLINE_VISIBILITY void __erase_to_end(size_type __pos); _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str) {__copy_assign_alloc(__str, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str, true_type) { if (__alloc() == __str.__alloc()) __alloc() = __str.__alloc(); else { 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()); } } } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void __move_assign(basic_string& __str, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value); _LIBCPP_INLINE_VISIBILITY void __move_assign(basic_string& __str, true_type) #if _LIBCPP_STD_VER > 14 _NOEXCEPT; #else _NOEXCEPT_(is_nothrow_move_assignable::value); #endif #endif _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(basic_string& __str) _NOEXCEPT_( !__alloc_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable::value) {__move_assign_alloc(__str, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(basic_string& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { __alloc() = _VSTD::move(__c.__alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(basic_string&, false_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); friend basic_string operator+<>(const basic_string&, const basic_string&); friend basic_string operator+<>(const value_type*, const basic_string&); friend basic_string operator+<>(value_type, const basic_string&); friend basic_string operator+<>(const basic_string&, const value_type*); friend basic_string operator+<>(const basic_string&, value_type); }; template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif // _LIBCPP_DEBUG_LEVEL >= 2 } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type #if _LIBCPP_DEBUG_LEVEL >= 2 __pos #endif ) { #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); if (__c) { const_pointer __new_last = __get_pointer() + __pos; for (__i_node** __p = __c->end_; __p != __c->beg_; ) { --__p; const_iterator* __i = static_cast((*__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 // _LIBCPP_DEBUG_LEVEL >= 2 } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string() _NOEXCEPT_(is_nothrow_default_constructible::value) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif __zero(); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value) #else _NOEXCEPT #endif : __r_(__second_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif __zero(); } template 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(); pointer __p; if (__reserve < __min_cap) { __set_short_size(__sz); __p = __get_short_pointer(); } else { size_type __cap = __recommend(__reserve); __p = __alloc_traits::allocate(__alloc(), __cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); __set_long_size(__sz); } traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); traits_type::assign(__p[__sz], value_type()); } template void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) { if (__sz > max_size()) this->__throw_length_error(); pointer __p; if (__sz < __min_cap) { __set_short_size(__sz); __p = __get_short_pointer(); } else { size_type __cap = __recommend(__sz); __p = __alloc_traits::allocate(__alloc(), __cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); __set_long_size(__sz); } traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); traits_type::assign(__p[__sz], value_type()); } template inline _LIBCPP_INLINE_VISIBILITY 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)); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY 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)); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY 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); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY 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); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; else __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template 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; else __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_move_constructible::value) #else _NOEXCEPT #endif : __r_(_VSTD::move(__str.__r_)) { __str.__zero(); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); #endif } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __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()); else { __r_.first().__r = __str.__r_.first().__r; __str.__zero(); } #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); #endif } #endif // _LIBCPP_CXX03_LANG template void basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) { if (__n > max_size()) this->__throw_length_error(); pointer __p; if (__n < __min_cap) { __set_short_size(__n); __p = __get_short_pointer(); } else { size_type __cap = __recommend(__n); __p = __alloc_traits::allocate(__alloc(), __cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); __set_long_size(__n); } traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c); traits_type::assign(__p[__n], value_type()); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY 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 __get_db()->__insert_c(this); #endif } template 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) this->__throw_out_of_range(); __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a) : __r_(__second_tag(), __a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) this->__throw_out_of_range(); __init(__str.data() + __pos, __str_sz - __pos); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template template 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 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 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 template typename enable_if < __is_exactly_input_iterator<_InputIterator>::value, void >::type basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) { __zero(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __first != __last; ++__first) push_back(*__first); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { if (__is_long()) __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) { size_type __sz = static_cast(_VSTD::distance(__first, __last)); if (__sz > max_size()) this->__throw_length_error(); pointer __p; if (__sz < __min_cap) { __set_short_size(__sz); __p = __get_short_pointer(); } else { size_type __cap = __recommend(__sz); __p = __alloc_traits::allocate(__alloc(), __cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); __set_long_size(__sz); } for (; __first != __last; ++__first, (void) ++__p) traits_type::assign(*__p, *__first); traits_type::assign(*__p, value_type()); } template template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) : __r_(__second_tag(), __a) { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string( initializer_list<_CharT> __il) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } template inline _LIBCPP_INLINE_VISIBILITY 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 __get_db()->__insert_c(this); #endif } #endif // _LIBCPP_CXX03_LANG template basic_string<_CharT, _Traits, _Allocator>::~basic_string() { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__erase_c(this); #endif if (__is_long()) __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); } template void basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace (size_type __old_cap, size_type __delta_cap, size_type __old_sz, size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) { size_type __ms = max_size(); if (__delta_cap > __ms - __old_cap - 1) this->__throw_length_error(); pointer __old_p = __get_pointer(); size_type __cap = __old_cap < __ms / 2 - __alignment ? __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1; pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); if (__n_copy != 0) traits_type::copy(_VSTD::__to_raw_pointer(__p), _VSTD::__to_raw_pointer(__old_p), __n_copy); if (__n_add != 0) traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add); size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; if (__sec_cp_sz != 0) traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); if (__old_cap+1 != __min_cap) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); __old_sz = __n_copy + __n_add + __sec_cp_sz; __set_long_size(__old_sz); traits_type::assign(__p[__old_sz], value_type()); } template void basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, size_type __n_copy, size_type __n_del, size_type __n_add) { size_type __ms = max_size(); if (__delta_cap > __ms - __old_cap) this->__throw_length_error(); pointer __old_p = __get_pointer(); size_type __cap = __old_cap < __ms / 2 - __alignment ? __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1; pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); if (__n_copy != 0) traits_type::copy(_VSTD::__to_raw_pointer(__p), _VSTD::__to_raw_pointer(__old_p), __n_copy); size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; if (__sec_cp_sz != 0) traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); if (__old_cap+1 != __min_cap) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); } // assign template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); size_type __cap = capacity(); if (__cap >= __n) { value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::move(__p, __s, __n); traits_type::assign(__p[__n], value_type()); __set_size(__n); __invalidate_iterators_past(__n); } else { size_type __sz = size(); __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); } return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) { size_type __cap = capacity(); if (__cap < __n) { size_type __sz = size(); __grow_by(__cap, __n - __cap, __sz, 0, __sz); } else __invalidate_iterators_past(__n); value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::assign(__p, __n, __c); traits_type::assign(__p[__n], value_type()); __set_size(__n); return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) { pointer __p; if (__is_long()) { __p = __get_long_pointer(); __set_long_size(1); } else { __p = __get_short_pointer(); __set_short_size(1); } traits_type::assign(*__p, __c); traits_type::assign(*++__p, value_type()); __invalidate_iterators_past(1); return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) { if (this != &__str) { __copy_assign_alloc(__str); assign(__str.data(), __str.size()); } return *this; } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value) { if (__alloc() != __str.__alloc()) assign(__str); else __move_assign(__str, true_type()); } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) #if _LIBCPP_STD_VER > 14 _NOEXCEPT #else _NOEXCEPT_(is_nothrow_move_assignable::value) #endif { clear(); shrink_to_fit(); __r_.first() = __str.__r_.first(); __move_assign_alloc(__str); __str.__zero(); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { __move_assign(__str, integral_constant()); return *this; } #endif template template 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>::assign(_InputIterator __first, _InputIterator __last) { const basic_string __temp(__first, __last, __alloc()); assign(__temp.data(), __temp.size()); return *this; } template template 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>::assign(_ForwardIterator __first, _ForwardIterator __last) { size_type __n = static_cast(_VSTD::distance(__first, __last)); size_type __cap = capacity(); if (__cap < __n) { size_type __sz = size(); __grow_by(__cap, __n - __cap, __sz, 0, __sz); } else __invalidate_iterators_past(__n); pointer __p = __get_pointer(); for (; __first != __last; ++__first, ++__p) traits_type::assign(*__p, *__first); traits_type::assign(*__p, value_type()); __set_size(__n); return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) { size_type __sz = __str.size(); if (__pos > __sz) this->__throw_out_of_range(); return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); } template template 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 basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) { _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); return assign(__s, traits_type::length(__s)); } // append template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); size_type __cap = capacity(); size_type __sz = size(); if (__cap - __sz >= __n) { if (__n) { value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); traits_type::copy(__p + __sz, __s, __n); __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); } } else __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) { if (__n) { size_type __cap = capacity(); size_type __sz = size(); if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); pointer __p = __get_pointer(); traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c); __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); } return *this; } template void basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) { bool __is_short = !__is_long(); size_type __cap; size_type __sz; if (__is_short) { __cap = __min_cap - 1; __sz = __get_short_size(); } else { __cap = __get_long_cap() - 1; __sz = __get_long_size(); } if (__sz == __cap) { __grow_by(__cap, 1, __sz, __sz, 0); __is_short = !__is_long(); } pointer __p; if (__is_short) { __p = __get_short_pointer() + __sz; __set_short_size(__sz+1); } else { __p = __get_long_pointer() + __sz; __set_long_size(__sz+1); } traits_type::assign(*__p, __c); traits_type::assign(*++__p, value_type()); } template bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last) { return __first <= __p && __p < __last; } template bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*) { return false; } template template 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(_VSTD::distance(__first, __last)); if (__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; } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) { return append(__str.data(), __str.size()); } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) { size_type __sz = __str.size(); if (__pos > __sz) this->__throw_out_of_range(); return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); } template template 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 basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) { _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); return append(__s, traits_type::length(__s)); } // insert template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); size_type __sz = size(); if (__pos > __sz) this->__throw_out_of_range(); size_type __cap = capacity(); if (__cap - __sz >= __n) { if (__n) { value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __pos; if (__n_move != 0) { if (__p + __pos <= __s && __s < __p + __sz) __s += __n; traits_type::move(__p + __pos + __n, __p + __pos, __n_move); } traits_type::move(__p + __pos, __s, __n); __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); } } else __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); return *this; } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) { size_type __sz = size(); if (__pos > __sz) this->__throw_out_of_range(); if (__n) { size_type __cap = capacity(); value_type* __p; if (__cap - __sz >= __n) { __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __pos; if (__n_move != 0) traits_type::move(__p + __pos + __n, __p + __pos, __n_move); } else { __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } traits_type::assign(__p + __pos, __n, __c); __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); } return *this; } template template typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, typename basic_string<_CharT, _Traits, _Allocator>::iterator >::type basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, range) called with an iterator not" " referring to this string"); #endif const basic_string __temp(__first, __last, __alloc()); return insert(__pos, __temp.data(), __temp.data() + __temp.size()); } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, typename basic_string<_CharT, _Traits, _Allocator>::iterator >::type basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, range) called with an iterator not" " referring to this string"); #endif size_type __ip = static_cast(__pos - begin()); size_type __n = static_cast(_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) { __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __ip; if (__n_move != 0) traits_type::move(__p + __ip + __n, __p + __ip, __n_move); } else { __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } __sz += __n; __set_size(__sz); traits_type::assign(__p[__sz], value_type()); for (__p += __ip; __first != __last; ++__p, ++__first) traits_type::assign(*__p, *__first); } return begin() + __ip; } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) { return insert(__pos1, __str.data(), __str.size()); } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n) { size_type __str_sz = __str.size(); if (__pos2 > __str_sz) this->__throw_out_of_range(); return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); } template template 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 basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) { _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); return insert(__pos, __s, traits_type::length(__s)); } template typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) { size_type __ip = static_cast(__pos - begin()); size_type __sz = size(); size_type __cap = capacity(); value_type* __p; if (__cap == __sz) { __grow_by(__cap, 1, __sz, __ip, 0, 1); __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } else { __p = _VSTD::__to_raw_pointer(__get_pointer()); size_type __n_move = __sz - __ip; if (__n_move != 0) traits_type::move(__p + __ip + 1, __p + __ip, __n_move); } traits_type::assign(__p[__ip], __c); traits_type::assign(__p[++__sz], value_type()); __set_size(__sz); return begin() + static_cast(__ip); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, n, value) called with an iterator not" " referring to this string"); #endif difference_type __p = __pos - begin(); insert(static_cast(__p), __n, __c); return begin() + __p; } // replace template 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(); if (__pos > __sz) this->__throw_out_of_range(); __n1 = _VSTD::min(__n1, __sz - __pos); size_type __cap = capacity(); if (__cap - __sz + __n1 >= __n2) { value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); if (__n1 != __n2) { size_type __n_move = __sz - __pos - __n1; if (__n_move != 0) { if (__n1 > __n2) { traits_type::move(__p + __pos, __s, __n2); traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); goto __finish; } if (__p + __pos < __s && __s < __p + __sz) { if (__p + __pos + __n1 <= __s) __s += __n2 - __n1; else // __p + __pos < __s < __p + __pos + __n1 { traits_type::move(__p + __pos, __s, __n1); __pos += __n1; __s += __n2; __n2 -= __n1; __n1 = 0; } } traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); } } 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); traits_type::assign(__p[__sz], value_type()); } else __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); return *this; } template 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) this->__throw_out_of_range(); __n1 = _VSTD::min(__n1, __sz - __pos); size_type __cap = capacity(); value_type* __p; if (__cap - __sz + __n1 >= __n2) { __p = _VSTD::__to_raw_pointer(__get_pointer()); if (__n1 != __n2) { size_type __n_move = __sz - __pos - __n1; if (__n_move != 0) traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); } } else { __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); __p = _VSTD::__to_raw_pointer(__get_long_pointer()); } traits_type::assign(__p + __pos, __n2, __c); __sz += __n2 - __n1; __set_size(__sz); __invalidate_iterators_past(__sz); traits_type::assign(__p[__sz], value_type()); return *this; } template template typename enable_if < __is_input_iterator<_InputIterator>::value, basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2) { const basic_string __temp(__j1, __j2, __alloc()); return this->replace(__i1, __i2, __temp); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) { return replace(__pos1, __n1, __str.data(), __str.size()); } template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) { size_type __str_sz = __str.size(); if (__pos2 > __str_sz) this->__throw_out_of_range(); return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); } template template 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 basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) { _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); return replace(__pos, __n1, __s, traits_type::length(__s)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) { return replace(static_cast(__i1 - begin()), static_cast(__i2 - __i1), __str.data(), __str.size()); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) { return replace(static_cast(__i1 - begin()), static_cast(__i2 - __i1), __s, __n); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) { return replace(static_cast(__i1 - begin()), static_cast(__i2 - __i1), __s); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) { return replace(static_cast(__i1 - begin()), static_cast(__i2 - __i1), __n, __c); } // erase template basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) { size_type __sz = size(); if (__pos > __sz) this->__throw_out_of_range(); if (__n) { value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); __n = _VSTD::min(__n, __sz - __pos); size_type __n_move = __sz - __pos - __n; if (__n_move != 0) traits_type::move(__p + __pos, __p + __pos + __n, __n_move); __sz -= __n; __set_size(__sz); __invalidate_iterators_past(__sz); traits_type::assign(__p[__sz], value_type()); } return *this; } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::erase(iterator) called with an iterator not" " referring to this string"); #endif _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); iterator __b = begin(); size_type __r = static_cast(__pos - __b); erase(__r, 1); return __b + static_cast(__r); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, "string::erase(iterator, iterator) called with an iterator not" " referring to this string"); #endif _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); iterator __b = begin(); size_type __r = static_cast(__first - __b); erase(__r, static_cast(__last - __first)); return __b + static_cast(__r); } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::pop_back() { _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); size_type __sz; if (__is_long()) { __sz = __get_long_size() - 1; __set_long_size(__sz); traits_type::assign(*(__get_long_pointer() + __sz), value_type()); } else { __sz = __get_short_size() - 1; __set_short_size(__sz); traits_type::assign(*(__get_short_pointer() + __sz), value_type()); } __invalidate_iterators_past(__sz); } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT { __invalidate_all_iterators(); if (__is_long()) { traits_type::assign(*__get_long_pointer(), value_type()); __set_long_size(0); } else { traits_type::assign(*__get_short_pointer(), value_type()); __set_short_size(0); } } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) { if (__is_long()) { traits_type::assign(*(__get_long_pointer() + __pos), value_type()); __set_long_size(__pos); } else { traits_type::assign(*(__get_short_pointer() + __pos), value_type()); __set_short_size(__pos); } __invalidate_iterators_past(__pos); } template void basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) { size_type __sz = size(); if (__n > __sz) append(__n - __sz, __c); else __erase_to_end(__n); } template inline _LIBCPP_INLINE_VISIBILITY 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 return (__m <= ~__long_mask ? __m : __m/2) - __alignment; #else return __m - __alignment; #endif } template void basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) { if (__res_arg > max_size()) this->__throw_length_error(); size_type __cap = capacity(); size_type __sz = size(); __res_arg = _VSTD::max(__res_arg, __sz); __res_arg = __recommend(__res_arg); if (__res_arg != __cap) { pointer __new_data, __p; bool __was_long, __now_long; if (__res_arg == __min_cap - 1) { __was_long = true; __now_long = false; __new_data = __get_short_pointer(); __p = __get_long_pointer(); } else { if (__res_arg > __cap) __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); else { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { return; } #else // _LIBCPP_NO_EXCEPTIONS if (__new_data == nullptr) return; #endif // _LIBCPP_NO_EXCEPTIONS } __now_long = true; __was_long = __is_long(); __p = __get_pointer(); } traits_type::copy(_VSTD::__to_raw_pointer(__new_data), _VSTD::__to_raw_pointer(__p), size()+1); if (__was_long) __alloc_traits::deallocate(__alloc(), __p, __cap+1); if (__now_long) { __set_long_cap(__res_arg+1); __set_long_size(__sz); __set_long_pointer(__new_data); } else __set_short_size(__sz); __invalidate_all_iterators(); } } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::const_reference basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); return *(data() + __pos); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::reference basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT { _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); return *(__get_pointer() + __pos); } template typename basic_string<_CharT, _Traits, _Allocator>::const_reference basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const { if (__n >= size()) this->__throw_out_of_range(); return (*this)[__n]; } template typename basic_string<_CharT, _Traits, _Allocator>::reference basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) { if (__n >= size()) this->__throw_out_of_range(); return (*this)[__n]; } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::reference basic_string<_CharT, _Traits, _Allocator>::front() { _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); return *__get_pointer(); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::const_reference basic_string<_CharT, _Traits, _Allocator>::front() const { _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); return *data(); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::reference basic_string<_CharT, _Traits, _Allocator>::back() { _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); return *(__get_pointer() + size() - 1); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::const_reference basic_string<_CharT, _Traits, _Allocator>::back() const { _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); return *(data() + size() - 1); } template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const { size_type __sz = size(); if (__pos > __sz) this->__throw_out_of_range(); size_type __rlen = _VSTD::min(__n, __sz - __pos); traits_type::copy(__s, data() + __pos, __rlen); return __rlen; } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const { return basic_string(*this, __pos, __n, __alloc()); } template inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT_DEBUG #else _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value) #endif { #if _LIBCPP_DEBUG_LEVEL >= 2 if (!__is_long()) __get_db()->__invalidate_all(this); if (!__str.__is_long()) __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()); } // find template struct _LIBCPP_HIDDEN __traits_eq { typedef typename _Traits::char_type char_type; _LIBCPP_INLINE_VISIBILITY bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT {return _Traits::eq(__x, __y);} }; template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); return __str_find (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, size_type __pos) const _NOEXCEPT { return __str_find (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_find (data(), size(), __s, __pos, traits_type::length(__s)); } template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __pos) const _NOEXCEPT { return __str_find (data(), size(), __c, __pos); } // rfind template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); return __str_rfind (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, size_type __pos) const _NOEXCEPT { return __str_rfind (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_rfind (data(), size(), __s, __pos, traits_type::length(__s)); } template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, size_type __pos) const _NOEXCEPT { return __str_rfind (data(), size(), __c, __pos); } // find_first_of template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); return __str_find_first_of (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_first_of (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_find_first_of (data(), size(), __s, __pos, traits_type::length(__s)); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, size_type __pos) const _NOEXCEPT { return find(__c, __pos); } // find_last_of template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); return __str_find_last_of (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_last_of (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_find_last_of (data(), size(), __s, __pos, traits_type::length(__s)); } template inline _LIBCPP_INLINE_VISIBILITY typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, size_type __pos) const _NOEXCEPT { return rfind(__c, __pos); } // find_first_not_of template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); return __str_find_first_not_of (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_first_not_of (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_find_first_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_first_not_of (data(), size(), __c, __pos); } // find_last_not_of template typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); return __str_find_last_not_of (data(), size(), __s, __pos, __n); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_last_not_of (data(), size(), __str.data(), __pos, __str.size()); } template 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 (data(), size(), __sv.data(), __pos, __sv.size()); } template 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 __str_find_last_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } template inline _LIBCPP_INLINE_VISIBILITY 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 __str_find_last_not_of (data(), size(), __c, __pos); } // compare template inline _LIBCPP_INLINE_VISIBILITY int basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT { size_t __lhs_sz = size(); 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; if (__lhs_sz < __rhs_sz) return -1; if (__lhs_sz > __rhs_sz) return 1; return 0; } template inline _LIBCPP_INLINE_VISIBILITY int basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT { return compare(__self_view(__str)); } template 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 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 inline _LIBCPP_INLINE_VISIBILITY int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str) const { return compare(__pos1, __n1, __str.data(), __str.size()); } template template 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 int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const { return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); } template int basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); return compare(0, npos, __s, traits_type::length(__s)); } template int basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const value_type* __s) const { _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); return compare(__pos1, __n1, __s, traits_type::length(__s)); } // __invariants template inline _LIBCPP_INLINE_VISIBILITY bool basic_string<_CharT, _Traits, _Allocator>::__invariants() const { if (size() > capacity()) return false; if (capacity() < __min_cap - 1) return false; if (data() == 0) return false; if (data()[size()] != value_type(0)) return false; return true; } // operator== template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { size_t __lhs_sz = __lhs.size(); return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), __rhs.data(), __lhs_sz) == 0; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const basic_string, _Allocator>& __lhs, const basic_string, _Allocator>& __rhs) _NOEXCEPT { size_t __lhs_sz = __lhs.size(); if (__lhs_sz != __rhs.size()) return false; const char* __lp = __lhs.data(); const char* __rp = __rhs.data(); if (__lhs.__is_long()) return char_traits::compare(__lp, __rp, __lhs_sz) == 0; for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) if (*__lp != *__rp) return false; return true; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { typedef basic_string<_CharT, _Traits, _Allocator> _String; _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); size_t __lhs_len = _Traits::length(__lhs); if (__lhs_len != __rhs.size()) return false; return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { typedef basic_string<_CharT, _Traits, _Allocator> _String; _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); size_t __rhs_len = _Traits::length(__rhs); if (__rhs_len != __lhs.size()) return false; return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__lhs == __rhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__lhs == __rhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { return !(__lhs == __rhs); } // operator< template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) < 0; } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { return __lhs.compare(__rhs) < 0; } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return __rhs.compare(__lhs) > 0; } // operator> template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return __rhs < __lhs; } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { return __rhs < __lhs; } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return __rhs < __lhs; } // operator<= template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__rhs < __lhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { return !(__rhs < __lhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__rhs < __lhs); } // operator>= template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__lhs < __rhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { return !(__lhs < __rhs); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { return !(__lhs < __rhs); } // operator + template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) { basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); __r.append(__rhs.data(), __rhs_sz); return __r; } template basic_string<_CharT, _Traits, _Allocator> operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) { basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs); typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz); __r.append(__rhs.data(), __rhs_sz); return __r; } template basic_string<_CharT, _Traits, _Allocator> operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) { basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); __r.__init(&__lhs, 1, 1 + __rhs_sz); __r.append(__rhs.data(), __rhs_sz); return __r; } template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs); __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); __r.append(__rhs, __rhs_sz); return __r; } template basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) { basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1); __r.push_back(__rhs); return __r; } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) { return _VSTD::move(__lhs.append(__rhs)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) { return _VSTD::move(__rhs.insert(0, __lhs)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) { return _VSTD::move(__lhs.append(__rhs)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) { return _VSTD::move(__rhs.insert(0, __lhs)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) { __rhs.insert(__rhs.begin(), __lhs); return _VSTD::move(__rhs); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) { return _VSTD::move(__lhs.append(__rhs)); } template inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator> operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) { __lhs.push_back(__rhs); return _VSTD::move(__lhs); } #endif // _LIBCPP_CXX03_LANG // swap template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) { __lhs.swap(__rhs); } #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS typedef basic_string u16string; typedef basic_string u32string; #endif // _LIBCPP_HAS_NO_UNICODE_CHARS _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS string to_string(int __val); _LIBCPP_FUNC_VIS string to_string(unsigned __val); _LIBCPP_FUNC_VIS string to_string(long __val); _LIBCPP_FUNC_VIS string to_string(unsigned long __val); _LIBCPP_FUNC_VIS string to_string(long long __val); _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); _LIBCPP_FUNC_VIS string to_string(float __val); _LIBCPP_FUNC_VIS string to_string(double __val); _LIBCPP_FUNC_VIS string to_string(long double __val); _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10); _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0); _LIBCPP_FUNC_VIS wstring to_wstring(int __val); _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); _LIBCPP_FUNC_VIS wstring to_wstring(long __val); _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); _LIBCPP_FUNC_VIS wstring to_wstring(float __val); _LIBCPP_FUNC_VIS wstring to_wstring(double __val); _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); template const typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::npos; template struct _LIBCPP_TEMPLATE_VIS hash > : public unary_function, size_t> { size_t operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; }; template size_t hash >::operator()( const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT { return __do_string_hash(__val.data(), __val.data() + __val.size()); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str); template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str); template basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str); #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str); #endif // _LIBCPP_CXX03_LANG #if _LIBCPP_DEBUG_LEVEL >= 2 template bool basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const { return this->data() <= _VSTD::__to_raw_pointer(__i->base()) && _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size(); } template bool basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const { return this->data() < _VSTD::__to_raw_pointer(__i->base()) && _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size(); } template bool basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const { const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; return this->data() <= __p && __p <= this->data() + this->size(); } template bool basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const { const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; return this->data() <= __p && __p < this->data() + this->size(); } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) -_LIBCPP_EXTERN_TEMPLATE(string operator+, allocator >(char const*, string const&)) +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+, allocator >(char const*, string const&)) #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals { inline namespace string_literals { inline _LIBCPP_INLINE_VISIBILITY basic_string operator "" s( const char *__str, size_t __len ) { return basic_string (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY basic_string operator "" s( const wchar_t *__str, size_t __len ) { return basic_string (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY basic_string operator "" s( const char16_t *__str, size_t __len ) { return basic_string (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY basic_string operator "" s( const char32_t *__str, size_t __len ) { return basic_string (__str, __len); } } } #endif _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_STRING Index: vendor/libc++/dist/include/vector =================================================================== --- vendor/libc++/dist/include/vector (revision 321189) +++ vendor/libc++/dist/include/vector (revision 321190) @@ -1,3364 +1,3357 @@ // -*- C++ -*- //===------------------------------ vector --------------------------------===// // // 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_VECTOR #define _LIBCPP_VECTOR /* vector synopsis namespace std { template > class vector { public: typedef T value_type; typedef Allocator allocator_type; typedef typename allocator_type::reference reference; typedef typename allocator_type::const_reference const_reference; typedef implementation-defined iterator; typedef implementation-defined const_iterator; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::difference_type difference_type; typedef typename allocator_type::pointer pointer; typedef typename allocator_type::const_pointer const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); explicit vector(size_type n); explicit vector(size_type n, const allocator_type&); // C++14 vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); template vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); vector(const vector& x); vector(vector&& x) noexcept(is_nothrow_move_constructible::value); vector(initializer_list il); vector(initializer_list il, const allocator_type& a); ~vector(); vector& operator=(const vector& x); vector& operator=(vector&& x) noexcept( allocator_type::propagate_on_container_move_assignment::value || allocator_type::is_always_equal::value); // C++17 vector& operator=(initializer_list il); template void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); allocator_type get_allocator() const noexcept; iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; reference front(); const_reference front() const; reference back(); const_reference back() const; value_type* data() noexcept; const value_type* data() const noexcept; void push_back(const value_type& x); void push_back(value_type&& x); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); template iterator emplace(const_iterator position, Args&&... args); iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, value_type&& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; void resize(size_type sz); void resize(size_type sz, const value_type& c); void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 bool __invariants() const; }; template > class vector { public: typedef bool value_type; typedef Allocator allocator_type; typedef implementation-defined iterator; typedef implementation-defined const_iterator; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::difference_type difference_type; typedef iterator pointer; typedef const_iterator const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; class reference { public: reference(const reference&) noexcept; operator bool() const noexcept; reference& operator=(const bool x) noexcept; reference& operator=(const reference& x) noexcept; iterator operator&() const noexcept; void flip() noexcept; }; class const_reference { public: const_reference(const reference&) noexcept; operator bool() const noexcept; const_iterator operator&() const noexcept; }; vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); template vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); vector(const vector& x); vector(vector&& x) noexcept(is_nothrow_move_constructible::value); vector(initializer_list il); vector(initializer_list il, const allocator_type& a); ~vector(); vector& operator=(const vector& x); vector& operator=(vector&& x) noexcept( allocator_type::propagate_on_container_move_assignment::value || allocator_type::is_always_equal::value); // C++17 vector& operator=(initializer_list il); template void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& u); void assign(initializer_list il); allocator_type get_allocator() const noexcept; iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_reverse_iterator crbegin() const noexcept; const_reverse_iterator crend() const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; size_type capacity() const noexcept; bool empty() const noexcept; void reserve(size_type n); void shrink_to_fit() noexcept; reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; reference front(); const_reference front() const; reference back(); const_reference back() const; void push_back(const value_type& x); template reference emplace_back(Args&&... args); // C++14; reference in C++17 void pop_back(); template iterator emplace(const_iterator position, Args&&... args); // C++14 iterator insert(const_iterator position, const value_type& x); iterator insert(const_iterator position, size_type n, const value_type& x); template iterator insert(const_iterator position, InputIterator first, InputIterator last); iterator insert(const_iterator position, initializer_list il); iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; void resize(size_type sz); void resize(size_type sz, value_type x); void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // C++17 void flip() noexcept; bool __invariants() const; }; template struct hash>; template bool operator==(const vector& x, const vector& y); template bool operator< (const vector& x, const vector& y); template bool operator!=(const vector& x, const vector& y); template bool operator> (const vector& x, const vector& y); template bool operator>=(const vector& x, const vector& y); template bool operator<=(const vector& x, const vector& y); template void swap(vector& x, vector& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include // for forward declaration of vector #include <__bit_reference> #include #include #include #include #include #include #include #include #include <__split_buffer> #include <__functional_base> #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 __vector_base_common { protected: _LIBCPP_ALWAYS_INLINE __vector_base_common() {} _LIBCPP_NORETURN void __throw_length_error() const; _LIBCPP_NORETURN void __throw_out_of_range() const; }; template void __vector_base_common<__b>::__throw_length_error() const { _VSTD::__throw_length_error("vector"); } template void __vector_base_common<__b>::__throw_out_of_range() const { _VSTD::__throw_out_of_range("vector"); } -#ifdef _LIBCPP_MSVC -#pragma warning( push ) -#pragma warning( disable: 4231 ) -#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC template class __vector_base : protected __vector_base_common { protected: typedef _Tp value_type; typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; typedef value_type& reference; typedef const value_type& const_reference; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef pointer iterator; typedef const_pointer const_iterator; pointer __begin_; pointer __end_; __compressed_pair __end_cap_; _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() _NOEXCEPT {return __end_cap_.second();} _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __end_cap_.second();} _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} _LIBCPP_INLINE_VISIBILITY __vector_base() _NOEXCEPT_(is_nothrow_default_constructible::value); _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); ~__vector_base(); _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {__destruct_at_end(__begin_);} _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return static_cast(__end_cap() - __begin_);} _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(pointer __new_last) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base& __c) {__copy_assign_alloc(__c, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__vector_base& __c) _NOEXCEPT_( !__alloc_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable::value) {__move_assign_alloc(__c, integral_constant());} private: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base& __c, true_type) { if (__alloc() != __c.__alloc()) { clear(); __alloc_traits::deallocate(__alloc(), __begin_, capacity()); __begin_ = __end_ = __end_cap() = nullptr; } __alloc() = __c.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base&, false_type) {} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__vector_base& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { __alloc() = _VSTD::move(__c.__alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__vector_base&, false_type) _NOEXCEPT {} }; template inline _LIBCPP_INLINE_VISIBILITY void __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { 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 inline _LIBCPP_INLINE_VISIBILITY __vector_base<_Tp, _Allocator>::__vector_base() _NOEXCEPT_(is_nothrow_default_constructible::value) : __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) { } template inline _LIBCPP_INLINE_VISIBILITY __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) : __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) { } template __vector_base<_Tp, _Allocator>::~__vector_base() { if (__begin_ != nullptr) { clear(); __alloc_traits::deallocate(__alloc(), __begin_, capacity()); } } template */> class _LIBCPP_TEMPLATE_VIS vector : private __vector_base<_Tp, _Allocator> { private: typedef __vector_base<_Tp, _Allocator> __base; typedef allocator<_Tp> __default_allocator_type; public: typedef vector __self; typedef _Tp value_type; typedef _Allocator allocator_type; typedef typename __base::__alloc_traits __alloc_traits; typedef typename __base::reference reference; typedef typename __base::const_reference const_reference; typedef typename __base::size_type size_type; typedef typename __base::difference_type difference_type; typedef typename __base::pointer pointer; typedef typename __base::const_pointer const_pointer; typedef __wrap_iter iterator; typedef __wrap_iter const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); _LIBCPP_INLINE_VISIBILITY vector() _NOEXCEPT_(is_nothrow_default_constructible::value) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value) #else _NOEXCEPT #endif : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 explicit vector(size_type __n, const allocator_type& __a); #endif vector(size_type __n, const_reference __x); vector(size_type __n, const_reference __x, const allocator_type& __a); template vector(_InputIterator __first, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, _InputIterator>::type __last); template vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); template vector(_ForwardIterator __first, typename enable_if<__is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, _ForwardIterator>::type __last); template vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY ~vector() { __get_db()->__erase_c(this); } #endif vector(const vector& __x); vector(const vector& __x, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector& operator=(const vector& __x); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY vector(initializer_list __il); _LIBCPP_INLINE_VISIBILITY vector(initializer_list __il, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector(vector&& __x) #if _LIBCPP_STD_VER > 14 _NOEXCEPT; #else _NOEXCEPT_(is_nothrow_move_constructible::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)); _LIBCPP_INLINE_VISIBILITY vector& operator=(initializer_list __il) {assign(__il.begin(), __il.end()); return *this;} #endif // !_LIBCPP_CXX03_LANG template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, void >::type assign(_InputIterator __first, _InputIterator __last); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, void >::type assign(_ForwardIterator __first, _ForwardIterator __last); void assign(size_type __n, const_reference __u); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void assign(initializer_list __il) {assign(__il.begin(), __il.end());} #endif _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return this->__alloc();} _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return begin();} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return end();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return static_cast(this->__end_ - this->__begin_);} _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return __base::capacity();} _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return this->__begin_ == this->__end_;} size_type max_size() const _NOEXCEPT; void reserve(size_type __n); void shrink_to_fit() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; reference at(size_type __n); const_reference at(size_type __n) const; _LIBCPP_INLINE_VISIBILITY reference front() { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } _LIBCPP_INLINE_VISIBILITY const_reference front() const { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } _LIBCPP_INLINE_VISIBILITY reference back() { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); } _LIBCPP_INLINE_VISIBILITY const_reference back() const { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); } _LIBCPP_INLINE_VISIBILITY value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(this->__begin_);} _LIBCPP_INLINE_VISIBILITY const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(this->__begin_);} _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); template _LIBCPP_INLINE_VISIBILITY #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_CXX03_LANG iterator insert(const_iterator __position, value_type&& __x); template iterator emplace(const_iterator __position, _Args&&... __args); #endif // !_LIBCPP_CXX03_LANG iterator insert(const_iterator __position, size_type __n, const_reference __x); template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, iterator >::type insert(const_iterator __position, _InputIterator __first, _InputIterator __last); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, iterator >::type insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __position, initializer_list __il) {return insert(__position, __il.begin(), __il.end());} #endif _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); iterator erase(const_iterator __first, const_iterator __last); _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT { size_type __old_size = size(); __base::clear(); __annotate_shrink(__old_size); __invalidate_all_iterators(); } void resize(size_type __sz); void resize(size_type __sz, const_reference __x); void swap(vector&) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT_DEBUG; #else _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value); #endif bool __invariants() const; #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; bool __decrementable(const const_iterator* __i) const; bool __addable(const const_iterator* __i, ptrdiff_t __n) const; bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; #endif // _LIBCPP_DEBUG_LEVEL >= 2 private: _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; void __construct_at_end(size_type __n); _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, const_reference __x); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); void __append(size_type __n); void __append(size_type __n, const_reference __x); _LIBCPP_INLINE_VISIBILITY iterator __make_iter(pointer __p) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; void __swap_out_circular_buffer(__split_buffer& __v); pointer __swap_out_circular_buffer(__split_buffer& __v, pointer __p); void __move_range(pointer __from_s, pointer __from_e, pointer __to); void __move_assign(vector& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value); void __move_assign(vector& __c, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value); _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(pointer __new_last) _NOEXCEPT { __invalidate_iterators_past(__new_last); size_type __old_size = size(); __base::__destruct_at_end(__new_last); __annotate_shrink(__old_size); } #ifndef _LIBCPP_CXX03_LANG template void __push_back_slow_path(_Up&& __x); template void __emplace_back_slow_path(_Args&&... __args); #else template 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. #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::value) __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); } #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); } _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(), data() + __old_size, data() + size()); } #ifndef _LIBCPP_HAS_NO_ASAN // The annotation for size increase should happen before the actual increase, // but if an exception is thrown after that the annotation has to be undone. struct __RAII_IncreaseAnnotator { __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1) : __commit(false), __v(__v), __old_size(__v.size() + __n) { __v.__annotate_increase(__n); } void __done() { __commit = true; } ~__RAII_IncreaseAnnotator() { if (__commit) return; __v.__annotate_shrink(__old_size); } bool __commit; const vector &__v; size_type __old_size; }; #else struct __RAII_IncreaseAnnotator { _LIBCPP_INLINE_VISIBILITY __RAII_IncreaseAnnotator(const vector &, size_type = 1) {} _LIBCPP_INLINE_VISIBILITY void __done() {} }; #endif }; template void vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer& __v) { __annotate_delete(); __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); _VSTD::swap(this->__begin_, __v.__begin_); _VSTD::swap(this->__end_, __v.__end_); _VSTD::swap(this->__end_cap(), __v.__end_cap()); __v.__first_ = __v.__begin_; __annotate_new(size()); __invalidate_all_iterators(); } template typename vector<_Tp, _Allocator>::pointer vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer& __v, pointer __p) { __annotate_delete(); pointer __r = __v.__begin_; __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_); __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_); _VSTD::swap(this->__begin_, __v.__begin_); _VSTD::swap(this->__end_, __v.__end_); _VSTD::swap(this->__end_cap(), __v.__end_cap()); __v.__first_ = __v.__begin_; __annotate_new(size()); __invalidate_all_iterators(); return __r; } // Allocate space for __n objects // throws length_error if __n > max_size() // throws (probably bad_alloc) if memory run out // Precondition: __begin_ == __end_ == __end_cap() == 0 // Precondition: __n > 0 // Postcondition: capacity() == __n // Postcondition: size() == 0 template void vector<_Tp, _Allocator>::allocate(size_type __n) { if (__n > max_size()) this->__throw_length_error(); this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); this->__end_cap() = this->__begin_ + __n; __annotate_new(0); } template void vector<_Tp, _Allocator>::deallocate() _NOEXCEPT { if (this->__begin_ != nullptr) { clear(); __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); this->__begin_ = this->__end_ = this->__end_cap() = nullptr; } } template typename vector<_Tp, _Allocator>::size_type vector<_Tp, _Allocator>::max_size() const _NOEXCEPT { return _VSTD::min(__alloc_traits::max_size(this->__alloc()), numeric_limits::max()); } // Precondition: __new_size > capacity() template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type vector<_Tp, _Allocator>::__recommend(size_type __new_size) const { const size_type __ms = max_size(); if (__new_size > __ms) this->__throw_length_error(); const size_type __cap = capacity(); if (__cap >= __ms / 2) return __ms; return _VSTD::max(2*__cap, __new_size); } // Default constructs __n objects starting at __end_ // throws if construction throws // Precondition: __n > 0 // Precondition: size() + __n <= capacity() // Postcondition: size() == size() + __n template void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) { allocator_type& __a = this->__alloc(); do { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); ++this->__end_; --__n; __annotator.__done(); } while (__n > 0); } // Copy constructs __n objects starting at __end_ from __x // throws if construction throws // Precondition: __n > 0 // Precondition: size() + __n <= capacity() // Postcondition: size() == old size() + __n // Postcondition: [i] == __x for all i in [size() - __n, __n) template inline void vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) { allocator_type& __a = this->__alloc(); do { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); ++this->__end_; --__n; __annotator.__done(); } while (__n > 0); } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) { allocator_type& __a = this->__alloc(); __RAII_IncreaseAnnotator __annotator(*this, __n); __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_); __annotator.__done(); } // Default constructs __n objects starting at __end_ // throws if construction throws // Postcondition: size() == size() + __n // Exception safety: strong. template void vector<_Tp, _Allocator>::__append(size_type __n) { if (static_cast(this->__end_cap() - this->__end_) >= __n) this->__construct_at_end(__n); else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + __n), size(), __a); __v.__construct_at_end(__n); __swap_out_circular_buffer(__v); } } // Default constructs __n objects starting at __end_ // throws if construction throws // Postcondition: size() == size() + __n // Exception safety: strong. template void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) { if (static_cast(this->__end_cap() - this->__end_) >= __n) this->__construct_at_end(__n, __x); else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + __n), size(), __a); __v.__construct_at_end(__n, __x); __swap_out_circular_buffer(__v); } } template vector<_Tp, _Allocator>::vector(size_type __n) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__n > 0) { allocate(__n); __construct_at_end(__n); } } #if _LIBCPP_STD_VER > 11 template vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__n > 0) { allocate(__n); __construct_at_end(__n); } } #endif template vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__n > 0) { allocate(__n); __construct_at_end(__n, __x); } } template vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__n > 0) { allocate(__n); __construct_at_end(__n, __x); } } template template vector<_Tp, _Allocator>::vector(_InputIterator __first, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, _InputIterator>::type __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __first != __last; ++__first) push_back(*__first); } template template vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value>::type*) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __first != __last; ++__first) push_back(*__first); } template template vector<_Tp, _Allocator>::vector(_ForwardIterator __first, typename enable_if<__is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, _ForwardIterator>::type __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n > 0) { allocate(__n); __construct_at_end(__first, __last, __n); } } template template vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value && is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value>::type*) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n > 0) { allocate(__n); __construct_at_end(__first, __last, __n); } } template vector<_Tp, _Allocator>::vector(const vector& __x) : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif size_type __n = __x.size(); if (__n > 0) { allocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } } template vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif size_type __n = __x.size(); if (__n > 0) { allocate(__n); __construct_at_end(__x.__begin_, __x.__end_, __n); } } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>::vector(vector&& __x) #if _LIBCPP_STD_VER > 14 _NOEXCEPT #else _NOEXCEPT_(is_nothrow_move_constructible::value) #endif : __base(_VSTD::move(__x.__alloc())) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); __get_db()->swap(this, &__x); #endif this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; } template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__a == __x.__alloc()) { this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__x); #endif } else { typedef move_iterator _Ip; assign(_Ip(__x.begin()), _Ip(__x.end())); } } template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>::vector(initializer_list __il) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__il.size() > 0) { allocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } } template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>::vector(initializer_list __il, const allocator_type& __a) : __base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__il.size() > 0) { allocate(__il.size()); __construct_at_end(__il.begin(), __il.end(), __il.size()); } } template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>& vector<_Tp, _Allocator>::operator=(vector&& __x) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { __move_assign(__x, integral_constant()); return *this; } template void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value) { if (__base::__alloc() != __c.__alloc()) { typedef move_iterator _Ip; assign(_Ip(__c.begin()), _Ip(__c.end())); } else __move_assign(__c, true_type()); } template void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { deallocate(); __base::__move_assign_alloc(__c); // this can throw this->__begin_ = __c.__begin_; this->__end_ = __c.__end_; this->__end_cap() = __c.__end_cap(); __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__c); #endif } #endif // !_LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY vector<_Tp, _Allocator>& vector<_Tp, _Allocator>::operator=(const vector& __x) { if (this != &__x) { __base::__copy_assign_alloc(__x); assign(__x.__begin_, __x.__end_); } return *this; } template template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< _Tp, typename iterator_traits<_InputIterator>::reference>::value, void >::type vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { clear(); for (; __first != __last; ++__first) push_back(*__first); } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value && is_constructible< _Tp, typename iterator_traits<_ForwardIterator>::reference>::value, void >::type vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) { size_type __new_size = static_cast(_VSTD::distance(__first, __last)); if (__new_size <= capacity()) { _ForwardIterator __mid = __last; bool __growing = false; if (__new_size > size()) { __growing = true; __mid = __first; _VSTD::advance(__mid, size()); } pointer __m = _VSTD::copy(__first, __mid, this->__begin_); if (__growing) __construct_at_end(__mid, __last, __new_size - size()); else this->__destruct_at_end(__m); } else { deallocate(); allocate(__recommend(__new_size)); __construct_at_end(__first, __last, __new_size); } __invalidate_all_iterators(); } template void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) { if (__n <= capacity()) { size_type __s = size(); _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); if (__n > __s) __construct_at_end(__n - __s, __u); else this->__destruct_at_end(this->__begin_ + __n); } else { deallocate(); allocate(__recommend(static_cast(__n))); __construct_at_end(__n, __u); } __invalidate_all_iterators(); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(this, __p); #else return iterator(__p); #endif } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_iterator vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(this, __p); #else return const_iterator(__p); #endif } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::begin() _NOEXCEPT { return __make_iter(this->__begin_); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_iterator vector<_Tp, _Allocator>::begin() const _NOEXCEPT { return __make_iter(this->__begin_); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::end() _NOEXCEPT { return __make_iter(this->__end_); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_iterator vector<_Tp, _Allocator>::end() const _NOEXCEPT { return __make_iter(this->__end_); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::operator[](size_type __n) { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_reference vector<_Tp, _Allocator>::operator[](size_type __n) const { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; } template typename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::at(size_type __n) { if (__n >= size()) this->__throw_out_of_range(); return this->__begin_[__n]; } template typename vector<_Tp, _Allocator>::const_reference vector<_Tp, _Allocator>::at(size_type __n) const { if (__n >= size()) this->__throw_out_of_range(); return this->__begin_[__n]; } template void vector<_Tp, _Allocator>::reserve(size_type __n) { if (__n > capacity()) { allocator_type& __a = this->__alloc(); __split_buffer __v(__n, size(), __a); __swap_out_circular_buffer(__v); } } template void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT { if (capacity() > size()) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS allocator_type& __a = this->__alloc(); __split_buffer __v(size(), size(), __a); __swap_out_circular_buffer(__v); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } #endif // _LIBCPP_NO_EXCEPTIONS } } template template void #ifndef _LIBCPP_CXX03_LANG vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) #else vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) #endif { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + 1), size(), __a); // __v.push_back(_VSTD::forward<_Up>(__x)); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x)); __v.__end_++; __swap_out_circular_buffer(__v); } template inline _LIBCPP_INLINE_VISIBILITY void vector<_Tp, _Allocator>::push_back(const_reference __x) { if (this->__end_ != this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), __x); __annotator.__done(); ++this->__end_; } else __push_back_slow_path(__x); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY void vector<_Tp, _Allocator>::push_back(value_type&& __x) { if (this->__end_ < this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), _VSTD::move(__x)); __annotator.__done(); ++this->__end_; } else __push_back_slow_path(_VSTD::move(__x)); } template template void vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + 1), size(), __a); // __v.emplace_back(_VSTD::forward<_Args>(__args)...); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...); __v.__end_++; __swap_out_circular_buffer(__v); } template template 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()) { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), _VSTD::forward<_Args>(__args)...); __annotator.__done(); ++this->__end_; } else __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); #if _LIBCPP_STD_VER > 14 return this->back(); #endif } #endif // !_LIBCPP_CXX03_LANG template inline void vector<_Tp, _Allocator>::pop_back() { _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); this->__destruct_at_end(this->__end_ - 1); } template inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::erase(const_iterator __position) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::erase(iterator) called with an iterator not" " referring to this vector"); #endif _LIBCPP_ASSERT(__position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator"); difference_type __ps = __position - cbegin(); pointer __p = this->__begin_ + __ps; this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); this->__invalidate_iterators_past(__p-1); iterator __r = __make_iter(__p); return __r; } template typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _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()); 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; } template void vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) { pointer __old_last = this->__end_; difference_type __n = __old_last - __to; for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), _VSTD::move(*__i)); _VSTD::move_backward(__from_s, __from_s + __n, __old_last); } template typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::insert(iterator, x) called with an iterator not" " referring to this vector"); #endif pointer __p = this->__begin_ + (__position - begin()); if (this->__end_ < this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); if (__p == this->__end_) { __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), __x); ++this->__end_; } else { __move_range(__p, this->__end_, __p + 1); const_pointer __xr = pointer_traits::pointer_to(__x); if (__p <= __xr && __xr < this->__end_) ++__xr; *__p = *__xr; } __annotator.__done(); } else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + 1), __p - this->__begin_, __a); __v.push_back(__x); __p = __swap_out_circular_buffer(__v, __p); } return __make_iter(__p); } #ifndef _LIBCPP_CXX03_LANG template typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::insert(iterator, x) called with an iterator not" " referring to this vector"); #endif pointer __p = this->__begin_ + (__position - begin()); if (this->__end_ < this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); if (__p == this->__end_) { __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), _VSTD::move(__x)); ++this->__end_; } else { __move_range(__p, this->__end_, __p + 1); *__p = _VSTD::move(__x); } __annotator.__done(); } else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + 1), __p - this->__begin_, __a); __v.push_back(_VSTD::move(__x)); __p = __swap_out_circular_buffer(__v, __p); } return __make_iter(__p); } template template typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::emplace(iterator, x) called with an iterator not" " referring to this vector"); #endif pointer __p = this->__begin_ + (__position - begin()); if (this->__end_ < this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); if (__p == this->__end_) { __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), _VSTD::forward<_Args>(__args)...); ++this->__end_; } else { __temp_value __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); __move_range(__p, this->__end_, __p + 1); *__p = _VSTD::move(__tmp.get()); } __annotator.__done(); } else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + 1), __p - this->__begin_, __a); __v.emplace_back(_VSTD::forward<_Args>(__args)...); __p = __swap_out_circular_buffer(__v, __p); } return __make_iter(__p); } #endif // !_LIBCPP_CXX03_LANG template typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::insert(iterator, n, x) called with an iterator not" " referring to this vector"); #endif pointer __p = this->__begin_ + (__position - begin()); if (__n > 0) { if (__n <= static_cast(this->__end_cap() - this->__end_)) { size_type __old_n = __n; pointer __old_last = this->__end_; if (__n > static_cast(this->__end_ - __p)) { size_type __cx = __n - (this->__end_ - __p); __construct_at_end(__cx, __x); __n -= __cx; } if (__n > 0) { __RAII_IncreaseAnnotator __annotator(*this, __n); __move_range(__p, __old_last, __p + __old_n); __annotator.__done(); const_pointer __xr = pointer_traits::pointer_to(__x); if (__p <= __xr && __xr < this->__end_) __xr += __old_n; _VSTD::fill_n(__p, __n, *__xr); } } else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + __n), __p - this->__begin_, __a); __v.__construct_at_end(__n, __x); __p = __swap_out_circular_buffer(__v, __p); } } return __make_iter(__p); } template template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value && is_constructible< _Tp, typename iterator_traits<_InputIterator>::reference>::value, typename vector<_Tp, _Allocator>::iterator >::type vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::insert(iterator, range) called with an iterator not" " referring to this vector"); #endif difference_type __off = __position - begin(); pointer __p = this->__begin_ + __off; allocator_type& __a = this->__alloc(); pointer __old_last = this->__end_; for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) { __RAII_IncreaseAnnotator __annotator(*this); __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); ++this->__end_; __annotator.__done(); } __split_buffer __v(__a); if (__first != __last) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __v.__construct_at_end(__first, __last); difference_type __old_size = __old_last - this->__begin_; difference_type __old_p = __p - this->__begin_; reserve(__recommend(size() + __v.size())); __p = this->__begin_ + __old_p; __old_last = this->__begin_ + __old_size; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { erase(__make_iter(__old_last), end()); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } __p = _VSTD::rotate(__p, __old_last, this->__end_); insert(__make_iter(__p), make_move_iterator(__v.begin()), make_move_iterator(__v.end())); return begin() + __off; } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value && is_constructible< _Tp, typename iterator_traits<_ForwardIterator>::reference>::value, typename vector<_Tp, _Allocator>::iterator >::type vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, "vector::insert(iterator, range) called with an iterator not" " referring to this vector"); #endif pointer __p = this->__begin_ + (__position - begin()); difference_type __n = _VSTD::distance(__first, __last); if (__n > 0) { if (__n <= this->__end_cap() - this->__end_) { size_type __old_n = __n; pointer __old_last = this->__end_; _ForwardIterator __m = __last; difference_type __dx = this->__end_ - __p; if (__n > __dx) { __m = __first; difference_type __diff = this->__end_ - __p; _VSTD::advance(__m, __diff); __construct_at_end(__m, __last, __n - __diff); __n = __dx; } if (__n > 0) { __RAII_IncreaseAnnotator __annotator(*this, __n); __move_range(__p, __old_last, __p + __old_n); __annotator.__done(); _VSTD::copy(__first, __m, __p); } } else { allocator_type& __a = this->__alloc(); __split_buffer __v(__recommend(size() + __n), __p - this->__begin_, __a); __v.__construct_at_end(__first, __last); __p = __swap_out_circular_buffer(__v, __p); } } return __make_iter(__p); } template void vector<_Tp, _Allocator>::resize(size_type __sz) { size_type __cs = size(); if (__cs < __sz) this->__append(__sz - __cs); else if (__cs > __sz) this->__destruct_at_end(this->__begin_ + __sz); } template void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) { size_type __cs = size(); if (__cs < __sz) this->__append(__sz - __cs, __x); else if (__cs > __sz) this->__destruct_at_end(this->__begin_ + __sz); } template void vector<_Tp, _Allocator>::swap(vector& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT_DEBUG #else _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value) #endif { _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || this->__alloc() == __x.__alloc(), "vector::swap: Either propagate_on_container_swap must be true" " or the allocators must compare equal"); _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(), integral_constant()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->swap(this, &__x); #endif // _LIBCPP_DEBUG_LEVEL >= 2 } template bool vector<_Tp, _Allocator>::__invariants() const { if (this->__begin_ == nullptr) { if (this->__end_ != nullptr || this->__end_cap() != nullptr) return false; } else { if (this->__begin_ > this->__end_) return false; if (this->__begin_ == this->__end_cap()) return false; if (this->__end_ > this->__end_cap()) return false; } return true; } #if _LIBCPP_DEBUG_LEVEL >= 2 template bool vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const { return this->__begin_ <= __i->base() && __i->base() < this->__end_; } template bool vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const { return this->__begin_ < __i->base() && __i->base() <= this->__end_; } template bool vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const { const_pointer __p = __i->base() + __n; return this->__begin_ <= __p && __p <= this->__end_; } template bool vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const { const_pointer __p = __i->base() + __n; return this->__begin_ <= __p && __p < this->__end_; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 template inline _LIBCPP_INLINE_VISIBILITY void vector<_Tp, _Allocator>::__invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif // _LIBCPP_DEBUG_LEVEL >= 2 } template 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((*__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 template class vector; template struct hash >; template struct __has_storage_type > { static const bool value = true; }; template class _LIBCPP_TEMPLATE_VIS vector : private __vector_base_common { public: typedef vector __self; typedef bool value_type; typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef size_type __storage_type; typedef __bit_iterator pointer; typedef __bit_iterator const_pointer; typedef pointer iterator; typedef const_pointer const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; private: typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; typedef allocator_traits<__storage_allocator> __storage_traits; typedef typename __storage_traits::pointer __storage_pointer; typedef typename __storage_traits::const_pointer __const_storage_pointer; __storage_pointer __begin_; size_type __size_; __compressed_pair __cap_alloc_; public: typedef __bit_reference reference; typedef __bit_const_reference const_reference; private: _LIBCPP_INLINE_VISIBILITY size_type& __cap() _NOEXCEPT {return __cap_alloc_.first();} _LIBCPP_INLINE_VISIBILITY const size_type& __cap() const _NOEXCEPT {return __cap_alloc_.first();} _LIBCPP_INLINE_VISIBILITY __storage_allocator& __alloc() _NOEXCEPT {return __cap_alloc_.second();} _LIBCPP_INLINE_VISIBILITY const __storage_allocator& __alloc() const _NOEXCEPT {return __cap_alloc_.second();} static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); _LIBCPP_INLINE_VISIBILITY static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT {return __n * __bits_per_word;} _LIBCPP_INLINE_VISIBILITY static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT {return (__n - 1) / __bits_per_word + 1;} public: _LIBCPP_INLINE_VISIBILITY vector() _NOEXCEPT_(is_nothrow_default_constructible::value); _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value); #else _NOEXCEPT; #endif ~vector(); explicit vector(size_type __n); #if _LIBCPP_STD_VER > 11 explicit vector(size_type __n, const allocator_type& __a); #endif vector(size_type __n, const value_type& __v); vector(size_type __n, const value_type& __v, const allocator_type& __a); template vector(_InputIterator __first, _InputIterator __last, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type* = 0); template vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type* = 0); template vector(_ForwardIterator __first, _ForwardIterator __last, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); template vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); vector(const vector& __v); vector(const vector& __v, const allocator_type& __a); vector& operator=(const vector& __v); #ifndef _LIBCPP_CXX03_LANG vector(initializer_list __il); vector(initializer_list __il, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector(vector&& __v) #if _LIBCPP_STD_VER > 14 _NOEXCEPT; #else _NOEXCEPT_(is_nothrow_move_constructible::value); #endif vector(vector&& __v, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY vector& operator=(vector&& __v) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); _LIBCPP_INLINE_VISIBILITY vector& operator=(initializer_list __il) {assign(__il.begin(), __il.end()); return *this;} #endif // !_LIBCPP_CXX03_LANG template typename enable_if < __is_input_iterator<_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value, void >::type assign(_InputIterator __first, _InputIterator __last); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type assign(_ForwardIterator __first, _ForwardIterator __last); void assign(size_type __n, const value_type& __x); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void assign(initializer_list __il) {assign(__il.begin(), __il.end());} #endif _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(this->__alloc());} size_type max_size() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return __internal_cap_to_external(__cap());} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __size_;} _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __size_ == 0;} void reserve(size_type __n); void shrink_to_fit() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __make_iter(0);} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __make_iter(0);} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __make_iter(__size_);} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __make_iter(__size_);} _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return __make_iter(0);} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return __make_iter(__size_);} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} reference at(size_type __n); const_reference at(size_type __n) const; _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} void push_back(const value_type& __x); #if _LIBCPP_STD_VER > 11 template #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_;} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } #endif iterator insert(const_iterator __position, const value_type& __x); iterator insert(const_iterator __position, size_type __n, const value_type& __x); iterator insert(const_iterator __position, size_type __n, const_reference __x); template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value, iterator >::type insert(const_iterator __position, _InputIterator __first, _InputIterator __last); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, iterator >::type insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __position, initializer_list __il) {return insert(__position, __il.begin(), __il.end());} #endif _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); iterator erase(const_iterator __first, const_iterator __last); _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {__size_ = 0;} void swap(vector&) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value); #endif static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } void resize(size_type __sz, value_type __x = false); void flip() _NOEXCEPT; bool __invariants() const; private: _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); void allocate(size_type __n); void deallocate() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY static size_type __align_it(size_type __new_size) _NOEXCEPT {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}; _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); void __append(size_type __n, const_reference __x); _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_type __pos) _NOEXCEPT {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_type __pos) const _NOEXCEPT {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos) _NOEXCEPT {return iterator(__begin_ + __pos / __bits_per_word, static_cast(__pos % __bits_per_word));} _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const _NOEXCEPT {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast(__pos % __bits_per_word));} _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {return begin() + (__p - cbegin());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const vector& __v) {__copy_assign_alloc(__v, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const vector& __c, true_type) { if (__alloc() != __c.__alloc()) deallocate(); __alloc() = __c.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const vector&, false_type) {} void __move_assign(vector& __c, false_type); void __move_assign(vector& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value); _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(vector& __c) _NOEXCEPT_( !__storage_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable::value) {__move_assign_alloc(__c, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(vector& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { __alloc() = _VSTD::move(__c.__alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(vector&, false_type) _NOEXCEPT {} size_t __hash_code() const _NOEXCEPT; friend class __bit_reference; friend class __bit_const_reference; friend class __bit_iterator; friend class __bit_iterator; friend struct __bit_array; friend struct _LIBCPP_TEMPLATE_VIS hash; }; template inline _LIBCPP_INLINE_VISIBILITY void vector::__invalidate_all_iterators() { } // Allocate space for __n objects // throws length_error if __n > max_size() // throws (probably bad_alloc) if memory run out // Precondition: __begin_ == __end_ == __cap() == 0 // Precondition: __n > 0 // Postcondition: capacity() == __n // Postcondition: size() == 0 template void vector::allocate(size_type __n) { if (__n > max_size()) this->__throw_length_error(); __n = __external_cap_to_internal(__n); this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); this->__size_ = 0; this->__cap() = __n; } template void vector::deallocate() _NOEXCEPT { if (this->__begin_ != nullptr) { __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); __invalidate_all_iterators(); this->__begin_ = nullptr; this->__size_ = this->__cap() = 0; } } template typename vector::size_type vector::max_size() const _NOEXCEPT { size_type __amax = __storage_traits::max_size(__alloc()); size_type __nmax = numeric_limits::max() / 2; // end() >= begin(), always if (__nmax / __bits_per_word <= __amax) return __nmax; return __internal_cap_to_external(__amax); } // Precondition: __new_size > capacity() template inline _LIBCPP_INLINE_VISIBILITY typename vector::size_type vector::__recommend(size_type __new_size) const { const size_type __ms = max_size(); if (__new_size > __ms) this->__throw_length_error(); const size_type __cap = capacity(); if (__cap >= __ms / 2) return __ms; return _VSTD::max(2*__cap, __align_it(__new_size)); } // Default constructs __n objects starting at __end_ // Precondition: __n > 0 // Precondition: size() + __n <= capacity() // Postcondition: size() == size() + __n template inline _LIBCPP_INLINE_VISIBILITY void vector::__construct_at_end(size_type __n, bool __x) { size_type __old_size = this->__size_; this->__size_ += __n; _VSTD::fill_n(__make_iter(__old_size), __n, __x); } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type vector::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) { size_type __old_size = this->__size_; this->__size_ += _VSTD::distance(__first, __last); _VSTD::copy(__first, __last, __make_iter(__old_size)); } template inline _LIBCPP_INLINE_VISIBILITY vector::vector() _NOEXCEPT_(is_nothrow_default_constructible::value) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { } template inline _LIBCPP_INLINE_VISIBILITY vector::vector(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value) #else _NOEXCEPT #endif : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { } template vector::vector(size_type __n) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { if (__n > 0) { allocate(__n); __construct_at_end(__n, false); } } #if _LIBCPP_STD_VER > 11 template vector::vector(size_type __n, const allocator_type& __a) : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { if (__n > 0) { allocate(__n); __construct_at_end(__n, false); } } #endif template vector::vector(size_type __n, const value_type& __x) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { if (__n > 0) { allocate(__n); __construct_at_end(__n, __x); } } template vector::vector(size_type __n, const value_type& __x, const allocator_type& __a) : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { if (__n > 0) { allocate(__n); __construct_at_end(__n, __x); } } template template vector::vector(_InputIterator __first, _InputIterator __last, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __first != __last; ++__first) push_back(*__first); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } template template vector::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __first != __last; ++__first) push_back(*__first); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } template template vector::vector(_ForwardIterator __first, _ForwardIterator __last, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n > 0) { allocate(__n); __construct_at_end(__first, __last); } } template template vector::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { size_type __n = static_cast(_VSTD::distance(__first, __last)); if (__n > 0) { allocate(__n); __construct_at_end(__first, __last); } } #ifndef _LIBCPP_CXX03_LANG template vector::vector(initializer_list __il) : __begin_(nullptr), __size_(0), __cap_alloc_(0) { size_type __n = static_cast(__il.size()); if (__n > 0) { allocate(__n); __construct_at_end(__il.begin(), __il.end()); } } template vector::vector(initializer_list __il, const allocator_type& __a) : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { size_type __n = static_cast(__il.size()); if (__n > 0) { allocate(__n); __construct_at_end(__il.begin(), __il.end()); } } #endif // _LIBCPP_CXX03_LANG template vector::~vector() { if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); } template vector::vector(const vector& __v) : __begin_(nullptr), __size_(0), __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { if (__v.size() > 0) { allocate(__v.size()); __construct_at_end(__v.begin(), __v.end()); } } template vector::vector(const vector& __v, const allocator_type& __a) : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { if (__v.size() > 0) { allocate(__v.size()); __construct_at_end(__v.begin(), __v.end()); } } template vector& vector::operator=(const vector& __v) { if (this != &__v) { __copy_assign_alloc(__v); if (__v.__size_) { if (__v.__size_ > capacity()) { deallocate(); allocate(__v.__size_); } _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); } __size_ = __v.__size_; } return *this; } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY vector::vector(vector&& __v) #if _LIBCPP_STD_VER > 14 _NOEXCEPT #else _NOEXCEPT_(is_nothrow_move_constructible::value) #endif : __begin_(__v.__begin_), __size_(__v.__size_), __cap_alloc_(__v.__cap_alloc_) { __v.__begin_ = nullptr; __v.__size_ = 0; __v.__cap() = 0; } template vector::vector(vector&& __v, const allocator_type& __a) : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { if (__a == allocator_type(__v.__alloc())) { this->__begin_ = __v.__begin_; this->__size_ = __v.__size_; this->__cap() = __v.__cap(); __v.__begin_ = nullptr; __v.__cap() = __v.__size_ = 0; } else if (__v.size() > 0) { allocate(__v.size()); __construct_at_end(__v.begin(), __v.end()); } } template inline _LIBCPP_INLINE_VISIBILITY vector& vector::operator=(vector&& __v) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { __move_assign(__v, integral_constant()); return *this; } template void vector::__move_assign(vector& __c, false_type) { if (__alloc() != __c.__alloc()) assign(__c.begin(), __c.end()); else __move_assign(__c, true_type()); } template void vector::__move_assign(vector& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { deallocate(); __move_assign_alloc(__c); this->__begin_ = __c.__begin_; this->__size_ = __c.__size_; this->__cap() = __c.__cap(); __c.__begin_ = nullptr; __c.__cap() = __c.__size_ = 0; } #endif // !_LIBCPP_CXX03_LANG template void vector::assign(size_type __n, const value_type& __x) { __size_ = 0; if (__n > 0) { size_type __c = capacity(); if (__n <= __c) __size_ = __n; else { vector __v(__alloc()); __v.reserve(__recommend(__n)); __v.__size_ = __n; swap(__v); } _VSTD::fill_n(begin(), __n, __x); } __invalidate_all_iterators(); } template template typename enable_if < __is_input_iterator<_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value, void >::type vector::assign(_InputIterator __first, _InputIterator __last) { clear(); for (; __first != __last; ++__first) push_back(*__first); } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, void >::type vector::assign(_ForwardIterator __first, _ForwardIterator __last) { clear(); difference_type __ns = _VSTD::distance(__first, __last); _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); const size_t __n = static_cast(__ns); if (__n) { if (__n > capacity()) { deallocate(); allocate(__n); } __construct_at_end(__first, __last); } } template void vector::reserve(size_type __n) { if (__n > capacity()) { vector __v(this->__alloc()); __v.allocate(__n); __v.__construct_at_end(this->begin(), this->end()); swap(__v); __invalidate_all_iterators(); } } template void vector::shrink_to_fit() _NOEXCEPT { if (__external_cap_to_internal(size()) > __cap()) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS vector(*this, allocator_type(__alloc())).swap(*this); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } #endif // _LIBCPP_NO_EXCEPTIONS } } template typename vector::reference vector::at(size_type __n) { if (__n >= size()) this->__throw_out_of_range(); return (*this)[__n]; } template typename vector::const_reference vector::at(size_type __n) const { if (__n >= size()) this->__throw_out_of_range(); return (*this)[__n]; } template void vector::push_back(const value_type& __x) { if (this->__size_ == this->capacity()) reserve(__recommend(this->__size_ + 1)); ++this->__size_; back() = __x; } template typename vector::iterator vector::insert(const_iterator __position, const value_type& __x) { iterator __r; if (size() < capacity()) { const_iterator __old_end = end(); ++__size_; _VSTD::copy_backward(__position, __old_end, end()); __r = __const_iterator_cast(__position); } else { vector __v(__alloc()); __v.reserve(__recommend(__size_ + 1)); __v.__size_ = __size_ + 1; __r = _VSTD::copy(cbegin(), __position, __v.begin()); _VSTD::copy_backward(__position, cend(), __v.end()); swap(__v); } *__r = __x; return __r; } template typename vector::iterator vector::insert(const_iterator __position, size_type __n, const value_type& __x) { iterator __r; size_type __c = capacity(); if (__n <= __c && size() <= __c - __n) { const_iterator __old_end = end(); __size_ += __n; _VSTD::copy_backward(__position, __old_end, end()); __r = __const_iterator_cast(__position); } else { vector __v(__alloc()); __v.reserve(__recommend(__size_ + __n)); __v.__size_ = __size_ + __n; __r = _VSTD::copy(cbegin(), __position, __v.begin()); _VSTD::copy_backward(__position, cend(), __v.end()); swap(__v); } _VSTD::fill_n(__r, __n, __x); return __r; } template template typename enable_if < __is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value, typename vector::iterator >::type vector::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) { difference_type __off = __position - begin(); iterator __p = __const_iterator_cast(__position); iterator __old_end = end(); for (; size() != capacity() && __first != __last; ++__first) { ++this->__size_; back() = *__first; } vector __v(__alloc()); if (__first != __last) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __v.assign(__first, __last); difference_type __old_size = static_cast(__old_end - begin()); difference_type __old_p = __p - begin(); reserve(__recommend(size() + __v.size())); __p = begin() + __old_p; __old_end = begin() + __old_size; #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { erase(__old_end, end()); throw; } #endif // _LIBCPP_NO_EXCEPTIONS } __p = _VSTD::rotate(__p, __old_end, end()); insert(__p, __v.begin(), __v.end()); return begin() + __off; } template template typename enable_if < __is_forward_iterator<_ForwardIterator>::value, typename vector::iterator >::type vector::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) { const difference_type __n_signed = _VSTD::distance(__first, __last); _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); const size_type __n = static_cast(__n_signed); iterator __r; size_type __c = capacity(); if (__n <= __c && size() <= __c - __n) { const_iterator __old_end = end(); __size_ += __n; _VSTD::copy_backward(__position, __old_end, end()); __r = __const_iterator_cast(__position); } else { vector __v(__alloc()); __v.reserve(__recommend(__size_ + __n)); __v.__size_ = __size_ + __n; __r = _VSTD::copy(cbegin(), __position, __v.begin()); _VSTD::copy_backward(__position, cend(), __v.end()); swap(__v); } _VSTD::copy(__first, __last, __r); return __r; } template inline _LIBCPP_INLINE_VISIBILITY typename vector::iterator vector::erase(const_iterator __position) { iterator __r = __const_iterator_cast(__position); _VSTD::copy(__position + 1, this->cend(), __r); --__size_; return __r; } template typename vector::iterator vector::erase(const_iterator __first, const_iterator __last) { iterator __r = __const_iterator_cast(__first); difference_type __d = __last - __first; _VSTD::copy(__last, this->cend(), __r); __size_ -= __d; return __r; } template void vector::swap(vector& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::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(), integral_constant()); } template void vector::resize(size_type __sz, value_type __x) { size_type __cs = size(); if (__cs < __sz) { iterator __r; size_type __c = capacity(); size_type __n = __sz - __cs; if (__n <= __c && __cs <= __c - __n) { __r = end(); __size_ += __n; } else { vector __v(__alloc()); __v.reserve(__recommend(__size_ + __n)); __v.__size_ = __size_ + __n; __r = _VSTD::copy(cbegin(), cend(), __v.begin()); swap(__v); } _VSTD::fill_n(__r, __n, __x); } else __size_ = __sz; } template void vector::flip() _NOEXCEPT { // do middle whole words size_type __n = __size_; __storage_pointer __p = __begin_; for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) *__p = ~*__p; // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__p & __m; *__p &= ~__m; *__p |= ~__b & __m; } } template bool vector::__invariants() const { if (this->__begin_ == nullptr) { if (this->__size_ != 0 || this->__cap() != 0) return false; } else { if (this->__cap() == 0) return false; if (this->__size_ > this->capacity()) return false; } return true; } template size_t vector::__hash_code() const _NOEXCEPT { size_t __h = 0; // do middle whole words size_type __n = __size_; __storage_pointer __p = __begin_; for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) __h ^= *__p; // do last partial word if (__n > 0) { const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __h ^= *__p & __m; } return __h; } template struct _LIBCPP_TEMPLATE_VIS hash > : public unary_function, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(const vector& __vec) const _NOEXCEPT {return __vec.__hash_code();} }; template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_VECTOR Index: vendor/libc++/dist/lib/CMakeLists.txt =================================================================== --- vendor/libc++/dist/lib/CMakeLists.txt (revision 321189) +++ vendor/libc++/dist/lib/CMakeLists.txt (revision 321190) @@ -1,391 +1,391 @@ set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE) # Get sources # FIXME: Don't use glob here file(GLOB LIBCXX_SOURCES ../src/*.cpp) if(WIN32) file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp) list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES}) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.cpp) list(APPEND LIBCXX_SOURCES ${LIBCXX_SOLARIS_SOURCES}) endif() # Add all the headers to the project for IDEs. if (LIBCXX_CONFIGURE_IDE) file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) if(WIN32) file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) endif() # Force them all into the headers dir on MSVC, otherwise they end up at # project scope because they don't have extensions. if (MSVC_IDE) source_group("Header Files" FILES ${LIBCXX_HEADERS}) endif() endif() if(NOT LIBCXX_INSTALL_LIBRARY) set(exclude_from_all EXCLUDE_FROM_ALL) endif() # If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) endif() add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR LIBCXX_CXX_ABI_LIBNAME STREQUAL "default")) set(LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY ON) endif() if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) add_library_flags("-Wl,--whole-archive" "-Wl,-Bstatic") add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") add_library_flags("-Wl,-Bdynamic" "-Wl,--no-whole-archive") elseif (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY) add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") else () add_interface_library("${LIBCXX_CXX_ABI_LIBRARY}") endif() if (APPLE AND LLVM_USE_SANITIZER) if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") else() message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") endif() if (LIBFILE) find_compiler_rt_dir(LIBDIR) if (NOT IS_DIRECTORY "${LIBDIR}") message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") endif() set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") add_link_flags("-Wl,-rpath,${LIBDIR}") endif() endif() # Generate private library list. add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread) add_library_flags_if(LIBCXX_HAS_C_LIB c) add_library_flags_if(LIBCXX_HAS_M_LIB m) add_library_flags_if(LIBCXX_HAS_RT_LIB rt) if (LIBCXX_USE_COMPILER_RT) find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) add_library_flags_if(LIBCXX_BUILTINS_LIBRARY "${LIBCXX_BUILTINS_LIBRARY}") else() add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) endif() add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic) # Add the unwinder library. if (LIBCXXABI_USE_LLVM_UNWINDER) if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) add_interface_library(unwind_shared) elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) add_interface_library(unwind_static) else() add_interface_library(unwind) endif() endif() # Setup flags. if (NOT WIN32) add_flags_if_supported(-fPIC) endif() add_link_flags_if_supported(-nodefaultlibs) if (LIBCXX_TARGETING_MSVC) if (LIBCXX_DEBUG_BUILD) set(LIB_SUFFIX "d") else() set(LIB_SUFFIX "") endif() add_compile_flags(/Zl) add_link_flags(/nodefaultlib) add_library_flags(ucrt${LIB_SUFFIX}) # Universal C runtime add_library_flags(vcruntime${LIB_SUFFIX}) # C++ runtime add_library_flags(msvcrt${LIB_SUFFIX}) # C runtime startup files add_library_flags(msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. # Required for standards-complaint wide character formatting functions # (e.g. `printfw`/`scanfw`) add_library_flags(iso_stdio_wide_specifiers) endif() if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY) if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION) set(LIBCXX_LIBCPPABI_VERSION "2") # Default value execute_process( COMMAND xcrun --show-sdk-version OUTPUT_VARIABLE sdk_ver RESULT_VARIABLE res OUTPUT_STRIP_TRAILING_WHITESPACE) if (res EQUAL 0) message(STATUS "Found SDK version ${sdk_ver}") string(REPLACE "10." "" sdk_ver "${sdk_ver}") if (sdk_ver LESS 9) set(LIBCXX_LIBCPPABI_VERSION "") else() set(LIBCXX_LIBCPPABI_VERSION "2") endif() endif() endif() if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) add_definitions(-D__STRICT_ANSI__) add_link_flags( "-compatibility_version 1" "-current_version 1" "-install_name /usr/lib/libc++.1.dylib" "-Wl,-reexport_library,/usr/lib/libc++abi.dylib" "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" "/usr/lib/libSystem.B.dylib") else() if (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "") list(FIND CMAKE_OSX_ARCHITECTURES "armv7" OSX_HAS_ARMV7) if (NOT OSX_HAS_ARMV7 EQUAL -1) set(OSX_RE_EXPORT_LINE "${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib" "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++sjlj-abi.exp") else() set(OSX_RE_EXPORT_LINE "-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib") endif() else() set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp") if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) add_link_flags("/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi-new-delete.exp") endif() endif() add_link_flags( "-compatibility_version 1" "-install_name /usr/lib/libc++.1.dylib" "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" "${OSX_RE_EXPORT_LINE}" "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/notweak.exp" "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/weak.exp") endif() endif() split_list(LIBCXX_COMPILE_FLAGS) split_list(LIBCXX_LINK_FLAGS) # Add an object library that contains the compiled source files. add_library(cxx_objects OBJECT ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) if(WIN32 AND NOT MINGW) target_compile_definitions(cxx_objects PRIVATE # Ignore the -MSC_VER mismatch, as we may build # with a different compatibility version. _ALLOW_MSC_VER_MISMATCH # Don't check the msvcprt iterator debug levels # as we will define the iterator types; libc++ # uses a different macro to identify the debug # level. _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH # We are building the c++ runtime, don't pull in # msvcprt. _CRTBLD # Don't warn on the use of "deprecated" # "insecure" functions which are standards # specified. _CRT_SECURE_NO_WARNINGS # Use the ISO conforming behaviour for conversion # in printf, scanf. _CRT_STDIO_ISO_WIDE_SPECIFIERS) endif() set_target_properties(cxx_objects PROPERTIES COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" ) set(LIBCXX_TARGETS) # Build the shared library. if (LIBCXX_ENABLE_SHARED) add_library(cxx_shared SHARED $) target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES}) set_target_properties(cxx_shared PROPERTIES LINK_FLAGS "${LIBCXX_LINK_FLAGS}" OUTPUT_NAME "c++" VERSION "${LIBCXX_ABI_VERSION}.0" SOVERSION "${LIBCXX_ABI_VERSION}" ) list(APPEND LIBCXX_TARGETS "cxx_shared") if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") # Since we most likely do not have a mt.exe replacement, disable the # manifest bundling. This allows a normal cmake invocation to pass which # will attempt to use the manifest tool to generate the bundled manifest set_target_properties(cxx_shared PROPERTIES APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") endif() endif() # Build the static library. if (LIBCXX_ENABLE_STATIC) add_library(cxx_static STATIC $) target_link_libraries(cxx_static ${LIBCXX_LIBRARIES}) set(CMAKE_STATIC_LIBRARY_PREFIX "lib") set_target_properties(cxx_static PROPERTIES LINK_FLAGS "${LIBCXX_LINK_FLAGS}" OUTPUT_NAME "c++" ) list(APPEND LIBCXX_TARGETS "cxx_static") # Attempt to merge the libc++.a archive and the ABI library archive into one. if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) set(MERGE_ARCHIVES_SEARCH_PATHS "") if (LIBCXX_CXX_ABI_LIBRARY_PATH) set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") endif() if ((TARGET ${LIBCXX_CXX_ABI_LIBRARY}) OR - (${LIBCXX_CXX_ABI_LIBRARY} STREQUAL "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI)) + (${LIBCXX_CXX_ABI_LIBRARY} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI)) set(MERGE_ARCHIVES_ABI_TARGET "$") else() set(MERGE_ARCHIVES_ABI_TARGET "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() add_custom_command(TARGET cxx_static POST_BUILD COMMAND ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py ARGS -o $ "$" "${MERGE_ARCHIVES_ABI_TARGET}" "${MERGE_ARCHIVES_SEARCH_PATHS}" WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} ) endif() endif() # Add a meta-target for both libraries. add_custom_target(cxx DEPENDS ${LIBCXX_TARGETS}) if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp) if (LIBCXX_ENABLE_FILESYSTEM) file(GLOB LIBCXX_FILESYSTEM_SOURCES ../src/experimental/filesystem/*.cpp) endif() add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES} ${LIBCXX_FILESYSTEM_SOURCES}) if (LIBCXX_ENABLE_SHARED) target_link_libraries(cxx_experimental cxx_shared) else() target_link_libraries(cxx_experimental cxx_static) endif() set(experimental_flags "${LIBCXX_COMPILE_FLAGS}") check_flag_supported(-std=c++14) if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) string(REPLACE "-std=c++11" "-std=c++14" experimental_flags "${LIBCXX_COMPILE_FLAGS}") endif() set_target_properties(cxx_experimental PROPERTIES COMPILE_FLAGS "${experimental_flags}" OUTPUT_NAME "c++experimental" ) endif() if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) if (LIBCXX_ENABLE_SHARED) add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) else() add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) endif() set_target_properties(cxx_external_threads PROPERTIES LINK_FLAGS "${LIBCXX_LINK_FLAGS}" COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" OUTPUT_NAME "c++external_threads" ) endif() # Generate a linker script inplace of a libc++.so symlink. Rerun this command # after cxx builds. if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) # Get the name of the ABI library and handle the case where CXXABI_LIBNAME # is a target name and not a library. Ex cxxabi_shared. set(LIBCXX_INTERFACE_LIBRARY_NAMES) foreach(lib ${LIBCXX_INTERFACE_LIBRARIES}) # FIXME: Handle cxxabi_static and unwind_static. if (TARGET ${lib} OR (${lib} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI) OR (${lib} MATCHES "unwind(_static|_shared)?" AND HAVE_LIBUNWIND)) list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$") else() list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}") endif() endforeach() #split_list(LIBCXX_INTERFACE_LIBRARY_NAMES) # Generate a linker script inplace of a libc++.so symlink. Rerun this command # after cxx builds. add_custom_command(TARGET cxx_shared POST_BUILD COMMAND ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py ARGS "$" ${LIBCXX_INTERFACE_LIBRARY_NAMES} WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} ) endif() if (LIBCXX_INSTALL_LIBRARY) if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) set(experimental_lib cxx_experimental) endif() install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib} LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ) # NOTE: This install command must go after the cxx install command otherwise # it will not be executed after the library symlinks are installed. if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) # Replace the libc++ filename with $ # after we required CMake 3.0. install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx) endif() endif() if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR LIBCXX_INSTALL_HEADERS)) if(LIBCXX_INSTALL_LIBRARY) set(lib_install_target cxx) endif() if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) set(experimental_lib_install_target cxx_experimental) endif() if(LIBCXX_INSTALL_HEADERS) set(header_install_target install-cxx-headers) endif() add_custom_target(install-cxx DEPENDS ${lib_install_target} ${experimental_lib_install_target} ${header_install_target} COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=cxx -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") add_custom_target(install-libcxx DEPENDS install-cxx) endif() Index: vendor/libc++/dist/test/support/test_macros.h =================================================================== --- vendor/libc++/dist/test/support/test_macros.h (revision 321189) +++ vendor/libc++/dist/test/support/test_macros.h (revision 321190) @@ -1,230 +1,233 @@ // -*- C++ -*- //===---------------------------- test_macros.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 SUPPORT_TEST_MACROS_HPP #define SUPPORT_TEST_MACROS_HPP #include // Get STL specific macros like _LIBCPP_VERSION #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" #endif #define TEST_CONCAT1(X, Y) X##Y #define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y) #ifdef __has_feature #define TEST_HAS_FEATURE(X) __has_feature(X) #else #define TEST_HAS_FEATURE(X) 0 #endif #ifdef __has_include #define TEST_HAS_INCLUDE(X) __has_include(X) #else #define TEST_HAS_INCLUDE(X) 0 #endif #ifdef __has_extension #define TEST_HAS_EXTENSION(X) __has_extension(X) #else #define TEST_HAS_EXTENSION(X) 0 #endif #ifdef __has_builtin #define TEST_HAS_BUILTIN(X) __has_builtin(X) #else #define TEST_HAS_BUILTIN(X) 0 #endif #ifdef __is_identifier // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by // the compiler and '1' otherwise. #define TEST_HAS_BUILTIN_IDENTIFIER(X) !__is_identifier(X) #else #define TEST_HAS_BUILTIN_IDENTIFIER(X) 0 #endif #if defined(__EDG__) # define TEST_COMPILER_EDG #elif defined(__clang__) # define TEST_COMPILER_CLANG # if defined(__apple_build_version__) # define TEST_COMPILER_APPLE_CLANG # endif #elif defined(_MSC_VER) # define TEST_COMPILER_C1XX #elif defined(__GNUC__) # define TEST_COMPILER_GCC #endif #if defined(__apple_build_version__) #define TEST_APPLE_CLANG_VER (__clang_major__ * 100) + __clang_minor__ #elif defined(__clang_major__) #define TEST_CLANG_VER (__clang_major__ * 100) + __clang_minor__ #elif defined(__GNUC__) #define TEST_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) #endif /* Make a nice name for the standard version */ #ifndef TEST_STD_VER #if __cplusplus <= 199711L # define TEST_STD_VER 3 #elif __cplusplus <= 201103L # define TEST_STD_VER 11 #elif __cplusplus <= 201402L # define TEST_STD_VER 14 +#elif __cplusplus <= 201703L +# define TEST_STD_VER 17 #else -# define TEST_STD_VER 16 // current year; greater than current standard +# define TEST_STD_VER 99 // greater than current standard +// This is deliberately different than _LIBCPP_STD_VER to discourage matching them up. #endif #endif // Attempt to deduce GCC version #if defined(_LIBCPP_VERSION) && TEST_HAS_INCLUDE() #include #define TEST_HAS_GLIBC #define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor) #endif /* Features that were introduced in C++14 */ #if TEST_STD_VER >= 14 #define TEST_HAS_EXTENDED_CONSTEXPR #define TEST_HAS_VARIABLE_TEMPLATES #endif /* Features that were introduced after C++14 */ #if TEST_STD_VER > 14 #endif #if TEST_STD_VER >= 11 #define TEST_ALIGNOF(...) alignof(__VA_ARGS__) #define TEST_ALIGNAS(...) alignas(__VA_ARGS__) #define TEST_CONSTEXPR constexpr #define TEST_NOEXCEPT noexcept #define TEST_NOEXCEPT_FALSE noexcept(false) #define TEST_NOEXCEPT_COND(...) noexcept(__VA_ARGS__) # if TEST_STD_VER >= 14 # define TEST_CONSTEXPR_CXX14 constexpr # else # define TEST_CONSTEXPR_CXX14 # endif # if TEST_STD_VER > 14 # define TEST_THROW_SPEC(...) # else # define TEST_THROW_SPEC(...) throw(__VA_ARGS__) # endif #else #define TEST_ALIGNOF(...) __alignof(__VA_ARGS__) #define TEST_ALIGNAS(...) __attribute__((__aligned__(__VA_ARGS__))) #define TEST_CONSTEXPR #define TEST_CONSTEXPR_CXX14 #define TEST_NOEXCEPT throw() #define TEST_NOEXCEPT_FALSE #define TEST_NOEXCEPT_COND(...) #define TEST_THROW_SPEC(...) throw(__VA_ARGS__) #endif #define TEST_ALIGNAS_TYPE(...) TEST_ALIGNAS(TEST_ALIGNOF(__VA_ARGS__)) #if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cpp_rtti) \ && !defined(__GXX_RTTI) #define TEST_HAS_NO_RTTI #endif #if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cpp_exceptions) \ && !defined(__EXCEPTIONS) #define TEST_HAS_NO_EXCEPTIONS #endif #if TEST_HAS_FEATURE(address_sanitizer) || TEST_HAS_FEATURE(memory_sanitizer) || \ TEST_HAS_FEATURE(thread_sanitizer) #define TEST_HAS_SANITIZERS #endif #if defined(_LIBCPP_NORETURN) #define TEST_NORETURN _LIBCPP_NORETURN #else #define TEST_NORETURN [[noreturn]] #endif #if defined(_LIBCPP_SAFE_STATIC) #define TEST_SAFE_STATIC _LIBCPP_SAFE_STATIC #else #define TEST_SAFE_STATIC #endif #if TEST_STD_VER < 11 #define ASSERT_NOEXCEPT(...) #define ASSERT_NOT_NOEXCEPT(...) #else #define ASSERT_NOEXCEPT(...) \ static_assert(noexcept(__VA_ARGS__), "Operation must be noexcept") #define ASSERT_NOT_NOEXCEPT(...) \ static_assert(!noexcept(__VA_ARGS__), "Operation must NOT be noexcept") #endif /* Macros for testing libc++ specific behavior and extensions */ #if defined(_LIBCPP_VERSION) #define LIBCPP_ASSERT(...) assert(__VA_ARGS__) #define LIBCPP_STATIC_ASSERT(...) static_assert(__VA_ARGS__) #define LIBCPP_ASSERT_NOEXCEPT(...) ASSERT_NOEXCEPT(__VA_ARGS__) #define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ASSERT_NOT_NOEXCEPT(__VA_ARGS__) #define LIBCPP_ONLY(...) __VA_ARGS__ #else #define LIBCPP_ASSERT(...) ((void)0) #define LIBCPP_STATIC_ASSERT(...) ((void)0) #define LIBCPP_ASSERT_NOEXCEPT(...) ((void)0) #define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ((void)0) #define LIBCPP_ONLY(...) ((void)0) #endif namespace test_macros_detail { template struct is_same { enum { value = 0};} ; template struct is_same { enum {value = 1}; }; } // namespace test_macros_detail #define ASSERT_SAME_TYPE(...) \ static_assert((test_macros_detail::is_same<__VA_ARGS__>::value), \ "Types differ unexpectedly") #ifndef TEST_HAS_NO_EXCEPTIONS #define TEST_THROW(...) throw __VA_ARGS__ #else #if defined(__GNUC__) #define TEST_THROW(...) __builtin_abort() #else #include #define TEST_THROW(...) ::abort() #endif #endif #if defined(__GNUC__) || defined(__clang__) template inline void DoNotOptimize(Tp const& value) { asm volatile("" : : "g"(value) : "memory"); } #else #include template inline void DoNotOptimize(Tp const& value) { const volatile void* volatile unused = __builtin_addressof(value); static_cast(unused); _ReadWriteBarrier(); } #endif #if defined(__GNUC__) #pragma GCC diagnostic pop #endif #endif // SUPPORT_TEST_MACROS_HPP Index: vendor/libc++/dist/www/cxx1z_status.html =================================================================== --- vendor/libc++/dist/www/cxx1z_status.html (revision 321189) +++ vendor/libc++/dist/www/cxx1z_status.html (revision 321190) @@ -1,495 +1,503 @@ libc++ C++1Z Status

libc++ C++1z Status

In November 2014, the C++ standard committee created a draft for the next version of the C++ standard, known here as "C++1z" (probably to be C++17).

In February 2017, the C++ standard committee approved this draft, and sent it to ISO for approval as C++17

This page shows the status of libc++; the status of clang's support of the language features is here.

The groups that have contributed papers:

  • LWG - Library working group
  • CWG - Core Language Working group
  • SG1 - Study group #1 (Concurrency working group)

Paper Status

+ + +
Paper #GroupPaper NameMeetingStatusFirst released version
N3911LWGTransformationTrait Alias void_t.UrbanaComplete3.6
N4089LWGSafe conversions in unique_ptr<T[]>.UrbanaIn progress3.9
N4169LWGA proposal to add invoke function templateUrbanaComplete3.7
N4190LWGRemoving auto_ptr, random_shuffle(), And Old Stuff.UrbanaIn progress
N4258LWGCleaning-up noexcept in the Library.UrbanaIn progress3.7
N4259CWGWording for std::uncaught_exceptionsUrbanaComplete3.7
N4277LWGTriviallyCopyable reference_wrapper.UrbanaComplete3.2
N4279LWGImproved insertion interface for unique-key maps.UrbanaComplete3.7
N4280LWGNon-member size() and moreUrbanaComplete3.6
N4284LWGContiguous Iterators.UrbanaComplete3.6
N4285CWGCleanup for exception-specification and throw-expression.UrbanaComplete4.0
N4387LWGimproving pair and tupleLenexaComplete4.0
N4389LWGbool_constantLenexaComplete3.7
N4508LWGshared_mutex for C++17LenexaComplete3.7
N4366LWGLWG 2228 missing SFINAE ruleLenexaComplete3.1
N4510LWGMinimal incomplete type support for standard containers, revision 4LenexaComplete3.6
P0004R1LWGRemove Deprecated iostreams aliases.KonaComplete3.8
P0006R0LWGAdopt Type Traits Variable Templates for C++17.KonaComplete3.8
P0092R1LWGPolishing <chrono>KonaComplete3.8
P0007R1LWGConstant View: A proposal for a std::as_const helper function template.KonaComplete3.8
P0156R0LWGVariadic lock_guard(rev 3).KonaReverted in Kona3.9
P0074R0LWGMaking std::owner_less more flexibleKonaComplete3.8
P0013R1LWGLogical type traits rev 2KonaComplete3.8
P0024R2LWGThe Parallelism TS Should be StandardizedJacksonville
P0226R1LWGMathematical Special Functions for C++17Jacksonville
P0220R1LWGAdopt Library Fundamentals V1 TS Components for C++17JacksonvilleIn Progress
P0218R1LWGAdopt the File System TS for C++17JacksonvilleIn Progress
P0033R1LWGRe-enabling shared_from_thisJacksonvilleComplete3.9
P0005R4LWGAdopt not_fn from Library Fundamentals 2 for C++17JacksonvilleComplete3.9
P0152R1LWGconstexpr atomic::is_always_lock_freeJacksonvilleComplete3.9
P0185R1LWGAdding [nothrow-]swappable traitsJacksonvilleComplete3.9
P0253R1LWGFixing a design mistake in the searchers interfaceJacksonvilleComplete3.9
P0025R0LWGAn algorithm to "clamp" a value between a pair of boundary valuesJacksonvilleComplete3.9
P0154R1LWGconstexpr std::hardware_{constructive,destructive}_interference_sizeJacksonville
P0030R1LWGProposal to Introduce a 3-Argument Overload to std::hypotJacksonvilleComplete3.9
P0031R0LWGA Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range AccessJacksonvilleComplete4.0
P0272R1LWGGive std::string a non-const .data() member functionJacksonvilleComplete3.9
P0077R2LWGis_callable, the missing INVOKE related traitJacksonvilleComplete3.9
p0032r3LWGHomogeneous interface for variant, any and optionalOuluComplete4.0
p0040r3LWGExtending memory management toolsOuluComplete4.0
p0063r3LWGC++17 should refer to C11 instead of C99OuluNothing to don/a
p0067r3LWGElementary string conversionsOuluNow P0067R5
p0083r3LWGSplicing Maps and SetsOulu
p0084r2LWGEmplace Return TypeOuluComplete4.0
p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
p0175r1LWGSynopses for the C libraryOulu
p0180r2LWGReserve a New Library Namespace for Future StandardizationOuluNothing to don/a
p0181r1LWGOrdered by DefaultOuluRemoved in Konan/a
p0209r2LWGmake_from_tuple: apply for constructionOuluComplete3.9
p0219r1LWGRelative Paths for FilesystemOulu
p0254r2LWGIntegrating std::string_view and std::stringOuluComplete4.0
p0258r2LWGhas_unique_object_representationsOulu
p0295r0LWGAdopt Selected Library Fundamentals V2 Components for C++17OuluComplete4.0
p0302r1LWGRemoving Allocator Support in std::functionOuluComplete4.0
p0307r2LWGMaking Optional Greater Equal AgainOuluComplete4.0
p0336r1LWGBetter Names for Parallel Execution Policies in C++17Oulu
p0337r0LWGDelete operator= for polymorphic_allocatorOuluComplete3.9
p0346r1LWGA <random> Nomenclature TweakOuluComplete3.9
p0358r1LWGFixes for not_fnOuluComplete3.9
p0371r1LWGTemporarily discourage memory_order_consumeOuluNothing to don/a
p0392r0LWGAdapting string_view by filesystem pathsOuluComplete4.0
p0393r3LWGMaking Variant Greater EqualOuluComplete4.0
P0394r4LWGHotel Parallelifornia: terminate() for Parallel Algorithms Exception HandlingOulu
P0003R5LWGRemoving Deprecated Exception Specifications from C++17IssaquahComplete5.0
P0067R5LWGElementary string conversions, revision 5Issaquah
P0403R1LWGLiteral suffixes for basic_string_viewIssaquahComplete4.0
P0414R2LWGMerging shared_ptr changes from Library Fundamentals to C++17Issaquah
P0418R2LWGFail or succeed: there is no atomic latticeIssaquah
P0426R1LWGConstexpr for std::char_traitsIssaquahComplete4.0
P0435R1LWGResolving LWG Issues re common_typeIssaquahComplete4.0
P0502R0LWGThrowing out of a parallel algorithm terminates - but how?Issaquah
P0503R0LWGCorrecting library usage of "literal type"IssaquahComplete4.0
P0504R0LWGRevisiting in-place tag types for any/optional/variantIssaquahComplete4.0
P0505R0LWGWording for GB 50 - constexpr for chronoIssaquahComplete4.0
P0508R0LWGWording for GB 58 - structured bindings for node_handlesIssaquah
P0509R1LWGUpdating “Restrictions on exception handling”IssaquahNothing to don/a
P0510R0LWGDisallowing references, incomplete types, arrays, and empty variantsIssaquahComplete4.0
P0513R0LWGPoisoning the HashIssaquahComplete5.0
P0516R0LWGClarify That shared_future’s Copy Operations have Wide ContractsIssaquahComplete4.0
P0517R0LWGMake future_error ConstructibleIssaquahComplete4.0
P0521R0LWGProposed Resolution for CA 14 (shared_ptr use_count/unique)IssaquahNothing to don/a
P0156R2LWGVariadic Lock guard(rev 5)KonaComplete5.0
P0270R3CWGRemoving C dependencies from signal handler wordingKona
P0298R3CWGA byte type definitionKonaComplete5.0
P0317R1LWGDirectory Entry Caching for FilesystemKona
P0430R2LWGFile system library on non-POSIX-like operating systemsKona
P0433R2LWGToward a resolution of US7 and US14: Integrating template deduction for class templates into the standard libraryKona
P0452R1LWGUnifying <numeric> Parallel AlgorithmsKona
P0467R2LWGIterator Concerns for Parallel AlgorithmsKona
P0492R2LWGProposed Resolution of C++17 National Body Comments for FilesystemsKona
P0518R1LWGAllowing copies as arguments to function objects given to parallel algorithms in response to CH11Kona
P0523R1LWGWording for CH 10: Complexity of parallel algorithmsKona
P0548R1LWGcommon_type and durationKonaComplete5.0
P0558R1LWGResolving atomic<T> named base class inconsistenciesKona
P0574R1LWGAlgorithm Complexity Constraints and Parallel OverloadsKona
P0599R1LWGnoexcept for hash functionsKonaComplete5.0
P0604R0LWGResolving GB 55, US 84, US 85, US 86Kona
P0607R0LWGInline Variables for the Standard LibraryKona
P0618R0LWGDeprecating <codecvt>Kona
P0623R0LWGFinal C++17 Parallel Algorithms FixesKona
P0682R1LWGRepairing elementary string conversionsToronto
P0739R0LWGSome improvements to class template argument deduction integration into the standard libraryToronto

[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]

Library Working group Issues Status

+ + + + +
Issue #Issue NameMeetingStatus
2016Allocators must be no-throw swappableUrbanaComplete
2118unique_ptr for array does not support cv qualification conversion of actual argumentUrbanaComplete
2170Aggregates cannot be DefaultConstructibleUrbanaComplete
2308Clarify container destructor requirements w.r.t. std::arrayUrbanaComplete
2340Replacement allocation functions declared as inlineUrbanaComplete
2354Unnecessary copying when inserting into maps with braced-init syntaxUrbanaComplete
2377std::align requirements overly strictUrbanaComplete
2396underlying_type doesn't say what to do for an incomplete enumeration typeUrbanaComplete
2399shared_ptr's constructor from unique_ptr should be constrainedUrbanaComplete
2400shared_ptr's get_deleter() should use addressof()UrbanaComplete
2401std::function needs more noexceptUrbanaComplete
2404mismatch()'s complexity needs to be updatedUrbanaComplete
2408SFINAE-friendly common_type / iterator_traits is missing in C++14UrbanaComplete
2106move_iterator wrapping iterators returning prvaluesUrbanaComplete
2129User specializations of std::initializer_listUrbanaComplete
2212tuple_size for const pair request headerUrbanaComplete
2217operator==(sub_match, string) slices on embedded '\0'sUrbanaComplete
2230"see below" for initializer_list constructors of unordered containersUrbanaComplete
2233bad_function_call::what() unhelpfulUrbanaComplete
2266vector and deque have incorrect insert requirementsUrbanaComplete
2325minmax_element()'s behavior differing from max_element()'s should be notedUrbanaComplete
2361Apply 2299 resolution throughout libraryUrbanaComplete
2365Missing noexcept in shared_ptr::shared_ptr(nullptr_t)UrbanaComplete
2376bad_weak_ptr::what() overspecifiedUrbanaComplete
2387More nested types that must be accessible and unambiguousUrbanaComplete
2059C++0x ambiguity problem with map::eraseLenexaComplete
2063Contradictory requirements for string move assignmentLenexaComplete
2076Bad CopyConstructible requirement in set constructorsLenexaComplete
2160Unintended destruction ordering-specification of resizeLenexaComplete
2168Inconsistent specification of uniform_real_distribution constructorLenexaComplete
2239min/max/minmax requirementsLenexaComplete
2364deque and vector pop_back don't specify iterator invalidation requirementsLenexaComplete
2369constexpr max(initializer_list) vs max_elementLenexaComplete
2378Behaviour of standard exception typesLenexaComplete
2403stof() should call strtof() and wcstof()LenexaComplete
2406negative_binomial_distribution should reject p == 1LenexaComplete
2407packaged_task(allocator_arg_t, const Allocator&, F&&) should neither be constrained nor explicitLenexaComplete
2411shared_ptr is only contextually convertible to boolLenexaComplete
2415Inconsistency between unique_ptr and shared_ptrLenexaComplete
2420function does not discard the return value of the target objectLenexaComplete
2425operator delete(void*, size_t) doesn't invalidate pointers sufficientlyLenexaComplete
2427Container adaptors as sequence containers, reduxLenexaComplete
2428"External declaration" used without being definedLenexaComplete
2433uninitialized_copy()/etc. should tolerate overloaded operator&LenexaComplete
2434shared_ptr::use_count() is efficientLenexaComplete
2437iterator_traits::reference can and can't be voidLenexaComplete
2438std::iterator inheritance shouldn't be mandatedLenexaComplete
2439unique_copy() sometimes can't fall back to reading its outputLenexaComplete
2440seed_seq::size() should be noexceptLenexaComplete
2442call_once() shouldn't DECAY_COPY()LenexaComplete
2448Non-normative Container destructor specificationLenexaComplete
2454Add raw_storage_iterator::base() memberLenexaComplete
2455Allocator default construction should be allowed to throwLenexaComplete
2458N3778 and new library deallocation signaturesLenexaComplete
2459std::polar should require a non-negative rhoLenexaComplete
2464try_emplace and insert_or_assign misspecifiedLenexaComplete
2467is_always_equal has slightly inconsistent defaultLenexaComplete
2470Allocator's destroy function should be allowed to fail to instantiateLenexaComplete
2482[c.strings] Table 73 mentions nonexistent functionsLenexaComplete
2488Placeholders should be allowed and encouraged to be constexprLenexaComplete
1169num_get not fully compatible with strto*KonaComplete
2072Unclear wording about capacity of temporary buffersKonaComplete
2101Some transformation types can produce impossible typesKonaComplete
2111Which unexpected/terminate handler is called from the exception handling runtime?KonaComplete
2119Missing hash specializations for extended integer typesKonaComplete
2127Move-construction with raw_storage_iteratorKonaComplete
2133Attitude to overloaded comma for iteratorsKonaComplete
2156Unordered containers' reserve(n) reserves for n-1 elementsKonaComplete
2218Unclear how containers use allocator_traits::construct()KonaComplete
2219INVOKE-ing a pointer to member with a reference_wrapper as the object expressionKonaComplete
2224Ambiguous status of access to non-live objectsKonaComplete
2234assert() should allow usage in constant expressionsKonaComplete
2244Issue on basic_istream::seekgKonaComplete
2250Follow-up On Library Issue 2207KonaComplete
2259Issues in 17.6.5.5 rules for member functionsKonaComplete
2273regex_match ambiguityKona
2336is_trivially_constructible/is_trivially_assignable traits are always falseKonaComplete
2353std::next is over-constrainedKonaComplete
2367pair and tuple are not correctly implemented for is_constructible with no argsKonaComplete
2380May <cstdlib> provide long ::abs(long) and long long ::abs(long long)?KonaComplete
2384Allocator's deallocate function needs better specificationKonaComplete
2385function::assign allocator argument doesn't make senseKonaComplete
2435reference_wrapper::operator()'s Remark should be deletedKonaComplete
2447Allocators and volatile-qualified value typesKonaComplete
2462std::ios_base::failure is overspecifiedKonaComplete
2466allocator_traits::max_size() default behavior is incorrectKonaComplete
2469Wrong specification of Requires clause of operator[] for map and unordered_mapKonaComplete
2473basic_filebuf's relation to C FILE semanticsKonaComplete
2476scoped_allocator_adaptor is not assignableKonaComplete
2477Inconsistency of wordings in std::vector::erase() and std::deque::erase()KonaComplete
2483throw_with_nested() should use is_finalKonaComplete
2484rethrow_if_nested() is doubly unimplementableKonaComplete
2485get() should be overloaded for const tuple&&KonaComplete
2486mem_fn() should be required to use perfect forwardingKonaComplete
2487bind() should be const-overloaded, not cv-overloadedKonaComplete
2489mem_fn() should be noexceptKonaComplete
2492Clarify requirements for compKonaComplete
2495There is no such thing as an Exception Safety elementKonaComplete
2192Validity and return type of std::abs(0u) is unclearJacksonville
2276Missing requirement on std::promise::set_exceptionJacksonvilleComplete
2296std::addressof should be constexprJacksonvilleComplete (Clang Only)
2450(greater|less|greater_equal|less_equal)<void> do not yield a total order for pointersJacksonvilleComplete
2520N4089 broke initializing unique_ptr<T[]> from a nullptrJacksonvilleComplete
2522[fund.ts.v2] Contradiction in set_default_resource specificationJacksonvilleComplete
2523std::promise synopsis shows two set_value_at_thread_exit()'s for no apparent reasonJacksonvilleComplete
2537Constructors for priority_queue taking allocators should call make_heapJacksonvilleComplete
2539[fund.ts.v2] invocation_trait definition definition doesn't work for surrogate call functionsJacksonville
2545Simplify wording for bind without explicitly specified return typeJacksonvilleComplete
2557Logical operator traits are broken in the zero-argument caseJacksonvilleComplete
2558[fund.ts.v2] Logical operator traits are broken in the zero-argument caseJacksonvilleComplete
2559Error in LWG 2234's resolutionJacksonvilleComplete
2560is_constructible underspecified when applied to a function typeJacksonvilleBroken in 3.6; See r261653.
2565std::function's move constructor should guarantee nothrow for reference_wrappers and function pointersJacksonvilleComplete
2566Requirements on the first template parameter of container adaptorsJacksonvilleComplete
2571§[map.modifiers]/2 imposes nonsensical requirement on insert(InputIterator, InputIterator)JacksonvilleComplete
2572The remarks for shared_ptr::operator* should apply to cv-qualified void as wellJacksonvilleComplete
2574[fund.ts.v2] std::experimental::function::operator=(F&&) should be constrainedJacksonville
2575[fund.ts.v2] experimental::function::assign should be removedJacksonville
2576istream_iterator and ostream_iterator should use std::addressofJacksonvilleComplete
2577{shared,unique}_lock should use std::addressofJacksonvilleComplete
2579Inconsistency wrt Allocators in basic_string assignment vs. basic_string::assignJacksonvilleComplete
2581Specialization of <type_traits> variable templates should be prohibitedJacksonvilleComplete
2582§[res.on.functions]/2's prohibition against incomplete types shouldn't apply to type traitsJacksonvilleComplete
2583There is no way to supply an allocator for basic_string(str, pos)JacksonvilleComplete
2585forward_list::resize(size_type, const value_type&) effects incorrectJacksonvilleComplete
2586Wrong value category used in scoped_allocator_adaptor::construct()Jacksonville
2590Aggregate initialization for std::arrayJacksonvilleComplete
2181Exceptions from seed sequence operationsOuluComplete
2309mutex::lock() should not throw device_or_resource_busyOuluComplete
2310Public exposition only member in std::arrayOuluComplete
2312tuple's constructor constraints need to be phrased more preciselyOuluComplete
2328Rvalue stream extraction should use perfect forwardingOuluComplete
2393std::function's Callable definition is brokenOuluComplete
2422std::numeric_limits<T>::is_modulo description: "most machines" errataOuluComplete
2426Issue about compare_exchangeOulu
2436Comparators for associative containers should always be CopyConstructibleOuluComplete
2441Exact-width atomic typedefs should be providedOuluComplete
2451[fund.ts.v2] optional should 'forward' T's implicit conversionsOulu
2509[fund.ts.v2] any_cast doesn't work with rvalue reference targets and cannot move with a value targetOuluComplete
2516[fund.ts.v2] Public "exposition only" members in observer_ptrOulu
2542Missing const requirements for associative containersOulu
2549Tuple EXPLICIT constructor templates that take tuple parameters end up taking references to temporaries and will create dangling referencesOuluComplete
2550Wording of unordered container's clear() method complexityOuluComplete
2551[fund.ts.v2] "Exception safety" cleanup in library fundamentals requiredOuluComplete
2555[fund.ts.v2] No handling for over-aligned types in optionalOuluComplete
2573[fund.ts.v2] std::hash<std::experimental::shared_ptr> does not work for arraysOulu
2596vector::data() should use addressofOuluComplete
2667path::root_directory() description is confusingOuluComplete
2669recursive_directory_iterator effects refers to non-existent functionsOuluComplete
2670system_complete refers to undefined variable 'base'OuluComplete
2671Errors in CopyOuluComplete
2673status() effects cannot be implemented as specifiedOuluComplete
2674Bidirectional iterator requirement on path::iterator is very expensiveOuluComplete
2683filesystem::copy() says "no effects"OuluComplete
2684priority_queue lacking comparator typedefOuluComplete
2685shared_ptr deleters must not throw on move constructionOuluComplete
2687{inclusive,exclusive}_scan misspecifiedOulu
2688clamp misses preconditions and has extraneous condition on resultOuluComplete
2689Parallel versions of std::copy and std::move shouldn't be in orderOulu
2698Effect of assign() on iterators/pointers/referencesOuluComplete
2704recursive_directory_iterator's members should require '*this is dereferenceable'OuluComplete
2706Error reporting for recursive_directory_iterator::pop() is under-specifiedOuluComplete
2707path construction and assignment should have "string_type&&" overloadsOuluComplete
2709offsetof is unnecessarily impreciseOulu
2710"Effects: Equivalent to ..." doesn't count "Synchronization:" as determined semanticsOuluComplete
2711path is convertible from approximately everything under the sunOuluComplete
2716Specification of shuffle and sample disallows lvalue URNGsOuluComplete
2718Parallelism bug in [algorithms.parallel.exec] p2Oulu
2719permissions function should not be noexcept due to narrow contractOuluComplete
2720permissions function incorrectly specified for symlinksOuluComplete
2721remove_all has incorrect post conditionsOuluComplete
2723Do directory_iterator and recursive_directory_iterator become the end iterator upon error?OuluComplete
2724The protected virtual member functions of memory_resource should be privateOulu
2725filesystem::exists(const path&, error_code&) error reportingOuluComplete
2726[recursive_]directory_iterator::increment(error_code&) is underspecifiedOuluComplete
2727Parallel algorithms with constexpr specifierOulu
2728status(p).permissions() and symlink_status(p).permissions() are not specifiedOuluComplete
2062Effect contradictions w/o no-throw guarantee of std::function swapsIssaquahComplete
2166Heap property underspecified?Issaquah
2221No formatted output operator for nullptrIssaquah
2223shrink_to_fit effect on iterator validityIssaquahComplete
2261Are containers required to use their 'pointer' type internally?Issaquah
2394locale::name specification unclear - what is implementation-defined?IssaquahComplete
2460LWG issue 2408 and value categoriesIssaquahComplete
2468Self-move-assignment of library typesIssaquah
2475Allow overwriting of std::basic_string terminator with charT() to allow cleaner interoperation with legacy APIsIssaquahComplete
2503multiline option should be added to syntax_option_typeIssaquah
2510Tag types should not be DefaultConstructibleIssaquah
2514Type traits must not be finalIssaquahComplete
2518[fund.ts.v2] Non-member swap for propagate_const should call member swapIssaquah
2519Iterator operator-= has gratuitous undefined behaviourIssaquahComplete
2521[fund.ts.v2] weak_ptr's converting move constructor should be modified as well for array supportIssaquah
2525[fund.ts.v2] get_memory_resource should be const and noexceptIssaquah
2527[fund.ts.v2] ALLOCATOR_OF for function::operator= has incorrect defaultIssaquah
2531future::get should explicitly state that the shared state is releasedIssaquah
2534Constrain rvalue stream operatorsIssaquah
2536What should <complex.h> do?IssaquahComplete
2540unordered_multimap::insert hint iteratorIssaquahComplete
2543LWG 2148 (hash support for enum types) seems under-specifiedIssaquahComplete
2544istreambuf_iterator(basic_streambuf* s) effects unclear when s is 0IssaquahComplete
2556Wide contract for future::share()IssaquahComplete
2562Consistent total ordering of pointers by comparison functorsIssaquah
2567Specification of logical operator traits uses BaseCharacteristic, which is defined only for UnaryTypeTraits and BinaryTypeTraitsIssaquahComplete
2568[fund.ts.v2] Specification of logical operator traits uses BaseCharacteristic, which is defined only for UnaryTypeTraits and BinaryTypeTraitsIssaquah
2569conjunction and disjunction requirements are too strictIssaquahComplete
2570[fund.ts.v2] conjunction and disjunction requirements are too strictIssaquah
2578Iterator requirements should reference iterator traitsIssaquahComplete
2584 ECMAScript IdentityEscape is ambiguousIssaquah
2588[fund.ts.v2] "Convertible to bool" requirement in conjunction and disjunctionIssaquah
2589match_results can't satisfy the requirements of a containerIssaquahComplete
2591std::function's member template target() should not lead to undefined behaviourIssaquahComplete
2598addressof works on temporariesIssaquahComplete
2664operator/ (and other append) semantics not useful if argument has rootIssaquahComplete
2665remove_filename() post condition is incorrectIssaquahComplete
2672Should is_empty use error_code in its specification?IssaquahComplete
2678std::filesystem enum classes overspecifiedIssaquahComplete
2679Inconsistent Use of Effects and Equivalent ToIssaquahComplete
2680Add "Equivalent to" to filesystemIssaquahComplete
2681filesystem::copy() cannot copy symlinksIssaquahComplete
2682filesystem::copy() won't create a symlink to a directoryIssaquahComplete
2686Why is std::hash specialized for error_code, but not error_condition?IssaquahComplete
2694Application of LWG 436 accidentally deleted definition of "facet"IssaquahComplete
2696Interaction between make_shared and enable_shared_from_this is underspecifiedIssaquah
2699Missing restriction in [numeric.requirements]IssaquahComplete
2712copy_file(from, to, ...) has a number of unspecified error conditionsIssaquahComplete
2722equivalent incorrectly specifies throws clauseIssaquahComplete
2729Missing SFINAE on std::pair::operator=Issaquah
2732Questionable specification of path::operator/= and path::appendIssaquahComplete
2733[fund.ts.v2] gcd / lcm and boolIssaquahComplete
2735std::abs(short), std::abs(signed char) and others should return int instead of double in order to be compatible with C++98 and CIssaquah
2736nullopt_t insufficiently constrainedIssaquahComplete
2738is_constructible with void typesIssaquahComplete
2739Issue with time_point non-member subtraction with an unsigned durationIssaquahComplete
2740constexpr optional::operator->IssaquahComplete
2742Inconsistent string interface taking string_viewIssaquahComplete
2744any's in_place constructorsIssaquahComplete
2745[fund.ts.v2] Implementability of LWG 2451Issaquah
2747Possibly redundant std::move in [alg.foreach]IssaquahComplete
2748swappable traits for optionalsIssaquahComplete
2749swappable traits for variantsIssaquahComplete
2750[fund.ts.v2] LWG 2451 conversion constructor constraintIssaquah
2752"Throws:" clauses of async and packaged_task are unimplementableIssaquah
2755[string.view.io] uses non-existent basic_string_view::to_string functionIssaquahComplete
2756C++ WP optional should 'forward' T's implicit conversionsIssaquahComplete
2758std::string{}.assign("ABCDE", 0, 1) is ambiguousIssaquahComplete
2759gcd / lcm and bool for the WPIssaquahComplete
2760non-const basic_string::data should not invalidate iteratorsIssaquahComplete
2765Did LWG 1123 go too far?IssaquahComplete
2767not_fn call_wrapper can form invalid typesIssaquahComplete
2769Redundant const in the return type of any_cast(const any&)IssaquahComplete
2771Broken Effects of some basic_string::compare functions in terms of basic_string_viewIssaquahComplete
2773Making std::ignore constexprIssaquahComplete
2777basic_string_view::copy should use char_traits::copyIssaquahComplete
2778basic_string_view is missing constexprIssaquahComplete
2260Missing requirement for Allocator::pointerKona
2676Provide filesystem::path overloads for File-based streamsKona
2768any_cast and move semanticsKonaComplete
2769Redundant const in the return type of any_cast(const any&)KonaComplete
2781Contradictory requirements for std::function and std::reference_wrapperKonaComplete
2782scoped_allocator_adaptor constructors must be constrainedKonaComplete
2784Resolution to LWG 2484 is missing "otherwise, no effects" and is hard to parseKonaComplete
2785quoted should work with basic_string_viewKonaComplete
2786Annex C should mention shared_ptr changes for array supportKonaComplete
2787§[file_status.cons] doesn't match class definitionKonaComplete
2788basic_string range mutators unintentionally require a default constructible allocatorKonaComplete
2789Equivalence of contained objectsKonaComplete
2790Missing specification of istreambuf_iterator::operator->KonaComplete
2794Missing requirements for allocator pointersKona
2795§[global.functions] provides incorrect example of ADL useKonaComplete
2796tuple should be a literal typeKonaComplete
2801Default-constructibility of unique_ptrKonaComplete
2802shared_ptr constructor requirements for a deleterKona
2804Unconditional constexpr default constructor for istream_iteratorKonaComplete
2806Base class of bad_optional_accessKonaComplete
2807std::invoke should use std::is_nothrow_callableKona
2812Range access is available with <string_view>KonaComplete
2824list::sort should say that the order of elements is unspecified if an exception is thrownKona
2826string_view iterators use old wordingKonaComplete
2834Resolution LWG 2223 is missing wording about end iteratorsKonaComplete
2835LWG 2536 seems to misspecify <tgmath.h>Kona
2837gcd and lcm should support a wider range of input valuesKonaComplete
2838is_literal_type specification needs a little cleanupKonaComplete
2842in_place_t check for optional::optional(U&&) should decay UKonaComplete
2850std::function move constructor does unnecessary workKonaComplete
2853Possible inconsistency in specification of erase in [vector.modifiers]KonaComplete
2855std::throw_with_nested("string_literal")KonaComplete
2857{variant,optional,any}::emplace should return the constructed valueKonaComplete
2861basic_string should require that charT match traits::char_typeKonaComplete
2866Incorrect derived classes constraintsKona
2868Missing specification of bad_any_cast::what()KonaComplete
2872Add definition for direct-non-list-initializationKonaComplete
2873Add noexcept to several shared_ptr related functionsKonaComplete
2874Constructor shared_ptr::shared_ptr(Y*) should be constrainedKona
2875shared_ptr::shared_ptr(Y*, D, […]) constructors should be constrainedKona
2876shared_ptr::shared_ptr(const weak_ptr<Y>&) constructor should be constrainedKona
2878Missing DefaultConstructible requirement for istream_iterator default constructorKona
2890The definition of 'object state' applies only to class typesKonaComplete
2900The copy and move constructors of optional are not constexprKonaComplete
2903The form of initialization for the emplace-constructors is not specifiedKona
2904Make variant move-assignment more exception safeKonaComplete
2905is_constructible_v<unique_ptr<P, D>, P, D const &> should be false when D is not copy constructibleKonaComplete
2908The less-than operator for shared pointers could do moreKona
2911An is_aggregate type trait is neededKonaComplete
2921packaged_task and type-erased allocatorsKona
2934optional<const T> doesn't compare with TKonaComplete
2901Variants cannot properly support allocatorsTorontoComplete
2955to_chars / from_chars depend on std::stringTorontoResolved by P0682R1
2956filesystem::canonical() still defined in terms of absolute(p, base)TorontoComplete

Last Updated: 25-May-2017

Index: vendor/libc++/dist/www/cxx2a_status.html =================================================================== --- vendor/libc++/dist/www/cxx2a_status.html (nonexistent) +++ vendor/libc++/dist/www/cxx2a_status.html (revision 321190) @@ -0,0 +1,90 @@ + + + + + + libc++ C++2a Status + + + + + + + +
+ +

libc++ C++2a Status

+ + +

In July 2017, the C++ standard committee created a draft for the next version of the C++ standard, known here as "C++2a" (probably to be C++20).

+

This page shows the status of libc++; the status of clang's support of the language features is here.

+ +

The groups that have contributed papers: +

    +
  • LWG - Library working group
  • +
  • CWG - Core Language Working group
  • +
  • SG1 - Study group #1 (Concurrency working group)
  • +
+

+ +

Paper Status

+ + + + + + + +
Paper #GroupPaper NameMeetingStatusFirst released version
P0463R1LWGEndian just EndianToronto
P0674R1LWGExtending make_shared to Support ArraysToronto
+ +

[ Note: "Nothing to do" means that no library changes were needed to implement this change -- end note]

+ +

Library Working group Issues Status

+ + + + + + + + + + + + + + + + + + + +
Issue #Issue NameMeetingStatus
2070allocate_shared should use allocator_traits<A>::constructTorontoResolved by P0674R1
2444Inconsistent complexity for std::sort_heapToronto
2593Moved-from state of AllocatorsToronto
2597std::log misspecified for complex numbersToronto
2783stack::emplace() and queue::emplace() should return decltype(auto)Toronto
2932Constraints on parallel algorithm implementations are underspecifiedToronto
2937Is equivalent("existing_thing", "not_existing_thing") an errorTorontoComplete
2940result_of specification also needs a little cleanupToronto
2942LWG 2873's resolution missed weak_ptr::owner_beforeToronto
2954Specialization of the convenience variable templates should be prohibitedToronto
2961Bad postcondition for set_default_resourceToronto
2966Incomplete resolution of US 74TorontoNothing to do
2974Diagnose out of bounds tuple_element/variant_alternativeTorontoComplete
+ +

Last Updated: 16-Jul-2017

+
+ + Property changes on: vendor/libc++/dist/www/cxx2a_status.html ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/html \ No newline at end of property Index: vendor/libc++/dist/www/index.html =================================================================== --- vendor/libc++/dist/www/index.html (revision 321189) +++ vendor/libc++/dist/www/index.html (revision 321190) @@ -1,227 +1,229 @@ "libc++" C++ Standard Library

"libc++" C++ Standard Library

libc++ is a new implementation of the C++ standard library, targeting C++11.

All of the code in libc++ is dual licensed under the MIT license and the UIUC License (a BSD-like license).

New Documentation Coming Soon!

Looking for documentation on how to use, build and test libc++? If so checkout the new libc++ documentation.

Click here for the new libc++ documentation.

Features and Goals

  • Correctness as defined by the C++11 standard.
  • Fast execution.
  • Minimal memory use.
  • Fast compile times.
  • ABI compatibility with gcc's libstdc++ for some low-level features such as exception objects, rtti and memory allocation.
  • Extensive unit tests.

Why a new C++ Standard Library for C++11?

After its initial introduction, many people have asked "why start a new library instead of contributing to an existing library?" (like Apache's libstdcxx, GNU's libstdc++, STLport, etc). There are many contributing reasons, but some of the major ones are:

  • From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++11, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.

  • Mainline libstdc++ has switched to GPL3, a license which the developers of libc++ cannot use. libstdc++ 4.2 (the last GPL2 version) could be independently extended to support C++11, but this would be a fork of the codebase (which is often seen as worse for a project than starting a new independent one). Another problem with libstdc++ is that it is tightly integrated with G++ development, tending to be tied fairly closely to the matching version of G++.

  • STLport and the Apache libstdcxx library are two other popular candidates, but both lack C++11 support. Our experience (and the experience of libstdc++ developers) is that adding support for C++11 (in particular rvalue references and move-only types) requires changes to almost every class and function, essentially amounting to a rewrite. Faced with a rewrite, we decided to start from scratch and evaluate every design decision from first principles based on experience.

    Further, both projects are apparently abandoned: STLport 5.2.1 was released in Oct'08, and STDCXX 4.2.1 in May'08.

Platform Support

libc++ is known to work on the following platforms, using g++-4.2 and clang (lack of C++11 language support disables some functionality). Note that functionality provided by <atomic> is only functional with clang.

  • Mac OS X i386
  • Mac OS X x86_64
  • FreeBSD 10+ i386
  • FreeBSD 10+ x86_64
  • FreeBSD 10+ ARM

Current Status

libc++ is a 100% complete C++11 implementation on Apple's OS X.

LLVM and Clang can self host in C++ and C++11 mode with libc++ on Linux.

libc++ is also a 100% complete C++14 implementation. A list of new features and changes for C++14 can be found here.

A list of features and changes for the next C++ standard, known here as "C++1z" (probably to be C++17) can be found here.

+

A list of features and changes for the C++ standard beyond C++17, known here as + "C++2a" (probably to be C++20) can be found here.

Implementation of the post-c++14 Technical Specifications is in progress. A list of features and the current status of these features can be found here.

Build Bots

The latest libc++ build results can be found at the following locations.

Get it and get involved!

First please review our Developer's Policy. The documentation for building and using libc++ can be found below.

Notes and Known Issues

  • Building libc++ with -fno-rtti is not supported. However linking against it with -fno-rtti is supported.
  • On OS X v10.8 and older the CMake option -DLIBCXX_LIBCPPABI_VERSION="" must be used during configuration.

Send discussions to the clang mailing list.

Bug reports and patches

If you think you've found a bug in libc++, please report it using the LLVM Bugzilla. If you're not sure, you can post a message to the cfe-dev mailing list or on IRC. Please include "libc++" in your subject.

If you want to contribute a patch to libc++, the best place for that is Phabricator. Please include [libc++] in the subject and add cfe-commits as a subscriber.

Design Documents

Index: vendor/libc++/dist/www/upcoming_meeting.html =================================================================== --- vendor/libc++/dist/www/upcoming_meeting.html (revision 321189) +++ vendor/libc++/dist/www/upcoming_meeting.html (revision 321190) @@ -1,99 +1,103 @@ libc++ Upcoming Meeting Status

libc++ Issaquah Status

This is a temporary page; please check the c++1z status here

This page shows the status of the papers and issues that are expected to be adopted in Toronto.

The groups that have contributed papers:

  • LWG - Library working group
  • CWG - Core Language Working group
  • SG1 - Study group #1 (Concurrency working group)

Paper Status

Paper #GroupPaper NameMeetingStatusFirst released version

Library Working group Issues Status

- + + + + +
Issue #Issue NameMeetingStatus
2444Inconsistent complexity for std::sort_heapToronto
2593Moved-from state of AllocatorsToronto
2597std::log misspecified for complex numbersToronto
2783stack::emplace() and queue::emplace() should return decltype(auto)Toronto
2932Constraints on parallel algorithm implementations are underspecifiedToronto
2937Is equivalent("existing_thing", "not_existing_thing") an error?TorontoComplete
2940result_of specification also needs a little cleanupToronto
2942LWG 2873's resolution missed weak_ptr::owner_beforeToronto
2954Specialization of the convenience variable templates should be prohibitedToronto
2961Bad postcondition for set_default_resourceToronto
2966Incomplete resolution of US 74Toronto
2974Diagnose out of bounds tuple_element/variant_alternativeToronto
Priority 1 Bugs
2665remove_filename() post condition is incorrectKonaWe do this already
2665remove_filename() post condition is incorrectTorontoWe do this already
Immediate Issues in Toronto
2901Variants cannot properly support allocatorsTorontoWe do this already
2956filesystem::canonical() still defined in terms of absolute(p, base)Toronto

Comments about the issues

  • 2444 -
  • 2593 -
  • 2597 - I think we do this already; probably needs tests
  • 2783 - should be easy to change; needs tests
  • 2932 - We're not doing the parallel algorithms yet.
  • 2937 - Implemented with tests. The PR LGTM (Eric)
  • 2940 - We haven't implemented result_of yet, but I don't think that this will require any changes.
  • 2942 - all of our owner_before overloads are already noexcept; just need to update the tests.
  • 2954 - I don't think there's anything to do here.
  • 2961 - We haven't implemented the PMR stuff yet.
  • 2966 - Wording cleanup; no code or test changes needed.
  • 2974 - I did this in r305196. Tests added in 306580

Last Updated: 28-Jun-2017