Index: projects/clang600-import/contrib/libc++/CREDITS.TXT =================================================================== --- projects/clang600-import/contrib/libc++/CREDITS.TXT (revision 327038) +++ projects/clang600-import/contrib/libc++/CREDITS.TXT (revision 327039) @@ -1,146 +1,150 @@ This file is a partial list of people who have contributed to the LLVM/libc++ project. If you have contributed a patch or made some other contribution to LLVM/libc++, please submit a patch to this file to add yourself, and it will be done! The list is sorted by surname and formatted to allow easy grepping and beautification by scripts. The fields are: name (N), email (E), web-address (W), PGP key ID and fingerprint (P), description (D), and snail-mail address (S). N: Saleem Abdulrasool E: compnerd@compnerd.org D: Minor patches and Linux fixes. N: Dan Albert E: danalbert@google.com D: Android support and test runner improvements. N: Dimitry Andric E: dimitry@andric.com D: Visibility fixes, minor FreeBSD portability patches. N: Holger Arnold E: holgerar@gmail.com D: Minor fix. N: Ruben Van Boxem E: vanboxem dot ruben at gmail dot com D: Initial Windows patches. N: David Chisnall E: theraven at theravensnest dot org D: FreeBSD and Solaris ports, libcxxrt support, some atomics work. N: Marshall Clow E: mclow.lists@gmail.com E: marshall@idio.com D: C++14 support, patches and bug fixes. N: Jonathan B Coe E: jbcoe@me.com D: Implementation of propagate_const. +N: Glen Joseph Fernandes +E: glenjofe@gmail.com +D: Implementation of to_address. + N: Eric Fiselier E: eric@efcs.ca D: LFTS support, patches and bug fixes. N: Bill Fisher E: william.w.fisher@gmail.com D: Regex bug fixes. N: Matthew Dempsky E: matthew@dempsky.org D: Minor patches and bug fixes. N: Google Inc. D: Copyright owner and contributor of the CityHash algorithm N: Howard Hinnant E: hhinnant@apple.com D: Architect and primary author of libc++ N: Hyeon-bin Jeong E: tuhertz@gmail.com D: Minor patches and bug fixes. N: Argyrios Kyrtzidis E: kyrtzidis@apple.com D: Bug fixes. N: Bruce Mitchener, Jr. E: bruce.mitchener@gmail.com D: Emscripten-related changes. N: Michel Morin E: mimomorin@gmail.com D: Minor patches to is_convertible. N: Andrew Morrow E: andrew.c.morrow@gmail.com D: Minor patches and Linux fixes. N: Michael Park E: mcypark@gmail.com D: Implementation of . N: Arvid Picciani E: aep at exys dot org D: Minor patches and musl port. N: Bjorn Reese E: breese@users.sourceforge.net D: Initial regex prototype N: Nico Rieck E: nico.rieck@gmail.com D: Windows fixes N: Jon Roelofs E: jonathan@codesourcery.com D: Remote testing, Newlib port, baremetal/single-threaded support. N: Jonathan Sauer D: Minor patches, mostly related to constexpr N: Craig Silverstein E: csilvers@google.com D: Implemented Cityhash as the string hash function on 64-bit machines N: Richard Smith D: Minor patches. N: Joerg Sonnenberger E: joerg@NetBSD.org D: NetBSD port. N: Stephan Tolksdorf E: st@quanttec.com D: Minor fix N: Michael van der Westhuizen E: r1mikey at gmail dot com N: Larisse Voufo D: Minor patches. N: Klaas de Vries E: klaas at klaasgaaf dot nl D: Minor bug fix. N: Zhang Xiongpang E: zhangxiongpang@gmail.com D: Minor patches and bug fixes. N: Xing Xue E: xingxue@ca.ibm.com D: AIX port N: Zhihao Yuan E: lichray@gmail.com D: Standard compatibility fixes. N: Jeffrey Yasskin E: jyasskin@gmail.com E: jyasskin@google.com D: Linux fixes. Index: projects/clang600-import/contrib/libc++/include/__config =================================================================== --- projects/clang600-import/contrib/libc++/include/__config (revision 327038) +++ projects/clang600-import/contrib/libc++/include/__config (revision 327039) @@ -1,1247 +1,1280 @@ // -*- 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 +#define _LIBCPP_VERSION 6000 #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 +#elif defined(__wasm__) +#define _LIBCPP_OBJECT_FORMAT_WASM 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. +// Fix undefined behavior in how std::list stores its 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 +// Fix undefined behavior in how __hash_table stores its 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 +// Use the smallest possible integer type to represent the index of the variant. +// Previously libc++ used "unsigned int" exclusivly. +#define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION #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 +#ifndef __has_cpp_attribute +#define __has_cpp_attribute(__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) +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) +# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" +#elif defined(_LIBCPP_ABI_FORCE_ITANIUM) +# define _LIBCPP_ABI_ITANIUM +#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) # define _LIBCPP_ABI_MICROSOFT #else -# define _LIBCPP_ABI_ITANIUM +# if defined(_WIN32) && defined(_MSC_VER) +# define _LIBCPP_ABI_MICROSOFT +# else +# define _LIBCPP_ABI_ITANIUM +# endif #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 +#define _LIBCPP_LITTLE_ENDIAN #endif // __LITTLE_ENDIAN__ #endif // __LITTLE_ENDIAN__ #ifdef __BIG_ENDIAN__ #if __BIG_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 0 -#define _LIBCPP_BIG_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN #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 +#define _LIBCPP_LITTLE_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 0 -#define _LIBCPP_BIG_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN #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 +# define _LIBCPP_LITTLE_ENDIAN # else // _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # 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 +# define _LIBCPP_LITTLE_ENDIAN # else // _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # 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_LITTLE_ENDIAN # 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 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 +# define _LIBCPP_LITTLE_ENDIAN # else -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # 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(__Fuchsia__) +# define _LIBCPP_USING_GETENTROPY #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) +#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 +# define _LIBCPP_LITTLE_ENDIAN # elif __BYTE_ORDER == __BIG_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # else // __BYTE_ORDER == __BIG_ENDIAN # error unable to determine endian # endif -#endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +#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 +#if __has_builtin(__builtin_launder) +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#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 +#if _GNUC_VER >= 700 +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#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_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_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) || \ +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \ 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 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 +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +#define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr +#else +#define _LIBCPP_CONSTEXPR_AFTER_CXX17 +#endif + +#if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) +#define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]] +#else +#define _LIBCPP_NODISCARD_AFTER_CXX17 +#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) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) +# if defined(_DLL) +# pragma(lib, "c++.lib") +# else +# pragma(lib, "libc++.lib") +# endif +#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) #endif // __cplusplus #endif // _LIBCPP_CONFIG Index: projects/clang600-import/contrib/libc++/include/__libcpp_version =================================================================== --- projects/clang600-import/contrib/libc++/include/__libcpp_version (revision 327038) +++ projects/clang600-import/contrib/libc++/include/__libcpp_version (revision 327039) @@ -1 +1 @@ -5000 +6000 Index: projects/clang600-import/contrib/libc++/include/__locale =================================================================== --- projects/clang600-import/contrib/libc++/include/__locale (revision 327038) +++ projects/clang600-import/contrib/libc++/include/__locale (revision 327039) @@ -1,1501 +1,1527 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP___LOCALE #define _LIBCPP___LOCALE #include <__config> #include #include #include #include #include #include #include #if defined(_LIBCPP_MSVCRT_LIKE) # include #elif defined(_AIX) # include #elif defined(__ANDROID__) // Android gained the locale aware functions in L (API level 21) # include # if __ANDROID_API__ <= 20 # include # endif #elif defined(__sun__) # include # include #elif defined(_NEWLIB_VERSION) # include #elif (defined(__APPLE__) || defined(__FreeBSD__) \ || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) # include #elif defined(__Fuchsia__) # include #elif defined(_LIBCPP_HAS_MUSL_LIBC) # include #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_STD -#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT) +#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) struct __libcpp_locale_guard { _LIBCPP_INLINE_VISIBILITY __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} _LIBCPP_INLINE_VISIBILITY ~__libcpp_locale_guard() { if (__old_loc_) uselocale(__old_loc_); } locale_t __old_loc_; private: __libcpp_locale_guard(__libcpp_locale_guard const&); __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); +}; +#elif defined(_LIBCPP_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)), + __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())), + __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())), + __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())), + __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())), + __locale_time(setlocale(LC_TIME, __l.__get_locale())) + // LC_MESSAGES is not supported on Windows. + {} + ~__libcpp_locale_guard() { + setlocale(LC_COLLATE, __locale_collate); + setlocale(LC_CTYPE, __locale_ctype); + setlocale(LC_MONETARY, __locale_monetary); + setlocale(LC_NUMERIC, __locale_numeric); + setlocale(LC_TIME, __locale_time); + _configthreadlocale(__status); + } + int __status; + char* __locale_collate; + char* __locale_ctype; + char* __locale_monetary; + char* __locale_numeric; + char* __locale_time; }; #endif class _LIBCPP_TYPE_VIS locale; template _LIBCPP_INLINE_VISIBILITY bool has_facet(const locale&) _NOEXCEPT; template _LIBCPP_INLINE_VISIBILITY const _Facet& use_facet(const locale&); class _LIBCPP_TYPE_VIS locale { public: // types: class _LIBCPP_TYPE_VIS facet; class _LIBCPP_TYPE_VIS id; typedef int category; _LIBCPP_AVAILABILITY_LOCALE_CATEGORY static const category // values assigned here are for exposition only none = 0, collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK, time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages; // construct/copy/destroy: locale() _NOEXCEPT; locale(const locale&) _NOEXCEPT; explicit locale(const char*); explicit locale(const string&); locale(const locale&, const char*, category); locale(const locale&, const string&, category); template _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*); locale(const locale&, const locale&, category); ~locale(); const locale& operator=(const locale&) _NOEXCEPT; template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const; // locale operations: string name() const; bool operator==(const locale&) const; bool operator!=(const locale& __y) const {return !(*this == __y);} template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const; // global locale objects: static locale global(const locale&); static const locale& classic(); private: class __imp; __imp* __locale_; void __install_ctor(const locale&, facet*, long); static locale& __global(); bool has_facet(id&) const; const facet* use_facet(id&) const; template friend bool has_facet(const locale&) _NOEXCEPT; template friend const _Facet& use_facet(const locale&); }; class _LIBCPP_TYPE_VIS locale::facet : public __shared_count { protected: _LIBCPP_INLINE_VISIBILITY explicit facet(size_t __refs = 0) : __shared_count(static_cast(__refs)-1) {} virtual ~facet(); // facet(const facet&) = delete; // effectively done in __shared_count // void operator=(const facet&) = delete; private: virtual void __on_zero_shared() _NOEXCEPT; }; class _LIBCPP_TYPE_VIS locale::id { once_flag __flag_; int32_t __id_; static int32_t __next_id; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {} private: void __init(); void operator=(const id&); // = delete; id(const id&); // = delete; public: // only needed for tests long __get(); friend class locale; friend class locale::__imp; }; template inline _LIBCPP_INLINE_VISIBILITY locale::locale(const locale& __other, _Facet* __f) { __install_ctor(__other, __f, __f ? __f->id.__get() : 0); } template locale locale::combine(const locale& __other) const { if (!_VSTD::has_facet<_Facet>(__other)) __throw_runtime_error("locale::combine: locale missing facet"); return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other))); } template inline _LIBCPP_INLINE_VISIBILITY bool has_facet(const locale& __l) _NOEXCEPT { return __l.has_facet(_Facet::id); } template inline _LIBCPP_INLINE_VISIBILITY const _Facet& use_facet(const locale& __l) { return static_cast(*__l.use_facet(_Facet::id)); } // template class collate; template class _LIBCPP_TEMPLATE_VIS collate : public locale::facet { public: typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_INLINE_VISIBILITY explicit collate(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_INLINE_VISIBILITY int compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { return do_compare(__lo1, __hi1, __lo2, __hi2); } _LIBCPP_INLINE_VISIBILITY string_type transform(const char_type* __lo, const char_type* __hi) const { return do_transform(__lo, __hi); } _LIBCPP_INLINE_VISIBILITY long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); } static locale::id id; protected: ~collate(); virtual int do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const; virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const {return string_type(__lo, __hi);} virtual long do_hash(const char_type* __lo, const char_type* __hi) const; }; template locale::id collate<_CharT>::id; template collate<_CharT>::~collate() { } template int collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { for (; __lo2 != __hi2; ++__lo1, ++__lo2) { if (__lo1 == __hi1 || *__lo1 < *__lo2) return -1; if (*__lo2 < *__lo1) return 1; } return __lo1 != __hi1; } template long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const { size_t __h = 0; const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; const size_t __mask = size_t(0xF) << (__sr + 4); for(const char_type* __p = __lo; __p != __hi; ++__p) { __h = (__h << 4) + static_cast(*__p); size_t __g = __h & __mask; __h ^= __g | (__g >> __sr); } return static_cast(__h); } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate) // template class collate_byname; template class _LIBCPP_TEMPLATE_VIS collate_byname; template <> class _LIBCPP_TYPE_VIS collate_byname : public collate { locale_t __l; public: typedef char char_type; typedef basic_string string_type; explicit collate_byname(const char* __n, size_t __refs = 0); explicit collate_byname(const string& __n, size_t __refs = 0); protected: ~collate_byname(); virtual int do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const; virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; }; template <> class _LIBCPP_TYPE_VIS collate_byname : public collate { locale_t __l; public: typedef wchar_t char_type; typedef basic_string string_type; explicit collate_byname(const char* __n, size_t __refs = 0); explicit collate_byname(const string& __n, size_t __refs = 0); protected: ~collate_byname(); virtual int do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const; virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; }; template bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, const basic_string<_CharT, _Traits, _Allocator>& __y) const { return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare( __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0; } // template class ctype class _LIBCPP_TYPE_VIS ctype_base { public: #if defined(__GLIBC__) typedef unsigned short mask; static const mask space = _ISspace; static const mask print = _ISprint; static const mask cntrl = _IScntrl; static const mask upper = _ISupper; static const mask lower = _ISlower; static const mask alpha = _ISalpha; static const mask digit = _ISdigit; static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; #elif defined(_LIBCPP_MSVCRT_LIKE) typedef unsigned short mask; static const mask space = _SPACE; static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; static const mask cntrl = _CONTROL; static const mask upper = _UPPER; static const mask lower = _LOWER; static const mask alpha = _ALPHA; static const mask digit = _DIGIT; static const mask punct = _PUNCT; static const mask xdigit = _HEX; static const mask blank = _BLANK; # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) # ifdef __APPLE__ typedef __uint32_t mask; # elif defined(__FreeBSD__) typedef unsigned long mask; # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) typedef unsigned short mask; # endif static const mask space = _CTYPE_S; static const mask print = _CTYPE_R; static const mask cntrl = _CTYPE_C; static const mask upper = _CTYPE_U; static const mask lower = _CTYPE_L; static const mask alpha = _CTYPE_A; static const mask digit = _CTYPE_D; static const mask punct = _CTYPE_P; static const mask xdigit = _CTYPE_X; # if defined(__NetBSD__) static const mask blank = _CTYPE_BL; # else static const mask blank = _CTYPE_B; # endif #elif defined(__sun__) || defined(_AIX) typedef unsigned int mask; static const mask space = _ISSPACE; static const mask print = _ISPRINT; static const mask cntrl = _ISCNTRL; static const mask upper = _ISUPPER; static const mask lower = _ISLOWER; static const mask alpha = _ISALPHA; static const mask digit = _ISDIGIT; static const mask punct = _ISPUNCT; static const mask xdigit = _ISXDIGIT; static const mask blank = _ISBLANK; #elif defined(_NEWLIB_VERSION) // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. typedef char mask; static const mask space = _S; static const mask print = _P | _U | _L | _N | _B; static const mask cntrl = _C; static const mask upper = _U; static const mask lower = _L; static const mask alpha = _U | _L; static const mask digit = _N; static const mask punct = _P; static const mask xdigit = _X | _N; static const mask blank = _B; # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT #else typedef unsigned long mask; static const mask space = 1<<0; static const mask print = 1<<1; static const mask cntrl = 1<<2; static const mask upper = 1<<3; static const mask lower = 1<<4; static const mask alpha = 1<<5; static const mask digit = 1<<6; static const mask punct = 1<<7; static const mask xdigit = 1<<8; static const mask blank = 1<<9; #endif static const mask alnum = alpha | digit; static const mask graph = alnum | punct; _LIBCPP_ALWAYS_INLINE ctype_base() {} }; template class _LIBCPP_TEMPLATE_VIS ctype; template <> class _LIBCPP_TYPE_VIS ctype : public locale::facet, public ctype_base { public: typedef wchar_t char_type; _LIBCPP_ALWAYS_INLINE explicit ctype(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE bool is(mask __m, char_type __c) const { return do_is(__m, __c); } _LIBCPP_ALWAYS_INLINE const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { return do_is(__low, __high, __vec); } _LIBCPP_ALWAYS_INLINE const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { return do_scan_is(__m, __low, __high); } _LIBCPP_ALWAYS_INLINE const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { return do_scan_not(__m, __low, __high); } _LIBCPP_ALWAYS_INLINE char_type toupper(char_type __c) const { return do_toupper(__c); } _LIBCPP_ALWAYS_INLINE const char_type* toupper(char_type* __low, const char_type* __high) const { return do_toupper(__low, __high); } _LIBCPP_ALWAYS_INLINE char_type tolower(char_type __c) const { return do_tolower(__c); } _LIBCPP_ALWAYS_INLINE const char_type* tolower(char_type* __low, const char_type* __high) const { return do_tolower(__low, __high); } _LIBCPP_ALWAYS_INLINE char_type widen(char __c) const { return do_widen(__c); } _LIBCPP_ALWAYS_INLINE const char* widen(const char* __low, const char* __high, char_type* __to) const { return do_widen(__low, __high, __to); } _LIBCPP_ALWAYS_INLINE char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } _LIBCPP_ALWAYS_INLINE const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { return do_narrow(__low, __high, __dfault, __to); } static locale::id id; protected: ~ctype(); virtual bool do_is(mask __m, char_type __c) const; virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; virtual char_type do_toupper(char_type) const; virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; virtual char_type do_tolower(char_type) const; virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; virtual char_type do_widen(char) const; virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; }; template <> class _LIBCPP_TYPE_VIS ctype : public locale::facet, public ctype_base { const mask* __tab_; bool __del_; public: typedef char char_type; explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); _LIBCPP_ALWAYS_INLINE bool is(mask __m, char_type __c) const { return isascii(__c) ? (__tab_[static_cast(__c)] & __m) !=0 : false; } _LIBCPP_ALWAYS_INLINE const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { for (; __low != __high; ++__low, ++__vec) *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; return __low; } _LIBCPP_ALWAYS_INLINE const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) break; return __low; } _LIBCPP_ALWAYS_INLINE const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) if (!(isascii(*__low) && (__tab_[static_cast(*__low)] & __m))) break; return __low; } _LIBCPP_ALWAYS_INLINE char_type toupper(char_type __c) const { return do_toupper(__c); } _LIBCPP_ALWAYS_INLINE const char_type* toupper(char_type* __low, const char_type* __high) const { return do_toupper(__low, __high); } _LIBCPP_ALWAYS_INLINE char_type tolower(char_type __c) const { return do_tolower(__c); } _LIBCPP_ALWAYS_INLINE const char_type* tolower(char_type* __low, const char_type* __high) const { return do_tolower(__low, __high); } _LIBCPP_ALWAYS_INLINE char_type widen(char __c) const { return do_widen(__c); } _LIBCPP_ALWAYS_INLINE const char* widen(const char* __low, const char* __high, char_type* __to) const { return do_widen(__low, __high, __to); } _LIBCPP_ALWAYS_INLINE char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } _LIBCPP_ALWAYS_INLINE const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { return do_narrow(__low, __high, __dfault, __to); } static locale::id id; #ifdef _CACHED_RUNES static const size_t table_size = _CACHED_RUNES; #else static const size_t table_size = 256; // FIXME: Don't hardcode this. #endif _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;} static const mask* classic_table() _NOEXCEPT; #if defined(__GLIBC__) || defined(__EMSCRIPTEN__) static const int* __classic_upper_table() _NOEXCEPT; static const int* __classic_lower_table() _NOEXCEPT; #endif #if defined(__NetBSD__) static const short* __classic_upper_table() _NOEXCEPT; static const short* __classic_lower_table() _NOEXCEPT; #endif protected: ~ctype(); virtual char_type do_toupper(char_type __c) const; virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; virtual char_type do_tolower(char_type __c) const; virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; virtual char_type do_widen(char __c) const; virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; virtual char do_narrow(char_type __c, char __dfault) const; virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; }; // template class ctype_byname; template class _LIBCPP_TEMPLATE_VIS ctype_byname; template <> class _LIBCPP_TYPE_VIS ctype_byname : public ctype { locale_t __l; public: explicit ctype_byname(const char*, size_t = 0); explicit ctype_byname(const string&, size_t = 0); protected: ~ctype_byname(); virtual char_type do_toupper(char_type) const; virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; virtual char_type do_tolower(char_type) const; virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; }; template <> class _LIBCPP_TYPE_VIS ctype_byname : public ctype { locale_t __l; public: explicit ctype_byname(const char*, size_t = 0); explicit ctype_byname(const string&, size_t = 0); protected: ~ctype_byname(); virtual bool do_is(mask __m, char_type __c) const; virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; virtual char_type do_toupper(char_type) const; virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; virtual char_type do_tolower(char_type) const; virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; virtual char_type do_widen(char) const; virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; }; template inline _LIBCPP_INLINE_VISIBILITY bool isspace(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::space, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isprint(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::print, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool iscntrl(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::cntrl, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isupper(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::upper, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool islower(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::lower, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isalpha(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::alpha, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isdigit(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::digit, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool ispunct(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::punct, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isxdigit(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::xdigit, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isalnum(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::alnum, __c); } template inline _LIBCPP_INLINE_VISIBILITY bool isgraph(_CharT __c, const locale& __loc) { return use_facet >(__loc).is(ctype_base::graph, __c); } template inline _LIBCPP_INLINE_VISIBILITY _CharT toupper(_CharT __c, const locale& __loc) { return use_facet >(__loc).toupper(__c); } template inline _LIBCPP_INLINE_VISIBILITY _CharT tolower(_CharT __c, const locale& __loc) { return use_facet >(__loc).tolower(__c); } // codecvt_base class _LIBCPP_TYPE_VIS codecvt_base { public: _LIBCPP_ALWAYS_INLINE codecvt_base() {} enum result {ok, partial, error, noconv}; }; // template class codecvt; template class _LIBCPP_TEMPLATE_VIS codecvt; // template <> class codecvt template <> class _LIBCPP_TYPE_VIS codecvt : public locale::facet, public codecvt_base { public: typedef char intern_type; typedef char extern_type; typedef mbstate_t state_type; _LIBCPP_ALWAYS_INLINE explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE result out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_unshift(__st, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const { return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE int encoding() const _NOEXCEPT { return do_encoding(); } _LIBCPP_ALWAYS_INLINE bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_ALWAYS_INLINE int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } _LIBCPP_ALWAYS_INLINE int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} ~codecvt(); virtual result do_out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual result do_in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual int do_encoding() const _NOEXCEPT; virtual bool do_always_noconv() const _NOEXCEPT; virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; virtual int do_max_length() const _NOEXCEPT; }; // template <> class codecvt template <> class _LIBCPP_TYPE_VIS codecvt : public locale::facet, public codecvt_base { locale_t __l; public: typedef wchar_t intern_type; typedef char extern_type; typedef mbstate_t state_type; explicit codecvt(size_t __refs = 0); _LIBCPP_ALWAYS_INLINE result out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_unshift(__st, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const { return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE int encoding() const _NOEXCEPT { return do_encoding(); } _LIBCPP_ALWAYS_INLINE bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_ALWAYS_INLINE int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } _LIBCPP_ALWAYS_INLINE int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; protected: explicit codecvt(const char*, size_t __refs = 0); ~codecvt(); virtual result do_out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual result do_in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual int do_encoding() const _NOEXCEPT; virtual bool do_always_noconv() const _NOEXCEPT; virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; virtual int do_max_length() const _NOEXCEPT; }; // template <> class codecvt template <> class _LIBCPP_TYPE_VIS codecvt : public locale::facet, public codecvt_base { public: typedef char16_t intern_type; typedef char extern_type; typedef mbstate_t state_type; _LIBCPP_ALWAYS_INLINE explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE result out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_unshift(__st, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const { return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE int encoding() const _NOEXCEPT { return do_encoding(); } _LIBCPP_ALWAYS_INLINE bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_ALWAYS_INLINE int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } _LIBCPP_ALWAYS_INLINE int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} ~codecvt(); virtual result do_out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual result do_in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual int do_encoding() const _NOEXCEPT; virtual bool do_always_noconv() const _NOEXCEPT; virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; virtual int do_max_length() const _NOEXCEPT; }; // template <> class codecvt template <> class _LIBCPP_TYPE_VIS codecvt : public locale::facet, public codecvt_base { public: typedef char32_t intern_type; typedef char extern_type; typedef mbstate_t state_type; _LIBCPP_ALWAYS_INLINE explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE result out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { return do_unshift(__st, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE result in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const { return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); } _LIBCPP_ALWAYS_INLINE int encoding() const _NOEXCEPT { return do_encoding(); } _LIBCPP_ALWAYS_INLINE bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } _LIBCPP_ALWAYS_INLINE int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { return do_length(__st, __frm, __end, __mx); } _LIBCPP_ALWAYS_INLINE int max_length() const _NOEXCEPT { return do_max_length(); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} ~codecvt(); virtual result do_out(state_type& __st, const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual result do_in(state_type& __st, const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; virtual int do_encoding() const _NOEXCEPT; virtual bool do_always_noconv() const _NOEXCEPT; virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; virtual int do_max_length() const _NOEXCEPT; }; // template class codecvt_byname template class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> { public: _LIBCPP_ALWAYS_INLINE explicit codecvt_byname(const char* __nm, size_t __refs = 0) : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} _LIBCPP_ALWAYS_INLINE explicit codecvt_byname(const string& __nm, size_t __refs = 0) : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} protected: ~codecvt_byname(); }; template codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() { } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname) _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); template struct __narrow_to_utf8 { template _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; }; template <> struct __narrow_to_utf8<8> { template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { for (; __wb < __we; ++__wb, ++__s) *__s = *__wb; return __s; } }; template <> struct __narrow_to_utf8<16> : public codecvt { _LIBCPP_ALWAYS_INLINE __narrow_to_utf8() : codecvt(1) {} ~__narrow_to_utf8(); template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { result __r = ok; mbstate_t __mb; while (__wb < __we && __r != error) { const int __sz = 32; char __buf[__sz]; char* __bn; const char16_t* __wn = (const char16_t*)__wb; __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf+__sz, __bn); if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) __throw_runtime_error("locale not supported"); for (const char* __p = __buf; __p < __bn; ++__p, ++__s) *__s = *__p; __wb = (const _CharT*)__wn; } return __s; } }; template <> struct __narrow_to_utf8<32> : public codecvt { _LIBCPP_ALWAYS_INLINE __narrow_to_utf8() : codecvt(1) {} ~__narrow_to_utf8(); template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { result __r = ok; mbstate_t __mb; while (__wb < __we && __r != error) { const int __sz = 32; char __buf[__sz]; char* __bn; const char32_t* __wn = (const char32_t*)__wb; __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf+__sz, __bn); if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) __throw_runtime_error("locale not supported"); for (const char* __p = __buf; __p < __bn; ++__p, ++__s) *__s = *__p; __wb = (const _CharT*)__wn; } return __s; } }; template struct __widen_from_utf8 { template _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; }; template <> struct __widen_from_utf8<8> { template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { for (; __nb < __ne; ++__nb, ++__s) *__s = *__nb; return __s; } }; template <> struct __widen_from_utf8<16> : public codecvt { _LIBCPP_ALWAYS_INLINE __widen_from_utf8() : codecvt(1) {} ~__widen_from_utf8(); template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { result __r = ok; mbstate_t __mb; while (__nb < __ne && __r != error) { const int __sz = 32; char16_t __buf[__sz]; char16_t* __bn; const char* __nn = __nb; __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, __buf, __buf+__sz, __bn); if (__r == codecvt_base::error || __nn == __nb) __throw_runtime_error("locale not supported"); for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) *__s = (wchar_t)*__p; __nb = __nn; } return __s; } }; template <> struct __widen_from_utf8<32> : public codecvt { _LIBCPP_ALWAYS_INLINE __widen_from_utf8() : codecvt(1) {} ~__widen_from_utf8(); template _LIBCPP_ALWAYS_INLINE _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { result __r = ok; mbstate_t __mb; while (__nb < __ne && __r != error) { const int __sz = 32; char32_t __buf[__sz]; char32_t* __bn; const char* __nn = __nb; __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, __buf, __buf+__sz, __bn); if (__r == codecvt_base::error || __nn == __nb) __throw_runtime_error("locale not supported"); for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) *__s = (wchar_t)*__p; __nb = __nn; } return __s; } }; // template class numpunct template class _LIBCPP_TEMPLATE_VIS numpunct; template <> class _LIBCPP_TYPE_VIS numpunct : public locale::facet { public: typedef char char_type; typedef basic_string string_type; explicit numpunct(size_t __refs = 0); _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();} _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();} static locale::id id; protected: ~numpunct(); virtual char_type do_decimal_point() const; virtual char_type do_thousands_sep() const; virtual string do_grouping() const; virtual string_type do_truename() const; virtual string_type do_falsename() const; char_type __decimal_point_; char_type __thousands_sep_; string __grouping_; }; template <> class _LIBCPP_TYPE_VIS numpunct : public locale::facet { public: typedef wchar_t char_type; typedef basic_string string_type; explicit numpunct(size_t __refs = 0); _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();} _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();} static locale::id id; protected: ~numpunct(); virtual char_type do_decimal_point() const; virtual char_type do_thousands_sep() const; virtual string do_grouping() const; virtual string_type do_truename() const; virtual string_type do_falsename() const; char_type __decimal_point_; char_type __thousands_sep_; string __grouping_; }; // template class numpunct_byname template class _LIBCPP_TEMPLATE_VIS numpunct_byname; template <> class _LIBCPP_TYPE_VIS numpunct_byname : public numpunct { public: typedef char char_type; typedef basic_string string_type; explicit numpunct_byname(const char* __nm, size_t __refs = 0); explicit numpunct_byname(const string& __nm, size_t __refs = 0); protected: ~numpunct_byname(); private: void __init(const char*); }; template <> class _LIBCPP_TYPE_VIS numpunct_byname : public numpunct { public: typedef wchar_t char_type; typedef basic_string string_type; explicit numpunct_byname(const char* __nm, size_t __refs = 0); explicit numpunct_byname(const string& __nm, size_t __refs = 0); protected: ~numpunct_byname(); private: void __init(const char*); }; _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___LOCALE Index: projects/clang600-import/contrib/libc++/include/__tree =================================================================== --- projects/clang600-import/contrib/libc++/include/__tree (revision 327038) +++ projects/clang600-import/contrib/libc++/include/__tree (revision 327039) @@ -1,2692 +1,2692 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // 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___TREE #define _LIBCPP___TREE #include <__config> #include #include #include #include #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 __tree; template class _LIBCPP_TEMPLATE_VIS __tree_iterator; template class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; template class __tree_end_node; template class __tree_node_base; template class __tree_node; #ifndef _LIBCPP_CXX03_LANG template union __value_type; #else template struct __value_type; #endif template ::value && !__libcpp_is_final<_Compare>::value> class __map_value_compare; template class __map_node_destructor; template class _LIBCPP_TEMPLATE_VIS __map_iterator; template class _LIBCPP_TEMPLATE_VIS __map_const_iterator; /* _NodePtr algorithms The algorithms taking _NodePtr are red black tree algorithms. Those algorithms taking a parameter named __root should assume that __root points to a proper red black tree (unless otherwise specified). Each algorithm herein assumes that __root->__parent_ points to a non-null structure which has a member __left_ which points back to __root. No other member is read or written to at __root->__parent_. __root->__parent_ will be referred to below (in comments only) as end_node. end_node->__left_ is an externably accessible lvalue for __root, and can be changed by node insertion and removal (without explicit reference to end_node). All nodes (with the exception of end_node), even the node referred to as __root, have a non-null __parent_ field. */ // Returns: true if __x is a left child of its parent, else false // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY bool __tree_is_left_child(_NodePtr __x) _NOEXCEPT { return __x == __x->__parent_->__left_; } -// Determintes if the subtree rooted at __x is a proper red black subtree. If +// Determines if the subtree rooted at __x is a proper red black subtree. If // __x is a proper subtree, returns the black height (null counts as 1). If // __x is an improper subtree, returns 0. template unsigned __tree_sub_invariant(_NodePtr __x) { if (__x == nullptr) return 1; // parent consistency checked by caller // check __x->__left_ consistency if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x) return 0; // check __x->__right_ consistency if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x) return 0; // check __x->__left_ != __x->__right_ unless both are nullptr if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr) return 0; // If this is red, neither child can be red if (!__x->__is_black_) { if (__x->__left_ && !__x->__left_->__is_black_) return 0; if (__x->__right_ && !__x->__right_->__is_black_) return 0; } unsigned __h = __tree_sub_invariant(__x->__left_); if (__h == 0) return 0; // invalid left subtree if (__h != __tree_sub_invariant(__x->__right_)) return 0; // invalid or different height right subtree return __h + __x->__is_black_; // return black height of this node } -// Determintes if the red black tree rooted at __root is a proper red black tree. +// Determines if the red black tree rooted at __root is a proper red black tree. // __root == nullptr is a proper tree. Returns true is __root is a proper // red black tree, else returns false. template bool __tree_invariant(_NodePtr __root) { if (__root == nullptr) return true; // check __x->__parent_ consistency if (__root->__parent_ == nullptr) return false; if (!__tree_is_left_child(__root)) return false; // root must be black if (!__root->__is_black_) return false; // do normal node checks return __tree_sub_invariant(__root) != 0; } // Returns: pointer to the left-most node under __x. // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { while (__x->__left_ != nullptr) __x = __x->__left_; return __x; } // Returns: pointer to the right-most node under __x. // Precondition: __x != nullptr. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { while (__x->__right_ != nullptr) __x = __x->__right_; return __x; } // Returns: pointer to the next in-order node after __x. // Precondition: __x != nullptr. template _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { if (__x->__right_ != nullptr) return __tree_min(__x->__right_); while (!__tree_is_left_child(__x)) __x = __x->__parent_unsafe(); return __x->__parent_unsafe(); } template inline _LIBCPP_INLINE_VISIBILITY _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEPT { if (__x->__right_ != nullptr) return static_cast<_EndNodePtr>(__tree_min(__x->__right_)); while (!__tree_is_left_child(__x)) __x = __x->__parent_unsafe(); return static_cast<_EndNodePtr>(__x->__parent_); } // Returns: pointer to the previous in-order node before __x. // Precondition: __x != nullptr. // Note: __x may be the end node. template inline _LIBCPP_INLINE_VISIBILITY _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT { if (__x->__left_ != nullptr) return __tree_max(__x->__left_); _NodePtr __xx = static_cast<_NodePtr>(__x); while (__tree_is_left_child(__xx)) __xx = __xx->__parent_unsafe(); return __xx->__parent_unsafe(); } // Returns: pointer to a node which has no children // Precondition: __x != nullptr. template _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { while (true) { if (__x->__left_ != nullptr) { __x = __x->__left_; continue; } if (__x->__right_ != nullptr) { __x = __x->__right_; continue; } break; } return __x; } // Effects: Makes __x->__right_ the subtree root with __x as its left child // while preserving in-order order. // Precondition: __x->__right_ != nullptr template void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { _NodePtr __y = __x->__right_; __x->__right_ = __y->__left_; if (__x->__right_ != nullptr) __x->__right_->__set_parent(__x); __y->__parent_ = __x->__parent_; if (__tree_is_left_child(__x)) __x->__parent_->__left_ = __y; else __x->__parent_unsafe()->__right_ = __y; __y->__left_ = __x; __x->__set_parent(__y); } // Effects: Makes __x->__left_ the subtree root with __x as its right child // while preserving in-order order. // Precondition: __x->__left_ != nullptr template void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { _NodePtr __y = __x->__left_; __x->__left_ = __y->__right_; if (__x->__left_ != nullptr) __x->__left_->__set_parent(__x); __y->__parent_ = __x->__parent_; if (__tree_is_left_child(__x)) __x->__parent_->__left_ = __y; else __x->__parent_unsafe()->__right_ = __y; __y->__right_ = __x; __x->__set_parent(__y); } // Effects: Rebalances __root after attaching __x to a leaf. // Precondition: __root != nulptr && __x != nullptr. // __x has no children. // __x == __root or == a direct or indirect child of __root. // If __x were to be unlinked from __root (setting __root to // nullptr if __root == __x), __tree_invariant(__root) == true. // Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ // may be different than the value passed in as __root. template void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT { __x->__is_black_ = __x == __root; while (__x != __root && !__x->__parent_unsafe()->__is_black_) { // __x->__parent_ != __root because __x->__parent_->__is_black == false if (__tree_is_left_child(__x->__parent_unsafe())) { _NodePtr __y = __x->__parent_unsafe()->__parent_unsafe()->__right_; if (__y != nullptr && !__y->__is_black_) { __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = __x == __root; __y->__is_black_ = true; } else { if (!__tree_is_left_child(__x)) { __x = __x->__parent_unsafe(); __tree_left_rotate(__x); } __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = false; __tree_right_rotate(__x); break; } } else { _NodePtr __y = __x->__parent_unsafe()->__parent_->__left_; if (__y != nullptr && !__y->__is_black_) { __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = __x == __root; __y->__is_black_ = true; } else { if (__tree_is_left_child(__x)) { __x = __x->__parent_unsafe(); __tree_right_rotate(__x); } __x = __x->__parent_unsafe(); __x->__is_black_ = true; __x = __x->__parent_unsafe(); __x->__is_black_ = false; __tree_left_rotate(__x); break; } } } } // Precondition: __root != nullptr && __z != nullptr. // __tree_invariant(__root) == true. // __z == __root or == a direct or indirect child of __root. // Effects: unlinks __z from the tree rooted at __root, rebalancing as needed. // Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_ // nor any of its children refer to __z. end_node->__left_ // may be different than the value passed in as __root. template void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT { // __z will be removed from the tree. Client still needs to destruct/deallocate it // __y is either __z, or if __z has two children, __tree_next(__z). // __y will have at most one child. // __y will be the initial hole in the tree (make the hole at a leaf) _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ? __z : __tree_next(__z); // __x is __y's possibly null single child _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_; // __w is __x's possibly null uncle (will become __x's sibling) _NodePtr __w = nullptr; // link __x to __y's parent, and find __w if (__x != nullptr) __x->__parent_ = __y->__parent_; if (__tree_is_left_child(__y)) { __y->__parent_->__left_ = __x; if (__y != __root) __w = __y->__parent_unsafe()->__right_; else __root = __x; // __w == nullptr } else { __y->__parent_unsafe()->__right_ = __x; // __y can't be root if it is a right child __w = __y->__parent_->__left_; } bool __removed_black = __y->__is_black_; // If we didn't remove __z, do so now by splicing in __y for __z, // but copy __z's color. This does not impact __x or __w. if (__y != __z) { // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr __y->__parent_ = __z->__parent_; if (__tree_is_left_child(__z)) __y->__parent_->__left_ = __y; else __y->__parent_unsafe()->__right_ = __y; __y->__left_ = __z->__left_; __y->__left_->__set_parent(__y); __y->__right_ = __z->__right_; if (__y->__right_ != nullptr) __y->__right_->__set_parent(__y); __y->__is_black_ = __z->__is_black_; if (__root == __z) __root = __y; } // There is no need to rebalance if we removed a red, or if we removed // the last node. if (__removed_black && __root != nullptr) { // Rebalance: // __x has an implicit black color (transferred from the removed __y) // associated with it, no matter what its color is. // If __x is __root (in which case it can't be null), it is supposed // to be black anyway, and if it is doubly black, then the double // can just be ignored. // If __x is red (in which case it can't be null), then it can absorb // the implicit black just by setting its color to black. // Since __y was black and only had one child (which __x points to), __x // is either red with no children, else null, otherwise __y would have // different black heights under left and right pointers. // if (__x == __root || __x != nullptr && !__x->__is_black_) if (__x != nullptr) __x->__is_black_ = true; else { // Else __x isn't root, and is "doubly black", even though it may // be null. __w can not be null here, else the parent would // see a black height >= 2 on the __x side and a black height // of 1 on the __w side (__w must be a non-null black or a red // with a non-null black child). while (true) { if (!__tree_is_left_child(__w)) // if x is left child { if (!__w->__is_black_) { __w->__is_black_ = true; __w->__parent_unsafe()->__is_black_ = false; __tree_left_rotate(__w->__parent_unsafe()); // __x is still valid // reset __root only if necessary if (__root == __w->__left_) __root = __w; // reset sibling, and it still can't be null __w = __w->__left_->__right_; } // __w->__is_black_ is now true, __w may have null children if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && (__w->__right_ == nullptr || __w->__right_->__is_black_)) { __w->__is_black_ = false; __x = __w->__parent_unsafe(); // __x can no longer be null if (__x == __root || !__x->__is_black_) { __x->__is_black_ = true; break; } // reset sibling, and it still can't be null __w = __tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_; // continue; } else // __w has a red child { if (__w->__right_ == nullptr || __w->__right_->__is_black_) { // __w left child is non-null and red __w->__left_->__is_black_ = true; __w->__is_black_ = false; __tree_right_rotate(__w); // __w is known not to be root, so root hasn't changed // reset sibling, and it still can't be null __w = __w->__parent_unsafe(); } // __w has a right red child, left child may be null __w->__is_black_ = __w->__parent_unsafe()->__is_black_; __w->__parent_unsafe()->__is_black_ = true; __w->__right_->__is_black_ = true; __tree_left_rotate(__w->__parent_unsafe()); break; } } else { if (!__w->__is_black_) { __w->__is_black_ = true; __w->__parent_unsafe()->__is_black_ = false; __tree_right_rotate(__w->__parent_unsafe()); // __x is still valid // reset __root only if necessary if (__root == __w->__right_) __root = __w; // reset sibling, and it still can't be null __w = __w->__right_->__left_; } // __w->__is_black_ is now true, __w may have null children if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && (__w->__right_ == nullptr || __w->__right_->__is_black_)) { __w->__is_black_ = false; __x = __w->__parent_unsafe(); // __x can no longer be null if (!__x->__is_black_ || __x == __root) { __x->__is_black_ = true; break; } // reset sibling, and it still can't be null __w = __tree_is_left_child(__x) ? __x->__parent_unsafe()->__right_ : __x->__parent_->__left_; // continue; } else // __w has a red child { if (__w->__left_ == nullptr || __w->__left_->__is_black_) { // __w right child is non-null and red __w->__right_->__is_black_ = true; __w->__is_black_ = false; __tree_left_rotate(__w); // __w is known not to be root, so root hasn't changed // reset sibling, and it still can't be null __w = __w->__parent_unsafe(); } // __w has a left red child, right child may be null __w->__is_black_ = __w->__parent_unsafe()->__is_black_; __w->__parent_unsafe()->__is_black_ = true; __w->__left_->__is_black_ = true; __tree_right_rotate(__w->__parent_unsafe()); break; } } } } } } // node traits #ifndef _LIBCPP_CXX03_LANG template struct __is_tree_value_type_imp : false_type {}; template struct __is_tree_value_type_imp<__value_type<_Key, _Value>> : true_type {}; template struct __is_tree_value_type : false_type {}; template struct __is_tree_value_type<_One> : __is_tree_value_type_imp::type> {}; #endif template struct __tree_key_value_types { typedef _Tp key_type; typedef _Tp __node_value_type; typedef _Tp __container_value_type; static const bool __is_map = false; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(_Tp const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static __container_value_type&& __move(__node_value_type& __v) { return _VSTD::move(__v); } #endif }; template struct __tree_key_value_types<__value_type<_Key, _Tp> > { typedef _Key key_type; typedef _Tp mapped_type; typedef __value_type<_Key, _Tp> __node_value_type; typedef pair __container_value_type; typedef pair<_Key, _Tp> __nc_value_type; typedef __container_value_type __map_value_type; static const bool __is_map = true; _LIBCPP_INLINE_VISIBILITY static key_type const& __get_key(__node_value_type const& __t) { return __t.__cc.first; } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, key_type const&>::type __get_key(_Up& __t) { return __t.first; } _LIBCPP_INLINE_VISIBILITY static __container_value_type const& __get_value(__node_value_type const& __t) { return __t.__cc; } template _LIBCPP_INLINE_VISIBILITY static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, __container_value_type const&>::type __get_value(_Up& __t) { return __t; } _LIBCPP_INLINE_VISIBILITY static __container_value_type* __get_ptr(__node_value_type& __n) { return _VSTD::addressof(__n.__cc); } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY static __nc_value_type&& __move(__node_value_type& __v) { return _VSTD::move(__v.__nc); } #endif }; template struct __tree_node_base_types { typedef _VoidPtr __void_pointer; typedef __tree_node_base<__void_pointer> __node_base_type; typedef typename __rebind_pointer<_VoidPtr, __node_base_type>::type __node_base_pointer; typedef __tree_end_node<__node_base_pointer> __end_node_type; typedef typename __rebind_pointer<_VoidPtr, __end_node_type>::type __end_node_pointer; #if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) typedef __end_node_pointer __parent_pointer; #else typedef typename conditional< is_pointer<__end_node_pointer>::value, __end_node_pointer, __node_base_pointer>::type __parent_pointer; #endif private: static_assert((is_same::element_type, void>::value), "_VoidPtr does not point to unqualified void type"); }; template , bool = _KVTypes::__is_map> struct __tree_map_pointer_types {}; template struct __tree_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { typedef typename _KVTypes::__map_value_type _Mv; typedef typename __rebind_pointer<_AllocPtr, _Mv>::type __map_value_type_pointer; typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type __const_map_value_type_pointer; }; template ::element_type> struct __tree_node_types; template struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> > : public __tree_node_base_types<_VoidPtr>, __tree_key_value_types<_Tp>, __tree_map_pointer_types<_Tp, _VoidPtr> { typedef __tree_node_base_types<_VoidPtr> __base; typedef __tree_key_value_types<_Tp> __key_base; typedef __tree_map_pointer_types<_Tp, _VoidPtr> __map_pointer_base; public: typedef typename pointer_traits<_NodePtr>::element_type __node_type; typedef _NodePtr __node_pointer; typedef _Tp __node_value_type; typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type __node_value_type_pointer; typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type __const_node_value_type_pointer; #if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) typedef typename __base::__end_node_pointer __iter_pointer; #else typedef typename conditional< is_pointer<__node_pointer>::value, typename __base::__end_node_pointer, __node_pointer>::type __iter_pointer; #endif private: static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); static_assert((is_same::type, _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); }; template struct __make_tree_node_types { typedef typename __rebind_pointer<_VoidPtr, __tree_node<_ValueTp, _VoidPtr> >::type _NodePtr; typedef __tree_node_types<_NodePtr> type; }; // node template class __tree_end_node { public: typedef _Pointer pointer; pointer __left_; _LIBCPP_INLINE_VISIBILITY __tree_end_node() _NOEXCEPT : __left_() {} }; template class __tree_node_base : public __tree_node_base_types<_VoidPtr>::__end_node_type { typedef __tree_node_base_types<_VoidPtr> _NodeBaseTypes; public: typedef typename _NodeBaseTypes::__node_base_pointer pointer; typedef typename _NodeBaseTypes::__parent_pointer __parent_pointer; pointer __right_; __parent_pointer __parent_; bool __is_black_; _LIBCPP_INLINE_VISIBILITY pointer __parent_unsafe() const { return static_cast(__parent_);} _LIBCPP_INLINE_VISIBILITY void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); } private: ~__tree_node_base() _LIBCPP_EQUAL_DELETE; __tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; __tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE; }; template class __tree_node : public __tree_node_base<_VoidPtr> { public: typedef _Tp __node_value_type; __node_value_type __value_; private: ~__tree_node() _LIBCPP_EQUAL_DELETE; __tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE; __tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_DELETE; }; template class __tree_node_destructor { typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; private: typedef __tree_node_types _NodeTypes; allocator_type& __na_; __tree_node_destructor& operator=(const __tree_node_destructor&); public: bool __value_constructed; _LIBCPP_INLINE_VISIBILITY explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT : __na_(__na), __value_constructed(__val) {} _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT { if (__value_constructed) __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } template friend class __map_node_destructor; }; template class _LIBCPP_TEMPLATE_VIS __tree_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef _NodePtr __node_pointer; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef pointer_traits<__node_pointer> __pointer_traits; __iter_pointer __ptr_; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef _DiffType difference_type; typedef value_type& reference; typedef typename _NodeTypes::__node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __ptr_(nullptr) #endif {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_np()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__get_np()->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator++() { __ptr_ = static_cast<__iter_pointer>( __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_iterator operator++(int) {__tree_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator--() { __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( static_cast<__end_node_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_iterator operator--(int) {__tree_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) {return !(__x == __y);} private: _LIBCPP_INLINE_VISIBILITY explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template friend class __tree; template friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; template friend class _LIBCPP_TEMPLATE_VIS __map_iterator; template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS set; template friend class _LIBCPP_TEMPLATE_VIS multiset; }; template class _LIBCPP_TEMPLATE_VIS __tree_const_iterator { typedef __tree_node_types<_NodePtr> _NodeTypes; typedef typename _NodeTypes::__node_pointer __node_pointer; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef pointer_traits<__node_pointer> __pointer_traits; __iter_pointer __ptr_; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef _DiffType difference_type; typedef const value_type& reference; typedef typename _NodeTypes::__const_node_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __ptr_(nullptr) #endif {} private: typedef __tree_iterator __non_const_iterator; public: _LIBCPP_INLINE_VISIBILITY __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_np()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__get_np()->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator++() { __ptr_ = static_cast<__iter_pointer>( __tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_const_iterator operator++(int) {__tree_const_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator--() { __ptr_ = static_cast<__iter_pointer>(__tree_prev_iter<__node_base_pointer>( static_cast<__end_node_pointer>(__ptr_))); return *this; } _LIBCPP_INLINE_VISIBILITY __tree_const_iterator operator--(int) {__tree_const_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) {return !(__x == __y);} private: _LIBCPP_INLINE_VISIBILITY explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} _LIBCPP_INLINE_VISIBILITY __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } template friend class __tree; template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS set; template friend class _LIBCPP_TEMPLATE_VIS multiset; template friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; }; #ifndef _LIBCPP_CXX03_LANG template struct __diagnose_tree_helper { static constexpr bool __trigger_diagnostics() _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Compare const&, _Tp const&, _Tp const&>::value, "the specified comparator type does not provide a const call operator") { return true; } }; template struct __diagnose_tree_helper< __value_type<_Key, _Value>, __map_value_compare<_Key, __value_type<_Key, _Value>, _KeyComp>, _Alloc > : __diagnose_tree_helper<_Key, _KeyComp, _Alloc> { }; #endif // !_LIBCPP_CXX03_LANG template class __tree { public: typedef _Tp value_type; typedef _Compare value_compare; typedef _Allocator allocator_type; private: typedef allocator_traits __alloc_traits; typedef typename __make_tree_node_types::type _NodeTypes; typedef typename _NodeTypes::key_type key_type; public: typedef typename _NodeTypes::__node_value_type __node_value_type; typedef typename _NodeTypes::__container_value_type __container_value_type; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; public: typedef typename _NodeTypes::__void_pointer __void_pointer; typedef typename _NodeTypes::__node_type __node; typedef typename _NodeTypes::__node_pointer __node_pointer; typedef typename _NodeTypes::__node_base_type __node_base; typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; typedef typename _NodeTypes::__end_node_type __end_node_t; typedef typename _NodeTypes::__end_node_pointer __end_node_ptr; typedef typename _NodeTypes::__parent_pointer __parent_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; private: // check for sane allocator pointer rebinding semantics. Rebinding the // allocator for a new pointer type should be exactly the same as rebinding // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); typedef typename __rebind_alloc_helper<__node_traits, __node_base>::type __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); private: __iter_pointer __begin_node_; __compressed_pair<__end_node_t, __node_allocator> __pair1_; __compressed_pair __pair3_; public: _LIBCPP_INLINE_VISIBILITY __iter_pointer __end_node() _NOEXCEPT { return static_cast<__iter_pointer>( pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()) ); } _LIBCPP_INLINE_VISIBILITY __iter_pointer __end_node() const _NOEXCEPT { return static_cast<__iter_pointer>( pointer_traits<__end_node_ptr>::pointer_to( const_cast<__end_node_t&>(__pair1_.first()) ) ); } _LIBCPP_INLINE_VISIBILITY __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();} private: _LIBCPP_INLINE_VISIBILITY const __node_allocator& __node_alloc() const _NOEXCEPT {return __pair1_.second();} _LIBCPP_INLINE_VISIBILITY __iter_pointer& __begin_node() _NOEXCEPT {return __begin_node_;} _LIBCPP_INLINE_VISIBILITY const __iter_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;} public: _LIBCPP_INLINE_VISIBILITY allocator_type __alloc() const _NOEXCEPT {return allocator_type(__node_alloc());} private: _LIBCPP_INLINE_VISIBILITY size_type& size() _NOEXCEPT {return __pair3_.first();} public: _LIBCPP_INLINE_VISIBILITY const size_type& size() const _NOEXCEPT {return __pair3_.first();} _LIBCPP_INLINE_VISIBILITY value_compare& value_comp() _NOEXCEPT {return __pair3_.second();} _LIBCPP_INLINE_VISIBILITY const value_compare& value_comp() const _NOEXCEPT {return __pair3_.second();} public: _LIBCPP_INLINE_VISIBILITY __node_pointer __root() const _NOEXCEPT {return static_cast<__node_pointer>(__end_node()->__left_);} __node_base_pointer* __root_ptr() const _NOEXCEPT { return _VSTD::addressof(__end_node()->__left_); } typedef __tree_iterator iterator; typedef __tree_const_iterator const_iterator; explicit __tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_copy_constructible::value); explicit __tree(const allocator_type& __a); __tree(const value_compare& __comp, const allocator_type& __a); __tree(const __tree& __t); __tree& operator=(const __tree& __t); template void __assign_unique(_InputIterator __first, _InputIterator __last); template void __assign_multi(_InputIterator __first, _InputIterator __last); #ifndef _LIBCPP_CXX03_LANG __tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value); __tree(__tree&& __t, const allocator_type& __a); __tree& operator=(__tree&& __t) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value); #endif // _LIBCPP_CXX03_LANG ~__tree(); _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(__begin_node());} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(__end_node());} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return std::min( __node_traits::max_size(__node_alloc()), numeric_limits::max());} void clear() _NOEXCEPT; void swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ); #else _NOEXCEPT_(__is_nothrow_swappable::value); #endif #ifndef _LIBCPP_CXX03_LANG template pair __emplace_unique_key_args(_Key const&, _Args&&... __args); template iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...); template pair __emplace_unique_impl(_Args&&... __args); template iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args); template iterator __emplace_multi(_Args&&... __args); template iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Pp&& __x) { return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); } template _LIBCPP_INLINE_VISIBILITY typename enable_if< __can_extract_map_key<_First, key_type, __container_value_type>::value, pair >::type __emplace_unique(_First&& __f, _Second&& __s) { return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), _VSTD::forward<_Second>(__s)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique(_Args&&... __args) { return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique(const_iterator __p, _Pp&& __x) { return __emplace_hint_unique_extract_key(__p, _VSTD::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); } template _LIBCPP_INLINE_VISIBILITY typename enable_if< __can_extract_map_key<_First, key_type, __container_value_type>::value, iterator >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) { return __emplace_hint_unique_key_args(__p, __f, _VSTD::forward<_First>(__f), _VSTD::forward<_Second>(__s)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) { return __emplace_hint_unique_impl(__p, _VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_fail_tag) { return __emplace_hint_unique_impl(__p, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_self_tag) { return __emplace_hint_unique_key_args(__p, __x, _VSTD::forward<_Pp>(__x)); } template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_first_tag) { return __emplace_hint_unique_key_args(__p, __x.first, _VSTD::forward<_Pp>(__x)); } #else template _LIBCPP_INLINE_VISIBILITY pair __emplace_unique_key_args(_Key const&, _Args& __args); template _LIBCPP_INLINE_VISIBILITY iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&); #endif _LIBCPP_INLINE_VISIBILITY pair __insert_unique(const __container_value_type& __v) { return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v); } _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, const __container_value_type& __v) { return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v); } #ifdef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const __container_value_type& __v); _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, const __container_value_type& __v); #else _LIBCPP_INLINE_VISIBILITY pair __insert_unique(__container_value_type&& __v) { return __emplace_unique_key_args(_NodeTypes::__get_key(__v), _VSTD::move(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, __container_value_type&& __v) { return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), _VSTD::move(__v)); } template ::type, __container_value_type >::value >::type> _LIBCPP_INLINE_VISIBILITY pair __insert_unique(_Vp&& __v) { return __emplace_unique(_VSTD::forward<_Vp>(__v)); } template ::type, __container_value_type >::value >::type> _LIBCPP_INLINE_VISIBILITY iterator __insert_unique(const_iterator __p, _Vp&& __v) { return __emplace_hint_unique(__p, _VSTD::forward<_Vp>(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(__container_value_type&& __v) { return __emplace_multi(_VSTD::move(__v)); } _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, __container_value_type&& __v) { return __emplace_hint_multi(__p, _VSTD::move(__v)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(_Vp&& __v) { return __emplace_multi(_VSTD::forward<_Vp>(__v)); } template _LIBCPP_INLINE_VISIBILITY iterator __insert_multi(const_iterator __p, _Vp&& __v) { return __emplace_hint_multi(__p, _VSTD::forward<_Vp>(__v)); } #endif // !_LIBCPP_CXX03_LANG pair __node_insert_unique(__node_pointer __nd); iterator __node_insert_unique(const_iterator __p, __node_pointer __nd); iterator __node_insert_multi(__node_pointer __nd); iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); template size_type __erase_unique(const _Key& __k); template size_type __erase_multi(const _Key& __k); void __insert_node_at(__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node); template iterator find(const _Key& __v); template const_iterator find(const _Key& __v) const; template size_type __count_unique(const _Key& __k) const; template size_type __count_multi(const _Key& __k) const; template _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const _Key& __v) {return __lower_bound(__v, __root(), __end_node());} template iterator __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result); template _LIBCPP_INLINE_VISIBILITY const_iterator lower_bound(const _Key& __v) const {return __lower_bound(__v, __root(), __end_node());} template const_iterator __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const; template _LIBCPP_INLINE_VISIBILITY iterator upper_bound(const _Key& __v) {return __upper_bound(__v, __root(), __end_node());} template iterator __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result); template _LIBCPP_INLINE_VISIBILITY const_iterator upper_bound(const _Key& __v) const {return __upper_bound(__v, __root(), __end_node());} template const_iterator __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const; template pair __equal_range_unique(const _Key& __k); template pair __equal_range_unique(const _Key& __k) const; template pair __equal_range_multi(const _Key& __k); template pair __equal_range_multi(const _Key& __k) const; typedef __tree_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; __node_holder remove(const_iterator __p) _NOEXCEPT; private: __node_base_pointer& __find_leaf_low(__parent_pointer& __parent, const key_type& __v); __node_base_pointer& __find_leaf_high(__parent_pointer& __parent, const key_type& __v); __node_base_pointer& __find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v); // FIXME: Make this function const qualified. Unfortunetly doing so // breaks existing code which uses non-const callable comparators. template __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v); template _LIBCPP_INLINE_VISIBILITY __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v) const { return const_cast<__tree*>(this)->__find_equal(__parent, __v); } template __node_base_pointer& __find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v); #ifndef _LIBCPP_CXX03_LANG template __node_holder __construct_node(_Args&& ...__args); #else __node_holder __construct_node(const __container_value_type& __v); #endif void destroy(__node_pointer __nd) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree& __t) {__copy_assign_alloc(__t, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree& __t, true_type) { if (__node_alloc() != __t.__node_alloc()) clear(); __node_alloc() = __t.__node_alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __tree&, false_type) {} void __move_assign(__tree& __t, false_type); void __move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree& __t) _NOEXCEPT_( !__node_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable<__node_allocator>::value) {__move_assign_alloc(__t, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {__node_alloc() = _VSTD::move(__t.__node_alloc());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} __node_pointer __detach(); static __node_pointer __detach(__node_pointer); template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; }; template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_copy_constructible::value) : __pair3_(0, __comp) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0) { __begin_node() = __end_node(); } template __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, __comp) { __begin_node() = __end_node(); } // Precondition: size() != 0 template typename __tree<_Tp, _Compare, _Allocator>::__node_pointer __tree<_Tp, _Compare, _Allocator>::__detach() { __node_pointer __cache = static_cast<__node_pointer>(__begin_node()); __begin_node() = __end_node(); __end_node()->__left_->__parent_ = nullptr; __end_node()->__left_ = nullptr; size() = 0; // __cache->__left_ == nullptr if (__cache->__right_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__right_); // __cache->__left_ == nullptr // __cache->__right_ == nullptr return __cache; } // Precondition: __cache != nullptr // __cache->left_ == nullptr // __cache->right_ == nullptr // This is no longer a red-black tree template typename __tree<_Tp, _Compare, _Allocator>::__node_pointer __tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) { if (__cache->__parent_ == nullptr) return nullptr; if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) { __cache->__parent_->__left_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); if (__cache->__right_ == nullptr) return __cache; return static_cast<__node_pointer>(__tree_leaf(__cache->__right_)); } // __cache is right child __cache->__parent_unsafe()->__right_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); if (__cache->__left_ == nullptr) return __cache; return static_cast<__node_pointer>(__tree_leaf(__cache->__left_)); } template __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) { if (this != &__t) { value_comp() = __t.value_comp(); __copy_assign_alloc(__t); __assign_multi(__t.begin(), __t.end()); } return *this; } template template void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _InputIterator __last) { typedef iterator_traits<_InputIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value), "__assign_unique may only be called with the containers value type"); if (size() != 0) { __node_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__value_ = *__first; __node_pointer __next = __detach(__cache); __node_insert_unique(__cache); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS if (__cache != nullptr) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); } } for (; __first != __last; ++__first) __insert_unique(*__first); } template template void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) { typedef iterator_traits<_InputIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value), "__assign_multi may only be called with the containers value type" " or the nodes value type"); if (size() != 0) { __node_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__value_ = *__first; __node_pointer __next = __detach(__cache); __node_insert_multi(__cache); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS if (__cache != nullptr) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); } } for (; __first != __last; ++__first) __insert_multi(_NodeTypes::__get_value(*__first)); } template __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) : __begin_node_(__iter_pointer()), __pair1_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), __pair3_(0, __t.value_comp()) { __begin_node() = __end_node(); } #ifndef _LIBCPP_CXX03_LANG template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_( is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible::value) : __begin_node_(_VSTD::move(__t.__begin_node_)), __pair1_(_VSTD::move(__t.__pair1_)), __pair3_(_VSTD::move(__t.__pair3_)) { if (size() == 0) __begin_node() = __end_node(); else { __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } template __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) : __pair1_(__second_tag(), __node_allocator(__a)), __pair3_(0, _VSTD::move(__t.value_comp())) { if (__a == __t.__alloc()) { if (__t.size() == 0) __begin_node() = __end_node(); else { __begin_node() = __t.__begin_node(); __end_node()->__left_ = __t.__end_node()->__left_; __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); size() = __t.size(); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } else { __begin_node() = __end_node(); } } template void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value) { destroy(static_cast<__node_pointer>(__end_node()->__left_)); __begin_node_ = __t.__begin_node_; __pair1_.first() = __t.__pair1_.first(); __move_assign_alloc(__t); __pair3_ = _VSTD::move(__t.__pair3_); if (size() == 0) __begin_node() = __end_node(); else { __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; } } template void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) { if (__node_alloc() == __t.__node_alloc()) __move_assign(__t, true_type()); else { value_comp() = _VSTD::move(__t.value_comp()); const_iterator __e = end(); if (size() != 0) { __node_pointer __cache = __detach(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS while (__cache != nullptr && __t.size() != 0) { __cache->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); __node_pointer __next = __detach(__cache); __node_insert_multi(__cache); __cache = __next; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); throw; } #endif // _LIBCPP_NO_EXCEPTIONS if (__cache != nullptr) { while (__cache->__parent_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__parent_); destroy(__cache); } } while (__t.size() != 0) __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_)); } } template __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable<__node_allocator>::value) { __move_assign(__t, integral_constant()); return *this; } #endif // _LIBCPP_CXX03_LANG template __tree<_Tp, _Compare, _Allocator>::~__tree() { static_assert((is_copy_constructible::value), "Comparator must be copy-constructible."); #ifndef _LIBCPP_CXX03_LANG static_assert((__diagnose_tree_helper<_Tp, _Compare, _Allocator>:: __trigger_diagnostics()), ""); #endif destroy(__root()); } template void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT { if (__nd != nullptr) { destroy(static_cast<__node_pointer>(__nd->__left_)); destroy(static_cast<__node_pointer>(__nd->__right_)); __node_allocator& __na = __node_alloc(); __node_traits::destroy(__na, _NodeTypes::__get_ptr(__nd->__value_)); __node_traits::deallocate(__na, __nd, 1); } } template void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) #if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable::value && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) ) #else _NOEXCEPT_(__is_nothrow_swappable::value) #endif { using _VSTD::swap; swap(__begin_node_, __t.__begin_node_); swap(__pair1_.first(), __t.__pair1_.first()); __swap_allocator(__node_alloc(), __t.__node_alloc()); __pair3_.swap(__t.__pair3_); if (size() == 0) __begin_node() = __end_node(); else __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); if (__t.size() == 0) __t.__begin_node() = __t.__end_node(); else __t.__end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__t.__end_node()); } template void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT { destroy(__root()); size() = 0; __begin_node() = __end_node(); __end_node()->__left_ = nullptr; } // Find lower_bound place to insert // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, const key_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__nd->__value_, __v)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } else { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find upper_bound place to insert // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent, const key_type& __v) { __node_pointer __nd = __root(); if (__nd != nullptr) { while (true) { if (value_comp()(__v, __nd->__value_)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } else { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find leaf place to insert closest to __hint // First check prior to __hint. // Next check after __hint. // Next do O(log N) search. // Set __parent to parent of null leaf // Return reference to null leaf template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v) { if (__hint == end() || !value_comp()(*__hint, __v)) // check before { // __v <= *__hint const_iterator __prior = __hint; if (__prior == begin() || !value_comp()(__v, *--__prior)) { // *prev(__hint) <= __v <= *__hint if (__hint.__ptr_->__left_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } else { __parent = static_cast<__parent_pointer>(__prior.__ptr_); return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } } // __v < *prev(__hint) return __find_leaf_high(__parent, __v); } // else __v > *__hint return __find_leaf_low(__parent, __v); } // Find place to insert if __v doesn't exist // Set __parent to parent of null leaf // Return reference to null leaf // If __v exists, set parent to node of __v and return reference to node of __v template template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, const _Key& __v) { __node_pointer __nd = __root(); __node_base_pointer* __nd_ptr = __root_ptr(); if (__nd != nullptr) { while (true) { if (value_comp()(__v, __nd->__value_)) { if (__nd->__left_ != nullptr) { __nd_ptr = _VSTD::addressof(__nd->__left_); __nd = static_cast<__node_pointer>(__nd->__left_); } else { __parent = static_cast<__parent_pointer>(__nd); return __parent->__left_; } } else if (value_comp()(__nd->__value_, __v)) { if (__nd->__right_ != nullptr) { __nd_ptr = _VSTD::addressof(__nd->__right_); __nd = static_cast<__node_pointer>(__nd->__right_); } else { __parent = static_cast<__parent_pointer>(__nd); return __nd->__right_; } } else { __parent = static_cast<__parent_pointer>(__nd); return *__nd_ptr; } } } __parent = static_cast<__parent_pointer>(__end_node()); return __parent->__left_; } // Find place to insert if __v doesn't exist // First check prior to __hint. // Next check after __hint. // Next do O(log N) search. // Set __parent to parent of null leaf // Return reference to null leaf // If __v exists, set parent to node of __v and return reference to node of __v template template typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v) { if (__hint == end() || value_comp()(__v, *__hint)) // check before { // __v < *__hint const_iterator __prior = __hint; if (__prior == begin() || value_comp()(*--__prior, __v)) { // *prev(__hint) < __v < *__hint if (__hint.__ptr_->__left_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } else { __parent = static_cast<__parent_pointer>(__prior.__ptr_); return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } } // __v <= *prev(__hint) return __find_equal(__parent, __v); } else if (value_comp()(*__hint, __v)) // check after { // *__hint < __v const_iterator __next = _VSTD::next(__hint); if (__next == end() || value_comp()(__v, *__next)) { // *__hint < __v < *_VSTD::next(__hint) if (__hint.__get_np()->__right_ == nullptr) { __parent = static_cast<__parent_pointer>(__hint.__ptr_); return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_; } else { __parent = static_cast<__parent_pointer>(__next.__ptr_); return __parent->__left_; } } // *next(__hint) <= __v return __find_equal(__parent, __v); } // else __v == *__hint __parent = static_cast<__parent_pointer>(__hint.__ptr_); __dummy = static_cast<__node_base_pointer>(__hint.__ptr_); return __dummy; } template void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) { __new_node->__left_ = nullptr; __new_node->__right_ = nullptr; __new_node->__parent_ = __parent; // __new_node->__is_black_ is initialized in __tree_balance_after_insert __child = __new_node; if (__begin_node()->__left_ != nullptr) __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_); __tree_balance_after_insert(__end_node()->__left_, __child); ++size(); } #ifndef _LIBCPP_CXX03_LANG template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) #else template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args& __args) #endif { __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __k); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { #ifndef _LIBCPP_CXX03_LANG __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); #else __node_holder __h = __construct_node(__args); #endif __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } return pair(iterator(__r), __inserted); } #ifndef _LIBCPP_CXX03_LANG template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( const_iterator __p, _Key const& __k, _Args&&... __args) #else template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( const_iterator __p, _Key const& __k, _Args& __args) #endif { __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { #ifndef _LIBCPP_CXX03_LANG __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); #else __node_holder __h = __construct_node(__args); #endif __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); } #ifndef _LIBCPP_CXX03_LANG template template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&& ...__args) { static_assert(!__is_tree_value_type<_Args...>::value, "Cannot construct from __value_type"); __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); __h.get_deleter().__value_constructed = true; return __h; } template template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __h->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } return pair(iterator(__r), __inserted); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __h->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) { __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } #else // _LIBCPP_CXX03_LANG template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::__construct_node(const __container_value_type& __v) { __node_allocator& __na = __node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); __h.get_deleter().__value_constructed = true; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_CXX03_LANG #ifdef _LIBCPP_CXX03_LANG template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__insert_multi(const __container_value_type& __v) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__v)); __node_holder __h = __construct_node(__v); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __container_value_type& __v) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__v)); __node_holder __h = __construct_node(__v); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } #endif template pair::iterator, bool> __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_equal(__parent, __nd->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; __inserted = true; } return pair(iterator(__r), __inserted); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, __node_pointer __nd) { __parent_pointer __parent; __node_base_pointer __dummy; __node_base_pointer& __child = __find_equal(__p, __parent, __nd->__value_); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; } return iterator(__r); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, __node_pointer __nd) { __parent_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { __node_pointer __np = __p.__get_np(); iterator __r(__p.__ptr_); ++__r; if (__begin_node() == __p.__ptr_) __begin_node() = __r.__ptr_; --size(); __node_allocator& __na = __node_alloc(); __tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np)); __node_traits::destroy(__na, _NodeTypes::__get_ptr( const_cast<__node_value_type&>(*__p))); __node_traits::deallocate(__na, __np, 1); return __r; } template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) { while (__f != __l) __f = erase(__f); return iterator(__l.__ptr_); } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) { iterator __i = find(__k); if (__i == end()) return 0; erase(__i); return 1; } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) { pair __p = __equal_range_multi(__k); size_type __r = 0; for (; __p.first != __p.second; ++__r) __p.first = erase(__p.first); return __r; } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) { iterator __p = __lower_bound(__v, __root(), __end_node()); if (__p != end() && !value_comp()(__v, *__p)) return __p; return end(); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const { const_iterator __p = __lower_bound(__v, __root(), __end_node()); if (__p != end() && !value_comp()(__v, *__p)) return __p; return end(); } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const { __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return 1; } return 0; } template template typename __tree<_Tp, _Compare, _Allocator>::size_type __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const { __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _VSTD::distance( __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result) ); } return 0; } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) { while (__root != nullptr) { if (!value_comp()(__root->__value_, __v)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const { while (__root != nullptr) { if (!value_comp()(__root->__value_, __v)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) { while (__root != nullptr) { if (value_comp()(__v, __root->__value_)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return iterator(__result); } template template typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const { while (__root != nullptr) { if (value_comp()(__v, __root->__value_)) { __result = static_cast<__iter_pointer>(__root); __root = static_cast<__node_pointer>(__root->__left_); } else __root = static_cast<__node_pointer>(__root->__right_); } return const_iterator(__result); } template template pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(iterator(__rt), iterator( __rt->__right_ != nullptr ? static_cast<__iter_pointer>(__tree_min(__rt->__right_)) : __result)); } return _Pp(iterator(__result), iterator(__result)); } template template pair::const_iterator, typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(const_iterator(__rt), const_iterator( __rt->__right_ != nullptr ? static_cast<__iter_pointer>(__tree_min(__rt->__right_)) : __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template template pair::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(iterator(__result), iterator(__result)); } template template pair::const_iterator, typename __tree<_Tp, _Compare, _Allocator>::const_iterator> __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const { typedef pair _Pp; __iter_pointer __result = __end_node(); __node_pointer __rt = __root(); while (__rt != nullptr) { if (value_comp()(__k, __rt->__value_)) { __result = static_cast<__iter_pointer>(__rt); __rt = static_cast<__node_pointer>(__rt->__left_); } else if (value_comp()(__rt->__value_, __k)) __rt = static_cast<__node_pointer>(__rt->__right_); else return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); } return _Pp(const_iterator(__result), const_iterator(__result)); } template typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT { __node_pointer __np = __p.__get_np(); if (__begin_node() == __p.__ptr_) { if (__np->__right_ != nullptr) __begin_node() = static_cast<__iter_pointer>(__np->__right_); else __begin_node() = static_cast<__iter_pointer>(__np->__parent_); } --size(); __tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np)); return __node_holder(__np, _Dp(__node_alloc(), true)); } template inline _LIBCPP_INLINE_VISIBILITY void swap(__tree<_Tp, _Compare, _Allocator>& __x, __tree<_Tp, _Compare, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP___TREE Index: projects/clang600-import/contrib/libc++/include/algorithm =================================================================== --- projects/clang600-import/contrib/libc++/include/algorithm (revision 327038) +++ projects/clang600-import/contrib/libc++/include/algorithm (revision 327039) @@ -1,5905 +1,5905 @@ // -*- 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 +class __invert // invert the sense of a comparison { private: _Predicate __p_; public: - _LIBCPP_INLINE_VISIBILITY __negate() {} + _LIBCPP_INLINE_VISIBILITY __invert() {} _LIBCPP_INLINE_VISIBILITY - explicit __negate(_Predicate __p) : __p_(__p) {} + explicit __invert(_Predicate __p) : __p_(__p) {} template _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);} + bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} }; #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)) + if (_BitScanForward(&where, __x)) 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)) + if (_BitScanForward64(&where, __x)) 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))) + if (_BitScanForward(&where, static_cast(__x))) return where; // Scan the High Word. - if (_BitScanForward(&where, static_cast(mask >> 32))) + if (_BitScanForward(&where, static_cast(__x >> 32))) return where + 32; // Create a bit offset from the LSB. #endif return 64; #endif // _LIBCPP_COMPILER_MSVC } // Precondition: __x != 0 inline _LIBCPP_INLINE_VISIBILITY unsigned __clz(unsigned __x) { #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)) + if (_BitScanReverse(&where, __x)) 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)) + if (_BitScanReverse64(&where, __x)) return static_cast(63 - where); #else // Scan the high 32 bits. - if (_BitScanReverse(&where, static_cast(mask >> 32))) + if (_BitScanReverse(&where, static_cast(__x >> 32))) return 63 - (where + 32); // Create a bit offset from the MSB. // Scan the low 32 bits. - if (_BitScanReverse(&where, static_cast(mask))) + if (_BitScanReverse(&where, static_cast(__x))) return 63 - where; #endif return 64; // Undefined Behavior. #endif // _LIBCPP_COMPILER_MSVC } inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) { #ifndef _LIBCPP_COMPILER_MSVC return __builtin_popcount (__x); #else static_assert(sizeof(unsigned) == 4, ""); return __popcnt(__x); #endif } inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned 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) { const size_t _WRt = numeric_limits::digits; 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_ < _WRt) _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_ < _WRt - 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, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator & __g, input_iterator_tag) { _Distance __k = 0; for (; __first != __last && __k < __n; ++__first, (void)++__k) - __output[__k] = *__first; + __output_iter[__k] = *__first; _Distance __sz = __k; for (; __first != __last; ++__first, (void)++__k) { _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); if (__r < __sz) - __output[__r] = *__first; + __output_iter[__r] = *__first; } - return __output + _VSTD::min(__n, __k); + return __output_iter + _VSTD::min(__n, __k); } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator& __g, forward_iterator_tag) { _Distance __unsampled_sz = _VSTD::distance(__first, __last); for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) { _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); if (__r < __n) { - *__output++ = *__first; + *__output_iter++ = *__first; --__n; } } - return __output; + return __output_iter; } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator& __g) { typedef typename iterator_traits<_PopulationIterator>::iterator_category _PopCategory; typedef typename iterator_traits<_PopulationIterator>::difference_type _Difference; static_assert(__is_forward_iterator<_PopulationIterator>::value || __is_random_access_iterator<_SampleIterator>::value, "SampleIterator must meet the requirements of RandomAccessIterator"); typedef typename common_type<_Distance, _Difference>::type _CommonType; _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); return _VSTD::__sample( - __first, __last, __output, _CommonType(__n), + __first, __last, __output_iter, _CommonType(__n), __g, _PopCategory()); } #if _LIBCPP_STD_VER > 14 template inline _LIBCPP_INLINE_VISIBILITY _SampleIterator sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator&& __g) { - return _VSTD::__sample(__first, __last, __output, __n, __g); + return _VSTD::__sample(__first, __last, __output_iter, __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); } _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&)) // 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)); + _RBi(__last), __invert<_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; + *__result = *__first1; ++__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: projects/clang600-import/contrib/libc++/include/array =================================================================== --- projects/clang600-import/contrib/libc++/include/array (revision 327038) +++ projects/clang600-import/contrib/libc++/include/array (revision 327039) @@ -1,346 +1,346 @@ // -*- C++ -*- //===---------------------------- array -----------------------------------===// // // 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_ARRAY #define _LIBCPP_ARRAY /* array synopsis namespace std { template struct array { // types: typedef T & reference; typedef const T & const_reference; typedef implementation defined iterator; typedef implementation defined const_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; // No explicit construct/copy/destroy for aggregate type void fill(const T& u); void swap(array& a) noexcept(is_nothrow_swappable_v); // iterators: 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; // capacity: constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr bool empty() const noexcept; // element access: reference operator[](size_type n); const_reference operator[](size_type n) const; // constexpr in C++14 const_reference at(size_type n) const; // constexpr in C++14 reference at(size_type n); reference front(); const_reference front() const; // constexpr in C++14 reference back(); const_reference back() const; // constexpr in C++14 T* data() noexcept; const T* data() const noexcept; }; template bool operator==(const array& x, const array& y); template bool operator!=(const array& x, const array& y); template bool operator<(const array& x, const array& y); template bool operator>(const array& x, const array& y); template bool operator<=(const array& x, const array& y); template bool operator>=(const array& x, const array& y); template void swap(array& x, array& y) noexcept(noexcept(x.swap(y))); template class tuple_size; template class tuple_element; template struct tuple_size>; template struct tuple_element>; template T& get(array&) noexcept; // constexpr in C++14 template const T& get(const array&) noexcept; // constexpr in C++14 template T&& get(array&&) noexcept; // constexpr in C++14 template const T&& get(const array&&) noexcept; // constexpr in C++14 } // std */ #include <__config> #include <__tuple> #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_STD template struct _LIBCPP_TEMPLATE_VIS array { // types: typedef array __self; typedef _Tp value_type; typedef value_type& reference; typedef const value_type& const_reference; typedef value_type* iterator; typedef const value_type* const_iterator; typedef value_type* pointer; typedef const value_type* const_pointer; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; value_type __elems_[_Size > 0 ? _Size : 1]; // No explicit construct/copy/destroy for aggregate type _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {_VSTD::fill_n(__elems_, _Size, __u);} _LIBCPP_INLINE_VISIBILITY void swap(array& __a) _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) { __swap_dispatch((std::integral_constant()), __a); } _LIBCPP_INLINE_VISIBILITY void __swap_dispatch(std::true_type, array&) {} _LIBCPP_INLINE_VISIBILITY void __swap_dispatch(std::false_type, array& __a) { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} // iterators: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator begin() _NOEXCEPT {return iterator(__elems_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cbegin() const _NOEXCEPT {return begin();} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cend() const _NOEXCEPT {return end();} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crend() const _NOEXCEPT {return rend();} // capacity: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} // element access: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator[](size_type __n) {return __elems_[__n];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference operator[](size_type __n) const {return __elems_[__n];} _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 value_type* data() _NOEXCEPT {return __elems_;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const value_type* data() const _NOEXCEPT {return __elems_;} }; template _LIBCPP_CONSTEXPR_AFTER_CXX14 typename array<_Tp, _Size>::reference array<_Tp, _Size>::at(size_type __n) { if (__n >= _Size) __throw_out_of_range("array::at"); return __elems_[__n]; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 typename array<_Tp, _Size>::const_reference array<_Tp, _Size>::at(size_type __n) const { if (__n >= _Size) __throw_out_of_range("array::at"); return __elems_[__n]; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if < _Size == 0 || __is_swappable<_Tp>::value, void >::type swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) _NOEXCEPT_(noexcept(__x.swap(__y))) { __x.swap(__y); } template class _LIBCPP_TEMPLATE_VIS tuple_size > : public integral_constant {}; template class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > { static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); public: typedef _Tp type; }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp& get(array<_Tp, _Size>& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); return __a.__elems_[_Ip]; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& get(const array<_Tp, _Size>& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); return __a.__elems_[_Ip]; } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& get(array<_Tp, _Size>&& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); return _VSTD::move(__a.__elems_[_Ip]); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp&& get(const array<_Tp, _Size>&& __a) _NOEXCEPT { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); return _VSTD::move(__a.__elems_[_Ip]); } #endif // !_LIBCPP_CXX03_LANG _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_ARRAY Index: projects/clang600-import/contrib/libc++/include/bitset =================================================================== --- projects/clang600-import/contrib/libc++/include/bitset (revision 327038) +++ projects/clang600-import/contrib/libc++/include/bitset (revision 327039) @@ -1,1097 +1,1110 @@ // -*- C++ -*- //===---------------------------- bitset ----------------------------------===// // // 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_BITSET #define _LIBCPP_BITSET /* bitset synopsis namespace std { namespace std { template class bitset { public: // bit reference: class reference { friend class bitset; reference() noexcept; public: ~reference() noexcept; reference& operator=(bool x) noexcept; // for b[i] = x; reference& operator=(const reference&) noexcept; // for b[i] = b[j]; bool operator~() const noexcept; // flips the bit operator bool() const noexcept; // for x = b[i]; reference& flip() noexcept; // for b[i].flip(); }; // 23.3.5.1 constructors: constexpr bitset() noexcept; constexpr bitset(unsigned long long val) noexcept; template explicit bitset(const charT* str, typename basic_string::size_type n = basic_string::npos, charT zero = charT('0'), charT one = charT('1')); template explicit bitset(const basic_string& str, typename basic_string::size_type pos = 0, typename basic_string::size_type n = basic_string::npos, charT zero = charT('0'), charT one = charT('1')); // 23.3.5.2 bitset operations: bitset& operator&=(const bitset& rhs) noexcept; bitset& operator|=(const bitset& rhs) noexcept; bitset& operator^=(const bitset& rhs) noexcept; bitset& operator<<=(size_t pos) noexcept; bitset& operator>>=(size_t pos) noexcept; bitset& set() noexcept; bitset& set(size_t pos, bool val = true); bitset& reset() noexcept; bitset& reset(size_t pos); bitset operator~() const noexcept; bitset& flip() noexcept; bitset& flip(size_t pos); // element access: constexpr bool operator[](size_t pos) const; // for b[i]; reference operator[](size_t pos); // for b[i]; unsigned long to_ulong() const; unsigned long long to_ullong() const; template basic_string to_string(charT zero = charT('0'), charT one = charT('1')) const; template basic_string > to_string(charT zero = charT('0'), charT one = charT('1')) const; template basic_string, allocator > to_string(charT zero = charT('0'), charT one = charT('1')) const; basic_string, allocator > to_string(char zero = '0', char one = '1') const; size_t count() const noexcept; constexpr size_t size() const noexcept; bool operator==(const bitset& rhs) const noexcept; bool operator!=(const bitset& rhs) const noexcept; bool test(size_t pos) const; bool all() const noexcept; bool any() const noexcept; bool none() const noexcept; bitset operator<<(size_t pos) const noexcept; bitset operator>>(size_t pos) const noexcept; }; // 23.3.5.3 bitset operators: template bitset operator&(const bitset&, const bitset&) noexcept; template bitset operator|(const bitset&, const bitset&) noexcept; template bitset operator^(const bitset&, const bitset&) noexcept; template basic_istream& operator>>(basic_istream& is, bitset& x); template basic_ostream& operator<<(basic_ostream& os, const bitset& x); template struct hash>; } // std */ #include <__config> #include <__bit_reference> #include #include #include #include #include #include <__functional_base> #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 __bitset; template struct __has_storage_type<__bitset<_N_words, _Size> > { static const bool value = true; }; template class __bitset { public: typedef ptrdiff_t difference_type; typedef size_t size_type; typedef size_type __storage_type; protected: typedef __bitset __self; typedef __storage_type* __storage_pointer; typedef const __storage_type* __const_storage_pointer; static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); friend class __bit_reference<__bitset>; friend class __bit_const_reference<__bitset>; friend class __bit_iterator<__bitset, false>; friend class __bit_iterator<__bitset, true>; friend struct __bit_array<__bitset>; __storage_type __first_[_N_words]; typedef __bit_reference<__bitset> reference; typedef __bit_const_reference<__bitset> const_reference; typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset& __v) _NOEXCEPT; void flip() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return to_ulong(integral_constant());} _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return to_ullong(integral_constant());} bool all() const _NOEXCEPT; bool any() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT; private: #ifdef _LIBCPP_CXX03_LANG void __init(unsigned long long __v, false_type) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __init(unsigned long long __v, true_type) _NOEXCEPT; #endif // _LIBCPP_CXX03_LANG unsigned long to_ulong(false_type) const; _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong(true_type) const; unsigned long long to_ullong(false_type) const; _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong(true_type) const; _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong(true_type, false_type) const; unsigned long long to_ullong(true_type, true_type) const; }; template inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT #ifndef _LIBCPP_CXX03_LANG : __first_{0} #endif { #ifdef _LIBCPP_CXX03_LANG _VSTD::fill_n(__first_, _N_words, __storage_type(0)); #endif } #ifdef _LIBCPP_CXX03_LANG template void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; - for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) - __t[__i] = static_cast<__storage_type>(__v); + size_t __sz = _Size; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) + if ( __sz < __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; + else + __t[__i] = static_cast<__storage_type>(__v); + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); } template inline _LIBCPP_INLINE_VISIBILITY void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { __first_[0] = __v; + if (_Size < __bits_per_word) + __first_[0] &= ( 1ULL << _Size ) - 1; + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); } #endif // _LIBCPP_CXX03_LANG template inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT #ifndef _LIBCPP_CXX03_LANG #if __SIZEOF_SIZE_T__ == 8 : __first_{__v} #elif __SIZEOF_SIZE_T__ == 4 - : __first_{static_cast<__storage_type>(__v), static_cast<__storage_type>(__v >> __bits_per_word)} + : __first_{static_cast<__storage_type>(__v), + _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) + : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} #else #error This constructor has not been ported to this platform #endif #endif { #ifdef _LIBCPP_CXX03_LANG __init(__v, integral_constant()); #endif } template inline void __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { for (size_type __i = 0; __i < _N_words; ++__i) __first_[__i] &= __v.__first_[__i]; } template inline void __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { for (size_type __i = 0; __i < _N_words; ++__i) __first_[__i] |= __v.__first_[__i]; } template inline void __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { for (size_type __i = 0; __i < _N_words; ++__i) __first_[__i] ^= __v.__first_[__i]; } template void __bitset<_N_words, _Size>::flip() _NOEXCEPT { // do middle whole words size_type __n = _Size; __storage_pointer __p = __first_; 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 unsigned long __bitset<_N_words, _Size>::to_ulong(false_type) const { const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); if (__i != __e) __throw_overflow_error("bitset to_ulong overflow error"); return __first_[0]; } template inline unsigned long __bitset<_N_words, _Size>::to_ulong(true_type) const { return __first_[0]; } template unsigned long long __bitset<_N_words, _Size>::to_ullong(false_type) const { const_iterator __e = __make_iter(_Size); const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); if (__i != __e) __throw_overflow_error("bitset to_ullong overflow error"); return to_ullong(true_type()); } template inline unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type) const { return to_ullong(true_type(), integral_constant()); } template inline unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const { return __first_[0]; } template unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const { unsigned long long __r = __first_[0]; for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) __r |= static_cast(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); return __r; } template bool __bitset<_N_words, _Size>::all() const _NOEXCEPT { // do middle whole words size_type __n = _Size; __const_storage_pointer __p = __first_; for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) if (~*__p) return false; // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); if (~*__p & __m) return false; } return true; } template bool __bitset<_N_words, _Size>::any() const _NOEXCEPT { // do middle whole words size_type __n = _Size; __const_storage_pointer __p = __first_; for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) if (*__p) return true; // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); if (*__p & __m) return true; } return false; } template inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT { size_t __h = 0; for (size_type __i = 0; __i < _N_words; ++__i) __h ^= __first_[__i]; return __h; } template class __bitset<1, _Size> { public: typedef ptrdiff_t difference_type; typedef size_t size_type; typedef size_type __storage_type; protected: typedef __bitset __self; typedef __storage_type* __storage_pointer; typedef const __storage_type* __const_storage_pointer; static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); friend class __bit_reference<__bitset>; friend class __bit_const_reference<__bitset>; friend class __bit_iterator<__bitset, false>; friend class __bit_iterator<__bitset, true>; friend struct __bit_array<__bitset>; __storage_type __first_; typedef __bit_reference<__bitset> reference; typedef __bit_const_reference<__bitset> const_reference; typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT {return reference(&__first_, __storage_type(1) << __pos);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {return const_reference(&__first_, __storage_type(1) << __pos);} _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset& __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const; _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const; _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT; }; template inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) { } template inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT - : __first_(static_cast<__storage_type>(__v)) + : __first_( + _Size == __bits_per_word ? static_cast<__storage_type>(__v) + : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) + ) { } template inline void __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { __first_ &= __v.__first_; } template inline void __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { __first_ |= __v.__first_; } template inline void __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { __first_ ^= __v.__first_; } template inline void __bitset<1, _Size>::flip() _NOEXCEPT { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); __first_ = ~__first_; __first_ &= __m; } template inline unsigned long __bitset<1, _Size>::to_ulong() const { return __first_; } template inline unsigned long long __bitset<1, _Size>::to_ullong() const { return __first_; } template inline bool __bitset<1, _Size>::all() const _NOEXCEPT { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); return !(~__first_ & __m); } template inline bool __bitset<1, _Size>::any() const _NOEXCEPT { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); return __first_ & __m; } template inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT { return __first_; } template <> class __bitset<0, 0> { public: typedef ptrdiff_t difference_type; typedef size_t size_type; typedef size_type __storage_type; protected: typedef __bitset __self; typedef __storage_type* __storage_pointer; typedef const __storage_type* __const_storage_pointer; static const unsigned __bits_per_word = static_cast(sizeof(__storage_type) * CHAR_BIT); friend class __bit_reference<__bitset>; friend class __bit_const_reference<__bitset>; friend class __bit_iterator<__bitset, false>; friend class __bit_iterator<__bitset, true>; friend struct __bit_array<__bitset>; typedef __bit_reference<__bitset> reference; typedef __bit_const_reference<__bitset> const_reference; typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT {return reference(0, 1);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {return const_reference(0, 1);} _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT {return iterator(0, 0);} _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT {return const_iterator(0, 0);} _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} }; inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT { } inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT { } template class _LIBCPP_TEMPLATE_VIS bitset; template struct hash >; template class _LIBCPP_TEMPLATE_VIS bitset : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> { public: static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; typedef __bitset<__n_words, _Size> base; public: typedef typename base::reference reference; typedef typename base::const_reference const_reference; // 23.3.5.1 constructors: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} template explicit bitset(const _CharT* __str, typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); template explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = (basic_string<_CharT,_Traits,_Allocator>::npos), _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); // 23.3.5.2 bitset operations: _LIBCPP_INLINE_VISIBILITY bitset& operator&=(const bitset& __rhs) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bitset& operator|=(const bitset& __rhs) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bitset& operator^=(const bitset& __rhs) _NOEXCEPT; bitset& operator<<=(size_t __pos) _NOEXCEPT; bitset& operator>>=(size_t __pos) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bitset& set() _NOEXCEPT; bitset& set(size_t __pos, bool __val = true); _LIBCPP_INLINE_VISIBILITY bitset& reset() _NOEXCEPT; bitset& reset(size_t __pos); _LIBCPP_INLINE_VISIBILITY bitset operator~() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bitset& flip() _NOEXCEPT; bitset& flip(size_t __pos); // element access: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);} _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const; _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const; template basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; template _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; template _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; _LIBCPP_INLINE_VISIBILITY basic_string, allocator > to_string(char __zero = '0', char __one = '1') const; _LIBCPP_INLINE_VISIBILITY size_t count() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY bool operator==(const bitset& __rhs) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool operator!=(const bitset& __rhs) const _NOEXCEPT; bool test(size_t __pos) const; _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} _LIBCPP_INLINE_VISIBILITY bitset operator<<(size_t __pos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bitset operator>>(size_t __pos) const _NOEXCEPT; private: _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} friend struct hash; }; template template bitset<_Size>::bitset(const _CharT* __str, typename basic_string<_CharT>::size_type __n, _CharT __zero, _CharT __one) { size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); for (size_t __i = 0; __i < __rlen; ++__i) if (__str[__i] != __zero && __str[__i] != __one) __throw_invalid_argument("bitset string ctor has invalid argument"); size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) { _CharT __c = __str[_Mp - 1 - __i]; if (__c == __zero) (*this)[__i] = false; else (*this)[__i] = true; } _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); } template template bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, _CharT __zero, _CharT __one) { if (__pos > __str.size()) __throw_out_of_range("bitset string pos out of range"); size_t __rlen = _VSTD::min(__n, __str.size() - __pos); for (size_t __i = __pos; __i < __pos + __rlen; ++__i) if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) __throw_invalid_argument("bitset string ctor has invalid argument"); size_t _Mp = _VSTD::min(__rlen, _Size); size_t __i = 0; for (; __i < _Mp; ++__i) { _CharT __c = __str[__pos + _Mp - 1 - __i]; if (_Traits::eq(__c, __zero)) (*this)[__i] = false; else (*this)[__i] = true; } _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); } template inline bitset<_Size>& bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT { base::operator&=(__rhs); return *this; } template inline bitset<_Size>& bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT { base::operator|=(__rhs); return *this; } template inline bitset<_Size>& bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT { base::operator^=(__rhs); return *this; } template bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT { __pos = _VSTD::min(__pos, _Size); _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); _VSTD::fill_n(base::__make_iter(0), __pos, false); return *this; } template bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT { __pos = _VSTD::min(__pos, _Size); _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); return *this; } template inline bitset<_Size>& bitset<_Size>::set() _NOEXCEPT { _VSTD::fill_n(base::__make_iter(0), _Size, true); return *this; } template bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) { if (__pos >= _Size) __throw_out_of_range("bitset set argument out of range"); (*this)[__pos] = __val; return *this; } template inline bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT { _VSTD::fill_n(base::__make_iter(0), _Size, false); return *this; } template bitset<_Size>& bitset<_Size>::reset(size_t __pos) { if (__pos >= _Size) __throw_out_of_range("bitset reset argument out of range"); (*this)[__pos] = false; return *this; } template inline bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT { bitset __x(*this); __x.flip(); return __x; } template inline bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT { base::flip(); return *this; } template bitset<_Size>& bitset<_Size>::flip(size_t __pos) { if (__pos >= _Size) __throw_out_of_range("bitset flip argument out of range"); reference r = base::__make_ref(__pos); r = ~r; return *this; } template inline unsigned long bitset<_Size>::to_ulong() const { return base::to_ulong(); } template inline unsigned long long bitset<_Size>::to_ullong() const { return base::to_ullong(); } template template basic_string<_CharT, _Traits, _Allocator> bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); for (size_t __i = 0; __i < _Size; ++__i) { if ((*this)[__i]) __r[_Size - 1 - __i] = __one; } return __r; } template template inline basic_string<_CharT, _Traits, allocator<_CharT> > bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); } template template inline basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); } template inline basic_string, allocator > bitset<_Size>::to_string(char __zero, char __one) const { return to_string, allocator >(__zero, __one); } template inline size_t bitset<_Size>::count() const _NOEXCEPT { return static_cast(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true)); } template inline bool bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT { return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); } template inline bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT { return !(*this == __rhs); } template bool bitset<_Size>::test(size_t __pos) const { if (__pos >= _Size) __throw_out_of_range("bitset test argument out of range"); return (*this)[__pos]; } template inline bool bitset<_Size>::all() const _NOEXCEPT { return base::all(); } template inline bool bitset<_Size>::any() const _NOEXCEPT { return base::any(); } template inline bitset<_Size> bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT { bitset __r = *this; __r <<= __pos; return __r; } template inline bitset<_Size> bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT { bitset __r = *this; __r >>= __pos; return __r; } template inline _LIBCPP_INLINE_VISIBILITY bitset<_Size> operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { bitset<_Size> __r = __x; __r &= __y; return __r; } template inline _LIBCPP_INLINE_VISIBILITY bitset<_Size> operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { bitset<_Size> __r = __x; __r |= __y; return __r; } template inline _LIBCPP_INLINE_VISIBILITY bitset<_Size> operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { bitset<_Size> __r = __x; __r ^= __y; return __r; } template struct _LIBCPP_TEMPLATE_VIS hash > : public unary_function, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT {return __bs.__hash_code();} }; template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_BITSET Index: projects/clang600-import/contrib/libc++/include/chrono =================================================================== --- projects/clang600-import/contrib/libc++/include/chrono (revision 327038) +++ projects/clang600-import/contrib/libc++/include/chrono (revision 327039) @@ -1,1167 +1,1167 @@ // -*- C++ -*- //===---------------------------- chrono ----------------------------------===// // // 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_CHRONO #define _LIBCPP_CHRONO /* chrono synopsis namespace std { namespace chrono { template constexpr ToDuration duration_cast(const duration& fd); template struct treat_as_floating_point : is_floating_point {}; template constexpr bool treat_as_floating_point_v = treat_as_floating_point::value; // C++17 template struct duration_values { public: static constexpr Rep zero(); static constexpr Rep max(); static constexpr Rep min(); }; // duration template > class duration { static_assert(!__is_duration::value, "A duration representation can not be a duration"); static_assert(__is_ratio::value, "Second template parameter of duration must be a std::ratio"); static_assert(Period::num > 0, "duration period must be positive"); public: typedef Rep rep; typedef typename _Period::type period; constexpr duration() = default; template constexpr explicit duration(const Rep2& r, typename enable_if < is_convertible::value && (treat_as_floating_point::value || !treat_as_floating_point::value && !treat_as_floating_point::value) >::type* = 0); // conversions template constexpr duration(const duration& d, typename enable_if < treat_as_floating_point::value || ratio_divide::type::den == 1 >::type* = 0); // observer constexpr rep count() const; // arithmetic constexpr common_type::type operator+() const; constexpr common_type::type operator-() const; constexpr duration& operator++(); constexpr duration operator++(int); constexpr duration& operator--(); constexpr duration operator--(int); constexpr duration& operator+=(const duration& d); constexpr duration& operator-=(const duration& d); duration& operator*=(const rep& rhs); duration& operator/=(const rep& rhs); // special values static constexpr duration zero(); static constexpr duration min(); static constexpr duration max(); }; typedef duration nanoseconds; typedef duration microseconds; typedef duration milliseconds; typedef duration seconds; typedef duration< long, ratio< 60> > minutes; typedef duration< long, ratio<3600> > hours; template class time_point { public: typedef Clock clock; typedef Duration duration; typedef typename duration::rep rep; typedef typename duration::period period; private: duration d_; // exposition only public: time_point(); // has value "epoch" // constexpr in C++14 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 // conversions template time_point(const time_point& t); // constexpr in C++14 // observer duration time_since_epoch() const; // constexpr in C++14 // arithmetic time_point& operator+=(const duration& d); time_point& operator-=(const duration& d); // special values static constexpr time_point min(); static constexpr time_point max(); }; } // chrono // common_type traits template struct common_type, chrono::duration>; template struct common_type, chrono::time_point>; namespace chrono { // duration arithmetic template constexpr typename common_type, duration>::type operator+(const duration& lhs, const duration& rhs); template constexpr typename common_type, duration>::type operator-(const duration& lhs, const duration& rhs); template constexpr duration::type, Period> operator*(const duration& d, const Rep2& s); template constexpr duration::type, Period> operator*(const Rep1& s, const duration& d); template constexpr duration::type, Period> operator/(const duration& d, const Rep2& s); template constexpr typename common_type::type operator/(const duration& lhs, const duration& rhs); // duration comparisons template constexpr bool operator==(const duration& lhs, const duration& rhs); template constexpr bool operator!=(const duration& lhs, const duration& rhs); template constexpr bool operator< (const duration& lhs, const duration& rhs); template constexpr bool operator<=(const duration& lhs, const duration& rhs); template constexpr bool operator> (const duration& lhs, const duration& rhs); template constexpr bool operator>=(const duration& lhs, const duration& rhs); // duration_cast template ToDuration duration_cast(const duration& d); template constexpr ToDuration floor(const duration& d); // C++17 template constexpr ToDuration ceil(const duration& d); // C++17 template constexpr ToDuration round(const duration& d); // C++17 // time_point arithmetic (all constexpr in C++14) template time_point>::type> operator+(const time_point& lhs, const duration& rhs); template time_point, Duration2>::type> operator+(const duration& lhs, const time_point& rhs); template time_point>::type> operator-(const time_point& lhs, const duration& rhs); template typename common_type::type operator-(const time_point& lhs, const time_point& rhs); // time_point comparisons (all constexpr in C++14) template bool operator==(const time_point& lhs, const time_point& rhs); template bool operator!=(const time_point& lhs, const time_point& rhs); template bool operator< (const time_point& lhs, const time_point& rhs); template bool operator<=(const time_point& lhs, const time_point& rhs); template bool operator> (const time_point& lhs, const time_point& rhs); template bool operator>=(const time_point& lhs, const time_point& rhs); // time_point_cast (constexpr in C++14) template time_point time_point_cast(const time_point& t); template constexpr time_point floor(const time_point& tp); // C++17 template constexpr time_point ceil(const time_point& tp); // C++17 template constexpr time_point round(const time_point& tp); // C++17 template constexpr duration abs(duration d); // C++17 // Clocks class system_clock { public: typedef microseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static const bool is_steady = false; // constexpr in C++14 static time_point now() noexcept; static time_t to_time_t (const time_point& __t) noexcept; static time_point from_time_t(time_t __t) noexcept; }; class steady_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static const bool is_steady = true; // constexpr in C++14 static time_point now() noexcept; }; typedef steady_clock high_resolution_clock; } // chrono -constexpr chrono::hours operator "" h(unsigned long long); // C++14 -constexpr chrono::duration> operator "" h(long double); // C++14 -constexpr chrono::minutes operator "" min(unsigned long long); // C++14 -constexpr chrono::duration> operator "" min(long double); // C++14 -constexpr chrono::seconds operator "" s(unsigned long long); // C++14 -constexpr chrono::duration operator "" s(long double); // C++14 -constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14 -constexpr chrono::duration operator "" ms(long double); // C++14 -constexpr chrono::microseconds operator "" us(unsigned long long); // C++14 -constexpr chrono::duration operator "" us(long double); // C++14 -constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14 -constexpr chrono::duration operator "" ns(long double); // C++14 +constexpr chrono::hours operator ""h(unsigned long long); // C++14 +constexpr chrono::duration> operator ""h(long double); // C++14 +constexpr chrono::minutes operator ""min(unsigned long long); // C++14 +constexpr chrono::duration> operator ""min(long double); // C++14 +constexpr chrono::seconds operator ""s(unsigned long long); // C++14 +constexpr chrono::duration operator ""s(long double); // C++14 +constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 +constexpr chrono::duration operator ""ms(long double); // C++14 +constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 +constexpr chrono::duration operator ""us(long double); // C++14 +constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 +constexpr chrono::duration operator ""ns(long double); // C++14 } // std */ #include <__config> #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { template > class _LIBCPP_TEMPLATE_VIS duration; template struct __is_duration : false_type {}; template struct __is_duration > : true_type {}; template struct __is_duration > : true_type {}; template struct __is_duration > : true_type {}; template struct __is_duration > : true_type {}; } // chrono template struct _LIBCPP_TEMPLATE_VIS common_type, chrono::duration<_Rep2, _Period2> > { typedef chrono::duration::type, typename __ratio_gcd<_Period1, _Period2>::type> type; }; namespace chrono { // duration_cast template ::type, bool = _Period::num == 1, bool = _Period::den == 1> struct __duration_cast; template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { return _ToDuration(static_cast(__fd.count())); } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; return _ToDuration(static_cast( static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; return _ToDuration(static_cast( static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const { typedef typename common_type::type _Ct; return _ToDuration(static_cast( static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den))); } }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, _ToDuration >::type duration_cast(const duration<_Rep, _Period>& __fd) { return __duration_cast, _ToDuration>()(__fd); } template struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template _LIBCPP_CONSTEXPR bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value; #endif template struct _LIBCPP_TEMPLATE_VIS duration_values { public: _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() {return _Rep(0);} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() {return numeric_limits<_Rep>::max();} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} }; #if _LIBCPP_STD_VER > 14 template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, _ToDuration >::type floor(const duration<_Rep, _Period>& __d) { _ToDuration __t = duration_cast<_ToDuration>(__d); if (__t > __d) __t = __t - _ToDuration{1}; return __t; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, _ToDuration >::type ceil(const duration<_Rep, _Period>& __d) { _ToDuration __t = duration_cast<_ToDuration>(__d); if (__t < __d) __t = __t + _ToDuration{1}; return __t; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, _ToDuration >::type round(const duration<_Rep, _Period>& __d) { _ToDuration __lower = floor<_ToDuration>(__d); _ToDuration __upper = __lower + _ToDuration{1}; auto __lowerDiff = __d - __lower; auto __upperDiff = __upper - __d; if (__lowerDiff < __upperDiff) return __lower; if (__lowerDiff > __upperDiff) return __upper; return __lower.count() & 1 ? __upper : __lower; } #endif // duration template class _LIBCPP_TEMPLATE_VIS duration { static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); static_assert(_Period::num > 0, "duration period must be positive"); template struct __no_overflow { private: static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; static const intmax_t __n1 = _R1::num / __gcd_n1_n2; static const intmax_t __d1 = _R1::den / __gcd_d1_d2; static const intmax_t __n2 = _R2::num / __gcd_n1_n2; static const intmax_t __d2 = _R2::den / __gcd_d1_d2; static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); template struct __mul // __overflow == false { static const intmax_t value = _Xp * _Yp; }; template struct __mul<_Xp, _Yp, true> { static const intmax_t value = 1; }; public: static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type; }; public: typedef _Rep rep; typedef typename _Period::type period; private: rep __rep_; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR #ifndef _LIBCPP_CXX03_LANG duration() = default; #else duration() {} #endif template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r, typename enable_if < is_convertible<_Rep2, rep>::value && (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value) >::type* = 0) : __rep_(__r) {} // conversions template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR duration(const duration<_Rep2, _Period2>& __d, typename enable_if < __no_overflow<_Period2, period>::value && ( treat_as_floating_point::value || (__no_overflow<_Period2, period>::type::den == 1 && !treat_as_floating_point<_Rep2>::value)) >::type* = 0) : __rep_(_VSTD::chrono::duration_cast(__d).count()) {} // observer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} // arithmetic _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator+() const {return typename common_type::type(*this);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type::type operator-() const {return typename common_type::type(-__rep_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} // special values _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() {return duration(duration_values::zero());} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() {return duration(duration_values::min());} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() {return duration(duration_values::max());} }; typedef duration nanoseconds; typedef duration microseconds; typedef duration milliseconds; typedef duration seconds; typedef duration< long, ratio< 60> > minutes; typedef duration< long, ratio<3600> > hours; // Duration == template struct __duration_eq { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; return _Ct(__lhs).count() == _Ct(__rhs).count(); } }; template struct __duration_eq<_LhsDuration, _LhsDuration> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {return __lhs.count() == __rhs.count();} }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); } // Duration != template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return !(__lhs == __rhs); } // Duration < template struct __duration_lt { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const { typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; return _Ct(__lhs).count() < _Ct(__rhs).count(); } }; template struct __duration_lt<_LhsDuration, _LhsDuration> { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {return __lhs.count() < __rhs.count();} }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); } // Duration > template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return __rhs < __lhs; } // Duration <= template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return !(__rhs < __lhs); } // Duration >= template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { return !(__lhs < __rhs); } // Duration + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); } // Duration - template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); } // Duration * template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, duration::type, _Period> >::type operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; typedef duration<_Cr, _Period> _Cd; return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, duration::type, _Period> >::type operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { return __d * __s; } // Duration / template ::value> struct __duration_divide_result { }; template ::type>::value> struct __duration_divide_imp { }; template struct __duration_divide_imp, _Rep2, true> { typedef duration::type, _Period> type; }; template struct __duration_divide_result, _Rep2, false> : __duration_divide_imp, _Rep2> { }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename __duration_divide_result, _Rep2>::type operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; typedef duration<_Cr, _Period> _Cd; return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<_Rep1, _Rep2>::type operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef typename common_type, duration<_Rep2, _Period2> >::type _Ct; return _Ct(__lhs).count() / _Ct(__rhs).count(); } // Duration % template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename __duration_divide_result, _Rep2>::type operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; typedef duration<_Cr, _Period> _Cd; return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type, duration<_Rep2, _Period2> >::type operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); } ////////////////////////////////////////////////////////// ///////////////////// time_point ///////////////////////// ////////////////////////////////////////////////////////// template class _LIBCPP_TEMPLATE_VIS time_point { static_assert(__is_duration<_Duration>::value, "Second template parameter of time_point must be a std::chrono::duration"); public: typedef _Clock clock; typedef _Duration duration; typedef typename duration::rep rep; typedef typename duration::period period; private: duration __d_; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} // conversions template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point(const time_point& t, typename enable_if < is_convertible<_Duration2, duration>::value >::type* = 0) : __d_(t.time_since_epoch()) {} // observer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} // arithmetic _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} // special values _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() {return time_point(duration::min());} _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() {return time_point(duration::max());} }; } // chrono template struct _LIBCPP_TEMPLATE_VIS common_type, chrono::time_point<_Clock, _Duration2> > { typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; }; namespace chrono { template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, _ToDuration> time_point_cast(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); } #if _LIBCPP_STD_VER > 14 template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, time_point<_Clock, _ToDuration> >::type floor(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, time_point<_Clock, _ToDuration> >::type ceil(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < __is_duration<_ToDuration>::value, time_point<_Clock, _ToDuration> >::type round(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename enable_if < numeric_limits<_Rep>::is_signed, duration<_Rep, _Period> >::type abs(duration<_Rep, _Period> __d) { return __d >= __d.zero() ? __d : -__d; } #endif // time_point == template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } // time_point != template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return !(__lhs == __rhs); } // time_point < template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } // time_point > template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return __rhs < __lhs; } // time_point <= template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return !(__rhs < __lhs); } // time_point >= template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return !(__lhs < __rhs); } // time_point operator+(time_point x, duration y); template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; return _Tr (__lhs.time_since_epoch() + __rhs); } // time_point operator+(duration x, time_point y); template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type, _Duration2>::type> operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return __rhs + __lhs; } // time_point operator-(time_point x, duration y); template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; return _Ret(__lhs.time_since_epoch() -__rhs); } // duration operator-(time_point x, time_point y); template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename common_type<_Duration1, _Duration2>::type operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } ////////////////////////////////////////////////////////// /////////////////////// clocks /////////////////////////// ////////////////////////////////////////////////////////// class _LIBCPP_TYPE_VIS system_clock { public: typedef microseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; static time_point now() _NOEXCEPT; static time_t to_time_t (const time_point& __t) _NOEXCEPT; static time_point from_time_t(time_t __t) _NOEXCEPT; }; #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK class _LIBCPP_TYPE_VIS steady_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; static time_point now() _NOEXCEPT; }; typedef steady_clock high_resolution_clock; #else typedef system_clock high_resolution_clock; #endif } // chrono #if _LIBCPP_STD_VER > 11 // Suffixes for duration literals [time.duration.literals] inline namespace literals { inline namespace chrono_literals { - constexpr chrono::hours operator"" h(unsigned long long __h) + constexpr chrono::hours operator""h(unsigned long long __h) { return chrono::hours(static_cast(__h)); } - constexpr chrono::duration> operator"" h(long double __h) + constexpr chrono::duration> operator""h(long double __h) { return chrono::duration>(__h); } - constexpr chrono::minutes operator"" min(unsigned long long __m) + constexpr chrono::minutes operator""min(unsigned long long __m) { return chrono::minutes(static_cast(__m)); } - constexpr chrono::duration> operator"" min(long double __m) + constexpr chrono::duration> operator""min(long double __m) { return chrono::duration> (__m); } - constexpr chrono::seconds operator"" s(unsigned long long __s) + constexpr chrono::seconds operator""s(unsigned long long __s) { return chrono::seconds(static_cast(__s)); } - constexpr chrono::duration operator"" s(long double __s) + constexpr chrono::duration operator""s(long double __s) { return chrono::duration (__s); } - constexpr chrono::milliseconds operator"" ms(unsigned long long __ms) + constexpr chrono::milliseconds operator""ms(unsigned long long __ms) { return chrono::milliseconds(static_cast(__ms)); } - constexpr chrono::duration operator"" ms(long double __ms) + constexpr chrono::duration operator""ms(long double __ms) { return chrono::duration(__ms); } - constexpr chrono::microseconds operator"" us(unsigned long long __us) + constexpr chrono::microseconds operator""us(unsigned long long __us) { return chrono::microseconds(static_cast(__us)); } - constexpr chrono::duration operator"" us(long double __us) + constexpr chrono::duration operator""us(long double __us) { return chrono::duration (__us); } - constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns) + constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) { return chrono::nanoseconds(static_cast(__ns)); } - constexpr chrono::duration operator"" ns(long double __ns) + constexpr chrono::duration operator""ns(long double __ns) { return chrono::duration (__ns); } }} namespace chrono { // hoist the literals into namespace std::chrono using namespace literals::chrono_literals; } #endif _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_CHRONO Index: projects/clang600-import/contrib/libc++/include/cstddef =================================================================== --- projects/clang600-import/contrib/libc++/include/cstddef (revision 327038) +++ projects/clang600-import/contrib/libc++/include/cstddef (revision 327039) @@ -1,90 +1,113 @@ // -*- C++ -*- //===--------------------------- cstddef ----------------------------------===// // // 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_CSTDDEF #define _LIBCPP_CSTDDEF /* cstddef synopsis Macros: offsetof(type,member-designator) NULL namespace std { Types: ptrdiff_t size_t max_align_t nullptr_t byte // C++17 } // std */ #include <__config> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif // Don't include our own ; we don't want to declare ::nullptr_t. #include_next #include <__nullptr> _LIBCPP_BEGIN_NAMESPACE_STD using ::ptrdiff_t; using ::size_t; #if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \ defined(__DEFINED_max_align_t) // Re-use the compiler's max_align_t where possible. using ::max_align_t; #else typedef long double max_align_t; #endif _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 namespace std // purposefully not versioned { enum class byte : unsigned char {}; -constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) | static_cast(__rhs)); } constexpr byte operator| (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) | static_cast(__rhs)); } +{ + return static_cast( + static_cast( + static_cast(__lhs) | static_cast(__rhs) + )); +} -constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) & static_cast(__rhs)); } +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs | __rhs; } + constexpr byte operator& (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) & static_cast(__rhs)); } +{ + return static_cast( + static_cast( + static_cast(__lhs) & static_cast(__rhs) + )); +} -constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) ^ static_cast(__rhs)); } +constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs & __rhs; } + constexpr byte operator^ (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) ^ static_cast(__rhs)); } +{ + return static_cast( + static_cast( + static_cast(__lhs) ^ static_cast(__rhs) + )); +} +constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs ^ __rhs; } + constexpr byte operator~ (byte __b) noexcept -{ return byte(~static_cast(__b)); } +{ + return static_cast( + static_cast( + ~static_cast(__b) + )); +} } #include // rest of byte #endif #endif // _LIBCPP_CSTDDEF Index: projects/clang600-import/contrib/libc++/include/deque =================================================================== --- projects/clang600-import/contrib/libc++/include/deque (revision 327038) +++ projects/clang600-import/contrib/libc++/include/deque (revision 327039) @@ -1,2910 +1,2910 @@ // -*- C++ -*- //===---------------------------- deque -----------------------------------===// // // 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_DEQUE #define _LIBCPP_DEQUE /* deque synopsis namespace std { template > class deque { public: // types: 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; // construct/copy/destroy: deque() noexcept(is_nothrow_default_constructible::value); explicit deque(const allocator_type& a); explicit deque(size_type n); explicit deque(size_type n, const allocator_type& a); // C++14 deque(size_type n, const value_type& v); deque(size_type n, const value_type& v, const allocator_type& a); template deque(InputIterator f, InputIterator l); template deque(InputIterator f, InputIterator l, const allocator_type& a); deque(const deque& c); deque(deque&& c) noexcept(is_nothrow_move_constructible::value); deque(initializer_list il, const Allocator& a = allocator_type()); deque(const deque& c, const allocator_type& a); deque(deque&& c, const allocator_type& a); ~deque(); deque& operator=(const deque& c); deque& operator=(deque&& c) noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value); deque& operator=(initializer_list il); template void assign(InputIterator f, InputIterator l); void assign(size_type n, const value_type& v); void assign(initializer_list il); allocator_type get_allocator() const noexcept; // iterators: 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; // capacity: size_type size() const noexcept; size_type max_size() const noexcept; void resize(size_type n); void resize(size_type n, const value_type& v); void shrink_to_fit(); bool empty() const noexcept; // element access: reference operator[](size_type i); const_reference operator[](size_type i) const; reference at(size_type i); const_reference at(size_type i) const; reference front(); const_reference front() const; reference back(); const_reference back() const; // modifiers: void push_front(const value_type& v); void push_front(value_type&& v); void push_back(const value_type& v); void push_back(value_type&& v); template reference emplace_front(Args&&... args); // reference in C++17 template reference emplace_back(Args&&... args); // reference in C++17 template iterator emplace(const_iterator p, Args&&... args); iterator insert(const_iterator p, const value_type& v); iterator insert(const_iterator p, value_type&& v); iterator insert(const_iterator p, size_type n, const value_type& v); template iterator insert(const_iterator p, InputIterator f, InputIterator l); iterator insert(const_iterator p, initializer_list il); void pop_front(); void pop_back(); iterator erase(const_iterator p); iterator erase(const_iterator f, const_iterator l); void swap(deque& c) noexcept(allocator_traits::is_always_equal::value); // C++17 void clear() noexcept; }; template bool operator==(const deque& x, const deque& y); template bool operator< (const deque& x, const deque& y); template bool operator!=(const deque& x, const deque& y); template bool operator> (const deque& x, const deque& y); template bool operator>=(const deque& x, const deque& y); template bool operator<=(const deque& x, const deque& y); // specialized algorithms: template void swap(deque& x, deque& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include <__split_buffer> #include #include #include #include #include #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 __deque_base; template > class _LIBCPP_TEMPLATE_VIS deque; template class _LIBCPP_TEMPLATE_VIS __deque_iterator; template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); template _OutputIterator copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); template _OutputIterator copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); template _OutputIterator move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); template _OutputIterator move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template struct __deque_block_size { static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16; }; template ::value #endif > class _LIBCPP_TEMPLATE_VIS __deque_iterator { typedef _MapPointer __map_iterator; public: typedef _Pointer pointer; typedef _DiffType difference_type; private: __map_iterator __m_iter_; pointer __ptr_; static const difference_type __block_size; public: typedef _ValueType value_type; typedef random_access_iterator_tag iterator_category; typedef _Reference reference; _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __m_iter_(nullptr), __ptr_(nullptr) #endif {} template _LIBCPP_INLINE_VISIBILITY __deque_iterator(const __deque_iterator& __it, typename enable_if::value>::type* = 0) _NOEXCEPT : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() { if (++__ptr_ - *__m_iter_ == __block_size) { ++__m_iter_; __ptr_ = *__m_iter_; } return *this; } _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) { __deque_iterator __tmp = *this; ++(*this); return __tmp; } _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() { if (__ptr_ == *__m_iter_) { --__m_iter_; __ptr_ = *__m_iter_ + __block_size; } --__ptr_; return *this; } _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) { __deque_iterator __tmp = *this; --(*this); return __tmp; } _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) { if (__n != 0) { __n += __ptr_ - *__m_iter_; if (__n > 0) { __m_iter_ += __n / __block_size; __ptr_ = *__m_iter_ + __n % __block_size; } else // (__n < 0) { difference_type __z = __block_size - 1 - __n; __m_iter_ -= __z / __block_size; __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); } } return *this; } _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) { return *this += -__n; } _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const { __deque_iterator __t(*this); __t += __n; return __t; } _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const { __deque_iterator __t(*this); __t -= __n; return __t; } _LIBCPP_INLINE_VISIBILITY friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) {return __it + __n;} _LIBCPP_INLINE_VISIBILITY friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) { if (__x != __y) return (__x.__m_iter_ - __y.__m_iter_) * __block_size + (__x.__ptr_ - *__x.__m_iter_) - (__y.__ptr_ - *__y.__m_iter_); return 0; } _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);} _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {return !(__x == __y);} _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) {return __x.__m_iter_ < __y.__m_iter_ || (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) {return __y < __x;} _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) {return !(__y < __x);} _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) {return !(__x < __y);} private: _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT : __m_iter_(__m), __ptr_(__p) {} template friend class __deque_base; template friend class _LIBCPP_TEMPLATE_VIS deque; template friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); template friend _OutputIterator copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); template friend _OutputIterator copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); template friend _OutputIterator move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); template friend _OutputIterator move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r); template friend __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); }; template const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>::__block_size = __deque_block_size<_ValueType, _DiffType>::value; // copy template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; if (__n > __bs) { __n = __bs; __m = __f + __n; } _VSTD::copy(__f, __m, __rb); __f = __m; __r += __n; } return __r; } template _OutputIterator copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } __r = _VSTD::copy(__fb, __fe, __r); __n -= __bs; __f += __bs; } return __r; } template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } __r = _VSTD::copy(__fb, __fe, __r); __n -= __bs; __f += __bs; } return __r; } // copy_backward template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; while (__f != __l) { __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); pointer __rb = *__rp.__m_iter_; pointer __re = __rp.__ptr_ + 1; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __f; if (__n > __bs) { __n = __bs; __m = __l - __n; } _VSTD::copy_backward(__m, __l, __re); __l = __m; __r -= __n; } return __r; } template _OutputIterator copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } __r = _VSTD::copy_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; } return __r; } template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } __r = _VSTD::copy_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; } return __r; } // move template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; if (__n > __bs) { __n = __bs; __m = __f + __n; } _VSTD::move(__f, __m, __rb); __f = __m; __r += __n; } return __r; } template _OutputIterator move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } __r = _VSTD::move(__fb, __fe, __r); __n -= __bs; __f += __bs; } return __r; } template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } __r = _VSTD::move(__fb, __fe, __r); __n -= __bs; __f += __bs; } return __r; } // move_backward template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(_RAIter __f, _RAIter __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; while (__f != __l) { __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); pointer __rb = *__rp.__m_iter_; pointer __re = __rp.__ptr_ + 1; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __f; if (__n > __bs) { __n = __bs; __m = __l - __n; } _VSTD::move_backward(__m, __l, __re); __l = __m; __r -= __n; } return __r; } template _OutputIterator move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, _OutputIterator __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } __r = _VSTD::move_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; } return __r; } template __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } __r = _VSTD::move_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; } return __r; } template class __deque_base_common { protected: _LIBCPP_NORETURN void __throw_length_error() const; _LIBCPP_NORETURN void __throw_out_of_range() const; }; template void __deque_base_common<__b>::__throw_length_error() const { _VSTD::__throw_length_error("deque"); } template void __deque_base_common<__b>::__throw_out_of_range() const { _VSTD::__throw_out_of_range("deque"); } template class __deque_base : protected __deque_base_common { __deque_base(const __deque_base& __c); __deque_base& operator=(const __deque_base& __c); 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; static const difference_type __block_size; typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; typedef allocator_traits<__pointer_allocator> __map_traits; typedef typename __map_traits::pointer __map_pointer; typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; typedef __split_buffer __map; typedef __deque_iterator iterator; typedef __deque_iterator const_iterator; __map __map_; size_type __start_; __compressed_pair __size_; iterator begin() _NOEXCEPT; const_iterator begin() const _NOEXCEPT; iterator end() _NOEXCEPT; const_iterator end() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} _LIBCPP_INLINE_VISIBILITY const size_type& size() const _NOEXCEPT {return __size_.first();} _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} _LIBCPP_INLINE_VISIBILITY __deque_base() _NOEXCEPT_(is_nothrow_default_constructible::value); _LIBCPP_INLINE_VISIBILITY explicit __deque_base(const allocator_type& __a); public: ~__deque_base(); #ifndef _LIBCPP_CXX03_LANG __deque_base(__deque_base&& __c) _NOEXCEPT_(is_nothrow_move_constructible::value); __deque_base(__deque_base&& __c, const allocator_type& __a); #endif // _LIBCPP_CXX03_LANG void swap(__deque_base& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value); #endif protected: void clear() _NOEXCEPT; bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __move_assign(__deque_base& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value) { __map_ = _VSTD::move(__c.__map_); __start_ = __c.__start_; size() = __c.size(); __move_assign_alloc(__c); __c.__start_ = __c.size() = 0; } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__deque_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 __move_assign_alloc(__deque_base& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { __alloc() = _VSTD::move(__c.__alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT {} }; template const typename __deque_base<_Tp, _Allocator>::difference_type __deque_base<_Tp, _Allocator>::__block_size = __deque_block_size::value; template bool __deque_base<_Tp, _Allocator>::__invariants() const { if (!__map_.__invariants()) return false; if (__map_.size() >= size_type(-1) / __block_size) return false; for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); __i != __e; ++__i) if (*__i == nullptr) return false; if (__map_.size() != 0) { if (size() >= __map_.size() * __block_size) return false; if (__start_ >= __map_.size() * __block_size - size()) return false; } else { if (size() != 0) return false; if (__start_ != 0) return false; } return true; } template typename __deque_base<_Tp, _Allocator>::iterator __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT { __map_pointer __mp = __map_.begin() + __start_ / __block_size; return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); } template typename __deque_base<_Tp, _Allocator>::const_iterator __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT { __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); } template typename __deque_base<_Tp, _Allocator>::iterator __deque_base<_Tp, _Allocator>::end() _NOEXCEPT { size_type __p = size() + __start_; __map_pointer __mp = __map_.begin() + __p / __block_size; return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); } template typename __deque_base<_Tp, _Allocator>::const_iterator __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT { size_type __p = size() + __start_; __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); } template inline __deque_base<_Tp, _Allocator>::__deque_base() _NOEXCEPT_(is_nothrow_default_constructible::value) : __start_(0), __size_(0) {} template inline __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} template __deque_base<_Tp, _Allocator>::~__deque_base() { clear(); typename __map::iterator __i = __map_.begin(); typename __map::iterator __e = __map_.end(); for (; __i != __e; ++__i) __alloc_traits::deallocate(__alloc(), *__i, __block_size); } #ifndef _LIBCPP_CXX03_LANG template __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) _NOEXCEPT_(is_nothrow_move_constructible::value) : __map_(_VSTD::move(__c.__map_)), __start_(_VSTD::move(__c.__start_)), __size_(_VSTD::move(__c.__size_)) { __c.__start_ = 0; __c.size() = 0; } template __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), __start_(_VSTD::move(__c.__start_)), __size_(_VSTD::move(__c.size()), __a) { if (__a == __c.__alloc()) { __c.__start_ = 0; __c.size() = 0; } else { __map_.clear(); __start_ = 0; size() = 0; } } #endif // _LIBCPP_CXX03_LANG template void __deque_base<_Tp, _Allocator>::swap(__deque_base& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value) #endif { __map_.swap(__c.__map_); _VSTD::swap(__start_, __c.__start_); _VSTD::swap(size(), __c.size()); __swap_allocator(__alloc(), __c.__alloc()); } template void __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT { allocator_type& __a = __alloc(); for (iterator __i = begin(), __e = end(); __i != __e; ++__i) __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); size() = 0; while (__map_.size() > 2) { __alloc_traits::deallocate(__a, __map_.front(), __block_size); __map_.pop_front(); } switch (__map_.size()) { case 1: __start_ = __block_size / 2; break; case 2: __start_ = __block_size; break; } } template */> class _LIBCPP_TEMPLATE_VIS deque : private __deque_base<_Tp, _Allocator> { public: // types: typedef _Tp value_type; typedef _Allocator allocator_type; static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); typedef __deque_base __base; typedef typename __base::__alloc_traits __alloc_traits; typedef typename __base::reference reference; typedef typename __base::const_reference const_reference; typedef typename __base::iterator iterator; typedef typename __base::const_iterator const_iterator; 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 _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY deque() _NOEXCEPT_(is_nothrow_default_constructible::value) {} _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} explicit deque(size_type __n); #if _LIBCPP_STD_VER > 11 explicit deque(size_type __n, const _Allocator& __a); #endif deque(size_type __n, const value_type& __v); deque(size_type __n, const value_type& __v, const allocator_type& __a); template deque(_InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); template deque(_InputIter __f, _InputIter __l, const allocator_type& __a, typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); deque(const deque& __c); deque(const deque& __c, const allocator_type& __a); deque& operator=(const deque& __c); #ifndef _LIBCPP_CXX03_LANG deque(initializer_list __il); deque(initializer_list __il, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY deque& operator=(initializer_list __il) {assign(__il); return *this;} _LIBCPP_INLINE_VISIBILITY deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); _LIBCPP_INLINE_VISIBILITY deque(deque&& __c, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY deque& operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value); _LIBCPP_INLINE_VISIBILITY void assign(initializer_list __il) {assign(__il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG template void assign(_InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value && !__is_random_access_iterator<_InputIter>::value>::type* = 0); template void assign(_RAIter __f, _RAIter __l, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); void assign(size_type __n, const value_type& __v); _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; // iterators: _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __base::begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __base::begin();} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __base::end();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __base::end();} _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(__base::end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(__base::end());} _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() _NOEXCEPT {return reverse_iterator(__base::begin());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(__base::begin());} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return __base::begin();} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return __base::end();} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const _NOEXCEPT {return const_reverse_iterator(__base::end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return const_reverse_iterator(__base::begin());} // capacity: _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __base::size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return std::min( __alloc_traits::max_size(__base::__alloc()), numeric_limits::max());} void resize(size_type __n); void resize(size_type __n, const value_type& __v); void shrink_to_fit() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __base::size() == 0;} // element access: _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __i); _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __i) const; _LIBCPP_INLINE_VISIBILITY reference at(size_type __i); _LIBCPP_INLINE_VISIBILITY const_reference at(size_type __i) const; _LIBCPP_INLINE_VISIBILITY reference front(); _LIBCPP_INLINE_VISIBILITY const_reference front() const; _LIBCPP_INLINE_VISIBILITY reference back(); _LIBCPP_INLINE_VISIBILITY const_reference back() const; // 23.2.2.3 modifiers: void push_front(const value_type& __v); void push_back(const value_type& __v); #ifndef _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 template reference emplace_front(_Args&&... __args); template reference emplace_back (_Args&&... __args); #else template void emplace_front(_Args&&... __args); template void emplace_back (_Args&&... __args); #endif template iterator emplace(const_iterator __p, _Args&&... __args); void push_front(value_type&& __v); void push_back(value_type&& __v); iterator insert(const_iterator __p, value_type&& __v); _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, initializer_list __il) {return insert(__p, __il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG iterator insert(const_iterator __p, const value_type& __v); iterator insert(const_iterator __p, size_type __n, const value_type& __v); template iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value &&!__is_forward_iterator<_InputIter>::value>::type* = 0); template iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); template iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); void pop_front(); void pop_back(); iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); _LIBCPP_INLINE_VISIBILITY void swap(deque& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value); #endif _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool __invariants() const {return __base::__invariants();} private: typedef typename __base::__map_const_pointer __map_const_pointer; _LIBCPP_INLINE_VISIBILITY static size_type __recommend_blocks(size_type __n) { return __n / __base::__block_size + (__n % __base::__block_size != 0); } _LIBCPP_INLINE_VISIBILITY size_type __capacity() const { return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; } _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const { return __base::__start_; } _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const { return __capacity() - (__base::__start_ + __base::size()); } template void __append(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value && !__is_forward_iterator<_InpIter>::value>::type* = 0); template void __append(_ForIter __f, _ForIter __l, typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); void __append(size_type __n); void __append(size_type __n, const value_type& __v); void __erase_to_end(const_iterator __f); void __add_front_capacity(); void __add_front_capacity(size_type __n); void __add_back_capacity(); void __add_back_capacity(size_type __n); iterator __move_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt); iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt); void __move_construct_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt); void __move_construct_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt); _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const deque& __c) {__copy_assign_alloc(__c, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const deque& __c, true_type) { if (__base::__alloc() != __c.__alloc()) { clear(); shrink_to_fit(); } __base::__alloc() = __c.__alloc(); __base::__map_.__alloc() = __c.__map_.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const deque&, false_type) {} void __move_assign(deque& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value); void __move_assign(deque& __c, false_type); }; template deque<_Tp, _Allocator>::deque(size_type __n) { if (__n > 0) __append(__n); } #if _LIBCPP_STD_VER > 11 template deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) : __base(__a) { if (__n > 0) __append(__n); } #endif template deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) { if (__n > 0) __append(__n, __v); } template deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) : __base(__a) { if (__n > 0) __append(__n, __v); } template template deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value>::type*) { __append(__f, __l); } template template deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, typename enable_if<__is_input_iterator<_InputIter>::value>::type*) : __base(__a) { __append(__f, __l); } template deque<_Tp, _Allocator>::deque(const deque& __c) : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) { __append(__c.begin(), __c.end()); } template deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) : __base(__a) { __append(__c.begin(), __c.end()); } template deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(const deque& __c) { if (this != &__c) { __copy_assign_alloc(__c); assign(__c.begin(), __c.end()); } return *this; } #ifndef _LIBCPP_CXX03_LANG template deque<_Tp, _Allocator>::deque(initializer_list __il) { __append(__il.begin(), __il.end()); } template deque<_Tp, _Allocator>::deque(initializer_list __il, const allocator_type& __a) : __base(__a) { __append(__il.begin(), __il.end()); } template inline deque<_Tp, _Allocator>::deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __base(_VSTD::move(__c)) { } template inline deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) : __base(_VSTD::move(__c), __a) { if (__a != __c.__alloc()) { typedef move_iterator _Ip; assign(_Ip(__c.begin()), _Ip(__c.end())); } } template inline deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value) { __move_assign(__c, integral_constant()); return *this; } template void deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) { if (__base::__alloc() != __c.__alloc()) { typedef move_iterator _Ip; assign(_Ip(__c.begin()), _Ip(__c.end())); } else __move_assign(__c, true_type()); } template void deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { clear(); shrink_to_fit(); __base::__move_assign(__c); } #endif // _LIBCPP_CXX03_LANG template template void deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value && !__is_random_access_iterator<_InputIter>::value>::type*) { iterator __i = __base::begin(); iterator __e = __base::end(); for (; __f != __l && __i != __e; ++__f, (void) ++__i) *__i = *__f; if (__f != __l) __append(__f, __l); else __erase_to_end(__i); } template template void deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) { if (static_cast(__l - __f) > __base::size()) { _RAIter __m = __f + __base::size(); _VSTD::copy(__f, __m, __base::begin()); __append(__m, __l); } else __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); } template void deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) { if (__n > __base::size()) { _VSTD::fill_n(__base::begin(), __base::size(), __v); __n -= __base::size(); __append(__n, __v); } else __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); } template inline _Allocator deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT { return __base::__alloc(); } template void deque<_Tp, _Allocator>::resize(size_type __n) { if (__n > __base::size()) __append(__n - __base::size()); else if (__n < __base::size()) __erase_to_end(__base::begin() + __n); } template void deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) { if (__n > __base::size()) __append(__n - __base::size(), __v); else if (__n < __base::size()) __erase_to_end(__base::begin() + __n); } template void deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT { allocator_type& __a = __base::__alloc(); if (empty()) { while (__base::__map_.size() > 0) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } __base::__start_ = 0; } else { if (__front_spare() >= __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); __base::__map_.pop_front(); __base::__start_ -= __base::__block_size; } if (__back_spare() >= __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } } __base::__map_.shrink_to_fit(); } template inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::operator[](size_type __i) { size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::operator[](size_type __i) const { size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::at(size_type __i) { if (__i >= __base::size()) __base::__throw_out_of_range(); size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::at(size_type __i) const { if (__i >= __base::size()) __base::__throw_out_of_range(); size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::front() { return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + __base::__start_ % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::front() const { return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + __base::__start_ % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::back() { size_type __p = __base::size() + __base::__start_ - 1; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::back() const { size_type __p = __base::size() + __base::__start_ - 1; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); } template void deque<_Tp, _Allocator>::push_back(const value_type& __v) { allocator_type& __a = __base::__alloc(); if (__back_spare() == 0) __add_back_capacity(); // __back_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); ++__base::size(); } template void deque<_Tp, _Allocator>::push_front(const value_type& __v) { allocator_type& __a = __base::__alloc(); if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); --__base::__start_; ++__base::size(); } #ifndef _LIBCPP_CXX03_LANG template void deque<_Tp, _Allocator>::push_back(value_type&& __v) { allocator_type& __a = __base::__alloc(); if (__back_spare() == 0) __add_back_capacity(); // __back_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); ++__base::size(); } template template #if _LIBCPP_STD_VER > 14 typename deque<_Tp, _Allocator>::reference #else void #endif deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) { allocator_type& __a = __base::__alloc(); if (__back_spare() == 0) __add_back_capacity(); // __back_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); ++__base::size(); #if _LIBCPP_STD_VER > 14 return *--__base::end(); #endif } template void deque<_Tp, _Allocator>::push_front(value_type&& __v) { allocator_type& __a = __base::__alloc(); if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); --__base::__start_; ++__base::size(); } template template #if _LIBCPP_STD_VER > 14 typename deque<_Tp, _Allocator>::reference #else void #endif deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) { allocator_type& __a = __base::__alloc(); if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); --__base::__start_; ++__base::size(); #if _LIBCPP_STD_VER > 14 return *__base::begin(); #endif } template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; allocator_type& __a = __base::__alloc(); if (__pos < __to_end) { // insert by shifting things backward if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 if (__pos == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); --__base::__start_; ++__base::size(); } else { iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); --__base::__start_; ++__base::size(); if (__pos > 1) __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); *__b = _VSTD::move(__v); } } else { // insert by shifting things forward if (__back_spare() == 0) __add_back_capacity(); // __back_capacity >= 1 size_type __de = __base::size() - __pos; if (__de == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); ++__base::size(); } else { iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) __e = _VSTD::move_backward(__e - __de, __em1, __e); *--__e = _VSTD::move(__v); } } return __base::begin() + __pos; } template template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; allocator_type& __a = __base::__alloc(); if (__pos < __to_end) { // insert by shifting things backward if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 if (__pos == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); --__base::__start_; ++__base::size(); } else { __temp_value __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); --__base::__start_; ++__base::size(); if (__pos > 1) __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); *__b = _VSTD::move(__tmp.get()); } } else { // insert by shifting things forward if (__back_spare() == 0) __add_back_capacity(); // __back_capacity >= 1 size_type __de = __base::size() - __pos; if (__de == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); ++__base::size(); } else { __temp_value __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) __e = _VSTD::move_backward(__e - __de, __em1, __e); *--__e = _VSTD::move(__tmp.get()); } } return __base::begin() + __pos; } #endif // _LIBCPP_CXX03_LANG template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; allocator_type& __a = __base::__alloc(); if (__pos < __to_end) { // insert by shifting things backward if (__front_spare() == 0) __add_front_capacity(); // __front_spare() >= 1 if (__pos == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); --__base::__start_; ++__base::size(); } else { const_pointer __vt = pointer_traits::pointer_to(__v); iterator __b = __base::begin(); iterator __bm1 = _VSTD::prev(__b); if (__vt == pointer_traits::pointer_to(*__b)) __vt = pointer_traits::pointer_to(*__bm1); __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); --__base::__start_; ++__base::size(); if (__pos > 1) __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); *__b = *__vt; } } else { // insert by shifting things forward if (__back_spare() == 0) __add_back_capacity(); // __back_capacity >= 1 size_type __de = __base::size() - __pos; if (__de == 0) { __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); ++__base::size(); } else { const_pointer __vt = pointer_traits::pointer_to(__v); iterator __e = __base::end(); iterator __em1 = _VSTD::prev(__e); if (__vt == pointer_traits::pointer_to(*__em1)) __vt = pointer_traits::pointer_to(*__e); __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); ++__base::size(); if (__de > 1) __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); *--__e = *__vt; } } return __base::begin() + __pos; } template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) { size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; allocator_type& __a = __base::__alloc(); if (__pos < __to_end) { // insert by shifting things backward if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() iterator __old_begin = __base::begin(); iterator __i = __old_begin; if (__n > __pos) { for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); __n = __pos; } if (__n > 0) { const_pointer __vt = pointer_traits::pointer_to(__v); iterator __obn = __old_begin + __n; __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); if (__n < __pos) __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); _VSTD::fill_n(__old_begin, __n, *__vt); } } else { // insert by shifting things forward size_type __back_capacity = __back_spare(); if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity iterator __old_end = __base::end(); iterator __i = __old_end; size_type __de = __base::size() - __pos; if (__n > __de) { for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); __n = __de; } if (__n > 0) { const_pointer __vt = pointer_traits::pointer_to(__v); iterator __oen = __old_end - __n; __move_construct_and_check(__oen, __old_end, __i, __vt); if (__n < __de) __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); _VSTD::fill_n(__old_end - __n, __n, *__vt); } } return __base::begin() + __pos; } template template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, typename enable_if<__is_input_iterator<_InputIter>::value &&!__is_forward_iterator<_InputIter>::value>::type*) { __split_buffer __buf(__base::__alloc()); __buf.__construct_at_end(__f, __l); typedef typename __split_buffer::iterator __bi; return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); } template template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*) { size_type __n = _VSTD::distance(__f, __l); __split_buffer __buf(__n, 0, __base::__alloc()); __buf.__construct_at_end(__f, __l); typedef typename __split_buffer::iterator __fwd; return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); } template template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) { size_type __n = _VSTD::distance(__f, __l); size_type __pos = __p - __base::begin(); size_type __to_end = __base::size() - __pos; allocator_type& __a = __base::__alloc(); if (__pos < __to_end) { // insert by shifting things backward if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() iterator __old_begin = __base::begin(); iterator __i = __old_begin; _BiIter __m = __f; if (__n > __pos) { __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); __n = __pos; } if (__n > 0) { iterator __obn = __old_begin + __n; for (iterator __j = __obn; __j != __old_begin;) { __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); --__base::__start_; ++__base::size(); } if (__n < __pos) __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); _VSTD::copy(__m, __l, __old_begin); } } else { // insert by shifting things forward size_type __back_capacity = __back_spare(); if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity iterator __old_end = __base::end(); iterator __i = __old_end; _BiIter __m = __l; size_type __de = __base::size() - __pos; if (__n > __de) { __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); __n = __de; } if (__n > 0) { iterator __oen = __old_end - __n; for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); if (__n < __de) __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); _VSTD::copy_backward(__f, __m, __old_end); } } return __base::begin() + __pos; } template template void deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value && !__is_forward_iterator<_InpIter>::value>::type*) { for (; __f != __l; ++__f) #ifdef _LIBCPP_CXX03_LANG push_back(*__f); #else emplace_back(*__f); #endif } template template void deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) { size_type __n = _VSTD::distance(__f, __l); allocator_type& __a = __base::__alloc(); size_type __back_capacity = __back_spare(); if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); } template void deque<_Tp, _Allocator>::__append(size_type __n) { allocator_type& __a = __base::__alloc(); size_type __back_capacity = __back_spare(); if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i)); } template void deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) { allocator_type& __a = __base::__alloc(); size_type __back_capacity = __back_spare(); if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); } // Create front capacity for one block of elements. // Strong guarantee. Either do it or don't touch anything. template void deque<_Tp, _Allocator>::__add_front_capacity() { allocator_type& __a = __base::__alloc(); if (__back_spare() >= __base::__block_size) { __base::__start_ += __base::__block_size; pointer __pt = __base::__map_.back(); __base::__map_.pop_back(); __base::__map_.push_front(__pt); } // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer else if (__base::__map_.size() < __base::__map_.capacity()) { // we can put the new buffer into the map, but don't shift things around // until all buffers are allocated. If we throw, we don't need to fix // anything up (any added buffers are undetectible) if (__base::__map_.__front_spare() > 0) __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); else { __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); // Done allocating, reorder capacity pointer __pt = __base::__map_.back(); __base::__map_.pop_back(); __base::__map_.push_front(__pt); } __base::__start_ = __base::__map_.size() == 1 ? __base::__block_size / 2 : __base::__start_ + __base::__block_size; } // Else need to allocate 1 buffer, *and* we need to reallocate __map_. else { __split_buffer __buf(max(2 * __base::__map_.capacity(), 1), 0, __base::__map_.__alloc()); typedef __allocator_destructor<_Allocator> _Dp; unique_ptr __hold( __alloc_traits::allocate(__a, __base::__block_size), _Dp(__a, __base::__block_size)); __buf.push_back(__hold.get()); __hold.release(); for (typename __base::__map_pointer __i = __base::__map_.begin(); __i != __base::__map_.end(); ++__i) __buf.push_back(*__i); _VSTD::swap(__base::__map_.__first_, __buf.__first_); _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); _VSTD::swap(__base::__map_.__end_, __buf.__end_); _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); __base::__start_ = __base::__map_.size() == 1 ? __base::__block_size / 2 : __base::__start_ + __base::__block_size; } } // Create front capacity for __n elements. // Strong guarantee. Either do it or don't touch anything. template void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) { allocator_type& __a = __base::__alloc(); size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); // Number of unused blocks at back: size_type __back_capacity = __back_spare() / __base::__block_size; __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need __nb -= __back_capacity; // number of blocks need to allocate // If __nb == 0, then we have sufficient capacity. if (__nb == 0) { __base::__start_ += __base::__block_size * __back_capacity; for (; __back_capacity > 0; --__back_capacity) { pointer __pt = __base::__map_.back(); __base::__map_.pop_back(); __base::__map_.push_front(__pt); } } // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) { // we can put the new buffers into the map, but don't shift things around // until all buffers are allocated. If we throw, we don't need to fix // anything up (any added buffers are undetectible) for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) { if (__base::__map_.__front_spare() == 0) break; __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); } for (; __nb > 0; --__nb, ++__back_capacity) __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); // Done allocating, reorder capacity __base::__start_ += __back_capacity * __base::__block_size; for (; __back_capacity > 0; --__back_capacity) { pointer __pt = __base::__map_.back(); __base::__map_.pop_back(); __base::__map_.push_front(__pt); } } // Else need to allocate __nb buffers, *and* we need to reallocate __map_. else { size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); __split_buffer __buf(max(2* __base::__map_.capacity(), __nb + __base::__map_.size()), 0, __base::__map_.__alloc()); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __nb > 0; --__nb) __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { for (typename __base::__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i) __alloc_traits::deallocate(__a, *__i, __base::__block_size); throw; } #endif // _LIBCPP_NO_EXCEPTIONS for (; __back_capacity > 0; --__back_capacity) { __buf.push_back(__base::__map_.back()); __base::__map_.pop_back(); } for (typename __base::__map_pointer __i = __base::__map_.begin(); __i != __base::__map_.end(); ++__i) __buf.push_back(*__i); _VSTD::swap(__base::__map_.__first_, __buf.__first_); _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); _VSTD::swap(__base::__map_.__end_, __buf.__end_); _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); __base::__start_ += __ds; } } // Create back capacity for one block of elements. // Strong guarantee. Either do it or don't touch anything. template void deque<_Tp, _Allocator>::__add_back_capacity() { allocator_type& __a = __base::__alloc(); if (__front_spare() >= __base::__block_size) { __base::__start_ -= __base::__block_size; pointer __pt = __base::__map_.front(); __base::__map_.pop_front(); __base::__map_.push_back(__pt); } // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers else if (__base::__map_.size() < __base::__map_.capacity()) { // we can put the new buffer into the map, but don't shift things around // until it is allocated. If we throw, we don't need to fix // anything up (any added buffers are undetectible) if (__base::__map_.__back_spare() != 0) __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); else { __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); // Done allocating, reorder capacity pointer __pt = __base::__map_.front(); __base::__map_.pop_front(); __base::__map_.push_back(__pt); } } // Else need to allocate 1 buffer, *and* we need to reallocate __map_. else { __split_buffer __buf(max(2* __base::__map_.capacity(), 1), __base::__map_.size(), __base::__map_.__alloc()); typedef __allocator_destructor<_Allocator> _Dp; unique_ptr __hold( __alloc_traits::allocate(__a, __base::__block_size), _Dp(__a, __base::__block_size)); __buf.push_back(__hold.get()); __hold.release(); for (typename __base::__map_pointer __i = __base::__map_.end(); __i != __base::__map_.begin();) __buf.push_front(*--__i); _VSTD::swap(__base::__map_.__first_, __buf.__first_); _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); _VSTD::swap(__base::__map_.__end_, __buf.__end_); _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); } } // Create back capacity for __n elements. // Strong guarantee. Either do it or don't touch anything. template void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) { allocator_type& __a = __base::__alloc(); size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); // Number of unused blocks at front: size_type __front_capacity = __front_spare() / __base::__block_size; __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need __nb -= __front_capacity; // number of blocks need to allocate // If __nb == 0, then we have sufficient capacity. if (__nb == 0) { __base::__start_ -= __base::__block_size * __front_capacity; for (; __front_capacity > 0; --__front_capacity) { pointer __pt = __base::__map_.front(); __base::__map_.pop_front(); __base::__map_.push_back(__pt); } } // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) { // we can put the new buffers into the map, but don't shift things around // until all buffers are allocated. If we throw, we don't need to fix // anything up (any added buffers are undetectible) for (; __nb > 0; --__nb) { if (__base::__map_.__back_spare() == 0) break; __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); } for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); // Done allocating, reorder capacity __base::__start_ -= __base::__block_size * __front_capacity; for (; __front_capacity > 0; --__front_capacity) { pointer __pt = __base::__map_.front(); __base::__map_.pop_front(); __base::__map_.push_back(__pt); } } // Else need to allocate __nb buffers, *and* we need to reallocate __map_. else { size_type __ds = __front_capacity * __base::__block_size; __split_buffer __buf(max(2* __base::__map_.capacity(), __nb + __base::__map_.size()), __base::__map_.size() - __front_capacity, __base::__map_.__alloc()); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (; __nb > 0; --__nb) __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { for (typename __base::__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i) __alloc_traits::deallocate(__a, *__i, __base::__block_size); throw; } #endif // _LIBCPP_NO_EXCEPTIONS for (; __front_capacity > 0; --__front_capacity) { __buf.push_back(__base::__map_.front()); __base::__map_.pop_front(); } for (typename __base::__map_pointer __i = __base::__map_.end(); __i != __base::__map_.begin();) __buf.push_front(*--__i); _VSTD::swap(__base::__map_.__first_, __buf.__first_); _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); _VSTD::swap(__base::__map_.__end_, __buf.__end_); _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); __base::__start_ -= __ds; } } template void deque<_Tp, _Allocator>::pop_front() { allocator_type& __a = __base::__alloc(); __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + __base::__start_ % __base::__block_size)); --__base::size(); if (++__base::__start_ >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); __base::__map_.pop_front(); __base::__start_ -= __base::__block_size; } } template void deque<_Tp, _Allocator>::pop_back() { allocator_type& __a = __base::__alloc(); size_type __p = __base::size() + __base::__start_ - 1; __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size)); --__base::size(); if (__back_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } } // move assign [__f, __l) to [__r, __r + (__l-__f)). // If __vt points into [__f, __l), then subtract (__f - __r) from __vt. template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) { // as if // for (; __f != __l; ++__f, ++__r) // *__r = _VSTD::move(*__f); difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __base::__block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } if (__fb <= __vt && __vt < __fe) __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; __r = _VSTD::move(__fb, __fe, __r); __n -= __bs; __f += __bs; } return __r; } // move assign [__f, __l) to [__r - (__l-__f), __r) backwards. // If __vt points into [__f, __l), then add (__r - __l) to __vt. template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) { // as if // while (__f != __l) // *--__r = _VSTD::move(*--__l); difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } if (__lb <= __vt && __vt < __le) __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; __r = _VSTD::move_backward(__lb, __le, __r); __n -= __bs; __l -= __bs - 1; } return __r; } // move construct [__f, __l) to [__r, __r + (__l-__f)). // If __vt points into [__f, __l), then add (__r - __f) to __vt. template void deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) { allocator_type& __a = __base::__alloc(); // as if // for (; __f != __l; ++__r, ++__f, ++__base::size()) // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; pointer __fe = *__f.__m_iter_ + __base::__block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { __bs = __n; __fe = __fb + __bs; } if (__fb <= __vt && __vt < __fe) __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); __n -= __bs; __f += __bs; } } // move construct [__f, __l) to [__r - (__l-__f), __r) backwards. // If __vt points into [__f, __l), then subtract (__l - __r) from __vt. template void deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, iterator __r, const_pointer& __vt) { allocator_type& __a = __base::__alloc(); // as if // for (iterator __j = __l; __j != __f;) // { // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); // --__base::__start_; // ++__base::size(); // } difference_type __n = __l - __f; while (__n > 0) { --__l; pointer __lb = *__l.__m_iter_; pointer __le = __l.__ptr_ + 1; difference_type __bs = __le - __lb; if (__bs > __n) { __bs = __n; __lb = __le - __bs; } if (__lb <= __vt && __vt < __le) __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; while (__le != __lb) { __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); --__base::__start_; ++__base::size(); } __n -= __bs; __l -= __bs - 1; } } template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f) { iterator __b = __base::begin(); difference_type __pos = __f - __b; iterator __p = __b + __pos; allocator_type& __a = __base::__alloc(); if (static_cast(__pos) <= (__base::size() - 1) / 2) { // erase from front _VSTD::move_backward(__b, __p, _VSTD::next(__p)); __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); --__base::size(); ++__base::__start_; if (__front_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); __base::__map_.pop_front(); __base::__start_ -= __base::__block_size; } } else { // erase from back iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); --__base::size(); if (__back_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } } return __base::begin() + __pos; } template typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) { difference_type __n = __l - __f; iterator __b = __base::begin(); difference_type __pos = __f - __b; iterator __p = __b + __pos; if (__n > 0) { allocator_type& __a = __base::__alloc(); if (static_cast(__pos) <= (__base::size() - __n) / 2) { // erase from front iterator __i = _VSTD::move_backward(__b, __p, __p + __n); for (; __b != __i; ++__b) __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); __base::size() -= __n; __base::__start_ += __n; while (__front_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); __base::__map_.pop_front(); __base::__start_ -= __base::__block_size; } } else { // erase from back iterator __i = _VSTD::move(__p + __n, __base::end(), __p); for (iterator __e = __base::end(); __i != __e; ++__i) __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); __base::size() -= __n; while (__back_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } } } return __base::begin() + __pos; } template void deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) { iterator __e = __base::end(); difference_type __n = __e - __f; if (__n > 0) { allocator_type& __a = __base::__alloc(); iterator __b = __base::begin(); difference_type __pos = __f - __b; for (iterator __p = __b + __pos; __p != __e; ++__p) __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); __base::size() -= __n; while (__back_spare() >= 2 * __base::__block_size) { __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); __base::__map_.pop_back(); } } } template inline void deque<_Tp, _Allocator>::swap(deque& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable::value) #endif { __base::swap(__c); } template inline void deque<_Tp, _Allocator>::clear() _NOEXCEPT { __base::clear(); } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { const typename deque<_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 deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_DEQUE Index: projects/clang600-import/contrib/libc++/include/exception =================================================================== --- projects/clang600-import/contrib/libc++/include/exception (revision 327038) +++ projects/clang600-import/contrib/libc++/include/exception (revision 327039) @@ -1,337 +1,337 @@ // -*- C++ -*- //===-------------------------- exception ---------------------------------===// // // 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_EXCEPTION #define _LIBCPP_EXCEPTION /* exception synopsis namespace std { class exception { public: exception() noexcept; exception(const exception&) noexcept; exception& operator=(const exception&) noexcept; virtual ~exception() noexcept; virtual const char* what() const noexcept; }; class bad_exception : public exception { public: bad_exception() noexcept; bad_exception(const bad_exception&) noexcept; bad_exception& operator=(const bad_exception&) noexcept; virtual ~bad_exception() noexcept; virtual const char* what() const noexcept; }; typedef void (*unexpected_handler)(); unexpected_handler set_unexpected(unexpected_handler f ) noexcept; unexpected_handler get_unexpected() noexcept; [[noreturn]] void unexpected(); typedef void (*terminate_handler)(); terminate_handler set_terminate(terminate_handler f ) noexcept; terminate_handler get_terminate() noexcept; [[noreturn]] void terminate() noexcept; bool uncaught_exception() noexcept; int uncaught_exceptions() noexcept; // C++17 typedef unspecified exception_ptr; exception_ptr current_exception() noexcept; void rethrow_exception [[noreturn]] (exception_ptr p); template exception_ptr make_exception_ptr(E e) noexcept; class nested_exception { public: nested_exception() noexcept; nested_exception(const nested_exception&) noexcept = default; nested_exception& operator=(const nested_exception&) noexcept = default; virtual ~nested_exception() = default; // access functions [[noreturn]] void rethrow_nested() const; exception_ptr nested_ptr() const noexcept; }; template [[noreturn]] void throw_with_nested(T&& t); template void rethrow_if_nested(const E& e); } // std */ #include <__config> #include #include #include -#if defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) #include #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) class _LIBCPP_EXCEPTION_ABI exception { public: _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {} virtual ~exception() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; class _LIBCPP_EXCEPTION_ABI bad_exception : public exception { public: _LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {} virtual ~bad_exception() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; -#endif // !_LIBCPP_ABI_MICROSOFT +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME #if _LIBCPP_STD_VER <= 14 \ || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ || defined(_LIBCPP_BUILDING_LIBRARY) typedef void (*unexpected_handler)(); _LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; _LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected(); #endif typedef void (*terminate_handler)(); _LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT; _LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT; _LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT; _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT; class _LIBCPP_TYPE_VIS exception_ptr; _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); #ifndef _LIBCPP_ABI_MICROSOFT class _LIBCPP_TYPE_VIS exception_ptr { void* __ptr_; public: _LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {} _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} exception_ptr(const exception_ptr&) _NOEXCEPT; exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; ~exception_ptr() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __ptr_ != nullptr;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {return !(__x == __y);} friend _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; friend _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); }; template exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { #ifndef _LIBCPP_NO_EXCEPTIONS try { throw __e; } catch (...) { return current_exception(); } #else ((void)__e); _VSTD::abort(); #endif } #else // _LIBCPP_ABI_MICROSOFT class _LIBCPP_TYPE_VIS exception_ptr { #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" #endif void* __ptr1_; void* __ptr2_; #if defined(__clang__) #pragma clang diagnostic pop #endif public: exception_ptr() _NOEXCEPT; exception_ptr(nullptr_t) _NOEXCEPT; exception_ptr(const exception_ptr& __other) _NOEXCEPT; exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; exception_ptr& operator=(nullptr_t) _NOEXCEPT; ~exception_ptr() _NOEXCEPT; _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT; }; _LIBCPP_FUNC_VIS bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {return !(__x == __y);} _LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; _LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr); _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p); // This is a built-in template function which automagically extracts the required // information. template void *__GetExceptionInfo(_E); template exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e)); } #endif // _LIBCPP_ABI_MICROSOFT // nested_exception class _LIBCPP_EXCEPTION_ABI nested_exception { exception_ptr __ptr_; public: nested_exception() _NOEXCEPT; // nested_exception(const nested_exception&) noexcept = default; // nested_exception& operator=(const nested_exception&) noexcept = default; virtual ~nested_exception() _NOEXCEPT; // access functions _LIBCPP_NORETURN void rethrow_nested() const; _LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;} }; template struct __nested : public _Tp, public nested_exception { _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} }; #ifndef _LIBCPP_NO_EXCEPTIONS template struct __throw_with_nested; template struct __throw_with_nested<_Tp, _Up, true> { _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void #ifndef _LIBCPP_CXX03_LANG __do_throw(_Tp&& __t) #else __do_throw (_Tp& __t) #endif // _LIBCPP_CXX03_LANG { throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); } }; template struct __throw_with_nested<_Tp, _Up, false> { _LIBCPP_NORETURN static inline _LIBCPP_ALWAYS_INLINE void #ifndef _LIBCPP_CXX03_LANG __do_throw(_Tp&& __t) #else __do_throw (_Tp& __t) #endif // _LIBCPP_CXX03_LANG { throw _VSTD::forward<_Tp>(__t); } }; #endif template _LIBCPP_NORETURN void #ifndef _LIBCPP_CXX03_LANG throw_with_nested(_Tp&& __t) #else throw_with_nested (_Tp& __t) #endif // _LIBCPP_CXX03_LANG { #ifndef _LIBCPP_NO_EXCEPTIONS typedef typename decay<_Tp>::type _Up; static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); __throw_with_nested<_Tp, _Up, is_class<_Up>::value && !is_base_of::value && !__libcpp_is_final<_Up>::value>:: __do_throw(_VSTD::forward<_Tp>(__t)); #else ((void)__t); // FIXME: Make this abort #endif } template struct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT( is_polymorphic<_From>::value && (!is_base_of<_To, _From>::value || is_convertible::value)) {}; template inline _LIBCPP_INLINE_VISIBILITY void rethrow_if_nested(const _Ep& __e, typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) { const nested_exception* __nep = dynamic_cast(_VSTD::addressof(__e)); if (__nep) __nep->rethrow_nested(); } template inline _LIBCPP_INLINE_VISIBILITY void rethrow_if_nested(const _Ep&, typename enable_if::value>::type* = 0) { } } // std #endif // _LIBCPP_EXCEPTION Index: projects/clang600-import/contrib/libc++/include/experimental/algorithm =================================================================== --- projects/clang600-import/contrib/libc++/include/experimental/algorithm (revision 327038) +++ projects/clang600-import/contrib/libc++/include/experimental/algorithm (revision 327039) @@ -1,73 +1,73 @@ // -*- 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_EXPERIMENTAL_ALGORITHM #define _LIBCPP_EXPERIMENTAL_ALGORITHM /* experimental/algorithm synopsis #include namespace std { namespace experimental { inline namespace fundamentals_v1 { template ForwardIterator search(ForwardIterator first, ForwardIterator last, const Searcher &searcher); template SampleIterator sample(PopulationIterator first, PopulationIterator last, SampleIterator out, Distance n, UniformRandomNumberGenerator &&g); } // namespace fundamentals_v1 } // namespace experimental } // namespace std */ #include #include #include #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_LFTS template _LIBCPP_INLINE_VISIBILITY _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) { return __s(__f, __l).first; } template inline _LIBCPP_INLINE_VISIBILITY _SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last, - _SampleIterator __output, _Distance __n, + _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator &&__g) { - return _VSTD::__sample(__first, __last, __output, __n, __g); + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); } _LIBCPP_END_NAMESPACE_LFTS _LIBCPP_POP_MACROS #endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */ Index: projects/clang600-import/contrib/libc++/include/experimental/filesystem =================================================================== --- projects/clang600-import/contrib/libc++/include/experimental/filesystem (revision 327038) +++ projects/clang600-import/contrib/libc++/include/experimental/filesystem (revision 327039) @@ -1,2139 +1,2140 @@ // -*- C++ -*- //===--------------------------- filesystem -------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM #define _LIBCPP_EXPERIMENTAL_FILESYSTEM /* filesystem synopsis namespace std { namespace experimental { namespace filesystem { inline namespace v1 { class path; void swap(path& lhs, path& rhs) _NOEXCEPT; size_t hash_value(const path& p) _NOEXCEPT; bool operator==(const path& lhs, const path& rhs) _NOEXCEPT; bool operator!=(const path& lhs, const path& rhs) _NOEXCEPT; bool operator< (const path& lhs, const path& rhs) _NOEXCEPT; bool operator<=(const path& lhs, const path& rhs) _NOEXCEPT; bool operator> (const path& lhs, const path& rhs) _NOEXCEPT; bool operator>=(const path& lhs, const path& rhs) _NOEXCEPT; path operator/ (const path& lhs, const path& rhs); template basic_ostream& operator<<(basic_ostream& os, const path& p); template basic_istream& operator>>(basic_istream& is, path& p); template path u8path(const Source& source); template path u8path(InputIterator first, InputIterator last); class filesystem_error; class directory_entry; class directory_iterator; // enable directory_iterator range-based for statements directory_iterator begin(directory_iterator iter) noexcept; directory_iterator end(const directory_iterator&) noexcept; class recursive_directory_iterator; // enable recursive_directory_iterator range-based for statements recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; recursive_directory_iterator end(const recursive_directory_iterator&) noexcept; class file_status; struct space_info { uintmax_t capacity; uintmax_t free; uintmax_t available; }; enum class file_type; enum class perms; enum class copy_options; enum class directory_options; typedef chrono::time_point file_time_type; // operational functions path absolute(const path& p, const path& base=current_path()); path canonical(const path& p, const path& base = current_path()); path canonical(const path& p, error_code& ec); path canonical(const path& p, const path& base, error_code& ec); void copy(const path& from, const path& to); - void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT; + void copy(const path& from, const path& to, error_code& ec); void copy(const path& from, const path& to, copy_options options); void copy(const path& from, const path& to, copy_options options, - error_code& ec) _NOEXCEPT; + error_code& ec); bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT; bool copy_file(const path& from, const path& to, copy_options option); bool copy_file(const path& from, const path& to, copy_options option, error_code& ec) _NOEXCEPT; void copy_symlink(const path& existing_symlink, const path& new_symlink); void copy_symlink(const path& existing_symlink, const path& new_symlink, error_code& ec) _NOEXCEPT; bool create_directories(const path& p); bool create_directories(const path& p, error_code& ec) _NOEXCEPT; bool create_directory(const path& p); bool create_directory(const path& p, error_code& ec) _NOEXCEPT; bool create_directory(const path& p, const path& attributes); bool create_directory(const path& p, const path& attributes, error_code& ec) _NOEXCEPT; void create_directory_symlink(const path& to, const path& new_symlink); void create_directory_symlink(const path& to, const path& new_symlink, error_code& ec) _NOEXCEPT; void create_hard_link(const path& to, const path& new_hard_link); void create_hard_link(const path& to, const path& new_hard_link, error_code& ec) _NOEXCEPT; void create_symlink(const path& to, const path& new_symlink); void create_symlink(const path& to, const path& new_symlink, error_code& ec) _NOEXCEPT; path current_path(); path current_path(error_code& ec); void current_path(const path& p); void current_path(const path& p, error_code& ec) _NOEXCEPT; bool exists(file_status s) _NOEXCEPT; bool exists(const path& p); bool exists(const path& p, error_code& ec) _NOEXCEPT; bool equivalent(const path& p1, const path& p2); bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT; uintmax_t file_size(const path& p); uintmax_t file_size(const path& p, error_code& ec) _NOEXCEPT; uintmax_t hard_link_count(const path& p); uintmax_t hard_link_count(const path& p, error_code& ec) _NOEXCEPT; bool is_block_file(file_status s) _NOEXCEPT; bool is_block_file(const path& p); bool is_block_file(const path& p, error_code& ec) _NOEXCEPT; bool is_character_file(file_status s) _NOEXCEPT; bool is_character_file(const path& p); bool is_character_file(const path& p, error_code& ec) _NOEXCEPT; bool is_directory(file_status s) _NOEXCEPT; bool is_directory(const path& p); bool is_directory(const path& p, error_code& ec) _NOEXCEPT; bool is_empty(const path& p); bool is_empty(const path& p, error_code& ec) _NOEXCEPT; bool is_fifo(file_status s) _NOEXCEPT; bool is_fifo(const path& p); bool is_fifo(const path& p, error_code& ec) _NOEXCEPT; bool is_other(file_status s) _NOEXCEPT; bool is_other(const path& p); bool is_other(const path& p, error_code& ec) _NOEXCEPT; bool is_regular_file(file_status s) _NOEXCEPT; bool is_regular_file(const path& p); bool is_regular_file(const path& p, error_code& ec) _NOEXCEPT; bool is_socket(file_status s) _NOEXCEPT; bool is_socket(const path& p); bool is_socket(const path& p, error_code& ec) _NOEXCEPT; bool is_symlink(file_status s) _NOEXCEPT; bool is_symlink(const path& p); bool is_symlink(const path& p, error_code& ec) _NOEXCEPT; file_time_type last_write_time(const path& p); file_time_type last_write_time(const path& p, error_code& ec) _NOEXCEPT; void last_write_time(const path& p, file_time_type new_time); void last_write_time(const path& p, file_time_type new_time, error_code& ec) _NOEXCEPT; void permissions(const path& p, perms prms); void permissions(const path& p, perms prms, error_code& ec) _NOEXCEPT; path read_symlink(const path& p); path read_symlink(const path& p, error_code& ec); bool remove(const path& p); bool remove(const path& p, error_code& ec) _NOEXCEPT; uintmax_t remove_all(const path& p); uintmax_t remove_all(const path& p, error_code& ec) _NOEXCEPT; void rename(const path& from, const path& to); void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT; void resize_file(const path& p, uintmax_t size); void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT; space_info space(const path& p); space_info space(const path& p, error_code& ec) _NOEXCEPT; file_status status(const path& p); file_status status(const path& p, error_code& ec) _NOEXCEPT; bool status_known(file_status s) _NOEXCEPT; file_status symlink_status(const path& p); file_status symlink_status(const path& p, error_code& ec) _NOEXCEPT; path system_complete(const path& p); path system_complete(const path& p, error_code& ec); path temp_directory_path(); path temp_directory_path(error_code& ec); } } } } // namespaces std::experimental::filesystem::v1 */ #include #include #include #include #include #include #include #include #include #include #include #include // for quoted #include #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif #define __cpp_lib_experimental_filesystem 201406 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM typedef chrono::time_point file_time_type; struct _LIBCPP_TYPE_VIS space_info { uintmax_t capacity; uintmax_t free; uintmax_t available; }; enum class _LIBCPP_ENUM_VIS file_type : signed char { none = 0, not_found = -1, regular = 1, directory = 2, symlink = 3, block = 4, character = 5, fifo = 6, socket = 7, unknown = 8 }; enum class _LIBCPP_ENUM_VIS perms : unsigned { none = 0, owner_read = 0400, owner_write = 0200, owner_exec = 0100, owner_all = 0700, group_read = 040, group_write = 020, group_exec = 010, group_all = 070, others_read = 04, others_write = 02, others_exec = 01, others_all = 07, all = 0777, set_uid = 04000, set_gid = 02000, sticky_bit = 01000, mask = 07777, unknown = 0xFFFF, add_perms = 0x10000, remove_perms = 0x20000, symlink_nofollow = 0x40000 }; _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS) { return static_cast(static_cast(_LHS) & static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS) { return static_cast(static_cast(_LHS) | static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS) { return static_cast(static_cast(_LHS) ^ static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS) { return static_cast(~static_cast(_LHS)); } _LIBCPP_INLINE_VISIBILITY inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; } _LIBCPP_INLINE_VISIBILITY inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; } _LIBCPP_INLINE_VISIBILITY inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; } enum class _LIBCPP_ENUM_VIS copy_options : unsigned short { none = 0, skip_existing = 1, overwrite_existing = 2, update_existing = 4, recursive = 8, copy_symlinks = 16, skip_symlinks = 32, directories_only = 64, create_symlinks = 128, create_hard_links = 256, __in_recursive_copy = 512, }; _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS) { return static_cast(static_cast(_LHS) & static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS) { return static_cast(static_cast(_LHS) | static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS) { return static_cast(static_cast(_LHS) ^ static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS) { return static_cast(~static_cast(_LHS)); } _LIBCPP_INLINE_VISIBILITY inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) { return _LHS = _LHS & _RHS; } _LIBCPP_INLINE_VISIBILITY inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) { return _LHS = _LHS | _RHS; } _LIBCPP_INLINE_VISIBILITY inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) { return _LHS = _LHS ^ _RHS; } enum class _LIBCPP_ENUM_VIS directory_options : unsigned char { none = 0, follow_directory_symlink = 1, skip_permission_denied = 2 }; _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS) { return static_cast(static_cast(_LHS) & static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS) { return static_cast(static_cast(_LHS) | static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS) { return static_cast(static_cast(_LHS) ^ static_cast(_RHS)); } _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS) { return static_cast(~static_cast(_LHS)); } _LIBCPP_INLINE_VISIBILITY inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS) { return _LHS = _LHS & _RHS; } _LIBCPP_INLINE_VISIBILITY inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS) { return _LHS = _LHS | _RHS; } _LIBCPP_INLINE_VISIBILITY inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS) { return _LHS = _LHS ^ _RHS; } class _LIBCPP_TYPE_VIS file_status { public: // constructors _LIBCPP_INLINE_VISIBILITY file_status() _NOEXCEPT : file_status(file_type::none) {} _LIBCPP_INLINE_VISIBILITY explicit file_status(file_type __ft, perms __prms = perms::unknown) _NOEXCEPT : __ft_(__ft), __prms_(__prms) {} file_status(const file_status&) _NOEXCEPT = default; file_status(file_status&&) _NOEXCEPT = default; _LIBCPP_INLINE_VISIBILITY ~file_status() {} file_status& operator=(const file_status&) _NOEXCEPT = default; file_status& operator=(file_status&&) _NOEXCEPT = default; // observers _LIBCPP_ALWAYS_INLINE file_type type() const _NOEXCEPT { return __ft_; } _LIBCPP_ALWAYS_INLINE perms permissions() const _NOEXCEPT { return __prms_; } // modifiers _LIBCPP_ALWAYS_INLINE void type(file_type __ft) _NOEXCEPT { __ft_ = __ft; } _LIBCPP_ALWAYS_INLINE void permissions(perms __p) _NOEXCEPT { __prms_ = __p; } private: file_type __ft_; perms __prms_; }; class _LIBCPP_TYPE_VIS directory_entry; template struct __can_convert_char { static const bool value = false; }; template struct __can_convert_char : public __can_convert_char<_Tp> { }; template <> struct __can_convert_char { static const bool value = true; using __char_type = char; }; template <> struct __can_convert_char { static const bool value = true; using __char_type = wchar_t; }; template <> struct __can_convert_char { static const bool value = true; using __char_type = char16_t; }; template <> struct __can_convert_char { static const bool value = true; using __char_type = char32_t; }; template typename enable_if<__can_convert_char<_ECharT>::value, bool>::type __is_separator(_ECharT __e) { return __e == _ECharT('/'); }; struct _NullSentinal {}; template using _Void = void; template struct __is_pathable_string : public false_type {}; template struct __is_pathable_string, _Void::__char_type>> : public __can_convert_char<_ECharT> { using _Str = basic_string<_ECharT, _Traits, _Alloc>; using _Base = __can_convert_char<_ECharT>; static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); } static _ECharT __first_or_null(_Str const& __s) { return __s.empty() ? _ECharT{} : __s[0]; } }; template struct __is_pathable_string, _Void::__char_type>> : public __can_convert_char<_ECharT> { using _Str = basic_string_view<_ECharT, _Traits>; using _Base = __can_convert_char<_ECharT>; static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); } static _ECharT __first_or_null(_Str const& __s) { return __s.empty() ? _ECharT{} : __s[0]; } }; template ::type, class _UnqualPtrType = typename remove_const< typename remove_pointer<_DS>::type>::type, bool _IsCharPtr = is_pointer<_DS>::value && __can_convert_char<_UnqualPtrType>::value > struct __is_pathable_char_array : false_type {}; template struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true> : __can_convert_char::type> { using _Base = __can_convert_char::type>; static _ECharT const* __range_begin(const _ECharT* __b) { return __b; } static _ECharT const* __range_end(const _ECharT* __b) { using _Iter = const _ECharT*; const _ECharT __sentinal = _ECharT{}; _Iter __e = __b; for (; *__e != __sentinal; ++__e) ; return __e; } static _ECharT __first_or_null(const _ECharT* __b) { return *__b; } }; template ::value, class = void> struct __is_pathable_iter : false_type {}; template struct __is_pathable_iter<_Iter, true, _Void::value_type>::__char_type>> : __can_convert_char::value_type> { using _ECharT = typename iterator_traits<_Iter>::value_type; using _Base = __can_convert_char<_ECharT>; static _Iter __range_begin(_Iter __b) { return __b; } static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; } static _ECharT __first_or_null(_Iter __b) { return *__b; } }; template ::value, bool _IsCharIterT = __is_pathable_char_array<_Tp>::value, bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value > struct __is_pathable : false_type { static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false"); }; template struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {}; template struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {}; template struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {}; template struct _PathCVT { static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible"); typedef __narrow_to_utf8 _Narrower; static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) { _Narrower()(back_inserter(__dest), __b, __e); } template static void __append_range(string& __dest, _Iter __b, _Iter __e) { static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); if (__b == __e) return; basic_string<_ECharT> __tmp(__b, __e); _Narrower()(back_inserter(__dest), __tmp.data(), __tmp.data() + __tmp.length()); } template static void __append_range(string& __dest, _Iter __b, _NullSentinal) { static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); const _ECharT __sentinal = _ECharT{}; if (*__b == __sentinal) return; basic_string<_ECharT> __tmp; for (; *__b != __sentinal; ++__b) __tmp.push_back(*__b); _Narrower()(back_inserter(__dest), __tmp.data(), __tmp.data() + __tmp.length()); } template static void __append_source(string& __dest, _Source const& __s) { using _Traits = __is_pathable<_Source>; __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s)); } }; template <> struct _PathCVT { template static typename enable_if< __is_exactly_input_iterator<_Iter>::value >::type __append_range(string& __dest, _Iter __b, _Iter __e) { for (; __b != __e; ++__b) __dest.push_back(*__b); } template static typename enable_if< __is_forward_iterator<_Iter>::value >::type __append_range(string& __dest, _Iter __b, _Iter __e) { __dest.__append_forward_unsafe(__b, __e); } template static void __append_range(string& __dest, _Iter __b, _NullSentinal) { const char __sentinal = char{}; for (; *__b != __sentinal; ++__b) __dest.push_back(*__b); } template static void __append_source(string& __dest, _Source const& __s) { using _Traits = __is_pathable<_Source>; __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s)); } }; class _LIBCPP_TYPE_VIS path { template using _EnableIfPathable = typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type; template using _SourceChar = typename __is_pathable<_Tp>::__char_type; template using _SourceCVT = _PathCVT<_SourceChar<_Tp>>; public: typedef char value_type; typedef basic_string string_type; typedef _VSTD::string_view __string_view; static _LIBCPP_CONSTEXPR value_type preferred_separator = '/'; // constructors and destructor _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {} _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {} _LIBCPP_INLINE_VISIBILITY path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {} template < class _Source, class = _EnableIfPathable<_Source, void> > path(const _Source& __src) { _SourceCVT<_Source>::__append_source(__pn_, __src); } template path(_InputIt __first, _InputIt __last) { typedef typename iterator_traits<_InputIt>::value_type _ItVal; _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); } // TODO Implement locale conversions. template > path(const _Source& __src, const locale& __loc); template path(_InputIt __first, _InputIt _last, const locale& __loc); _LIBCPP_INLINE_VISIBILITY ~path() = default; // assignments _LIBCPP_INLINE_VISIBILITY path& operator=(const path& __p) { __pn_ = __p.__pn_; return *this; } _LIBCPP_INLINE_VISIBILITY path& operator=(path&& __p) _NOEXCEPT { __pn_ = _VSTD::move(__p.__pn_); return *this; } template _LIBCPP_INLINE_VISIBILITY path& operator=(string_type&& __s) _NOEXCEPT { __pn_ = _VSTD::move(__s); return *this; } _LIBCPP_INLINE_VISIBILITY path& assign(string_type&& __s) _NOEXCEPT { __pn_ = _VSTD::move(__s); return *this; } template _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> operator=(const _Source& __src) { return this->assign(__src); } template _EnableIfPathable<_Source> assign(const _Source& __src) { __pn_.clear(); _SourceCVT<_Source>::__append_source(__pn_, __src); return *this; } template path& assign(_InputIt __first, _InputIt __last) { typedef typename iterator_traits<_InputIt>::value_type _ItVal; __pn_.clear(); _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); return *this; } private: template void __append_sep_if_needed(_ECharT __first_or_null) { const _ECharT __null_val = {}; bool __append_sep = !empty() && !__is_separator(__pn_.back()) && __first_or_null != __null_val && // non-empty !__is_separator(__first_or_null); if (__append_sep) __pn_ += preferred_separator; } public: // appends path& operator/=(const path& __p) { _LIBCPP_ASSERT(!__p.has_root_name(), "cannot append to a path with a root name"); __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]); __pn_ += __p.native(); return *this; } template _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> operator/=(const _Source& __src) { return this->append(__src); } template _EnableIfPathable<_Source> append(const _Source& __src) { using _Traits = __is_pathable<_Source>; using _CVT = _PathCVT<_SourceChar<_Source>>; __append_sep_if_needed(_Traits::__first_or_null(__src)); _CVT::__append_source(__pn_, __src); return *this; } template path& append(_InputIt __first, _InputIt __last) { typedef typename iterator_traits<_InputIt>::value_type _ItVal; static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); using _CVT = _PathCVT<_ItVal>; if (__first != __last) { __append_sep_if_needed(*__first); _CVT::__append_range(__pn_, __first, __last); } return *this; } // concatenation _LIBCPP_INLINE_VISIBILITY path& operator+=(const path& __x) { __pn_ += __x.__pn_; return *this; } _LIBCPP_INLINE_VISIBILITY path& operator+=(const string_type& __x) { __pn_ += __x; return *this; } _LIBCPP_INLINE_VISIBILITY path& operator+=(__string_view __x) { __pn_ += __x; return *this; } _LIBCPP_INLINE_VISIBILITY path& operator+=(const value_type* __x) { __pn_ += __x; return *this; } _LIBCPP_INLINE_VISIBILITY path& operator+=(value_type __x) { __pn_ += __x; return *this; } template typename enable_if<__can_convert_char<_ECharT>::value, path&>::type operator+=(_ECharT __x) { basic_string<_ECharT> __tmp; __tmp += __x; _PathCVT<_ECharT>::__append_source(__pn_, __tmp); return *this; } template _EnableIfPathable<_Source> operator+=(const _Source& __x) { return this->concat(__x); } template _EnableIfPathable<_Source> concat(const _Source& __x) { _SourceCVT<_Source>::__append_source(__pn_, __x); return *this; } template path& concat(_InputIt __first, _InputIt __last) { typedef typename iterator_traits<_InputIt>::value_type _ItVal; _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); return *this; } // modifiers _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT { __pn_.clear(); } path& make_preferred() { return *this; } _LIBCPP_INLINE_VISIBILITY path& remove_filename() { if (__pn_.size() == __root_path_raw().size()) clear(); else __pn_ = __parent_path(); return *this; } path& replace_filename(const path& __replacement) { remove_filename(); return (*this /= __replacement); } path& replace_extension(const path& __replacement = path()); _LIBCPP_INLINE_VISIBILITY void swap(path& __rhs) _NOEXCEPT { __pn_.swap(__rhs.__pn_); } // native format observers _LIBCPP_INLINE_VISIBILITY const string_type& native() const _NOEXCEPT { return __pn_; } _LIBCPP_INLINE_VISIBILITY const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); } _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; } template , class _Allocator = allocator<_ECharT> > basic_string<_ECharT, _Traits, _Allocator> string(const _Allocator& __a = _Allocator()) const { using _CVT = __widen_from_utf8; using _Str = basic_string<_ECharT, _Traits, _Allocator>; _Str __s(__a); __s.reserve(__pn_.size()); _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); return __s; } _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; } _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string(); } _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; } _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string(); } _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string(); } // generic format observers template , class _Allocator = allocator<_ECharT> > basic_string<_ECharT, _Traits, _Allocator> generic_string(const _Allocator& __a = _Allocator()) const { return string<_ECharT, _Traits, _Allocator>(__a); } std::string generic_string() const { return __pn_; } std::wstring generic_wstring() const { return string(); } std::string generic_u8string() const { return __pn_; } std::u16string generic_u16string() const { return string(); } std::u32string generic_u32string() const { return string(); } private: int __compare(__string_view) const; __string_view __root_name() const; __string_view __root_directory() const; __string_view __root_path_raw() const; __string_view __relative_path() const; __string_view __parent_path() const; __string_view __filename() const; __string_view __stem() const; __string_view __extension() const; public: // compare _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);} _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); } _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); } _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); } // decomposition _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); } _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); } _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); } _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); } _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); } _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); } _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());} _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); } // query - _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); } + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT { return __pn_.empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); } _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); } _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); } // iterators class _LIBCPP_TYPE_VIS iterator; typedef iterator const_iterator; iterator begin() const; iterator end() const; private: inline _LIBCPP_INLINE_VISIBILITY path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; } string_type __pn_; }; inline _LIBCPP_ALWAYS_INLINE void swap(path& __lhs, path& __rhs) _NOEXCEPT { __lhs.swap(__rhs); } _LIBCPP_FUNC_VIS size_t hash_value(const path& __p) _NOEXCEPT; inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) == 0; } inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) != 0; } inline _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) < 0; } inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) <= 0; } inline _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) > 0; } inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT { return __lhs.compare(__rhs) >= 0; } inline _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs, const path& __rhs) { return path(__lhs) /= __rhs; } template _LIBCPP_INLINE_VISIBILITY typename enable_if::value && is_same<_Traits, char_traits>::value, basic_ostream<_CharT, _Traits>& >::type operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { __os << std::__quoted(__p.native()); return __os; } template _LIBCPP_INLINE_VISIBILITY typename enable_if::value || !is_same<_Traits, char_traits>::value, basic_ostream<_CharT, _Traits>& >::type operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { __os << std::__quoted(__p.string<_CharT, _Traits>()); return __os; } template _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) { basic_string<_CharT, _Traits> __tmp; __is >> __quoted(__tmp); __p = __tmp; return __is; } template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_pathable<_Source>::value, path>::type u8path(const _Source& __s){ static_assert(is_same::__char_type, char>::value, "u8path(Source const&) requires Source have a character type of type 'char'"); return path(__s); } template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_pathable<_InputIt>::value, path>::type u8path(_InputIt __f, _InputIt __l) { static_assert(is_same::__char_type, char>::value, "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"); return path(__f, __l); } class _LIBCPP_TYPE_VIS path::iterator { public: typedef bidirectional_iterator_tag iterator_category; typedef path value_type; typedef std::ptrdiff_t difference_type; typedef const path* pointer; typedef const path& reference; typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator public: _LIBCPP_INLINE_VISIBILITY iterator() : __stashed_elem_(), __path_ptr_(nullptr), __entry_(), __state_(__singular) {} iterator(const iterator&) = default; ~iterator() = default; iterator& operator=(const iterator&) = default; _LIBCPP_INLINE_VISIBILITY reference operator*() const { return __stashed_elem_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return &__stashed_elem_; } _LIBCPP_INLINE_VISIBILITY iterator& operator++() { _LIBCPP_ASSERT(__state_ != __singular, "attempting to increment a singular iterator"); _LIBCPP_ASSERT(__state_ != __at_end, "attempting to increment the end iterator"); return __increment(); } _LIBCPP_INLINE_VISIBILITY iterator operator++(int) { iterator __it(*this); this->operator++(); return __it; } _LIBCPP_INLINE_VISIBILITY iterator& operator--() { _LIBCPP_ASSERT(__state_ != __singular, "attempting to decrement a singular iterator"); _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), "attempting to decrement the begin iterator"); return __decrement(); } _LIBCPP_INLINE_VISIBILITY iterator operator--(int) { iterator __it(*this); this->operator--(); return __it; } private: friend class path; static constexpr unsigned char __singular = 0; static constexpr unsigned char __at_end = 6; inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&, const iterator&); iterator& __increment(); iterator& __decrement(); path __stashed_elem_; const path* __path_ptr_; path::__string_view __entry_; unsigned char __state_; }; inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) { return __lhs.__path_ptr_ == __rhs.__path_ptr_ && __lhs.__entry_.data() == __rhs.__entry_.data(); } inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) { return !(__lhs == __rhs); } class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { public: _LIBCPP_INLINE_VISIBILITY filesystem_error(const string& __what, error_code __ec) : system_error(__ec, __what), __paths_(make_shared<_Storage>(path(), path())) {} _LIBCPP_INLINE_VISIBILITY filesystem_error(const string& __what, const path& __p1, error_code __ec) : system_error(__ec, __what), __paths_(make_shared<_Storage>(__p1, path())) {} _LIBCPP_INLINE_VISIBILITY filesystem_error(const string& __what, const path& __p1, const path& __p2, error_code __ec) : system_error(__ec, __what), __paths_(make_shared<_Storage>(__p1, __p2)) {} _LIBCPP_INLINE_VISIBILITY const path& path1() const _NOEXCEPT { return __paths_->first; } _LIBCPP_INLINE_VISIBILITY const path& path2() const _NOEXCEPT { return __paths_->second; } ~filesystem_error() override; // key function // TODO(ericwf): Create a custom error message. //const char* what() const _NOEXCEPT; private: typedef pair _Storage; shared_ptr<_Storage> __paths_; }; template _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE #ifndef _LIBCPP_NO_EXCEPTIONS void __throw_filesystem_error(_Args && ...__args) { throw filesystem_error(std::forward<_Args>(__args)...); } #else void __throw_filesystem_error(_Args&&...) { _VSTD::abort(); } #endif // operational functions _LIBCPP_FUNC_VIS path __canonical(const path&, const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __copy(const path& __from, const path& __to, copy_options __opt, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS bool __copy_file(const path& __from, const path& __to, copy_options __opt, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS bool __create_directories(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS bool __create_directory(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS bool __create_directory(const path& p, const path & attributes, error_code *ec=nullptr); _LIBCPP_FUNC_VIS void __create_directory_symlink(const path& __to, const path& __new_symlink, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __create_hard_link(const path& __to, const path& __new_hard_link, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __create_symlink(const path& __to, const path& __new_symlink, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS path __current_path(error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __current_path(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS bool __equivalent(const path&, const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS uintmax_t __file_size(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS bool __fs_is_empty(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS file_time_type __last_write_time(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS void __last_write_time(const path& p, file_time_type new_time, error_code *ec=nullptr); _LIBCPP_FUNC_VIS void __permissions(const path& p, perms prms, error_code *ec=nullptr); _LIBCPP_FUNC_VIS path __read_symlink(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS bool __remove(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS uintmax_t __remove_all(const path& p, error_code *ec=nullptr); _LIBCPP_FUNC_VIS void __rename(const path& from, const path& to, error_code *ec=nullptr); _LIBCPP_FUNC_VIS void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr); _LIBCPP_FUNC_VIS space_info __space(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS file_status __status(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS file_status __symlink_status(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS path __system_complete(const path&, error_code *__ec=nullptr); _LIBCPP_FUNC_VIS path __temp_directory_path(error_code *__ec=nullptr); inline _LIBCPP_INLINE_VISIBILITY path current_path() { return __current_path(); } inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) { return __current_path(&__ec); } inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) { __current_path(__p); } inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p, error_code& __ec) _NOEXCEPT { __current_path(__p, &__ec); } _LIBCPP_FUNC_VIS path absolute(const path&, const path& __p2 = current_path()); inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, const path& __base = current_path()) { return __canonical(__p, __base); } inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, error_code& __ec) { path __base = __current_path(&__ec); if (__ec) return {}; return __canonical(__p, __base, &__ec); } inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p, const path& __base, error_code& __ec) { return __canonical(__p, __base, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to) { __copy(__from, __to, copy_options::none); } inline _LIBCPP_INLINE_VISIBILITY -void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { +void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, copy_options __opt) { __copy(__from, __to, __opt); } inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, - copy_options __opt, error_code& __ec) _NOEXCEPT { + copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to) { return __copy_file(__from, __to, copy_options::none); } inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { return __copy_file(__from, __to, copy_options::none, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt) { return __copy_file(__from, __to, __opt); } inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from, const path& __to, copy_options __opt, error_code& __ec) _NOEXCEPT { return __copy_file(__from, __to, __opt, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing, const path& __new) { __copy_symlink(__existing, __new); } inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT { __copy_symlink(__ext, __new, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) { return __create_directories(__p); } inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p, error_code& __ec) _NOEXCEPT { return __create_directories(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) { return __create_directory(__p); } inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT { return __create_directory(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs) { return __create_directory(__p, __attrs); } inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT { return __create_directory(__p, __attrs, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __to, const path& __new) { __create_directory_symlink(__to, __new); } inline _LIBCPP_INLINE_VISIBILITY void create_directory_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT { __create_directory_symlink(__to, __new, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to, const path& __new) { __create_hard_link(__to, __new); } inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT { __create_hard_link(__to, __new, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to, const path& __new) { __create_symlink(__to, __new); } inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT { return __create_symlink(__to, __new, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) _NOEXCEPT { return __s.type() != file_type::none; } inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) _NOEXCEPT { return status_known(__s) && __s.type() != file_type::not_found; } inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p) { return exists(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec) _NOEXCEPT { auto __s = __status(__p, &__ec); if (status_known(__s)) __ec.clear(); return exists(__s); } inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2) { return __equivalent(__p1, __p2); } inline _LIBCPP_INLINE_VISIBILITY bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT { return __equivalent(__p1, __p2, &__ec); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) { return __file_size(__p); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT { return __file_size(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) { return __hard_link_count(__p); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT { return __hard_link_count(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) _NOEXCEPT { return __s.type() == file_type::block; } inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) { return is_block_file(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT { return is_block_file(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(file_status __s) _NOEXCEPT { return __s.type() == file_type::character; } inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) { return is_character_file(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT { return is_character_file(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) _NOEXCEPT { return __s.type() == file_type::directory; } inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) { return is_directory(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT { return is_directory(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) { return __fs_is_empty(__p); } inline _LIBCPP_INLINE_VISIBILITY -bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT { +bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) _NOEXCEPT { return __s.type() == file_type::fifo; } inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) { return is_fifo(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT { return is_fifo(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(file_status __s) _NOEXCEPT { return __s.type() == file_type::regular; } inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) { return is_regular_file(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT { return is_regular_file(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) _NOEXCEPT { return __s.type() == file_type::socket; } inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) { return is_socket(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT { return is_socket(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) _NOEXCEPT { return __s.type() == file_type::symlink; } inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) { return is_symlink(__symlink_status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT { return is_symlink(__symlink_status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) _NOEXCEPT { return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); } inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) { return is_other(__status(__p)); } inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p, error_code& __ec) _NOEXCEPT { return is_other(__status(__p, &__ec)); } inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p) { return __last_write_time(__p); } inline _LIBCPP_INLINE_VISIBILITY file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT { return __last_write_time(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t) { __last_write_time(__p, __t); } inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT { __last_write_time(__p, __t, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms) { __permissions(__p, __prms); } inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms, error_code& __ec) { __permissions(__p, __prms, &__ec); } inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) { return __read_symlink(__p); } inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p, error_code& __ec) { return __read_symlink(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) { return __remove(__p); } inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p, error_code& __ec) _NOEXCEPT { return __remove(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) { return __remove_all(__p); } inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p, error_code& __ec) _NOEXCEPT { return __remove_all(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to) { return __rename(__from, __to); } inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { return __rename(__from, __to, &__ec); } inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns) { return __resize_file(__p, __ns); } inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT { return __resize_file(__p, __ns, &__ec); } inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) { return __space(__p); } inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p, error_code& __ec) _NOEXCEPT { return __space(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) { return __status(__p); } inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p, error_code& __ec) _NOEXCEPT { return __status(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) { return __symlink_status(__p); } inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT { return __symlink_status(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY path system_complete(const path& __p) { return __system_complete(__p); } inline _LIBCPP_INLINE_VISIBILITY path system_complete(const path& __p, error_code& __ec) { return __system_complete(__p, &__ec); } inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() { return __temp_directory_path(); } inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) { return __temp_directory_path(&__ec); } class directory_entry { typedef _VSTD_FS::path _Path; public: // constructors and destructors directory_entry() _NOEXCEPT = default; directory_entry(directory_entry const&) = default; directory_entry(directory_entry&&) _NOEXCEPT = default; _LIBCPP_INLINE_VISIBILITY explicit directory_entry(_Path const& __p) : __p_(__p) {} ~directory_entry() {} directory_entry& operator=(directory_entry const&) = default; directory_entry& operator=(directory_entry&&) _NOEXCEPT = default; _LIBCPP_INLINE_VISIBILITY void assign(_Path const& __p) { __p_ = __p; } _LIBCPP_INLINE_VISIBILITY void replace_filename(_Path const& __p) { __p_ = __p_.parent_path() / __p; } _LIBCPP_INLINE_VISIBILITY _Path const& path() const _NOEXCEPT { return __p_; } _LIBCPP_INLINE_VISIBILITY operator const _Path&() const _NOEXCEPT { return __p_; } _LIBCPP_INLINE_VISIBILITY file_status status() const { return _VSTD_FS::status(__p_); } _LIBCPP_INLINE_VISIBILITY file_status status(error_code& __ec) const _NOEXCEPT { return _VSTD_FS::status(__p_, __ec); } _LIBCPP_INLINE_VISIBILITY file_status symlink_status() const { return _VSTD_FS::symlink_status(__p_); } _LIBCPP_INLINE_VISIBILITY file_status symlink_status(error_code& __ec) const _NOEXCEPT { return _VSTD_FS::symlink_status(__p_, __ec); } _LIBCPP_INLINE_VISIBILITY bool operator< (directory_entry const& __rhs) const _NOEXCEPT { return __p_ < __rhs.__p_; } _LIBCPP_INLINE_VISIBILITY bool operator==(directory_entry const& __rhs) const _NOEXCEPT { return __p_ == __rhs.__p_; } _LIBCPP_INLINE_VISIBILITY bool operator!=(directory_entry const& __rhs) const _NOEXCEPT { return __p_ != __rhs.__p_; } _LIBCPP_INLINE_VISIBILITY bool operator<=(directory_entry const& __rhs) const _NOEXCEPT { return __p_ <= __rhs.__p_; } _LIBCPP_INLINE_VISIBILITY bool operator> (directory_entry const& __rhs) const _NOEXCEPT { return __p_ > __rhs.__p_; } _LIBCPP_INLINE_VISIBILITY bool operator>=(directory_entry const& __rhs) const _NOEXCEPT { return __p_ >= __rhs.__p_; } private: _Path __p_; }; class directory_iterator; class recursive_directory_iterator; class __dir_stream; class __dir_element_proxy { public: inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() { return _VSTD::move(__elem_); } private: friend class directory_iterator; friend class recursive_directory_iterator; explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {} __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {} directory_entry __elem_; }; class directory_iterator { public: typedef directory_entry value_type; typedef ptrdiff_t difference_type; typedef value_type const* pointer; typedef value_type const& reference; typedef input_iterator_tag iterator_category; public: //ctor & dtor directory_iterator() _NOEXCEPT { } explicit directory_iterator(const path& __p) : directory_iterator(__p, nullptr) { } directory_iterator(const path& __p, directory_options __opts) : directory_iterator(__p, nullptr, __opts) { } - directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + directory_iterator(const path& __p, error_code& __ec) : directory_iterator(__p, &__ec) { } directory_iterator(const path& __p, directory_options __opts, - error_code& __ec) _NOEXCEPT + error_code& __ec) : directory_iterator(__p, &__ec, __opts) { } directory_iterator(const directory_iterator&) = default; directory_iterator(directory_iterator&&) = default; directory_iterator& operator=(const directory_iterator&) = default; directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT { // non-default implementation provided to support self-move assign. if (this != &__o) { __imp_ = _VSTD::move(__o.__imp_); } return *this; } ~directory_iterator() = default; const directory_entry& operator*() const { _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced"); return __dereference(); } const directory_entry* operator->() const { return &**this; } directory_iterator& operator++() { return __increment(); } __dir_element_proxy operator++(int) { __dir_element_proxy __p(**this); __increment(); return __p; } - directory_iterator& increment(error_code& __ec) _NOEXCEPT + directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } private: inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const directory_iterator& __lhs, const directory_iterator& __rhs) _NOEXCEPT; // construct the dir_stream _LIBCPP_FUNC_VIS directory_iterator(const path&, error_code *, directory_options = directory_options::none); _LIBCPP_FUNC_VIS directory_iterator& __increment(error_code * __ec = nullptr); _LIBCPP_FUNC_VIS const directory_entry& __dereference() const; private: shared_ptr<__dir_stream> __imp_; }; inline _LIBCPP_INLINE_VISIBILITY bool operator==(const directory_iterator& __lhs, const directory_iterator& __rhs) _NOEXCEPT { return __lhs.__imp_ == __rhs.__imp_; } inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const directory_iterator& __lhs, const directory_iterator& __rhs) _NOEXCEPT { return !(__lhs == __rhs); } // enable directory_iterator range-based for statements inline _LIBCPP_INLINE_VISIBILITY directory_iterator begin(directory_iterator __iter) _NOEXCEPT { return __iter; } inline _LIBCPP_INLINE_VISIBILITY directory_iterator end(const directory_iterator&) _NOEXCEPT { return directory_iterator(); } class recursive_directory_iterator { public: using value_type = directory_entry; using difference_type = std::ptrdiff_t; using pointer = directory_entry const *; using reference = directory_entry const &; using iterator_category = std::input_iterator_tag; public: // constructors and destructor _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator() _NOEXCEPT : __rec_(false) {} _LIBCPP_INLINE_VISIBILITY explicit recursive_directory_iterator(const path& __p, directory_options __xoptions = directory_options::none) : recursive_directory_iterator(__p, __xoptions, nullptr) { } _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator(const path& __p, - directory_options __xoptions, error_code& __ec) _NOEXCEPT + directory_options __xoptions, error_code& __ec) : recursive_directory_iterator(__p, __xoptions, &__ec) { } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + recursive_directory_iterator(const path& __p, error_code& __ec) : recursive_directory_iterator(__p, directory_options::none, &__ec) { } recursive_directory_iterator(const recursive_directory_iterator&) = default; recursive_directory_iterator(recursive_directory_iterator&&) = default; recursive_directory_iterator & operator=(const recursive_directory_iterator&) = default; _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator & operator=(recursive_directory_iterator&& __o) noexcept { // non-default implementation provided to support self-move assign. if (this != &__o) { __imp_ = _VSTD::move(__o.__imp_); __rec_ = __o.__rec_; } return *this; } ~recursive_directory_iterator() = default; _LIBCPP_INLINE_VISIBILITY const directory_entry& operator*() const { return __dereference(); } _LIBCPP_INLINE_VISIBILITY const directory_entry* operator->() const { return &__dereference(); } recursive_directory_iterator& operator++() { return __increment(); } _LIBCPP_INLINE_VISIBILITY __dir_element_proxy operator++(int) { __dir_element_proxy __p(**this); __increment(); return __p; } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT + recursive_directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } _LIBCPP_FUNC_VIS directory_options options() const; _LIBCPP_FUNC_VIS int depth() const; _LIBCPP_INLINE_VISIBILITY void pop() { __pop(); } _LIBCPP_INLINE_VISIBILITY void pop(error_code& __ec) { __pop(&__ec); } _LIBCPP_INLINE_VISIBILITY bool recursion_pending() const { return __rec_; } _LIBCPP_INLINE_VISIBILITY void disable_recursion_pending() { __rec_ = false; } private: recursive_directory_iterator(const path& __p, directory_options __opt, error_code *__ec); _LIBCPP_FUNC_VIS const directory_entry& __dereference() const; _LIBCPP_FUNC_VIS bool __try_recursion(error_code* __ec); _LIBCPP_FUNC_VIS void __advance(error_code* __ec=nullptr); _LIBCPP_FUNC_VIS recursive_directory_iterator& __increment(error_code *__ec=nullptr); _LIBCPP_FUNC_VIS void __pop(error_code* __ec=nullptr); inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const recursive_directory_iterator&, const recursive_directory_iterator&) _NOEXCEPT; struct __shared_imp; shared_ptr<__shared_imp> __imp_; bool __rec_; }; // class recursive_directory_iterator inline _LIBCPP_INLINE_VISIBILITY bool operator==(const recursive_directory_iterator& __lhs, const recursive_directory_iterator& __rhs) _NOEXCEPT { return __lhs.__imp_ == __rhs.__imp_; } _LIBCPP_INLINE_VISIBILITY inline bool operator!=(const recursive_directory_iterator& __lhs, const recursive_directory_iterator& __rhs) _NOEXCEPT { return !(__lhs == __rhs); } // enable recursive_directory_iterator range-based for statements inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT { return __iter; } inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT { return recursive_directory_iterator(); } _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM #endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM Index: projects/clang600-import/contrib/libc++/include/experimental/iterator =================================================================== --- projects/clang600-import/contrib/libc++/include/experimental/iterator (revision 327038) +++ projects/clang600-import/contrib/libc++/include/experimental/iterator (revision 327039) @@ -1,114 +1,114 @@ // -*- C++ -*- //===----------------------------- iterator -------------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_EXPERIMENTAL_ITERATOR #define _LIBCPP_EXPERIMENTAL_ITERATOR /* namespace std { namespace experimental { inline namespace fundamentals_v2 { template > class ostream_joiner { public: typedef charT char_type; typedef traits traits_type; typedef basic_ostream ostream_type; typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; ostream_joiner(ostream_type& s, const DelimT& delimiter); ostream_joiner(ostream_type& s, DelimT&& delimiter); template ostream_joiner& operator=(const T& value); ostream_joiner& operator*() noexcept; ostream_joiner& operator++() noexcept; ostream_joiner& operator++(int) noexcept; private: ostream_type* out_stream; // exposition only DelimT delim; // exposition only bool first_element; // exposition only }; template ostream_joiner, charT, traits> make_ostream_joiner(basic_ostream& os, DelimT&& delimiter); } // inline namespace fundamentals_v2 } // namespace experimental } // namespace std */ #include #if _LIBCPP_STD_VER > 11 #include _LIBCPP_BEGIN_NAMESPACE_LFTS template > class ostream_joiner { public: typedef _CharT char_type; typedef _Traits traits_type; typedef basic_ostream ostream_type; typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; ostream_joiner(ostream_type& __os, _Delim&& __d) - : __output(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} ostream_joiner(ostream_type& __os, const _Delim& __d) - : __output(_VSTD::addressof(__os)), __delim(__d), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} template ostream_joiner& operator=(const _Tp& __v) { if (!__first) - *__output << __delim; + *__output_iter << __delim; __first = false; - *__output << __v; + *__output_iter << __v; return *this; } ostream_joiner& operator*() _NOEXCEPT { return *this; } ostream_joiner& operator++() _NOEXCEPT { return *this; } ostream_joiner& operator++(int) _NOEXCEPT { return *this; } private: - ostream_type* __output; + ostream_type* __output_iter; _Delim __delim; bool __first; }; template ostream_joiner::type, _CharT, _Traits> make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d) { return ostream_joiner::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); } _LIBCPP_END_NAMESPACE_LFTS #endif /* _LIBCPP_STD_VER > 11 */ #endif // _LIBCPP_EXPERIMENTAL_ITERATOR Index: projects/clang600-import/contrib/libc++/include/forward_list =================================================================== --- projects/clang600-import/contrib/libc++/include/forward_list (revision 327038) +++ projects/clang600-import/contrib/libc++/include/forward_list (revision 327039) @@ -1,1725 +1,1725 @@ // -*- C++ -*- //===----------------------- forward_list ---------------------------------===// // // 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_FORWARD_LIST #define _LIBCPP_FORWARD_LIST /* forward_list synopsis namespace std { template > class forward_list { public: typedef T value_type; typedef Allocator allocator_type; typedef value_type& reference; typedef const value_type& const_reference; typedef typename allocator_traits::pointer pointer; typedef typename allocator_traits::const_pointer const_pointer; typedef typename allocator_traits::size_type size_type; typedef typename allocator_traits::difference_type difference_type; typedef
iterator; typedef
const_iterator; forward_list() noexcept(is_nothrow_default_constructible::value); explicit forward_list(const allocator_type& a); explicit forward_list(size_type n); explicit forward_list(size_type n, const allocator_type& a); // C++14 forward_list(size_type n, const value_type& v); forward_list(size_type n, const value_type& v, const allocator_type& a); template forward_list(InputIterator first, InputIterator last); template forward_list(InputIterator first, InputIterator last, const allocator_type& a); forward_list(const forward_list& x); forward_list(const forward_list& x, const allocator_type& a); forward_list(forward_list&& x) noexcept(is_nothrow_move_constructible::value); forward_list(forward_list&& x, const allocator_type& a); forward_list(initializer_list il); forward_list(initializer_list il, const allocator_type& a); ~forward_list(); forward_list& operator=(const forward_list& x); forward_list& operator=(forward_list&& x) noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value); forward_list& operator=(initializer_list il); template void assign(InputIterator first, InputIterator last); void assign(size_type n, const value_type& v); 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; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; iterator before_begin() noexcept; const_iterator before_begin() const noexcept; const_iterator cbefore_begin() const noexcept; bool empty() const noexcept; size_type max_size() const noexcept; reference front(); const_reference front() const; template reference emplace_front(Args&&... args); // reference in C++17 void push_front(const value_type& v); void push_front(value_type&& v); void pop_front(); template iterator emplace_after(const_iterator p, Args&&... args); iterator insert_after(const_iterator p, const value_type& v); iterator insert_after(const_iterator p, value_type&& v); iterator insert_after(const_iterator p, size_type n, const value_type& v); template iterator insert_after(const_iterator p, InputIterator first, InputIterator last); iterator insert_after(const_iterator p, initializer_list il); iterator erase_after(const_iterator p); iterator erase_after(const_iterator first, const_iterator last); void swap(forward_list& x) noexcept(allocator_traits::is_always_equal::value); // C++17 void resize(size_type n); void resize(size_type n, const value_type& v); void clear() noexcept; void splice_after(const_iterator p, forward_list& x); void splice_after(const_iterator p, forward_list&& x); void splice_after(const_iterator p, forward_list& x, const_iterator i); void splice_after(const_iterator p, forward_list&& x, const_iterator i); void splice_after(const_iterator p, forward_list& x, const_iterator first, const_iterator last); void splice_after(const_iterator p, forward_list&& x, const_iterator first, const_iterator last); void remove(const value_type& v); template void remove_if(Predicate pred); void unique(); template void unique(BinaryPredicate binary_pred); void merge(forward_list& x); void merge(forward_list&& x); template void merge(forward_list& x, Compare comp); template void merge(forward_list&& x, Compare comp); void sort(); template void sort(Compare comp); void reverse() noexcept; }; template bool operator==(const forward_list& x, const forward_list& y); template bool operator< (const forward_list& x, const forward_list& y); template bool operator!=(const forward_list& x, const forward_list& y); template bool operator> (const forward_list& x, const forward_list& y); template bool operator>=(const forward_list& x, const forward_list& y); template bool operator<=(const forward_list& x, const forward_list& y); template void swap(forward_list& x, forward_list& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD template struct __forward_list_node; template struct __forward_begin_node; template struct __forward_list_node_value_type; template struct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > { typedef _Tp type; }; template struct __forward_node_traits { typedef typename remove_cv< typename pointer_traits<_NodePtr>::element_type>::type __node; typedef typename __forward_list_node_value_type<__node>::type __node_value_type; typedef _NodePtr __node_pointer; typedef __forward_begin_node<_NodePtr> __begin_node; typedef typename __rebind_pointer<_NodePtr, __begin_node>::type __begin_node_pointer; typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; #if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB) typedef __begin_node_pointer __iter_node_pointer; #else typedef typename conditional< is_pointer<__void_pointer>::value, __begin_node_pointer, __node_pointer >::type __iter_node_pointer; #endif typedef typename conditional< is_same<__iter_node_pointer, __node_pointer>::value, __begin_node_pointer, __node_pointer >::type __non_iter_node_pointer; _LIBCPP_INLINE_VISIBILITY static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) { return __p; } _LIBCPP_INLINE_VISIBILITY static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) { return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p)); } }; template struct __forward_begin_node { typedef _NodePtr pointer; typedef typename __rebind_pointer<_NodePtr, __forward_begin_node>::type __begin_node_pointer; pointer __next_; _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {} _LIBCPP_INLINE_VISIBILITY __begin_node_pointer __next_as_begin() const { return static_cast<__begin_node_pointer>(__next_); } }; template struct _LIBCPP_HIDDEN __begin_node_of { typedef __forward_begin_node< typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type > type; }; template struct __forward_list_node : public __begin_node_of<_Tp, _VoidPtr>::type { typedef _Tp value_type; value_type __value_; }; template > class _LIBCPP_TEMPLATE_VIS forward_list; template class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; template class _LIBCPP_TEMPLATE_VIS __forward_list_iterator { typedef __forward_node_traits<_NodePtr> __traits; typedef typename __traits::__node_pointer __node_pointer; typedef typename __traits::__begin_node_pointer __begin_node_pointer; typedef typename __traits::__iter_node_pointer __iter_node_pointer; typedef typename __traits::__void_pointer __void_pointer; __iter_node_pointer __ptr_; _LIBCPP_INLINE_VISIBILITY __begin_node_pointer __get_begin() const { return static_cast<__begin_node_pointer>( static_cast<__void_pointer>(__ptr_)); } _LIBCPP_INLINE_VISIBILITY __node_pointer __get_unsafe_node_pointer() const { return static_cast<__node_pointer>( static_cast<__void_pointer>(__ptr_)); } _LIBCPP_INLINE_VISIBILITY explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {} _LIBCPP_INLINE_VISIBILITY explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__traits::__as_iter_node(__p)) {} _LIBCPP_INLINE_VISIBILITY explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__traits::__as_iter_node(__p)) {} template friend class _LIBCPP_TEMPLATE_VIS forward_list; template friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator; public: typedef forward_iterator_tag iterator_category; typedef typename __traits::__node_value_type value_type; typedef value_type& reference; typedef typename pointer_traits<__node_pointer>::difference_type difference_type; typedef typename __rebind_pointer<__node_pointer, value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_unsafe_node_pointer()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return pointer_traits::pointer_to(__get_unsafe_node_pointer()->__value_); } _LIBCPP_INLINE_VISIBILITY __forward_list_iterator& operator++() { __ptr_ = __traits::__as_iter_node(__ptr_->__next_); return *this; } _LIBCPP_INLINE_VISIBILITY __forward_list_iterator operator++(int) { __forward_list_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {return !(__x == __y);} }; template class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator { static_assert((!is_const::element_type>::value), ""); typedef _NodeConstPtr _NodePtr; typedef __forward_node_traits<_NodePtr> __traits; typedef typename __traits::__node __node; typedef typename __traits::__node_pointer __node_pointer; typedef typename __traits::__begin_node_pointer __begin_node_pointer; typedef typename __traits::__iter_node_pointer __iter_node_pointer; typedef typename __traits::__void_pointer __void_pointer; __iter_node_pointer __ptr_; __begin_node_pointer __get_begin() const { return static_cast<__begin_node_pointer>( static_cast<__void_pointer>(__ptr_)); } __node_pointer __get_unsafe_node_pointer() const { return static_cast<__node_pointer>( static_cast<__void_pointer>(__ptr_)); } _LIBCPP_INLINE_VISIBILITY explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {} _LIBCPP_INLINE_VISIBILITY explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__traits::__as_iter_node(__p)) {} _LIBCPP_INLINE_VISIBILITY explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__traits::__as_iter_node(__p)) {} template friend class forward_list; public: typedef forward_iterator_tag iterator_category; typedef typename __traits::__node_value_type value_type; typedef const value_type& reference; typedef typename pointer_traits<__node_pointer>::difference_type difference_type; typedef typename __rebind_pointer<__node_pointer, const value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} _LIBCPP_INLINE_VISIBILITY __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __get_unsafe_node_pointer()->__value_;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to( __get_unsafe_node_pointer()->__value_);} _LIBCPP_INLINE_VISIBILITY __forward_list_const_iterator& operator++() { __ptr_ = __traits::__as_iter_node(__ptr_->__next_); return *this; } _LIBCPP_INLINE_VISIBILITY __forward_list_const_iterator operator++(int) { __forward_list_const_iterator __t(*this); ++(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __forward_list_const_iterator& __x, const __forward_list_const_iterator& __y) {return __x.__ptr_ == __y.__ptr_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __forward_list_const_iterator& __x, const __forward_list_const_iterator& __y) {return !(__x == __y);} }; template class __forward_list_base { protected: typedef _Tp value_type; typedef _Alloc allocator_type; typedef typename allocator_traits::void_pointer void_pointer; typedef __forward_list_node __node; typedef typename __begin_node_of::type __begin_node; typedef typename __rebind_alloc_helper, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; typedef typename __rebind_alloc_helper< allocator_traits, __begin_node >::type __begin_node_allocator; typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer; __compressed_pair<__begin_node, __node_allocator> __before_begin_; _LIBCPP_INLINE_VISIBILITY __begin_node_pointer __before_begin() _NOEXCEPT {return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());} _LIBCPP_INLINE_VISIBILITY __begin_node_pointer __before_begin() const _NOEXCEPT {return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));} _LIBCPP_INLINE_VISIBILITY __node_allocator& __alloc() _NOEXCEPT {return __before_begin_.second();} _LIBCPP_INLINE_VISIBILITY const __node_allocator& __alloc() const _NOEXCEPT {return __before_begin_.second();} typedef __forward_list_iterator<__node_pointer> iterator; typedef __forward_list_const_iterator<__node_pointer> const_iterator; _LIBCPP_INLINE_VISIBILITY __forward_list_base() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) : __before_begin_(__begin_node()) {} _LIBCPP_INLINE_VISIBILITY __forward_list_base(const allocator_type& __a) : __before_begin_(__begin_node(), __node_allocator(__a)) {} #ifndef _LIBCPP_CXX03_LANG public: _LIBCPP_INLINE_VISIBILITY __forward_list_base(__forward_list_base&& __x) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); #endif // _LIBCPP_CXX03_LANG private: __forward_list_base(const __forward_list_base&); __forward_list_base& operator=(const __forward_list_base&); public: ~__forward_list_base(); protected: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __forward_list_base& __x) {__copy_assign_alloc(__x, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__forward_list_base& __x) _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable<__node_allocator>::value) {__move_assign_alloc(__x, integral_constant());} public: _LIBCPP_INLINE_VISIBILITY void swap(__forward_list_base& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || __is_nothrow_swappable<__node_allocator>::value); #endif protected: void clear() _NOEXCEPT; private: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __forward_list_base&, false_type) {} _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __forward_list_base& __x, true_type) { if (__alloc() != __x.__alloc()) clear(); __alloc() = __x.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__forward_list_base& __x, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {__alloc() = _VSTD::move(__x.__alloc());} }; #ifndef _LIBCPP_CXX03_LANG template inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) : __before_begin_(_VSTD::move(__x.__before_begin_)) { __x.__before_begin()->__next_ = nullptr; } template inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, const allocator_type& __a) : __before_begin_(__begin_node(), __node_allocator(__a)) { if (__alloc() == __x.__alloc()) { __before_begin()->__next_ = __x.__before_begin()->__next_; __x.__before_begin()->__next_ = nullptr; } } #endif // _LIBCPP_CXX03_LANG template __forward_list_base<_Tp, _Alloc>::~__forward_list_base() { clear(); } template inline void __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || __is_nothrow_swappable<__node_allocator>::value) #endif { __swap_allocator(__alloc(), __x.__alloc(), integral_constant()); using _VSTD::swap; swap(__before_begin()->__next_, __x.__before_begin()->__next_); } template void __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT { __node_allocator& __a = __alloc(); for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) { __node_pointer __next = __p->__next_; __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); __node_traits::deallocate(__a, __p, 1); __p = __next; } __before_begin()->__next_ = nullptr; } template */> class _LIBCPP_TEMPLATE_VIS forward_list : private __forward_list_base<_Tp, _Alloc> { typedef __forward_list_base<_Tp, _Alloc> base; typedef typename base::__node_allocator __node_allocator; typedef typename base::__node __node; typedef typename base::__node_traits __node_traits; typedef typename base::__node_pointer __node_pointer; typedef typename base::__begin_node_pointer __begin_node_pointer; public: typedef _Tp value_type; typedef _Alloc allocator_type; static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); typedef value_type& reference; typedef const value_type& const_reference; typedef typename allocator_traits::pointer pointer; typedef typename allocator_traits::const_pointer const_pointer; typedef typename allocator_traits::size_type size_type; typedef typename allocator_traits::difference_type difference_type; typedef typename base::iterator iterator; typedef typename base::const_iterator const_iterator; _LIBCPP_INLINE_VISIBILITY forward_list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {} // = default; _LIBCPP_INLINE_VISIBILITY explicit forward_list(const allocator_type& __a); explicit forward_list(size_type __n); #if _LIBCPP_STD_VER > 11 explicit forward_list(size_type __n, const allocator_type& __a); #endif forward_list(size_type __n, const value_type& __v); forward_list(size_type __n, const value_type& __v, const allocator_type& __a); template forward_list(_InputIterator __f, _InputIterator __l, typename enable_if< __is_input_iterator<_InputIterator>::value >::type* = nullptr); template forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a, typename enable_if< __is_input_iterator<_InputIterator>::value >::type* = nullptr); forward_list(const forward_list& __x); forward_list(const forward_list& __x, const allocator_type& __a); forward_list& operator=(const forward_list& __x); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY forward_list(forward_list&& __x) _NOEXCEPT_(is_nothrow_move_constructible::value) : base(_VSTD::move(__x)) {} forward_list(forward_list&& __x, const allocator_type& __a); forward_list(initializer_list __il); forward_list(initializer_list __il, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY forward_list& operator=(forward_list&& __x) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value); _LIBCPP_INLINE_VISIBILITY forward_list& operator=(initializer_list __il); _LIBCPP_INLINE_VISIBILITY void assign(initializer_list __il); #endif // _LIBCPP_CXX03_LANG // ~forward_list() = default; template typename enable_if < __is_input_iterator<_InputIterator>::value, void >::type assign(_InputIterator __f, _InputIterator __l); void assign(size_type __n, const value_type& __v); _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(base::__alloc());} _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(base::__before_begin()->__next_);} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return const_iterator(base::__before_begin()->__next_);} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return iterator(nullptr);} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(nullptr);} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return const_iterator(base::__before_begin()->__next_);} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return const_iterator(nullptr);} _LIBCPP_INLINE_VISIBILITY iterator before_begin() _NOEXCEPT {return iterator(base::__before_begin());} _LIBCPP_INLINE_VISIBILITY const_iterator before_begin() const _NOEXCEPT {return const_iterator(base::__before_begin());} _LIBCPP_INLINE_VISIBILITY const_iterator cbefore_begin() const _NOEXCEPT {return const_iterator(base::__before_begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::__before_begin()->__next_ == nullptr;} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { return std::min( __node_traits::max_size(base::__alloc()), numeric_limits::max()); } _LIBCPP_INLINE_VISIBILITY reference front() {return base::__before_begin()->__next_->__value_;} _LIBCPP_INLINE_VISIBILITY const_reference front() const {return base::__before_begin()->__next_->__value_;} #ifndef _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 14 template reference emplace_front(_Args&&... __args); #else template void emplace_front(_Args&&... __args); #endif void push_front(value_type&& __v); #endif // _LIBCPP_CXX03_LANG void push_front(const value_type& __v); void pop_front(); #ifndef _LIBCPP_CXX03_LANG template iterator emplace_after(const_iterator __p, _Args&&... __args); iterator insert_after(const_iterator __p, value_type&& __v); iterator insert_after(const_iterator __p, initializer_list __il) {return insert_after(__p, __il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG iterator insert_after(const_iterator __p, const value_type& __v); iterator insert_after(const_iterator __p, size_type __n, const value_type& __v); template _LIBCPP_INLINE_VISIBILITY typename enable_if < __is_input_iterator<_InputIterator>::value, iterator >::type insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); iterator erase_after(const_iterator __p); iterator erase_after(const_iterator __f, const_iterator __l); _LIBCPP_INLINE_VISIBILITY void swap(forward_list& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) #endif {base::swap(__x);} void resize(size_type __n); void resize(size_type __n, const value_type& __v); _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {base::clear();} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x); _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i); _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l); #endif // _LIBCPP_CXX03_LANG void splice_after(const_iterator __p, forward_list& __x); void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); void splice_after(const_iterator __p, forward_list& __x, const_iterator __f, const_iterator __l); void remove(const value_type& __v); template void remove_if(_Predicate __pred); _LIBCPP_INLINE_VISIBILITY void unique() {unique(__equal_to());} template void unique(_BinaryPredicate __binary_pred); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x) {merge(__x, __less());} template _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x, _Compare __comp) {merge(__x, _VSTD::move(__comp));} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list& __x) {merge(__x, __less());} template void merge(forward_list& __x, _Compare __comp); _LIBCPP_INLINE_VISIBILITY void sort() {sort(__less());} template _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp); void reverse() _NOEXCEPT; private: #ifndef _LIBCPP_CXX03_LANG void __move_assign(forward_list& __x, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value); void __move_assign(forward_list& __x, false_type); #endif // _LIBCPP_CXX03_LANG template static __node_pointer __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp); template static __node_pointer __sort(__node_pointer __f, difference_type __sz, _Compare& __comp); }; template inline forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) : base(__a) { } template forward_list<_Tp, _Alloc>::forward_list(size_type __n) { if (__n > 0) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); __h->__next_ = nullptr; __p->__next_ = __h.release(); } } } #if _LIBCPP_STD_VER > 11 template forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __base_alloc) : base ( __base_alloc ) { if (__n > 0) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); __h->__next_ = nullptr; __p->__next_ = __h.release(); } } } #endif template forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) { insert_after(cbefore_begin(), __n, __v); } template forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a) { insert_after(cbefore_begin(), __n, __v); } template template forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, typename enable_if< __is_input_iterator<_InputIterator>::value >::type*) { insert_after(cbefore_begin(), __f, __l); } template template forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a, typename enable_if< __is_input_iterator<_InputIterator>::value >::type*) : base(__a) { insert_after(cbefore_begin(), __f, __l); } template forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x) : base(allocator_type( __node_traits::select_on_container_copy_construction(__x.__alloc()) ) ) { insert_after(cbefore_begin(), __x.begin(), __x.end()); } template forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, const allocator_type& __a) : base(__a) { insert_after(cbefore_begin(), __x.begin(), __x.end()); } template forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) { if (this != &__x) { base::__copy_assign_alloc(__x); assign(__x.begin(), __x.end()); } return *this; } #ifndef _LIBCPP_CXX03_LANG template forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, const allocator_type& __a) : base(_VSTD::move(__x), __a) { if (base::__alloc() != __x.__alloc()) { typedef move_iterator _Ip; insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end())); } } template forward_list<_Tp, _Alloc>::forward_list(initializer_list __il) { insert_after(cbefore_begin(), __il.begin(), __il.end()); } template forward_list<_Tp, _Alloc>::forward_list(initializer_list __il, const allocator_type& __a) : base(__a) { insert_after(cbefore_begin(), __il.begin(), __il.end()); } template void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) _NOEXCEPT_(is_nothrow_move_assignable::value) { clear(); base::__move_assign_alloc(__x); base::__before_begin()->__next_ = __x.__before_begin()->__next_; __x.__before_begin()->__next_ = nullptr; } template void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) { if (base::__alloc() == __x.__alloc()) __move_assign(__x, true_type()); else { typedef move_iterator _Ip; assign(_Ip(__x.begin()), _Ip(__x.end())); } } template inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value) { __move_assign(__x, integral_constant()); return *this; } template inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(initializer_list __il) { assign(__il.begin(), __il.end()); return *this; } #endif // _LIBCPP_CXX03_LANG template template typename enable_if < __is_input_iterator<_InputIterator>::value, void >::type forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) { iterator __i = before_begin(); iterator __j = _VSTD::next(__i); iterator __e = end(); for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f) *__j = *__f; if (__j == __e) insert_after(__i, __f, __l); else erase_after(__i, __e); } template void forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) { iterator __i = before_begin(); iterator __j = _VSTD::next(__i); iterator __e = end(); for (; __j != __e && __n > 0; --__n, ++__i, ++__j) *__j = __v; if (__j == __e) insert_after(__i, __n, __v); else erase_after(__i, __e); } #ifndef _LIBCPP_CXX03_LANG template inline void forward_list<_Tp, _Alloc>::assign(initializer_list __il) { assign(__il.begin(), __il.end()); } template template #if _LIBCPP_STD_VER > 14 typename forward_list<_Tp, _Alloc>::reference #else void #endif forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...); __h->__next_ = base::__before_begin()->__next_; base::__before_begin()->__next_ = __h.release(); #if _LIBCPP_STD_VER > 14 return base::__before_begin()->__next_->__value_; #endif } template void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); __h->__next_ = base::__before_begin()->__next_; base::__before_begin()->__next_ = __h.release(); } #endif // _LIBCPP_CXX03_LANG template void forward_list<_Tp, _Alloc>::push_front(const value_type& __v) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); __h->__next_ = base::__before_begin()->__next_; base::__before_begin()->__next_ = __h.release(); } template void forward_list<_Tp, _Alloc>::pop_front() { __node_allocator& __a = base::__alloc(); __node_pointer __p = base::__before_begin()->__next_; base::__before_begin()->__next_ = __p->__next_; __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); __node_traits::deallocate(__a, __p, 1); } #ifndef _LIBCPP_CXX03_LANG template template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) { __begin_node_pointer const __r = __p.__get_begin(); __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...); __h->__next_ = __r->__next_; __r->__next_ = __h.release(); return iterator(__r->__next_); } template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) { __begin_node_pointer const __r = __p.__get_begin(); __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); __h->__next_ = __r->__next_; __r->__next_ = __h.release(); return iterator(__r->__next_); } #endif // _LIBCPP_CXX03_LANG template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) { __begin_node_pointer const __r = __p.__get_begin(); __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); __h->__next_ = __r->__next_; __r->__next_ = __h.release(); return iterator(__r->__next_); } template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const value_type& __v) { __begin_node_pointer __r = __p.__get_begin(); if (__n > 0) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); __node_pointer __first = __h.release(); __node_pointer __last = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (--__n; __n != 0; --__n, __last = __last->__next_) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); __last->__next_ = __h.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (__first != nullptr) { __node_pointer __next = __first->__next_; __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); __node_traits::deallocate(__a, __first, 1); __first = __next; } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __last->__next_ = __r->__next_; __r->__next_ = __first; __r = static_cast<__begin_node_pointer>(__last); } return iterator(__r); } template template typename enable_if < __is_input_iterator<_InputIterator>::value, typename forward_list<_Tp, _Alloc>::iterator >::type forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l) { __begin_node_pointer __r = __p.__get_begin(); if (__f != __l) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); __node_pointer __first = __h.release(); __node_pointer __last = __first; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); __last->__next_ = __h.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (__first != nullptr) { __node_pointer __next = __first->__next_; __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); __node_traits::deallocate(__a, __first, 1); __first = __next; } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __last->__next_ = __r->__next_; __r->__next_ = __first; __r = static_cast<__begin_node_pointer>(__last); } return iterator(__r); } template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) { __begin_node_pointer __p = __f.__get_begin(); __node_pointer __n = __p->__next_; __p->__next_ = __n->__next_; __node_allocator& __a = base::__alloc(); __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); __node_traits::deallocate(__a, __n, 1); return iterator(__p->__next_); } template typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) { __node_pointer __e = __l.__get_unsafe_node_pointer(); if (__f != __l) { __begin_node_pointer __bp = __f.__get_begin(); __node_pointer __n = __bp->__next_; if (__n != __e) { __bp->__next_ = __e; __node_allocator& __a = base::__alloc(); do { __node_pointer __tmp = __n->__next_; __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); __node_traits::deallocate(__a, __n, 1); __n = __tmp; } while (__n != __e); } } return iterator(__e); } template void forward_list<_Tp, _Alloc>::resize(size_type __n) { size_type __sz = 0; iterator __p = before_begin(); iterator __i = begin(); iterator __e = end(); for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) ; if (__i != __e) erase_after(__p, __e); else { __n -= __sz; if (__n > 0) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); __h->__next_ = nullptr; __ptr->__next_ = __h.release(); } } } } template void forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) { size_type __sz = 0; iterator __p = before_begin(); iterator __i = begin(); iterator __e = end(); for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) ; if (__i != __e) erase_after(__p, __e); else { __n -= __sz; if (__n > 0) { __node_allocator& __a = base::__alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1)); for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) { __h.reset(__node_traits::allocate(__a, 1)); __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); __h->__next_ = nullptr; __ptr->__next_ = __h.release(); } } } } template void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& __x) { if (!__x.empty()) { if (__p.__get_begin()->__next_ != nullptr) { const_iterator __lm1 = __x.before_begin(); while (__lm1.__get_begin()->__next_ != nullptr) ++__lm1; __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; } __p.__get_begin()->__next_ = __x.__before_begin()->__next_; __x.__before_begin()->__next_ = nullptr; } } template void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& /*__other*/, const_iterator __i) { const_iterator __lm1 = _VSTD::next(__i); if (__p != __i && __p != __lm1) { __i.__get_begin()->__next_ = __lm1.__get_begin()->__next_; __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; __p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer(); } } template void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& /*__other*/, const_iterator __f, const_iterator __l) { if (__f != __l && __p != __f) { const_iterator __lm1 = __f; while (__lm1.__get_begin()->__next_ != __l.__get_begin()) ++__lm1; if (__f != __lm1) { __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_; __p.__get_begin()->__next_ = __f.__get_begin()->__next_; __f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer(); } } } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x) { splice_after(__p, __x); } template inline _LIBCPP_INLINE_VISIBILITY void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x, const_iterator __i) { splice_after(__p, __x, __i); } template inline _LIBCPP_INLINE_VISIBILITY void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l) { splice_after(__p, __x, __f, __l); } #endif // _LIBCPP_CXX03_LANG template void forward_list<_Tp, _Alloc>::remove(const value_type& __v) { forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing iterator __e = end(); for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) { if (__i.__get_begin()->__next_->__value_ == __v) { iterator __j = _VSTD::next(__i, 2); for (; __j != __e && *__j == __v; ++__j) ; __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j); if (__j == __e) break; __i = __j; } else ++__i; } } template template void forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) { iterator __e = end(); for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) { if (__pred(__i.__get_begin()->__next_->__value_)) { iterator __j = _VSTD::next(__i, 2); for (; __j != __e && __pred(*__j); ++__j) ; erase_after(__i, __j); if (__j == __e) break; __i = __j; } else ++__i; } } template template void forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) { for (iterator __i = begin(), __e = end(); __i != __e;) { iterator __j = _VSTD::next(__i); for (; __j != __e && __binary_pred(*__i, *__j); ++__j) ; if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer()) erase_after(__i, __j); __i = __j; } } template template void forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) { if (this != &__x) { base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_, __x.__before_begin()->__next_, __comp); __x.__before_begin()->__next_ = nullptr; } } template template typename forward_list<_Tp, _Alloc>::__node_pointer forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp) { if (__f1 == nullptr) return __f2; if (__f2 == nullptr) return __f1; __node_pointer __r; if (__comp(__f2->__value_, __f1->__value_)) { __node_pointer __t = __f2; while (__t->__next_ != nullptr && __comp(__t->__next_->__value_, __f1->__value_)) __t = __t->__next_; __r = __f2; __f2 = __t->__next_; __t->__next_ = __f1; } else __r = __f1; __node_pointer __p = __f1; __f1 = __f1->__next_; while (__f1 != nullptr && __f2 != nullptr) { if (__comp(__f2->__value_, __f1->__value_)) { __node_pointer __t = __f2; while (__t->__next_ != nullptr && __comp(__t->__next_->__value_, __f1->__value_)) __t = __t->__next_; __p->__next_ = __f2; __f2 = __t->__next_; __t->__next_ = __f1; } __p = __f1; __f1 = __f1->__next_; } if (__f2 != nullptr) __p->__next_ = __f2; return __r; } template template inline void forward_list<_Tp, _Alloc>::sort(_Compare __comp) { base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_, _VSTD::distance(begin(), end()), __comp); } template template typename forward_list<_Tp, _Alloc>::__node_pointer forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, _Compare& __comp) { switch (__sz) { case 0: case 1: return __f1; case 2: if (__comp(__f1->__next_->__value_, __f1->__value_)) { __node_pointer __t = __f1->__next_; __t->__next_ = __f1; __f1->__next_ = nullptr; __f1 = __t; } return __f1; } difference_type __sz1 = __sz / 2; difference_type __sz2 = __sz - __sz1; __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer(); __node_pointer __f2 = __t->__next_; __t->__next_ = nullptr; return __merge(__sort(__f1, __sz1, __comp), __sort(__f2, __sz2, __comp), __comp); } template void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT { __node_pointer __p = base::__before_begin()->__next_; if (__p != nullptr) { __node_pointer __f = __p->__next_; __p->__next_ = nullptr; while (__f != nullptr) { __node_pointer __t = __f->__next_; __f->__next_ = __p; __p = __f; __f = __t; } base::__before_begin()->__next_ = __p; } } template bool operator==(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { typedef forward_list<_Tp, _Alloc> _Cp; typedef typename _Cp::const_iterator _Ip; _Ip __ix = __x.begin(); _Ip __ex = __x.end(); _Ip __iy = __y.begin(); _Ip __ey = __y.end(); for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy) if (!(*__ix == *__iy)) return false; return (__ix == __ex) == (__iy == __ey); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_FORWARD_LIST Index: projects/clang600-import/contrib/libc++/include/fstream =================================================================== --- projects/clang600-import/contrib/libc++/include/fstream (revision 327038) +++ projects/clang600-import/contrib/libc++/include/fstream (revision 327039) @@ -1,1484 +1,1484 @@ // -*- C++ -*- //===------------------------- fstream ------------------------------------===// // // 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_FSTREAM #define _LIBCPP_FSTREAM /* fstream synopsis template > class basic_filebuf : public basic_streambuf { public: typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // 27.9.1.2 Constructors/destructor: basic_filebuf(); basic_filebuf(basic_filebuf&& rhs); virtual ~basic_filebuf(); // 27.9.1.3 Assign/swap: basic_filebuf& operator=(basic_filebuf&& rhs); void swap(basic_filebuf& rhs); // 27.9.1.4 Members: bool is_open() const; basic_filebuf* open(const char* s, ios_base::openmode mode); basic_filebuf* open(const string& s, ios_base::openmode mode); basic_filebuf* close(); protected: // 27.9.1.5 Overridden virtual functions: virtual streamsize showmanyc(); virtual int_type underflow(); virtual int_type uflow(); virtual int_type pbackfail(int_type c = traits_type::eof()); virtual int_type overflow (int_type c = traits_type::eof()); virtual basic_streambuf* setbuf(char_type* s, streamsize n); virtual pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out); virtual int sync(); virtual void imbue(const locale& loc); }; template void swap(basic_filebuf& x, basic_filebuf& y); typedef basic_filebuf filebuf; typedef basic_filebuf wfilebuf; template > class basic_ifstream : public basic_istream { public: typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; basic_ifstream(); explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); basic_ifstream(basic_ifstream&& rhs); basic_ifstream& operator=(basic_ifstream&& rhs); void swap(basic_ifstream& rhs); basic_filebuf* rdbuf() const; bool is_open() const; void open(const char* s, ios_base::openmode mode = ios_base::in); void open(const string& s, ios_base::openmode mode = ios_base::in); void close(); }; template void swap(basic_ifstream& x, basic_ifstream& y); typedef basic_ifstream ifstream; typedef basic_ifstream wifstream; template > class basic_ofstream : public basic_ostream { public: typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; basic_ofstream(); explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); basic_ofstream(basic_ofstream&& rhs); basic_ofstream& operator=(basic_ofstream&& rhs); void swap(basic_ofstream& rhs); basic_filebuf* rdbuf() const; bool is_open() const; void open(const char* s, ios_base::openmode mode = ios_base::out); void open(const string& s, ios_base::openmode mode = ios_base::out); void close(); }; template void swap(basic_ofstream& x, basic_ofstream& y); typedef basic_ofstream ofstream; typedef basic_ofstream wofstream; template > class basic_fstream : public basic_iostream { public: typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; basic_fstream(); explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); basic_fstream(basic_fstream&& rhs); basic_fstream& operator=(basic_fstream&& rhs); void swap(basic_fstream& rhs); basic_filebuf* rdbuf() const; bool is_open() const; void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); void close(); }; template void swap(basic_fstream& x, basic_fstream& y); typedef basic_fstream fstream; typedef basic_fstream wfstream; } // std */ #include <__config> #include #include #include <__locale> #include #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 _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> { public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; typedef typename traits_type::state_type state_type; // 27.9.1.2 Constructors/destructor: basic_filebuf(); #ifndef _LIBCPP_CXX03_LANG basic_filebuf(basic_filebuf&& __rhs); #endif virtual ~basic_filebuf(); // 27.9.1.3 Assign/swap: #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_filebuf& operator=(basic_filebuf&& __rhs); #endif void swap(basic_filebuf& __rhs); // 27.9.1.4 Members: _LIBCPP_INLINE_VISIBILITY bool is_open() const; #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE basic_filebuf* open(const char* __s, ios_base::openmode __mode); _LIBCPP_INLINE_VISIBILITY basic_filebuf* open(const string& __s, ios_base::openmode __mode); #endif basic_filebuf* close(); protected: // 27.9.1.5 Overridden virtual functions: virtual int_type underflow(); virtual int_type pbackfail(int_type __c = traits_type::eof()); virtual int_type overflow (int_type __c = traits_type::eof()); virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out); virtual int sync(); virtual void imbue(const locale& __loc); private: char* __extbuf_; const char* __extbufnext_; const char* __extbufend_; char __extbuf_min_[8]; size_t __ebs_; char_type* __intbuf_; size_t __ibs_; FILE* __file_; const codecvt* __cv_; state_type __st_; state_type __st_last_; ios_base::openmode __om_; ios_base::openmode __cm_; bool __owns_eb_; bool __owns_ib_; bool __always_noconv_; bool __read_mode(); void __write_mode(); }; template basic_filebuf<_CharT, _Traits>::basic_filebuf() : __extbuf_(0), __extbufnext_(0), __extbufend_(0), __ebs_(0), __intbuf_(0), __ibs_(0), __file_(0), __cv_(nullptr), __st_(), __st_last_(), __om_(0), __cm_(0), __owns_eb_(false), __owns_ib_(false), __always_noconv_(false) { if (has_facet >(this->getloc())) { __cv_ = &use_facet >(this->getloc()); __always_noconv_ = __cv_->always_noconv(); } setbuf(0, 4096); } #ifndef _LIBCPP_CXX03_LANG template basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) : basic_streambuf<_CharT, _Traits>(__rhs) { if (__rhs.__extbuf_ == __rhs.__extbuf_min_) { __extbuf_ = __extbuf_min_; __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); } else { __extbuf_ = __rhs.__extbuf_; __extbufnext_ = __rhs.__extbufnext_; __extbufend_ = __rhs.__extbufend_; } __ebs_ = __rhs.__ebs_; __intbuf_ = __rhs.__intbuf_; __ibs_ = __rhs.__ibs_; __file_ = __rhs.__file_; __cv_ = __rhs.__cv_; __st_ = __rhs.__st_; __st_last_ = __rhs.__st_last_; __om_ = __rhs.__om_; __cm_ = __rhs.__cm_; __owns_eb_ = __rhs.__owns_eb_; __owns_ib_ = __rhs.__owns_ib_; __always_noconv_ = __rhs.__always_noconv_; if (__rhs.pbase()) { if (__rhs.pbase() == __rhs.__intbuf_) this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase())); else this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); - this->pbump(__rhs. pptr() - __rhs.pbase()); + this->__pbump(__rhs. pptr() - __rhs.pbase()); } else if (__rhs.eback()) { if (__rhs.eback() == __rhs.__intbuf_) this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), __intbuf_ + (__rhs.egptr() - __rhs.eback())); else this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); } __rhs.__extbuf_ = 0; __rhs.__extbufnext_ = 0; __rhs.__extbufend_ = 0; __rhs.__ebs_ = 0; __rhs.__intbuf_ = 0; __rhs.__ibs_ = 0; __rhs.__file_ = 0; __rhs.__st_ = state_type(); __rhs.__st_last_ = state_type(); __rhs.__om_ = 0; __rhs.__cm_ = 0; __rhs.__owns_eb_ = false; __rhs.__owns_ib_ = false; __rhs.setg(0, 0, 0); __rhs.setp(0, 0); } template inline basic_filebuf<_CharT, _Traits>& basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) { close(); swap(__rhs); return *this; } #endif // _LIBCPP_CXX03_LANG template basic_filebuf<_CharT, _Traits>::~basic_filebuf() { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS close(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } #endif // _LIBCPP_NO_EXCEPTIONS if (__owns_eb_) delete [] __extbuf_; if (__owns_ib_) delete [] __intbuf_; } template void basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) { basic_streambuf::swap(__rhs); if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) { _VSTD::swap(__extbuf_, __rhs.__extbuf_); _VSTD::swap(__extbufnext_, __rhs.__extbufnext_); _VSTD::swap(__extbufend_, __rhs.__extbufend_); } else { ptrdiff_t __ln = __extbufnext_ - __extbuf_; ptrdiff_t __le = __extbufend_ - __extbuf_; ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_; ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_; if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) { __extbuf_ = __rhs.__extbuf_; __rhs.__extbuf_ = __rhs.__extbuf_min_; } else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) { __rhs.__extbuf_ = __extbuf_; __extbuf_ = __extbuf_min_; } __extbufnext_ = __extbuf_ + __rn; __extbufend_ = __extbuf_ + __re; __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; __rhs.__extbufend_ = __rhs.__extbuf_ + __le; } _VSTD::swap(__ebs_, __rhs.__ebs_); _VSTD::swap(__intbuf_, __rhs.__intbuf_); _VSTD::swap(__ibs_, __rhs.__ibs_); _VSTD::swap(__file_, __rhs.__file_); _VSTD::swap(__cv_, __rhs.__cv_); _VSTD::swap(__st_, __rhs.__st_); _VSTD::swap(__st_last_, __rhs.__st_last_); _VSTD::swap(__om_, __rhs.__om_); _VSTD::swap(__cm_, __rhs.__cm_); _VSTD::swap(__owns_eb_, __rhs.__owns_eb_); _VSTD::swap(__owns_ib_, __rhs.__owns_ib_); _VSTD::swap(__always_noconv_, __rhs.__always_noconv_); if (this->eback() == (char_type*)__rhs.__extbuf_min_) { ptrdiff_t __n = this->gptr() - this->eback(); ptrdiff_t __e = this->egptr() - this->eback(); this->setg((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __n, (char_type*)__extbuf_min_ + __e); } else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) { ptrdiff_t __n = this->pptr() - this->pbase(); ptrdiff_t __e = this->epptr() - this->pbase(); this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e); - this->pbump(__n); + this->__pbump(__n); } if (__rhs.eback() == (char_type*)__extbuf_min_) { ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); __rhs.setg((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __n, (char_type*)__rhs.__extbuf_min_ + __e); } else if (__rhs.pbase() == (char_type*)__extbuf_min_) { ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e); - __rhs.pbump(__n); + __rhs.__pbump(__n); } } template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) { __x.swap(__y); } template inline bool basic_filebuf<_CharT, _Traits>::is_open() const { return __file_ != 0; } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { basic_filebuf<_CharT, _Traits>* __rt = 0; if (__file_ == 0) { __rt = this; const char* __mdstr; switch (__mode & ~ios_base::ate) { case ios_base::out: case ios_base::out | ios_base::trunc: __mdstr = "w"; break; case ios_base::out | ios_base::app: case ios_base::app: __mdstr = "a"; break; case ios_base::in: __mdstr = "r"; break; case ios_base::in | ios_base::out: __mdstr = "r+"; break; case ios_base::in | ios_base::out | ios_base::trunc: __mdstr = "w+"; break; case ios_base::in | ios_base::out | ios_base::app: case ios_base::in | ios_base::app: __mdstr = "a+"; break; case ios_base::out | ios_base::binary: case ios_base::out | ios_base::trunc | ios_base::binary: __mdstr = "wb"; break; case ios_base::out | ios_base::app | ios_base::binary: case ios_base::app | ios_base::binary: __mdstr = "ab"; break; case ios_base::in | ios_base::binary: __mdstr = "rb"; break; case ios_base::in | ios_base::out | ios_base::binary: __mdstr = "r+b"; break; case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: __mdstr = "w+b"; break; case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: case ios_base::in | ios_base::app | ios_base::binary: __mdstr = "a+b"; break; default: __rt = 0; break; } if (__rt) { __file_ = fopen(__s, __mdstr); if (__file_) { __om_ = __mode; if (__mode & ios_base::ate) { if (fseek(__file_, 0, SEEK_END)) { fclose(__file_); __file_ = 0; __rt = 0; } } } else __rt = 0; } } return __rt; } template inline basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { return open(__s.c_str(), __mode); } #endif template basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::close() { basic_filebuf<_CharT, _Traits>* __rt = 0; if (__file_) { __rt = this; unique_ptr __h(__file_, fclose); if (sync()) __rt = 0; if (fclose(__h.release()) == 0) __file_ = 0; else __rt = 0; } return __rt; } template typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::underflow() { if (__file_ == 0) return traits_type::eof(); bool __initial = __read_mode(); char_type __1buf; if (this->gptr() == 0) this->setg(&__1buf, &__1buf+1, &__1buf+1); const size_t __unget_sz = __initial ? 0 : min((this->egptr() - this->eback()) / 2, 4); int_type __c = traits_type::eof(); if (this->gptr() == this->egptr()) { memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); if (__always_noconv_) { size_t __nmemb = static_cast(this->egptr() - this->eback() - __unget_sz); __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_); if (__nmemb != 0) { this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb); __c = traits_type::to_int_type(*this->gptr()); } } else { _LIBCPP_ASSERT ( !(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" ); if (__extbufend_ != __extbufnext_) memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); size_t __nmemb = _VSTD::min(static_cast(__ibs_ - __unget_sz), static_cast(__extbufend_ - __extbufnext_)); codecvt_base::result __r; __st_last_ = __st_; size_t __nr = fread((void*) const_cast(__extbufnext_), 1, __nmemb, __file_); if (__nr != 0) { if (!__cv_) __throw_bad_cast(); __extbufend_ = __extbufnext_ + __nr; char_type* __inext; __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->eback() + __ibs_, __inext); if (__r == codecvt_base::noconv) { this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast(__extbufend_)); __c = traits_type::to_int_type(*this->gptr()); } else if (__inext != this->eback() + __unget_sz) { this->setg(this->eback(), this->eback() + __unget_sz, __inext); __c = traits_type::to_int_type(*this->gptr()); } } } } else __c = traits_type::to_int_type(*this->gptr()); if (this->eback() == &__1buf) this->setg(0, 0, 0); return __c; } template typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) { if (__file_ && this->eback() < this->gptr()) { if (traits_type::eq_int_type(__c, traits_type::eof())) { this->gbump(-1); return traits_type::not_eof(__c); } if ((__om_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { this->gbump(-1); *this->gptr() = traits_type::to_char_type(__c); return __c; } } return traits_type::eof(); } template typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) { if (__file_ == 0) return traits_type::eof(); __write_mode(); char_type __1buf; char_type* __pb_save = this->pbase(); char_type* __epb_save = this->epptr(); if (!traits_type::eq_int_type(__c, traits_type::eof())) { if (this->pptr() == 0) this->setp(&__1buf, &__1buf+1); *this->pptr() = traits_type::to_char_type(__c); this->pbump(1); } if (this->pptr() != this->pbase()) { if (__always_noconv_) { size_t __nmemb = static_cast(this->pptr() - this->pbase()); if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) return traits_type::eof(); } else { char* __extbe = __extbuf_; codecvt_base::result __r; do { if (!__cv_) __throw_bad_cast(); const char_type* __e; __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); if (__e == this->pbase()) return traits_type::eof(); if (__r == codecvt_base::noconv) { size_t __nmemb = static_cast(this->pptr() - this->pbase()); if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) return traits_type::eof(); } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) { size_t __nmemb = static_cast(__extbe - __extbuf_); if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) return traits_type::eof(); if (__r == codecvt_base::partial) { this->setp(const_cast(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else return traits_type::eof(); } while (__r == codecvt_base::partial); } this->setp(__pb_save, __epb_save); } return traits_type::not_eof(__c); } template basic_streambuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) { this->setg(0, 0, 0); this->setp(0, 0); if (__owns_eb_) delete [] __extbuf_; if (__owns_ib_) delete [] __intbuf_; __ebs_ = __n; if (__ebs_ > sizeof(__extbuf_min_)) { if (__always_noconv_ && __s) { __extbuf_ = (char*)__s; __owns_eb_ = false; } else { __extbuf_ = new char[__ebs_]; __owns_eb_ = true; } } else { __extbuf_ = __extbuf_min_; __ebs_ = sizeof(__extbuf_min_); __owns_eb_ = false; } if (!__always_noconv_) { __ibs_ = max(__n, sizeof(__extbuf_min_)); if (__s && __ibs_ >= sizeof(__extbuf_min_)) { __intbuf_ = __s; __owns_ib_ = false; } else { __intbuf_ = new char_type[__ibs_]; __owns_ib_ = true; } } else { __ibs_ = 0; __intbuf_ = 0; __owns_ib_ = false; } return this; } template typename basic_filebuf<_CharT, _Traits>::pos_type basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { if (!__cv_) __throw_bad_cast(); int __width = __cv_->encoding(); if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) return pos_type(off_type(-1)); // __width > 0 || __off == 0 int __whence; switch (__way) { case ios_base::beg: __whence = SEEK_SET; break; case ios_base::cur: __whence = SEEK_CUR; break; case ios_base::end: __whence = SEEK_END; break; default: return pos_type(off_type(-1)); } #if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) return pos_type(off_type(-1)); pos_type __r = ftell(__file_); #else if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) return pos_type(off_type(-1)); pos_type __r = ftello(__file_); #endif __r.state(__st_); return __r; } template typename basic_filebuf<_CharT, _Traits>::pos_type basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) { if (__file_ == 0 || sync()) return pos_type(off_type(-1)); #if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, __sp, SEEK_SET)) return pos_type(off_type(-1)); #else if (fseeko(__file_, __sp, SEEK_SET)) return pos_type(off_type(-1)); #endif __st_ = __sp.state(); return __sp; } template int basic_filebuf<_CharT, _Traits>::sync() { if (__file_ == 0) return 0; if (!__cv_) __throw_bad_cast(); if (__cm_ & ios_base::out) { if (this->pptr() != this->pbase()) if (overflow() == traits_type::eof()) return -1; codecvt_base::result __r; do { char* __extbe; __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); size_t __nmemb = static_cast(__extbe - __extbuf_); if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) return -1; } while (__r == codecvt_base::partial); if (__r == codecvt_base::error) return -1; if (fflush(__file_)) return -1; } else if (__cm_ & ios_base::in) { off_type __c; state_type __state = __st_last_; bool __update_st = false; if (__always_noconv_) __c = this->egptr() - this->gptr(); else { int __width = __cv_->encoding(); __c = __extbufend_ - __extbufnext_; if (__width > 0) __c += __width * (this->egptr() - this->gptr()); else { if (this->gptr() != this->egptr()) { const int __off = __cv_->length(__state, __extbuf_, __extbufnext_, this->gptr() - this->eback()); __c += __extbufnext_ - __extbuf_ - __off; __update_st = true; } } } #if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) if (fseek(__file_, -__c, SEEK_CUR)) return -1; #else if (fseeko(__file_, -__c, SEEK_CUR)) return -1; #endif if (__update_st) __st_ = __state; __extbufnext_ = __extbufend_ = __extbuf_; this->setg(0, 0, 0); __cm_ = 0; } return 0; } template void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) { sync(); __cv_ = &use_facet >(__loc); bool __old_anc = __always_noconv_; __always_noconv_ = __cv_->always_noconv(); if (__old_anc != __always_noconv_) { this->setg(0, 0, 0); this->setp(0, 0); // invariant, char_type is char, else we couldn't get here if (__always_noconv_) // need to dump __intbuf_ { if (__owns_eb_) delete [] __extbuf_; __owns_eb_ = __owns_ib_; __ebs_ = __ibs_; __extbuf_ = (char*)__intbuf_; __ibs_ = 0; __intbuf_ = 0; __owns_ib_ = false; } else // need to obtain an __intbuf_. { // If __extbuf_ is user-supplied, use it, else new __intbuf_ if (!__owns_eb_ && __extbuf_ != __extbuf_min_) { __ibs_ = __ebs_; __intbuf_ = (char_type*)__extbuf_; __owns_ib_ = false; __extbuf_ = new char[__ebs_]; __owns_eb_ = true; } else { __ibs_ = __ebs_; __intbuf_ = new char_type[__ibs_]; __owns_ib_ = true; } } } } template bool basic_filebuf<_CharT, _Traits>::__read_mode() { if (!(__cm_ & ios_base::in)) { this->setp(0, 0); if (__always_noconv_) this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_); else this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); __cm_ = ios_base::in; return true; } return false; } template void basic_filebuf<_CharT, _Traits>::__write_mode() { if (!(__cm_ & ios_base::out)) { this->setg(0, 0, 0); if (__ebs_ > sizeof(__extbuf_min_)) { if (__always_noconv_) this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1)); else this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); } else this->setp(0, 0); __cm_ = ios_base::out; } } // basic_ifstream template class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> { public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; _LIBCPP_INLINE_VISIBILITY basic_ifstream(); #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_INLINE_VISIBILITY explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); _LIBCPP_INLINE_VISIBILITY explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); #endif #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_ifstream(basic_ifstream&& __rhs); _LIBCPP_INLINE_VISIBILITY basic_ifstream& operator=(basic_ifstream&& __rhs); #endif _LIBCPP_INLINE_VISIBILITY void swap(basic_ifstream& __rhs); _LIBCPP_INLINE_VISIBILITY basic_filebuf* rdbuf() const; _LIBCPP_INLINE_VISIBILITY bool is_open() const; #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE void open(const char* __s, ios_base::openmode __mode = ios_base::in); void open(const string& __s, ios_base::openmode __mode = ios_base::in); #endif _LIBCPP_INLINE_VISIBILITY void close(); private: basic_filebuf __sb_; }; template inline basic_ifstream<_CharT, _Traits>::basic_ifstream() : basic_istream(&__sb_) { } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) : basic_istream(&__sb_) { if (__sb_.open(__s, __mode | ios_base::in) == 0) this->setstate(ios_base::failbit); } template inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) : basic_istream(&__sb_) { if (__sb_.open(__s, __mode | ios_base::in) == 0) this->setstate(ios_base::failbit); } #endif #ifndef _LIBCPP_CXX03_LANG template inline basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) : basic_istream(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) { this->set_rdbuf(&__sb_); } template inline basic_ifstream<_CharT, _Traits>& basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) { basic_istream::operator=(_VSTD::move(__rhs)); __sb_ = _VSTD::move(__rhs.__sb_); return *this; } #endif // _LIBCPP_CXX03_LANG template inline void basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) { basic_istream::swap(__rhs); __sb_.swap(__rhs.__sb_); } template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) { __x.swap(__y); } template inline basic_filebuf<_CharT, _Traits>* basic_ifstream<_CharT, _Traits>::rdbuf() const { return const_cast*>(&__sb_); } template inline bool basic_ifstream<_CharT, _Traits>::is_open() const { return __sb_.is_open(); } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template void basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode | ios_base::in)) this->clear(); else this->setstate(ios_base::failbit); } template void basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode | ios_base::in)) this->clear(); else this->setstate(ios_base::failbit); } #endif template inline void basic_ifstream<_CharT, _Traits>::close() { if (__sb_.close() == 0) this->setstate(ios_base::failbit); } // basic_ofstream template class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> { public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; _LIBCPP_INLINE_VISIBILITY basic_ofstream(); _LIBCPP_INLINE_VISIBILITY explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); _LIBCPP_INLINE_VISIBILITY explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_ofstream(basic_ofstream&& __rhs); _LIBCPP_INLINE_VISIBILITY basic_ofstream& operator=(basic_ofstream&& __rhs); #endif _LIBCPP_INLINE_VISIBILITY void swap(basic_ofstream& __rhs); _LIBCPP_INLINE_VISIBILITY basic_filebuf* rdbuf() const; _LIBCPP_INLINE_VISIBILITY bool is_open() const; #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE void open(const char* __s, ios_base::openmode __mode = ios_base::out); void open(const string& __s, ios_base::openmode __mode = ios_base::out); #endif _LIBCPP_INLINE_VISIBILITY void close(); private: basic_filebuf __sb_; }; template inline basic_ofstream<_CharT, _Traits>::basic_ofstream() : basic_ostream(&__sb_) { } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) : basic_ostream(&__sb_) { if (__sb_.open(__s, __mode | ios_base::out) == 0) this->setstate(ios_base::failbit); } template inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) : basic_ostream(&__sb_) { if (__sb_.open(__s, __mode | ios_base::out) == 0) this->setstate(ios_base::failbit); } #endif #ifndef _LIBCPP_CXX03_LANG template inline basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) : basic_ostream(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) { this->set_rdbuf(&__sb_); } template inline basic_ofstream<_CharT, _Traits>& basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) { basic_ostream::operator=(_VSTD::move(__rhs)); __sb_ = _VSTD::move(__rhs.__sb_); return *this; } #endif // _LIBCPP_CXX03_LANG template inline void basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) { basic_ostream::swap(__rhs); __sb_.swap(__rhs.__sb_); } template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) { __x.swap(__y); } template inline basic_filebuf<_CharT, _Traits>* basic_ofstream<_CharT, _Traits>::rdbuf() const { return const_cast*>(&__sb_); } template inline bool basic_ofstream<_CharT, _Traits>::is_open() const { return __sb_.is_open(); } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template void basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode | ios_base::out)) this->clear(); else this->setstate(ios_base::failbit); } template void basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode | ios_base::out)) this->clear(); else this->setstate(ios_base::failbit); } #endif template inline void basic_ofstream<_CharT, _Traits>::close() { if (__sb_.close() == 0) this->setstate(ios_base::failbit); } // basic_fstream template class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> { public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; _LIBCPP_INLINE_VISIBILITY basic_fstream(); #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_INLINE_VISIBILITY explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); _LIBCPP_INLINE_VISIBILITY explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); #endif #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_fstream(basic_fstream&& __rhs); _LIBCPP_INLINE_VISIBILITY basic_fstream& operator=(basic_fstream&& __rhs); #endif _LIBCPP_INLINE_VISIBILITY void swap(basic_fstream& __rhs); _LIBCPP_INLINE_VISIBILITY basic_filebuf* rdbuf() const; _LIBCPP_INLINE_VISIBILITY bool is_open() const; #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); #endif _LIBCPP_INLINE_VISIBILITY void close(); private: basic_filebuf __sb_; }; template inline basic_fstream<_CharT, _Traits>::basic_fstream() : basic_iostream(&__sb_) { } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template inline basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) : basic_iostream(&__sb_) { if (__sb_.open(__s, __mode) == 0) this->setstate(ios_base::failbit); } template inline basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) : basic_iostream(&__sb_) { if (__sb_.open(__s, __mode) == 0) this->setstate(ios_base::failbit); } #endif #ifndef _LIBCPP_CXX03_LANG template inline basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) : basic_iostream(_VSTD::move(__rhs)), __sb_(_VSTD::move(__rhs.__sb_)) { this->set_rdbuf(&__sb_); } template inline basic_fstream<_CharT, _Traits>& basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) { basic_iostream::operator=(_VSTD::move(__rhs)); __sb_ = _VSTD::move(__rhs.__sb_); return *this; } #endif // _LIBCPP_CXX03_LANG template inline void basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) { basic_iostream::swap(__rhs); __sb_.swap(__rhs.__sb_); } template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) { __x.swap(__y); } template inline basic_filebuf<_CharT, _Traits>* basic_fstream<_CharT, _Traits>::rdbuf() const { return const_cast*>(&__sb_); } template inline bool basic_fstream<_CharT, _Traits>::is_open() const { return __sb_.is_open(); } #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE template void basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode)) this->clear(); else this->setstate(ios_base::failbit); } template void basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { if (__sb_.open(__s, __mode)) this->clear(); else this->setstate(ios_base::failbit); } #endif template inline void basic_fstream<_CharT, _Traits>::close() { if (__sb_.close() == 0) this->setstate(ios_base::failbit); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_FSTREAM Index: projects/clang600-import/contrib/libc++/include/future =================================================================== --- projects/clang600-import/contrib/libc++/include/future (revision 327038) +++ projects/clang600-import/contrib/libc++/include/future (revision 327039) @@ -1,2617 +1,2618 @@ // -*- C++ -*- //===--------------------------- future -----------------------------------===// // // 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_FUTURE #define _LIBCPP_FUTURE /* future synopsis namespace std { enum class future_errc { future_already_retrieved = 1, promise_already_satisfied, no_state, broken_promise }; enum class launch { async = 1, deferred = 2, any = async | deferred }; enum class future_status { ready, timeout, deferred }; template <> struct is_error_code_enum : public true_type { }; error_code make_error_code(future_errc e) noexcept; error_condition make_error_condition(future_errc e) noexcept; const error_category& future_category() noexcept; class future_error : public logic_error { public: future_error(error_code ec); // exposition only explicit future_error(future_errc); // C++17 const error_code& code() const noexcept; const char* what() const noexcept; }; template class promise { public: promise(); template promise(allocator_arg_t, const Allocator& a); promise(promise&& rhs) noexcept; promise(const promise& rhs) = delete; ~promise(); // assignment promise& operator=(promise&& rhs) noexcept; promise& operator=(const promise& rhs) = delete; void swap(promise& other) noexcept; // retrieving the result future get_future(); // setting the result void set_value(const R& r); void set_value(R&& r); void set_exception(exception_ptr p); // setting the result with deferred notification void set_value_at_thread_exit(const R& r); void set_value_at_thread_exit(R&& r); void set_exception_at_thread_exit(exception_ptr p); }; template class promise { public: promise(); template promise(allocator_arg_t, const Allocator& a); promise(promise&& rhs) noexcept; promise(const promise& rhs) = delete; ~promise(); // assignment promise& operator=(promise&& rhs) noexcept; promise& operator=(const promise& rhs) = delete; void swap(promise& other) noexcept; // retrieving the result future get_future(); // setting the result void set_value(R& r); void set_exception(exception_ptr p); // setting the result with deferred notification void set_value_at_thread_exit(R&); void set_exception_at_thread_exit(exception_ptr p); }; template <> class promise { public: promise(); template promise(allocator_arg_t, const Allocator& a); promise(promise&& rhs) noexcept; promise(const promise& rhs) = delete; ~promise(); // assignment promise& operator=(promise&& rhs) noexcept; promise& operator=(const promise& rhs) = delete; void swap(promise& other) noexcept; // retrieving the result future get_future(); // setting the result void set_value(); void set_exception(exception_ptr p); // setting the result with deferred notification void set_value_at_thread_exit(); void set_exception_at_thread_exit(exception_ptr p); }; template void swap(promise& x, promise& y) noexcept; template struct uses_allocator, Alloc> : public true_type {}; template class future { public: future() noexcept; future(future&&) noexcept; future(const future& rhs) = delete; ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; shared_future share() noexcept; // retrieving the value R get(); // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template class future { public: future() noexcept; future(future&&) noexcept; future(const future& rhs) = delete; ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; shared_future share() noexcept; // retrieving the value R& get(); // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template <> class future { public: future() noexcept; future(future&&) noexcept; future(const future& rhs) = delete; ~future(); future& operator=(const future& rhs) = delete; future& operator=(future&&) noexcept; shared_future share() noexcept; // retrieving the value void get(); // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template class shared_future { public: shared_future() noexcept; shared_future(const shared_future& rhs); shared_future(future&&) noexcept; shared_future(shared_future&& rhs) noexcept; ~shared_future(); shared_future& operator=(const shared_future& rhs); shared_future& operator=(shared_future&& rhs) noexcept; // retrieving the value const R& get() const; // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template class shared_future { public: shared_future() noexcept; shared_future(const shared_future& rhs); shared_future(future&&) noexcept; shared_future(shared_future&& rhs) noexcept; ~shared_future(); shared_future& operator=(const shared_future& rhs); shared_future& operator=(shared_future&& rhs) noexcept; // retrieving the value R& get() const; // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template <> class shared_future { public: shared_future() noexcept; shared_future(const shared_future& rhs); shared_future(future&&) noexcept; shared_future(shared_future&& rhs) noexcept; ~shared_future(); shared_future& operator=(const shared_future& rhs); shared_future& operator=(shared_future&& rhs) noexcept; // retrieving the value void get() const; // functions to check state bool valid() const noexcept; void wait() const; template future_status wait_for(const chrono::duration& rel_time) const; template future_status wait_until(const chrono::time_point& abs_time) const; }; template future::type(typename decay::type...)>::type> async(F&& f, Args&&... args); template future::type(typename decay::type...)>::type> async(launch policy, F&& f, Args&&... args); template class packaged_task; // undefined template class packaged_task { public: typedef R result_type; // extension // construction and destruction packaged_task() noexcept; template explicit packaged_task(F&& f); template packaged_task(allocator_arg_t, const Allocator& a, F&& f); ~packaged_task(); // no copy packaged_task(const packaged_task&) = delete; packaged_task& operator=(const packaged_task&) = delete; // move support packaged_task(packaged_task&& other) noexcept; packaged_task& operator=(packaged_task&& other) noexcept; void swap(packaged_task& other) noexcept; bool valid() const noexcept; // result retrieval future get_future(); // execution void operator()(ArgTypes... ); void make_ready_at_thread_exit(ArgTypes...); void reset(); }; template void swap(packaged_task&) noexcept; template struct uses_allocator, Alloc>; } // std */ #include <__config> #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif #ifdef _LIBCPP_HAS_NO_THREADS #error is not supported on this single threaded system #else // !_LIBCPP_HAS_NO_THREADS _LIBCPP_BEGIN_NAMESPACE_STD //enum class future_errc _LIBCPP_DECLARE_STRONG_ENUM(future_errc) { future_already_retrieved = 1, promise_already_satisfied, no_state, broken_promise }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc) template <> struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public true_type {}; #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS template <> struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public true_type { }; #endif //enum class launch _LIBCPP_DECLARE_STRONG_ENUM(launch) { async = 1, deferred = 2, any = async | deferred }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) #ifndef _LIBCPP_HAS_NO_STRONG_ENUMS #ifdef _LIBCXX_UNDERLYING_TYPE typedef underlying_type::type __launch_underlying_type; #else typedef int __launch_underlying_type; #endif inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR launch operator&(launch __x, launch __y) { return static_cast(static_cast<__launch_underlying_type>(__x) & static_cast<__launch_underlying_type>(__y)); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR launch operator|(launch __x, launch __y) { return static_cast(static_cast<__launch_underlying_type>(__x) | static_cast<__launch_underlying_type>(__y)); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR launch operator^(launch __x, launch __y) { return static_cast(static_cast<__launch_underlying_type>(__x) ^ static_cast<__launch_underlying_type>(__y)); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR launch operator~(launch __x) { return static_cast(~static_cast<__launch_underlying_type>(__x) & 3); } inline _LIBCPP_INLINE_VISIBILITY launch& operator&=(launch& __x, launch __y) { __x = __x & __y; return __x; } inline _LIBCPP_INLINE_VISIBILITY launch& operator|=(launch& __x, launch __y) { __x = __x | __y; return __x; } inline _LIBCPP_INLINE_VISIBILITY launch& operator^=(launch& __x, launch __y) { __x = __x ^ __y; return __x; } #endif // !_LIBCPP_HAS_NO_STRONG_ENUMS //enum class future_status _LIBCPP_DECLARE_STRONG_ENUM(future_status) { ready, timeout, deferred }; _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status) _LIBCPP_FUNC_VIS const error_category& future_category() _NOEXCEPT; inline _LIBCPP_INLINE_VISIBILITY error_code make_error_code(future_errc __e) _NOEXCEPT { return error_code(static_cast(__e), future_category()); } inline _LIBCPP_INLINE_VISIBILITY error_condition make_error_condition(future_errc __e) _NOEXCEPT { return error_condition(static_cast(__e), future_category()); } class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error : public logic_error { error_code __ec_; public: future_error(error_code __ec); #if _LIBCPP_STD_VERS > 14 explicit future_error(future_errc _Ev) : logic_error(), __ec_(make_error_code(_Ev)) {} #endif _LIBCPP_INLINE_VISIBILITY const error_code& code() const _NOEXCEPT {return __ec_;} virtual ~future_error() _NOEXCEPT; }; _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE #ifndef _LIBCPP_NO_EXCEPTIONS _LIBCPP_AVAILABILITY_FUTURE_ERROR #endif void __throw_future_error(future_errc _Ev) { #ifndef _LIBCPP_NO_EXCEPTIONS throw future_error(make_error_code(_Ev)); #else ((void)_Ev); _VSTD::abort(); #endif } class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state : public __shared_count { protected: exception_ptr __exception_; mutable mutex __mut_; mutable condition_variable __cv_; unsigned __state_; virtual void __on_zero_shared() _NOEXCEPT; void __sub_wait(unique_lock& __lk); public: enum { __constructed = 1, __future_attached = 2, ready = 4, deferred = 8 }; _LIBCPP_INLINE_VISIBILITY __assoc_sub_state() : __state_(0) {} _LIBCPP_INLINE_VISIBILITY bool __has_value() const {return (__state_ & __constructed) || (__exception_ != nullptr);} _LIBCPP_INLINE_VISIBILITY void __set_future_attached() { lock_guard __lk(__mut_); __state_ |= __future_attached; } _LIBCPP_INLINE_VISIBILITY bool __has_future_attached() const {return (__state_ & __future_attached) != 0;} _LIBCPP_INLINE_VISIBILITY void __set_deferred() {__state_ |= deferred;} void __make_ready(); _LIBCPP_INLINE_VISIBILITY bool __is_ready() const {return (__state_ & ready) != 0;} void set_value(); void set_value_at_thread_exit(); void set_exception(exception_ptr __p); void set_exception_at_thread_exit(exception_ptr __p); void copy(); void wait(); template future_status _LIBCPP_INLINE_VISIBILITY wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const; template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const; virtual void __execute(); }; template future_status __assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const { unique_lock __lk(__mut_); if (__state_ & deferred) return future_status::deferred; while (!(__state_ & ready) && _Clock::now() < __abs_time) __cv_.wait_until(__lk, __abs_time); if (__state_ & ready) return future_status::ready; return future_status::timeout; } template inline future_status __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const { return wait_until(chrono::steady_clock::now() + __rel_time); } template class _LIBCPP_AVAILABILITY_FUTURE __assoc_state : public __assoc_sub_state { typedef __assoc_sub_state base; typedef typename aligned_storage::value>::type _Up; protected: _Up __value_; virtual void __on_zero_shared() _NOEXCEPT; public: template #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES void set_value(_Arg&& __arg); #else void set_value(_Arg& __arg); #endif template #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES void set_value_at_thread_exit(_Arg&& __arg); #else void set_value_at_thread_exit(_Arg& __arg); #endif _Rp move(); typename add_lvalue_reference<_Rp>::type copy(); }; template void __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT { if (this->__state_ & base::__constructed) reinterpret_cast<_Rp*>(&__value_)->~_Rp(); delete this; } template template _LIBCPP_AVAILABILITY_FUTURE void #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __assoc_state<_Rp>::set_value(_Arg&& __arg) #else __assoc_state<_Rp>::set_value(_Arg& __arg) #endif { unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); this->__state_ |= base::__constructed | base::ready; __cv_.notify_all(); } template template void #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) #else __assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg) #endif { unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg)); this->__state_ |= base::__constructed; __thread_local_data()->__make_ready_at_thread_exit(this); } template _Rp __assoc_state<_Rp>::move() { unique_lock __lk(this->__mut_); this->__sub_wait(__lk); if (this->__exception_ != nullptr) rethrow_exception(this->__exception_); return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_)); } template typename add_lvalue_reference<_Rp>::type __assoc_state<_Rp>::copy() { unique_lock __lk(this->__mut_); this->__sub_wait(__lk); if (this->__exception_ != nullptr) rethrow_exception(this->__exception_); return *reinterpret_cast<_Rp*>(&__value_); } template class _LIBCPP_AVAILABILITY_FUTURE __assoc_state<_Rp&> : public __assoc_sub_state { typedef __assoc_sub_state base; typedef _Rp* _Up; protected: _Up __value_; virtual void __on_zero_shared() _NOEXCEPT; public: void set_value(_Rp& __arg); void set_value_at_thread_exit(_Rp& __arg); _Rp& copy(); }; template void __assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT { delete this; } template void __assoc_state<_Rp&>::set_value(_Rp& __arg) { unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); __value_ = _VSTD::addressof(__arg); this->__state_ |= base::__constructed | base::ready; __cv_.notify_all(); } template void __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) { unique_lock __lk(this->__mut_); if (this->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); __value_ = _VSTD::addressof(__arg); this->__state_ |= base::__constructed; __thread_local_data()->__make_ready_at_thread_exit(this); } template _Rp& __assoc_state<_Rp&>::copy() { unique_lock __lk(this->__mut_); this->__sub_wait(__lk); if (this->__exception_ != nullptr) rethrow_exception(this->__exception_); return *__value_; } template class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; _Alloc __alloc_; virtual void __on_zero_shared() _NOEXCEPT; public: _LIBCPP_INLINE_VISIBILITY explicit __assoc_state_alloc(const _Alloc& __a) : __alloc_(__a) {} }; template void __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT { if (this->__state_ & base::__constructed) reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp(); typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; _Al __a(__alloc_); this->~__assoc_state_alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } template class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc<_Rp&, _Alloc> : public __assoc_state<_Rp&> { typedef __assoc_state<_Rp&> base; _Alloc __alloc_; virtual void __on_zero_shared() _NOEXCEPT; public: _LIBCPP_INLINE_VISIBILITY explicit __assoc_state_alloc(const _Alloc& __a) : __alloc_(__a) {} }; template void __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT { typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al; typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; _Al __a(__alloc_); this->~__assoc_state_alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } template class _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state_alloc : public __assoc_sub_state { typedef __assoc_sub_state base; _Alloc __alloc_; virtual void __on_zero_shared() _NOEXCEPT; public: _LIBCPP_INLINE_VISIBILITY explicit __assoc_sub_state_alloc(const _Alloc& __a) : __alloc_(__a) {} }; template void __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT { typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al; typedef allocator_traits<_Al> _ATraits; typedef pointer_traits _PTraits; _Al __a(__alloc_); this->~__assoc_sub_state_alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } template class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; _Fp __func_; public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY explicit __deferred_assoc_state(_Fp&& __f); #endif virtual void __execute(); }; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template inline __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f) : __func_(_VSTD::forward<_Fp>(__f)) { this->__set_deferred(); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void __deferred_assoc_state<_Rp, _Fp>::__execute() { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->set_value(__func_()); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state : public __assoc_sub_state { typedef __assoc_sub_state base; _Fp __func_; public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY explicit __deferred_assoc_state(_Fp&& __f); #endif virtual void __execute(); }; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template inline __deferred_assoc_state::__deferred_assoc_state(_Fp&& __f) : __func_(_VSTD::forward<_Fp>(__f)) { this->__set_deferred(); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void __deferred_assoc_state::__execute() { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __func_(); this->set_value(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state : public __assoc_state<_Rp> { typedef __assoc_state<_Rp> base; _Fp __func_; virtual void __on_zero_shared() _NOEXCEPT; public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY explicit __async_assoc_state(_Fp&& __f); #endif virtual void __execute(); }; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template inline __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f) : __func_(_VSTD::forward<_Fp>(__f)) { } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void __async_assoc_state<_Rp, _Fp>::__execute() { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->set_value(__func_()); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT { this->wait(); base::__on_zero_shared(); } template class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state : public __assoc_sub_state { typedef __assoc_sub_state base; _Fp __func_; virtual void __on_zero_shared() _NOEXCEPT; public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY explicit __async_assoc_state(_Fp&& __f); #endif virtual void __execute(); }; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template inline __async_assoc_state::__async_assoc_state(_Fp&& __f) : __func_(_VSTD::forward<_Fp>(__f)) { } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void __async_assoc_state::__execute() { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __func_(); this->set_value(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void __async_assoc_state::__on_zero_shared() _NOEXCEPT { this->wait(); base::__on_zero_shared(); } template class _LIBCPP_TEMPLATE_VIS promise; template class _LIBCPP_TEMPLATE_VIS shared_future; // future template class _LIBCPP_TEMPLATE_VIS future; template future<_Rp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __make_deferred_assoc_state(_Fp&& __f); #else __make_deferred_assoc_state(_Fp __f); #endif template future<_Rp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __make_async_assoc_state(_Fp&& __f); #else __make_async_assoc_state(_Fp __f); #endif template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future { __assoc_state<_Rp>* __state_; explicit future(__assoc_state<_Rp>* __state); template friend class promise; template friend class shared_future; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); template friend future<_R1> __make_async_assoc_state(_Fp&& __f); #else template friend future<_R1> __make_deferred_assoc_state(_Fp __f); template friend future<_R1> __make_async_assoc_state(_Fp __f); #endif public: _LIBCPP_INLINE_VISIBILITY future() _NOEXCEPT : __state_(nullptr) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY future(future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} future(const future&) = delete; future& operator=(const future&) = delete; _LIBCPP_INLINE_VISIBILITY future& operator=(future&& __rhs) _NOEXCEPT { future(std::move(__rhs)).swap(*this); return *this; } #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: future(const future&); future& operator=(const future&); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY shared_future<_Rp> share() _NOEXCEPT; // retrieving the value _Rp get(); _LIBCPP_INLINE_VISIBILITY void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template future<_Rp>::future(__assoc_state<_Rp>* __state) : __state_(__state) { if (__state_->__has_future_attached()) __throw_future_error(future_errc::future_already_retrieved); __state_->__add_shared(); __state_->__set_future_attached(); } struct __release_shared_count { void operator()(__shared_count* p) {p->__release_shared();} }; template future<_Rp>::~future() { if (__state_) __state_->__release_shared(); } template _Rp future<_Rp>::get() { unique_ptr<__shared_count, __release_shared_count> __(__state_); __assoc_state<_Rp>* __s = __state_; __state_ = nullptr; return __s->move(); } template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future<_Rp&> { __assoc_state<_Rp&>* __state_; explicit future(__assoc_state<_Rp&>* __state); template friend class promise; template friend class shared_future; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); template friend future<_R1> __make_async_assoc_state(_Fp&& __f); #else template friend future<_R1> __make_deferred_assoc_state(_Fp __f); template friend future<_R1> __make_async_assoc_state(_Fp __f); #endif public: _LIBCPP_INLINE_VISIBILITY future() _NOEXCEPT : __state_(nullptr) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY future(future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} future(const future&) = delete; future& operator=(const future&) = delete; _LIBCPP_INLINE_VISIBILITY future& operator=(future&& __rhs) _NOEXCEPT { future(std::move(__rhs)).swap(*this); return *this; } #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: future(const future&); future& operator=(const future&); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY shared_future<_Rp&> share() _NOEXCEPT; // retrieving the value _Rp& get(); _LIBCPP_INLINE_VISIBILITY void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template future<_Rp&>::future(__assoc_state<_Rp&>* __state) : __state_(__state) { if (__state_->__has_future_attached()) __throw_future_error(future_errc::future_already_retrieved); __state_->__add_shared(); __state_->__set_future_attached(); } template future<_Rp&>::~future() { if (__state_) __state_->__release_shared(); } template _Rp& future<_Rp&>::get() { unique_ptr<__shared_count, __release_shared_count> __(__state_); __assoc_state<_Rp&>* __s = __state_; __state_ = nullptr; return __s->copy(); } template <> class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE future { __assoc_sub_state* __state_; explicit future(__assoc_sub_state* __state); template friend class promise; template friend class shared_future; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template friend future<_R1> __make_deferred_assoc_state(_Fp&& __f); template friend future<_R1> __make_async_assoc_state(_Fp&& __f); #else template friend future<_R1> __make_deferred_assoc_state(_Fp __f); template friend future<_R1> __make_async_assoc_state(_Fp __f); #endif public: _LIBCPP_INLINE_VISIBILITY future() _NOEXCEPT : __state_(nullptr) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY future(future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} future(const future&) = delete; future& operator=(const future&) = delete; _LIBCPP_INLINE_VISIBILITY future& operator=(future&& __rhs) _NOEXCEPT { future(std::move(__rhs)).swap(*this); return *this; } #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: future(const future&); future& operator=(const future&); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~future(); _LIBCPP_INLINE_VISIBILITY shared_future share() _NOEXCEPT; // retrieving the value void get(); _LIBCPP_INLINE_VISIBILITY void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template inline _LIBCPP_INLINE_VISIBILITY void swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT { __x.swap(__y); } // promise template class packaged_task; template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise { __assoc_state<_Rp>* __state_; _LIBCPP_INLINE_VISIBILITY explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} template friend class packaged_task; public: promise(); template promise(allocator_arg_t, const _Alloc& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise(promise&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} promise(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~promise(); // assignment #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise& operator=(promise&& __rhs) _NOEXCEPT { promise(std::move(__rhs)).swap(*this); return *this; } promise& operator=(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise& operator=(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // retrieving the result future<_Rp> get_future(); // setting the result void set_value(const _Rp& __r); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES void set_value(_Rp&& __r); #endif void set_exception(exception_ptr __p); // setting the result with deferred notification void set_value_at_thread_exit(const _Rp& __r); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES void set_value_at_thread_exit(_Rp&& __r); #endif void set_exception_at_thread_exit(exception_ptr __p); }; template promise<_Rp>::promise() : __state_(new __assoc_state<_Rp>) { } template template promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_state_alloc<_Rp, _Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } template promise<_Rp>::~promise() { if (__state_) { if (!__state_->__has_value() && __state_->use_count() > 1) __state_->set_exception(make_exception_ptr( future_error(make_error_code(future_errc::broken_promise)) )); __state_->__release_shared(); } } template future<_Rp> promise<_Rp>::get_future() { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); return future<_Rp>(__state_); } template void promise<_Rp>::set_value(const _Rp& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value(__r); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template void promise<_Rp>::set_value(_Rp&& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value(_VSTD::move(__r)); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void promise<_Rp>::set_exception(exception_ptr __p) { _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" ); if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_exception(__p); } template void promise<_Rp>::set_value_at_thread_exit(const _Rp& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value_at_thread_exit(__r); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template void promise<_Rp>::set_value_at_thread_exit(_Rp&& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value_at_thread_exit(_VSTD::move(__r)); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template void promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) { _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" ); if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_exception_at_thread_exit(__p); } // promise template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<_Rp&> { __assoc_state<_Rp&>* __state_; _LIBCPP_INLINE_VISIBILITY explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} template friend class packaged_task; public: promise(); template promise(allocator_arg_t, const _Allocator& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise(promise&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} promise(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~promise(); // assignment #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise& operator=(promise&& __rhs) _NOEXCEPT { promise(std::move(__rhs)).swap(*this); return *this; } promise& operator=(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise& operator=(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // retrieving the result future<_Rp&> get_future(); // setting the result void set_value(_Rp& __r); void set_exception(exception_ptr __p); // setting the result with deferred notification void set_value_at_thread_exit(_Rp&); void set_exception_at_thread_exit(exception_ptr __p); }; template promise<_Rp&>::promise() : __state_(new __assoc_state<_Rp&>) { } template template promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_state_alloc<_Rp&, _Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } template promise<_Rp&>::~promise() { if (__state_) { if (!__state_->__has_value() && __state_->use_count() > 1) __state_->set_exception(make_exception_ptr( future_error(make_error_code(future_errc::broken_promise)) )); __state_->__release_shared(); } } template future<_Rp&> promise<_Rp&>::get_future() { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); return future<_Rp&>(__state_); } template void promise<_Rp&>::set_value(_Rp& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value(__r); } template void promise<_Rp&>::set_exception(exception_ptr __p) { _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" ); if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_exception(__p); } template void promise<_Rp&>::set_value_at_thread_exit(_Rp& __r) { if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_value_at_thread_exit(__r); } template void promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) { _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" ); if (__state_ == nullptr) __throw_future_error(future_errc::no_state); __state_->set_exception_at_thread_exit(__p); } // promise template <> class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE promise { __assoc_sub_state* __state_; _LIBCPP_INLINE_VISIBILITY explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {} template friend class packaged_task; public: promise(); template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS promise(allocator_arg_t, const _Allocator& __a); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise(promise&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} promise(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~promise(); // assignment #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY promise& operator=(promise&& __rhs) _NOEXCEPT { promise(std::move(__rhs)).swap(*this); return *this; } promise& operator=(const promise& __rhs) = delete; #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES private: promise& operator=(const promise& __rhs); public: #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // retrieving the result future get_future(); // setting the result void set_value(); void set_exception(exception_ptr __p); // setting the result with deferred notification void set_value_at_thread_exit(); void set_exception_at_thread_exit(exception_ptr __p); }; template promise::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_sub_state_alloc<_Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; typedef __allocator_destructor<_A2> _D2; _A2 __a(__a0); unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); ::new(static_cast(_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _VSTD::addressof(*__hold.release()); } template inline _LIBCPP_INLINE_VISIBILITY void swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT { __x.swap(__y); } template struct _LIBCPP_TEMPLATE_VIS uses_allocator, _Alloc> : public true_type {}; #ifndef _LIBCPP_HAS_NO_VARIADICS // packaged_task template class __packaged_task_base; template class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_base<_Rp(_ArgTypes...)> { __packaged_task_base(const __packaged_task_base&); __packaged_task_base& operator=(const __packaged_task_base&); public: _LIBCPP_INLINE_VISIBILITY __packaged_task_base() {} _LIBCPP_INLINE_VISIBILITY virtual ~__packaged_task_base() {} virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0; virtual void destroy() = 0; virtual void destroy_deallocate() = 0; virtual _Rp operator()(_ArgTypes&& ...) = 0; }; template class __packaged_task_func; template class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __packaged_task_base<_Rp(_ArgTypes...)> { __compressed_pair<_Fp, _Alloc> __f_; public: _LIBCPP_INLINE_VISIBILITY explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {} _LIBCPP_INLINE_VISIBILITY explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {} _LIBCPP_INLINE_VISIBILITY __packaged_task_func(const _Fp& __f, const _Alloc& __a) : __f_(__f, __a) {} _LIBCPP_INLINE_VISIBILITY __packaged_task_func(_Fp&& __f, const _Alloc& __a) : __f_(_VSTD::move(__f), __a) {} virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT; virtual void destroy(); virtual void destroy_deallocate(); virtual _Rp operator()(_ArgTypes&& ... __args); }; template void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to( __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT { ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second())); } template void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() { __f_.~__compressed_pair<_Fp, _Alloc>(); } template void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() { typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap; typedef allocator_traits<_Ap> _ATraits; typedef pointer_traits _PTraits; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(_PTraits::pointer_to(*this), 1); } template _Rp __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) { return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); } template class __packaged_task_function; template class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)> { typedef __packaged_task_base<_Rp(_ArgTypes...)> __base; typename aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; public: typedef _Rp result_type; // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY __packaged_task_function() _NOEXCEPT : __f_(nullptr) {} template __packaged_task_function(_Fp&& __f); template __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f); __packaged_task_function(__packaged_task_function&&) _NOEXCEPT; __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT; __packaged_task_function(const __packaged_task_function&) = delete; __packaged_task_function& operator=(const __packaged_task_function&) = delete; ~__packaged_task_function(); void swap(__packaged_task_function&) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY _Rp operator()(_ArgTypes...) const; }; template __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT { if (__f.__f_ == nullptr) __f_ = nullptr; else if (__f.__f_ == (__base*)&__f.__buf_) { __f_ = (__base*)&__buf_; __f.__f_->__move_to(__f_); } else { __f_ = __f.__f_; __f.__f_ = nullptr; } } template template __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f) : __f_(nullptr) { typedef typename remove_reference::type>::type _FR; typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); } else { typedef allocator<_FF> _Ap; _Ap __a; typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a)); __f_ = __hold.release(); } } template template __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function( allocator_arg_t, const _Alloc& __a0, _Fp&& __f) : __f_(nullptr) { typedef typename remove_reference::type>::type _FR; typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) { __f_ = (__base*)&__buf_; ::new (__f_) _FF(_VSTD::forward<_Fp>(__f)); } else { typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); ::new (static_cast(_VSTD::addressof(*__hold.get()))) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a)); __f_ = _VSTD::addressof(*__hold.release()); } } template __packaged_task_function<_Rp(_ArgTypes...)>& __packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT { if (__f_ == (__base*)&__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = nullptr; if (__f.__f_ == nullptr) __f_ = nullptr; else if (__f.__f_ == (__base*)&__f.__buf_) { __f_ = (__base*)&__buf_; __f.__f_->__move_to(__f_); } else { __f_ = __f.__f_; __f.__f_ = nullptr; } return *this; } template __packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function() { if (__f_ == (__base*)&__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); } template void __packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT { if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { typename aligned_storage::type __tempbuf; __base* __t = (__base*)&__tempbuf; __f_->__move_to(__t); __f_->destroy(); __f_ = nullptr; __f.__f_->__move_to((__base*)&__buf_); __f.__f_->destroy(); __f.__f_ = nullptr; __f_ = (__base*)&__buf_; __t->__move_to((__base*)&__f.__buf_); __t->destroy(); __f.__f_ = (__base*)&__f.__buf_; } else if (__f_ == (__base*)&__buf_) { __f_->__move_to((__base*)&__f.__buf_); __f_->destroy(); __f_ = __f.__f_; __f.__f_ = (__base*)&__f.__buf_; } else if (__f.__f_ == (__base*)&__f.__buf_) { __f.__f_->__move_to((__base*)&__buf_); __f.__f_->destroy(); __f.__f_ = __f_; __f_ = (__base*)&__buf_; } else _VSTD::swap(__f_, __f.__f_); } template inline _Rp __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); } template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<_Rp(_ArgTypes...)> { public: typedef _Rp result_type; // extension private: __packaged_task_function __f_; promise __p_; public: // construction and destruction _LIBCPP_INLINE_VISIBILITY packaged_task() _NOEXCEPT : __p_(nullptr) {} template ::type, packaged_task >::value >::type > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} template ::type, packaged_task >::value >::type > _LIBCPP_INLINE_VISIBILITY packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), __p_(allocator_arg, __a) {} // ~packaged_task() = default; // no copy packaged_task(const packaged_task&) = delete; packaged_task& operator=(const packaged_task&) = delete; // move support _LIBCPP_INLINE_VISIBILITY packaged_task(packaged_task&& __other) _NOEXCEPT : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} _LIBCPP_INLINE_VISIBILITY packaged_task& operator=(packaged_task&& __other) _NOEXCEPT { __f_ = _VSTD::move(__other.__f_); __p_ = _VSTD::move(__other.__p_); return *this; } _LIBCPP_INLINE_VISIBILITY void swap(packaged_task& __other) _NOEXCEPT { __f_.swap(__other.__f_); __p_.swap(__other.__p_); } _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} // result retrieval _LIBCPP_INLINE_VISIBILITY future get_future() {return __p_.get_future();} // execution void operator()(_ArgTypes... __args); void make_ready_at_thread_exit(_ArgTypes... __args); void reset(); }; template void packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) { if (__p_.__state_ == nullptr) __throw_future_error(future_errc::no_state); if (__p_.__state_->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...)); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __p_.set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) { if (__p_.__state_ == nullptr) __throw_future_error(future_errc::no_state); if (__p_.__state_->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...)); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __p_.set_exception_at_thread_exit(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void packaged_task<_Rp(_ArgTypes...)>::reset() { if (!valid()) __throw_future_error(future_errc::no_state); __p_ = promise(); } template class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task { public: typedef void result_type; // extension private: __packaged_task_function __f_; promise __p_; public: // construction and destruction _LIBCPP_INLINE_VISIBILITY packaged_task() _NOEXCEPT : __p_(nullptr) {} template ::type, packaged_task >::value >::type > _LIBCPP_INLINE_VISIBILITY explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {} template ::type, packaged_task >::value >::type > _LIBCPP_INLINE_VISIBILITY packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), __p_(allocator_arg, __a) {} // ~packaged_task() = default; // no copy packaged_task(const packaged_task&) = delete; packaged_task& operator=(const packaged_task&) = delete; // move support _LIBCPP_INLINE_VISIBILITY packaged_task(packaged_task&& __other) _NOEXCEPT : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {} _LIBCPP_INLINE_VISIBILITY packaged_task& operator=(packaged_task&& __other) _NOEXCEPT { __f_ = _VSTD::move(__other.__f_); __p_ = _VSTD::move(__other.__p_); return *this; } _LIBCPP_INLINE_VISIBILITY void swap(packaged_task& __other) _NOEXCEPT { __f_.swap(__other.__f_); __p_.swap(__other.__p_); } _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;} // result retrieval _LIBCPP_INLINE_VISIBILITY future get_future() {return __p_.get_future();} // execution void operator()(_ArgTypes... __args); void make_ready_at_thread_exit(_ArgTypes... __args); void reset(); }; template void packaged_task::operator()(_ArgTypes... __args) { if (__p_.__state_ == nullptr) __throw_future_error(future_errc::no_state); if (__p_.__state_->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __f_(_VSTD::forward<_ArgTypes>(__args)...); __p_.set_value(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __p_.set_exception(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void packaged_task::make_ready_at_thread_exit(_ArgTypes... __args) { if (__p_.__state_ == nullptr) __throw_future_error(future_errc::no_state); if (__p_.__state_->__has_value()) __throw_future_error(future_errc::promise_already_satisfied); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS __f_(_VSTD::forward<_ArgTypes>(__args)...); __p_.set_value_at_thread_exit(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __p_.set_exception_at_thread_exit(current_exception()); } #endif // _LIBCPP_NO_EXCEPTIONS } template void packaged_task::reset() { if (!valid()) __throw_future_error(future_errc::no_state); __p_ = promise(); } template inline _LIBCPP_INLINE_VISIBILITY void swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT { __x.swap(__y); } template struct _LIBCPP_TEMPLATE_VIS uses_allocator, _Alloc> : public true_type {}; template future<_Rp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __make_deferred_assoc_state(_Fp&& __f) #else __make_deferred_assoc_state(_Fp __f) #endif { unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count> __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); return future<_Rp>(__h.get()); } template future<_Rp> #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __make_async_assoc_state(_Fp&& __f) #else __make_async_assoc_state(_Fp __f) #endif { unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f))); _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach(); return future<_Rp>(__h.get()); } template class __async_func { tuple<_Fp, _Args...> __f_; public: typedef typename __invoke_of<_Fp, _Args...>::type _Rp; _LIBCPP_INLINE_VISIBILITY explicit __async_func(_Fp&& __f, _Args&&... __args) : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {} _LIBCPP_INLINE_VISIBILITY __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {} _Rp operator()() { typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index; return __execute(_Index()); } private: template _Rp __execute(__tuple_indices<_Indices...>) { return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...); } }; inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value ) { return (int(__policy) & int(__value)) != 0; } template +_LIBCPP_NODISCARD_AFTER_CXX17 future::type, typename decay<_Args>::type...>::type> async(launch __policy, _Fp&& __f, _Args&&... __args) { typedef __async_func::type, typename decay<_Args>::type...> _BF; typedef typename _BF::_Rp _Rp; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif if (__does_policy_contain(__policy, launch::async)) return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), __decay_copy(_VSTD::forward<_Args>(__args))...)); #ifndef _LIBCPP_NO_EXCEPTIONS } catch ( ... ) { if (__policy == launch::async) throw ; } #endif if (__does_policy_contain(__policy, launch::deferred)) return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)), __decay_copy(_VSTD::forward<_Args>(__args))...)); return future<_Rp>{}; } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY future::type, typename decay<_Args>::type...>::type> async(_Fp&& __f, _Args&&... __args) { return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f), _VSTD::forward<_Args>(__args)...); } #endif // _LIBCPP_HAS_NO_VARIADICS // shared_future template class _LIBCPP_TEMPLATE_VIS shared_future { __assoc_state<_Rp>* __state_; public: _LIBCPP_INLINE_VISIBILITY shared_future() _NOEXCEPT : __state_(nullptr) {} _LIBCPP_INLINE_VISIBILITY shared_future(const shared_future& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {if (__state_) __state_->__add_shared();} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_) {__f.__state_ = nullptr;} _LIBCPP_INLINE_VISIBILITY shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~shared_future(); shared_future& operator=(const shared_future& __rhs) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future& operator=(shared_future&& __rhs) _NOEXCEPT { shared_future(std::move(__rhs)).swap(*this); return *this; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES // retrieving the value _LIBCPP_INLINE_VISIBILITY const _Rp& get() const {return __state_->copy();} _LIBCPP_INLINE_VISIBILITY void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template shared_future<_Rp>::~shared_future() { if (__state_) __state_->__release_shared(); } template shared_future<_Rp>& shared_future<_Rp>::operator=(const shared_future& __rhs) _NOEXCEPT { if (__rhs.__state_) __rhs.__state_->__add_shared(); if (__state_) __state_->__release_shared(); __state_ = __rhs.__state_; return *this; } template class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&> { __assoc_state<_Rp&>* __state_; public: _LIBCPP_INLINE_VISIBILITY shared_future() _NOEXCEPT : __state_(nullptr) {} _LIBCPP_INLINE_VISIBILITY shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) {if (__state_) __state_->__add_shared();} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_) {__f.__state_ = nullptr;} _LIBCPP_INLINE_VISIBILITY shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~shared_future(); shared_future& operator=(const shared_future& __rhs); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future& operator=(shared_future&& __rhs) _NOEXCEPT { shared_future(std::move(__rhs)).swap(*this); return *this; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES // retrieving the value _LIBCPP_INLINE_VISIBILITY _Rp& get() const {return __state_->copy();} _LIBCPP_INLINE_VISIBILITY void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template shared_future<_Rp&>::~shared_future() { if (__state_) __state_->__release_shared(); } template shared_future<_Rp&>& shared_future<_Rp&>::operator=(const shared_future& __rhs) { if (__rhs.__state_) __rhs.__state_->__add_shared(); if (__state_) __state_->__release_shared(); __state_ = __rhs.__state_; return *this; } template <> class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE shared_future { __assoc_sub_state* __state_; public: _LIBCPP_INLINE_VISIBILITY shared_future() _NOEXCEPT : __state_(nullptr) {} _LIBCPP_INLINE_VISIBILITY shared_future(const shared_future& __rhs) : __state_(__rhs.__state_) {if (__state_) __state_->__add_shared();} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future(future&& __f) _NOEXCEPT : __state_(__f.__state_) {__f.__state_ = nullptr;} _LIBCPP_INLINE_VISIBILITY shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;} #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES ~shared_future(); shared_future& operator=(const shared_future& __rhs); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_future& operator=(shared_future&& __rhs) _NOEXCEPT { shared_future(std::move(__rhs)).swap(*this); return *this; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES // retrieving the value _LIBCPP_INLINE_VISIBILITY void get() const {__state_->copy();} _LIBCPP_INLINE_VISIBILITY void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);} // functions to check state _LIBCPP_INLINE_VISIBILITY bool valid() const _NOEXCEPT {return __state_ != nullptr;} _LIBCPP_INLINE_VISIBILITY void wait() const {__state_->wait();} template _LIBCPP_INLINE_VISIBILITY future_status wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {return __state_->wait_for(__rel_time);} template _LIBCPP_INLINE_VISIBILITY future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {return __state_->wait_until(__abs_time);} }; template inline _LIBCPP_INLINE_VISIBILITY void swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT { __x.swap(__y); } template inline shared_future<_Rp> future<_Rp>::share() _NOEXCEPT { return shared_future<_Rp>(_VSTD::move(*this)); } template inline shared_future<_Rp&> future<_Rp&>::share() _NOEXCEPT { return shared_future<_Rp&>(_VSTD::move(*this)); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES inline shared_future future::share() _NOEXCEPT { return shared_future(_VSTD::move(*this)); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_END_NAMESPACE_STD #endif // !_LIBCPP_HAS_NO_THREADS #endif // _LIBCPP_FUTURE Index: projects/clang600-import/contrib/libc++/include/istream =================================================================== --- projects/clang600-import/contrib/libc++/include/istream (revision 327038) +++ projects/clang600-import/contrib/libc++/include/istream (revision 327039) @@ -1,1690 +1,1692 @@ // -*- C++ -*- //===--------------------------- istream ----------------------------------===// // // 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_ISTREAM #define _LIBCPP_ISTREAM /* istream synopsis template > class basic_istream : virtual public basic_ios { public: // types (inherited from basic_ios (27.5.4)): typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // 27.7.1.1.1 Constructor/destructor: explicit basic_istream(basic_streambuf* sb); basic_istream(basic_istream&& rhs); virtual ~basic_istream(); // 27.7.1.1.2 Assign/swap: basic_istream& operator=(basic_istream&& rhs); void swap(basic_istream& rhs); // 27.7.1.1.3 Prefix/suffix: class sentry; // 27.7.1.2 Formatted input: basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); basic_istream& operator>>(basic_ios& (*pf)(basic_ios&)); basic_istream& operator>>(ios_base& (*pf)(ios_base&)); basic_istream& operator>>(basic_streambuf* sb); basic_istream& operator>>(bool& n); basic_istream& operator>>(short& n); basic_istream& operator>>(unsigned short& n); basic_istream& operator>>(int& n); basic_istream& operator>>(unsigned int& n); basic_istream& operator>>(long& n); basic_istream& operator>>(unsigned long& n); basic_istream& operator>>(long long& n); basic_istream& operator>>(unsigned long long& n); basic_istream& operator>>(float& f); basic_istream& operator>>(double& f); basic_istream& operator>>(long double& f); basic_istream& operator>>(void*& p); // 27.7.1.3 Unformatted input: streamsize gcount() const; int_type get(); basic_istream& get(char_type& c); basic_istream& get(char_type* s, streamsize n); basic_istream& get(char_type* s, streamsize n, char_type delim); basic_istream& get(basic_streambuf& sb); basic_istream& get(basic_streambuf& sb, char_type delim); basic_istream& getline(char_type* s, streamsize n); basic_istream& getline(char_type* s, streamsize n, char_type delim); basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof()); int_type peek(); basic_istream& read (char_type* s, streamsize n); streamsize readsome(char_type* s, streamsize n); basic_istream& putback(char_type c); basic_istream& unget(); int sync(); pos_type tellg(); basic_istream& seekg(pos_type); basic_istream& seekg(off_type, ios_base::seekdir); protected: basic_istream(const basic_istream& rhs) = delete; basic_istream(basic_istream&& rhs); // 27.7.2.1.2 Assign/swap: basic_istream& operator=(const basic_istream& rhs) = delete; basic_istream& operator=(basic_istream&& rhs); void swap(basic_istream& rhs); }; // 27.7.1.2.3 character extraction templates: template basic_istream& operator>>(basic_istream&, charT&); template basic_istream& operator>>(basic_istream&, unsigned char&); template basic_istream& operator>>(basic_istream&, signed char&); template basic_istream& operator>>(basic_istream&, charT*); template basic_istream& operator>>(basic_istream&, unsigned char*); template basic_istream& operator>>(basic_istream&, signed char*); template void swap(basic_istream& x, basic_istream& y); typedef basic_istream istream; typedef basic_istream wistream; template > class basic_iostream : public basic_istream, public basic_ostream { public: // types: typedef charT char_type; typedef traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // constructor/destructor explicit basic_iostream(basic_streambuf* sb); basic_iostream(basic_iostream&& rhs); virtual ~basic_iostream(); // assign/swap basic_iostream& operator=(basic_iostream&& rhs); void swap(basic_iostream& rhs); }; template void swap(basic_iostream& x, basic_iostream& y); typedef basic_iostream iostream; typedef basic_iostream wiostream; template basic_istream& ws(basic_istream& is); template basic_istream& operator>>(basic_istream&& is, T& x); } // std */ #include <__config> #include #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 _LIBCPP_TEMPLATE_VIS basic_istream : virtual public basic_ios<_CharT, _Traits> { streamsize __gc_; public: // types (inherited from basic_ios (27.5.4)): typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // 27.7.1.1.1 Constructor/destructor: inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY explicit basic_istream(basic_streambuf* __sb) : __gc_(0) { this->init(__sb); } virtual ~basic_istream(); protected: #ifndef _LIBCPP_CXX03_LANG inline _LIBCPP_INLINE_VISIBILITY basic_istream(basic_istream&& __rhs); // 27.7.1.1.2 Assign/swap: inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator=(basic_istream&& __rhs); #endif inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void swap(basic_istream& __rhs) { _VSTD::swap(__gc_, __rhs.__gc_); basic_ios::swap(__rhs); } #ifndef _LIBCPP_CXX03_LANG basic_istream (const basic_istream& __rhs) = delete; basic_istream& operator=(const basic_istream& __rhs) = delete; #endif public: // 27.7.1.1.3 Prefix/suffix: class _LIBCPP_TEMPLATE_VIS sentry; // 27.7.1.2 Formatted input: inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) { return __pf(*this); } inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& operator>>(basic_ios& (*__pf)(basic_ios&)) { __pf(*this); return *this; } inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) { __pf(*this); return *this; } basic_istream& operator>>(basic_streambuf* __sb); basic_istream& operator>>(bool& __n); basic_istream& operator>>(short& __n); basic_istream& operator>>(unsigned short& __n); basic_istream& operator>>(int& __n); basic_istream& operator>>(unsigned int& __n); basic_istream& operator>>(long& __n); basic_istream& operator>>(unsigned long& __n); basic_istream& operator>>(long long& __n); basic_istream& operator>>(unsigned long long& __n); basic_istream& operator>>(float& __f); basic_istream& operator>>(double& __f); basic_istream& operator>>(long double& __f); basic_istream& operator>>(void*& __p); // 27.7.1.3 Unformatted input: _LIBCPP_INLINE_VISIBILITY streamsize gcount() const {return __gc_;} int_type get(); inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& get(char_type& __c) { int_type __ch = get(); if (__ch != traits_type::eof()) __c = traits_type::to_char_type(__ch); return *this; } inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& get(char_type* __s, streamsize __n) { return get(__s, __n, this->widen('\n')); } basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& get(basic_streambuf& __sb) { return get(__sb, this->widen('\n')); } basic_istream& get(basic_streambuf& __sb, char_type __dlm); inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY basic_istream& getline(char_type* __s, streamsize __n) { return getline(__s, __n, this->widen('\n')); } basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); int_type peek(); basic_istream& read (char_type* __s, streamsize __n); streamsize readsome(char_type* __s, streamsize __n); basic_istream& putback(char_type __c); basic_istream& unget(); int sync(); pos_type tellg(); basic_istream& seekg(pos_type __pos); basic_istream& seekg(off_type __off, ios_base::seekdir __dir); }; template class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry { bool __ok_; sentry(const sentry&); // = delete; sentry& operator=(const sentry&); // = delete; public: explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); // ~sentry() = default; _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const {return __ok_;} }; template basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws) : __ok_(false) { if (__is.good()) { if (__is.tie()) __is.tie()->flush(); if (!__noskipws && (__is.flags() & ios_base::skipws)) { typedef istreambuf_iterator<_CharT, _Traits> _Ip; const ctype<_CharT>& __ct = use_facet >(__is.getloc()); _Ip __i(__is); _Ip __eof; for (; __i != __eof; ++__i) if (!__ct.is(__ct.space, *__i)) break; if (__i == __eof) __is.setstate(ios_base::failbit | ios_base::eofbit); } __ok_ = __is.good(); } else __is.setstate(ios_base::failbit); } #ifndef _LIBCPP_CXX03_LANG template basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) : __gc_(__rhs.__gc_) { __rhs.__gc_ = 0; this->move(__rhs); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) { swap(__rhs); return *this; } #endif // _LIBCPP_CXX03_LANG template basic_istream<_CharT, _Traits>::~basic_istream() { } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long long& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(float& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(double& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long double& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(bool& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(short& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; long __temp; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); if (__temp < numeric_limits::min()) { __err |= ios_base::failbit; __n = numeric_limits::min(); } else if (__temp > numeric_limits::max()) { __err |= ios_base::failbit; __n = numeric_limits::max(); } else __n = static_cast(__temp); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(int& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this); if (__s) { typedef istreambuf_iterator _Ip; typedef num_get _Fp; ios_base::iostate __err = ios_base::goodbit; long __temp; use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); if (__temp < numeric_limits::min()) { __err |= ios_base::failbit; __n = numeric_limits::min(); } else if (__temp > numeric_limits::max()) { __err |= ios_base::failbit; __n = numeric_limits::max(); } else __n = static_cast(__temp); this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is); if (__sen) { streamsize __n = __is.width(); if (__n <= 0) __n = numeric_limits::max() / sizeof(_CharT) - 1; streamsize __c = 0; const ctype<_CharT>& __ct = use_facet >(__is.getloc()); ios_base::iostate __err = ios_base::goodbit; while (__c < __n-1) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { __err |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); if (__ct.is(__ct.space, __ch)) break; *__s++ = __ch; ++__c; __is.rdbuf()->sbumpc(); } *__s = _CharT(); __is.width(0); if (__c == 0) __err |= ios_base::failbit; __is.setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator>>(basic_istream& __is, unsigned char* __s) { return __is >> (char*)__s; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator>>(basic_istream& __is, signed char* __s) { return __is >> (char*)__s; } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is); if (__sen) { typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); if (_Traits::eq_int_type(__i, _Traits::eof())) __is.setstate(ios_base::eofbit | ios_base::failbit); else __c = _Traits::to_char_type(__i); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator>>(basic_istream& __is, unsigned char& __c) { return __is >> (char&)__c; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream& operator>>(basic_istream& __is, signed char& __c) { return __is >> (char&)__c; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_streambuf* __sb) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this, true); if (__s) { if (__sb) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS ios_base::iostate __err = ios_base::goodbit; while (true) { typename traits_type::int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, _Traits::eof())) { __err |= ios_base::eofbit; break; } if (traits_type::eq_int_type( __sb->sputc(traits_type::to_char_type(__i)), traits_type::eof())) break; ++__gc_; this->rdbuf()->sbumpc(); } if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { if (__gc_ == 0) this->__set_failbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS } else this->setstate(ios_base::failbit); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get() { __gc_ = 0; int_type __r = traits_type::eof(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __s(*this, true); if (__s) { __r = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__r, traits_type::eof())) this->setstate(ios_base::failbit | ios_base::eofbit); else __gc_ = 1; } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __r; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { if (__n > 0) { ios_base::iostate __err = ios_base::goodbit; while (__gc_ < __n-1) { int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { __err |= ios_base::eofbit; break; } char_type __ch = traits_type::to_char_type(__i); if (traits_type::eq(__ch, __dlm)) break; *__s++ = __ch; ++__gc_; this->rdbuf()->sbumpc(); } *__s = char_type(); if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); } else this->setstate(ios_base::failbit); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(basic_streambuf& __sb, char_type __dlm) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { ios_base::iostate __err = ios_base::goodbit; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS while (true) { typename traits_type::int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { __err |= ios_base::eofbit; break; } char_type __ch = traits_type::to_char_type(__i); if (traits_type::eq(__ch, __dlm)) break; if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) break; ++__gc_; this->rdbuf()->sbumpc(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { } #endif // _LIBCPP_NO_EXCEPTIONS if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { ios_base::iostate __err = ios_base::goodbit; while (true) { typename traits_type::int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { __err |= ios_base::eofbit; break; } char_type __ch = traits_type::to_char_type(__i); if (traits_type::eq(__ch, __dlm)) { this->rdbuf()->sbumpc(); ++__gc_; break; } if (__gc_ >= __n-1) { __err |= ios_base::failbit; break; } *__s++ = __ch; this->rdbuf()->sbumpc(); ++__gc_; } - if (__n > 0) - *__s = char_type(); if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); } + if (__n > 0) + *__s = char_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { + if (__n > 0) + *__s = char_type(); this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { ios_base::iostate __err = ios_base::goodbit; if (__n == numeric_limits::max()) { while (true) { typename traits_type::int_type __i = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { __err |= ios_base::eofbit; break; } ++__gc_; if (traits_type::eq_int_type(__i, __dlm)) break; } } else { while (__gc_ < __n) { typename traits_type::int_type __i = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { __err |= ios_base::eofbit; break; } ++__gc_; if (traits_type::eq_int_type(__i, __dlm)) break; } } this->setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek() { __gc_ = 0; int_type __r = traits_type::eof(); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { __r = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__r, traits_type::eof())) this->setstate(ios_base::eofbit); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __r; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { __gc_ = this->rdbuf()->sgetn(__s, __n); if (__gc_ != __n) this->setstate(ios_base::failbit | ios_base::eofbit); } else this->setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { streamsize __c = this->rdbuf()->in_avail(); switch (__c) { case -1: this->setstate(ios_base::eofbit); break; case 0: break; default: read(__s, _VSTD::min(__c, __n)); break; } } else this->setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __gc_; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_type __c) { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->clear(this->rdstate() & ~ios_base::eofbit); sentry __sen(*this, true); if (__sen) { if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) this->setstate(ios_base::badbit); } else this->setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() { __gc_ = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->clear(this->rdstate() & ~ios_base::eofbit); sentry __sen(*this, true); if (__sen) { if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) this->setstate(ios_base::badbit); } else this->setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template int basic_istream<_CharT, _Traits>::sync() { int __r = 0; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) { if (this->rdbuf() == 0) return -1; if (this->rdbuf()->pubsync() == -1) { this->setstate(ios_base::badbit); return -1; } } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __r; } template typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>::tellg() { pos_type __r(-1); #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS sentry __sen(*this, true); if (__sen) __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __r; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->clear(this->rdstate() & ~ios_base::eofbit); sentry __sen(*this, true); if (__sen) { if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) this->setstate(ios_base::failbit); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS this->clear(this->rdstate() & ~ios_base::eofbit); sentry __sen(*this, true); if (__sen) { if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) this->setstate(ios_base::failbit); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return *this; } template basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _Traits>& __is) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); if (__sen) { const ctype<_CharT>& __ct = use_facet >(__is.getloc()); while (true) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { __is.setstate(ios_base::eofbit); break; } if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) break; __is.rdbuf()->sbumpc(); } } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) { __is >> _VSTD::forward<_Tp>(__x); return __is; } #endif // _LIBCPP_CXX03_LANG template class _LIBCPP_TEMPLATE_VIS basic_iostream : public basic_istream<_CharT, _Traits>, public basic_ostream<_CharT, _Traits> { public: // types: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // constructor/destructor inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY explicit basic_iostream(basic_streambuf* __sb) : basic_istream<_CharT, _Traits>(__sb) {} virtual ~basic_iostream(); protected: #ifndef _LIBCPP_CXX03_LANG inline _LIBCPP_INLINE_VISIBILITY basic_iostream(basic_iostream&& __rhs); // assign/swap inline _LIBCPP_INLINE_VISIBILITY basic_iostream& operator=(basic_iostream&& __rhs); #endif inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void swap(basic_iostream& __rhs) { basic_istream::swap(__rhs); } public: }; #ifndef _LIBCPP_CXX03_LANG template basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) { } template basic_iostream<_CharT, _Traits>& basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) { swap(__rhs); return *this; } #endif // _LIBCPP_CXX03_LANG template basic_iostream<_CharT, _Traits>::~basic_iostream() { } template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is); if (__sen) { __str.clear(); streamsize __n = __is.width(); if (__n <= 0) __n = __str.max_size(); if (__n <= 0) __n = numeric_limits::max(); streamsize __c = 0; const ctype<_CharT>& __ct = use_facet >(__is.getloc()); ios_base::iostate __err = ios_base::goodbit; while (__c < __n) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { __err |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); if (__ct.is(__ct.space, __ch)) break; __str.push_back(__ch); ++__c; __is.rdbuf()->sbumpc(); } __is.width(0); if (__c == 0) __err |= ios_base::failbit; __is.setstate(__err); } else __is.setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } template basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); if (__sen) { __str.clear(); ios_base::iostate __err = ios_base::goodbit; streamsize __extr = 0; while (true) { typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { __err |= ios_base::eofbit; break; } ++__extr; _CharT __ch = _Traits::to_char_type(__i); if (_Traits::eq(__ch, __dlm)) break; __str.push_back(__ch); if (__str.size() == __str.max_size()) { __err |= ios_base::failbit; break; } } if (__extr == 0) __err |= ios_base::failbit; __is.setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { return getline(__is, __str, __is.widen('\n')); } #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) { return getline(__is, __str, __dlm); } template inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { return getline(__is, __str, __is.widen('\n')); } #endif // _LIBCPP_CXX03_LANG template basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS typename basic_istream<_CharT, _Traits>::sentry __sen(__is); if (__sen) { basic_string<_CharT, _Traits> __str; const ctype<_CharT>& __ct = use_facet >(__is.getloc()); size_t __c = 0; ios_base::iostate __err = ios_base::goodbit; _CharT __zero = __ct.widen('0'); _CharT __one = __ct.widen('1'); while (__c < _Size) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { __err |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) break; __str.push_back(__ch); ++__c; __is.rdbuf()->sbumpc(); } __x = bitset<_Size>(__str); if (__c == 0) __err |= ios_base::failbit; __is.setstate(__err); } else __is.setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS return __is; } #ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream) #endif _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_ISTREAM Index: projects/clang600-import/contrib/libc++/include/iterator =================================================================== --- projects/clang600-import/contrib/libc++/include/iterator (revision 327038) +++ projects/clang600-import/contrib/libc++/include/iterator (revision 327039) @@ -1,1828 +1,1882 @@ // -*- C++ -*- //===-------------------------- iterator ----------------------------------===// // // 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_ITERATOR #define _LIBCPP_ITERATOR /* iterator synopsis namespace std { template struct iterator_traits { typedef typename Iterator::difference_type difference_type; typedef typename Iterator::value_type value_type; typedef typename Iterator::pointer pointer; typedef typename Iterator::reference reference; typedef typename Iterator::iterator_category iterator_category; }; template struct iterator_traits { typedef ptrdiff_t difference_type; typedef T value_type; typedef T* pointer; typedef T& reference; typedef random_access_iterator_tag iterator_category; }; -template -struct iterator_traits -{ - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef const T* pointer; - typedef const T& reference; - typedef random_access_iterator_tag iterator_category; -}; - template struct iterator { typedef T value_type; typedef Distance difference_type; typedef Pointer pointer; typedef Reference reference; typedef Category iterator_category; }; struct input_iterator_tag {}; struct output_iterator_tag {}; struct forward_iterator_tag : public input_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {}; // 27.4.3, iterator operations // extension: second argument not conforming to C++03 template // constexpr in C++17 constexpr void advance(InputIterator& i, typename iterator_traits::difference_type n); template // constexpr in C++17 constexpr typename iterator_traits::difference_type distance(InputIterator first, InputIterator last); template // constexpr in C++17 constexpr InputIterator next(InputIterator x, typename iterator_traits::difference_type n = 1); template // constexpr in C++17 constexpr BidirectionalIterator prev(BidirectionalIterator x, typename iterator_traits::difference_type n = 1); template class reverse_iterator : public iterator::iterator_category, typename iterator_traits::value_type, typename iterator_traits::difference_type, typename iterator_traits::pointer, typename iterator_traits::reference> { protected: Iterator current; public: typedef Iterator iterator_type; typedef typename iterator_traits::difference_type difference_type; typedef typename iterator_traits::reference reference; typedef typename iterator_traits::pointer pointer; constexpr reverse_iterator(); constexpr explicit reverse_iterator(Iterator x); template constexpr reverse_iterator(const reverse_iterator& u); template constexpr reverse_iterator& operator=(const reverse_iterator& u); constexpr Iterator base() const; constexpr reference operator*() const; constexpr pointer operator->() const; constexpr reverse_iterator& operator++(); constexpr reverse_iterator operator++(int); constexpr reverse_iterator& operator--(); constexpr reverse_iterator operator--(int); constexpr reverse_iterator operator+ (difference_type n) const; constexpr reverse_iterator& operator+=(difference_type n); constexpr reverse_iterator operator- (difference_type n) const; constexpr reverse_iterator& operator-=(difference_type n); constexpr reference operator[](difference_type n) const; }; template constexpr bool // constexpr in C++17 operator==(const reverse_iterator& x, const reverse_iterator& y); template constexpr bool // constexpr in C++17 operator<(const reverse_iterator& x, const reverse_iterator& y); template constexpr bool // constexpr in C++17 operator!=(const reverse_iterator& x, const reverse_iterator& y); template constexpr bool // constexpr in C++17 operator>(const reverse_iterator& x, const reverse_iterator& y); template constexpr bool // constexpr in C++17 operator>=(const reverse_iterator& x, const reverse_iterator& y); template constexpr bool // constexpr in C++17 operator<=(const reverse_iterator& x, const reverse_iterator& y); template constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> decltype(__y.base() - __x.base()); // constexpr in C++17 template constexpr reverse_iterator operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x); // constexpr in C++17 template constexpr reverse_iterator make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 template class back_insert_iterator { protected: Container* container; public: typedef Container container_type; typedef void value_type; typedef void difference_type; typedef void reference; typedef void pointer; explicit back_insert_iterator(Container& x); back_insert_iterator& operator=(const typename Container::value_type& value); back_insert_iterator& operator*(); back_insert_iterator& operator++(); back_insert_iterator operator++(int); }; template back_insert_iterator back_inserter(Container& x); template class front_insert_iterator { protected: Container* container; public: typedef Container container_type; typedef void value_type; typedef void difference_type; typedef void reference; typedef void pointer; explicit front_insert_iterator(Container& x); front_insert_iterator& operator=(const typename Container::value_type& value); front_insert_iterator& operator*(); front_insert_iterator& operator++(); front_insert_iterator operator++(int); }; template front_insert_iterator front_inserter(Container& x); template class insert_iterator { protected: Container* container; typename Container::iterator iter; public: typedef Container container_type; typedef void value_type; typedef void difference_type; typedef void reference; typedef void pointer; insert_iterator(Container& x, typename Container::iterator i); insert_iterator& operator=(const typename Container::value_type& value); insert_iterator& operator*(); insert_iterator& operator++(); insert_iterator& operator++(int); }; template insert_iterator inserter(Container& x, Iterator i); template class move_iterator { public: typedef Iterator iterator_type; typedef typename iterator_traits::difference_type difference_type; typedef Iterator pointer; typedef typename iterator_traits::value_type value_type; typedef typename iterator_traits::iterator_category iterator_category; typedef value_type&& reference; constexpr move_iterator(); // all the constexprs are in C++17 constexpr explicit move_iterator(Iterator i); template constexpr move_iterator(const move_iterator& u); template constexpr move_iterator& operator=(const move_iterator& u); constexpr iterator_type base() const; constexpr reference operator*() const; constexpr pointer operator->() const; constexpr move_iterator& operator++(); constexpr move_iterator operator++(int); constexpr move_iterator& operator--(); constexpr move_iterator operator--(int); constexpr move_iterator operator+(difference_type n) const; constexpr move_iterator& operator+=(difference_type n); constexpr move_iterator operator-(difference_type n) const; constexpr move_iterator& operator-=(difference_type n); constexpr unspecified operator[](difference_type n) const; private: Iterator current; // exposition only }; template constexpr bool // constexpr in C++17 operator==(const move_iterator& x, const move_iterator& y); template constexpr bool // constexpr in C++17 operator!=(const move_iterator& x, const move_iterator& y); template constexpr bool // constexpr in C++17 operator<(const move_iterator& x, const move_iterator& y); template constexpr bool // constexpr in C++17 operator<=(const move_iterator& x, const move_iterator& y); template constexpr bool // constexpr in C++17 operator>(const move_iterator& x, const move_iterator& y); template constexpr bool // constexpr in C++17 operator>=(const move_iterator& x, const move_iterator& y); template constexpr auto // constexpr in C++17 operator-(const move_iterator& x, const move_iterator& y) -> decltype(x.base() - y.base()); template constexpr move_iterator operator+( // constexpr in C++17 typename move_iterator::difference_type n, const move_iterator& x); template // constexpr in C++17 constexpr move_iterator make_move_iterator(const Iterator& i); template , class Distance = ptrdiff_t> class istream_iterator : public iterator { public: typedef charT char_type; typedef traits traits_type; typedef basic_istream istream_type; constexpr istream_iterator(); istream_iterator(istream_type& s); istream_iterator(const istream_iterator& x); ~istream_iterator(); const T& operator*() const; const T* operator->() const; istream_iterator& operator++(); istream_iterator operator++(int); }; template bool operator==(const istream_iterator& x, const istream_iterator& y); template bool operator!=(const istream_iterator& x, const istream_iterator& y); template > class ostream_iterator : public iterator { public: typedef charT char_type; typedef traits traits_type; typedef basic_ostream ostream_type; ostream_iterator(ostream_type& s); ostream_iterator(ostream_type& s, const charT* delimiter); ostream_iterator(const ostream_iterator& x); ~ostream_iterator(); ostream_iterator& operator=(const T& value); ostream_iterator& operator*(); ostream_iterator& operator++(); ostream_iterator& operator++(int); }; template > class istreambuf_iterator : public iterator { public: typedef charT char_type; typedef traits traits_type; typedef typename traits::int_type int_type; typedef basic_streambuf streambuf_type; typedef basic_istream istream_type; istreambuf_iterator() noexcept; istreambuf_iterator(istream_type& s) noexcept; istreambuf_iterator(streambuf_type* s) noexcept; istreambuf_iterator(a-private-type) noexcept; charT operator*() const; pointer operator->() const; istreambuf_iterator& operator++(); a-private-type operator++(int); bool equal(const istreambuf_iterator& b) const; }; template bool operator==(const istreambuf_iterator& a, const istreambuf_iterator& b); template bool operator!=(const istreambuf_iterator& a, const istreambuf_iterator& b); template > class ostreambuf_iterator : public iterator { public: typedef charT char_type; typedef traits traits_type; typedef basic_streambuf streambuf_type; typedef basic_ostream ostream_type; ostreambuf_iterator(ostream_type& s) noexcept; ostreambuf_iterator(streambuf_type* s) noexcept; ostreambuf_iterator& operator=(charT c); ostreambuf_iterator& operator*(); ostreambuf_iterator& operator++(); ostreambuf_iterator& operator++(int); bool failed() const noexcept; }; template constexpr auto begin(C& c) -> decltype(c.begin()); template constexpr auto begin(const C& c) -> decltype(c.begin()); template constexpr auto end(C& c) -> decltype(c.end()); template constexpr auto end(const C& c) -> decltype(c.end()); template constexpr T* begin(T (&array)[N]); template constexpr T* end(T (&array)[N]); template auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 template auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 template auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 template auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 template auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 template constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 template reverse_iterator constexpr rbegin(initializer_list il); // C++14 template reverse_iterator constexpr rend(initializer_list il); // C++14 template reverse_iterator constexpr rbegin(T (&array)[N]); // C++14 template reverse_iterator constexpr rend(T (&array)[N]); // C++14 template constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 template constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 // 24.8, container access: template constexpr auto size(const C& c) -> decltype(c.size()); // C++17 template constexpr size_t size(const T (&array)[N]) noexcept; // C++17 template constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 template constexpr bool empty(const T (&array)[N]) noexcept; // C++17 template constexpr bool empty(initializer_list il) noexcept; // C++17 template constexpr auto data(C& c) -> decltype(c.data()); // C++17 template constexpr auto data(const C& c) -> decltype(c.data()); // C++17 template constexpr T* data(T (&array)[N]) noexcept; // C++17 template constexpr const E* data(initializer_list il) noexcept; // C++17 } // std */ #include <__config> #include // for forward declarations of vector and string. #include <__functional_base> #include #include #include #ifdef __APPLE__ #include #endif #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_STD struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; template struct __has_iterator_category { private: struct __two {char __lx; char __lxx;}; template static __two __test(...); template static char __test(typename _Up::iterator_category* = 0); public: static const bool value = sizeof(__test<_Tp>(0)) == 1; }; template struct __iterator_traits_impl {}; template struct __iterator_traits_impl<_Iter, true> { typedef typename _Iter::difference_type difference_type; typedef typename _Iter::value_type value_type; typedef typename _Iter::pointer pointer; typedef typename _Iter::reference reference; typedef typename _Iter::iterator_category iterator_category; }; template struct __iterator_traits {}; template struct __iterator_traits<_Iter, true> : __iterator_traits_impl < _Iter, is_convertible::value || is_convertible::value > {}; // iterator_traits will only have the nested types if Iterator::iterator_category // exists. Else iterator_traits will be an empty class. This is a // conforming extension which allows some programs to compile and behave as // the client expects instead of failing at compile time. template struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {}; template struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> { typedef ptrdiff_t difference_type; - typedef typename remove_const<_Tp>::type value_type; + typedef typename remove_cv<_Tp>::type value_type; typedef _Tp* pointer; typedef _Tp& reference; typedef random_access_iterator_tag iterator_category; }; template >::value> struct __has_iterator_category_convertible_to : public integral_constant::iterator_category, _Up>::value> {}; template struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; template struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; template struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; template struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; template struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; template struct __is_exactly_input_iterator : public integral_constant::value && !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; template struct _LIBCPP_TEMPLATE_VIS iterator { typedef _Tp value_type; typedef _Distance difference_type; typedef _Pointer pointer; typedef _Reference reference; typedef _Category iterator_category; }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) { for (; __n > 0; --__n) ++__i; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_BiDirIter& __i, typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) { if (__n >= 0) for (; __n > 0; --__n) ++__i; else for (; __n < 0; ++__n) --__i; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void __advance(_RandIter& __i, typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) { __i += __n; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n) { __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_InputIter>::difference_type __distance(_InputIter __first, _InputIter __last, input_iterator_tag) { typename iterator_traits<_InputIter>::difference_type __r(0); for (; __first != __last; ++__first) ++__r; return __r; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_RandIter>::difference_type __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) { return __last - __first; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename iterator_traits<_InputIter>::difference_type distance(_InputIter __first, _InputIter __last) { return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_InputIter +typename enable_if +< + __is_input_iterator<_InputIter>::value, + _InputIter +>::type next(_InputIter __x, - typename iterator_traits<_InputIter>::difference_type __n = 1, - typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0) + typename iterator_traits<_InputIter>::difference_type __n = 1) { _VSTD::advance(__x, __n); return __x; } -template +template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_BidiretionalIter -prev(_BidiretionalIter __x, - typename iterator_traits<_BidiretionalIter>::difference_type __n = 1, - typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0) +typename enable_if +< + __is_bidirectional_iterator<_BidirectionalIter>::value, + _BidirectionalIter +>::type +prev(_BidirectionalIter __x, + typename iterator_traits<_BidirectionalIter>::difference_type __n = 1) { _VSTD::advance(__x, -__n); return __x; } template struct __is_stashing_iterator : false_type {}; template struct __is_stashing_iterator<_Tp, typename __void_t::type> : true_type {}; template class _LIBCPP_TEMPLATE_VIS reverse_iterator : public iterator::iterator_category, typename iterator_traits<_Iter>::value_type, typename iterator_traits<_Iter>::difference_type, typename iterator_traits<_Iter>::pointer, typename iterator_traits<_Iter>::reference> { private: /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break static_assert(!__is_stashing_iterator<_Iter>::value, "The specified iterator type cannot be used with reverse_iterator; " "Using stashing iterators with reverse_iterator causes undefined behavior"); protected: _Iter current; public: typedef _Iter iterator_type; typedef typename iterator_traits<_Iter>::difference_type difference_type; typedef typename iterator_traits<_Iter>::reference reference; typedef typename iterator_traits<_Iter>::pointer pointer; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator() : __t(), current() {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) { __t = current = __u.base(); return *this; } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return current;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator*() const {_Iter __tmp = current; return *--__tmp;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 pointer operator->() const {return _VSTD::addressof(operator*());} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator& operator++() {--current; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator& operator--() {++current; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator[](difference_type __n) const {return *(*this + __n);} }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() == __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() > __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() != __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() < __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() <= __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __x.base() >= __y.base(); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) -> decltype(__y.base() - __x.base()) { return __y.base() - __x.base(); } #else template inline _LIBCPP_INLINE_VISIBILITY typename reverse_iterator<_Iter1>::difference_type operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) { return __y.base() - __x.base(); } #endif template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Iter> operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) { return reverse_iterator<_Iter>(__x.base() - __n); } #if _LIBCPP_STD_VER > 11 template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) { return reverse_iterator<_Iter>(__i); } #endif template class _LIBCPP_TEMPLATE_VIS back_insert_iterator : public iterator { protected: _Container* container; public: typedef _Container container_type; _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) {container->push_back(__value_); return *this;} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) {container->push_back(_VSTD::move(__value_)); return *this;} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} }; template inline _LIBCPP_INLINE_VISIBILITY back_insert_iterator<_Container> back_inserter(_Container& __x) { return back_insert_iterator<_Container>(__x); } template class _LIBCPP_TEMPLATE_VIS front_insert_iterator : public iterator { protected: _Container* container; public: typedef _Container container_type; _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) {container->push_front(__value_); return *this;} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) {container->push_front(_VSTD::move(__value_)); return *this;} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} }; template inline _LIBCPP_INLINE_VISIBILITY front_insert_iterator<_Container> front_inserter(_Container& __x) { return front_insert_iterator<_Container>(__x); } template class _LIBCPP_TEMPLATE_VIS insert_iterator : public iterator { protected: _Container* container; typename _Container::iterator iter; public: typedef _Container container_type; _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) : container(_VSTD::addressof(__x)), iter(__i) {} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) {iter = container->insert(iter, __value_); ++iter; return *this;} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} }; template inline _LIBCPP_INLINE_VISIBILITY insert_iterator<_Container> inserter(_Container& __x, typename _Container::iterator __i) { return insert_iterator<_Container>(__x, __i); } template , class _Distance = ptrdiff_t> class _LIBCPP_TEMPLATE_VIS istream_iterator : public iterator { public: typedef _CharT char_type; typedef _Traits traits_type; typedef basic_istream<_CharT,_Traits> istream_type; private: istream_type* __in_stream_; _Tp __value_; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) { if (!(*__in_stream_ >> __value_)) __in_stream_ = 0; } _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() { if (!(*__in_stream_ >> __value_)) __in_stream_ = 0; return *this; } _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) {istream_iterator __t(*this); ++(*this); return __t;} + template friend _LIBCPP_INLINE_VISIBILITY - bool operator==(const istream_iterator& __x, const istream_iterator& __y) - {return __x.__in_stream_ == __y.__in_stream_;} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); + template friend _LIBCPP_INLINE_VISIBILITY - bool operator!=(const istream_iterator& __x, const istream_iterator& __y) - {return !(__x == __y);} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); }; +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return __x.__in_stream_ == __y.__in_stream_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return !(__x == __y); +} + template > class _LIBCPP_TEMPLATE_VIS ostream_iterator : public iterator { public: typedef _CharT char_type; typedef _Traits traits_type; typedef basic_ostream<_CharT,_Traits> ostream_type; private: ostream_type* __out_stream_; const char_type* __delim_; public: _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) { *__out_stream_ << __value_; if (__delim_) *__out_stream_ << __delim_; return *this; } _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} }; template class _LIBCPP_TEMPLATE_VIS istreambuf_iterator : public iterator { public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename _Traits::int_type int_type; typedef basic_streambuf<_CharT,_Traits> streambuf_type; typedef basic_istream<_CharT,_Traits> istream_type; private: mutable streambuf_type* __sbuf_; class __proxy { char_type __keep_; streambuf_type* __sbuf_; _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) : __keep_(__c), __sbuf_(__s) {} friend class istreambuf_iterator; public: _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} }; _LIBCPP_INLINE_VISIBILITY bool __test_for_eof() const { if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) __sbuf_ = 0; return __sbuf_ == 0; } public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {} _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {} _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT : __sbuf_(__p.__sbuf_) {} _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return static_cast(__sbuf_->sgetc());} _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() { __sbuf_->sbumpc(); return *this; } _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) { return __proxy(__sbuf_->sbumpc(), __sbuf_); } _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const {return __test_for_eof() == __b.__test_for_eof();} }; template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, const istreambuf_iterator<_CharT,_Traits>& __b) {return __a.equal(__b);} template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, const istreambuf_iterator<_CharT,_Traits>& __b) {return !__a.equal(__b);} template class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator : public iterator { public: typedef _CharT char_type; typedef _Traits traits_type; typedef basic_streambuf<_CharT,_Traits> streambuf_type; typedef basic_ostream<_CharT,_Traits> ostream_type; private: streambuf_type* __sbuf_; public: _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {} _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {} _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) { if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) __sbuf_ = 0; return *this; } _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} #if !defined(__APPLE__) || \ (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) template friend _LIBCPP_HIDDEN ostreambuf_iterator<_Ch, _Tr> __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl); #endif }; template class _LIBCPP_TEMPLATE_VIS move_iterator { private: _Iter __i; public: typedef _Iter iterator_type; typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::value_type value_type; typedef typename iterator_traits::difference_type difference_type; typedef iterator_type pointer; #ifndef _LIBCPP_CXX03_LANG typedef typename iterator_traits::reference __reference; typedef typename conditional< is_reference<__reference>::value, typename remove_reference<__reference>::type&&, __reference >::type reference; #else typedef typename iterator_traits::reference reference; #endif _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator() : __i() {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 explicit move_iterator(_Iter __x) : __i(__x) {} template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator*() const { return static_cast(*__i); } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 pointer operator->() const { return __i;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator& operator++() {++__i; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator& operator--() {--__i; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator[](difference_type __n) const { return static_cast(__i[__n]); } }; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() == __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() < __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() != __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() > __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() >= __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 bool operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() <= __y.base(); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) -> decltype(__x.base() - __y.base()) { return __x.base() - __y.base(); } #else template inline _LIBCPP_INLINE_VISIBILITY typename move_iterator<_Iter1>::difference_type operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() - __y.base(); } #endif template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator<_Iter> operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) { return move_iterator<_Iter>(__x.base() + __n); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator<_Iter> make_move_iterator(_Iter __i) { return move_iterator<_Iter>(__i); } // __wrap_iter template class __wrap_iter; template _LIBCPP_INLINE_VISIBILITY bool operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template _LIBCPP_INLINE_VISIBILITY bool operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template _LIBCPP_INLINE_VISIBILITY bool operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template _LIBCPP_INLINE_VISIBILITY bool operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template _LIBCPP_INLINE_VISIBILITY bool operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template _LIBCPP_INLINE_VISIBILITY bool operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()); #else template _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #endif template _LIBCPP_INLINE_VISIBILITY __wrap_iter<_Iter> operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG; template _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); template _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); template _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); template _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2); #if _LIBCPP_DEBUG_LEVEL < 2 template _LIBCPP_INLINE_VISIBILITY typename enable_if < is_trivially_copy_assignable<_Tp>::value, _Tp* >::type __unwrap_iter(__wrap_iter<_Tp*>); #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); #endif template class __wrap_iter { public: typedef _Iter iterator_type; typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::value_type value_type; typedef typename iterator_traits::difference_type difference_type; typedef typename iterator_traits::pointer pointer; typedef typename iterator_traits::reference reference; private: iterator_type __i; public: _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG #if _LIBCPP_STD_VER > 11 : __i{} #endif { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); #endif } template _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u, typename enable_if::value>::type* = 0) _NOEXCEPT_DEBUG : __i(__u.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__iterator_copy(this, &__u); #endif } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter& __x) : __i(__x.base()) { __get_db()->__iterator_copy(this, &__x); } _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator=(const __wrap_iter& __x) { if (this != &__x) { __get_db()->__iterator_copy(this, &__x); __i = __x.__i; } return *this; } _LIBCPP_INLINE_VISIBILITY ~__wrap_iter() { __get_db()->__erase_i(this); } #endif _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable iterator"); #endif return *__i; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable iterator"); #endif return (pointer)_VSTD::addressof(*__i); } _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable iterator"); #endif ++__i; return *this; } _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG {__wrap_iter __tmp(*this); ++(*this); return __tmp;} _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), "Attempted to decrement non-decrementable iterator"); #endif --__i; return *this; } _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG {__wrap_iter __tmp(*this); --(*this); return __tmp;} _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG {__wrap_iter __w(*this); __w += __n; return __w;} _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), "Attempted to add/subtract iterator outside of valid range"); #endif __i += __n; return *this; } _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG {return *this + (-__n);} _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG {*this += -__n; return *this;} _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), "Attempted to subscript iterator outside of valid range"); #endif return __i[__n]; } _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;} private: #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x) { __get_db()->__insert_ic(this, __p); } #else _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {} #endif template friend class __wrap_iter; template friend class basic_string; template friend class _LIBCPP_TEMPLATE_VIS vector; template friend bool operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template friend bool operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template friend bool operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template friend bool operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template friend bool operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; template friend bool operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #ifndef _LIBCPP_CXX03_LANG template friend auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()); #else template friend typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; #endif template friend __wrap_iter<_Iter1> operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG; template friend _Op copy(_Ip, _Ip, _Op); template friend _B2 copy_backward(_B1, _B1, _B2); template friend _Op move(_Ip, _Ip, _Op); template friend _B2 move_backward(_B1, _B1, _B2); #if _LIBCPP_DEBUG_LEVEL < 2 template friend typename enable_if < is_trivially_copy_assignable<_Tp>::value, _Tp* >::type __unwrap_iter(__wrap_iter<_Tp*>); #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); #endif }; template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return __x.base() == __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), "Attempted to compare incomparable iterators"); #endif return __x.base() < __y.base(); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG { return !(__y < __x); } #ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG -> decltype(__x.base() - __y.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), "Attempted to subtract incompatible iterators"); #endif return __x.base() - __y.base(); } #else template inline _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), "Attempted to subtract incompatible iterators"); #endif return __x.base() - __y.base(); } #endif template inline _LIBCPP_INLINE_VISIBILITY __wrap_iter<_Iter> operator+(typename __wrap_iter<_Iter>::difference_type __n, __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG { __x += __n; return __x; } template struct __libcpp_is_trivial_iterator : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; template struct __libcpp_is_trivial_iterator > : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template struct __libcpp_is_trivial_iterator > : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp* begin(_Tp (&__array)[_Np]) { return __array; } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp* end(_Tp (&__array)[_Np]) { return __array + _Np; } #if !defined(_LIBCPP_CXX03_LANG) template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(_Cp& __c) -> decltype(__c.begin()) { return __c.begin(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(const _Cp& __c) -> decltype(__c.begin()) { return __c.begin(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(_Cp& __c) -> decltype(__c.end()) { return __c.end(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(const _Cp& __c) -> decltype(__c.end()) { return __c.end(); } #if _LIBCPP_STD_VER > 11 template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin(initializer_list<_Ep> __il) { return reverse_iterator(__il.end()); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rend(initializer_list<_Ep> __il) { return reverse_iterator(__il.begin()); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) { return _VSTD::begin(__c); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) { return _VSTD::end(__c); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(const _Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) { return _VSTD::rbegin(__c); } template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) { return _VSTD::rend(__c); } #endif #else // defined(_LIBCPP_CXX03_LANG) template inline _LIBCPP_INLINE_VISIBILITY typename _Cp::iterator begin(_Cp& __c) { return __c.begin(); } template inline _LIBCPP_INLINE_VISIBILITY typename _Cp::const_iterator begin(const _Cp& __c) { return __c.begin(); } template inline _LIBCPP_INLINE_VISIBILITY typename _Cp::iterator end(_Cp& __c) { return __c.end(); } template inline _LIBCPP_INLINE_VISIBILITY typename _Cp::const_iterator end(const _Cp& __c) { return __c.end(); } #endif // !defined(_LIBCPP_CXX03_LANG) #if _LIBCPP_STD_VER > 14 + +// #if _LIBCPP_STD_VER > 11 +// template <> +// struct _LIBCPP_TEMPLATE_VIS plus +// { +// template +// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +// auto operator()(_T1&& __t, _T2&& __u) const +// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) +// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) +// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } +// typedef void is_transparent; +// }; +// #endif + template -constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); } +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } template +inline _LIBCPP_INLINE_VISIBILITY constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } template -constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); } +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } template +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } template +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } template constexpr -auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template constexpr -auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template +inline _LIBCPP_INLINE_VISIBILITY constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } template +inline _LIBCPP_INLINE_VISIBILITY constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } #endif _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_ITERATOR Index: projects/clang600-import/contrib/libc++/include/list =================================================================== --- projects/clang600-import/contrib/libc++/include/list (revision 327038) +++ projects/clang600-import/contrib/libc++/include/list (revision 327039) @@ -1,2431 +1,2421 @@ // -*- C++ -*- //===---------------------------- list ------------------------------------===// // // 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_LIST #define _LIBCPP_LIST /* list synopsis namespace std { template > class list { public: // types: typedef T value_type; typedef Alloc allocator_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 implementation-defined size_type; typedef implementation-defined difference_type; typedef reverse_iterator reverse_iterator; typedef reverse_iterator const_reverse_iterator; list() noexcept(is_nothrow_default_constructible::value); explicit list(const allocator_type& a); explicit list(size_type n); explicit list(size_type n, const allocator_type& a); // C++14 list(size_type n, const value_type& value); list(size_type n, const value_type& value, const allocator_type& a); template list(Iter first, Iter last); template list(Iter first, Iter last, const allocator_type& a); list(const list& x); list(const list&, const allocator_type& a); list(list&& x) noexcept(is_nothrow_move_constructible::value); list(list&&, const allocator_type& a); list(initializer_list); list(initializer_list, const allocator_type& a); ~list(); list& operator=(const list& x); list& operator=(list&& x) noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value); list& operator=(initializer_list); template void assign(Iter first, Iter last); void assign(size_type n, const value_type& t); void assign(initializer_list); 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; reference front(); const_reference front() const; reference back(); const_reference back() const; bool empty() const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; template reference emplace_front(Args&&... args); // reference in C++17 void pop_front(); template reference emplace_back(Args&&... args); // reference in C++17 void pop_back(); void push_front(const value_type& x); void push_front(value_type&& x); void push_back(const value_type& x); void push_back(value_type&& x); 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, Iter first, Iter last); iterator insert(const_iterator position, initializer_list il); iterator erase(const_iterator position); iterator erase(const_iterator position, const_iterator last); void resize(size_type sz); void resize(size_type sz, const value_type& c); void swap(list&) noexcept(allocator_traits::is_always_equal::value); // C++17 void clear() noexcept; void splice(const_iterator position, list& x); void splice(const_iterator position, list&& x); void splice(const_iterator position, list& x, const_iterator i); void splice(const_iterator position, list&& x, const_iterator i); void splice(const_iterator position, list& x, const_iterator first, const_iterator last); void splice(const_iterator position, list&& x, const_iterator first, const_iterator last); void remove(const value_type& value); template void remove_if(Pred pred); void unique(); template void unique(BinaryPredicate binary_pred); void merge(list& x); void merge(list&& x); template void merge(list& x, Compare comp); template void merge(list&& x, Compare comp); void sort(); template void sort(Compare comp); void reverse() noexcept; }; template bool operator==(const list& x, const list& y); template bool operator< (const list& x, const list& y); template bool operator!=(const list& x, const list& y); template bool operator> (const list& x, const list& y); template bool operator>=(const list& x, const list& y); template bool operator<=(const list& x, const list& y); template void swap(list& x, list& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include #include #include #include #include #include #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 struct __list_node; template struct __list_node_base; template struct __list_node_pointer_traits { typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type __node_pointer; typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type __base_pointer; #if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB) typedef __base_pointer __link_pointer; #else typedef typename conditional< is_pointer<_VoidPtr>::value, __base_pointer, __node_pointer >::type __link_pointer; #endif typedef typename conditional< is_same<__link_pointer, __node_pointer>::value, __base_pointer, __node_pointer >::type __non_link_pointer; static _LIBCPP_INLINE_VISIBILITY __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) { return __p; } static _LIBCPP_INLINE_VISIBILITY __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) { return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p)); } }; template struct __list_node_base { typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; typedef typename _NodeTraits::__node_pointer __node_pointer; typedef typename _NodeTraits::__base_pointer __base_pointer; typedef typename _NodeTraits::__link_pointer __link_pointer; __link_pointer __prev_; __link_pointer __next_; _LIBCPP_INLINE_VISIBILITY __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())), __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {} _LIBCPP_INLINE_VISIBILITY __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); } _LIBCPP_INLINE_VISIBILITY __node_pointer __as_node() { return static_cast<__node_pointer>(__self()); } }; template struct __list_node : public __list_node_base<_Tp, _VoidPtr> { _Tp __value_; typedef __list_node_base<_Tp, _VoidPtr> __base; typedef typename __base::__link_pointer __link_pointer; _LIBCPP_INLINE_VISIBILITY __link_pointer __as_link() { return static_cast<__link_pointer>(__base::__self()); } }; template > class _LIBCPP_TEMPLATE_VIS list; template class __list_imp; template class _LIBCPP_TEMPLATE_VIS __list_const_iterator; template class _LIBCPP_TEMPLATE_VIS __list_iterator { typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; typedef typename _NodeTraits::__link_pointer __link_pointer; __link_pointer __ptr_; #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT : __ptr_(__p) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} #endif template friend class list; template friend class __list_imp; template friend class __list_const_iterator; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef value_type& reference; typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer; typedef typename pointer_traits::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY __list_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); #endif } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __list_iterator(const __list_iterator& __p) : __ptr_(__p.__ptr_) { __get_db()->__iterator_copy(this, &__p); } _LIBCPP_INLINE_VISIBILITY ~__list_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __list_iterator& operator=(const __list_iterator& __p) { if (this != &__p) { __get_db()->__iterator_copy(this, &__p); __ptr_ = __p.__ptr_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::iterator"); #endif return __ptr_->__as_node()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::iterator"); #endif return pointer_traits::pointer_to(__ptr_->__as_node()->__value_); } _LIBCPP_INLINE_VISIBILITY __list_iterator& operator++() { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable list::iterator"); #endif __ptr_ = __ptr_->__next_; return *this; } _LIBCPP_INLINE_VISIBILITY __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __list_iterator& operator--() { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), "Attempted to decrement non-decrementable list::iterator"); #endif __ptr_ = __ptr_->__prev_; return *this; } _LIBCPP_INLINE_VISIBILITY __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_iterator& __x, const __list_iterator& __y) { return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __list_iterator& __x, const __list_iterator& __y) {return !(__x == __y);} }; template class _LIBCPP_TEMPLATE_VIS __list_const_iterator { typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; typedef typename _NodeTraits::__link_pointer __link_pointer; __link_pointer __ptr_; #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT : __ptr_(__p) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} #endif template friend class list; template friend class __list_imp; public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef const value_type& reference; typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer; typedef typename pointer_traits::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); #endif } _LIBCPP_INLINE_VISIBILITY __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT : __ptr_(__p.__ptr_) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__iterator_copy(this, &__p); #endif } #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY __list_const_iterator(const __list_const_iterator& __p) : __ptr_(__p.__ptr_) { __get_db()->__iterator_copy(this, &__p); } _LIBCPP_INLINE_VISIBILITY ~__list_const_iterator() { __get_db()->__erase_i(this); } _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator=(const __list_const_iterator& __p) { if (this != &__p) { __get_db()->__iterator_copy(this, &__p); __ptr_ = __p.__ptr_; } return *this; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY reference operator*() const { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif return __ptr_->__as_node()->__value_; } _LIBCPP_INLINE_VISIBILITY pointer operator->() const { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to dereference a non-dereferenceable list::iterator"); + "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif return pointer_traits::pointer_to(__ptr_->__as_node()->__value_); } _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator++() { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to increment non-incrementable list::const_iterator"); #endif __ptr_ = __ptr_->__next_; return *this; } _LIBCPP_INLINE_VISIBILITY __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator--() { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), "Attempted to decrement non-decrementable list::const_iterator"); #endif __ptr_ = __ptr_->__prev_; return *this; } _LIBCPP_INLINE_VISIBILITY __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) { return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) {return !(__x == __y);} }; template class __list_imp { __list_imp(const __list_imp&); __list_imp& operator=(const __list_imp&); protected: typedef _Tp value_type; typedef _Alloc allocator_type; typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::void_pointer __void_pointer; typedef __list_iterator iterator; typedef __list_const_iterator const_iterator; typedef __list_node_base __node_base; typedef __list_node __node; typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_alloc_traits; typedef typename __node_alloc_traits::pointer __node_pointer; typedef typename __node_alloc_traits::pointer __node_const_pointer; typedef __list_node_pointer_traits __node_pointer_traits; typedef typename __node_pointer_traits::__link_pointer __link_pointer; typedef __link_pointer __link_const_pointer; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::difference_type difference_type; typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; __node_base __end_; __compressed_pair __size_alloc_; _LIBCPP_INLINE_VISIBILITY __link_pointer __end_as_link() const _NOEXCEPT { return __node_pointer_traits::__unsafe_link_pointer_cast( const_cast<__node_base&>(__end_).__self()); } _LIBCPP_INLINE_VISIBILITY size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} _LIBCPP_INLINE_VISIBILITY const size_type& __sz() const _NOEXCEPT {return __size_alloc_.first();} _LIBCPP_INLINE_VISIBILITY __node_allocator& __node_alloc() _NOEXCEPT {return __size_alloc_.second();} _LIBCPP_INLINE_VISIBILITY const __node_allocator& __node_alloc() const _NOEXCEPT {return __size_alloc_.second();} _LIBCPP_INLINE_VISIBILITY size_type __node_alloc_max_size() const _NOEXCEPT { return __node_alloc_traits::max_size(__node_alloc()); } _LIBCPP_INLINE_VISIBILITY static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY __list_imp(const allocator_type& __a); ~__list_imp(); void clear() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __sz() == 0;} _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__end_.__next_, this); #else return iterator(__end_.__next_); #endif } _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(__end_.__next_, this); #else return const_iterator(__end_.__next_); #endif } _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__end_as_link(), this); #else return iterator(__end_as_link()); #endif } _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 return const_iterator(__end_as_link(), this); #else return const_iterator(__end_as_link()); #endif } void swap(__list_imp& __c) #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 void __copy_assign_alloc(const __list_imp& __c) {__copy_assign_alloc(__c, integral_constant());} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__list_imp& __c) _NOEXCEPT_( !__node_alloc_traits::propagate_on_container_move_assignment::value || is_nothrow_move_assignable<__node_allocator>::value) {__move_assign_alloc(__c, integral_constant());} private: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __list_imp& __c, true_type) { if (__node_alloc() != __c.__node_alloc()) clear(); __node_alloc() = __c.__node_alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __list_imp&, false_type) {} _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__list_imp& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) { __node_alloc() = _VSTD::move(__c.__node_alloc()); } _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators() { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif } }; // Unlink nodes [__f, __l] template inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT { __f->__prev_->__next_ = __l->__next_; __l->__next_->__prev_ = __f->__prev_; } template inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) : __size_alloc_(0) { } template inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) : __size_alloc_(0, __node_allocator(__a)) { } template __list_imp<_Tp, _Alloc>::~__list_imp() { clear(); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__erase_c(this); #endif } template void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT { if (!empty()) { __node_allocator& __na = __node_alloc(); __link_pointer __f = __end_.__next_; __link_pointer __l = __end_as_link(); __unlink_nodes(__f, __l->__prev_); __sz() = 0; while (__f != __l) { __node_pointer __np = __f->__as_node(); __f = __f->__next_; __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); } __invalidate_all_iterators(); } } template void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) #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->__node_alloc() == __c.__node_alloc(), "list::swap: Either propagate_on_container_swap must be true" " or the allocators must compare equal"); using _VSTD::swap; __swap_allocator(__node_alloc(), __c.__node_alloc()); swap(__sz(), __c.__sz()); swap(__end_, __c.__end_); if (__sz() == 0) __end_.__next_ = __end_.__prev_ = __end_as_link(); else __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link(); if (__c.__sz() == 0) __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link(); else __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link(); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); std::swap(__cn1->beg_, __cn2->beg_); std::swap(__cn1->end_, __cn2->end_); std::swap(__cn1->cap_, __cn2->cap_); for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) { --__p; const_iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ == __c.__end_as_link()) { __cn2->__add(*__p); if (--__cn1->end_ != __p) memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); } else (*__p)->__c_ = __cn1; } for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) { --__p; const_iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ == __end_as_link()) { __cn1->__add(*__p); if (--__cn2->end_ != __p) memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); } else (*__p)->__c_ = __cn2; } __db->unlock(); #endif } template */> class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> { typedef __list_imp<_Tp, _Alloc> base; typedef typename base::__node __node; typedef typename base::__node_allocator __node_allocator; typedef typename base::__node_pointer __node_pointer; typedef typename base::__node_alloc_traits __node_alloc_traits; typedef typename base::__node_base __node_base; typedef typename base::__node_base_pointer __node_base_pointer; typedef typename base::__link_pointer __link_pointer; public: typedef _Tp value_type; typedef _Alloc allocator_type; static_assert((is_same::value), "Invalid allocator::value_type"); typedef value_type& reference; typedef const value_type& const_reference; typedef typename base::pointer pointer; typedef typename base::const_pointer const_pointer; typedef typename base::size_type size_type; typedef typename base::difference_type difference_type; typedef typename base::iterator iterator; typedef typename base::const_iterator const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } _LIBCPP_INLINE_VISIBILITY explicit list(const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif } explicit list(size_type __n); #if _LIBCPP_STD_VER > 11 explicit list(size_type __n, const allocator_type& __a); #endif list(size_type __n, const value_type& __x); list(size_type __n, const value_type& __x, const allocator_type& __a); template list(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); template list(_InpIter __f, _InpIter __l, const allocator_type& __a, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); list(const list& __c); list(const list& __c, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY list& operator=(const list& __c); #ifndef _LIBCPP_CXX03_LANG list(initializer_list __il); list(initializer_list __il, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY list(list&& __c, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY list& operator=(list&& __c) _NOEXCEPT_( __node_alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value); _LIBCPP_INLINE_VISIBILITY list& operator=(initializer_list __il) {assign(__il.begin(), __il.end()); return *this;} _LIBCPP_INLINE_VISIBILITY void assign(initializer_list __il) {assign(__il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG template void assign(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); void assign(size_type __n, const value_type& __x); _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return base::__sz();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::empty();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT { return std::min( base::__node_alloc_max_size(), numeric_limits::max()); } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return base::begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return base::begin();} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return base::end();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return base::end();} _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT {return base::begin();} _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT {return base::end();} _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_reverse_iterator crbegin() const _NOEXCEPT {return const_reverse_iterator(end());} _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return const_reverse_iterator(begin());} _LIBCPP_INLINE_VISIBILITY reference front() { _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); return base::__end_.__next_->__as_node()->__value_; } _LIBCPP_INLINE_VISIBILITY const_reference front() const { _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); return base::__end_.__next_->__as_node()->__value_; } _LIBCPP_INLINE_VISIBILITY reference back() { _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); return base::__end_.__prev_->__as_node()->__value_; } _LIBCPP_INLINE_VISIBILITY const_reference back() const { _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); return base::__end_.__prev_->__as_node()->__value_; } #ifndef _LIBCPP_CXX03_LANG void push_front(value_type&& __x); void push_back(value_type&& __x); template #if _LIBCPP_STD_VER > 14 reference emplace_front(_Args&&... __args); #else void emplace_front(_Args&&... __args); #endif template #if _LIBCPP_STD_VER > 14 reference emplace_back(_Args&&... __args); #else void emplace_back(_Args&&... __args); #endif template iterator emplace(const_iterator __p, _Args&&... __args); iterator insert(const_iterator __p, value_type&& __x); _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, initializer_list __il) {return insert(__p, __il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG void push_front(const value_type& __x); void push_back(const value_type& __x); #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); } #else _LIBCPP_INLINE_VISIBILITY void __emplace_back(value_type const& __arg) { push_back(__arg); } #endif iterator insert(const_iterator __p, const value_type& __x); iterator insert(const_iterator __p, size_type __n, const value_type& __x); template iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); _LIBCPP_INLINE_VISIBILITY void swap(list& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT_DEBUG #else _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) #endif {base::swap(__c);} _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {base::clear();} void pop_front(); void pop_back(); iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); void resize(size_type __n); void resize(size_type __n, const value_type& __x); void splice(const_iterator __p, list& __c); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c) {splice(__p, __c);} _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c, const_iterator __i) {splice(__p, __c, __i);} _LIBCPP_INLINE_VISIBILITY void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {splice(__p, __c, __f, __l);} #endif void splice(const_iterator __p, list& __c, const_iterator __i); void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); void remove(const value_type& __x); template void remove_if(_Pred __pred); _LIBCPP_INLINE_VISIBILITY void unique(); template void unique(_BinaryPred __binary_pred); _LIBCPP_INLINE_VISIBILITY void merge(list& __c); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(list&& __c) {merge(__c);} template _LIBCPP_INLINE_VISIBILITY void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} #endif template void merge(list& __c, _Comp __comp); _LIBCPP_INLINE_VISIBILITY void sort(); template _LIBCPP_INLINE_VISIBILITY void sort(_Comp __comp); void reverse() _NOEXCEPT; bool __invariants() const; + typedef __allocator_destructor<__node_allocator> __node_destructor; + typedef unique_ptr<__node, __node_destructor> __hold_pointer; + + _LIBCPP_INLINE_VISIBILITY + __hold_pointer __allocate_node(__node_allocator& __na) { + __node_pointer __p = __node_alloc_traits::allocate(__na, 1); + __p->__prev_ = nullptr; + return __hold_pointer(__p, __node_destructor(__na, 1)); + } + #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; 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 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l); _LIBCPP_INLINE_VISIBILITY void __link_nodes_at_front(__link_pointer __f, __link_pointer __l); _LIBCPP_INLINE_VISIBILITY void __link_nodes_at_back (__link_pointer __f, __link_pointer __l); iterator __iterator(size_type __n); template static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); void __move_assign(list& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); void __move_assign(list& __c, false_type); }; // Link in nodes [__f, __l] just prior to __p template inline void list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l) { __p->__prev_->__next_ = __f; __f->__prev_ = __p->__prev_; __p->__prev_ = __l; __l->__next_ = __p; } // Link in nodes [__f, __l] at the front of the list template inline void list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l) { __f->__prev_ = base::__end_as_link(); __l->__next_ = base::__end_.__next_; __l->__next_->__prev_ = __l; base::__end_.__next_ = __f; } // Link in nodes [__f, __l] at the front of the list template inline void list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l) { __l->__next_ = base::__end_as_link(); __f->__prev_ = base::__end_.__prev_; __f->__prev_->__next_ = __f; base::__end_.__prev_ = __l; } template inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) { return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) : _VSTD::prev(end(), base::__sz() - __n); } template list<_Tp, _Alloc>::list(size_type __n) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) #ifndef _LIBCPP_CXX03_LANG emplace_back(); #else push_back(value_type()); #endif } #if _LIBCPP_STD_VER > 11 template list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) emplace_back(); } #endif template list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) push_back(__x); } template list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __n > 0; --__n) push_back(__x); } template template list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type*) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __f != __l; ++__f) __emplace_back(*__f); } template template list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, typename enable_if<__is_input_iterator<_InpIter>::value>::type*) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (; __f != __l; ++__f) __emplace_back(*__f); } template list<_Tp, _Alloc>::list(const list& __c) : base(allocator_type( __node_alloc_traits::select_on_container_copy_construction( __c.__node_alloc()))) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) push_back(*__i); } template list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) push_back(*__i); } #ifndef _LIBCPP_CXX03_LANG template list<_Tp, _Alloc>::list(initializer_list __il, const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (typename initializer_list::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i) push_back(*__i); } template list<_Tp, _Alloc>::list(initializer_list __il) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif for (typename initializer_list::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i) push_back(*__i); } template inline list<_Tp, _Alloc>::list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) : base(allocator_type(_VSTD::move(__c.__node_alloc()))) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif splice(end(), __c); } template inline list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) : base(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); #endif if (__a == __c.get_allocator()) splice(end(), __c); else { typedef move_iterator _Ip; assign(_Ip(__c.begin()), _Ip(__c.end())); } } template inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(list&& __c) _NOEXCEPT_( __node_alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<__node_allocator>::value) { __move_assign(__c, integral_constant()); return *this; } template void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) { if (base::__node_alloc() != __c.__node_alloc()) { typedef move_iterator _Ip; assign(_Ip(__c.begin()), _Ip(__c.end())); } else __move_assign(__c, true_type()); } template void list<_Tp, _Alloc>::__move_assign(list& __c, true_type) _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) { clear(); base::__move_assign_alloc(__c); splice(end(), __c); } #endif // _LIBCPP_CXX03_LANG template inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) { if (this != &__c) { base::__copy_assign_alloc(__c); assign(__c.begin(), __c.end()); } return *this; } template template void list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type*) { iterator __i = begin(); iterator __e = end(); for (; __f != __l && __i != __e; ++__f, ++__i) *__i = *__f; if (__i == __e) insert(__e, __f, __l); else erase(__i, __e); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif } template void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) { iterator __i = begin(); iterator __e = end(); for (; __n > 0 && __i != __e; --__n, ++__i) *__i = __x; if (__i == __e) insert(__e, __n, __x); else erase(__i, __e); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__invalidate_all(this); #endif } template inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT { return allocator_type(base::__node_alloc()); } template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, x) called with an iterator not" " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__hold.release()->__as_link(), this); #else return iterator(__hold.release()->__as_link()); #endif } template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, n, x) called with an iterator not" " referring to this list"); iterator __r(__p.__ptr_, this); #else iterator __r(__p.__ptr_); #endif if (__n > 0) { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 __r = iterator(__hold->__as_link(), this); #else __r = iterator(__hold->__as_link()); #endif __hold.release(); iterator __e = __r; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (--__n; __n != 0; --__n, ++__e, ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __e.__ptr_->__next_ = __hold->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (true) { __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); __link_pointer __prev = __e.__ptr_->__prev_; __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); if (__prev == 0) break; #if _LIBCPP_DEBUG_LEVEL >= 2 __e = iterator(__prev, this); #else __e = iterator(__prev); #endif } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; } template template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, typename enable_if<__is_input_iterator<_InpIter>::value>::type*) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, range) called with an iterator not" " referring to this list"); iterator __r(__p.__ptr_, this); #else iterator __r(__p.__ptr_); #endif if (__f != __l) { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 __r = iterator(__hold.get()->__as_link(), this); #else __r = iterator(__hold.get()->__as_link()); #endif __hold.release(); iterator __e = __r; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); __e.__ptr_->__next_ = __hold.get()->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (true) { __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); __link_pointer __prev = __e.__ptr_->__prev_; __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); if (__prev == 0) break; #if _LIBCPP_DEBUG_LEVEL >= 2 __e = iterator(__prev, this); #else __e = iterator(__prev); #endif } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; } template void list<_Tp, _Alloc>::push_front(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_front(__nl, __nl); ++base::__sz(); __hold.release(); } template void list<_Tp, _Alloc>::push_back(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); } #ifndef _LIBCPP_CXX03_LANG template void list<_Tp, _Alloc>::push_front(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); } template void list<_Tp, _Alloc>::push_back(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); __hold.release(); } template template #if _LIBCPP_STD_VER > 14 typename list<_Tp, _Alloc>::reference #else void #endif list<_Tp, _Alloc>::emplace_front(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); #if _LIBCPP_STD_VER > 14 return __hold.release()->__value_; #else __hold.release(); #endif } template template #if _LIBCPP_STD_VER > 14 typename list<_Tp, _Alloc>::reference #else void #endif list<_Tp, _Alloc>::emplace_back(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_back(__nl, __nl); ++base::__sz(); #if _LIBCPP_STD_VER > 14 return __hold.release()->__value_; #else __hold.release(); #endif } template template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::emplace(iterator, args...) called with an iterator not" " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold.get()->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); ++base::__sz(); __hold.release(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__nl, this); #else return iterator(__nl); #endif } template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, x) called with an iterator not" " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_pointer __nl = __hold->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); ++base::__sz(); __hold.release(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__nl, this); #else return iterator(__nl); #endif } #endif // _LIBCPP_CXX03_LANG template void list<_Tp, _Alloc>::pop_front() { _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); __node_allocator& __na = base::__node_alloc(); __link_pointer __n = base::__end_.__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __p = __c->end_; __p != __c->beg_; ) { --__p; iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif __node_pointer __np = __n->__as_node(); __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); } template void list<_Tp, _Alloc>::pop_back() { _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); __node_allocator& __na = base::__node_alloc(); __link_pointer __n = base::__end_.__prev_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __p = __c->end_; __p != __c->beg_; ) { --__p; iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif __node_pointer __np = __n->__as_node(); __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); } template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::erase(iterator) called with an iterator not" " referring to this list"); #endif _LIBCPP_ASSERT(__p != end(), "list::erase(iterator) called with a non-dereferenceable iterator"); __node_allocator& __na = base::__node_alloc(); __link_pointer __n = __p.__ptr_; __link_pointer __r = __n->__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __ip = __c->end_; __ip != __c->beg_; ) { --__ip; iterator* __i = static_cast((*__ip)->__i_); if (__i->__ptr_ == __n) { (*__ip)->__c_ = nullptr; if (--__c->end_ != __ip) memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif __node_pointer __np = __n->__as_node(); __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__r, this); #else return iterator(__r); #endif } template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, "list::erase(iterator, iterator) called with an iterator not" " referring to this list"); _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this, "list::erase(iterator, iterator) called with an iterator not" " referring to this list"); #endif if (__f != __l) { __node_allocator& __na = base::__node_alloc(); base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); while (__f != __l) { __link_pointer __n = __f.__ptr_; ++__f; --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); for (__i_node** __p = __c->end_; __p != __c->beg_; ) { --__p; iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); } } __get_db()->unlock(); #endif __node_pointer __np = __n->__as_node(); __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); __node_alloc_traits::deallocate(__na, __np, 1); } } #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__l.__ptr_, this); #else return iterator(__l.__ptr_); #endif } template void list<_Tp, _Alloc>::resize(size_type __n) { if (__n < base::__sz()) erase(__iterator(__n), end()); else if (__n > base::__sz()) { __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 iterator __r = iterator(__hold.release()->__as_link(), this); #else iterator __r = iterator(__hold.release()->__as_link()); #endif iterator __e = __r; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (--__n; __n != 0; --__n, ++__e, ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); __e.__ptr_->__next_ = __hold.get()->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (true) { __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); __link_pointer __prev = __e.__ptr_->__prev_; __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); if (__prev == 0) break; #if _LIBCPP_DEBUG_LEVEL >= 2 __e = iterator(__prev, this); #else __e = iterator(__prev); #endif } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __link_nodes_at_back(__r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } template void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) { if (__n < base::__sz()) erase(__iterator(__n), end()); else if (__n > base::__sz()) { __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; __link_pointer __nl = __hold.release()->__as_link(); #if _LIBCPP_DEBUG_LEVEL >= 2 iterator __r = iterator(__nl, this); #else iterator __r = iterator(__nl); #endif iterator __e = __r; #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS for (--__n; __n != 0; --__n, ++__e, ++__ds) { __hold.reset(__node_alloc_traits::allocate(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __e.__ptr_->__next_ = __hold.get()->__as_link(); __hold->__prev_ = __e.__ptr_; __hold.release(); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { while (true) { __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); __link_pointer __prev = __e.__ptr_->__prev_; __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); if (__prev == 0) break; #if _LIBCPP_DEBUG_LEVEL >= 2 __e = iterator(__prev, this); #else __e = iterator(__prev); #endif } throw; } #endif // _LIBCPP_NO_EXCEPTIONS __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } template void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) { _LIBCPP_ASSERT(this != &__c, "list::splice(iterator, list) called with this == &list"); #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::splice(iterator, list) called with an iterator not" " referring to this list"); #endif if (!__c.empty()) { __link_pointer __f = __c.__end_.__next_; __link_pointer __l = __c.__end_.__prev_; base::__unlink_nodes(__f, __l); __link_nodes(__p.__ptr_, __f, __l); base::__sz() += __c.__sz(); __c.__sz() = 0; #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; iterator* __i = static_cast((*__ip)->__i_); if (__i->__ptr_ != __c.__end_as_link()) { __cn1->__add(*__ip); (*__ip)->__c_ = __cn1; if (--__cn2->end_ != __ip) memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } __db->unlock(); #endif } } template void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::splice(iterator, list, iterator) called with first iterator not" " referring to this list"); _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, "list::splice(iterator, list, iterator) called with second iterator not" " referring to list argument"); _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), "list::splice(iterator, list, iterator) called with second iterator not" " derefereceable"); #endif if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) { __link_pointer __f = __i.__ptr_; base::__unlink_nodes(__f, __f); __link_nodes(__p.__ptr_, __f, __f); --__c.__sz(); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; iterator* __j = static_cast((*__ip)->__i_); if (__j->__ptr_ == __f) { __cn1->__add(*__ip); (*__ip)->__c_ = __cn1; if (--__cn2->end_ != __ip) memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } __db->unlock(); #endif } } template void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::splice(iterator, list, iterator, iterator) called with first iterator not" " referring to this list"); _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, "list::splice(iterator, list, iterator, iterator) called with second iterator not" " referring to list argument"); if (this == &__c) { for (const_iterator __i = __f; __i != __l; ++__i) _LIBCPP_ASSERT(__i != __p, "list::splice(iterator, list, iterator, iterator)" " called with the first iterator within the range" " of the second and third iterators"); } #endif if (__f != __l) { if (this != &__c) { size_type __s = _VSTD::distance(__f, __l); __c.__sz() -= __s; base::__sz() += __s; } __link_pointer __first = __f.__ptr_; --__l; __link_pointer __last = __l.__ptr_; base::__unlink_nodes(__first, __last); __link_nodes(__p.__ptr_, __first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; iterator* __j = static_cast((*__ip)->__i_); for (__link_pointer __k = __f.__ptr_; __k != __l.__ptr_; __k = __k->__next_) { if (__j->__ptr_ == __k) { __cn1->__add(*__ip); (*__ip)->__c_ = __cn1; if (--__cn2->end_ != __ip) memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); } } } __db->unlock(); #endif } } template void list<_Tp, _Alloc>::remove(const value_type& __x) { list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing for (const_iterator __i = begin(), __e = end(); __i != __e;) { if (*__i == __x) { const_iterator __j = _VSTD::next(__i); for (; __j != __e && *__j == __x; ++__j) ; __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); __i = __j; if (__i != __e) ++__i; } else ++__i; } } template template void list<_Tp, _Alloc>::remove_if(_Pred __pred) { for (iterator __i = begin(), __e = end(); __i != __e;) { if (__pred(*__i)) { iterator __j = _VSTD::next(__i); for (; __j != __e && __pred(*__j); ++__j) ; __i = erase(__i, __j); if (__i != __e) ++__i; } else ++__i; } } template inline void list<_Tp, _Alloc>::unique() { unique(__equal_to()); } template template void list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) { for (iterator __i = begin(), __e = end(); __i != __e;) { iterator __j = _VSTD::next(__i); for (; __j != __e && __binary_pred(*__i, *__j); ++__j) ; if (++__i != __j) __i = erase(__i, __j); } } template inline void list<_Tp, _Alloc>::merge(list& __c) { merge(__c, __less()); } template template void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) { if (this != &__c) { iterator __f1 = begin(); iterator __e1 = end(); iterator __f2 = __c.begin(); iterator __e2 = __c.end(); while (__f1 != __e1 && __f2 != __e2) { if (__comp(*__f2, *__f1)) { size_type __ds = 1; iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) ; base::__sz() += __ds; __c.__sz() -= __ds; __link_pointer __f = __f2.__ptr_; __link_pointer __l = __m2.__ptr_->__prev_; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else ++__f1; } splice(__e1, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); __c_node* __cn2 = __db->__find_c(&__c); for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) { --__p; iterator* __i = static_cast((*__p)->__i_); if (__i->__ptr_ != __c.__end_as_link()) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; if (--__cn2->end_ != __p) memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); } } __db->unlock(); #endif } } template inline void list<_Tp, _Alloc>::sort() { sort(__less()); } template template inline void list<_Tp, _Alloc>::sort(_Comp __comp) { __sort(begin(), end(), base::__sz(), __comp); } template template typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) { switch (__n) { case 0: case 1: return __f1; case 2: if (__comp(*--__e2, *__f1)) { __link_pointer __f = __e2.__ptr_; base::__unlink_nodes(__f, __f); __link_nodes(__f1.__ptr_, __f, __f); return __e2; } return __f1; } size_type __n2 = __n / 2; iterator __e1 = _VSTD::next(__f1, __n2); iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); if (__comp(*__f2, *__f1)) { iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; __link_pointer __f = __f2.__ptr_; __link_pointer __l = __m2.__ptr_->__prev_; __r = __f2; __e1 = __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else ++__f1; while (__f1 != __e1 && __f2 != __e2) { if (__comp(*__f2, *__f1)) { iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; __link_pointer __f = __f2.__ptr_; __link_pointer __l = __m2.__ptr_->__prev_; if (__e1 == __f2) __e1 = __m2; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else ++__f1; } return __r; } template void list<_Tp, _Alloc>::reverse() _NOEXCEPT { if (base::__sz() > 1) { iterator __e = end(); for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) { _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); __i.__ptr_ = __i.__ptr_->__prev_; } _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); } } template bool list<_Tp, _Alloc>::__invariants() const { return size() == _VSTD::distance(begin(), end()); } #if _LIBCPP_DEBUG_LEVEL >= 2 template bool list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const { return __i->__ptr_ != this->__end_as_link(); } template bool list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const { return !empty() && __i->__ptr_ != base::__end_.__next_; } template bool list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const { return false; } template bool list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const { return false; } #endif // _LIBCPP_DEBUG_LEVEL >= 2 template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_LIST Index: projects/clang600-import/contrib/libc++/include/locale =================================================================== --- projects/clang600-import/contrib/libc++/include/locale (revision 327038) +++ projects/clang600-import/contrib/libc++/include/locale (revision 327039) @@ -1,4335 +1,4335 @@ // -*- C++ -*- //===-------------------------- locale ------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_LOCALE #define _LIBCPP_LOCALE /* locale synopsis namespace std { class locale { public: // types: class facet; class id; typedef int category; static const category // values assigned here are for exposition only none = 0x000, collate = 0x010, ctype = 0x020, monetary = 0x040, numeric = 0x080, time = 0x100, messages = 0x200, all = collate | ctype | monetary | numeric | time | messages; // construct/copy/destroy: locale() noexcept; locale(const locale& other) noexcept; explicit locale(const char* std_name); explicit locale(const string& std_name); locale(const locale& other, const char* std_name, category); locale(const locale& other, const string& std_name, category); template locale(const locale& other, Facet* f); locale(const locale& other, const locale& one, category); ~locale(); // not virtual const locale& operator=(const locale& other) noexcept; template locale combine(const locale& other) const; // locale operations: basic_string name() const; bool operator==(const locale& other) const; bool operator!=(const locale& other) const; template bool operator()(const basic_string& s1, const basic_string& s2) const; // global locale objects: static locale global(const locale&); static const locale& classic(); }; template const Facet& use_facet(const locale&); template bool has_facet(const locale&) noexcept; // 22.3.3, convenience interfaces: template bool isspace (charT c, const locale& loc); template bool isprint (charT c, const locale& loc); template bool iscntrl (charT c, const locale& loc); template bool isupper (charT c, const locale& loc); template bool islower (charT c, const locale& loc); template bool isalpha (charT c, const locale& loc); template bool isdigit (charT c, const locale& loc); template bool ispunct (charT c, const locale& loc); template bool isxdigit(charT c, const locale& loc); template bool isalnum (charT c, const locale& loc); template bool isgraph (charT c, const locale& loc); template charT toupper(charT c, const locale& loc); template charT tolower(charT c, const locale& loc); template, class Byte_alloc = allocator> class wstring_convert { public: typedef basic_string, Byte_alloc> byte_string; typedef basic_string, Wide_alloc> wide_string; typedef typename Codecvt::state_type state_type; typedef typename wide_string::traits_type::int_type int_type; explicit wstring_convert(Codecvt* pcvt = new Codecvt); // explicit in C++14 wstring_convert(Codecvt* pcvt, state_type state); explicit wstring_convert(const byte_string& byte_err, // explicit in C++14 const wide_string& wide_err = wide_string()); wstring_convert(const wstring_convert&) = delete; // C++14 wstring_convert & operator=(const wstring_convert &) = delete; // C++14 ~wstring_convert(); wide_string from_bytes(char byte); wide_string from_bytes(const char* ptr); wide_string from_bytes(const byte_string& str); wide_string from_bytes(const char* first, const char* last); byte_string to_bytes(Elem wchar); byte_string to_bytes(const Elem* wptr); byte_string to_bytes(const wide_string& wstr); byte_string to_bytes(const Elem* first, const Elem* last); size_t converted() const; // noexcept in C++14 state_type state() const; }; template > class wbuffer_convert : public basic_streambuf { public: typedef typename Tr::state_type state_type; explicit wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, state_type state = state_type()); // explicit in C++14 wbuffer_convert(const wbuffer_convert&) = delete; // C++14 wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14 ~wbuffer_convert(); // C++14 streambuf* rdbuf() const; streambuf* rdbuf(streambuf* bytebuf); state_type state() const; }; // 22.4.1 and 22.4.1.3, ctype: class ctype_base; template class ctype; template <> class ctype; // specialization template class ctype_byname; template <> class ctype_byname; // specialization class codecvt_base; template class codecvt; template class codecvt_byname; // 22.4.2 and 22.4.3, numeric: template class num_get; template class num_put; template class numpunct; template class numpunct_byname; // 22.4.4, col lation: template class collate; template class collate_byname; // 22.4.5, date and time: class time_base; template class time_get; template class time_get_byname; template class time_put; template class time_put_byname; // 22.4.6, money: class money_base; template class money_get; template class money_put; template class moneypunct; template class moneypunct_byname; // 22.4.7, message retrieval: class messages_base; template class messages; template class messages_byname; } // std */ #include <__config> #include <__locale> #include <__debug> #include #include #include #include #include #include #ifndef __APPLE__ #include #endif #include #include #include #ifdef _LIBCPP_HAS_CATOPEN #include #endif #ifdef __APPLE__ #include #endif #ifdef _LIBCPP_LOCALE__L_EXTENSIONS #include <__bsd_locale_defaults.h> #else #include <__bsd_locale_fallbacks.h> #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD #if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_GET_C_LOCALE 0 #elif defined(__CloudABI__) || defined(__NetBSD__) # define _LIBCPP_GET_C_LOCALE LC_C_LOCALE #else # define _LIBCPP_GET_C_LOCALE __cloc() // Get the C locale object _LIBCPP_FUNC_VIS locale_t __cloc(); #define __cloc_defined #endif // __scan_keyword // Scans [__b, __e) until a match is found in the basic_strings range // [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). // __b will be incremented (visibly), consuming CharT until a match is found // or proved to not exist. A keyword may be "", in which will match anything. // If one keyword is a prefix of another, and the next CharT in the input // might match another keyword, the algorithm will attempt to find the longest // matching keyword. If the longer matching keyword ends up not matching, then // no keyword match is found. If no keyword match is found, __ke is returned // and failbit is set in __err. // Else an iterator pointing to the matching keyword is found. If more than // one keyword matches, an iterator to the first matching keyword is returned. // If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false, // __ct is used to force to lower case before comparing characters. // Examples: // Keywords: "a", "abb" // If the input is "a", the first keyword matches and eofbit is set. // If the input is "abc", no match is found and "ab" are consumed. template _LIBCPP_HIDDEN _ForwardIterator __scan_keyword(_InputIterator& __b, _InputIterator __e, _ForwardIterator __kb, _ForwardIterator __ke, const _Ctype& __ct, ios_base::iostate& __err, bool __case_sensitive = true) { typedef typename iterator_traits<_InputIterator>::value_type _CharT; size_t __nkw = static_cast(_VSTD::distance(__kb, __ke)); const unsigned char __doesnt_match = '\0'; const unsigned char __might_match = '\1'; const unsigned char __does_match = '\2'; unsigned char __statbuf[100]; unsigned char* __status = __statbuf; unique_ptr __stat_hold(0, free); if (__nkw > sizeof(__statbuf)) { __status = (unsigned char*)malloc(__nkw); if (__status == 0) __throw_bad_alloc(); __stat_hold.reset(__status); } size_t __n_might_match = __nkw; // At this point, any keyword might match size_t __n_does_match = 0; // but none of them definitely do // Initialize all statuses to __might_match, except for "" keywords are __does_match unsigned char* __st = __status; for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) { if (!__ky->empty()) *__st = __might_match; else { *__st = __does_match; --__n_might_match; ++__n_does_match; } } // While there might be a match, test keywords against the next CharT for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) { // Peek at the next CharT but don't consume it _CharT __c = *__b; if (!__case_sensitive) __c = __ct.toupper(__c); bool __consume = false; // For each keyword which might match, see if the __indx character is __c // If a match if found, consume __c // If a match is found, and that is the last character in the keyword, // then that keyword matches. // If the keyword doesn't match this character, then change the keyword // to doesn't match __st = __status; for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) { if (*__st == __might_match) { _CharT __kc = (*__ky)[__indx]; if (!__case_sensitive) __kc = __ct.toupper(__kc); if (__c == __kc) { __consume = true; if (__ky->size() == __indx+1) { *__st = __does_match; --__n_might_match; ++__n_does_match; } } else { *__st = __doesnt_match; --__n_might_match; } } } // consume if we matched a character if (__consume) { ++__b; // If we consumed a character and there might be a matched keyword that // was marked matched on a previous iteration, then such keywords // which are now marked as not matching. if (__n_might_match + __n_does_match > 1) { __st = __status; for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) { if (*__st == __does_match && __ky->size() != __indx+1) { *__st = __doesnt_match; --__n_does_match; } } } } } // We've exited the loop because we hit eof and/or we have no more "might matches". if (__b == __e) __err |= ios_base::eofbit; // Return the first matching result for (__st = __status; __kb != __ke; ++__kb, (void) ++__st) if (*__st == __does_match) break; if (__kb == __ke) __err |= ios_base::failbit; return __kb; } struct _LIBCPP_TYPE_VIS __num_get_base { static const int __num_get_buf_sz = 40; static int __get_base(ios_base&); static const char __src[33]; }; _LIBCPP_FUNC_VIS void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err); template struct __num_get : protected __num_get_base { static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep); static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, unsigned& __dc, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, _CharT* __atoms); #else static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) { locale __loc = __iob.getloc(); const numpunct<_CharT>& __np = use_facet >(__loc); __thousands_sep = __np.thousands_sep(); return __np.grouping(); } const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const { return __do_widen_p(__iob, __atoms); } static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, unsigned& __dc, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, const _CharT* __atoms); private: template const T* __do_widen_p(ios_base& __iob, T* __atoms) const { locale __loc = __iob.getloc(); use_facet >(__loc).widen(__src, __src + 26, __atoms); return __atoms; } const char* __do_widen_p(ios_base& __iob, char* __atoms) const { (void)__iob; (void)__atoms; return __src; } #endif }; #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET template string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) { locale __loc = __iob.getloc(); use_facet >(__loc).widen(__src, __src + 26, __atoms); const numpunct<_CharT>& __np = use_facet >(__loc); __thousands_sep = __np.thousands_sep(); return __np.grouping(); } #endif template string __num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep) { locale __loc = __iob.getloc(); use_facet >(__loc).widen(__src, __src + 32, __atoms); const numpunct<_CharT>& __np = use_facet >(__loc); __decimal_point = __np.decimal_point(); __thousands_sep = __np.thousands_sep(); return __np.grouping(); } template int #ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, unsigned& __dc, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, _CharT* __atoms) #else __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, unsigned& __dc, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, const _CharT* __atoms) #endif { if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) { *__a_end++ = __ct == __atoms[24] ? '+' : '-'; __dc = 0; return 0; } if (__grouping.size() != 0 && __ct == __thousands_sep) { if (__g_end-__g < __num_get_buf_sz) { *__g_end++ = __dc; __dc = 0; } return 0; } ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms; if (__f >= 24) return -1; switch (__base) { case 8: case 10: if (__f >= __base) return -1; break; case 16: if (__f < 22) break; if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') { __dc = 0; *__a_end++ = __src[__f]; return 0; } return -1; } *__a_end++ = __src[__f]; ++__dc; return 0; } template int __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) { if (__ct == __decimal_point) { if (!__in_units) return -1; __in_units = false; *__a_end++ = '.'; if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) *__g_end++ = __dc; return 0; } if (__ct == __thousands_sep && __grouping.size() != 0) { if (!__in_units) return -1; if (__g_end-__g < __num_get_buf_sz) { *__g_end++ = __dc; __dc = 0; } return 0; } ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms; if (__f >= 32) return -1; char __x = __src[__f]; if (__x == '-' || __x == '+') { if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F)) { *__a_end++ = __x; return 0; } return -1; } if (__x == 'x' || __x == 'X') __exp = 'P'; else if ((__x & 0x5F) == __exp) { __exp |= 0x80; if (__in_units) { __in_units = false; if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) *__g_end++ = __dc; } } *__a_end++ = __x; if (__f >= 22) return 0; ++__dc; return 0; } _LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get) _LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get) template > class _LIBCPP_TEMPLATE_VIS num_get : public locale::facet, private __num_get<_CharT> { public: typedef _CharT char_type; typedef _InputIterator iter_type; _LIBCPP_ALWAYS_INLINE explicit num_get(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { return do_get(__b, __e, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const { return do_get(__b, __e, __iob, __err, __v); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~num_get() {} template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_floating_point (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const; template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_signed (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const; template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type __do_get_unsigned (iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const; virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const; virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const; }; template locale::id num_get<_CharT, _InputIterator>::id; template _Tp __num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) { if (__a != __a_end) { typename remove_reference::type __save_errno = errno; errno = 0; char *__p2; long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); typename remove_reference::type __current_errno = errno; if (__current_errno == 0) errno = __save_errno; if (__p2 != __a_end) { __err = ios_base::failbit; return 0; } else if (__current_errno == ERANGE || __ll < numeric_limits<_Tp>::min() || numeric_limits<_Tp>::max() < __ll) { __err = ios_base::failbit; if (__ll > 0) return numeric_limits<_Tp>::max(); else return numeric_limits<_Tp>::min(); } return static_cast<_Tp>(__ll); } __err = ios_base::failbit; return 0; } template _Tp __num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) { if (__a != __a_end) { if (*__a == '-') { __err = ios_base::failbit; return 0; } typename remove_reference::type __save_errno = errno; errno = 0; char *__p2; unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); typename remove_reference::type __current_errno = errno; if (__current_errno == 0) errno = __save_errno; if (__p2 != __a_end) { __err = ios_base::failbit; return 0; } else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) { __err = ios_base::failbit; return numeric_limits<_Tp>::max(); } return static_cast<_Tp>(__ll); } __err = ios_base::failbit; return 0; } template _LIBCPP_INLINE_VISIBILITY _Tp __do_strtod(const char* __a, char** __p2); template <> inline _LIBCPP_INLINE_VISIBILITY float __do_strtod(const char* __a, char** __p2) { return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE); } template <> inline _LIBCPP_INLINE_VISIBILITY double __do_strtod(const char* __a, char** __p2) { return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE); } template <> inline _LIBCPP_INLINE_VISIBILITY long double __do_strtod(const char* __a, char** __p2) { return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE); } template _LIBCPP_HIDDEN _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) { if (__a != __a_end) { typename remove_reference::type __save_errno = errno; errno = 0; char *__p2; _Tp __ld = __do_strtod<_Tp>(__a, &__p2); typename remove_reference::type __current_errno = errno; if (__current_errno == 0) errno = __save_errno; if (__p2 != __a_end) { __err = ios_base::failbit; return 0; } else if (__current_errno == ERANGE) __err = ios_base::failbit; return __ld; } __err = ios_base::failbit; return 0; } template _InputIterator num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const { if ((__iob.flags() & ios_base::boolalpha) == 0) { long __lv = -1; __b = do_get(__b, __e, __iob, __err, __lv); switch (__lv) { case 0: __v = false; break; case 1: __v = true; break; default: __v = true; __err = ios_base::failbit; break; } return __b; } const ctype<_CharT>& __ct = use_facet >(__iob.getloc()); const numpunct<_CharT>& __np = use_facet >(__iob.getloc()); typedef typename numpunct<_CharT>::string_type string_type; const string_type __names[2] = {__np.truename(), __np.falsename()}; const string_type* __i = __scan_keyword(__b, __e, __names, __names+2, __ct, __err); __v = __i == __names; return __b; } // signed template template _InputIterator num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const { // Stage 1 int __base = this->__get_base(__iob); // Stage 2 char_type __thousands_sep; const int __atoms_size = 26; #ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET char_type __atoms1[__atoms_size]; const char_type *__atoms = this->__do_widen(__iob, __atoms1); string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); #else char_type __atoms[__atoms_size]; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); #endif string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) { if (__a_end == __a + __buf.size()) { size_t __tmp = __buf.size(); __buf.resize(2*__buf.size()); __buf.resize(__buf.capacity()); __a = &__buf[0]; __a_end = __a + __tmp; } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 __v = __num_get_signed_integral<_Signed>(__a, __a_end, __err, __base); // Digit grouping checked __check_grouping(__grouping, __g, __g_end, __err); // EOF checked if (__b == __e) __err |= ios_base::eofbit; return __b; } // unsigned template template _InputIterator num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const { // Stage 1 int __base = this->__get_base(__iob); // Stage 2 char_type __thousands_sep; const int __atoms_size = 26; #ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET char_type __atoms1[__atoms_size]; const char_type *__atoms = this->__do_widen(__iob, __atoms1); string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); #else char_type __atoms[__atoms_size]; string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); #endif string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) { if (__a_end == __a + __buf.size()) { size_t __tmp = __buf.size(); __buf.resize(2*__buf.size()); __buf.resize(__buf.capacity()); __a = &__buf[0]; __a_end = __a + __tmp; } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; } if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 __v = __num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base); // Digit grouping checked __check_grouping(__grouping, __g, __g_end, __err); // EOF checked if (__b == __e) __err |= ios_base::eofbit; return __b; } // floating point template template _InputIterator num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const { // Stage 1, nothing to do // Stage 2 char_type __atoms[32]; char_type __decimal_point; char_type __thousands_sep; string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; bool __in_units = true; char __exp = 'E'; for (; __b != __e; ++__b) { if (__a_end == __a + __buf.size()) { size_t __tmp = __buf.size(); __buf.resize(2*__buf.size()); __buf.resize(__buf.capacity()); __a = &__buf[0]; __a_end = __a + __tmp; } if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, __decimal_point, __thousands_sep, __grouping, __g, __g_end, __dc, __atoms)) break; } if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) *__g_end++ = __dc; // Stage 3 __v = __num_get_float<_Fp>(__a, __a_end, __err); // Digit grouping checked __check_grouping(__grouping, __g, __g_end, __err); // EOF checked if (__b == __e) __err |= ios_base::eofbit; return __b; } template _InputIterator num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const { // Stage 1 int __base = 16; // Stage 2 char_type __atoms[26]; char_type __thousands_sep = 0; string __grouping; use_facet >(__iob.getloc()).widen(__num_get_base::__src, __num_get_base::__src + 26, __atoms); string __buf; __buf.resize(__buf.capacity()); char* __a = &__buf[0]; char* __a_end = __a; unsigned __g[__num_get_base::__num_get_buf_sz]; unsigned* __g_end = __g; unsigned __dc = 0; for (; __b != __e; ++__b) { if (__a_end == __a + __buf.size()) { size_t __tmp = __buf.size(); __buf.resize(2*__buf.size()); __buf.resize(__buf.capacity()); __a = &__buf[0]; __a_end = __a + __tmp; } if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) break; } // Stage 3 __buf.resize(__a_end - __a); if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) __err = ios_base::failbit; // EOF checked if (__b == __e) __err |= ios_base::eofbit; return __b; } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get) struct _LIBCPP_TYPE_VIS __num_put_base { protected: static void __format_int(char* __fmt, const char* __len, bool __signd, ios_base::fmtflags __flags); static bool __format_float(char* __fmt, const char* __len, ios_base::fmtflags __flags); static char* __identify_padding(char* __nb, char* __ne, const ios_base& __iob); }; template struct __num_put : protected __num_put_base { static void __widen_and_group_int(char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc); static void __widen_and_group_float(char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc); }; template void __num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) { const ctype<_CharT>& __ct = use_facet > (__loc); const numpunct<_CharT>& __npt = use_facet >(__loc); string __grouping = __npt.grouping(); if (__grouping.empty()) { __ct.widen(__nb, __ne, __ob); __oe = __ob + (__ne - __nb); } else { __oe = __ob; char* __nf = __nb; if (*__nf == '-' || *__nf == '+') *__oe++ = __ct.widen(*__nf++); if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) { *__oe++ = __ct.widen(*__nf++); *__oe++ = __ct.widen(*__nf++); } reverse(__nf, __ne); _CharT __thousands_sep = __npt.thousands_sep(); unsigned __dc = 0; unsigned __dg = 0; for (char* __p = __nf; __p < __ne; ++__p) { if (static_cast(__grouping[__dg]) > 0 && __dc == static_cast(__grouping[__dg])) { *__oe++ = __thousands_sep; __dc = 0; if (__dg < __grouping.size()-1) ++__dg; } *__oe++ = __ct.widen(*__p); ++__dc; } reverse(__ob + (__nf - __nb), __oe); } if (__np == __ne) __op = __oe; else __op = __ob + (__np - __nb); } template void __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) { const ctype<_CharT>& __ct = use_facet > (__loc); const numpunct<_CharT>& __npt = use_facet >(__loc); string __grouping = __npt.grouping(); __oe = __ob; char* __nf = __nb; if (*__nf == '-' || *__nf == '+') *__oe++ = __ct.widen(*__nf++); char* __ns; if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) { *__oe++ = __ct.widen(*__nf++); *__oe++ = __ct.widen(*__nf++); for (__ns = __nf; __ns < __ne; ++__ns) if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) break; } else { for (__ns = __nf; __ns < __ne; ++__ns) if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) break; } if (__grouping.empty()) { __ct.widen(__nf, __ns, __oe); __oe += __ns - __nf; } else { reverse(__nf, __ns); _CharT __thousands_sep = __npt.thousands_sep(); unsigned __dc = 0; unsigned __dg = 0; for (char* __p = __nf; __p < __ns; ++__p) { if (__grouping[__dg] > 0 && __dc == static_cast(__grouping[__dg])) { *__oe++ = __thousands_sep; __dc = 0; if (__dg < __grouping.size()-1) ++__dg; } *__oe++ = __ct.widen(*__p); ++__dc; } reverse(__ob + (__nf - __nb), __oe); } for (__nf = __ns; __nf < __ne; ++__nf) { if (*__nf == '.') { *__oe++ = __npt.decimal_point(); ++__nf; break; } else *__oe++ = __ct.widen(*__nf); } __ct.widen(__nf, __ne, __oe); __oe += __ne - __nf; if (__np == __ne) __op = __oe; else __op = __ob + (__np - __nb); } _LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put) _LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put) template > class _LIBCPP_TEMPLATE_VIS num_put : public locale::facet, private __num_put<_CharT> { public: typedef _CharT char_type; typedef _OutputIterator iter_type; _LIBCPP_ALWAYS_INLINE explicit num_put(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const { return do_put(__s, __iob, __fl, __v); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const { return do_put(__s, __iob, __fl, __v); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~num_put() {} virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const; virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const; }; template locale::id num_put<_CharT, _OutputIterator>::id; template _LIBCPP_HIDDEN _OutputIterator __pad_and_output(_OutputIterator __s, const _CharT* __ob, const _CharT* __op, const _CharT* __oe, ios_base& __iob, _CharT __fl) { streamsize __sz = __oe - __ob; streamsize __ns = __iob.width(); if (__ns > __sz) __ns -= __sz; else __ns = 0; for (;__ob < __op; ++__ob, ++__s) *__s = *__ob; for (; __ns; --__ns, ++__s) *__s = __fl; for (; __ob < __oe; ++__ob, ++__s) *__s = *__ob; __iob.width(0); return __s; } #if !defined(__APPLE__) || \ (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) template _LIBCPP_HIDDEN ostreambuf_iterator<_CharT, _Traits> __pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s, const _CharT* __ob, const _CharT* __op, const _CharT* __oe, ios_base& __iob, _CharT __fl) { if (__s.__sbuf_ == nullptr) return __s; streamsize __sz = __oe - __ob; streamsize __ns = __iob.width(); if (__ns > __sz) __ns -= __sz; else __ns = 0; streamsize __np = __op - __ob; if (__np > 0) { if (__s.__sbuf_->sputn(__ob, __np) != __np) { __s.__sbuf_ = nullptr; return __s; } } if (__ns > 0) { basic_string<_CharT, _Traits> __sp(__ns, __fl); if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) { __s.__sbuf_ = nullptr; return __s; } } __np = __oe - __op; if (__np > 0) { if (__s.__sbuf_->sputn(__op, __np) != __np) { __s.__sbuf_ = nullptr; return __s; } } __iob.width(0); return __s; } #endif template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const { if ((__iob.flags() & ios_base::boolalpha) == 0) return do_put(__s, __iob, __fl, (unsigned long)__v); const numpunct& __np = use_facet >(__iob.getloc()); typedef typename numpunct::string_type string_type; #if _LIBCPP_DEBUG_LEVEL >= 2 string_type __tmp(__v ? __np.truename() : __np.falsename()); string_type __nm = _VSTD::move(__tmp); #else string_type __nm = __v ? __np.truename() : __np.falsename(); #endif for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) *__s = *__i; return __s; } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const { // Stage 1 - Get number in narrow char char __fmt[6] = {'%', 0}; const char* __len = "l"; this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const { // Stage 1 - Get number in narrow char char __fmt[8] = {'%', 0}; const char* __len = "ll"; this->__format_int(__fmt+1, __len, true, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + ((__iob.flags() & ios_base::showbase) != 0) + 2; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const { // Stage 1 - Get number in narrow char char __fmt[6] = {'%', 0}; const char* __len = "l"; this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const { // Stage 1 - Get number in narrow char char __fmt[8] = {'%', 0}; const char* __len = "ll"; this->__format_int(__fmt+1, __len, false, __iob.flags()); const unsigned __nbuf = (numeric_limits::digits / 3) + ((numeric_limits::digits % 3) != 0) + ((__iob.flags() & ios_base::showbase) != 0) + 1; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const { // Stage 1 - Get number in narrow char char __fmt[8] = {'%', 0}; const char* __len = ""; bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); const unsigned __nbuf = 30; char __nar[__nbuf]; char* __nb = __nar; int __nc; if (__specify_precision) __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); else __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); unique_ptr __nbh(0, free); if (__nc > static_cast(__nbuf-1)) { if (__specify_precision) __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); else __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); if (__nb == 0) __throw_bad_alloc(); __nbh.reset(__nb); } char* __ne = __nb + __nc; char* __np = this->__identify_padding(__nb, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __ob = __o; unique_ptr __obh(0, free); if (__nb != __nar) { __ob = (char_type*)malloc(2*static_cast(__nc)*sizeof(char_type)); if (__ob == 0) __throw_bad_alloc(); __obh.reset(__ob); } char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); return __s; } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const { // Stage 1 - Get number in narrow char char __fmt[8] = {'%', 0}; const char* __len = "L"; bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); const unsigned __nbuf = 30; char __nar[__nbuf]; char* __nb = __nar; int __nc; if (__specify_precision) __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); else __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); unique_ptr __nbh(0, free); if (__nc > static_cast(__nbuf-1)) { if (__specify_precision) __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); else __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); if (__nb == 0) __throw_bad_alloc(); __nbh.reset(__nb); } char* __ne = __nb + __nc; char* __np = this->__identify_padding(__nb, __ne, __iob); // Stage 2 - Widen __nar while adding thousands separators char_type __o[2*(__nbuf-1) - 1]; char_type* __ob = __o; unique_ptr __obh(0, free); if (__nb != __nar) { __ob = (char_type*)malloc(2*static_cast(__nc)*sizeof(char_type)); if (__ob == 0) __throw_bad_alloc(); __obh.reset(__ob); } char_type* __op; // pad here char_type* __oe; // end of output this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); // [__o, __oe) contains thousands_sep'd wide number // Stage 3 & 4 __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); return __s; } template _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const { // Stage 1 - Get pointer in narrow char char __fmt[6] = "%p"; const unsigned __nbuf = 20; char __nar[__nbuf]; int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); char* __ne = __nar + __nc; char* __np = this->__identify_padding(__nar, __ne, __iob); // Stage 2 - Widen __nar char_type __o[2*(__nbuf-1) - 1]; char_type* __op; // pad here char_type* __oe; // end of output const ctype& __ct = use_facet >(__iob.getloc()); __ct.widen(__nar, __ne, __o); __oe = __o + (__ne - __nar); if (__np == __ne) __op = __oe; else __op = __o + (__np - __nar); // [__o, __oe) contains wide number // Stage 3 & 4 return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put) template _LIBCPP_HIDDEN int __get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) { // Precondition: __n >= 1 if (__b == __e) { __err |= ios_base::eofbit | ios_base::failbit; return 0; } // get first digit _CharT __c = *__b; if (!__ct.is(ctype_base::digit, __c)) { __err |= ios_base::failbit; return 0; } int __r = __ct.narrow(__c, 0) - '0'; for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n) { // get next digit __c = *__b; if (!__ct.is(ctype_base::digit, __c)) return __r; __r = __r * 10 + __ct.narrow(__c, 0) - '0'; } if (__b == __e) __err |= ios_base::eofbit; return __r; } class _LIBCPP_TYPE_VIS time_base { public: enum dateorder {no_order, dmy, mdy, ymd, ydm}; }; template class _LIBCPP_TEMPLATE_VIS __time_get_c_storage { protected: typedef basic_string<_CharT> string_type; virtual const string_type* __weeks() const; virtual const string_type* __months() const; virtual const string_type* __am_pm() const; virtual const string_type& __c() const; virtual const string_type& __r() const; virtual const string_type& __x() const; virtual const string_type& __X() const; _LIBCPP_ALWAYS_INLINE ~__time_get_c_storage() {} }; template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage::__weeks() const; template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage::__months() const; template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage::__am_pm() const; template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage::__c() const; template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage::__r() const; template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage::__x() const; template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage::__X() const; template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage::__weeks() const; template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage::__months() const; template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage::__am_pm() const; template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage::__c() const; template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage::__r() const; template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage::__x() const; template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage::__X() const; template > class _LIBCPP_TEMPLATE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> { public: typedef _CharT char_type; typedef _InputIterator iter_type; typedef time_base::dateorder dateorder; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE explicit time_get(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE dateorder date_order() const { return this->do_date_order(); } _LIBCPP_ALWAYS_INLINE iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { return do_get_time(__b, __e, __iob, __err, __tm); } _LIBCPP_ALWAYS_INLINE iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { return do_get_date(__b, __e, __iob, __err, __tm); } _LIBCPP_ALWAYS_INLINE iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { return do_get_weekday(__b, __e, __iob, __err, __tm); } _LIBCPP_ALWAYS_INLINE iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { return do_get_monthname(__b, __e, __iob, __err, __tm); } _LIBCPP_ALWAYS_INLINE iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { return do_get_year(__b, __e, __iob, __err, __tm); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm *__tm, char __fmt, char __mod = 0) const { return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); } iter_type get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, const char_type* __fmtb, const char_type* __fmte) const; static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~time_get() {} virtual dateorder do_date_order() const; virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const; private: void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_weekdayname(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_monthname(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; void __get_day_year_num(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const; }; template locale::id time_get<_CharT, _InputIterator>::id; // time_get primitives template void time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { // Note: ignoring case comes from the POSIX strptime spec const string_type* __wk = this->__weeks(); ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk; if (__i < 14) __w = __i % 7; } template void time_get<_CharT, _InputIterator>::__get_monthname(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { // Note: ignoring case comes from the POSIX strptime spec const string_type* __month = this->__months(); ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month; if (__i < 24) __m = __i % 12; } template void time_get<_CharT, _InputIterator>::__get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) __d = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; if (!(__err & ios_base::failbit) && __t <= 11) __m = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); if (!(__err & ios_base::failbit)) { if (__t < 69) __t += 2000; else if (69 <= __t && __t <= 99) __t += 1900; __y = __t - 1900; } } template void time_get<_CharT, _InputIterator>::__get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); if (!(__err & ios_base::failbit)) __y = __t - 1900; } template void time_get<_CharT, _InputIterator>::__get_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); if (!(__err & ios_base::failbit) && __t <= 23) __h = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) __h = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); if (!(__err & ios_base::failbit) && __t <= 59) __m = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); if (!(__err & ios_base::failbit) && __t <= 60) __s = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1); if (!(__err & ios_base::failbit) && __t <= 6) __w = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3); if (!(__err & ios_base::failbit) && __t <= 365) __d = __t; else __err |= ios_base::failbit; } template void time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) ; if (__b == __e) __err |= ios_base::eofbit; } template void time_get<_CharT, _InputIterator>::__get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { const string_type* __ap = this->__am_pm(); if (__ap[0].size() + __ap[1].size() == 0) { __err |= ios_base::failbit; return; } ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap; if (__i == 0 && __h == 12) __h = 0; else if (__i == 1 && __h < 12) __h += 12; } template void time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype& __ct) const { if (__b == __e) { __err |= ios_base::eofbit | ios_base::failbit; return; } if (__ct.narrow(*__b, 0) != '%') __err |= ios_base::failbit; else if(++__b == __e) __err |= ios_base::eofbit; } // time_get end primitives template _InputIterator time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, const char_type* __fmtb, const char_type* __fmte) const { const ctype& __ct = use_facet >(__iob.getloc()); __err = ios_base::goodbit; while (__fmtb != __fmte && __err == ios_base::goodbit) { if (__b == __e) { __err = ios_base::failbit; break; } if (__ct.narrow(*__fmtb, 0) == '%') { if (++__fmtb == __fmte) { __err = ios_base::failbit; break; } char __cmd = __ct.narrow(*__fmtb, 0); char __opt = '\0'; if (__cmd == 'E' || __cmd == '0') { if (++__fmtb == __fmte) { __err = ios_base::failbit; break; } __opt = __cmd; __cmd = __ct.narrow(*__fmtb, 0); } __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt); ++__fmtb; } else if (__ct.is(ctype_base::space, *__fmtb)) { for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) ; for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) ; } else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) { ++__b; ++__fmtb; } else __err = ios_base::failbit; } if (__b == __e) __err |= ios_base::eofbit; return __b; } template typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const { return mdy; } template _InputIterator time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); } template _InputIterator time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { const string_type& __fmt = this->__x(); return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); } template _InputIterator time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { const ctype& __ct = use_facet >(__iob.getloc()); __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); return __b; } template _InputIterator time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { const ctype& __ct = use_facet >(__iob.getloc()); __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); return __b; } template _InputIterator time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { const ctype& __ct = use_facet >(__iob.getloc()); __get_year(__tm->tm_year, __b, __e, __err, __ct); return __b; } template _InputIterator time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const { __err = ios_base::goodbit; const ctype& __ct = use_facet >(__iob.getloc()); switch (__fmt) { case 'a': case 'A': __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); break; case 'b': case 'B': case 'h': __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); break; case 'c': { const string_type& __fm = this->__c(); __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); } break; case 'd': case 'e': __get_day(__tm->tm_mday, __b, __e, __err, __ct); break; case 'D': { const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); } break; case 'F': { const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); } break; case 'H': __get_hour(__tm->tm_hour, __b, __e, __err, __ct); break; case 'I': __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct); break; case 'j': __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct); break; case 'm': __get_month(__tm->tm_mon, __b, __e, __err, __ct); break; case 'M': __get_minute(__tm->tm_min, __b, __e, __err, __ct); break; case 'n': case 't': __get_white_space(__b, __e, __err, __ct); break; case 'p': __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct); break; case 'r': { const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); } break; case 'R': { const char_type __fm[] = {'%', 'H', ':', '%', 'M'}; __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); } break; case 'S': __get_second(__tm->tm_sec, __b, __e, __err, __ct); break; case 'T': { const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); } break; case 'w': __get_weekday(__tm->tm_wday, __b, __e, __err, __ct); break; case 'x': return do_get_date(__b, __e, __iob, __err, __tm); case 'X': { const string_type& __fm = this->__X(); __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); } break; case 'y': __get_year(__tm->tm_year, __b, __e, __err, __ct); break; case 'Y': __get_year4(__tm->tm_year, __b, __e, __err, __ct); break; case '%': __get_percent(__b, __e, __err, __ct); break; default: __err |= ios_base::failbit; } return __b; } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get) class _LIBCPP_TYPE_VIS __time_get { protected: locale_t __loc_; __time_get(const char* __nm); __time_get(const string& __nm); ~__time_get(); }; template class _LIBCPP_TEMPLATE_VIS __time_get_storage : public __time_get { protected: typedef basic_string<_CharT> string_type; string_type __weeks_[14]; string_type __months_[24]; string_type __am_pm_[2]; string_type __c_; string_type __r_; string_type __x_; string_type __X_; explicit __time_get_storage(const char* __nm); explicit __time_get_storage(const string& __nm); _LIBCPP_ALWAYS_INLINE ~__time_get_storage() {} time_base::dateorder __do_date_order() const; private: void init(const ctype<_CharT>&); string_type __analyze(char __fmt, const ctype<_CharT>&); }; template > class _LIBCPP_TEMPLATE_VIS time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> { public: typedef time_base::dateorder dateorder; typedef _InputIterator iter_type; typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_INLINE_VISIBILITY explicit time_get_byname(const char* __nm, size_t __refs = 0) : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {} _LIBCPP_INLINE_VISIBILITY explicit time_get_byname(const string& __nm, size_t __refs = 0) : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {} protected: _LIBCPP_INLINE_VISIBILITY ~time_get_byname() {} _LIBCPP_INLINE_VISIBILITY virtual dateorder do_date_order() const {return this->__do_date_order();} private: _LIBCPP_INLINE_VISIBILITY virtual const string_type* __weeks() const {return this->__weeks_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type* __months() const {return this->__months_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type* __am_pm() const {return this->__am_pm_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type& __c() const {return this->__c_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type& __r() const {return this->__r_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type& __x() const {return this->__x_;} _LIBCPP_INLINE_VISIBILITY virtual const string_type& __X() const {return this->__X_;} }; _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname) class _LIBCPP_TYPE_VIS __time_put { locale_t __loc_; protected: _LIBCPP_ALWAYS_INLINE __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} __time_put(const char* __nm); __time_put(const string& __nm); ~__time_put(); void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const; void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const; }; template > class _LIBCPP_TEMPLATE_VIS time_put : public locale::facet, private __time_put { public: typedef _CharT char_type; typedef _OutputIterator iter_type; _LIBCPP_ALWAYS_INLINE explicit time_put(size_t __refs = 0) : locale::facet(__refs) {} iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe) const; _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const { return do_put(__s, __iob, __fl, __tm, __fmt, __mod); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~time_put() {} virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const; _LIBCPP_ALWAYS_INLINE explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {} _LIBCPP_ALWAYS_INLINE explicit time_put(const string& __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {} }; template locale::id time_put<_CharT, _OutputIterator>::id; template _OutputIterator time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe) const { const ctype& __ct = use_facet >(__iob.getloc()); for (; __pb != __pe; ++__pb) { if (__ct.narrow(*__pb, 0) == '%') { if (++__pb == __pe) { *__s++ = __pb[-1]; break; } char __mod = 0; char __fmt = __ct.narrow(*__pb, 0); if (__fmt == 'E' || __fmt == 'O') { if (++__pb == __pe) { *__s++ = __pb[-2]; *__s++ = __pb[-1]; break; } __mod = __fmt; __fmt = __ct.narrow(*__pb, 0); } __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); } else *__s++ = *__pb; } return __s; } template _OutputIterator time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const { char_type __nar[100]; char_type* __nb = __nar; char_type* __ne = __nb + 100; __do_put(__nb, __ne, __tm, __fmt, __mod); return _VSTD::copy(__nb, __ne, __s); } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put) template > class _LIBCPP_TEMPLATE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> { public: _LIBCPP_ALWAYS_INLINE explicit time_put_byname(const char* __nm, size_t __refs = 0) : time_put<_CharT, _OutputIterator>(__nm, __refs) {} _LIBCPP_ALWAYS_INLINE explicit time_put_byname(const string& __nm, size_t __refs = 0) : time_put<_CharT, _OutputIterator>(__nm, __refs) {} protected: _LIBCPP_ALWAYS_INLINE ~time_put_byname() {} }; _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname) // money_base class _LIBCPP_TYPE_VIS money_base { public: enum part {none, space, symbol, sign, value}; struct pattern {char field[4];}; _LIBCPP_ALWAYS_INLINE money_base() {} }; // moneypunct template class _LIBCPP_TEMPLATE_VIS moneypunct : public locale::facet, public money_base { public: typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} _LIBCPP_ALWAYS_INLINE string_type curr_symbol() const {return do_curr_symbol();} _LIBCPP_ALWAYS_INLINE string_type positive_sign() const {return do_positive_sign();} _LIBCPP_ALWAYS_INLINE string_type negative_sign() const {return do_negative_sign();} _LIBCPP_ALWAYS_INLINE int frac_digits() const {return do_frac_digits();} _LIBCPP_ALWAYS_INLINE pattern pos_format() const {return do_pos_format();} _LIBCPP_ALWAYS_INLINE pattern neg_format() const {return do_neg_format();} static locale::id id; static const bool intl = _International; protected: _LIBCPP_ALWAYS_INLINE ~moneypunct() {} virtual char_type do_decimal_point() const {return numeric_limits::max();} virtual char_type do_thousands_sep() const {return numeric_limits::max();} virtual string do_grouping() const {return string();} virtual string_type do_curr_symbol() const {return string_type();} virtual string_type do_positive_sign() const {return string_type();} virtual string_type do_negative_sign() const {return string_type(1, '-');} virtual int do_frac_digits() const {return 0;} virtual pattern do_pos_format() const {pattern __p = {{symbol, sign, none, value}}; return __p;} virtual pattern do_neg_format() const {pattern __p = {{symbol, sign, none, value}}; return __p;} }; template locale::id moneypunct<_CharT, _International>::id; template const bool moneypunct<_CharT, _International>::intl; _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct) // moneypunct_byname template class _LIBCPP_TEMPLATE_VIS moneypunct_byname : public moneypunct<_CharT, _International> { public: typedef money_base::pattern pattern; typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE explicit moneypunct_byname(const char* __nm, size_t __refs = 0) : moneypunct<_CharT, _International>(__refs) {init(__nm);} _LIBCPP_ALWAYS_INLINE explicit moneypunct_byname(const string& __nm, size_t __refs = 0) : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());} protected: _LIBCPP_ALWAYS_INLINE ~moneypunct_byname() {} virtual char_type do_decimal_point() const {return __decimal_point_;} virtual char_type do_thousands_sep() const {return __thousands_sep_;} virtual string do_grouping() const {return __grouping_;} virtual string_type do_curr_symbol() const {return __curr_symbol_;} virtual string_type do_positive_sign() const {return __positive_sign_;} virtual string_type do_negative_sign() const {return __negative_sign_;} virtual int do_frac_digits() const {return __frac_digits_;} virtual pattern do_pos_format() const {return __pos_format_;} virtual pattern do_neg_format() const {return __neg_format_;} private: char_type __decimal_point_; char_type __thousands_sep_; string __grouping_; string_type __curr_symbol_; string_type __positive_sign_; string_type __negative_sign_; int __frac_digits_; pattern __pos_format_; pattern __neg_format_; void init(const char*); }; template<> _LIBCPP_FUNC_VIS void moneypunct_byname::init(const char*); template<> _LIBCPP_FUNC_VIS void moneypunct_byname::init(const char*); template<> _LIBCPP_FUNC_VIS void moneypunct_byname::init(const char*); template<> _LIBCPP_FUNC_VIS void moneypunct_byname::init(const char*); _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname) // money_get template class __money_get { protected: typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE __money_get() {} static void __gather_info(bool __intl, const locale& __loc, money_base::pattern& __pat, char_type& __dp, char_type& __ts, string& __grp, string_type& __sym, string_type& __psn, string_type& __nsn, int& __fd); }; template void __money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, money_base::pattern& __pat, char_type& __dp, char_type& __ts, string& __grp, string_type& __sym, string_type& __psn, string_type& __nsn, int& __fd) { if (__intl) { const moneypunct& __mp = use_facet >(__loc); __pat = __mp.neg_format(); __nsn = __mp.negative_sign(); __psn = __mp.positive_sign(); __dp = __mp.decimal_point(); __ts = __mp.thousands_sep(); __grp = __mp.grouping(); __sym = __mp.curr_symbol(); __fd = __mp.frac_digits(); } else { const moneypunct& __mp = use_facet >(__loc); __pat = __mp.neg_format(); __nsn = __mp.negative_sign(); __psn = __mp.positive_sign(); __dp = __mp.decimal_point(); __ts = __mp.thousands_sep(); __grp = __mp.grouping(); __sym = __mp.curr_symbol(); __fd = __mp.frac_digits(); } } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get) template > class _LIBCPP_TEMPLATE_VIS money_get : public locale::facet, private __money_get<_CharT> { public: typedef _CharT char_type; typedef _InputIterator iter_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE explicit money_get(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { return do_get(__b, __e, __intl, __iob, __err, __v); } _LIBCPP_ALWAYS_INLINE iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const { return do_get(__b, __e, __intl, __iob, __err, __v); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~money_get() {} virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const; virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const; private: static bool __do_get(iter_type& __b, iter_type __e, bool __intl, const locale& __loc, ios_base::fmtflags __flags, ios_base::iostate& __err, bool& __neg, const ctype& __ct, unique_ptr& __wb, char_type*& __wn, char_type* __we); }; template locale::id money_get<_CharT, _InputIterator>::id; _LIBCPP_FUNC_VIS void __do_nothing(void*); template _LIBCPP_HIDDEN void __double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e) { bool __owns = __b.get_deleter() != __do_nothing; size_t __cur_cap = static_cast(__e-__b.get()) * sizeof(_Tp); size_t __new_cap = __cur_cap < numeric_limits::max() / 2 ? 2 * __cur_cap : numeric_limits::max(); if (__new_cap == 0) __new_cap = sizeof(_Tp); size_t __n_off = static_cast(__n - __b.get()); _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap); if (__t == 0) __throw_bad_alloc(); if (__owns) __b.release(); __b = unique_ptr<_Tp, void(*)(void*)>(__t, free); __new_cap /= sizeof(_Tp); __n = __b.get() + __n_off; __e = __b.get() + __new_cap; } // true == success template bool money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, bool __intl, const locale& __loc, ios_base::fmtflags __flags, ios_base::iostate& __err, bool& __neg, const ctype& __ct, unique_ptr& __wb, char_type*& __wn, char_type* __we) { const unsigned __bz = 100; unsigned __gbuf[__bz]; unique_ptr __gb(__gbuf, __do_nothing); unsigned* __gn = __gb.get(); unsigned* __ge = __gn + __bz; money_base::pattern __pat; char_type __dp; char_type __ts; string __grp; string_type __sym; string_type __psn; string_type __nsn; // Capture the spaces read into money_base::{space,none} so they // can be compared to initial spaces in __sym. string_type __spaces; int __fd; __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, __sym, __psn, __nsn, __fd); const string_type* __trailing_sign = 0; __wn = __wb.get(); for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) { switch (__pat.field[__p]) { case money_base::space: if (__p != 3) { if (__ct.is(ctype_base::space, *__b)) __spaces.push_back(*__b++); else { __err |= ios_base::failbit; return false; } } _LIBCPP_FALLTHROUGH(); case money_base::none: if (__p != 3) { while (__b != __e && __ct.is(ctype_base::space, *__b)) __spaces.push_back(*__b++); } break; case money_base::sign: if (__psn.size() + __nsn.size() > 0) { if (__psn.size() == 0 || __nsn.size() == 0) { // sign is optional if (__psn.size() > 0) { // __nsn.size() == 0 if (*__b == __psn[0]) { ++__b; if (__psn.size() > 1) __trailing_sign = &__psn; } else __neg = true; } else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0 { ++__b; __neg = true; if (__nsn.size() > 1) __trailing_sign = &__nsn; } } else // sign is required { if (*__b == __psn[0]) { ++__b; if (__psn.size() > 1) __trailing_sign = &__psn; } else if (*__b == __nsn[0]) { ++__b; __neg = true; if (__nsn.size() > 1) __trailing_sign = &__nsn; } else { __err |= ios_base::failbit; return false; } } } break; case money_base::symbol: { bool __more_needed = __trailing_sign || (__p < 2) || (__p == 2 && __pat.field[3] != static_cast(money_base::none)); bool __sb = (__flags & ios_base::showbase) != 0; if (__sb || __more_needed) { typename string_type::const_iterator __sym_space_end = __sym.begin(); if (__p > 0 && (__pat.field[__p - 1] == money_base::none || __pat.field[__p - 1] == money_base::space)) { // Match spaces we've already read against spaces at // the beginning of __sym. while (__sym_space_end != __sym.end() && __ct.is(ctype_base::space, *__sym_space_end)) ++__sym_space_end; const size_t __num_spaces = __sym_space_end - __sym.begin(); if (__num_spaces > __spaces.size() || !equal(__spaces.end() - __num_spaces, __spaces.end(), __sym.begin())) { // No match. Put __sym_space_end back at the // beginning of __sym, which will prevent a // match in the next loop. __sym_space_end = __sym.begin(); } } typename string_type::const_iterator __sym_curr_char = __sym_space_end; while (__sym_curr_char != __sym.end() && __b != __e && *__b == *__sym_curr_char) { ++__b; ++__sym_curr_char; } if (__sb && __sym_curr_char != __sym.end()) { __err |= ios_base::failbit; return false; } } } break; case money_base::value: { unsigned __ng = 0; for (; __b != __e; ++__b) { char_type __c = *__b; if (__ct.is(ctype_base::digit, __c)) { if (__wn == __we) __double_or_nothing(__wb, __wn, __we); *__wn++ = __c; ++__ng; } else if (__grp.size() > 0 && __ng > 0 && __c == __ts) { if (__gn == __ge) __double_or_nothing(__gb, __gn, __ge); *__gn++ = __ng; __ng = 0; } else break; } if (__gb.get() != __gn && __ng > 0) { if (__gn == __ge) __double_or_nothing(__gb, __gn, __ge); *__gn++ = __ng; } if (__fd > 0) { if (__b == __e || *__b != __dp) { __err |= ios_base::failbit; return false; } for (++__b; __fd > 0; --__fd, ++__b) { if (__b == __e || !__ct.is(ctype_base::digit, *__b)) { __err |= ios_base::failbit; return false; } if (__wn == __we) __double_or_nothing(__wb, __wn, __we); *__wn++ = *__b; } } if (__wn == __wb.get()) { __err |= ios_base::failbit; return false; } } break; } } if (__trailing_sign) { for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) { if (__b == __e || *__b != (*__trailing_sign)[__i]) { __err |= ios_base::failbit; return false; } } } if (__gb.get() != __gn) { ios_base::iostate __et = ios_base::goodbit; __check_grouping(__grp, __gb.get(), __gn, __et); if (__et) { __err |= ios_base::failbit; return false; } } return true; } template _InputIterator money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { const int __bz = 100; char_type __wbuf[__bz]; unique_ptr __wb(__wbuf, __do_nothing); char_type* __wn; char_type* __we = __wbuf + __bz; locale __loc = __iob.getloc(); const ctype& __ct = use_facet >(__loc); bool __neg = false; if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) { const char __src[] = "0123456789"; char_type __atoms[sizeof(__src)-1]; __ct.widen(__src, __src + (sizeof(__src)-1), __atoms); char __nbuf[__bz]; char* __nc = __nbuf; unique_ptr __h(0, free); if (__wn - __wb.get() > __bz-2) { __h.reset((char*)malloc(static_cast(__wn - __wb.get() + 2))); if (__h.get() == 0) __throw_bad_alloc(); __nc = __h.get(); } if (__neg) *__nc++ = '-'; for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms]; *__nc = char(); if (sscanf(__nbuf, "%Lf", &__v) != 1) __throw_runtime_error("money_get error"); } if (__b == __e) __err |= ios_base::eofbit; return __b; } template _InputIterator money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const { const int __bz = 100; char_type __wbuf[__bz]; unique_ptr __wb(__wbuf, __do_nothing); char_type* __wn; char_type* __we = __wbuf + __bz; locale __loc = __iob.getloc(); const ctype& __ct = use_facet >(__loc); bool __neg = false; if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) { __v.clear(); if (__neg) __v.push_back(__ct.widen('-')); char_type __z = __ct.widen('0'); char_type* __w; for (__w = __wb.get(); __w < __wn-1; ++__w) if (*__w != __z) break; __v.append(__w, __wn); } if (__b == __e) __err |= ios_base::eofbit; return __b; } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get) // money_put template class __money_put { protected: typedef _CharT char_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE __money_put() {} static void __gather_info(bool __intl, bool __neg, const locale& __loc, money_base::pattern& __pat, char_type& __dp, char_type& __ts, string& __grp, string_type& __sym, string_type& __sn, int& __fd); static void __format(char_type* __mb, char_type*& __mi, char_type*& __me, ios_base::fmtflags __flags, const char_type* __db, const char_type* __de, const ctype& __ct, bool __neg, const money_base::pattern& __pat, char_type __dp, char_type __ts, const string& __grp, const string_type& __sym, const string_type& __sn, int __fd); }; template void __money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc, money_base::pattern& __pat, char_type& __dp, char_type& __ts, string& __grp, string_type& __sym, string_type& __sn, int& __fd) { if (__intl) { const moneypunct& __mp = use_facet >(__loc); if (__neg) { __pat = __mp.neg_format(); __sn = __mp.negative_sign(); } else { __pat = __mp.pos_format(); __sn = __mp.positive_sign(); } __dp = __mp.decimal_point(); __ts = __mp.thousands_sep(); __grp = __mp.grouping(); __sym = __mp.curr_symbol(); __fd = __mp.frac_digits(); } else { const moneypunct& __mp = use_facet >(__loc); if (__neg) { __pat = __mp.neg_format(); __sn = __mp.negative_sign(); } else { __pat = __mp.pos_format(); __sn = __mp.positive_sign(); } __dp = __mp.decimal_point(); __ts = __mp.thousands_sep(); __grp = __mp.grouping(); __sym = __mp.curr_symbol(); __fd = __mp.frac_digits(); } } template void __money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me, ios_base::fmtflags __flags, const char_type* __db, const char_type* __de, const ctype& __ct, bool __neg, const money_base::pattern& __pat, char_type __dp, char_type __ts, const string& __grp, const string_type& __sym, const string_type& __sn, int __fd) { __me = __mb; for (unsigned __p = 0; __p < 4; ++__p) { switch (__pat.field[__p]) { case money_base::none: __mi = __me; break; case money_base::space: __mi = __me; *__me++ = __ct.widen(' '); break; case money_base::sign: if (!__sn.empty()) *__me++ = __sn[0]; break; case money_base::symbol: if (!__sym.empty() && (__flags & ios_base::showbase)) __me = _VSTD::copy(__sym.begin(), __sym.end(), __me); break; case money_base::value: { // remember start of value so we can reverse it char_type* __t = __me; // find beginning of digits if (__neg) ++__db; // find end of digits const char_type* __d; for (__d = __db; __d < __de; ++__d) if (!__ct.is(ctype_base::digit, *__d)) break; // print fractional part if (__fd > 0) { int __f; for (__f = __fd; __d > __db && __f > 0; --__f) *__me++ = *--__d; char_type __z = __f > 0 ? __ct.widen('0') : char_type(); for (; __f > 0; --__f) *__me++ = __z; *__me++ = __dp; } // print units part if (__d == __db) { *__me++ = __ct.widen('0'); } else { unsigned __ng = 0; unsigned __ig = 0; unsigned __gl = __grp.empty() ? numeric_limits::max() : static_cast(__grp[__ig]); while (__d != __db) { if (__ng == __gl) { *__me++ = __ts; __ng = 0; if (++__ig < __grp.size()) __gl = __grp[__ig] == numeric_limits::max() ? numeric_limits::max() : static_cast(__grp[__ig]); } *__me++ = *--__d; ++__ng; } } // reverse it reverse(__t, __me); } break; } } // print rest of sign, if any if (__sn.size() > 1) __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me); // set alignment if ((__flags & ios_base::adjustfield) == ios_base::left) __mi = __me; else if ((__flags & ios_base::adjustfield) != ios_base::internal) __mi = __mb; } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put) template > class _LIBCPP_TEMPLATE_VIS money_put : public locale::facet, private __money_put<_CharT> { public: typedef _CharT char_type; typedef _OutputIterator iter_type; typedef basic_string string_type; _LIBCPP_ALWAYS_INLINE explicit money_put(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const { return do_put(__s, __intl, __iob, __fl, __units); } _LIBCPP_ALWAYS_INLINE iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const { return do_put(__s, __intl, __iob, __fl, __digits); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~money_put() {} virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const; virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const; }; template locale::id money_put<_CharT, _OutputIterator>::id; template _OutputIterator money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const { // convert to char const size_t __bs = 100; char __buf[__bs]; char* __bb = __buf; char_type __digits[__bs]; char_type* __db = __digits; size_t __n = static_cast(snprintf(__bb, __bs, "%.0Lf", __units)); unique_ptr __hn(0, free); unique_ptr __hd(0, free); // secure memory for digit storage if (__n > __bs-1) { __n = static_cast(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units)); if (__bb == 0) __throw_bad_alloc(); __hn.reset(__bb); __hd.reset((char_type*)malloc(__n * sizeof(char_type))); if (__hd == nullptr) __throw_bad_alloc(); __db = __hd.get(); } // gather info locale __loc = __iob.getloc(); const ctype& __ct = use_facet >(__loc); __ct.widen(__bb, __bb + __n, __db); bool __neg = __n > 0 && __bb[0] == '-'; money_base::pattern __pat; char_type __dp; char_type __ts; string __grp; string_type __sym; string_type __sn; int __fd; this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); // secure memory for formatting char_type __mbuf[__bs]; char_type* __mb = __mbuf; unique_ptr __hw(0, free); size_t __exn = static_cast(__n) > __fd ? (__n - static_cast(__fd)) * 2 + __sn.size() + __sym.size() + static_cast(__fd) + 1 : __sn.size() + __sym.size() + static_cast(__fd) + 2; if (__exn > __bs) { __hw.reset((char_type*)malloc(__exn * sizeof(char_type))); __mb = __hw.get(); if (__mb == 0) __throw_bad_alloc(); } // format char_type* __mi; char_type* __me; this->__format(__mb, __mi, __me, __iob.flags(), __db, __db + __n, __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); } template _OutputIterator money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const { // gather info locale __loc = __iob.getloc(); const ctype& __ct = use_facet >(__loc); bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); money_base::pattern __pat; char_type __dp; char_type __ts; string __grp; string_type __sym; string_type __sn; int __fd; this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); // secure memory for formatting char_type __mbuf[100]; char_type* __mb = __mbuf; unique_ptr __h(0, free); size_t __exn = static_cast(__digits.size()) > __fd ? (__digits.size() - static_cast(__fd)) * 2 + __sn.size() + __sym.size() + static_cast(__fd) + 1 : __sn.size() + __sym.size() + static_cast(__fd) + 2; if (__exn > 100) { __h.reset((char_type*)malloc(__exn * sizeof(char_type))); __mb = __h.get(); if (__mb == 0) __throw_bad_alloc(); } // format char_type* __mi; char_type* __me; this->__format(__mb, __mi, __me, __iob.flags(), __digits.data(), __digits.data() + __digits.size(), __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put) // messages class _LIBCPP_TYPE_VIS messages_base { public: typedef ptrdiff_t catalog; _LIBCPP_ALWAYS_INLINE messages_base() {} }; template class _LIBCPP_TEMPLATE_VIS messages : public locale::facet, public messages_base { public: typedef _CharT char_type; typedef basic_string<_CharT> string_type; _LIBCPP_ALWAYS_INLINE explicit messages(size_t __refs = 0) : locale::facet(__refs) {} _LIBCPP_ALWAYS_INLINE catalog open(const basic_string& __nm, const locale& __loc) const { return do_open(__nm, __loc); } _LIBCPP_ALWAYS_INLINE string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { return do_get(__c, __set, __msgid, __dflt); } _LIBCPP_ALWAYS_INLINE void close(catalog __c) const { do_close(__c); } static locale::id id; protected: _LIBCPP_ALWAYS_INLINE ~messages() {} virtual catalog do_open(const basic_string&, const locale&) const; virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const; virtual void do_close(catalog) const; }; template locale::id messages<_CharT>::id; template typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string& __nm, const locale&) const { #ifdef _LIBCPP_HAS_CATOPEN catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); if (__cat != -1) __cat = static_cast((static_cast(__cat) >> 1)); return __cat; #else // !_LIBCPP_HAS_CATOPEN return -1; #endif // _LIBCPP_HAS_CATOPEN } template typename messages<_CharT>::string_type messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { #ifdef _LIBCPP_HAS_CATOPEN string __ndflt; __narrow_to_utf8()(back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size()); if (__c != -1) __c <<= 1; nl_catd __cat = (nl_catd)__c; char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); string_type __w; __widen_from_utf8()(back_inserter(__w), __n, __n + strlen(__n)); return __w; #else // !_LIBCPP_HAS_CATOPEN return __dflt; #endif // _LIBCPP_HAS_CATOPEN } template void messages<_CharT>::do_close(catalog __c) const { #ifdef _LIBCPP_HAS_CATOPEN if (__c != -1) __c <<= 1; nl_catd __cat = (nl_catd)__c; catclose(__cat); #endif // _LIBCPP_HAS_CATOPEN } _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages) template class _LIBCPP_TEMPLATE_VIS messages_byname : public messages<_CharT> { public: typedef messages_base::catalog catalog; typedef basic_string<_CharT> string_type; _LIBCPP_ALWAYS_INLINE explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {} _LIBCPP_ALWAYS_INLINE explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {} protected: _LIBCPP_ALWAYS_INLINE ~messages_byname() {} }; _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname) template, class _Byte_alloc = allocator > class _LIBCPP_TEMPLATE_VIS wstring_convert { public: typedef basic_string, _Byte_alloc> byte_string; typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string; typedef typename _Codecvt::state_type state_type; typedef typename wide_string::traits_type::int_type int_type; private: byte_string __byte_err_string_; wide_string __wide_err_string_; _Codecvt* __cvtptr_; state_type __cvtstate_; size_t __cvtcount_; wstring_convert(const wstring_convert& __wc); wstring_convert& operator=(const wstring_convert& __wc); public: _LIBCPP_ALWAYS_INLINE _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(_Codecvt* __pcvt = new _Codecvt); _LIBCPP_ALWAYS_INLINE wstring_convert(_Codecvt* __pcvt, state_type __state); _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string()); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_ALWAYS_INLINE wstring_convert(wstring_convert&& __wc); #endif ~wstring_convert(); _LIBCPP_ALWAYS_INLINE wide_string from_bytes(char __byte) {return from_bytes(&__byte, &__byte+1);} _LIBCPP_ALWAYS_INLINE wide_string from_bytes(const char* __ptr) {return from_bytes(__ptr, __ptr + char_traits::length(__ptr));} _LIBCPP_ALWAYS_INLINE wide_string from_bytes(const byte_string& __str) {return from_bytes(__str.data(), __str.data() + __str.size());} wide_string from_bytes(const char* __first, const char* __last); _LIBCPP_ALWAYS_INLINE byte_string to_bytes(_Elem __wchar) {return to_bytes(&__wchar, &__wchar+1);} _LIBCPP_ALWAYS_INLINE byte_string to_bytes(const _Elem* __wptr) {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));} _LIBCPP_ALWAYS_INLINE byte_string to_bytes(const wide_string& __wstr) {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());} byte_string to_bytes(const _Elem* __first, const _Elem* __last); _LIBCPP_ALWAYS_INLINE size_t converted() const _NOEXCEPT {return __cvtcount_;} _LIBCPP_ALWAYS_INLINE state_type state() const {return __cvtstate_;} }; template inline wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: wstring_convert(_Codecvt* __pcvt) : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) { } template inline wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: wstring_convert(_Codecvt* __pcvt, state_type __state) : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) { } template wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err) : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtstate_(), __cvtcount_(0) { __cvtptr_ = new _Codecvt; } #ifndef _LIBCPP_CXX03_LANG template inline wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: wstring_convert(wstring_convert&& __wc) : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)), __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)), __cvtptr_(__wc.__cvtptr_), __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_) { __wc.__cvtptr_ = nullptr; } #endif // _LIBCPP_CXX03_LANG template wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() { delete __cvtptr_; } template typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: from_bytes(const char* __frm, const char* __frm_end) { __cvtcount_ = 0; if (__cvtptr_ != nullptr) { wide_string __ws(2*(__frm_end - __frm), _Elem()); if (__frm != __frm_end) __ws.resize(__ws.capacity()); codecvt_base::result __r = codecvt_base::ok; state_type __st = __cvtstate_; if (__frm != __frm_end) { _Elem* __to = &__ws[0]; _Elem* __to_end = __to + __ws.size(); const char* __frm_nxt; do { _Elem* __to_nxt; __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); __cvtcount_ += __frm_nxt - __frm; if (__frm_nxt == __frm) { __r = codecvt_base::error; } else if (__r == codecvt_base::noconv) { __ws.resize(__to - &__ws[0]); // This only gets executed if _Elem is char __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); __frm = __frm_nxt; __r = codecvt_base::ok; } else if (__r == codecvt_base::ok) { __ws.resize(__to_nxt - &__ws[0]); __frm = __frm_nxt; } else if (__r == codecvt_base::partial) { ptrdiff_t __s = __to_nxt - &__ws[0]; __ws.resize(2 * __s); __to = &__ws[0] + __s; __to_end = &__ws[0] + __ws.size(); __frm = __frm_nxt; } } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); } if (__r == codecvt_base::ok) return __ws; } if (__wide_err_string_.empty()) __throw_range_error("wstring_convert: from_bytes error"); return __wide_err_string_; } template typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: to_bytes(const _Elem* __frm, const _Elem* __frm_end) { __cvtcount_ = 0; if (__cvtptr_ != nullptr) { byte_string __bs(2*(__frm_end - __frm), char()); if (__frm != __frm_end) __bs.resize(__bs.capacity()); codecvt_base::result __r = codecvt_base::ok; state_type __st = __cvtstate_; if (__frm != __frm_end) { char* __to = &__bs[0]; char* __to_end = __to + __bs.size(); const _Elem* __frm_nxt; do { char* __to_nxt; __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); __cvtcount_ += __frm_nxt - __frm; if (__frm_nxt == __frm) { __r = codecvt_base::error; } else if (__r == codecvt_base::noconv) { __bs.resize(__to - &__bs[0]); // This only gets executed if _Elem is char __bs.append((const char*)__frm, (const char*)__frm_end); __frm = __frm_nxt; __r = codecvt_base::ok; } else if (__r == codecvt_base::ok) { __bs.resize(__to_nxt - &__bs[0]); __frm = __frm_nxt; } else if (__r == codecvt_base::partial) { ptrdiff_t __s = __to_nxt - &__bs[0]; __bs.resize(2 * __s); __to = &__bs[0] + __s; __to_end = &__bs[0] + __bs.size(); __frm = __frm_nxt; } } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); } if (__r == codecvt_base::ok) { size_t __s = __bs.size(); __bs.resize(__bs.capacity()); char* __to = &__bs[0] + __s; char* __to_end = __to + __bs.size(); do { char* __to_nxt; __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); if (__r == codecvt_base::noconv) { __bs.resize(__to - &__bs[0]); __r = codecvt_base::ok; } else if (__r == codecvt_base::ok) { __bs.resize(__to_nxt - &__bs[0]); } else if (__r == codecvt_base::partial) { ptrdiff_t __sp = __to_nxt - &__bs[0]; __bs.resize(2 * __sp); __to = &__bs[0] + __sp; __to_end = &__bs[0] + __bs.size(); } } while (__r == codecvt_base::partial); if (__r == codecvt_base::ok) return __bs; } } if (__byte_err_string_.empty()) __throw_range_error("wstring_convert: to_bytes error"); return __byte_err_string_; } template > class _LIBCPP_TEMPLATE_VIS wbuffer_convert : public basic_streambuf<_Elem, _Tr> { public: // types: typedef _Elem char_type; typedef _Tr traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; typedef typename _Codecvt::state_type state_type; private: char* __extbuf_; const char* __extbufnext_; const char* __extbufend_; char __extbuf_min_[8]; size_t __ebs_; char_type* __intbuf_; size_t __ibs_; streambuf* __bufptr_; _Codecvt* __cv_; state_type __st_; ios_base::openmode __cm_; bool __owns_eb_; bool __owns_ib_; bool __always_noconv_; wbuffer_convert(const wbuffer_convert&); wbuffer_convert& operator=(const wbuffer_convert&); public: _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); ~wbuffer_convert(); _LIBCPP_INLINE_VISIBILITY streambuf* rdbuf() const {return __bufptr_;} _LIBCPP_INLINE_VISIBILITY streambuf* rdbuf(streambuf* __bytebuf) { streambuf* __r = __bufptr_; __bufptr_ = __bytebuf; return __r; } _LIBCPP_INLINE_VISIBILITY state_type state() const {return __st_;} protected: virtual int_type underflow(); virtual int_type pbackfail(int_type __c = traits_type::eof()); virtual int_type overflow (int_type __c = traits_type::eof()); virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out); virtual int sync(); private: bool __read_mode(); void __write_mode(); wbuffer_convert* __close(); }; template wbuffer_convert<_Codecvt, _Elem, _Tr>:: wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) : __extbuf_(0), __extbufnext_(0), __extbufend_(0), __ebs_(0), __intbuf_(0), __ibs_(0), __bufptr_(__bytebuf), __cv_(__pcvt), __st_(__state), __cm_(0), __owns_eb_(false), __owns_ib_(false), __always_noconv_(__cv_ ? __cv_->always_noconv() : false) { setbuf(0, 4096); } template wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() { __close(); delete __cv_; if (__owns_eb_) delete [] __extbuf_; if (__owns_ib_) delete [] __intbuf_; } template typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() { if (__cv_ == 0 || __bufptr_ == 0) return traits_type::eof(); bool __initial = __read_mode(); char_type __1buf; if (this->gptr() == 0) this->setg(&__1buf, &__1buf+1, &__1buf+1); const size_t __unget_sz = __initial ? 0 : min((this->egptr() - this->eback()) / 2, 4); int_type __c = traits_type::eof(); if (this->gptr() == this->egptr()) { memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); if (__always_noconv_) { streamsize __nmemb = static_cast(this->egptr() - this->eback() - __unget_sz); __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb); if (__nmemb != 0) { this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb); __c = *this->gptr(); } } else { _LIBCPP_ASSERT(!(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" ); if (__extbufend_ != __extbufnext_) memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); streamsize __nmemb = _VSTD::min(static_cast(this->egptr() - this->eback() - __unget_sz), static_cast(__extbufend_ - __extbufnext_)); codecvt_base::result __r; // FIXME: Do we ever need to restore the state here? //state_type __svs = __st_; streamsize __nr = __bufptr_->sgetn(const_cast(__extbufnext_), __nmemb); if (__nr != 0) { __extbufend_ = __extbufnext_ + __nr; char_type* __inext; __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->egptr(), __inext); if (__r == codecvt_base::noconv) { this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*) const_cast(__extbufend_)); __c = *this->gptr(); } else if (__inext != this->eback() + __unget_sz) { this->setg(this->eback(), this->eback() + __unget_sz, __inext); __c = *this->gptr(); } } } } else __c = *this->gptr(); if (this->eback() == &__1buf) this->setg(0, 0, 0); return __c; } template typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) { if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) { if (traits_type::eq_int_type(__c, traits_type::eof())) { this->gbump(-1); return traits_type::not_eof(__c); } if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { this->gbump(-1); *this->gptr() = traits_type::to_char_type(__c); return __c; } } return traits_type::eof(); } template typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) { if (__cv_ == 0 || __bufptr_ == 0) return traits_type::eof(); __write_mode(); char_type __1buf; char_type* __pb_save = this->pbase(); char_type* __epb_save = this->epptr(); if (!traits_type::eq_int_type(__c, traits_type::eof())) { if (this->pptr() == 0) this->setp(&__1buf, &__1buf+1); *this->pptr() = traits_type::to_char_type(__c); this->pbump(1); } if (this->pptr() != this->pbase()) { if (__always_noconv_) { streamsize __nmemb = static_cast(this->pptr() - this->pbase()); if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) return traits_type::eof(); } else { char* __extbe = __extbuf_; codecvt_base::result __r; do { const char_type* __e; __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); if (__e == this->pbase()) return traits_type::eof(); if (__r == codecvt_base::noconv) { streamsize __nmemb = static_cast(this->pptr() - this->pbase()); if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) return traits_type::eof(); } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) { streamsize __nmemb = static_cast(__extbe - __extbuf_); if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) return traits_type::eof(); if (__r == codecvt_base::partial) { this->setp(const_cast(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else return traits_type::eof(); } while (__r == codecvt_base::partial); } this->setp(__pb_save, __epb_save); } return traits_type::not_eof(__c); } template basic_streambuf<_Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) { this->setg(0, 0, 0); this->setp(0, 0); if (__owns_eb_) delete [] __extbuf_; if (__owns_ib_) delete [] __intbuf_; __ebs_ = __n; if (__ebs_ > sizeof(__extbuf_min_)) { if (__always_noconv_ && __s) { __extbuf_ = (char*)__s; __owns_eb_ = false; } else { __extbuf_ = new char[__ebs_]; __owns_eb_ = true; } } else { __extbuf_ = __extbuf_min_; __ebs_ = sizeof(__extbuf_min_); __owns_eb_ = false; } if (!__always_noconv_) { __ibs_ = max(__n, sizeof(__extbuf_min_)); if (__s && __ibs_ >= sizeof(__extbuf_min_)) { __intbuf_ = __s; __owns_ib_ = false; } else { __intbuf_ = new char_type[__ibs_]; __owns_ib_ = true; } } else { __ibs_ = 0; __intbuf_ = 0; __owns_ib_ = false; } return this; } template typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) { int __width = __cv_->encoding(); if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync()) return pos_type(off_type(-1)); // __width > 0 || __off == 0, now check __way if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end) return pos_type(off_type(-1)); pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om); __r.state(__st_); return __r; } template typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) { if (__cv_ == 0 || __bufptr_ == 0 || sync()) return pos_type(off_type(-1)); if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1))) return pos_type(off_type(-1)); return __sp; } template int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() { if (__cv_ == 0 || __bufptr_ == 0) return 0; if (__cm_ & ios_base::out) { if (this->pptr() != this->pbase()) if (overflow() == traits_type::eof()) return -1; codecvt_base::result __r; do { char* __extbe; __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); streamsize __nmemb = static_cast(__extbe - __extbuf_); if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) return -1; } while (__r == codecvt_base::partial); if (__r == codecvt_base::error) return -1; if (__bufptr_->pubsync()) return -1; } else if (__cm_ & ios_base::in) { off_type __c; if (__always_noconv_) __c = this->egptr() - this->gptr(); else { int __width = __cv_->encoding(); __c = __extbufend_ - __extbufnext_; if (__width > 0) __c += __width * (this->egptr() - this->gptr()); else { if (this->gptr() != this->egptr()) { reverse(this->gptr(), this->egptr()); codecvt_base::result __r; const char_type* __e = this->gptr(); char* __extbe; do { __r = __cv_->out(__st_, __e, this->egptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); switch (__r) { case codecvt_base::noconv: __c += this->egptr() - this->gptr(); break; case codecvt_base::ok: case codecvt_base::partial: __c += __extbe - __extbuf_; break; default: return -1; } } while (__r == codecvt_base::partial); } } } if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1))) return -1; this->setg(0, 0, 0); __cm_ = 0; } return 0; } template bool wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() { if (!(__cm_ & ios_base::in)) { this->setp(0, 0); if (__always_noconv_) this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_); else this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); __cm_ = ios_base::in; return true; } return false; } template void wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() { if (!(__cm_ & ios_base::out)) { this->setg(0, 0, 0); if (__ebs_ > sizeof(__extbuf_min_)) { if (__always_noconv_) this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1)); else this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); } else this->setp(0, 0); __cm_ = ios_base::out; } } template wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() { wbuffer_convert* __rt = 0; if (__cv_ != 0 && __bufptr_ != 0) { __rt = this; if ((__cm_ & ios_base::out) && sync()) __rt = 0; } return __rt; } _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS #endif // _LIBCPP_LOCALE Index: projects/clang600-import/contrib/libc++/include/map =================================================================== --- projects/clang600-import/contrib/libc++/include/map (revision 327038) +++ projects/clang600-import/contrib/libc++/include/map (revision 327039) @@ -1,1926 +1,1926 @@ // -*- C++ -*- //===----------------------------- map ------------------------------------===// // // 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_MAP #define _LIBCPP_MAP /* map synopsis namespace std { template , class Allocator = allocator>> class map { public: // types: typedef Key key_type; typedef T mapped_type; typedef pair value_type; typedef Compare key_compare; typedef Allocator allocator_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 typename allocator_type::size_type size_type; typedef typename allocator_type::difference_type difference_type; typedef implementation-defined iterator; typedef implementation-defined const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; class value_compare : public binary_function { friend class map; protected: key_compare comp; value_compare(key_compare c); public: bool operator()(const value_type& x, const value_type& y) const; }; // construct/copy/destroy: map() noexcept( is_nothrow_default_constructible::value && is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value); explicit map(const key_compare& comp); map(const key_compare& comp, const allocator_type& a); template map(InputIterator first, InputIterator last, const key_compare& comp = key_compare()); template map(InputIterator first, InputIterator last, const key_compare& comp, const allocator_type& a); map(const map& m); map(map&& m) noexcept( is_nothrow_move_constructible::value && is_nothrow_move_constructible::value); explicit map(const allocator_type& a); map(const map& m, const allocator_type& a); map(map&& m, const allocator_type& a); map(initializer_list il, const key_compare& comp = key_compare()); map(initializer_list il, const key_compare& comp, const allocator_type& a); template map(InputIterator first, InputIterator last, const allocator_type& a) : map(first, last, Compare(), a) {} // C++14 map(initializer_list il, const allocator_type& a) : map(il, Compare(), a) {} // C++14 ~map(); map& operator=(const map& m); map& operator=(map&& m) noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value); map& operator=(initializer_list il); // iterators: 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; // capacity: bool empty() const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; // element access: mapped_type& operator[](const key_type& k); mapped_type& operator[](key_type&& k); mapped_type& at(const key_type& k); const mapped_type& at(const key_type& k) const; // modifiers: template pair emplace(Args&&... args); template iterator emplace_hint(const_iterator position, Args&&... args); pair insert(const value_type& v); pair insert( value_type&& v); // C++17 template pair insert(P&& p); iterator insert(const_iterator position, const value_type& v); iterator insert(const_iterator position, value_type&& v); // C++17 template iterator insert(const_iterator position, P&& p); template void insert(InputIterator first, InputIterator last); void insert(initializer_list il); template pair try_emplace(const key_type& k, Args&&... args); // C++17 template pair try_emplace(key_type&& k, Args&&... args); // C++17 template iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 template iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 template pair insert_or_assign(const key_type& k, M&& obj); // C++17 template pair insert_or_assign(key_type&& k, M&& obj); // C++17 template iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 template iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 iterator erase(const_iterator position); iterator erase(iterator position); // C++14 size_type erase(const key_type& k); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; void swap(map& m) noexcept(allocator_traits::is_always_equal::value && is_nothrow_swappable::value); // C++17 // observers: allocator_type get_allocator() const noexcept; key_compare key_comp() const; value_compare value_comp() const; // map operations: iterator find(const key_type& k); const_iterator find(const key_type& k) const; template iterator find(const K& x); // C++14 template const_iterator find(const K& x) const; // C++14 template size_type count(const K& x) const; // C++14 size_type count(const key_type& k) const; iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template iterator lower_bound(const K& x); // C++14 template const_iterator lower_bound(const K& x) const; // C++14 iterator upper_bound(const key_type& k); const_iterator upper_bound(const key_type& k) const; template iterator upper_bound(const K& x); // C++14 template const_iterator upper_bound(const K& x) const; // C++14 pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; template pair equal_range(const K& x); // C++14 template pair equal_range(const K& x) const; // C++14 }; template bool operator==(const map& x, const map& y); template bool operator< (const map& x, const map& y); template bool operator!=(const map& x, const map& y); template bool operator> (const map& x, const map& y); template bool operator>=(const map& x, const map& y); template bool operator<=(const map& x, const map& y); // specialized algorithms: template void swap(map& x, map& y) noexcept(noexcept(x.swap(y))); template , class Allocator = allocator>> class multimap { public: // types: typedef Key key_type; typedef T mapped_type; typedef pair value_type; typedef Compare key_compare; typedef Allocator allocator_type; typedef typename allocator_type::reference reference; typedef typename allocator_type::const_reference const_reference; 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 implementation-defined iterator; typedef implementation-defined const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; class value_compare : public binary_function { friend class multimap; protected: key_compare comp; value_compare(key_compare c); public: bool operator()(const value_type& x, const value_type& y) const; }; // construct/copy/destroy: multimap() noexcept( is_nothrow_default_constructible::value && is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value); explicit multimap(const key_compare& comp); multimap(const key_compare& comp, const allocator_type& a); template multimap(InputIterator first, InputIterator last, const key_compare& comp); template multimap(InputIterator first, InputIterator last, const key_compare& comp, const allocator_type& a); multimap(const multimap& m); multimap(multimap&& m) noexcept( is_nothrow_move_constructible::value && is_nothrow_move_constructible::value); explicit multimap(const allocator_type& a); multimap(const multimap& m, const allocator_type& a); multimap(multimap&& m, const allocator_type& a); multimap(initializer_list il, const key_compare& comp = key_compare()); multimap(initializer_list il, const key_compare& comp, const allocator_type& a); template multimap(InputIterator first, InputIterator last, const allocator_type& a) : multimap(first, last, Compare(), a) {} // C++14 multimap(initializer_list il, const allocator_type& a) : multimap(il, Compare(), a) {} // C++14 ~multimap(); multimap& operator=(const multimap& m); multimap& operator=(multimap&& m) noexcept( allocator_type::propagate_on_container_move_assignment::value && is_nothrow_move_assignable::value && is_nothrow_move_assignable::value); multimap& operator=(initializer_list il); // iterators: 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; // capacity: bool empty() const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; // modifiers: template iterator emplace(Args&&... args); template iterator emplace_hint(const_iterator position, Args&&... args); iterator insert(const value_type& v); iterator insert( value_type&& v); // C++17 template iterator insert(P&& p); iterator insert(const_iterator position, const value_type& v); iterator insert(const_iterator position, value_type&& v); // C++17 template iterator insert(const_iterator position, P&& p); template void insert(InputIterator first, InputIterator last); void insert(initializer_list il); iterator erase(const_iterator position); iterator erase(iterator position); // C++14 size_type erase(const key_type& k); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; void swap(multimap& m) noexcept(allocator_traits::is_always_equal::value && is_nothrow_swappable::value); // C++17 // observers: allocator_type get_allocator() const noexcept; key_compare key_comp() const; value_compare value_comp() const; // map operations: iterator find(const key_type& k); const_iterator find(const key_type& k) const; template iterator find(const K& x); // C++14 template const_iterator find(const K& x) const; // C++14 template size_type count(const K& x) const; // C++14 size_type count(const key_type& k) const; iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template iterator lower_bound(const K& x); // C++14 template const_iterator lower_bound(const K& x) const; // C++14 iterator upper_bound(const key_type& k); const_iterator upper_bound(const key_type& k) const; template iterator upper_bound(const K& x); // C++14 template const_iterator upper_bound(const K& x) const; // C++14 pair equal_range(const key_type& k); pair equal_range(const key_type& k) const; template pair equal_range(const K& x); // C++14 template pair equal_range(const K& x) const; // C++14 }; template bool operator==(const multimap& x, const multimap& y); template bool operator< (const multimap& x, const multimap& y); template bool operator!=(const multimap& x, const multimap& y); template bool operator> (const multimap& x, const multimap& y); template bool operator>=(const multimap& x, const multimap& y); template bool operator<=(const multimap& x, const multimap& y); // specialized algorithms: template void swap(multimap& x, multimap& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include <__tree> #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_STD template class __map_value_compare : private _Compare { public: _LIBCPP_INLINE_VISIBILITY __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) : _Compare() {} _LIBCPP_INLINE_VISIBILITY __map_value_compare(_Compare c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) : _Compare(c) {} _LIBCPP_INLINE_VISIBILITY const _Compare& key_comp() const _NOEXCEPT {return *this;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _CP& __y) const {return static_cast(*this)(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _Key& __y) const {return static_cast(*this)(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const {return static_cast(*this)(__x, __y.__cc.first);} void swap(__map_value_compare&__y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) { using _VSTD::swap; swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y)); } #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type operator () ( const _K2& __x, const _CP& __y ) const {return static_cast(*this) (__x, __y.__cc.first);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type operator () (const _CP& __x, const _K2& __y) const {return static_cast(*this) (__x.__cc.first, __y);} #endif }; template class __map_value_compare<_Key, _CP, _Compare, false> { _Compare comp; public: _LIBCPP_INLINE_VISIBILITY __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value) : comp() {} _LIBCPP_INLINE_VISIBILITY __map_value_compare(_Compare c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value) : comp(c) {} _LIBCPP_INLINE_VISIBILITY const _Compare& key_comp() const _NOEXCEPT {return comp;} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _CP& __y) const {return comp(__x.__cc.first, __y.__cc.first);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _CP& __x, const _Key& __y) const {return comp(__x.__cc.first, __y);} _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const {return comp(__x, __y.__cc.first);} void swap(__map_value_compare&__y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) { using _VSTD::swap; swap(comp, __y.comp); } #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type operator () ( const _K2& __x, const _CP& __y ) const {return comp (__x, __y.__cc.first);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type operator () (const _CP& __x, const _K2& __y) const {return comp (__x.__cc.first, __y);} #endif }; template inline _LIBCPP_INLINE_VISIBILITY void swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, __map_value_compare<_Key, _CP, _Compare, __b>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } template class __map_node_destructor { typedef _Allocator allocator_type; typedef allocator_traits __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; private: allocator_type& __na_; __map_node_destructor& operator=(const __map_node_destructor&); public: bool __first_constructed; bool __second_constructed; _LIBCPP_INLINE_VISIBILITY explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT : __na_(__na), __first_constructed(false), __second_constructed(false) {} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY __map_node_destructor(__tree_node_destructor&& __x) _NOEXCEPT : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) { __x.__value_constructed = false; } #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void operator()(pointer __p) _NOEXCEPT { if (__second_constructed) __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); if (__first_constructed) __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } }; template class map; template class multimap; template class __map_const_iterator; #ifndef _LIBCPP_CXX03_LANG template union __value_type { typedef _Key key_type; typedef _Tp mapped_type; typedef pair value_type; typedef pair __nc_value_type; value_type __cc; __nc_value_type __nc; _LIBCPP_INLINE_VISIBILITY __value_type& operator=(const __value_type& __v) {__nc = __v.__cc; return *this;} _LIBCPP_INLINE_VISIBILITY __value_type& operator=(__value_type&& __v) {__nc = _VSTD::move(__v.__nc); return *this;} template ::value >::type > _LIBCPP_INLINE_VISIBILITY __value_type& operator=(_ValueTp&& __v) { __nc = _VSTD::forward<_ValueTp>(__v); return *this; } private: __value_type() _LIBCPP_EQUAL_DELETE; ~__value_type() _LIBCPP_EQUAL_DELETE; __value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE; __value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE; }; #else template struct __value_type { typedef _Key key_type; typedef _Tp mapped_type; typedef pair value_type; value_type __cc; private: __value_type(); __value_type(__value_type const&); __value_type& operator=(__value_type const&); ~__value_type(); }; #endif // _LIBCPP_CXX03_LANG template struct __extract_key_value_types; template struct __extract_key_value_types<__value_type<_Key, _Tp> > { typedef _Key const __key_type; typedef _Tp __mapped_type; }; template class _LIBCPP_TEMPLATE_VIS __map_iterator { typedef typename _TreeIterator::_NodeTypes _NodeTypes; typedef typename _TreeIterator::__pointer_traits __pointer_traits; _TreeIterator __i_; public: typedef bidirectional_iterator_tag iterator_category; typedef typename _NodeTypes::__map_value_type value_type; typedef typename _TreeIterator::difference_type difference_type; typedef value_type& reference; typedef typename _NodeTypes::__map_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __map_iterator() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_iterator& operator++() {++__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __map_iterator operator++(int) { __map_iterator __t(*this); ++(*this); return __t; } _LIBCPP_INLINE_VISIBILITY __map_iterator& operator--() {--__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __map_iterator operator--(int) { __map_iterator __t(*this); --(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __map_iterator& __x, const __map_iterator& __y) {return __x.__i_ == __y.__i_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {return __x.__i_ != __y.__i_;} template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; }; template class _LIBCPP_TEMPLATE_VIS __map_const_iterator { typedef typename _TreeIterator::_NodeTypes _NodeTypes; typedef typename _TreeIterator::__pointer_traits __pointer_traits; _TreeIterator __i_; public: typedef bidirectional_iterator_tag iterator_category; typedef typename _NodeTypes::__map_value_type value_type; typedef typename _TreeIterator::difference_type difference_type; typedef const value_type& reference; typedef typename _NodeTypes::__const_map_value_type_pointer pointer; _LIBCPP_INLINE_VISIBILITY __map_const_iterator() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return pointer_traits::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_const_iterator& operator++() {++__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __map_const_iterator operator++(int) { __map_const_iterator __t(*this); ++(*this); return __t; } _LIBCPP_INLINE_VISIBILITY __map_const_iterator& operator--() {--__i_; return *this;} _LIBCPP_INLINE_VISIBILITY __map_const_iterator operator--(int) { __map_const_iterator __t(*this); --(*this); return __t; } friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {return __x.__i_ == __y.__i_;} friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {return __x.__i_ != __y.__i_;} template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; template friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; }; template , class _Allocator = allocator > > class _LIBCPP_TEMPLATE_VIS map { public: // types: typedef _Key key_type; typedef _Tp mapped_type; typedef pair value_type; typedef pair __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); class _LIBCPP_TEMPLATE_VIS value_compare : public binary_function { friend class map; protected: key_compare comp; _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} public: _LIBCPP_INLINE_VISIBILITY bool operator()(const value_type& __x, const value_type& __y) const {return comp(__x.first, __y.first);} }; private: typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; typedef typename __rebind_alloc_helper, __value_type>::type __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; __base __tree_; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef __map_iterator iterator; typedef __map_const_iterator const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY map() _NOEXCEPT_( is_nothrow_default_constructible::value && is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value) : __tree_(__vc(key_compare())) {} _LIBCPP_INLINE_VISIBILITY explicit map(const key_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value) : __tree_(__vc(__comp)) {} _LIBCPP_INLINE_VISIBILITY explicit map(const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} template _LIBCPP_INLINE_VISIBILITY map(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) { insert(__f, __l); } template _LIBCPP_INLINE_VISIBILITY map(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { insert(__f, __l); } #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY map(_InputIterator __f, _InputIterator __l, const allocator_type& __a) : map(__f, __l, key_compare(), __a) {} #endif _LIBCPP_INLINE_VISIBILITY map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); } _LIBCPP_INLINE_VISIBILITY map& operator=(const map& __m) { #ifndef _LIBCPP_CXX03_LANG __tree_ = __m.__tree_; #else if (this != &__m) { __tree_.clear(); __tree_.value_comp() = __m.__tree_.value_comp(); __tree_.__copy_assign_alloc(__m.__tree_); insert(__m.begin(), __m.end()); } #endif return *this; } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY map(map&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __tree_(_VSTD::move(__m.__tree_)) { } map(map&& __m, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY map& operator=(map&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) { __tree_ = _VSTD::move(__m.__tree_); return *this; } _LIBCPP_INLINE_VISIBILITY map(initializer_list __il, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) { insert(__il.begin(), __il.end()); } _LIBCPP_INLINE_VISIBILITY map(initializer_list __il, const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { insert(__il.begin(), __il.end()); } #if _LIBCPP_STD_VER > 11 _LIBCPP_INLINE_VISIBILITY map(initializer_list __il, const allocator_type& __a) : map(__il, key_compare(), __a) {} #endif _LIBCPP_INLINE_VISIBILITY map& operator=(initializer_list __il) { __tree_.__assign_unique(__il.begin(), __il.end()); return *this; } #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit map(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) { } _LIBCPP_INLINE_VISIBILITY map(const map& __m, const allocator_type& __a) : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) { insert(__m.begin(), __m.end()); } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __tree_.end();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __tree_.end();} _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 + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return __tree_.max_size();} mapped_type& operator[](const key_type& __k); #ifndef _LIBCPP_CXX03_LANG mapped_type& operator[](key_type&& __k); #endif mapped_type& at(const key_type& __k); const mapped_type& at(const key_type& __k) const; _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} _LIBCPP_INLINE_VISIBILITY key_compare key_comp() const {return __tree_.value_comp().key_comp();} _LIBCPP_INLINE_VISIBILITY value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY pair emplace(_Args&& ...__args) { return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY iterator emplace_hint(const_iterator __p, _Args&& ...__args) { return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...); } template ::value>::type> _LIBCPP_INLINE_VISIBILITY pair insert(_Pp&& __p) {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));} template ::value>::type> _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, _Pp&& __p) {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY pair insert(const value_type& __v) {return __tree_.__insert_unique(__v);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, const value_type& __v) {return __tree_.__insert_unique(__p.__i_, __v);} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY pair insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, value_type&& __v) {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));} _LIBCPP_INLINE_VISIBILITY void insert(initializer_list __il) {insert(__il.begin(), __il.end());} #endif template _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __f, _InputIterator __l) { for (const_iterator __e = cend(); __f != __l; ++__f) insert(__e.__i_, *__f); } #if _LIBCPP_STD_VER > 14 template _LIBCPP_INLINE_VISIBILITY pair try_emplace(const key_type& __k, _Args&&... __args) { return __tree_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); } template _LIBCPP_INLINE_VISIBILITY pair try_emplace(key_type&& __k, _Args&&... __args) { return __tree_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); } template _LIBCPP_INLINE_VISIBILITY iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) { return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); } template _LIBCPP_INLINE_VISIBILITY iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) { return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); } template _LIBCPP_INLINE_VISIBILITY pair insert_or_assign(const key_type& __k, _Vp&& __v) { iterator __p = lower_bound(__k); if ( __p != end() && !key_comp()(__k, __p->first)) { __p->second = _VSTD::forward<_Vp>(__v); return _VSTD::make_pair(__p, false); } return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); } template _LIBCPP_INLINE_VISIBILITY pair insert_or_assign(key_type&& __k, _Vp&& __v) { iterator __p = lower_bound(__k); if ( __p != end() && !key_comp()(__k, __p->first)) { __p->second = _VSTD::forward<_Vp>(__v); return _VSTD::make_pair(__p, false); } return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true); } template _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) { iterator __p = lower_bound(__k); if ( __p != end() && !key_comp()(__k, __p->first)) { __p->second = _VSTD::forward<_Vp>(__v); return __p; } return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v)); } template _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) { iterator __p = lower_bound(__k); if ( __p != end() && !key_comp()(__k, __p->first)) { __p->second = _VSTD::forward<_Vp>(__v); return __p; } return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); } #endif // _LIBCPP_STD_VER > 14 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __tree_.__erase_unique(__k);} _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __f, const_iterator __l) {return __tree_.erase(__f.__i_, __l.__i_);} _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {__tree_.clear();} _LIBCPP_INLINE_VISIBILITY void swap(map& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {__tree_.swap(__m.__tree_);} _LIBCPP_INLINE_VISIBILITY iterator find(const key_type& __k) {return __tree_.find(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator find(const key_type& __k) const {return __tree_.find(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type find(const _K2& __k) {return __tree_.find(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type find(const _K2& __k) const {return __tree_.find(__k);} #endif _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __tree_.__count_unique(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type count(const _K2& __k) const {return __tree_.__count_unique(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator lower_bound(const key_type& __k) const {return __tree_.lower_bound(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator upper_bound(const key_type& __k) {return __tree_.upper_bound(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator upper_bound(const key_type& __k) const {return __tree_.upper_bound(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} #endif _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) {return __tree_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) const {return __tree_.__equal_range_unique(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);} #endif private: typedef typename __base::__node __node; typedef typename __base::__node_allocator __node_allocator; typedef typename __base::__node_pointer __node_pointer; typedef typename __base::__node_base_pointer __node_base_pointer; typedef typename __base::__parent_pointer __parent_pointer; typedef __map_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; #ifdef _LIBCPP_CXX03_LANG __node_holder __construct_node_with_key(const key_type& __k); #endif }; #ifndef _LIBCPP_CXX03_LANG template map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a) : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) { if (__a != __m.get_allocator()) { const_iterator __e = cend(); while (!__m.empty()) __tree_.__insert_unique(__e.__i_, _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__nc)); } } template _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) { return __tree_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), _VSTD::forward_as_tuple()).first->__cc.second; } template _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) { return __tree_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), _VSTD::forward_as_tuple()).first->__cc.second; } #else // _LIBCPP_CXX03_LANG template typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); __h.get_deleter().__first_constructed = true; __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) { __parent_pointer __parent; __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { __node_holder __h = __construct_node_with_key(__k); __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return __r->__value_.__cc.second; } #endif // _LIBCPP_CXX03_LANG template _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) { __parent_pointer __parent; __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); #ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS return static_cast<__node_pointer>(__child)->__value_.__cc.second; } template const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const { __parent_pointer __parent; __node_base_pointer __child = __tree_.__find_equal(__parent, __k); #ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS return static_cast<__node_pointer>(__child)->__value_.__cc.second; } template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(map<_Key, _Tp, _Compare, _Allocator>& __x, map<_Key, _Tp, _Compare, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } template , class _Allocator = allocator > > class _LIBCPP_TEMPLATE_VIS multimap { public: // types: typedef _Key key_type; typedef _Tp mapped_type; typedef pair value_type; typedef pair __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); class _LIBCPP_TEMPLATE_VIS value_compare : public binary_function { friend class multimap; protected: key_compare comp; _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {} public: _LIBCPP_INLINE_VISIBILITY bool operator()(const value_type& __x, const value_type& __y) const {return comp(__x.first, __y.first);} }; private: typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; typedef typename __rebind_alloc_helper, __value_type>::type __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; __base __tree_; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef __map_iterator iterator; typedef __map_const_iterator const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; _LIBCPP_INLINE_VISIBILITY multimap() _NOEXCEPT_( is_nothrow_default_constructible::value && is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value) : __tree_(__vc(key_compare())) {} _LIBCPP_INLINE_VISIBILITY explicit multimap(const key_compare& __comp) _NOEXCEPT_( is_nothrow_default_constructible::value && is_nothrow_copy_constructible::value) : __tree_(__vc(__comp)) {} _LIBCPP_INLINE_VISIBILITY explicit multimap(const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {} template _LIBCPP_INLINE_VISIBILITY multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) { insert(__f, __l); } template _LIBCPP_INLINE_VISIBILITY multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { insert(__f, __l); } #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a) : multimap(__f, __l, key_compare(), __a) {} #endif _LIBCPP_INLINE_VISIBILITY multimap(const multimap& __m) : __tree_(__m.__tree_.value_comp(), __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) { insert(__m.begin(), __m.end()); } _LIBCPP_INLINE_VISIBILITY multimap& operator=(const multimap& __m) { #ifndef _LIBCPP_CXX03_LANG __tree_ = __m.__tree_; #else if (this != &__m) { __tree_.clear(); __tree_.value_comp() = __m.__tree_.value_comp(); __tree_.__copy_assign_alloc(__m.__tree_); insert(__m.begin(), __m.end()); } #endif return *this; } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY multimap(multimap&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __tree_(_VSTD::move(__m.__tree_)) { } multimap(multimap&& __m, const allocator_type& __a); _LIBCPP_INLINE_VISIBILITY multimap& operator=(multimap&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) { __tree_ = _VSTD::move(__m.__tree_); return *this; } _LIBCPP_INLINE_VISIBILITY multimap(initializer_list __il, const key_compare& __comp = key_compare()) : __tree_(__vc(__comp)) { insert(__il.begin(), __il.end()); } _LIBCPP_INLINE_VISIBILITY multimap(initializer_list __il, const key_compare& __comp, const allocator_type& __a) : __tree_(__vc(__comp), typename __base::allocator_type(__a)) { insert(__il.begin(), __il.end()); } #if _LIBCPP_STD_VER > 11 _LIBCPP_INLINE_VISIBILITY multimap(initializer_list __il, const allocator_type& __a) : multimap(__il, key_compare(), __a) {} #endif _LIBCPP_INLINE_VISIBILITY multimap& operator=(initializer_list __il) { __tree_.__assign_multi(__il.begin(), __il.end()); return *this; } #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit multimap(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) { } _LIBCPP_INLINE_VISIBILITY multimap(const multimap& __m, const allocator_type& __a) : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) { insert(__m.begin(), __m.end()); } _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __tree_.end();} _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __tree_.end();} _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 + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return __tree_.max_size();} _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());} _LIBCPP_INLINE_VISIBILITY key_compare key_comp() const {return __tree_.value_comp().key_comp();} _LIBCPP_INLINE_VISIBILITY value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY iterator emplace(_Args&& ...__args) { return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY iterator emplace_hint(const_iterator __p, _Args&& ...__args) { return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); } template ::value>::type> _LIBCPP_INLINE_VISIBILITY iterator insert(_Pp&& __p) {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));} template ::value>::type> _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, _Pp&& __p) {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));} _LIBCPP_INLINE_VISIBILITY iterator insert(value_type&& __v) {return __tree_.__insert_multi(_VSTD::move(__v));} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, value_type&& __v) {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));} _LIBCPP_INLINE_VISIBILITY void insert(initializer_list __il) {insert(__il.begin(), __il.end());} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __p, const value_type& __v) {return __tree_.__insert_multi(__p.__i_, __v);} template _LIBCPP_INLINE_VISIBILITY void insert(_InputIterator __f, _InputIterator __l) { for (const_iterator __e = cend(); __f != __l; ++__f) __tree_.__insert_multi(__e.__i_, *__f); } _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __f, const_iterator __l) {return __tree_.erase(__f.__i_, __l.__i_);} _LIBCPP_INLINE_VISIBILITY void clear() {__tree_.clear();} _LIBCPP_INLINE_VISIBILITY void swap(multimap& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {__tree_.swap(__m.__tree_);} _LIBCPP_INLINE_VISIBILITY iterator find(const key_type& __k) {return __tree_.find(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator find(const key_type& __k) const {return __tree_.find(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type find(const _K2& __k) {return __tree_.find(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type find(const _K2& __k) const {return __tree_.find(__k);} #endif _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __tree_.__count_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator lower_bound(const key_type& __k) const {return __tree_.lower_bound(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator upper_bound(const key_type& __k) {return __tree_.upper_bound(__k);} _LIBCPP_INLINE_VISIBILITY const_iterator upper_bound(const key_type& __k) const {return __tree_.upper_bound(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);} #endif _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) {return __tree_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) const {return __tree_.__equal_range_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} #endif private: typedef typename __base::__node __node; typedef typename __base::__node_allocator __node_allocator; typedef typename __base::__node_pointer __node_pointer; typedef __map_node_destructor<__node_allocator> _Dp; typedef unique_ptr<__node, _Dp> __node_holder; }; #ifndef _LIBCPP_CXX03_LANG template multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a)) { if (__a != __m.get_allocator()) { const_iterator __e = cend(); while (!__m.empty()) __tree_.__insert_multi(__e.__i_, _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__nc)); } } #endif template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY void swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, multimap<_Key, _Tp, _Compare, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_MAP Index: projects/clang600-import/contrib/libc++/include/memory =================================================================== --- projects/clang600-import/contrib/libc++/include/memory (revision 327038) +++ projects/clang600-import/contrib/libc++/include/memory (revision 327039) @@ -1,5542 +1,5601 @@ // -*- C++ -*- //===-------------------------- memory ------------------------------------===// // // 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_MEMORY #define _LIBCPP_MEMORY /* memory synopsis namespace std { struct allocator_arg_t { }; constexpr allocator_arg_t allocator_arg = allocator_arg_t(); template struct uses_allocator; template struct pointer_traits { typedef Ptr pointer; typedef
element_type; typedef
difference_type; template using rebind =
; static pointer pointer_to(
); }; template struct pointer_traits { typedef T* pointer; typedef T element_type; typedef ptrdiff_t difference_type; template using rebind = U*; static pointer pointer_to(
) noexcept; }; +template constexpr T* to_address(T* p) noexcept; // C++20 +template auto to_address(const Ptr& p) noexcept; // C++20 + template struct allocator_traits { typedef Alloc allocator_type; typedef typename allocator_type::value_type value_type; typedef Alloc::pointer | value_type* pointer; typedef Alloc::const_pointer | pointer_traits::rebind const_pointer; typedef Alloc::void_pointer | pointer_traits::rebind void_pointer; typedef Alloc::const_void_pointer | pointer_traits::rebind const_void_pointer; typedef Alloc::difference_type | pointer_traits::difference_type difference_type; typedef Alloc::size_type | make_unsigned::type size_type; typedef Alloc::propagate_on_container_copy_assignment | false_type propagate_on_container_copy_assignment; typedef Alloc::propagate_on_container_move_assignment | false_type propagate_on_container_move_assignment; typedef Alloc::propagate_on_container_swap | false_type propagate_on_container_swap; typedef Alloc::is_always_equal | is_empty is_always_equal; template using rebind_alloc = Alloc::rebind::other | Alloc; template using rebind_traits = allocator_traits>; - static pointer allocate(allocator_type& a, size_type n); - static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); + static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20 + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; template static void construct(allocator_type& a, T* p, Args&&... args); template static void destroy(allocator_type& a, T* p); static size_type max_size(const allocator_type& a); // noexcept in C++14 static allocator_type select_on_container_copy_construction(const allocator_type& a); }; template <> class allocator { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind {typedef allocator<_Up> other;}; }; template class allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef typename add_lvalue_reference::type reference; typedef typename add_lvalue_reference::type const_reference; typedef T value_type; template struct rebind {typedef allocator other;}; allocator() noexcept; allocator(const allocator&) noexcept; template allocator(const allocator&) noexcept; ~allocator(); pointer address(reference x) const noexcept; const_pointer address(const_reference x) const noexcept; pointer allocate(size_type, allocator::const_pointer hint = 0); void deallocate(pointer p, size_type n) noexcept; size_type max_size() const noexcept; template void construct(U* p, Args&&... args); template void destroy(U* p); }; template bool operator==(const allocator&, const allocator&) noexcept; template bool operator!=(const allocator&, const allocator&) noexcept; template class raw_storage_iterator : public iterator // purposefully not C++03 { public: explicit raw_storage_iterator(OutputIterator x); raw_storage_iterator& operator*(); raw_storage_iterator& operator=(const T& element); raw_storage_iterator& operator++(); raw_storage_iterator operator++(int); }; template pair get_temporary_buffer(ptrdiff_t n) noexcept; template void return_temporary_buffer(T* p) noexcept; template T* addressof(T& r) noexcept; template T* addressof(const T&& r) noexcept = delete; template ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); template ForwardIterator uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); template void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); template ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x); template void destroy_at(T* location); template void destroy(ForwardIterator first, ForwardIterator last); template ForwardIterator destroy_n(ForwardIterator first, Size n); template ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); template pair uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); template void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); template ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); template void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); template ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); template struct auto_ptr_ref {}; // removed in C++17 template class auto_ptr // removed in C++17 { public: typedef X element_type; explicit auto_ptr(X* p =0) throw(); auto_ptr(auto_ptr&) throw(); template auto_ptr(auto_ptr&) throw(); auto_ptr& operator=(auto_ptr&) throw(); template auto_ptr& operator=(auto_ptr&) throw(); auto_ptr& operator=(auto_ptr_ref r) throw(); ~auto_ptr() throw(); typename add_lvalue_reference::type operator*() const throw(); X* operator->() const throw(); X* get() const throw(); X* release() throw(); void reset(X* p =0) throw(); auto_ptr(auto_ptr_ref) throw(); template operator auto_ptr_ref() throw(); template operator auto_ptr() throw(); }; template struct default_delete { constexpr default_delete() noexcept = default; template default_delete(const default_delete&) noexcept; void operator()(T*) const noexcept; }; template struct default_delete { constexpr default_delete() noexcept = default; void operator()(T*) const noexcept; template void operator()(U*) const = delete; }; template > class unique_ptr { public: typedef see below pointer; typedef T element_type; typedef D deleter_type; // constructors constexpr unique_ptr() noexcept; explicit unique_ptr(pointer p) noexcept; unique_ptr(pointer p, see below d1) noexcept; unique_ptr(pointer p, see below d2) noexcept; unique_ptr(unique_ptr&& u) noexcept; unique_ptr(nullptr_t) noexcept : unique_ptr() { } template unique_ptr(unique_ptr&& u) noexcept; template unique_ptr(auto_ptr&& u) noexcept; // removed in C++17 // destructor ~unique_ptr(); // assignment unique_ptr& operator=(unique_ptr&& u) noexcept; template unique_ptr& operator=(unique_ptr&& u) noexcept; unique_ptr& operator=(nullptr_t) noexcept; // observers typename add_lvalue_reference::type operator*() const; pointer operator->() const noexcept; pointer get() const noexcept; deleter_type& get_deleter() noexcept; const deleter_type& get_deleter() const noexcept; explicit operator bool() const noexcept; // modifiers pointer release() noexcept; void reset(pointer p = pointer()) noexcept; void swap(unique_ptr& u) noexcept; }; template class unique_ptr { public: typedef implementation-defined pointer; typedef T element_type; typedef D deleter_type; // constructors constexpr unique_ptr() noexcept; explicit unique_ptr(pointer p) noexcept; unique_ptr(pointer p, see below d) noexcept; unique_ptr(pointer p, see below d) noexcept; unique_ptr(unique_ptr&& u) noexcept; unique_ptr(nullptr_t) noexcept : unique_ptr() { } // destructor ~unique_ptr(); // assignment unique_ptr& operator=(unique_ptr&& u) noexcept; unique_ptr& operator=(nullptr_t) noexcept; // observers T& operator[](size_t i) const; pointer get() const noexcept; deleter_type& get_deleter() noexcept; const deleter_type& get_deleter() const noexcept; explicit operator bool() const noexcept; // modifiers pointer release() noexcept; void reset(pointer p = pointer()) noexcept; void reset(nullptr_t) noexcept; template void reset(U) = delete; void swap(unique_ptr& u) noexcept; }; template void swap(unique_ptr& x, unique_ptr& y) noexcept; template bool operator==(const unique_ptr& x, const unique_ptr& y); template bool operator!=(const unique_ptr& x, const unique_ptr& y); template bool operator<(const unique_ptr& x, const unique_ptr& y); template bool operator<=(const unique_ptr& x, const unique_ptr& y); template bool operator>(const unique_ptr& x, const unique_ptr& y); template bool operator>=(const unique_ptr& x, const unique_ptr& y); template bool operator==(const unique_ptr& x, nullptr_t) noexcept; template bool operator==(nullptr_t, const unique_ptr& y) noexcept; template bool operator!=(const unique_ptr& x, nullptr_t) noexcept; template bool operator!=(nullptr_t, const unique_ptr& y) noexcept; template bool operator<(const unique_ptr& x, nullptr_t); template bool operator<(nullptr_t, const unique_ptr& y); template bool operator<=(const unique_ptr& x, nullptr_t); template bool operator<=(nullptr_t, const unique_ptr& y); template bool operator>(const unique_ptr& x, nullptr_t); template bool operator>(nullptr_t, const unique_ptr& y); template bool operator>=(const unique_ptr& x, nullptr_t); template bool operator>=(nullptr_t, const unique_ptr& y); class bad_weak_ptr : public std::exception { bad_weak_ptr() noexcept; }; template unique_ptr make_unique(Args&&... args); // C++14 template unique_ptr make_unique(size_t n); // C++14 template unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] +template + basic_ostream& operator<< (basic_ostream& os, unique_ptr const& p); + template class shared_ptr { public: typedef T element_type; typedef weak_ptr weak_type; // C++17 // constructors: constexpr shared_ptr() noexcept; template explicit shared_ptr(Y* p); template shared_ptr(Y* p, D d); template shared_ptr(Y* p, D d, A a); template shared_ptr(nullptr_t p, D d); template shared_ptr(nullptr_t p, D d, A a); template shared_ptr(const shared_ptr& r, T *p) noexcept; shared_ptr(const shared_ptr& r) noexcept; template shared_ptr(const shared_ptr& r) noexcept; shared_ptr(shared_ptr&& r) noexcept; template shared_ptr(shared_ptr&& r) noexcept; template explicit shared_ptr(const weak_ptr& r); template shared_ptr(auto_ptr&& r); // removed in C++17 template shared_ptr(unique_ptr&& r); shared_ptr(nullptr_t) : shared_ptr() { } // destructor: ~shared_ptr(); // assignment: shared_ptr& operator=(const shared_ptr& r) noexcept; template shared_ptr& operator=(const shared_ptr& r) noexcept; shared_ptr& operator=(shared_ptr&& r) noexcept; template shared_ptr& operator=(shared_ptr&& r); template shared_ptr& operator=(auto_ptr&& r); // removed in C++17 template shared_ptr& operator=(unique_ptr&& r); // modifiers: void swap(shared_ptr& r) noexcept; void reset() noexcept; template void reset(Y* p); template void reset(Y* p, D d); template void reset(Y* p, D d, A a); // observers: T* get() const noexcept; T& operator*() const noexcept; T* operator->() const noexcept; long use_count() const noexcept; bool unique() const noexcept; explicit operator bool() const noexcept; template bool owner_before(shared_ptr const& b) const noexcept; template bool owner_before(weak_ptr const& b) const noexcept; }; // shared_ptr comparisons: template bool operator==(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator!=(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator<(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator>(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator<=(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator>=(shared_ptr const& a, shared_ptr const& b) noexcept; template bool operator==(const shared_ptr& x, nullptr_t) noexcept; template bool operator==(nullptr_t, const shared_ptr& y) noexcept; template bool operator!=(const shared_ptr& x, nullptr_t) noexcept; template bool operator!=(nullptr_t, const shared_ptr& y) noexcept; template bool operator<(const shared_ptr& x, nullptr_t) noexcept; template bool operator<(nullptr_t, const shared_ptr& y) noexcept; template bool operator<=(const shared_ptr& x, nullptr_t) noexcept; template bool operator<=(nullptr_t, const shared_ptr& y) noexcept; template bool operator>(const shared_ptr& x, nullptr_t) noexcept; template bool operator>(nullptr_t, const shared_ptr& y) noexcept; template bool operator>=(const shared_ptr& x, nullptr_t) noexcept; template bool operator>=(nullptr_t, const shared_ptr& y) noexcept; // shared_ptr specialized algorithms: template void swap(shared_ptr& a, shared_ptr& b) noexcept; // shared_ptr casts: template shared_ptr static_pointer_cast(shared_ptr const& r) noexcept; template shared_ptr dynamic_pointer_cast(shared_ptr const& r) noexcept; template shared_ptr const_pointer_cast(shared_ptr const& r) noexcept; // shared_ptr I/O: template basic_ostream& operator<< (basic_ostream& os, shared_ptr const& p); // shared_ptr get_deleter: template D* get_deleter(shared_ptr const& p) noexcept; template shared_ptr make_shared(Args&&... args); template shared_ptr allocate_shared(const A& a, Args&&... args); template class weak_ptr { public: typedef T element_type; // constructors constexpr weak_ptr() noexcept; template weak_ptr(shared_ptr const& r) noexcept; weak_ptr(weak_ptr const& r) noexcept; template weak_ptr(weak_ptr const& r) noexcept; weak_ptr(weak_ptr&& r) noexcept; // C++14 template weak_ptr(weak_ptr&& r) noexcept; // C++14 // destructor ~weak_ptr(); // assignment weak_ptr& operator=(weak_ptr const& r) noexcept; template weak_ptr& operator=(weak_ptr const& r) noexcept; template weak_ptr& operator=(shared_ptr const& r) noexcept; weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 template weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 // modifiers void swap(weak_ptr& r) noexcept; void reset() noexcept; // observers long use_count() const noexcept; bool expired() const noexcept; shared_ptr lock() const noexcept; template bool owner_before(shared_ptr const& b) const noexcept; template bool owner_before(weak_ptr const& b) const noexcept; }; // weak_ptr specialized algorithms: template void swap(weak_ptr& a, weak_ptr& b) noexcept; // class owner_less: template struct owner_less; template struct owner_less> : binary_function, shared_ptr, bool> { typedef bool result_type; bool operator()(shared_ptr const&, shared_ptr const&) const noexcept; bool operator()(shared_ptr const&, weak_ptr const&) const noexcept; bool operator()(weak_ptr const&, shared_ptr const&) const noexcept; }; template struct owner_less> : binary_function, weak_ptr, bool> { typedef bool result_type; bool operator()(weak_ptr const&, weak_ptr const&) const noexcept; bool operator()(shared_ptr const&, weak_ptr const&) const noexcept; bool operator()(weak_ptr const&, shared_ptr const&) const noexcept; }; template <> // Added in C++14 struct owner_less { template bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; template bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; template bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; template bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; typedef void is_transparent; }; template class enable_shared_from_this { protected: constexpr enable_shared_from_this() noexcept; enable_shared_from_this(enable_shared_from_this const&) noexcept; enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; ~enable_shared_from_this(); public: shared_ptr shared_from_this(); shared_ptr shared_from_this() const; }; template bool atomic_is_lock_free(const shared_ptr* p); template shared_ptr atomic_load(const shared_ptr* p); template shared_ptr atomic_load_explicit(const shared_ptr* p, memory_order mo); template void atomic_store(shared_ptr* p, shared_ptr r); template void atomic_store_explicit(shared_ptr* p, shared_ptr r, memory_order mo); template shared_ptr atomic_exchange(shared_ptr* p, shared_ptr r); template shared_ptr atomic_exchange_explicit(shared_ptr* p, shared_ptr r, memory_order mo); template bool atomic_compare_exchange_weak(shared_ptr* p, shared_ptr* v, shared_ptr w); template bool atomic_compare_exchange_strong( shared_ptr* p, shared_ptr* v, shared_ptr w); template bool atomic_compare_exchange_weak_explicit(shared_ptr* p, shared_ptr* v, shared_ptr w, memory_order success, memory_order failure); template bool atomic_compare_exchange_strong_explicit(shared_ptr* p, shared_ptr* v, shared_ptr w, memory_order success, memory_order failure); // Hash support template struct hash; template struct hash >; template struct hash >; // Pointer safety enum class pointer_safety { relaxed, preferred, strict }; void declare_reachable(void *p); template T *undeclare_reachable(T *p); void declare_no_pointers(char *p, size_t n); void undeclare_no_pointers(char *p, size_t n); pointer_safety get_pointer_safety() noexcept; void* align(size_t alignment, size_t size, void*& ptr, size_t& space); } // std */ #include <__config> #include #include #include #include #include #include #include #include #include <__functional_base> #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) # include #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD template inline _LIBCPP_ALWAYS_INLINE _ValueType __libcpp_relaxed_load(_ValueType const* __value) { #if !defined(_LIBCPP_HAS_NO_THREADS) && \ defined(__ATOMIC_RELAXED) && \ (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) return __atomic_load_n(__value, __ATOMIC_RELAXED); #else return *__value; #endif } template inline _LIBCPP_ALWAYS_INLINE _ValueType __libcpp_acquire_load(_ValueType const* __value) { #if !defined(_LIBCPP_HAS_NO_THREADS) && \ defined(__ATOMIC_ACQUIRE) && \ (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) return __atomic_load_n(__value, __ATOMIC_ACQUIRE); #else return *__value; #endif } // addressof moved to template class allocator; template <> class _LIBCPP_TEMPLATE_VIS allocator { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind {typedef allocator<_Up> other;}; }; template <> class _LIBCPP_TEMPLATE_VIS allocator { public: typedef const void* pointer; typedef const void* const_pointer; typedef const void value_type; template struct rebind {typedef allocator<_Up> other;}; }; // pointer_traits template struct __has_element_type : false_type {}; template -struct __has_element_type<_Tp, +struct __has_element_type<_Tp, typename __void_t::type> : true_type {}; template ::value> struct __pointer_traits_element_type; template struct __pointer_traits_element_type<_Ptr, true> { typedef typename _Ptr::element_type type; }; #ifndef _LIBCPP_HAS_NO_VARIADICS template