Revert "Update aosp/master libcxx rebase to r263688"

The world is burning.

This reverts commit c004fd909c006eec55077c52ee119e1fa338c9e9, reversing
changes made to 1418e4163da4bb0b9e3fe496e51c23a0dce399d9.
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index d3dcc52..95206bf 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,12 +1,10 @@
 if (NOT LIBCXX_INSTALL_SUPPORT_HEADERS)
   set(LIBCXX_SUPPORT_HEADER_PATTERN PATTERN "support" EXCLUDE)
 endif()
-
 set(LIBCXX_HEADER_PATTERN
   PATTERN "*"
   PATTERN "CMakeLists.txt" EXCLUDE
   PATTERN ".svn" EXCLUDE
-  PATTERN "__config_site.in" EXCLUDE
   ${LIBCXX_SUPPORT_HEADER_PATTERN}
   )
 
@@ -19,44 +17,8 @@
 if (LIBCXX_INSTALL_HEADERS)
   install(DIRECTORY .
     DESTINATION include/c++/v1
-    COMPONENT libcxx-headers
     FILES_MATCHING
     ${LIBCXX_HEADER_PATTERN}
     PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
   )
-
-  if (LIBCXX_NEEDS_SITE_CONFIG)
-    set(UNIX_CAT cat)
-    if (WIN32)
-      set(UNIX_CAT type)
-    endif()
-    # Generate and install a custom __config header. The new header is created
-    # by  prepending __config_site to the current __config header.
-    add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config
-      COMMAND ${CMAKE_COMMAND} -E copy ${LIBCXX_BINARY_DIR}/__config_site ${LIBCXX_BINARY_DIR}/__generated_config
-      COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> ${LIBCXX_BINARY_DIR}/__generated_config
-      DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config
-              ${LIBCXX_BINARY_DIR}/__config_site
-    )
-    # Add a target that executes the generation commands.
-    add_custom_target(generate_config_header ALL
-      DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config)
-    # Install the generated header as __config.
-    install(FILES ${LIBCXX_BINARY_DIR}/__generated_config
-      DESTINATION include/c++/v1
-      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
-      RENAME __config
-      COMPONENT libcxx-headers)
-  endif()
-
-  if (NOT CMAKE_CONFIGURATION_TYPES)
-    # this target is just needed as a placeholder for the distribution target
-    add_custom_target(libcxx-headers)
-    add_custom_target(install-libcxx-headers
-                      DEPENDS libcxx-headers
-                      COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=libcxx-headers
-                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
-  endif()
-
 endif()
diff --git a/include/__bsd_locale_defaults.h b/include/__bsd_locale_defaults.h
deleted file mode 100644
index f315ca2..0000000
--- a/include/__bsd_locale_defaults.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// -*- C++ -*-
-//===---------------------- __bsd_locale_defaults.h -----------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// The BSDs have lots of *_l functions.  We don't want to define those symbols
-// on other platforms though, for fear of conflicts with user code.  So here,
-// we will define the mapping from an internal macro to the real BSD symbol.
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_BSD_LOCALE_DEFAULTS_H
-#define _LIBCPP_BSD_LOCALE_DEFAULTS_H
-
-#define __libcpp_mb_cur_max_l(loc)                          MB_CUR_MAX_L(loc)
-#define __libcpp_btowc_l(ch, loc)                           btowc_l(ch, loc)
-#define __libcpp_wctob_l(wch, loc)                          wctob_l(wch, loc)
-#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc)  wcsnrtombs_l(dst, src, nwc, len, ps, loc)
-#define __libcpp_wcrtomb_l(src, wc, ps, loc)                wcrtomb_l(src, wc, ps, loc)
-#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc)  mbsnrtowcs_l(dst, src, nms, len, ps, loc)
-#define __libcpp_mbrtowc_l(pwc, s, n, ps, l)                mbrtowc_l(pwc, s, n, ps, l)
-#define __libcpp_mbtowc_l(pwc, pmb, max, l)                 mbtowc_l(pwc, pmb, max, l)
-#define __libcpp_mbrlen_l(s, n, ps, l)                      mbrlen_l(s, n, ps, l)
-#define __libcpp_localeconv_l(l)                            localeconv_l(l)
-#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l)         mbsrtowcs_l(dest, src, len, ps, l)
-#define __libcpp_snprintf_l(...)                            snprintf_l(__VA_ARGS__)
-#define __libcpp_asprintf_l(...)                            asprintf_l(__VA_ARGS__)
-#define __libcpp_sscanf_l(...)                              sscanf_l(__VA_ARGS__)
-
-#endif // _LIBCPP_BSD_LOCALE_DEFAULTS_H
diff --git a/include/__bsd_locale_fallbacks.h b/include/__bsd_locale_fallbacks.h
deleted file mode 100644
index cbc8ad2..0000000
--- a/include/__bsd_locale_fallbacks.h
+++ /dev/null
@@ -1,138 +0,0 @@
-// -*- C++ -*-
-//===---------------------- __bsd_locale_fallbacks.h ----------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// The BSDs have lots of *_l functions.  This file provides reimplementations
-// of those functions for non-BSD platforms.
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
-#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
-
-#include <stdlib.h>
-#include <memory>
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-typedef _VSTD::remove_pointer<locale_t>::type __use_locale_struct;
-typedef _VSTD::unique_ptr<__use_locale_struct, decltype(&uselocale)> __locale_raii;
-
-inline _LIBCPP_ALWAYS_INLINE
-decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return MB_CUR_MAX;
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-wint_t __libcpp_btowc_l(int __c, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return btowc(__c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_wctob_l(wint_t __c, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return wctob(__c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
-                         size_t __len, mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return wcrtomb(__s, __wc, __ps);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
-                      size_t __len, mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
-                   mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return mbrtowc(__pwc, __s, __n, __ps);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return mbtowc(__pwc, __pmb, __max);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return mbrlen(__s, __n, __ps);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-lconv *__libcpp_localeconv_l(locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return localeconv();
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
-                     mbstate_t *__ps, locale_t __l)
-{
-    __locale_raii __current( uselocale(__l), uselocale );
-    return mbsrtowcs(__dest, __src, __len, __ps);
-}
-
-inline
-int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
-    va_list __va;
-    va_start(__va, __format);
-    __locale_raii __current( uselocale(__l), uselocale );
-    int __res = vsnprintf(__s, __n, __format, __va);
-    va_end(__va);
-    return __res;
-}
-
-inline
-int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
-    va_list __va;
-    va_start(__va, __format);
-    __locale_raii __current( uselocale(__l), uselocale );
-    int __res = vasprintf(__s, __format, __va);
-    va_end(__va);
-    return __res;
-}
-
-inline
-int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
-    va_list __va;
-    va_start(__va, __format);
-    __locale_raii __current( uselocale(__l), uselocale );
-    int __res = vsscanf(__s, __format, __va);
-    va_end(__va);
-    return __res;
-}
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
diff --git a/include/__config b/include/__config
index f64cce3..e001215 100644
--- a/include/__config
+++ b/include/__config
@@ -11,39 +11,19 @@
 #ifndef _LIBCPP_CONFIG
 #define _LIBCPP_CONFIG
 
-#if defined(_MSC_VER) && !defined(__clang__)
-#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
-#endif
-
-#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
+#if !defined(_MSC_VER) || defined(__clang__)
 #pragma GCC system_header
 #endif
 
-#ifdef __cplusplus
-
 #ifdef __GNUC__
 #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
 #else
 #define _GNUC_VER 0
 #endif
 
-#define _LIBCPP_VERSION 3900
+#define _LIBCPP_VERSION 3800
 
-#ifndef _LIBCPP_ABI_VERSION
 #define _LIBCPP_ABI_VERSION 1
-#endif
-
-#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
-// Change short string represention so that string data starts at offset 0,
-// improving its alignment in some cases.
-#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
-// Fix deque iterator type in order to support incomplete types.
-#define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
-// Fix undefined behavior in how std::list stores it's linked nodes.
-#define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
-#define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
-#define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
-#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)
@@ -57,9 +37,6 @@
 #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
@@ -84,16 +61,6 @@
 #endif  // __BIG_ENDIAN__
 #endif  // __BIG_ENDIAN__
 
-#ifdef __BYTE_ORDER__
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 1
-#define _LIBCPP_BIG_ENDIAN 0
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 0
-#define _LIBCPP_BIG_ENDIAN 1
-#endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#endif // __BYTE_ORDER__
-
 #ifdef __FreeBSD__
 # include <sys/endian.h>
 #  if _BYTE_ORDER == _LITTLE_ENDIAN
@@ -180,12 +147,6 @@
 # endif
 #endif  // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
 
-#if __has_attribute(__no_sanitize__)
-#define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
-#else
-#define _LIBCPP_NO_CFI
-#endif
-
 #ifdef _WIN32
 
 // only really useful for a DLL
@@ -244,12 +205,6 @@
 #  endif
 #endif
 
-#ifndef _LIBCPP_PREFERRED_OVERLOAD
-#  if __has_attribute(__enable_if__)
-#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
-#  endif
-#endif
-
 #ifndef _LIBCPP_TYPE_VIS_ONLY
 # define _LIBCPP_TYPE_VIS_ONLY _LIBCPP_TYPE_VIS
 #endif
@@ -272,12 +227,9 @@
 
 #if defined(__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__)) ||                                                     \
-    defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
-#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&        \
+    !defined(__arm__)
+#define _LIBCPP_ALTERNATE_STRING_LAYOUT
 #endif
 
 #if __has_feature(cxx_alignas)
@@ -297,7 +249,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
+#if !(__has_feature(cxx_exceptions))
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
@@ -319,9 +271,7 @@
 #  define _LIBCPP_NORETURN __attribute__ ((noreturn))
 #endif
 
-#if !(__has_feature(cxx_default_function_template_args))
-#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
-#endif
+#define _LIBCPP_UNUSED __attribute__((__unused__))
 
 #if !(__has_feature(cxx_defaulted_functions))
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -404,23 +354,24 @@
 #elif defined(__ANDROID__)
 #define _LIBCPP_HAS_QUICK_EXIT
 #elif defined(__linux__)
-#if !defined(_LIBCPP_HAS_MUSL_LIBC)
-# include <features.h>
+#include <features.h>
 #if __GLIBC_PREREQ(2, 15)
 #define _LIBCPP_HAS_QUICK_EXIT
 #endif
 #if __GLIBC_PREREQ(2, 17)
 #define _LIBCPP_HAS_C11_FEATURES
 #endif
-#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
+#if (__has_feature(cxx_noexcept))
+#  define _NOEXCEPT noexcept
+#  define _NOEXCEPT_(x) noexcept(x)
+#  define _NOEXCEPT_OR_FALSE(x) noexcept(x)
+#else
+#  define _NOEXCEPT throw()
+#  define _NOEXCEPT_(x)
+#  define _NOEXCEPT_OR_FALSE(x) false
 #endif
 
 #if __has_feature(underlying_type)
@@ -445,11 +396,6 @@
 #define _LIBCPP_HAS_NO_ASAN
 #endif
 
-// Allow for build-time disabling of unsigned integer sanitization
-#if !defined(_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize)
-#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
-#endif 
-
 #elif defined(__GNUC__)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
@@ -457,6 +403,8 @@
 
 #define _LIBCPP_NORETURN __attribute__((noreturn))
 
+#define _LIBCPP_UNUSED __attribute__((__unused__))
+
 #if _GNUC_VER >= 407
 #define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T)
 #define _LIBCPP_IS_LITERAL(T) __is_literal_type(T)
@@ -471,6 +419,8 @@
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
+#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+
 // constexpr was added to GCC in 4.6.
 #if _GNUC_VER < 406
 #define _LIBCPP_HAS_NO_CONSTEXPR
@@ -479,21 +429,19 @@
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #endif
 
-// Determine if GCC supports relaxed constexpr
-#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L
+// No version of GCC supports relaxed constexpr rules
 #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
+
+#define _NOEXCEPT throw()
+#define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
 
 #ifndef __GXX_EXPERIMENTAL_CXX0X__
 
 #define _LIBCPP_HAS_NO_ADVANCED_SFINAE
 #define _LIBCPP_HAS_NO_DECLTYPE
-#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define _LIBCPP_HAS_NO_NULLPTR
@@ -501,32 +449,32 @@
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_VARIADICS
 #define _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
 #define _LIBCPP_HAS_NO_STRONG_ENUMS
-#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-#define _LIBCPP_HAS_NO_NOEXCEPT
 
 #else  // __GXX_EXPERIMENTAL_CXX0X__
 
+#define _LIBCPP_HAS_NO_TRAILING_RETURN
+#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
+
 #if _GNUC_VER < 403
-#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
 #define _LIBCPP_HAS_NO_RVALUE_REFERENCES
-#define _LIBCPP_HAS_NO_STATIC_ASSERT
 #endif
 
+#if _GNUC_VER < 403
+#define _LIBCPP_HAS_NO_STATIC_ASSERT
+#endif
 
 #if _GNUC_VER < 404
 #define _LIBCPP_HAS_NO_DECLTYPE
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
-#define _LIBCPP_HAS_NO_TRAILING_RETURN
 #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
-#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 #endif
 
 #if _GNUC_VER < 407
@@ -553,19 +501,22 @@
 #elif defined(_LIBCPP_MSVC)
 
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-#define _LIBCPP_HAS_NO_NOEXCEPT
 #define __alignof__ __alignof
 #define _LIBCPP_NORETURN __declspec(noreturn)
+#define _LIBCPP_UNUSED
 #define _ALIGNAS(x) __declspec(align(x))
 #define _LIBCPP_HAS_NO_VARIADICS
 
-
+#define _NOEXCEPT throw ()
+#define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
 
 #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {
 #define _LIBCPP_END_NAMESPACE_STD  }
@@ -583,12 +534,16 @@
 #define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
 #define _ATTRIBUTE(x) __attribute__((x))
 #define _LIBCPP_NORETURN __attribute__((noreturn))
+#define _LIBCPP_UNUSED
 
-#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
+#define _NOEXCEPT throw()
+#define _NOEXCEPT_(x)
+#define _NOEXCEPT_OR_FALSE(x) false
+
 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
 #define _LIBCPP_HAS_NO_ADVANCED_SFINAE
+#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
 #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
@@ -612,14 +567,6 @@
 
 #endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__
 
-#ifndef _LIBCPP_HAS_NO_NOEXCEPT
-#  define _NOEXCEPT noexcept
-#  define _NOEXCEPT_(x) noexcept(x)
-#else
-#  define _NOEXCEPT throw()
-#  define _NOEXCEPT_(x)
-#endif
-
 #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
 typedef unsigned short char16_t;
 typedef unsigned int   char32_t;
@@ -631,11 +578,9 @@
 
 #ifdef _LIBCPP_HAS_NO_STATIC_ASSERT
 
-extern "C++" {
 template <bool> struct __static_assert_test;
 template <> struct __static_assert_test<true> {};
 template <unsigned> struct __static_assert_check {};
-}
 #define static_assert(__b, __m) \
     typedef __static_assert_check<sizeof(__static_assert_test<(__b)>)> \
     _LIBCPP_CONCAT(__t, __LINE__)
@@ -663,12 +608,6 @@
 #define _LIBCPP_DEFAULT = default;
 #endif
 
-#ifdef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
-#define _LIBCPP_EQUAL_DELETE
-#else
-#define _LIBCPP_EQUAL_DELETE = delete
-#endif
-
 #ifdef __GNUC__
 #define _NOALIAS __attribute__((__malloc__))
 #else
@@ -726,12 +665,10 @@
 #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(_WIN32) && !defined(__ANDROID__) && !defined(_NEWLIB_VERSION)
+#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(_NEWLIB_VERSION) && \
+    !defined(__CloudABI__)
 #define _LIBCPP_HAS_CATOPEN 1
 #endif
-#endif
 
 #ifdef __FreeBSD__
 #define _DECLARE_C99_LDBL_MATH 1
@@ -779,18 +716,6 @@
 #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
-
-#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
 extern "C" void __sanitizer_annotate_contiguous_container(
   const void *, const void *, const void *, const void *);
@@ -800,7 +725,7 @@
 // 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 && \
+#  if defined(__GNUG__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \
    (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI)
 #    define _LIBCPP_NO_RTTI
 #  elif (defined(_MSC_VER) && !defined(__clang__)) && !defined(_CPPRTTI)
@@ -812,21 +737,6 @@
 #  define _LIBCPP_WEAK __attribute__((__weak__))
 #endif
 
-// Thread API
-#ifndef _LIBCPP_HAS_NO_THREADS
-# if defined(__FreeBSD__) || \
-    defined(__NetBSD__) || \
-    defined(__linux__) || \
-    defined(__APPLE__) || \
-    defined(__CloudABI__) || \
-    defined(__sun__)
-#  define _LIBCPP_THREAD_API_PTHREAD
-# else
-#  error "No thread API"
-# endif // _LIBCPP_THREAD_API
-#endif // _LIBCPP_HAS_NO_THREADS
-
-
 #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.
@@ -847,7 +757,7 @@
 #define _LIBCPP_HAS_NO_STDOUT
 #endif
 
-#if defined(__ANDROID__) || defined(__CloudABI__) || defined(_LIBCPP_HAS_MUSL_LIBC)
+#if defined(__ANDROID__) || defined(__CloudABI__)
 #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
 #endif
 
@@ -857,34 +767,4 @@
 #define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 #endif
 
-#if __has_feature(cxx_atomic) || __has_extension(c_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 __cplusplus < 201103L
-#define _LIBCPP_CXX03_LANG
-#else
-#if defined(_LIBCPP_HAS_NO_VARIADIC_TEMPLATES) || defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
-#error Libc++ requires a feature complete C++11 compiler in C++11 or greater.
-#endif
-#endif
-
-#if (defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) \
-      && __has_attribute(acquire_capability))
-#define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
-#endif
-
-#endif // __cplusplus
-
-#endif // _LIBCPP_CONFIG
+#endif  // _LIBCPP_CONFIG
diff --git a/include/__config_site.in b/include/__config_site.in
deleted file mode 100644
index ec64485..0000000
--- a/include/__config_site.in
+++ /dev/null
@@ -1,23 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-//                     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_SITE
-#define _LIBCPP_CONFIG_SITE
-
-#cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@
-#cmakedefine _LIBCPP_ABI_UNSTABLE
-#cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
-#cmakedefine _LIBCPP_HAS_NO_STDIN
-#cmakedefine _LIBCPP_HAS_NO_STDOUT
-#cmakedefine _LIBCPP_HAS_NO_THREADS
-#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
-#cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
-#cmakedefine _LIBCPP_HAS_MUSL_LIBC
-
-#endif // _LIBCPP_CONFIG_SITE
diff --git a/include/__functional_03 b/include/__functional_03
index 4edbb09..56a8475 100644
--- a/include/__functional_03
+++ b/include/__functional_03
@@ -451,6 +451,15 @@
     aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
+    template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const _Fp&) {return true;}
+    template <class _R2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)()) {return __p;}
+    template <class _R2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2()>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -549,7 +558,7 @@
                                      typename enable_if<!is_integral<_Fp>::value>::type*)
     : __f_(0)
 {
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -576,7 +585,7 @@
     : __f_(0)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -727,6 +736,27 @@
     aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
+    template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const _Fp&) {return true;}
+    template <class _R2, class _B0>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)(_B0)) {return __p;}
+    template <class _R2, class _Cp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)()) {return __p;}
+    template <class _R2, class _Cp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;}
+    template <class _R2, class _Cp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;}
+    template <class _R2, class _Cp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;}
+    template <class _R2, class _B0>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2(_B0)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -825,7 +855,7 @@
                                      typename enable_if<!is_integral<_Fp>::value>::type*)
     : __f_(0)
 {
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -852,7 +882,7 @@
     : __f_(0)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -1003,6 +1033,27 @@
     aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
+    template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const _Fp&) {return true;}
+    template <class _R2, class _B0, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;}
+    template <class _R2, class _Cp, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;}
+    template <class _R2, class _Cp, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;}
+    template <class _R2, class _Cp, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;}
+    template <class _R2, class _Cp, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;}
+    template <class _R2, class _B0, class _B1>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -1101,7 +1152,7 @@
                                  typename enable_if<!is_integral<_Fp>::value>::type*)
     : __f_(0)
 {
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -1128,7 +1179,7 @@
     : __f_(0)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -1278,6 +1329,27 @@
     aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
+    template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const _Fp&) {return true;}
+    template <class _R2, class _B0, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;}
+    template <class _R2, class _Cp, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;}
+    template <class _R2, class _Cp, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const) {return __p;}
+    template <class _R2, class _Cp, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) volatile) {return __p;}
+    template <class _R2, class _Cp, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;}
+    template <class _R2, class _B0, class _B1, class _B2>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2(_B0, _B1, _B2)>& __p) {return __p;}
 public:
     typedef _Rp result_type;
 
@@ -1377,7 +1449,7 @@
                                      typename enable_if<!is_integral<_Fp>::value>::type*)
     : __f_(0)
 {
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
@@ -1404,7 +1476,7 @@
     : __f_(0)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_))
diff --git a/include/__functional_base b/include/__functional_base
index 1a08ea2..3ff2e35 100644
--- a/include/__functional_base
+++ b/include/__functional_base
@@ -38,6 +38,8 @@
     typedef _Result result_type;
 };
 
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
+
 template <class _Tp>
 struct __has_result_type
 {
@@ -75,6 +77,57 @@
 };
 #endif
 
+// addressof
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+addressof(_Tp& __x) _NOEXCEPT
+{
+    return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
+}
+
+#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
+// Objective-C++ Automatic Reference Counting uses qualified pointers
+// that require special addressof() signatures. When
+// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
+// itself is providing these definitions. Otherwise, we provide them.
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__strong _Tp*
+addressof(__strong _Tp& __x) _NOEXCEPT
+{
+  return &__x;
+}
+
+#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__weak _Tp*
+addressof(__weak _Tp& __x) _NOEXCEPT
+{
+  return &__x;
+}
+#endif
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__autoreleasing _Tp*
+addressof(__autoreleasing _Tp& __x) _NOEXCEPT
+{
+  return &__x;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__unsafe_unretained _Tp*
+addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
+{
+  return &__x;
+}
+#endif
+
+
 // __weak_result_type
 
 template <class _Tp>
@@ -304,19 +357,75 @@
 
 #endif // _LIBCPP_HAS_NO_VARIADICS
 
-#ifndef _LIBCPP_CXX03_LANG
+// __invoke
 
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+// bullets 1 and 2
+
+template <class _Fp, class _A0, class ..._Args,
+            class>
+inline _LIBCPP_INLINE_VISIBILITY
+auto
+__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
+    -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
+{
+    return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
+}
+
+template <class _Fp, class _A0, class ..._Args,
+            class>
+inline _LIBCPP_INLINE_VISIBILITY
+auto
+__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
+    -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
+{
+    return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
+}
+
+// bullets 3 and 4
+
+template <class _Fp, class _A0,
+            class>
+inline _LIBCPP_INLINE_VISIBILITY
+auto
+__invoke(_Fp&& __f, _A0&& __a0)
+    -> decltype(_VSTD::forward<_A0>(__a0).*__f)
+{
+    return _VSTD::forward<_A0>(__a0).*__f;
+}
+
+template <class _Fp, class _A0,
+            class>
+inline _LIBCPP_INLINE_VISIBILITY
+auto
+__invoke(_Fp&& __f, _A0&& __a0)
+    -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
+{
+    return (*_VSTD::forward<_A0>(__a0)).*__f;
+}
+
+// bullet 5
+
+template <class _Fp, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+auto
+__invoke(_Fp&& __f, _Args&& ...__args)
+    -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
+{
+    return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
+}
 template <class _Tp, class ..._Args>
 struct __invoke_return
 {
     typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
 };
 
-#else // defined(_LIBCPP_CXX03_LANG)
+#else // _LIBCPP_HAS_NO_VARIADICS
 
 #include <__functional_base_03>
 
-#endif  // !defined(_LIBCPP_CXX03_LANG)
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
 
 template <class _Ret>
@@ -406,119 +515,51 @@
 #ifndef _LIBCPP_HAS_NO_VARIADICS
     // invoke
     template <class... _ArgTypes>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_of<type&, _ArgTypes...>::type
-    operator() (_ArgTypes&&... __args) const {
-        return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
-    }
+       _LIBCPP_INLINE_VISIBILITY
+       typename __invoke_of<type&, _ArgTypes...>::type
+          operator() (_ArgTypes&&... __args) const
+          {
+              return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
+          }
 #else
 
     _LIBCPP_INLINE_VISIBILITY
     typename __invoke_return<type>::type
-    operator() () const {
-        return __invoke(get());
-    }
+       operator() () const
+       {
+           return __invoke(get());
+       }
 
     template <class _A0>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return0<type, _A0>::type
-    operator() (_A0& __a0) const {
-        return __invoke(get(), __a0);
-    }
-
-    template <class _A0>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return0<type, _A0 const>::type
-    operator() (_A0 const& __a0) const {
-        return __invoke(get(), __a0);
-    }
+       _LIBCPP_INLINE_VISIBILITY
+       typename __invoke_return0<type&, _A0>::type
+          operator() (_A0& __a0) const
+          {
+              return __invoke<type&, _A0>(get(), __a0);
+          }
 
     template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0, _A1>::type
-    operator() (_A0& __a0, _A1& __a1) const {
-        return __invoke(get(), __a0, __a1);
-    }
-
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0 const, _A1>::type
-    operator() (_A0 const& __a0, _A1& __a1) const {
-        return __invoke(get(), __a0, __a1);
-    }
-
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0, _A1 const>::type
-    operator() (_A0& __a0, _A1 const& __a1) const {
-        return __invoke(get(), __a0, __a1);
-    }
-
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0 const, _A1 const>::type
-    operator() (_A0 const& __a0, _A1 const& __a1) const {
-        return __invoke(get(), __a0, __a1);
-    }
+       _LIBCPP_INLINE_VISIBILITY
+       typename __invoke_return1<type&, _A0, _A1>::type
+          operator() (_A0& __a0, _A1& __a1) const
+          {
+              return __invoke<type&, _A0, _A1>(get(), __a0, __a1);
+          }
 
     template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1, _A2>::type
-    operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1, _A2>::type
-    operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1 const, _A2>::type
-    operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1, _A2 const>::type
-    operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
-    operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
-    operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
-    operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
-    operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
-        return __invoke(get(), __a0, __a1, __a2);
-    }
+       _LIBCPP_INLINE_VISIBILITY
+       typename __invoke_return2<type&, _A0, _A1, _A2>::type
+          operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
+          {
+              return __invoke<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2);
+          }
 #endif // _LIBCPP_HAS_NO_VARIADICS
 };
 
+template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
+template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
+template <class _Tp> struct __is_reference_wrapper
+    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
diff --git a/include/__functional_base_03 b/include/__functional_base_03
index 8407dcf..0a7ff62 100644
--- a/include/__functional_base_03
+++ b/include/__functional_base_03
@@ -14,128 +14,431 @@
 // manual variadic expansion for <functional>
 
 // __invoke
-
-template <class _Ret, class _T1, bool _IsFunc, bool _IsBase>
-struct __enable_invoke_imp;
-
-template <class _Ret, class _T1>
-struct __enable_invoke_imp<_Ret, _T1, true, true> {
-    typedef _Ret _Bullet1;
-    typedef _Bullet1 type;
-};
-
-template <class _Ret, class _T1>
-struct __enable_invoke_imp<_Ret, _T1, true, false>  {
-    typedef _Ret _Bullet2;
-    typedef _Bullet2 type;
-};
-
-template <class _Ret, class _T1>
-struct __enable_invoke_imp<_Ret, _T1, false, true>  {
-    typedef typename add_lvalue_reference<
-                typename __apply_cv<_T1, _Ret>::type
-            >::type _Bullet3;
-    typedef _Bullet3 type;
-};
-
-template <class _Ret, class _T1>
-struct __enable_invoke_imp<_Ret, _T1, false, false>  {
-    typedef typename add_lvalue_reference<
-                typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Ret>::type
-            >::type _Bullet4;
-    typedef _Bullet4 type;
-};
-
-template <class _Ret, class _T1>
-struct __enable_invoke_imp<_Ret, _T1*, false, false>  {
-    typedef typename add_lvalue_reference<
-                typename __apply_cv<_T1, _Ret>::type
-            >::type _Bullet4;
-    typedef _Bullet4  type;
-};
-
-template <class _Fn, class _T1,
-          class _Traits = __member_pointer_traits<_Fn>,
-          class _Ret = typename _Traits::_ReturnType,
-          class _Class = typename _Traits::_ClassType>
-struct __enable_invoke : __enable_invoke_imp<
-    _Ret, _T1,
-    is_member_function_pointer<_Fn>::value,
-    is_base_of<_Class, typename remove_reference<_T1>::type>::value>
-{
-};
-
-__nat __invoke(__any, ...);
-
 // first bullet
 
-template <class _Fn, class _T1>
+template <class _Rp, class _Tp, class _T1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet1
-__invoke(_Fn __f, _T1& __t1) {
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(), _T1& __t1)
+{
     return (__t1.*__f)();
 }
 
-template <class _Fn, class _T1, class _A0>
+template <class _Rp, class _Tp, class _T1, class _A0>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet1
-__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0), _T1& __t1, _A0& __a0)
+{
     return (__t1.*__f)(__a0);
 }
 
-template <class _Fn, class _T1, class _A0, class _A1>
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet1
-__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1)
+{
     return (__t1.*__f)(__a0, __a1);
 }
 
-template <class _Fn, class _T1, class _A0, class _A1, class _A2>
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet1
-__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
     return (__t1.*__f)(__a0, __a1, __a2);
 }
 
-template <class _Fn, class _T1>
+template <class _Rp, class _Tp, class _T1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet2
-__invoke(_Fn __f, _T1& __t1) {
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() const, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) const, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() volatile, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() const volatile, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+// second bullet
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(), _T1 __t1)
+{
     return ((*__t1).*__f)();
 }
 
-template <class _Fn, class _T1, class _A0>
+template <class _Rp, class _Tp, class _T1, class _A0>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet2
-__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0), _T1 __t1, _A0& __a0)
+{
     return ((*__t1).*__f)(__a0);
 }
 
-template <class _Fn, class _T1, class _A0, class _A1>
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet2
-__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1)
+{
     return ((*__t1).*__f)(__a0, __a1);
 }
 
-template <class _Fn, class _T1, class _A0, class _A1, class _A2>
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet2
-__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
     return ((*__t1).*__f)(__a0, __a1, __a2);
 }
 
-template <class _Fn, class _T1>
+template <class _Rp, class _Tp, class _T1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet3
-__invoke(_Fn __f, _T1& __t1) {
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() const, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) const, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() volatile, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)() const volatile, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    _Rp
+>::type
+__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+// third bullet
+
+template <class _Rp, class _Tp, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_member_object_pointer<_Rp _Tp::*>::value &&
+    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+   __apply_cv<_T1, _Rp>
+>::type::type&
+__invoke(_Rp _Tp::* __f, _T1& __t1)
+{
     return __t1.*__f;
 }
 
-template <class _Fn, class _T1>
+
+// forth bullet
+
+template <class _T1, class _Rp, bool>
+struct __4th_helper
+{
+};
+
+template <class _T1, class _Rp>
+struct __4th_helper<_T1, _Rp, true>
+{
+    typedef typename __apply_cv<decltype(*_VSTD::declval<_T1&>()), _Rp>::type type;
+};
+
+template <class _Rp, class _Tp, class _T1>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __enable_invoke<_Fn, _T1>::_Bullet4
-__invoke(_Fn __f, _T1& __t1) {
+typename __4th_helper<_T1, _Rp,
+    is_member_object_pointer<_Rp _Tp::*>::value &&
+    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value
+>::type&
+__invoke(_Rp _Tp::* __f, _T1& __t1)
+{
     return (*__t1).*__f;
 }
 
@@ -185,28 +488,29 @@
     typedef decltype(__invoke(_VSTD::declval<_Fp&>())) type;
 };
 
-template <class _Tp, class _A0>
+template <class _Tp, class _A0, bool = is_member_object_pointer<_Tp>::value>
 struct __invoke_return0
 {
     typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>())) type;
 };
 
 template <class _Rp, class _Tp, class _A0>
-struct __invoke_return0<_Rp _Tp::*, _A0>
+struct __invoke_return0<_Rp _Tp::*, _A0, true>
 {
-    typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type;
+    typedef typename __apply_cv<_A0, _Rp>::type& type;
+};
+
+template <class _Rp, class _Tp, class _A0>
+struct __invoke_return0<_Rp _Tp::*, _A0*, true>
+{
+    typedef typename __apply_cv<_A0, _Rp>::type& type;
 };
 
 template <class _Tp, class _A0, class _A1>
 struct __invoke_return1
 {
     typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(),
-                                                      _VSTD::declval<_A1&>())) type;
-};
-
-template <class _Rp, class _Class, class _A0, class _A1>
-struct __invoke_return1<_Rp _Class::*, _A0, _A1> {
-    typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type;
+                                                     _VSTD::declval<_A1&>())) type;
 };
 
 template <class _Tp, class _A0, class _A1, class _A2>
@@ -217,8 +521,4 @@
                                                       _VSTD::declval<_A2&>())) type;
 };
 
-template <class _Ret, class _Class, class _A0, class _A1, class _A2>
-struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> {
-    typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type;
-};
 #endif  // _LIBCPP_FUNCTIONAL_BASE_03
diff --git a/include/__hash_table b/include/__hash_table
index 8f6fc4d..dac4cfd 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -17,7 +17,6 @@
 #include <iterator>
 #include <algorithm>
 #include <cmath>
-#include <utility>
 
 #include <__undef_min_max>
 #include <__undef___deallocate>
@@ -30,29 +29,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Key, class _Tp>
-union __hash_value_type;
-#else
-template <class _Key, class _Tp>
-struct __hash_value_type;
-#endif
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp>
-struct __is_hash_value_type_imp : false_type {};
-
-template <class _Key, class _Value>
-struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
-
-template <class ..._Args>
-struct __is_hash_value_type : false_type {};
-
-template <class _One>
-struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
-#endif
-
 _LIBCPP_FUNC_VIS
 size_t __next_prime(size_t __n);
 
@@ -70,13 +46,18 @@
 struct __hash_node
     : public __hash_node_base
              <
-                 typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
+                 typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                     rebind<__hash_node<_Tp, _VoidPtr> >
+#else
+                     rebind<__hash_node<_Tp, _VoidPtr> >::other
+#endif
              >
 {
-    typedef _Tp __node_value_type;
+    typedef _Tp value_type;
 
     size_t     __hash_;
-    __node_value_type __value_;
+    value_type __value_;
 };
 
 inline _LIBCPP_INLINE_VISIBILITY
@@ -100,175 +81,32 @@
     return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
 }
 
-
 template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
-
-template <class _NodePtr>      class _LIBCPP_TYPE_VIS_ONLY __hash_iterator;
 template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
-template <class _NodePtr>      class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator;
-template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
 template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
 template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
     class _LIBCPP_TYPE_VIS_ONLY unordered_map;
 
-template <class _Tp>
-struct __hash_key_value_types {
-  static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
-  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 <class _Key, class _Tp>
-struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
-  typedef _Key                                         key_type;
-  typedef _Tp                                          mapped_type;
-  typedef __hash_value_type<_Key, _Tp>                 __node_value_type;
-  typedef pair<const _Key, _Tp>                        __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(__container_value_type const& __v) {
-    return __v.first;
-  }
-
-  template <class _Up>
-  _LIBCPP_INLINE_VISIBILITY
-  static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
-      __container_value_type const&>::type
-  __get_value(_Up& __t) {
-    return __t.__cc;
-  }
-
-  template <class _Up>
-  _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 <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
-          bool = _KVTypes::__is_map>
-struct __hash_map_pointer_types {};
-
-template <class _Tp, class _AllocPtr, class _KVTypes>
-struct __hash_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 <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
-struct __hash_node_types;
-
-template <class _NodePtr, class _Tp, class _VoidPtr>
-struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
-    : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
-
-{
-  typedef __hash_key_value_types<_Tp>           __base;
-
-public:
-  typedef ptrdiff_t difference_type;
-  typedef size_t size_type;
-
-  typedef typename __rebind_pointer<_NodePtr, void>::type       __void_pointer;
-
-  typedef typename pointer_traits<_NodePtr>::element_type       __node_type;
-  typedef _NodePtr                                              __node_pointer;
-
-  typedef __hash_node_base<__node_pointer>                      __node_base_type;
-  typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
-                                                             __node_base_pointer;
-
-  typedef _Tp                                                 __node_value_type;
-  typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
-                                                      __node_value_type_pointer;
-  typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
-                                                __const_node_value_type_pointer;
-private:
-    static_assert(!is_const<__node_type>::value,
-                "_NodePtr should never be a pointer to const");
-    static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
-                  "_VoidPtr does not point to unqualified void type");
-    static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
-                          _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
-};
-
-
-
-template <class _HashIterator>
-struct __hash_node_types_from_iterator;
-template <class _NodePtr>
-struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
-template <class _NodePtr>
-struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
-template <class _NodePtr>
-struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
-template <class _NodePtr>
-struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
-
-
-template <class _NodeValueTp, class _VoidPtr>
-struct __make_hash_node_types {
-  typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
-  typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
-  typedef __hash_node_types<_NodePtr> type;
-};
-
 template <class _NodePtr>
 class _LIBCPP_TYPE_VIS_ONLY __hash_iterator
 {
-    typedef __hash_node_types<_NodePtr> _NodeTypes;
-    typedef _NodePtr                    __node_pointer;
+    typedef _NodePtr __node_pointer;
 
     __node_pointer            __node_;
 
 public:
-    typedef forward_iterator_tag                           iterator_category;
-    typedef typename _NodeTypes::__node_value_type         value_type;
-    typedef typename _NodeTypes::difference_type           difference_type;
-    typedef value_type&                                    reference;
-    typedef typename _NodeTypes::__node_value_type_pointer pointer;
+    typedef forward_iterator_tag                         iterator_category;
+    typedef typename pointer_traits<__node_pointer>::element_type::value_type value_type;
+    typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
+    typedef value_type&                                  reference;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                     rebind<value_type>
+#else
+                     rebind<value_type>::other
+#endif
+                                                         pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT
 #if _LIBCPP_STD_VER > 11
@@ -377,24 +215,37 @@
     template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
 };
 
-template <class _NodePtr>
+template <class _ConstNodePtr>
 class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator
 {
-    static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
-    typedef __hash_node_types<_NodePtr> _NodeTypes;
-    typedef _NodePtr __node_pointer;
+    typedef _ConstNodePtr __node_pointer;
 
-    __node_pointer __node_;
+    __node_pointer         __node_;
+
+    typedef typename remove_const<
+        typename pointer_traits<__node_pointer>::element_type
+                                 >::type __node;
 
 public:
-    typedef __hash_iterator<_NodePtr> __non_const_iterator;
-
-    typedef forward_iterator_tag                                 iterator_category;
-    typedef typename _NodeTypes::__node_value_type               value_type;
-    typedef typename _NodeTypes::difference_type                 difference_type;
-    typedef const value_type&                                    reference;
-    typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
-
+    typedef forward_iterator_tag                       iterator_category;
+    typedef typename __node::value_type                value_type;
+    typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
+    typedef const value_type&                          reference;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                       pointer;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__node>
+#else
+            rebind<__node>::other
+#endif
+                                                      __non_const_node_pointer;
+    typedef __hash_iterator<__non_const_node_pointer> __non_const_iterator;
 
     _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT
 #if _LIBCPP_STD_VER > 11
@@ -510,22 +361,30 @@
     template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
 };
 
+template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
+
 template <class _NodePtr>
 class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator
 {
-    typedef __hash_node_types<_NodePtr> _NodeTypes;
-    typedef _NodePtr                    __node_pointer;
+    typedef _NodePtr __node_pointer;
 
     __node_pointer         __node_;
     size_t                 __bucket_;
     size_t                 __bucket_count_;
 
+    typedef pointer_traits<__node_pointer>          __pointer_traits;
 public:
     typedef forward_iterator_tag                                iterator_category;
-    typedef typename _NodeTypes::__node_value_type              value_type;
-    typedef typename _NodeTypes::difference_type                difference_type;
+    typedef typename __pointer_traits::element_type::value_type value_type;
+    typedef typename __pointer_traits::difference_type          difference_type;
     typedef value_type&                                         reference;
-    typedef typename _NodeTypes::__node_value_type_pointer      pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT
     {
@@ -648,8 +507,7 @@
 template <class _ConstNodePtr>
 class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator
 {
-    typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
-    typedef _ConstNodePtr                    __node_pointer;
+    typedef _ConstNodePtr __node_pointer;
 
     __node_pointer         __node_;
     size_t                 __bucket_;
@@ -658,18 +516,29 @@
     typedef pointer_traits<__node_pointer>          __pointer_traits;
     typedef typename __pointer_traits::element_type __node;
     typedef typename remove_const<__node>::type     __non_const_node;
-    typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
-        __non_const_node_pointer;
-public:
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__non_const_node>
+#else
+            rebind<__non_const_node>::other
+#endif
+                                                    __non_const_node_pointer;
     typedef __hash_local_iterator<__non_const_node_pointer>
                                                     __non_const_iterator;
-
-    typedef forward_iterator_tag                                 iterator_category;
-    typedef typename _NodeTypes::__node_value_type               value_type;
-    typedef typename _NodeTypes::difference_type                 difference_type;
-    typedef const value_type&                                    reference;
-    typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
-
+public:
+    typedef forward_iterator_tag                       iterator_category;
+    typedef typename remove_const<
+                        typename __pointer_traits::element_type::value_type
+                     >::type                           value_type;
+    typedef typename __pointer_traits::difference_type difference_type;
+    typedef const value_type&                          reference;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                       pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT
     {
@@ -856,11 +725,10 @@
 {
     typedef _Alloc                                          allocator_type;
     typedef allocator_traits<allocator_type>                __alloc_traits;
-
+    typedef typename __alloc_traits::value_type::value_type value_type;
 public:
     typedef typename __alloc_traits::pointer                pointer;
 private:
-    typedef __hash_node_types<pointer> _NodeTypes;
 
     allocator_type& __na_;
 
@@ -880,7 +748,7 @@
     void operator()(pointer __p) _NOEXCEPT
     {
         if (__value_constructed)
-            __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_));
         if (__p)
             __alloc_traits::deallocate(__na_, __p, 1);
     }
@@ -899,47 +767,28 @@
 
 private:
     typedef allocator_traits<allocator_type> __alloc_traits;
-    typedef typename
-      __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
-                                                                     _NodeTypes;
 public:
-
-    typedef typename _NodeTypes::__node_value_type           __node_value_type;
-    typedef typename _NodeTypes::__container_value_type      __container_value_type;
-    typedef typename _NodeTypes::key_type                    key_type;
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
     typedef typename __alloc_traits::pointer         pointer;
     typedef typename __alloc_traits::const_pointer   const_pointer;
-#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
     typedef typename __alloc_traits::size_type       size_type;
-#else
-    typedef typename _NodeTypes::size_type           size_type;
-#endif
-    typedef typename _NodeTypes::difference_type     difference_type;
+    typedef typename __alloc_traits::difference_type difference_type;
 public:
     // Create __node
-
-    typedef typename _NodeTypes::__node_type __node;
+    typedef __hash_node<value_type, typename __alloc_traits::void_pointer> __node;
     typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
     typedef allocator_traits<__node_allocator>       __node_traits;
-    typedef typename _NodeTypes::__void_pointer      __void_pointer;
-    typedef typename _NodeTypes::__node_pointer      __node_pointer;
-    typedef typename _NodeTypes::__node_pointer      __node_const_pointer;
-    typedef typename _NodeTypes::__node_base_type    __first_node;
-    typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
-
-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, __first_node>::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.");
+    typedef typename __node_traits::pointer          __node_pointer;
+    typedef typename __node_traits::pointer          __node_const_pointer;
+    typedef __hash_node_base<__node_pointer>         __first_node;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__first_node>
+#else
+            rebind<__first_node>::other
+#endif
+                                                     __node_base_pointer;
 
 private:
 
@@ -950,10 +799,10 @@
     typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
 
     // --- Member data begin ---
-    __bucket_list                                         __bucket_list_;
-    __compressed_pair<__first_node, __node_allocator>     __p1_;
-    __compressed_pair<size_type, hasher>                  __p2_;
-    __compressed_pair<float, key_equal>                   __p3_;
+    __bucket_list                                     __bucket_list_;
+    __compressed_pair<__first_node, __node_allocator> __p1_;
+    __compressed_pair<size_type, hasher>              __p2_;
+    __compressed_pair<float, key_equal>               __p3_;
     // --- Member data end ---
 
     _LIBCPP_INLINE_VISIBILITY
@@ -989,7 +838,6 @@
     typedef __hash_local_iterator<__node_pointer>             local_iterator;
     typedef __hash_const_local_iterator<__node_pointer>       const_local_iterator;
 
-    _LIBCPP_INLINE_VISIBILITY
     __hash_table()
         _NOEXCEPT_(
             is_nothrow_default_constructible<__bucket_list>::value &&
@@ -997,14 +845,13 @@
             is_nothrow_default_constructible<__node_allocator>::value &&
             is_nothrow_default_constructible<hasher>::value &&
             is_nothrow_default_constructible<key_equal>::value);
-    _LIBCPP_INLINE_VISIBILITY
     __hash_table(const hasher& __hf, const key_equal& __eql);
     __hash_table(const hasher& __hf, const key_equal& __eql,
                  const allocator_type& __a);
     explicit __hash_table(const allocator_type& __a);
     __hash_table(const __hash_table& __u);
     __hash_table(const __hash_table& __u, const allocator_type& __a);
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     __hash_table(__hash_table&& __u)
         _NOEXCEPT_(
             is_nothrow_move_constructible<__bucket_list>::value &&
@@ -1013,12 +860,11 @@
             is_nothrow_move_constructible<hasher>::value &&
             is_nothrow_move_constructible<key_equal>::value);
     __hash_table(__hash_table&& __u, const allocator_type& __a);
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~__hash_table();
 
     __hash_table& operator=(const __hash_table& __u);
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     __hash_table& operator=(__hash_table&& __u)
         _NOEXCEPT_(
             __node_traits::propagate_on_container_move_assignment::value &&
@@ -1043,103 +889,41 @@
     iterator             __node_insert_multi(const_iterator __p,
                                              __node_pointer __nd);
 
-#ifndef _LIBCPP_CXX03_LANG
-    template <class _Key, class ..._Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
-
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
     template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique(_Pp&& __x) {
-      return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
-                                          __can_extract_key<_Pp, key_type>());
-    }
-
-    template <class _First, class _Second>
-    _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<
-        __can_extract_map_key<_First, key_type, __container_value_type>::value,
-        pair<iterator, bool>
-    >::type __emplace_unique(_First&& __f, _Second&& __s) {
-        return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
-                                              _VSTD::forward<_Second>(__s));
-    }
-
+        pair<iterator, bool> __emplace_unique(_Args&&... __args);
     template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique(_Args&&... __args) {
-      return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
-      return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
-    }
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
-      return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
-    }
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
-      return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
-    }
-
+        iterator __emplace_multi(_Args&&... __args);
     template <class... _Args>
+        iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
+#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _ValueTp>
     _LIBCPP_INLINE_VISIBILITY
-    iterator __emplace_multi(_Args&&... __args);
-    template <class... _Args>
+    pair<iterator, bool> __insert_unique_value(_ValueTp&& __x);
+#else
     _LIBCPP_INLINE_VISIBILITY
-    iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
-
-
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __insert_unique(__container_value_type&& __x) {
-      return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
-    }
-
-    template <class _Pp, class = typename enable_if<
-            !__is_same_uncvref<_Pp, __container_value_type>::value
-        >::type>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __insert_unique(_Pp&& __x) {
-      return __emplace_unique(_VSTD::forward<_Pp>(__x));
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __insert_multi(_Pp&& __x) {
-      return __emplace_multi(_VSTD::forward<_Pp>(__x));
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __insert_multi(const_iterator __p, _Pp&& __x) {
-        return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
-    }
-
-#else  // !defined(_LIBCPP_CXX03_LANG)
-    template <class _Key, class _Args>
-    pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
-
-    iterator __insert_multi(const __container_value_type& __x);
-    iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
+    pair<iterator, bool> __insert_unique_value(const value_type& __x);
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
-        return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
-    }
+    pair<iterator, bool> __insert_unique(const value_type& __x);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    pair<iterator, bool> __insert_unique(value_type&& __x);
+    template <class _Pp>
+    pair<iterator, bool> __insert_unique(_Pp&& __x);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _Pp>
+        iterator __insert_multi(_Pp&& __x);
+    template <class _Pp>
+        iterator __insert_multi(const_iterator __p, _Pp&& __x);
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    iterator __insert_multi(const value_type& __x);
+    iterator __insert_multi(const_iterator __p, const value_type& __x);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     void clear() _NOEXCEPT;
     void rehash(size_type __n);
@@ -1152,13 +936,9 @@
         return __bucket_list_.get_deleter().size();
     }
 
-    _LIBCPP_INLINE_VISIBILITY
     iterator       begin() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     iterator       end() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator begin() const _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator end() const _NOEXCEPT;
 
     template <class _Key>
@@ -1187,7 +967,6 @@
     __node_holder remove(const_iterator __p) _NOEXCEPT;
 
     template <class _Key>
-        _LIBCPP_INLINE_VISIBILITY
         size_type __count_unique(const _Key& __k) const;
     template <class _Key>
         size_type __count_multi(const _Key& __k) const;
@@ -1299,17 +1078,16 @@
 private:
     void __rehash(size_type __n);
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class ..._Args>
-    __node_holder __construct_node(_Args&& ...__args);
-
-    template <class _First, class ..._Rest>
-    __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
-#else // _LIBCPP_CXX03_LANG
-    __node_holder __construct_node(const __container_value_type& __v);
-    __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
+        __node_holder __construct_node(_Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+    __node_holder __construct_node(value_type&& __v, size_t __hash);
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node(const value_type& __v);
 #endif
-
+    __node_holder __construct_node(const value_type& __v, size_t __hash);
 
     _LIBCPP_INLINE_VISIBILITY
     void __copy_assign_alloc(const __hash_table& __u)
@@ -1319,7 +1097,6 @@
     _LIBCPP_INLINE_VISIBILITY
         void __copy_assign_alloc(const __hash_table&, false_type) {}
 
-#ifndef _LIBCPP_CXX03_LANG
     void __move_assign(__hash_table& __u, false_type);
     void __move_assign(__hash_table& __u, true_type)
         _NOEXCEPT_(
@@ -1346,7 +1123,6 @@
     }
     _LIBCPP_INLINE_VISIBILITY
         void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
-#endif // _LIBCPP_CXX03_LANG
 
     void __deallocate(__node_pointer __np) _NOEXCEPT;
     __node_pointer __detach() _NOEXCEPT;
@@ -1356,12 +1132,11 @@
 };
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
     _NOEXCEPT_(
         is_nothrow_default_constructible<__bucket_list>::value &&
         is_nothrow_default_constructible<__first_node>::value &&
-        is_nothrow_default_constructible<__node_allocator>::value &&
         is_nothrow_default_constructible<hasher>::value &&
         is_nothrow_default_constructible<key_equal>::value)
     : __p2_(0),
@@ -1370,7 +1145,7 @@
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
                                                        const key_equal& __eql)
     : __bucket_list_(nullptr, __bucket_list_deleter()),
@@ -1423,14 +1198,13 @@
 {
 }
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
         _NOEXCEPT_(
             is_nothrow_move_constructible<__bucket_list>::value &&
             is_nothrow_move_constructible<__first_node>::value &&
-            is_nothrow_move_constructible<__node_allocator>::value &&
             is_nothrow_move_constructible<hasher>::value &&
             is_nothrow_move_constructible<key_equal>::value)
     : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
@@ -1472,7 +1246,7 @@
     }
 }
 
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
@@ -1537,7 +1311,7 @@
         }
         __get_db()->unlock();
 #endif
-        __node_traits::destroy(__na, _NodeTypes::__get_ptr(__np->__value_));
+        __node_traits::destroy(__na, _VSTD::addressof(__np->__value_));
         __node_traits::deallocate(__na, __np, 1);
         __np = __next;
     }
@@ -1556,7 +1330,7 @@
     return __cache;
 }
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 void
@@ -1629,7 +1403,8 @@
         const_iterator __i = __u.begin();
         while (__u.size() != 0)
         {
-            __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
+            __node_holder __h =
+                    __construct_node(_VSTD::move(__u.remove(__i++)->__value_));
             __node_insert_multi(__h.get());
             __h.release();
         }
@@ -1637,7 +1412,7 @@
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __hash_table<_Tp, _Hash, _Equal, _Alloc>&
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
     _NOEXCEPT_(
@@ -1651,7 +1426,7 @@
     return *this;
 }
 
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 template <class _InputIterator>
@@ -1659,11 +1434,6 @@
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__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 (bucket_count() != 0)
     {
         __node_pointer __cache = __detach();
@@ -1698,12 +1468,6 @@
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__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 (bucket_count() != 0)
     {
         __node_pointer __cache = __detach();
@@ -1729,11 +1493,11 @@
         __deallocate(__cache);
     }
     for (; __first != __last; ++__first)
-        __insert_multi(_NodeTypes::__get_value(*__first));
+        __insert_multi(*__first);
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
 {
@@ -1745,7 +1509,7 @@
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
 {
@@ -1757,7 +1521,7 @@
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
 {
@@ -1769,7 +1533,7 @@
 }
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
 {
@@ -1955,24 +1719,31 @@
     return __node_insert_multi(__cp);
 }
 
-
-
-#ifndef _LIBCPP_CXX03_LANG
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-template <class _Key, class ..._Args>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x)
+{
+    return __insert_unique_value(__x);
+}
+
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _ValueTp>
 _LIBCPP_INLINE_VISIBILITY
 pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(_ValueTp&& __x)
 #else
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-template <class _Key, class _Args>
 _LIBCPP_INLINE_VISIBILITY
 pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(const value_type& __x)
 #endif
 {
-
-    size_t __hash = hash_function()(__k);
+#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
+    typedef const value_type& _ValueTp;
+#endif
+    size_t __hash = hash_function()(__x);
     size_type __bc = bucket_count();
     bool __inserted = false;
     __node_pointer __nd;
@@ -1987,17 +1758,13 @@
                                        __constrain_hash(__nd->__hash_, __bc) == __chash;
                                                            __nd = __nd->__next_)
             {
-                if (key_eq()(__nd->__value_, __k))
+                if (key_eq()(__nd->__value_, __x))
                     goto __done;
             }
         }
     }
     {
-#ifndef _LIBCPP_CXX03_LANG
-        __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
-#else
-        __node_holder __h = __construct_node_hash(__hash, __args);
-#endif
+        __node_holder __h = __construct_node(_VSTD::forward<_ValueTp>(__x), __hash);
         if (size()+1 > __bc * max_load_factor() || __bc == 0)
         {
             rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
@@ -2009,7 +1776,7 @@
         __node_pointer __pn = __bucket_list_[__chash];
         if (__pn == nullptr)
         {
-            __pn = static_cast<__node_pointer>(static_cast<__void_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
+            __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
             __h->__next_ = __pn->__next_;
             __pn->__next_ = __h.get();
             // fix up __bucket_list_
@@ -2035,12 +1802,13 @@
 #endif
 }
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 template <class... _Args>
 pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique(_Args&&... __args)
 {
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     pair<iterator, bool> __r = __node_insert_unique(__h.get());
@@ -2077,11 +1845,64 @@
     return __r;
 }
 
-#else // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(value_type&& __x)
+{
+    return __insert_unique_value(_VSTD::move(__x));
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Pp>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(_Pp&& __x)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
+    pair<iterator, bool> __r = __node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Pp>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(_Pp&& __x)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
+    iterator __r = __node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Pp>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
+                                                         _Pp&& __x)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "unordered container::insert(const_iterator, rvalue) called with an iterator not"
+        " referring to this unordered container");
+#endif
+    __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const value_type& __x)
 {
     __node_holder __h = __construct_node(__x);
     iterator __r = __node_insert_multi(__h.get());
@@ -2092,7 +1913,7 @@
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
-                                                         const __container_value_type& __x)
+                                                         const value_type& __x)
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
     _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
@@ -2105,7 +1926,7 @@
     return __r;
 }
 
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 void
@@ -2244,74 +2065,70 @@
     return end();
 }
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 template <class ..._Args>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
 {
-    static_assert(!__is_hash_value_type<_Args...>::value,
-                  "Construct cannot be called with a hash 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)...);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__value_constructed = true;
     __h->__hash_ = hash_function()(__h->__value_);
     __h->__next_ = nullptr;
     return __h;
 }
 
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
-template <class _First, class ..._Rest>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
-    size_t __hash, _First&& __f, _Rest&& ...__rest)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(value_type&& __v,
+                                                           size_t __hash)
 {
-    static_assert(!__is_hash_value_type<_First, _Rest...>::value,
-                  "Construct cannot be called with a hash 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<_First>(__f),
-                             _VSTD::forward<_Rest>(__rest)...);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
     __h.get_deleter().__value_constructed = true;
     __h->__hash_ = __hash;
     __h->__next_ = nullptr;
     return __h;
 }
 
-#else  // _LIBCPP_CXX03_LANG
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const 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);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
     __h.get_deleter().__value_constructed = true;
     __h->__hash_ = hash_function()(__h->__value_);
     __h->__next_ = nullptr;
-    return _LIBCPP_EXPLICIT_MOVE(__h);  // explicitly moved for C++03
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
 
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
-__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
-                                                                const __container_value_type& __v)
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v,
+                                                           size_t __hash)
 {
     __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);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
     __h.get_deleter().__value_constructed = true;
     __h->__hash_ = __hash;
     __h->__next_ = nullptr;
-    return _LIBCPP_EXPLICIT_MOVE(__h);  // explicitly moved for C++03
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
 
-#endif  // _LIBCPP_CXX03_LANG
-
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
@@ -2441,7 +2258,7 @@
 
 template <class _Tp, class _Hash, class _Equal, class _Alloc>
 template <class _Key>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
 __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
 {
diff --git a/include/__locale b/include/__locale
index 7bc701d..1989558 100644
--- a/include/__locale
+++ b/include/__locale
@@ -37,8 +37,6 @@
 #elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
 # include <xlocale.h>
-#elif defined(_LIBCPP_HAS_MUSL_LIBC)
-# include <support/musl/xlocale.h>
 #endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -331,7 +329,7 @@
 class _LIBCPP_TYPE_VIS ctype_base
 {
 public:
-#if defined(__GLIBC__)
+#ifdef __GLIBC__
     typedef unsigned short mask;
     static const mask space  = _ISspace;
     static const mask print  = _ISprint;
@@ -361,7 +359,7 @@
     typedef __uint32_t mask;
 # elif defined(__FreeBSD__)
     typedef unsigned long mask;
-# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
+# elif defined(__EMSCRIPTEN__) ||  defined(__NetBSD__)
     typedef unsigned short mask;
 # endif
     static const mask space  = _CTYPE_S;
diff --git a/include/__mutex_base b/include/__mutex_base
index 32536a6..d5ece7c 100644
--- a/include/__mutex_base
+++ b/include/__mutex_base
@@ -14,7 +14,7 @@
 #include <__config>
 #include <chrono>
 #include <system_error>
-#include <__threading_support>
+#include <pthread.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -24,24 +24,16 @@
 
 #ifndef _LIBCPP_HAS_NO_THREADS
 
-#ifndef _LIBCPP_THREAD_SAFETY_ANNOTATION
-#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
-#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
-#  else
-#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
-#  endif
-#endif  // _LIBCPP_THREAD_SAFETY_ANNOTATION
-
-class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex
+class _LIBCPP_TYPE_VIS mutex
 {
-    __libcpp_mutex_t __m_;
+    pthread_mutex_t __m_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-    constexpr mutex() _NOEXCEPT : __m_(_LIBCPP_MUTEX_INITIALIZER) {}
+     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
 #else
-    mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;}
+     mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
 #endif
      ~mutex();
 
@@ -50,11 +42,11 @@
     mutex& operator=(const mutex&);// = delete;
 
 public:
-    void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
-    bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
-    void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
+    void lock();
+    bool try_lock() _NOEXCEPT;
+    void unlock() _NOEXCEPT;
 
-    typedef __libcpp_mutex_t* native_handle_type;
+    typedef pthread_mutex_t* native_handle_type;
     _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
 };
 
@@ -77,7 +69,7 @@
 #endif
 
 template <class _Mutex>
-class _LIBCPP_TYPE_VIS_ONLY _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) lock_guard
+class _LIBCPP_TYPE_VIS_ONLY lock_guard
 {
 public:
     typedef _Mutex mutex_type;
@@ -87,13 +79,13 @@
 public:
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
+    explicit lock_guard(mutex_type& __m)
         : __m_(__m) {__m_.lock();}
     _LIBCPP_INLINE_VISIBILITY
-    lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
+    lock_guard(mutex_type& __m, adopt_lock_t)
         : __m_(__m) {}
     _LIBCPP_INLINE_VISIBILITY
-    ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
+    ~lock_guard() {__m_.unlock();}
 
 private:
     lock_guard(lock_guard const&);// = delete;
@@ -115,24 +107,24 @@
     unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
     _LIBCPP_INLINE_VISIBILITY
     explicit unique_lock(mutex_type& __m)
-        : __m_(_VSTD::addressof(__m)), __owns_(true) {__m_->lock();}
+        : __m_(&__m), __owns_(true) {__m_->lock();}
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
-        : __m_(_VSTD::addressof(__m)), __owns_(false) {}
+        : __m_(&__m), __owns_(false) {}
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(mutex_type& __m, try_to_lock_t)
-        : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock()) {}
+        : __m_(&__m), __owns_(__m.try_lock()) {}
     _LIBCPP_INLINE_VISIBILITY
     unique_lock(mutex_type& __m, adopt_lock_t)
-        : __m_(_VSTD::addressof(__m)), __owns_(true) {}
+        : __m_(&__m), __owns_(true) {}
     template <class _Clock, class _Duration>
     _LIBCPP_INLINE_VISIBILITY
         unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t)
-            : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_until(__t)) {}
+            : __m_(&__m), __owns_(__m.try_lock_until(__t)) {}
     template <class _Rep, class _Period>
     _LIBCPP_INLINE_VISIBILITY
         unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
-            : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_for(__d)) {}
+            : __m_(&__m), __owns_(__m.try_lock_for(__d)) {}
     _LIBCPP_INLINE_VISIBILITY
     ~unique_lock()
     {
@@ -274,13 +266,13 @@
 
 class _LIBCPP_TYPE_VIS condition_variable
 {
-    __libcpp_condvar_t  __cv_;
+    pthread_cond_t __cv_;
 public:
     _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
-    constexpr condition_variable() : __cv_(_LIBCPP_CONDVAR_INITIALIZER) {}
+    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
 #else
-    condition_variable() {__cv_ = (__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;}
+    condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
 #endif
     ~condition_variable();
 
@@ -314,12 +306,11 @@
 
     template <class _Rep, class _Period, class _Predicate>
         bool
-        _LIBCPP_INLINE_VISIBILITY
         wait_for(unique_lock<mutex>& __lk,
                  const chrono::duration<_Rep, _Period>& __d,
                  _Predicate __pred);
 
-    typedef __libcpp_condvar_t* native_handle_type;
+    typedef pthread_cond_t* native_handle_type;
     _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;}
 
 private:
@@ -399,7 +390,7 @@
 }
 
 template <class _Rep, class _Period, class _Predicate>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 condition_variable::wait_for(unique_lock<mutex>& __lk,
                              const chrono::duration<_Rep, _Period>& __d,
diff --git a/include/__nullptr b/include/__nullptr
deleted file mode 100644
index 95415a6..0000000
--- a/include/__nullptr
+++ /dev/null
@@ -1,66 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- __nullptr --------------------------------===//
-//
-//                     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_NULLPTR
-#define _LIBCPP_NULLPTR
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#ifdef _LIBCPP_HAS_NO_NULLPTR
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
-{
-    void* __lx;
-
-    struct __nat {int __for_bool_;};
-
-    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
-    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
-
-    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
-
-    template <class _Tp>
-        _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
-        operator _Tp* () const {return 0;}
-
-    template <class _Tp, class _Up>
-        _LIBCPP_ALWAYS_INLINE
-        operator _Tp _Up::* () const {return 0;}
-
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
-    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
-};
-
-inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
-
-#define nullptr _VSTD::__get_nullptr_t()
-
-_LIBCPP_END_NAMESPACE_STD
-
-#else  // _LIBCPP_HAS_NO_NULLPTR
-
-namespace std
-{
-    typedef decltype(nullptr) nullptr_t;
-}
-
-#endif  // _LIBCPP_HAS_NO_NULLPTR
-
-#endif  // _LIBCPP_NULLPTR
diff --git a/include/__split_buffer b/include/__split_buffer
index 79d1aa1..727b1b6 100644
--- a/include/__split_buffer
+++ b/include/__split_buffer
@@ -56,12 +56,9 @@
     _LIBCPP_INLINE_VISIBILITY pointer&              __end_cap() _NOEXCEPT       {return __end_cap_.first();}
     _LIBCPP_INLINE_VISIBILITY const pointer&        __end_cap() const _NOEXCEPT {return __end_cap_.first();}
 
-    _LIBCPP_INLINE_VISIBILITY
     __split_buffer()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
-    _LIBCPP_INLINE_VISIBILITY
     explicit __split_buffer(__alloc_rr& __a);
-    _LIBCPP_INLINE_VISIBILITY
     explicit __split_buffer(const __alloc_rr& __a);
     __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
     ~__split_buffer();
@@ -131,9 +128,7 @@
 
     _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
         {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());}
-        _LIBCPP_INLINE_VISIBILITY
         void __destruct_at_begin(pointer __new_begin, false_type);
-        _LIBCPP_INLINE_VISIBILITY
         void __destruct_at_begin(pointer __new_begin, true_type);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -271,7 +266,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
 {
@@ -280,7 +275,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
 {
@@ -314,7 +309,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __split_buffer<_Tp, _Allocator>::__split_buffer()
     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
     : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr)
@@ -322,14 +317,14 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
     : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
 {
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
     : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
 {
diff --git a/include/__threading_support b/include/__threading_support
deleted file mode 100644
index 49fdca2..0000000
--- a/include/__threading_support
+++ /dev/null
@@ -1,205 +0,0 @@
-// -*- 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_THREADING_SUPPORT
-#define _LIBCPP_THREADING_SUPPORT
-
-#include <__config>
-
-#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
-#pragma GCC system_header
-#endif
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#if defined(_LIBCPP_THREAD_API_PTHREAD)
-#include <pthread.h>
-#include <sched.h>
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if defined(_LIBCPP_THREAD_API_PTHREAD)
-
-// Mutex
-#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-typedef pthread_mutex_t __libcpp_mutex_t;
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_recursive_mutex_init(__libcpp_mutex_t* __m)
-{
-    pthread_mutexattr_t attr;
-    int __ec = pthread_mutexattr_init(&attr);
-    if (__ec) return __ec;
-    __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-    if (__ec)
-    {
-        pthread_mutexattr_destroy(&attr);
-        return __ec;
-    }
-    __ec = pthread_mutex_init(__m, &attr);
-    if (__ec)
-    {
-        pthread_mutexattr_destroy(&attr);
-        return __ec;
-    }
-    __ec = pthread_mutexattr_destroy(&attr);
-    if (__ec)
-    {
-        pthread_mutex_destroy(__m);
-        return __ec;
-    }
-    return 0;
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_mutex_lock(__libcpp_mutex_t* __m)
-{
-    return pthread_mutex_lock(__m);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_mutex_trylock(__libcpp_mutex_t* __m)
-{
-    return pthread_mutex_trylock(__m);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_mutex_unlock(__libcpp_mutex_t* __m)
-{
-    return pthread_mutex_unlock(__m);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_mutex_destroy(__libcpp_mutex_t* __m)
-{
-    return pthread_mutex_destroy(__m);
-}
-
-// Condition variable
-#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
-typedef pthread_cond_t __libcpp_condvar_t;
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_condvar_signal(__libcpp_condvar_t* __cv)
-{
-    return pthread_cond_signal(__cv);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv)
-{
-    return pthread_cond_broadcast(__cv);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m)
-{
-    return pthread_cond_wait(__cv, __m);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, timespec* __ts)
-{
-    return pthread_cond_timedwait(__cv, __m, __ts);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv)
-{
-    return pthread_cond_destroy(__cv);
-}
-
-// Thread id
-typedef pthread_t __libcpp_thread_id;
-
-// Returns non-zero if the thread ids are equal, otherwise 0
-inline _LIBCPP_ALWAYS_INLINE
-bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
-{
-    return pthread_equal(t1, t2) != 0;
-}
-
-// Returns non-zero if t1 < t2, otherwise 0
-inline _LIBCPP_ALWAYS_INLINE
-bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
-{
-    return t1 < t2;
-}
-
-// Thread
-typedef pthread_t __libcpp_thread_t;
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg)
-{
-    return pthread_create(__t, 0, __func, __arg);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-__libcpp_thread_id __libcpp_thread_get_current_id()
-{
-    return pthread_self();
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t)
-{
-    return *__t;
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_thread_join(__libcpp_thread_t* __t)
-{
-    return pthread_join(*__t, 0);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_thread_detach(__libcpp_thread_t* __t)
-{
-    return pthread_detach(*__t);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-void __libcpp_thread_yield()
-{
-    sched_yield();
-}
-
-// Thread local storage
-typedef pthread_key_t __libcpp_tl_key;
-
-inline _LIBCPP_ALWAYS_INLINE
-int __libcpp_tl_create(__libcpp_tl_key* __key, void (*__at_exit)(void*))
-{
-    return pthread_key_create(__key, __at_exit);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-void* __libcpp_tl_get(__libcpp_tl_key __key)
-{
-    return pthread_getspecific(__key);
-}
-
-inline _LIBCPP_ALWAYS_INLINE
-void __libcpp_tl_set(__libcpp_tl_key __key, void* __p)
-{
-    pthread_setspecific(__key, __p);
-}
-
-#else // !_LIBCPP_THREAD_API_PTHREAD
-  #error "No thread API selected."
-#endif
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP_HAS_NO_THREADS
-
-#endif // _LIBCPP_THREADING_SUPPORT
diff --git a/include/__tree b/include/__tree
index 62178e3..8030eef 100644
--- a/include/__tree
+++ b/include/__tree
@@ -37,22 +37,6 @@
 template <class _Key, class _Compare, class _Allocator>
     class _LIBCPP_TYPE_VIS_ONLY multiset;
 
-template <class _Pointer> class __tree_end_node;
-template <class _VoidPtr> class __tree_node_base;
-template <class _Tp, class _VoidPtr> class __tree_node;
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Key, class _Value>
-union __value_type;
-#else
-template <class _Key, class _Value>
-struct __value_type;
-#endif
-
-template <class _Allocator> class __map_node_destructor;
-template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_iterator;
-template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
-
 /*
 
 _NodePtr algorithms
@@ -518,225 +502,18 @@
     }
 }
 
-// node traits
-
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp>
-struct __is_tree_value_type_imp : false_type {};
-
-template <class _Key, class _Value>
-struct __is_tree_value_type_imp<__value_type<_Key, _Value>> : true_type {};
-
-template <class ..._Args>
-struct __is_tree_value_type : false_type {};
-
-template <class _One>
-struct __is_tree_value_type<_One> : __is_tree_value_type_imp<typename __uncvref<_One>::type> {};
-#endif
-
-template <class _Tp>
-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 <class _Key, class _Tp>
-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<const _Key, _Tp>                        __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 <class _Up>
-  _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 <class _Up>
-  _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 <class _VoidPtr>
-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;
-private:
-  static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
-                  "_VoidPtr does not point to unqualified void type");
-};
-
-template <class _Tp, class _AllocPtr, class _KVTypes = __tree_key_value_types<_Tp>,
-         bool = _KVTypes::__is_map>
-struct __tree_map_pointer_types {};
-
-template <class _Tp, class _AllocPtr, class _KVTypes>
-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 <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
-struct __tree_node_types;
-
-template <class _NodePtr, class _Tp, class _VoidPtr>
-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;
-private:
-    static_assert(!is_const<__node_type>::value,
-                "_NodePtr should never be a pointer to const");
-    static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
-                          _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
-};
-
-template <class _ValueTp, class _VoidPtr>
-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 _Pointer>
-class __tree_end_node
-{
-public:
-    typedef _Pointer pointer;
-    pointer __left_;
-
-    _LIBCPP_INLINE_VISIBILITY
-    __tree_end_node() _NOEXCEPT : __left_() {}
-};
-
-template <class _VoidPtr>
-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;
-
-    pointer __right_;
-    pointer __parent_;
-    bool __is_black_;
-
-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 _Tp, class _VoidPtr>
-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 _Allocator> class __map_node_destructor;
 
 template <class _Allocator>
 class __tree_node_destructor
 {
     typedef _Allocator                                      allocator_type;
     typedef allocator_traits<allocator_type>                __alloc_traits;
-
+    typedef typename __alloc_traits::value_type::value_type value_type;
 public:
     typedef typename __alloc_traits::pointer                pointer;
 private:
-    typedef __tree_node_types<pointer> _NodeTypes;
+
     allocator_type& __na_;
 
     __tree_node_destructor& operator=(const __tree_node_destructor&);
@@ -754,7 +531,7 @@
     void operator()(pointer __p) _NOEXCEPT
     {
         if (__value_constructed)
-            __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_));
         if (__p)
             __alloc_traits::deallocate(__na_, __p, 1);
     }
@@ -762,23 +539,105 @@
     template <class> friend class __map_node_destructor;
 };
 
+// node
+
+template <class _Pointer>
+class __tree_end_node
+{
+public:
+    typedef _Pointer pointer;
+    pointer __left_;
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_end_node() _NOEXCEPT : __left_() {}
+};
+
+template <class _VoidPtr>
+class __tree_node_base
+    : public __tree_end_node
+             <
+                typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                     rebind<__tree_node_base<_VoidPtr> >
+#else
+                     rebind<__tree_node_base<_VoidPtr> >::other
+#endif
+             >
+{
+    __tree_node_base(const __tree_node_base&);
+    __tree_node_base& operator=(const __tree_node_base&);
+public:
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__tree_node_base>
+#else
+            rebind<__tree_node_base>::other
+#endif
+                                                pointer;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const __tree_node_base>
+#else
+            rebind<const __tree_node_base>::other
+#endif
+                                                const_pointer;
+    typedef __tree_end_node<pointer> base;
+
+    pointer __right_;
+    pointer __parent_;
+    bool __is_black_;
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_node_base() _NOEXCEPT
+        : __right_(), __parent_(), __is_black_(false) {}
+};
+
+template <class _Tp, class _VoidPtr>
+class __tree_node
+    : public __tree_node_base<_VoidPtr>
+{
+public:
+    typedef __tree_node_base<_VoidPtr> base;
+    typedef _Tp value_type;
+
+    value_type __value_;
+
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+    template <class ..._Args>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tree_node(_Args&& ...__args)
+            : __value_(_VSTD::forward<_Args>(__args)...) {}
+#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __tree_node(const value_type& __v)
+            : __value_(__v) {}
+#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+};
+
+template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_iterator;
+template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
 
 template <class _Tp, class _NodePtr, class _DiffType>
 class _LIBCPP_TYPE_VIS_ONLY __tree_iterator
 {
-    typedef __tree_node_types<_NodePtr>                     _NodeTypes;
-    typedef _NodePtr                                        __node_pointer;
-    typedef typename _NodeTypes::__node_base_pointer        __node_base_pointer;
-    typedef pointer_traits<__node_pointer> __pointer_traits;
+    typedef _NodePtr                                              __node_pointer;
+    typedef typename pointer_traits<__node_pointer>::element_type __node;
 
     __node_pointer __ptr_;
 
+    typedef pointer_traits<__node_pointer> __pointer_traits;
 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;
+    typedef bidirectional_iterator_tag iterator_category;
+    typedef _Tp                        value_type;
+    typedef _DiffType                  difference_type;
+    typedef value_type&                reference;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                       pointer;
 
     _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT
 #if _LIBCPP_STD_VER > 11
@@ -793,7 +652,7 @@
     _LIBCPP_INLINE_VISIBILITY
     __tree_iterator& operator++() {
       __ptr_ = static_cast<__node_pointer>(
-          __tree_next(static_cast<__node_base_pointer>(__ptr_)));
+          __tree_next(static_cast<typename __node::base::pointer>(__ptr_)));
       return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -803,7 +662,7 @@
     _LIBCPP_INLINE_VISIBILITY
     __tree_iterator& operator--() {
       __ptr_ = static_cast<__node_pointer>(
-          __tree_prev(static_cast<__node_base_pointer>(__ptr_)));
+          __tree_prev(static_cast<typename __node::base::pointer>(__ptr_)));
       return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -829,22 +688,27 @@
     template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multiset;
 };
 
-template <class _Tp, class _NodePtr, class _DiffType>
+template <class _Tp, class _ConstNodePtr, class _DiffType>
 class _LIBCPP_TYPE_VIS_ONLY __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 pointer_traits<__node_pointer> __pointer_traits;
+    typedef _ConstNodePtr                                         __node_pointer;
+    typedef typename pointer_traits<__node_pointer>::element_type __node;
 
     __node_pointer __ptr_;
 
+    typedef pointer_traits<__node_pointer> __pointer_traits;
 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;
+    typedef bidirectional_iterator_tag       iterator_category;
+    typedef _Tp                              value_type;
+    typedef _DiffType                        difference_type;
+    typedef const value_type&                reference;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                       pointer;
 
     _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() _NOEXCEPT
 #if _LIBCPP_STD_VER > 11
@@ -853,8 +717,16 @@
     {}
 
 private:
-    typedef __tree_iterator<value_type, __node_pointer, difference_type>
-                                                           __non_const_iterator;
+    typedef typename remove_const<__node>::type  __non_const_node;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__non_const_node>
+#else
+            rebind<__non_const_node>::other
+#endif
+                                                 __non_const_node_pointer;
+    typedef __tree_iterator<value_type, __non_const_node_pointer, difference_type>
+                                                 __non_const_iterator;
 public:
     _LIBCPP_INLINE_VISIBILITY
     __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT
@@ -866,6 +738,14 @@
 
     _LIBCPP_INLINE_VISIBILITY
     __tree_const_iterator& operator++() {
+      typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+          rebind<typename __node::base>
+#else
+          rebind<typename __node::base>::other
+#endif
+              __node_base_pointer;
+
       __ptr_ = static_cast<__node_pointer>(
           __tree_next(static_cast<__node_base_pointer>(__ptr_)));
       return *this;
@@ -877,6 +757,14 @@
 
     _LIBCPP_INLINE_VISIBILITY
     __tree_const_iterator& operator--() {
+      typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+          rebind<typename __node::base>
+#else
+          rebind<typename __node::base>::other
+#endif
+              __node_base_pointer;
+
       __ptr_ = static_cast<__node_pointer>(
           __tree_prev(static_cast<__node_base_pointer>(__ptr_)));
       return *this;
@@ -912,51 +800,40 @@
     typedef _Tp                                      value_type;
     typedef _Compare                                 value_compare;
     typedef _Allocator                               allocator_type;
-
-private:
     typedef allocator_traits<allocator_type>         __alloc_traits;
-    typedef typename __make_tree_node_types<value_type,
-        typename __alloc_traits::void_pointer>::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 __alloc_traits::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 __tree_node<value_type, __void_pointer> __node;
+    typedef __tree_node_base<__void_pointer>        __node_base;
     typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
-    typedef allocator_traits<__node_allocator>         __node_traits;
-
+    typedef allocator_traits<__node_allocator>       __node_traits;
+    typedef typename __node_traits::pointer          __node_pointer;
+    typedef typename __node_traits::pointer          __node_const_pointer;
+    typedef typename __node_base::pointer            __node_base_pointer;
+    typedef typename __node_base::pointer            __node_base_const_pointer;
 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.");
+    typedef typename __node_base::base __end_node_t;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__end_node_t>
+#else
+            rebind<__end_node_t>::other
+#endif
+                                                     __end_node_ptr;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__end_node_t>
+#else
+            rebind<__end_node_t>::other
+#endif
+                                                     __end_node_const_ptr;
 
-private:
-    __node_pointer                                     __begin_node_;
+    __node_pointer                                          __begin_node_;
     __compressed_pair<__end_node_t, __node_allocator>  __pair1_;
     __compressed_pair<size_type, value_compare>        __pair3_;
 
@@ -964,18 +841,18 @@
     _LIBCPP_INLINE_VISIBILITY
     __node_pointer __end_node() _NOEXCEPT
     {
-        return static_cast<__node_pointer>(
-                pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
-        );
+        return static_cast<__node_pointer>
+               (
+                   pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
+               );
     }
     _LIBCPP_INLINE_VISIBILITY
-    __node_pointer __end_node() const _NOEXCEPT
+    __node_const_pointer __end_node() const _NOEXCEPT
     {
-        return static_cast<__node_pointer>(
-            pointer_traits<__end_node_ptr>::pointer_to(
-                const_cast<__end_node_t&>(__pair1_.first())
-            )
-        );
+        return static_cast<__node_const_pointer>
+               (
+                   pointer_traits<__end_node_const_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first()))
+               );
     }
     _LIBCPP_INLINE_VISIBILITY
           __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();}
@@ -1003,10 +880,12 @@
     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_pointer __root() _NOEXCEPT
+        {return static_cast<__node_pointer>      (__end_node()->__left_);}
+    _LIBCPP_INLINE_VISIBILITY
+    __node_const_pointer __root() const _NOEXCEPT
+        {return static_cast<__node_const_pointer>(__end_node()->__left_);}
 
     typedef __tree_iterator<value_type, __node_pointer, difference_type>             iterator;
     typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator;
@@ -1062,194 +941,37 @@
 #endif
             );
 
-
-#ifndef _LIBCPP_CXX03_LANG
-    template <class _Key, class ..._Args>
-    pair<iterator, bool>
-    __emplace_unique_key_args(_Key const&, _Args&&... __args);
-    template <class _Key, class ..._Args>
-    iterator
-    __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...);
-
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class... _Args>
-    pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
-
-    template <class... _Args>
-    iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args);
-
-    template <class... _Args>
-    iterator __emplace_multi(_Args&&... __args);
-
-    template <class... _Args>
-    iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique(_Pp&& __x) {
-        return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
-                                            __can_extract_key<_Pp, key_type>());
-    }
-
-    template <class _First, class _Second>
-    _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<
-        __can_extract_map_key<_First, key_type, __container_value_type>::value,
         pair<iterator, bool>
-    >::type __emplace_unique(_First&& __f, _Second&& __s) {
-        return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
-                                              _VSTD::forward<_Second>(__s));
-    }
-
+        __emplace_unique(_Args&&... __args);
     template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique(_Args&&... __args) {
-        return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
-      return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
-      return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
-    }
-
-    template <class _Pp>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
-      return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
-    }
-
-    template <class _Pp>
-    _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 <class _First, class _Second>
-    _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));
-    }
+        __emplace_multi(_Args&&... __args);
 
     template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) {
-        return __emplace_hint_unique_impl(__p, _VSTD::forward<_Args>(__args)...);
-    }
-
-    template <class _Pp>
-    _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 <class _Pp>
-    _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 <class _Pp>
-    _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 <class _Key, class _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
-    template <class _Key, class _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&);
-#endif
-
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __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<iterator, bool> __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 <class _Vp, class = typename enable_if<
-            !is_same<typename __unconstref<_Vp>::type,
-                     __container_value_type
-            >::value
-        >::type>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> __insert_unique(_Vp&& __v) {
-        return __emplace_unique(_VSTD::forward<_Vp>(__v));
-    }
-
-    template <class _Vp, class = typename enable_if<
-            !is_same<typename __unconstref<_Vp>::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));
-    }
+        iterator
+        __emplace_hint_unique(const_iterator __p, _Args&&... __args);
+    template <class... _Args>
+        iterator
+        __emplace_hint_multi(const_iterator __p, _Args&&... __args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
     template <class _Vp>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __insert_multi(_Vp&& __v) {
-        return __emplace_multi(_VSTD::forward<_Vp>(__v));
-    }
-
+        pair<iterator, bool> __insert_unique(_Vp&& __v);
     template <class _Vp>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator __insert_multi(const_iterator __p, _Vp&& __v) {
-        return __emplace_hint_multi(__p, _VSTD::forward<_Vp>(__v));
-    }
+        iterator __insert_unique(const_iterator __p, _Vp&& __v);
+    template <class _Vp>
+        iterator __insert_multi(_Vp&& __v);
+    template <class _Vp>
+        iterator __insert_multi(const_iterator __p, _Vp&& __v);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#endif // !_LIBCPP_CXX03_LANG
+    pair<iterator, bool> __insert_unique(const value_type& __v);
+    iterator __insert_unique(const_iterator __p, const value_type& __v);
+    iterator __insert_multi(const value_type& __v);
+    iterator __insert_multi(const_iterator __p, const value_type& __v);
 
     pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
     iterator             __node_insert_unique(const_iterator __p,
@@ -1293,8 +1015,8 @@
             {return __lower_bound(__v, __root(), __end_node());}
     template <class _Key>
         const_iterator __lower_bound(const _Key& __v,
-                                     __node_pointer __root,
-                                     __node_pointer __result) const;
+                                     __node_const_pointer __root,
+                                     __node_const_pointer __result) const;
     template <class _Key>
         _LIBCPP_INLINE_VISIBILITY
         iterator upper_bound(const _Key& __v)
@@ -1309,8 +1031,8 @@
             {return __upper_bound(__v, __root(), __end_node());}
     template <class _Key>
         const_iterator __upper_bound(const _Key& __v,
-                                     __node_pointer __root,
-                                     __node_pointer __result) const;
+                                     __node_const_pointer __root,
+                                     __node_const_pointer __result) const;
     template <class _Key>
         pair<iterator, iterator>
         __equal_range_unique(const _Key& __k);
@@ -1331,12 +1053,12 @@
     __node_holder remove(const_iterator __p) _NOEXCEPT;
 private:
     typename __node_base::pointer&
-        __find_leaf_low(typename __node_base::pointer& __parent, const key_type& __v);
+        __find_leaf_low(typename __node_base::pointer& __parent, const value_type& __v);
     typename __node_base::pointer&
-        __find_leaf_high(typename __node_base::pointer& __parent, const key_type& __v);
+        __find_leaf_high(typename __node_base::pointer& __parent, const value_type& __v);
     typename __node_base::pointer&
         __find_leaf(const_iterator __hint,
-                    typename __node_base::pointer& __parent, const key_type& __v);
+                    typename __node_base::pointer& __parent, const value_type& __v);
     template <class _Key>
         typename __node_base::pointer&
         __find_equal(typename __node_base::pointer& __parent, const _Key& __v);
@@ -1345,11 +1067,11 @@
         __find_equal(const_iterator __hint, typename __node_base::pointer& __parent,
                      const _Key& __v);
 
-#ifndef _LIBCPP_CXX03_LANG
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
     template <class ..._Args>
-    __node_holder __construct_node(_Args&& ...__args);
-#else
-    __node_holder __construct_node(const __container_value_type& __v);
+        __node_holder __construct_node(_Args&& ...__args);
+#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+        __node_holder __construct_node(const value_type& __v);
 #endif
 
     void destroy(__node_pointer __nd) _NOEXCEPT;
@@ -1483,11 +1205,6 @@
 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();
@@ -1528,12 +1245,6 @@
 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();
@@ -1566,7 +1277,7 @@
         }
     }
     for (; __first != __last; ++__first)
-        __insert_multi(_NodeTypes::__get_value(*__first));
+        __insert_multi(*__first);
 }
 
 template <class _Tp, class _Compare, class _Allocator>
@@ -1690,7 +1401,7 @@
             }
         }
         while (__t.size() != 0)
-            __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_));
+            __insert_multi(__e, _VSTD::move(__t.remove(__t.begin())->__value_));
     }
 }
 
@@ -1725,7 +1436,7 @@
         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::destroy(__na, _VSTD::addressof(__nd->__value_));
         __node_traits::deallocate(__na, __nd, 1);
     }
 }
@@ -1772,7 +1483,7 @@
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
 __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer& __parent,
-                                                   const key_type& __v)
+                                                   const value_type& __v)
 {
     __node_pointer __nd = __root();
     if (__nd != nullptr)
@@ -1811,7 +1522,7 @@
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
 __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointer& __parent,
-                                                    const key_type& __v)
+                                                    const value_type& __v)
 {
     __node_pointer __nd = __root();
     if (__nd != nullptr)
@@ -1854,7 +1565,7 @@
 typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
 __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint,
                                                typename __node_base::pointer& __parent,
-                                               const key_type& __v)
+                                               const value_type& __v)
 {
     if (__hint == end() || !value_comp()(*__hint, __v))  // check before
     {
@@ -1997,7 +1708,6 @@
     __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<__node_pointer>(__begin_node()->__left_);
@@ -2005,89 +1715,25 @@
     ++size();
 }
 
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp, class _Compare, class _Allocator>
-template <class _Key, class... _Args>
-pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
-#else
-template <class _Tp, class _Compare, class _Allocator>
-template <class _Key, class _Args>
-pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
-#endif
-{
-    __node_base_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, bool>(iterator(__r), __inserted);
-}
-
-
-#ifndef _LIBCPP_CXX03_LANG
-template <class _Tp, class _Compare, class _Allocator>
-template <class _Key, class... _Args>
-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 <class _Tp, class _Compare, class _Allocator>
-template <class _Key, class _Args>
-typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
-    const_iterator __p, _Key const& __k, _Args& __args)
-#endif
-{
-    __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_equal(__p, __parent, __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
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp, class _Compare, class _Allocator>
 template <class ..._Args>
 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)...);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...);
     __h.get_deleter().__value_constructed = true;
     return __h;
 }
 
-
 template <class _Tp, class _Compare, class _Allocator>
 template <class... _Args>
 pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
-__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args)
+__tree<_Tp, _Compare, _Allocator>::__emplace_unique(_Args&&... __args)
 {
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
@@ -2106,7 +1752,7 @@
 template <class _Tp, class _Compare, class _Allocator>
 template <class... _Args>
 typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args)
+__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique(const_iterator __p, _Args&&... __args)
 {
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
@@ -2127,7 +1773,7 @@
 {
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_));
+    __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
     __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(static_cast<__node_pointer>(__h.release()));
 }
@@ -2140,34 +1786,116 @@
 {
     __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_));
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
     __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(static_cast<__node_pointer>(__h.release()));
 }
 
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#else  // _LIBCPP_CXX03_LANG
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Vp>
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(_Vp&& __v)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
+    pair<iterator, bool> __r = __node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Vp>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, _Vp&& __v)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
+    iterator __r = __node_insert_unique(__p, __h.get());
+    if (__r.__ptr_ == __h.get())
+        __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Vp>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(_Vp&& __v)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+    return iterator(__h.release());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Vp>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, _Vp&& __v)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v));
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+    return iterator(__h.release());
+}
+
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::__node_holder
-__tree<_Tp, _Compare, _Allocator>::__construct_node(const __container_value_type& __v)
+__tree<_Tp, _Compare, _Allocator>::__construct_node(const 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);
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
     __h.get_deleter().__value_constructed = true;
-    return _LIBCPP_EXPLICIT_MOVE(__h);  // explicitly moved for C++03
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
 
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-#ifdef _LIBCPP_CXX03_LANG
 template <class _Tp, class _Compare, class _Allocator>
-typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__insert_multi(const __container_value_type& __v)
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(const value_type& __v)
 {
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__v));
+    __node_base_pointer& __child = __find_equal(__parent, __v);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    bool __inserted = false;
+    if (__child == nullptr)
+    {
+        __node_holder __h = __construct_node(__v);
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+        __r = __h.release();
+        __inserted = true;
+    }
+    return pair<iterator, bool>(iterator(__r), __inserted);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, const value_type& __v)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal(__p, __parent, __v);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __node_holder __h = __construct_node(__v);
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+        __r = __h.release();
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(const value_type& __v)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __v);
     __node_holder __h = __construct_node(__v);
     __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
     return iterator(__h.release());
@@ -2175,15 +1903,14 @@
 
 template <class _Tp, class _Compare, class _Allocator>
 typename __tree<_Tp, _Compare, _Allocator>::iterator
-__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __container_value_type& __v)
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const value_type& __v)
 {
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__v));
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __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 <class _Tp, class _Compare, class _Allocator>
 pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
@@ -2223,7 +1950,7 @@
 __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd)
 {
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_));
+    __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_);
     __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
     return iterator(__nd);
 }
@@ -2234,7 +1961,7 @@
                                                        __node_pointer __nd)
 {
     __node_base_pointer __parent;
-    __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_));
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_);
     __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
     return iterator(__nd);
 }
@@ -2252,8 +1979,7 @@
     __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::destroy(__na, const_cast<value_type*>(_VSTD::addressof(*__p)));
     __node_traits::deallocate(__na, __np, 1);
     return __r;
 }
@@ -2318,17 +2044,17 @@
 typename __tree<_Tp, _Compare, _Allocator>::size_type
 __tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const
 {
-    __node_pointer __result = __end_node();
-    __node_pointer __rt = __root();
+    __node_const_pointer __result = __end_node();
+    __node_const_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_pointer>(__rt->__left_);
+            __rt = static_cast<__node_const_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_pointer>(__rt->__right_);
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
         else
             return 1;
     }
@@ -2340,21 +2066,21 @@
 typename __tree<_Tp, _Compare, _Allocator>::size_type
 __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const
 {
-    __node_pointer __result = __end_node();
-    __node_pointer __rt = __root();
+    __node_const_pointer __result = __end_node();
+    __node_const_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_pointer>(__rt->__left_);
+            __rt = static_cast<__node_const_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_pointer>(__rt->__right_);
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
         else
             return _VSTD::distance(
-                __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
-                __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)
+                __lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
+                __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result)
             );
     }
     return 0;
@@ -2384,18 +2110,18 @@
 template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::const_iterator
 __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v,
-                                                 __node_pointer __root,
-                                                 __node_pointer __result) const
+                                                 __node_const_pointer __root,
+                                                 __node_const_pointer __result) const
 {
     while (__root != nullptr)
     {
         if (!value_comp()(__root->__value_, __v))
         {
             __result = __root;
-            __root = static_cast<__node_pointer>(__root->__left_);
+            __root = static_cast<__node_const_pointer>(__root->__left_);
         }
         else
-            __root = static_cast<__node_pointer>(__root->__right_);
+            __root = static_cast<__node_const_pointer>(__root->__right_);
     }
     return const_iterator(__result);
 }
@@ -2424,18 +2150,18 @@
 template <class _Key>
 typename __tree<_Tp, _Compare, _Allocator>::const_iterator
 __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v,
-                                                 __node_pointer __root,
-                                                 __node_pointer __result) const
+                                                 __node_const_pointer __root,
+                                                 __node_const_pointer __result) const
 {
     while (__root != nullptr)
     {
         if (value_comp()(__v, __root->__value_))
         {
             __result = __root;
-            __root = static_cast<__node_pointer>(__root->__left_);
+            __root = static_cast<__node_const_pointer>(__root->__left_);
         }
         else
-            __root = static_cast<__node_pointer>(__root->__right_);
+            __root = static_cast<__node_const_pointer>(__root->__right_);
     }
     return const_iterator(__result);
 }
@@ -2475,22 +2201,22 @@
 __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const
 {
     typedef pair<const_iterator, const_iterator> _Pp;
-    __node_pointer __result = __end_node();
-    __node_pointer __rt = __root();
+    __node_const_pointer __result = __end_node();
+    __node_const_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_pointer>(__rt->__left_);
+            __rt = static_cast<__node_const_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_pointer>(__rt->__right_);
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
         else
             return _Pp(const_iterator(__rt),
                       const_iterator(
                           __rt->__right_ != nullptr ?
-                              static_cast<__node_pointer>(__tree_min(__rt->__right_))
+                              static_cast<__node_const_pointer>(__tree_min(__rt->__right_))
                             : __result));
     }
     return _Pp(const_iterator(__result), const_iterator(__result));
@@ -2528,20 +2254,20 @@
 __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const
 {
     typedef pair<const_iterator, const_iterator> _Pp;
-    __node_pointer __result = __end_node();
-    __node_pointer __rt = __root();
+    __node_const_pointer __result = __end_node();
+    __node_const_pointer __rt = __root();
     while (__rt != nullptr)
     {
         if (value_comp()(__k, __rt->__value_))
         {
             __result = __rt;
-            __rt = static_cast<__node_pointer>(__rt->__left_);
+            __rt = static_cast<__node_const_pointer>(__rt->__left_);
         }
         else if (value_comp()(__rt->__value_, __k))
-            __rt = static_cast<__node_pointer>(__rt->__right_);
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
         else
-            return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
-                      __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
+            return _Pp(__lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
+                      __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result));
     }
     return _Pp(const_iterator(__result), const_iterator(__result));
 }
diff --git a/include/__tuple b/include/__tuple
index 09c6839..2837ce7 100644
--- a/include/__tuple
+++ b/include/__tuple
@@ -86,15 +86,12 @@
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
 get(tuple<_Tp...>&&) _NOEXCEPT;
-
-template <size_t _Ip, class ..._Tp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
-get(const tuple<_Tp...>&&) _NOEXCEPT;
 #endif
 
 // pair specializations
 
+template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair;
+
 template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
 
 template <size_t _Ip, class _T1, class _T2>
@@ -112,11 +109,6 @@
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
 get(pair<_T1, _T2>&&) _NOEXCEPT;
-
-template <size_t _Ip, class _T1, class _T2>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
-get(const pair<_T1, _T2>&&) _NOEXCEPT;
 #endif
 
 // array specializations
@@ -140,15 +132,35 @@
 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp&&
 get(array<_Tp, _Size>&&) _NOEXCEPT;
-
-template <size_t _Ip, class _Tp, size_t _Size>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-const _Tp&&
-get(const array<_Tp, _Size>&&) _NOEXCEPT;
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_VARIADICS)
 
+// __lazy_and
+
+template <bool _Last, class ..._Preds>
+struct __lazy_and_impl;
+
+template <class ..._Preds>
+struct __lazy_and_impl<false, _Preds...> : false_type {};
+
+template <>
+struct __lazy_and_impl<true> : true_type {};
+
+template <class _Pred>
+struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {};
+
+template <class _Hp, class ..._Tp>
+struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {};
+
+template <class _P1, class ..._Pr>
+struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {};
+
+// __lazy_not
+
+template <class _Pred>
+struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
+
 // __make_tuple_indices
 
 template <size_t...> struct __tuple_indices {};
diff --git a/include/algorithm b/include/algorithm
index 7a6db7a..c1635fc 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -543,12 +543,6 @@
     T
     min(initializer_list<T> t, Compare comp);  // constexpr in C++14
 
-template<class T>
-    constexpr const T& clamp( const T& v, const T& lo, const T& hi );               // C++17
-
-template<class T, class Compare>
-    constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ); // C++17
-
 template <class ForwardIterator>
     ForwardIterator
     max_element(ForwardIterator first, ForwardIterator last);  // constexpr in C++14
@@ -630,7 +624,7 @@
 #include <initializer_list>
 #include <type_traits>
 #include <cstring>
-#include <utility> // needed to provide swap_ranges.
+#include <utility>
 #include <memory>
 #include <iterator>
 #include <cstddef>
@@ -857,7 +851,7 @@
 {
     for (; __first != __last; ++__first)
         __f(*__first);
-    return _LIBCPP_EXPLICIT_MOVE(__f);  // explicitly moved for (emulated) C++03
+    return _VSTD::move(__f);  // explicitly moved for (emulated) C++03
 }
 
 // find
@@ -1421,20 +1415,20 @@
 // search
 
 template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
-pair<_ForwardIterator1, _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
+        return __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);
+                return __last1;
             if (__pred(*__first1, *__first2))
                 break;
             ++__first1;
@@ -1445,9 +1439,9 @@
         while (true)
         {
             if (++__m2 == __last2)  // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
-                return make_pair(__first1, __m1);
+                return __first1;
             if (++__m1 == __last1)  // Otherwise if source exhaused, pattern not found
-                return make_pair(__last1, __last1);
+                return __last1;
             if (!__pred(*__m1, *__m2))  // if there is a mismatch, restart with a new __first1
             {
                 ++__first1;
@@ -1458,21 +1452,20 @@
 }
 
 template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
-_LIBCPP_CONSTEXPR_AFTER_CXX11 
-pair<_RandomAccessIterator1, _RandomAccessIterator1>
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
 __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
-         _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
+           _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;
+    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _D1;
+    typedef typename std::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;
+    _D2 __len2 = __last2 - __first2;
     if (__len2 == 0)
-        return make_pair(__first1, __first1);
-    const _D1 __len1 = __last1 - __first1;
+        return __first1;
+    _D1 __len1 = __last1 - __first1;
     if (__len1 < __len2)
-        return make_pair(__last1, __last1);
+        return __last1;
     const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
     while (true)
     {
@@ -1480,7 +1473,7 @@
         while (true)
         {
             if (__first1 == __s)
-                return make_pair(__last1, __last1);
+                return __last1;
             if (__pred(*__first1, *__first2))
                 break;
             ++__first1;
@@ -1512,7 +1505,7 @@
             if (__pred(*__first1, *__first2))
                 break;
         case 0:
-            return make_pair(__last1, __last1);
+            return __last1;
         }
     __phase2:
 #endif  // !_LIBCPP_UNROLL_LOOPS
@@ -1522,7 +1515,7 @@
          while (true)
          {
              if (++__m2 == __last2)
-                 return make_pair(__first1, __first1 + __len2);
+                 return __first1;
              ++__m1;          // no need to check range on __m1 because __s guarantees we have enough source
              if (!__pred(*__m1, *__m2))
              {
@@ -1562,7 +1555,7 @@
             if (!__pred(*__m1, *__m2))
                 break;
         case 0:
-            return make_pair(__first1, __first1 + __len2);
+            return __first1;
         }
     __continue:
         ++__first1;
@@ -1578,9 +1571,8 @@
 {
     return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>
                          (__first1, __last1, __first2, __last2, __pred,
-                          typename iterator_traits<_ForwardIterator1>::iterator_category(),
-                          typename iterator_traits<_ForwardIterator2>::iterator_category())
-            .first;
+                          typename std::iterator_traits<_ForwardIterator1>::iterator_category(),
+                          typename std::iterator_traits<_ForwardIterator2>::iterator_category());
 }
 
 template <class _ForwardIterator1, class _ForwardIterator2>
@@ -1589,8 +1581,8 @@
 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;
+    typedef typename std::iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename std::iterator_traits<_ForwardIterator2>::value_type __v2;
     return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
 }
 
@@ -1695,6 +1687,25 @@
 }
 
 // copy
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
 template <class _Iter>
 inline _LIBCPP_INLINE_VISIBILITY
 _Iter
@@ -2319,7 +2330,7 @@
     {
         if (__first == --__last)
             break;
-        _VSTD::iter_swap(__first, __last);
+        swap(*__first, *__last);
         ++__first;
     }
 }
@@ -2331,7 +2342,7 @@
 {
     if (__first != __last)
         for (; __first < --__last; ++__first)
-            _VSTD::iter_swap(__first, __last);
+            swap(*__first, *__last);
 }
 
 template <class _BidirectionalIterator>
@@ -2665,27 +2676,6 @@
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-#if _LIBCPP_STD_VER > 14
-// clamp
-template<class _Tp, class _Compare>
-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<class _Tp>
-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 <class _ForwardIterator, class _Compare>
@@ -5754,6 +5744,34 @@
                                   __less<typename iterator_traits<_BidirectionalIterator>::value_type>());
 }
 
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    _Tp
+>::type
+__rotate_left(_Tp __t, _Tp __n = 1)
+{
+    const unsigned __bits = static_cast<unsigned>(sizeof(_Tp) * __CHAR_BIT__ - 1);
+    __n &= __bits;
+    return static_cast<_Tp>((__t << __n) | (static_cast<typename make_unsigned<_Tp>::type>(__t) >> (__bits - __n)));
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    _Tp
+>::type
+__rotate_right(_Tp __t, _Tp __n = 1)
+{
+    const unsigned __bits = static_cast<unsigned>(sizeof(_Tp) * __CHAR_BIT__ - 1);
+    __n &= __bits;
+    return static_cast<_Tp>((__t << (__bits - __n)) | (static_cast<typename make_unsigned<_Tp>::type>(__t) >> __n));
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_ALGORITHM
diff --git a/include/array b/include/array
index 719286d..2e02a43 100644
--- a/include/array
+++ b/include/array
@@ -34,7 +34,7 @@
 
     // No explicit construct/copy/destroy for aggregate type
     void fill(const T& u);
-    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
+    void swap(array& a) noexcept(noexcept(swap(declval<T&>(), declval<T&>())));
 
     // iterators:
     iterator begin() noexcept;
@@ -89,13 +89,12 @@
   void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
 
 template <class T> class tuple_size;
-template <size_t I, class T> class tuple_element;
+template <int I, class T> class tuple_element;
 template <class T, size_t N> struct tuple_size<array<T, N>>;
-template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
-template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
-template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
-template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
-template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
+template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>;
+template <int I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
+template <int I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
+template <int I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
 
 }  // std
 
@@ -141,15 +140,8 @@
     _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<bool, _Size == 0>()), __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_);}
+    void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
+        {_VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);}
 
     // iterators:
     _LIBCPP_INLINE_VISIBILITY
@@ -283,12 +275,11 @@
 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)))
+swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+                                  _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
 {
     __x.swap(__y);
 }
@@ -333,15 +324,6 @@
     return _VSTD::move(__a.__elems_[_Ip]);
 }
 
-template <size_t _Ip, class _Tp, size_t _Size>
-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_HAS_NO_RVALUE_REFERENCES
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/include/atomic b/include/atomic
index a0245eb..97a998d 100644
--- a/include/atomic
+++ b/include/atomic
@@ -17,10 +17,6 @@
 namespace std
 {
 
-// feature test macro
-
-#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
-
 // order and consistency
 
 typedef enum memory_order
@@ -93,7 +89,6 @@
 template <class T>
 struct atomic
 {
-    static constexpr bool is_always_lock_free;
     bool is_lock_free() const volatile noexcept;
     bool is_lock_free() const noexcept;
     void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -132,7 +127,6 @@
 template <>
 struct atomic<integral>
 {
-    static constexpr bool is_always_lock_free;
     bool is_lock_free() const volatile noexcept;
     bool is_lock_free() const noexcept;
     void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -208,7 +202,6 @@
 template <class T>
 struct atomic<T*>
 {
-    static constexpr bool is_always_lock_free;
     bool is_lock_free() const volatile noexcept;
     bool is_lock_free() const noexcept;
     void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -542,40 +535,25 @@
 
 #ifdef _LIBCPP_HAS_NO_THREADS
 #error <atomic> is not supported on this single threaded system
-#endif
-#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
-#error <atomic> is not implemented
-#endif
-
-#if _LIBCPP_STD_VER > 14
-// FIXME: use the right feature test macro value as chose by SG10.
-# define __cpp_lib_atomic_is_always_lock_free 201603L
-#endif
+#else // !_LIBCPP_HAS_NO_THREADS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#if !__has_feature(cxx_atomic) && _GNUC_VER < 407
+#error <atomic> is not implemented
+#else
+
 typedef enum memory_order
 {
     memory_order_relaxed, memory_order_consume, memory_order_acquire,
     memory_order_release, memory_order_acq_rel, memory_order_seq_cst
 } memory_order;
 
-#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
+#if _GNUC_VER >= 407
 namespace __gcc_atomic {
 template <typename _Tp>
 struct __gcc_atomic_t {
-
-#if _GNUC_VER >= 501
-    static_assert(is_trivially_copyable<_Tp>::value,
-      "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
-#endif
-
-  _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
-    __gcc_atomic_t() _NOEXCEPT = default;
-#else
-    __gcc_atomic_t() _NOEXCEPT : __a_value() {}
-#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+  __gcc_atomic_t() _NOEXCEPT {}
   _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
     : __a_value(value) {}
   _Tp __a_value;
@@ -596,7 +574,7 @@
       sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
 };
 
-static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
+static inline constexpr int __to_gcc_order(memory_order __order) {
   // Avoid switch statement to make this a constexpr.
   return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
          (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
@@ -606,7 +584,7 @@
               __ATOMIC_CONSUME))));
 }
 
-static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
+static inline constexpr int __to_gcc_failure_order(memory_order __order) {
   // Avoid switch statement to make this a constexpr.
   return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
          (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
@@ -827,7 +805,7 @@
   return __atomic_fetch_xor(&__a->__a_value, __pattern,
                             __gcc_atomic::__to_gcc_order(__order));
 }
-#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
+#endif // _GNUC_VER >= 407
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -837,17 +815,6 @@
     return __y;
 }
 
-#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
-#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
-#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
-#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
-#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
-#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
-#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
-#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
-#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
-#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
-
 // general atomic<T>
 
 template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
@@ -855,14 +822,10 @@
 {
     mutable _Atomic(_Tp) __a_;
 
-#if defined(__cpp_lib_atomic_is_always_lock_free)
-  static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
-#endif
-
     _LIBCPP_INLINE_VISIBILITY
     bool is_lock_free() const volatile _NOEXCEPT
     {
-#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
+#if __has_feature(cxx_atomic)
     return __c11_atomic_is_lock_free(sizeof(_Tp));
 #else
     return __atomic_is_lock_free(sizeof(_Tp), 0);
@@ -947,11 +910,6 @@
 #endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 };
 
-#if defined(__cpp_lib_atomic_is_always_lock_free)
-template <class _Tp, bool __b>
-_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
-#endif
-
 // atomic<Integral>
 
 template <class _Tp>
@@ -1689,7 +1647,7 @@
 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 
     _LIBCPP_INLINE_VISIBILITY
-    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
+    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
 
 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
     atomic_flag(const atomic_flag&) = delete;
@@ -1821,6 +1779,23 @@
 #define ATOMIC_FLAG_INIT {false}
 #define ATOMIC_VAR_INIT(__v) {__v}
 
+// lock-free property
+
+#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
+#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
+#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
+#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
+#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
+#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
+#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
+
+#endif  //  !__has_feature(cxx_atomic)
+
 _LIBCPP_END_NAMESPACE_STD
 
+#endif  // !_LIBCPP_HAS_NO_THREADS
+
 #endif  // _LIBCPP_ATOMIC
diff --git a/include/bitset b/include/bitset
index 3f9b964..8c278cc 100644
--- a/include/bitset
+++ b/include/bitset
@@ -168,9 +168,7 @@
     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
@@ -182,11 +180,8 @@
     _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;
@@ -197,27 +192,22 @@
 
     bool all() const _NOEXCEPT;
     bool any() const _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     size_t __hash_code() const _NOEXCEPT;
 private:
 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
     void __init(unsigned long long __v, false_type) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     void __init(unsigned long long __v, true_type) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_CONSTEXPR
     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 <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
@@ -255,7 +245,7 @@
 #endif  // _LIBCPP_HAS_NO_CONSTEXPR
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
@@ -274,7 +264,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
 {
@@ -283,7 +273,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
 {
@@ -292,7 +282,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
 {
@@ -335,7 +325,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long
 __bitset<_N_words, _Size>::to_ulong(true_type) const
 {
@@ -358,7 +348,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long long
 __bitset<_N_words, _Size>::to_ullong(true_type) const
 {
@@ -366,7 +356,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long long
 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
 {
@@ -424,7 +414,7 @@
 }
 
 template <size_t _N_words, size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
 {
@@ -460,9 +450,7 @@
     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
@@ -474,32 +462,23 @@
     _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 <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<1, _Size>::__bitset() _NOEXCEPT
     : __first_(0)
@@ -507,7 +486,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
     : __first_(static_cast<__storage_type>(__v))
@@ -515,7 +494,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
 {
@@ -523,7 +502,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
 {
@@ -531,7 +510,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
 {
@@ -539,7 +518,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __bitset<1, _Size>::flip() _NOEXCEPT
 {
@@ -549,7 +528,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long
 __bitset<1, _Size>::to_ulong() const
 {
@@ -557,7 +536,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long long
 __bitset<1, _Size>::to_ullong() const
 {
@@ -565,7 +544,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 __bitset<1, _Size>::all() const _NOEXCEPT
 {
@@ -574,7 +553,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 __bitset<1, _Size>::any() const _NOEXCEPT
 {
@@ -583,7 +562,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 __bitset<1, _Size>::__hash_code() const _NOEXCEPT
 {
@@ -614,9 +593,7 @@
     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
@@ -643,20 +620,20 @@
     _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
 };
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<0, 0>::__bitset() _NOEXCEPT
 {
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
 {
 }
 
 template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset;
-template <size_t _Size> struct hash<bitset<_Size> >;
+template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >;
 
 template <size_t _Size>
 class _LIBCPP_TYPE_VIS_ONLY bitset
@@ -686,23 +663,16 @@
                         _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);
 
@@ -710,40 +680,28 @@
     _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 <class _CharT, class _Traits, class _Allocator>
         basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
                                                             _CharT __one = _CharT('1')) const;
     template <class _CharT, class _Traits>
-        _LIBCPP_INLINE_VISIBILITY
         basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
                                                                     _CharT __one = _CharT('1')) const;
     template <class _CharT>
-        _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<char, char_traits<char>, allocator<char> > 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:
@@ -816,7 +774,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
 {
@@ -825,7 +783,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
 {
@@ -834,7 +792,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
 {
@@ -863,7 +821,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::set() _NOEXCEPT
 {
@@ -886,7 +844,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::reset() _NOEXCEPT
 {
@@ -909,7 +867,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>
 bitset<_Size>::operator~() const _NOEXCEPT
 {
@@ -919,7 +877,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>&
 bitset<_Size>::flip() _NOEXCEPT
 {
@@ -943,7 +901,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long
 bitset<_Size>::to_ulong() const
 {
@@ -951,7 +909,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unsigned long long
 bitset<_Size>::to_ullong() const
 {
@@ -974,7 +932,7 @@
 
 template <size_t _Size>
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, allocator<_CharT> >
 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
 {
@@ -983,7 +941,7 @@
 
 template <size_t _Size>
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
 {
@@ -991,7 +949,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string<char, char_traits<char>, allocator<char> >
 bitset<_Size>::to_string(char __zero, char __one) const
 {
@@ -999,7 +957,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 bitset<_Size>::count() const _NOEXCEPT
 {
@@ -1007,7 +965,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
 {
@@ -1015,7 +973,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
 {
@@ -1036,7 +994,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 bitset<_Size>::all() const _NOEXCEPT
 {
@@ -1044,7 +1002,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 bitset<_Size>::any() const _NOEXCEPT
 {
@@ -1052,7 +1010,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>
 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
 {
@@ -1062,7 +1020,7 @@
 }
 
 template <size_t _Size>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bitset<_Size>
 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
 {
diff --git a/include/cctype b/include/cctype
index 7fc8134..26c740f 100644
--- a/include/cctype
+++ b/include/cctype
@@ -37,6 +37,10 @@
 
 #include <__config>
 #include <ctype.h>
+#if defined(_LIBCPP_MSVCRT)
+#include "support/win32/support.h"
+#include "support/win32/locale_win32.h"
+#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -45,76 +49,116 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #ifdef isalnum
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalnum(int __c) {return isalnum(__c);}
 #undef isalnum
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isalnum(int __c) {return __libcpp_isalnum(__c);}
+#else  // isalnum
+using ::isalnum;
+#endif  // isalnum
 
 #ifdef isalpha
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalpha(int __c) {return isalpha(__c);}
 #undef isalpha
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isalpha(int __c) {return __libcpp_isalpha(__c);}
+#else  // isalpha
+using ::isalpha;
+#endif  // isalpha
 
 #ifdef isblank
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isblank(int __c) {return isblank(__c);}
 #undef isblank
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isblank(int __c) {return __libcpp_isblank(__c);}
+#else  // isblank
+using ::isblank;
+#endif  // isblank
 
 #ifdef iscntrl
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iscntrl(int __c) {return iscntrl(__c);}
 #undef iscntrl
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int iscntrl(int __c) {return __libcpp_iscntrl(__c);}
+#else  // iscntrl
+using ::iscntrl;
+#endif  // iscntrl
 
 #ifdef isdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isdigit(int __c) {return isdigit(__c);}
 #undef isdigit
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isdigit(int __c) {return __libcpp_isdigit(__c);}
+#else  // isdigit
+using ::isdigit;
+#endif  // isdigit
 
 #ifdef isgraph
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isgraph(int __c) {return isgraph(__c);}
 #undef isgraph
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isgraph(int __c) {return __libcpp_isgraph(__c);}
+#else  // isgraph
+using ::isgraph;
+#endif  // isgraph
 
 #ifdef islower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_islower(int __c) {return islower(__c);}
 #undef islower
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int islower(int __c) {return __libcpp_islower(__c);}
+#else  // islower
+using ::islower;
+#endif  // islower
 
 #ifdef isprint
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isprint(int __c) {return isprint(__c);}
 #undef isprint
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isprint(int __c) {return __libcpp_isprint(__c);}
+#else  // isprint
+using ::isprint;
+#endif  // isprint
 
 #ifdef ispunct
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ispunct(int __c) {return ispunct(__c);}
 #undef ispunct
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int ispunct(int __c) {return __libcpp_ispunct(__c);}
+#else  // ispunct
+using ::ispunct;
+#endif  // ispunct
 
 #ifdef isspace
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isspace(int __c) {return isspace(__c);}
 #undef isspace
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isspace(int __c) {return __libcpp_isspace(__c);}
+#else  // isspace
+using ::isspace;
+#endif  // isspace
 
 #ifdef isupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isupper(int __c) {return isupper(__c);}
 #undef isupper
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isupper(int __c) {return __libcpp_isupper(__c);}
+#else  // isupper
+using ::isupper;
+#endif  // isupper
 
 #ifdef isxdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isxdigit(int __c) {return isxdigit(__c);}
 #undef isxdigit
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int isxdigit(int __c) {return __libcpp_isxdigit(__c);}
+#else  // isxdigit
+using ::isxdigit;
+#endif  // isxdigit
 
 #ifdef tolower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_tolower(int __c) {return tolower(__c);}
 #undef tolower
-#endif
+inline _LIBCPP_INLINE_VISIBILITY int tolower(int __c) {return __libcpp_tolower(__c);}
+#else  // tolower
+using ::tolower;
+#endif  // tolower
 
 #ifdef toupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_toupper(int __c) {return toupper(__c);}
 #undef toupper
-#endif
-
-
-using ::isalnum;
-using ::isalpha;
-using ::isblank;
-using ::iscntrl;
-using ::isdigit;
-using ::isgraph;
-using ::islower;
-using ::isprint;
-using ::ispunct;
-using ::isspace;
-using ::isupper;
-using ::isxdigit;
-using ::tolower;
+inline _LIBCPP_INLINE_VISIBILITY int toupper(int __c) {return __libcpp_toupper(__c);}
+#else  // toupper
 using ::toupper;
+#endif  // toupper
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/include/cerrno b/include/cerrno
index bab13b8..9804e4e 100644
--- a/include/cerrno
+++ b/include/cerrno
@@ -30,4 +30,364 @@
 #pragma GCC system_header
 #endif
 
+#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
+
+#ifdef ELAST
+
+const int __elast1 = ELAST+1;
+const int __elast2 = ELAST+2;
+
+#else
+
+const int __elast1 = 104;
+const int __elast2 = 105;
+
+#endif
+
+#ifdef ENOTRECOVERABLE
+
+#define EOWNERDEAD __elast1
+
+#ifdef ELAST
+#undef ELAST
+#define ELAST EOWNERDEAD
+#endif
+
+#elif defined(EOWNERDEAD)
+
+#define ENOTRECOVERABLE __elast1
+#ifdef ELAST
+#undef ELAST
+#define ELAST ENOTRECOVERABLE
+#endif
+
+#else  // defined(EOWNERDEAD)
+
+#define EOWNERDEAD __elast1
+#define ENOTRECOVERABLE __elast2
+#ifdef ELAST
+#undef ELAST
+#define ELAST ENOTRECOVERABLE
+#endif
+
+#endif  // defined(EOWNERDEAD)
+
+#endif  // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
+
+//  supply errno values likely to be missing, particularly on Windows
+
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT 9901
+#endif
+
+#ifndef EADDRINUSE
+#define EADDRINUSE 9902
+#endif
+
+#ifndef EADDRNOTAVAIL
+#define EADDRNOTAVAIL 9903
+#endif
+
+#ifndef EISCONN
+#define EISCONN 9904
+#endif
+
+#ifndef EBADMSG
+#define EBADMSG 9905
+#endif
+
+#ifndef ECONNABORTED
+#define ECONNABORTED 9906
+#endif
+
+#ifndef EALREADY
+#define EALREADY 9907
+#endif
+
+#ifndef ECONNREFUSED
+#define ECONNREFUSED 9908
+#endif
+
+#ifndef ECONNRESET
+#define ECONNRESET 9909
+#endif
+
+#ifndef EDESTADDRREQ
+#define EDESTADDRREQ 9910
+#endif
+
+#ifndef EHOSTUNREACH
+#define EHOSTUNREACH 9911
+#endif
+
+#ifndef EIDRM
+#define EIDRM 9912
+#endif
+
+#ifndef EMSGSIZE
+#define EMSGSIZE 9913
+#endif
+
+#ifndef ENETDOWN
+#define ENETDOWN 9914
+#endif
+
+#ifndef ENETRESET
+#define ENETRESET 9915
+#endif
+
+#ifndef ENETUNREACH
+#define ENETUNREACH 9916
+#endif
+
+#ifndef ENOBUFS
+#define ENOBUFS 9917
+#endif
+
+#ifndef ENOLINK
+#define ENOLINK 9918
+#endif
+
+#ifndef ENODATA
+#define ENODATA 9919
+#endif
+
+#ifndef ENOMSG
+#define ENOMSG 9920
+#endif
+
+#ifndef ENOPROTOOPT
+#define ENOPROTOOPT 9921
+#endif
+
+#ifndef ENOSR
+#define ENOSR 9922
+#endif
+
+#ifndef ENOTSOCK
+#define ENOTSOCK 9923
+#endif
+
+#ifndef ENOSTR
+#define ENOSTR 9924
+#endif
+
+#ifndef ENOTCONN
+#define ENOTCONN 9925
+#endif
+
+#ifndef ENOTSUP
+#define ENOTSUP 9926
+#endif
+
+#ifndef ECANCELED
+#define ECANCELED 9927
+#endif
+
+#ifndef EINPROGRESS
+#define EINPROGRESS 9928
+#endif
+
+#ifndef EOPNOTSUPP
+#define EOPNOTSUPP 9929
+#endif
+
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK 9930
+#endif
+
+#ifndef EOWNERDEAD
+#define EOWNERDEAD  9931
+#endif
+
+#ifndef EPROTO
+#define EPROTO 9932
+#endif
+
+#ifndef EPROTONOSUPPORT
+#define EPROTONOSUPPORT 9933
+#endif
+
+#ifndef ENOTRECOVERABLE
+#define ENOTRECOVERABLE 9934
+#endif
+
+#ifndef ETIME
+#define ETIME 9935
+#endif
+
+#ifndef ETXTBSY
+#define ETXTBSY 9936
+#endif
+
+#ifndef ETIMEDOUT
+#define ETIMEDOUT 9938
+#endif
+
+#ifndef ELOOP
+#define ELOOP 9939
+#endif
+
+#ifndef EOVERFLOW
+#define EOVERFLOW 9940
+#endif
+
+#ifndef EPROTOTYPE
+#define EPROTOTYPE 9941
+#endif
+
+#ifndef ENOSYS
+#define ENOSYS 9942
+#endif
+
+#ifndef EINVAL
+#define EINVAL 9943
+#endif
+
+#ifndef ERANGE
+#define ERANGE 9944
+#endif
+
+#ifndef EILSEQ
+#define EILSEQ 9945
+#endif
+
+//  Windows Mobile doesn't appear to define these:
+
+#ifndef E2BIG
+#define E2BIG 9946
+#endif
+
+#ifndef EDOM
+#define EDOM 9947
+#endif
+
+#ifndef EFAULT
+#define EFAULT 9948
+#endif
+
+#ifndef EBADF
+#define EBADF 9949
+#endif
+
+#ifndef EPIPE
+#define EPIPE 9950
+#endif
+
+#ifndef EXDEV
+#define EXDEV 9951
+#endif
+
+#ifndef EBUSY
+#define EBUSY 9952
+#endif
+
+#ifndef ENOTEMPTY
+#define ENOTEMPTY 9953
+#endif
+
+#ifndef ENOEXEC
+#define ENOEXEC 9954
+#endif
+
+#ifndef EEXIST
+#define EEXIST 9955
+#endif
+
+#ifndef EFBIG
+#define EFBIG 9956
+#endif
+
+#ifndef ENAMETOOLONG
+#define ENAMETOOLONG 9957
+#endif
+
+#ifndef ENOTTY
+#define ENOTTY 9958
+#endif
+
+#ifndef EINTR
+#define EINTR 9959
+#endif
+
+#ifndef ESPIPE
+#define ESPIPE 9960
+#endif
+
+#ifndef EIO
+#define EIO 9961
+#endif
+
+#ifndef EISDIR
+#define EISDIR 9962
+#endif
+
+#ifndef ECHILD
+#define ECHILD 9963
+#endif
+
+#ifndef ENOLCK
+#define ENOLCK 9964
+#endif
+
+#ifndef ENOSPC
+#define ENOSPC 9965
+#endif
+
+#ifndef ENXIO
+#define ENXIO 9966
+#endif
+
+#ifndef ENODEV
+#define ENODEV 9967
+#endif
+
+#ifndef ENOENT
+#define ENOENT 9968
+#endif
+
+#ifndef ESRCH
+#define ESRCH 9969
+#endif
+
+#ifndef ENOTDIR
+#define ENOTDIR 9970
+#endif
+
+#ifndef ENOMEM
+#define ENOMEM 9971
+#endif
+
+#ifndef EPERM
+#define EPERM 9972
+#endif
+
+#ifndef EACCES
+#define EACCES 9973
+#endif
+
+#ifndef EROFS
+#define EROFS 9974
+#endif
+
+#ifndef EDEADLK
+#define EDEADLK 9975
+#endif
+
+#ifndef EAGAIN
+#define EAGAIN 9976
+#endif
+
+#ifndef ENFILE
+#define ENFILE 9977
+#endif
+
+#ifndef EMFILE
+#define EMFILE 9978
+#endif
+
+#ifndef EMLINK
+#define EMLINK 9979
+#endif
+
 #endif  // _LIBCPP_CERRNO
diff --git a/include/cfenv b/include/cfenv
index 4fc6304..dd7db37 100644
--- a/include/cfenv
+++ b/include/cfenv
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===---------------------------- cfenv -----------------------------------===//
+//===---------------------------- cctype ----------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
diff --git a/include/cfloat b/include/cfloat
index 176fa9d..5fa5655 100644
--- a/include/cfloat
+++ b/include/cfloat
@@ -67,4 +67,12 @@
 #pragma GCC system_header
 #endif
 
+#ifndef FLT_EVAL_METHOD
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif
+
+#ifndef DECIMAL_DIG
+#define DECIMAL_DIG __DECIMAL_DIG__
+#endif
+
 #endif  // _LIBCPP_CFLOAT
diff --git a/include/chrono b/include/chrono
index 68484e9..9229234 100644
--- a/include/chrono
+++ b/include/chrono
@@ -26,9 +26,6 @@
 
 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
 
-template <class Rep> constexpr bool treat_as_floating_point_v
-    = treat_as_floating_point<Rep>::value;                       // C++17
-
 template <class Rep>
 struct duration_values
 {
@@ -197,13 +194,6 @@
 template <class ToDuration, class Rep, class Period>
   ToDuration duration_cast(const duration<Rep, Period>& d);
 
-template <class ToDuration, class Rep, class Period>
-    constexpr ToDuration floor(const duration<Rep, Period>& d);    // C++17
-template <class ToDuration, class Rep, class Period>
-    constexpr ToDuration ceil(const duration<Rep, Period>& d);     // C++17
-template <class ToDuration, class Rep, class Period>
-    constexpr ToDuration round(const duration<Rep, Period>& d);    // C++17
-
 // time_point arithmetic (all constexpr in C++14)
 template <class Clock, class Duration1, class Rep2, class Period2>
   time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
@@ -237,20 +227,6 @@
 template <class ToDuration, class Clock, class Duration>
   time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
 
-template <class ToDuration, class Clock, class Duration>
-    constexpr time_point<Clock, ToDuration>
-    floor(const time_point<Clock, Duration>& tp);                  // C++17
-
-template <class ToDuration, class Clock, class Duration>
-    constexpr time_point<Clock, ToDuration>
-    ceil(const time_point<Clock, Duration>& tp);                   // C++17
-
-template <class ToDuration, class Clock, class Duration>
-    constexpr time_point<Clock, ToDuration>
-    round(const time_point<Clock, Duration>& tp);                  // C++17
-
-template <class Rep, class Period>
-    constexpr duration<Rep, Period> abs(duration<Rep, Period> d);  // C++17
 // Clocks
 
 class system_clock
@@ -416,11 +392,6 @@
 template <class _Rep>
 struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Rep> _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
-    = treat_as_floating_point<_Rep>::value;
-#endif
-
 template <class _Rep>
 struct _LIBCPP_TYPE_VIS_ONLY duration_values
 {
@@ -430,58 +401,6 @@
     _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  {return numeric_limits<_Rep>::lowest();}
 };
 
-#if _LIBCPP_STD_VER > 14
-template <class _ToDuration, class _Rep, class _Period>
-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 <class _ToDuration, class _Rep, class _Period>
-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 <class _ToDuration, class _Rep, class _Period>
-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 _Rep, class _Period>
@@ -888,56 +807,6 @@
     return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
 }
 
-#if _LIBCPP_STD_VER > 14
-template <class _ToDuration, class _Clock, class _Duration>
-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 <class _ToDuration, class _Clock, class _Duration>
-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 <class _ToDuration, class _Clock, class _Duration>
-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 <class _Rep, class _Period>
-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 <class _Clock, class _Duration1, class _Duration2>
diff --git a/include/cinttypes b/include/cinttypes
index 3f61b06..cfd763c 100644
--- a/include/cinttypes
+++ b/include/cinttypes
@@ -246,7 +246,10 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using::imaxdiv_t;
+
+#undef imaxabs
 using::imaxabs;
+#undef imaxdiv
 using::imaxdiv;
 using::strtoimax;
 using::strtoumax;
diff --git a/include/cmath b/include/cmath
index b3e9594..5f9aaed 100644
--- a/include/cmath
+++ b/include/cmath
@@ -209,10 +209,6 @@
 float          hypotf(float x, float y);
 long double    hypotl(long double x, long double y);
 
-double       hypot(double x, double y, double z);                // C++17
-float        hypot(float x, float y, float z);                   // C++17
-long double  hypot(long double x, long double y, long double z); // C++17
-
 int ilogb (arithmetic x);
 int ilogbf(float x);
 int ilogbl(long double x);
@@ -303,11 +299,340 @@
 
 #include <__config>
 #include <math.h>
+#include <type_traits>
+
+#ifdef _LIBCPP_MSVCRT
+#include "support/win32/math_win32.h"
+#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
+// signbit
+
+#ifdef signbit
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT
+{
+    return signbit(__lcpp_x);
+}
+
+#undef signbit
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+signbit(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // signbit
+
+// fpclassify
+
+#ifdef fpclassify
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+int
+__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT
+{
+    return fpclassify(__lcpp_x);
+}
+
+#undef fpclassify
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
+fpclassify(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // fpclassify
+
+// isfinite
+
+#ifdef isfinite
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
+{
+    return isfinite(__lcpp_x);
+}
+
+#undef isfinite
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isfinite(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // isfinite
+
+// isinf
+
+#ifdef isinf
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
+{
+    return isinf(__lcpp_x);
+}
+
+#undef isinf
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isinf(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // isinf
+
+// isnan
+
+#ifdef isnan
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
+{
+    return isnan(__lcpp_x);
+}
+
+#undef isnan
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isnan(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // isnan
+
+// isnormal
+
+#ifdef isnormal
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT
+{
+    return isnormal(__lcpp_x);
+}
+
+#undef isnormal
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
+isnormal(_A1 __lcpp_x) _NOEXCEPT
+{
+    return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x);
+}
+
+#endif  // isnormal
+
+// isgreater
+
+#ifdef isgreater
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return isgreater(__lcpp_x, __lcpp_y);
+}
+
+#undef isgreater
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // isgreater
+
+// isgreaterequal
+
+#ifdef isgreaterequal
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return isgreaterequal(__lcpp_x, __lcpp_y);
+}
+
+#undef isgreaterequal
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // isgreaterequal
+
+// isless
+
+#ifdef isless
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return isless(__lcpp_x, __lcpp_y);
+}
+
+#undef isless
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // isless
+
+// islessequal
+
+#ifdef islessequal
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return islessequal(__lcpp_x, __lcpp_y);
+}
+
+#undef islessequal
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // islessequal
+
+// islessgreater
+
+#ifdef islessgreater
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return islessgreater(__lcpp_x, __lcpp_y);
+}
+
+#undef islessgreater
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // islessgreater
+
+// isunordered
+
+#ifdef isunordered
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    return isunordered(__lcpp_x, __lcpp_y);
+}
+
+#undef isunordered
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::enable_if
+<
+    std::is_arithmetic<_A1>::value &&
+    std::is_arithmetic<_A2>::value,
+    bool
+>::type
+isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename std::__promote<_A1, _A2>::type type;
+    return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y);
+}
+
+#endif  // isunordered
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::signbit;
@@ -327,130 +652,794 @@
 using ::float_t;
 using ::double_t;
 
-#ifndef _AIX
+// abs
+
+#if defined(__sun__)
 using ::abs;
 #endif
 
+#if !defined(_AIX) && !defined(__sun__)
+inline _LIBCPP_INLINE_VISIBILITY
+float
+abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
+#endif // !defined(_AIX)
+
 #ifndef __sun__
+
+// acos
+
 using ::acos;
 using ::acosf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       acos(float __lcpp_x) _NOEXCEPT       {return acosf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);}
+
+// asin
+
 using ::asin;
 using ::asinf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       asin(float __lcpp_x) _NOEXCEPT       {return asinf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);}
+
+// atan
+
 using ::atan;
 using ::atanf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       atan(float __lcpp_x) _NOEXCEPT       {return atanf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);}
+
+// atan2
+
 using ::atan2;
 using ::atan2f;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT             {return atan2f(__lcpp_y, __lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);}
+#endif
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x);
+}
+
+// ceil
+
 using ::ceil;
 using ::ceilf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __lcpp_x) _NOEXCEPT       {return ceilf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);}
+
+// cos
+
 using ::cos;
 using ::cosf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       cos(float __lcpp_x) _NOEXCEPT       {return cosf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return cosl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cos(_A1 __lcpp_x) _NOEXCEPT {return cos((double)__lcpp_x);}
+
+// cosh
+
 using ::cosh;
 using ::coshf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __lcpp_x) _NOEXCEPT       {return coshf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return coshl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cosh(_A1 __lcpp_x) _NOEXCEPT {return cosh((double)__lcpp_x);}
+
 #endif // __sun__
+// exp
 
 using ::exp;
 using ::expf;
 
 #ifndef __sun__
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       exp(float __lcpp_x) _NOEXCEPT       {return expf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return expl(__lcpp_x);}
+#endif
+
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+exp(_A1 __lcpp_x) _NOEXCEPT {return exp((double)__lcpp_x);}
+
+// fabs
+
 using ::fabs;
 using ::fabsf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __lcpp_x) _NOEXCEPT       {return fabsf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+fabs(_A1 __lcpp_x) _NOEXCEPT {return fabs((double)__lcpp_x);}
+
+// floor
+
 using ::floor;
 using ::floorf;
-#endif //__sun__
 
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       floor(float __lcpp_x) _NOEXCEPT       {return floorf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return floorl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+floor(_A1 __lcpp_x) _NOEXCEPT {return floor((double)__lcpp_x);}
+
+// fmod
+
+#endif //__sun__
 using ::fmod;
 using ::fmodf;
-
 #ifndef __sun__
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmodf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmodl(__lcpp_x, __lcpp_y);}
+#endif
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+
+// frexp
+
 using ::frexp;
 using ::frexpf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT       {return frexpf(__lcpp_x, __lcpp_e);}
+inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpl(__lcpp_x, __lcpp_e);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexp((double)__lcpp_x, __lcpp_e);}
+
+// ldexp
+
 using ::ldexp;
 using ::ldexpf;
-#endif // __sun__
 
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT       {return ldexpf(__lcpp_x, __lcpp_e);}
+inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpl(__lcpp_x, __lcpp_e);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexp((double)__lcpp_x, __lcpp_e);}
+
+// log
+
+#endif // __sun__
 using ::log;
 using ::logf;
-
 #ifndef __sun__
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       log(float __lcpp_x) _NOEXCEPT       {return logf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return logl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x);}
+
+
+// log10
+
 using ::log10;
 using ::log10f;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       log10(float __lcpp_x) _NOEXCEPT       {return log10f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return log10l(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log10(_A1 __lcpp_x) _NOEXCEPT {return log10((double)__lcpp_x);}
+
+// modf
+
 using ::modf;
 using ::modff;
-#endif // __sun__ 
 
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT             {return modff(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return modfl(__lcpp_x, __lcpp_y);}
+#endif
+
+// pow
+
+#endif // __sun__ 
 using ::pow;
 using ::powf;
 
 #ifndef __sun__
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return powf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return powl(__lcpp_x, __lcpp_y);}
+#endif
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return pow((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// sin
+
 using ::sin;
 using ::sinf;
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       sin(float __lcpp_x) _NOEXCEPT       {return sinf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return sinl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sin(_A1 __lcpp_x) _NOEXCEPT {return sin((double)__lcpp_x);}
+
+// sinh
+
 using ::sinh;
 using ::sinhf;
-#endif // __sun__
 
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __lcpp_x) _NOEXCEPT       {return sinhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return sinhl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sinh(_A1 __lcpp_x) _NOEXCEPT {return sinh((double)__lcpp_x);}
+
+// sqrt
+
+#endif // __sun__
 using ::sqrt;
 using ::sqrtf;
+
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(__sun__) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __lcpp_x) _NOEXCEPT       {return sqrtf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return sqrtl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sqrt(_A1 __lcpp_x) _NOEXCEPT {return sqrt((double)__lcpp_x);}
+
+// tan
+
 using ::tan;
 using ::tanf;
-
 #ifndef __sun__
+
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       tan(float __lcpp_x) _NOEXCEPT       {return tanf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return tanl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tan(_A1 __lcpp_x) _NOEXCEPT {return tan((double)__lcpp_x);}
+
+// tanh
+
 using ::tanh;
 using ::tanhf;
 
+#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
+inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __lcpp_x) _NOEXCEPT       {return tanhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return tanhl(__lcpp_x);}
+#endif
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tanh(_A1 __lcpp_x) _NOEXCEPT {return tanh((double)__lcpp_x);}
+
+// acosh
+
 #ifndef _LIBCPP_MSVCRT
 using ::acosh;
 using ::acoshf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __lcpp_x) _NOEXCEPT       {return acoshf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+acosh(_A1 __lcpp_x) _NOEXCEPT {return acosh((double)__lcpp_x);}
+#endif
+
+// asinh
+
+#ifndef _LIBCPP_MSVCRT
 using ::asinh;
 using ::asinhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __lcpp_x) _NOEXCEPT       {return asinhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+asinh(_A1 __lcpp_x) _NOEXCEPT {return asinh((double)__lcpp_x);}
+#endif
+
+// atanh
+
+#ifndef _LIBCPP_MSVCRT
 using ::atanh;
 using ::atanhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __lcpp_x) _NOEXCEPT       {return atanhf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+atanh(_A1 __lcpp_x) _NOEXCEPT {return atanh((double)__lcpp_x);}
+#endif
+
+// cbrt
+
+#ifndef _LIBCPP_MSVCRT
 using ::cbrt;
 using ::cbrtf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __lcpp_x) _NOEXCEPT       {return cbrtf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cbrt(_A1 __lcpp_x) _NOEXCEPT {return cbrt((double)__lcpp_x);}
 #endif
 
+// copysign
+
 using ::copysign;
 using ::copysignf;
 
+#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
+inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
+                                                float __lcpp_y) _NOEXCEPT {
+  return copysignf(__lcpp_x, __lcpp_y);
+}
+inline _LIBCPP_INLINE_VISIBILITY long double
+copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
+  return copysignl(__lcpp_x, __lcpp_y);
+}
+#endif
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
 #ifndef _LIBCPP_MSVCRT
+
+// erf
+
 using ::erf;
 using ::erff;
+
+inline _LIBCPP_INLINE_VISIBILITY float       erf(float __lcpp_x) _NOEXCEPT       {return erff(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return erfl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+erf(_A1 __lcpp_x) _NOEXCEPT {return erf((double)__lcpp_x);}
+
+// erfc
+
 using ::erfc;
 using ::erfcf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __lcpp_x) _NOEXCEPT       {return erfcf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return erfcl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+erfc(_A1 __lcpp_x) _NOEXCEPT {return erfc((double)__lcpp_x);}
+
+// exp2
+
 using ::exp2;
 using ::exp2f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __lcpp_x) _NOEXCEPT       {return exp2f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return exp2l(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+exp2(_A1 __lcpp_x) _NOEXCEPT {return exp2((double)__lcpp_x);}
+
+// expm1
+
 using ::expm1;
 using ::expm1f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __lcpp_x) _NOEXCEPT       {return expm1f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return expm1l(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+expm1(_A1 __lcpp_x) _NOEXCEPT {return expm1((double)__lcpp_x);}
+
+// fdim
+
 using ::fdim;
 using ::fdimf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fdimf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fdiml(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// fma
+
 using ::fmaf;
 using ::fma;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT                   {return fmaf(__lcpp_x, __lcpp_y, __lcpp_z);}
+inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return fmal(__lcpp_x, __lcpp_y, __lcpp_z);}
+
+template <class _A1, class _A2, class _A3>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value &&
+    is_arithmetic<_A3>::value,
+    __promote<_A1, _A2, _A3>
+>::type
+fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2, _A3>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value &&
+                      is_same<_A3, __result_type>::value)), "");
+    return fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
+}
+
+// fmax
+
 using ::fmax;
 using ::fmaxf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmaxf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmaxl(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// fmin
+
 using ::fmin;
 using ::fminf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fminf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fminl(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// hypot
+
 using ::hypot;
 using ::hypotf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return hypotf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return hypotl(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// ilogb
+
 using ::ilogb;
 using ::ilogbf;
+
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT       {return ilogbf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ilogbl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, int>::type
+ilogb(_A1 __lcpp_x) _NOEXCEPT {return ilogb((double)__lcpp_x);}
+
+// lgamma
+
 using ::lgamma;
 using ::lgammaf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __lcpp_x) _NOEXCEPT       {return lgammaf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return lgammal(__lcpp_x);}
+
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+lgamma(_A1 __lcpp_x) _NOEXCEPT {return lgamma((double)__lcpp_x);}
+
+
+// llrint
+
 using ::llrint;
 using ::llrintf;
+
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT       {return llrintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return llrintl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long long>::type
+llrint(_A1 __lcpp_x) _NOEXCEPT {return llrint((double)__lcpp_x);}
+
+// llround
+
 using ::llround;
 using ::llroundf;
+
+inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT       {return llroundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return llroundl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long long>::type
+llround(_A1 __lcpp_x) _NOEXCEPT {return llround((double)__lcpp_x);}
+
+// log1p
+
 using ::log1p;
 using ::log1pf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __lcpp_x) _NOEXCEPT       {return log1pf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return log1pl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log1p(_A1 __lcpp_x) _NOEXCEPT {return log1p((double)__lcpp_x);}
+
+// log2
+
 using ::log2;
 using ::log2f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log2(float __lcpp_x) _NOEXCEPT       {return log2f(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return log2l(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log2(_A1 __lcpp_x) _NOEXCEPT {return log2((double)__lcpp_x);}
+
+// logb
+
 using ::logb;
 using ::logbf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       logb(float __lcpp_x) _NOEXCEPT       {return logbf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return logbl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+logb(_A1 __lcpp_x) _NOEXCEPT {return logb((double)__lcpp_x);}
+
+// lrint
+
 using ::lrint;
 using ::lrintf;
+
+inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT       {return lrintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return lrintl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long>::type
+lrint(_A1 __lcpp_x) _NOEXCEPT {return lrint((double)__lcpp_x);}
+
+// lround
+
 using ::lround;
 using ::lroundf;
+
+inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT       {return lroundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return lroundl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long>::type
+lround(_A1 __lcpp_x) _NOEXCEPT {return lround((double)__lcpp_x);}
+
 #endif // _LIBCPP_MSVCRT
 #endif // __sun__
 
+// nan
+
 #ifndef _LIBCPP_MSVCRT
 using ::nan;
 using ::nanf;
@@ -458,28 +1447,183 @@
 
 #ifndef __sun__
 #ifndef _LIBCPP_MSVCRT
+
+// nearbyint
+
 using ::nearbyint;
 using ::nearbyintf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __lcpp_x) _NOEXCEPT       {return nearbyintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return nearbyintl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+nearbyint(_A1 __lcpp_x) _NOEXCEPT {return nearbyint((double)__lcpp_x);}
+
+// nextafter
+
 using ::nextafter;
 using ::nextafterf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return nextafterf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nextafterl(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// nexttoward
+
 using ::nexttoward;
 using ::nexttowardf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT       {return nexttowardf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardl(__lcpp_x, __lcpp_y);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttoward((double)__lcpp_x, __lcpp_y);}
+
+// remainder
+
 using ::remainder;
 using ::remainderf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return remainderf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return remainderl(__lcpp_x, __lcpp_y);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y);
+}
+
+// remquo
+
 using ::remquo;
 using ::remquof;
+
+inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT             {return remquof(__lcpp_x, __lcpp_y, __lcpp_z);}
+inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquol(__lcpp_x, __lcpp_y, __lcpp_z);}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __lazy_enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    __promote<_A1, _A2>
+>::type
+remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z);
+}
+
+// rint
+
 using ::rint;
 using ::rintf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       rint(float __lcpp_x) _NOEXCEPT       {return rintf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return rintl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+rint(_A1 __lcpp_x) _NOEXCEPT {return rint((double)__lcpp_x);}
+
+// round
+
 using ::round;
 using ::roundf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       round(float __lcpp_x) _NOEXCEPT       {return roundf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return roundl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+round(_A1 __lcpp_x) _NOEXCEPT {return round((double)__lcpp_x);}
+
+// scalbln
+
 using ::scalbln;
 using ::scalblnf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT       {return scalblnf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnl(__lcpp_x, __lcpp_y);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalbln((double)__lcpp_x, __lcpp_y);}
+
+// scalbn
+
 using ::scalbn;
 using ::scalbnf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT       {return scalbnf(__lcpp_x, __lcpp_y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnl(__lcpp_x, __lcpp_y);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbn((double)__lcpp_x, __lcpp_y);}
+
+// tgamma
+
 using ::tgamma;
 using ::tgammaf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __lcpp_x) _NOEXCEPT       {return tgammaf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return tgammal(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tgamma(_A1 __lcpp_x) _NOEXCEPT {return tgamma((double)__lcpp_x);}
+
+// trunc
+
 using ::trunc;
 using ::truncf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __lcpp_x) _NOEXCEPT       {return truncf(__lcpp_x);}
+inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return truncl(__lcpp_x);}
+
+template <class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+trunc(_A1 __lcpp_x) _NOEXCEPT {return trunc((double)__lcpp_x);}
+
 #endif // !_LIBCPP_MSVCRT
 
 using ::acosl;
@@ -503,7 +1647,6 @@
 using ::sinhl;
 using ::sqrtl;
 using ::tanl;
-
 #ifndef _LIBCPP_MSVCRT
 using ::tanhl;
 using ::acoshl;
@@ -511,9 +1654,7 @@
 using ::atanhl;
 using ::cbrtl;
 #endif  // !_LIBCPP_MSVCRT
-
 using ::copysignl;
-
 #ifndef _LIBCPP_MSVCRT
 using ::erfl;
 using ::erfcl;
@@ -551,31 +1692,6 @@
 using ::lgamma;
 using ::lgammaf;
 #endif // __sun__
-
-#if _LIBCPP_STD_VER > 14
-inline _LIBCPP_INLINE_VISIBILITY float       hypot(       float x,       float y,       float z ) { return sqrt(x*x + y*y + z*z); }
-inline _LIBCPP_INLINE_VISIBILITY double      hypot(      double x,      double y,      double z ) { return sqrt(x*x + y*y + z*z); }
-inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
-
-template <class _A1, class _A2, class _A3>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value &&
-    std::is_arithmetic<_A3>::value,
-    std::__promote<_A1, _A2, _A3>
->::type
-hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value &&
-                     std::is_same<_A3, __result_type>::value)), "");
-    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
-}
-#endif
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_CMATH
diff --git a/include/complex b/include/complex
index f56138f..2943da1 100644
--- a/include/complex
+++ b/include/complex
@@ -332,9 +332,7 @@
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f)
         : __re_(__re), __im_(__im) {}
-    _LIBCPP_INLINE_VISIBILITY
     explicit _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
-    _LIBCPP_INLINE_VISIBILITY
     explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;}
@@ -390,9 +388,7 @@
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0)
         : __re_(__re), __im_(__im) {}
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
-    _LIBCPP_INLINE_VISIBILITY
     explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;}
@@ -448,9 +444,7 @@
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L)
         : __re_(__re), __im_(__im) {}
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR complex(const complex<float>& __c);
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;}
@@ -496,32 +490,32 @@
         }
 };
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<float>::complex(const complex<double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<float>::complex(const complex<long double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<double>::complex(const complex<float>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<double>::complex(const complex<long double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<long double>::complex(const complex<float>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 complex<long double>::complex(const complex<double>& __c)
     : __re_(__c.real()), __im_(__c.imag()) {}
@@ -1405,7 +1399,7 @@
     }
     if (isinf(__x.imag()))
         return complex<_Tp>(__pi/_Tp(2), -__x.imag());
-    if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag())))
+    if (__x.real() == 0)
         return complex<_Tp>(__pi/_Tp(2), -__x.imag());
     complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1)));
     if (signbit(__x.imag()))
diff --git a/include/complex.h b/include/complex.h
index c235966..7003d31 100644
--- a/include/complex.h
+++ b/include/complex.h
@@ -18,12 +18,6 @@
 
 */
 
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
 #ifdef __cplusplus
 
 #include <ccomplex>
@@ -34,4 +28,8 @@
 
 #endif  // __cplusplus
 
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
 #endif  // _LIBCPP_COMPLEX_H
diff --git a/include/condition_variable b/include/condition_variable
index 10e0077..1af2484 100644
--- a/include/condition_variable
+++ b/include/condition_variable
@@ -124,18 +124,14 @@
     condition_variable __cv_;
     shared_ptr<mutex>  __mut_;
 public:
-    _LIBCPP_INLINE_VISIBILITY
     condition_variable_any();
 
-    _LIBCPP_INLINE_VISIBILITY
     void notify_one() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     void notify_all() _NOEXCEPT;
 
     template <class _Lock>
         void wait(_Lock& __lock);
     template <class _Lock, class _Predicate>
-        _LIBCPP_INLINE_VISIBILITY
         void wait(_Lock& __lock, _Predicate __pred);
 
     template <class _Lock, class _Clock, class _Duration>
@@ -145,30 +141,27 @@
 
     template <class _Lock, class _Clock, class _Duration, class _Predicate>
         bool
-        _LIBCPP_INLINE_VISIBILITY
         wait_until(_Lock& __lock,
                    const chrono::time_point<_Clock, _Duration>& __t,
                    _Predicate __pred);
 
     template <class _Lock, class _Rep, class _Period>
         cv_status
-        _LIBCPP_INLINE_VISIBILITY
         wait_for(_Lock& __lock,
                  const chrono::duration<_Rep, _Period>& __d);
 
     template <class _Lock, class _Rep, class _Period, class _Predicate>
         bool
-        _LIBCPP_INLINE_VISIBILITY
         wait_for(_Lock& __lock,
                  const chrono::duration<_Rep, _Period>& __d,
                  _Predicate __pred);
 };
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 condition_variable_any::condition_variable_any()
     : __mut_(make_shared<mutex>()) {}
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 condition_variable_any::notify_one() _NOEXCEPT
 {
@@ -176,7 +169,7 @@
     __cv_.notify_one();
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 condition_variable_any::notify_all() _NOEXCEPT
 {
@@ -203,7 +196,7 @@
 }  // __mut_.unlock(), __lock.lock()
 
 template <class _Lock, class _Predicate>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 condition_variable_any::wait(_Lock& __lock, _Predicate __pred)
 {
@@ -225,7 +218,7 @@
 }  // __mut_.unlock(), __lock.lock()
 
 template <class _Lock, class _Clock, class _Duration, class _Predicate>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 condition_variable_any::wait_until(_Lock& __lock,
                                    const chrono::time_point<_Clock, _Duration>& __t,
@@ -238,7 +231,7 @@
 }
 
 template <class _Lock, class _Rep, class _Period>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 cv_status
 condition_variable_any::wait_for(_Lock& __lock,
                                  const chrono::duration<_Rep, _Period>& __d)
@@ -247,7 +240,7 @@
 }
 
 template <class _Lock, class _Rep, class _Period, class _Predicate>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 condition_variable_any::wait_for(_Lock& __lock,
                                  const chrono::duration<_Rep, _Period>& __d,
diff --git a/include/csetjmp b/include/csetjmp
index 58a9c73..d0b2c07 100644
--- a/include/csetjmp
+++ b/include/csetjmp
@@ -38,6 +38,10 @@
 #pragma GCC system_header
 #endif
 
+#ifndef setjmp
+#define setjmp(env) setjmp(env)
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::jmp_buf;
diff --git a/include/cstddef b/include/cstddef
index edd106c..c3ca64a 100644
--- a/include/cstddef
+++ b/include/cstddef
@@ -35,14 +35,12 @@
 
 #include <__config>
 
+#include <stddef.h>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
-#include_next <stddef.h>
-#include <__nullptr>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::ptrdiff_t;
@@ -55,6 +53,50 @@
 typedef long double max_align_t;
 #endif
 
+#ifdef _LIBCPP_HAS_NO_NULLPTR
+
+struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
+{
+    void* __lx;
+
+    struct __nat {int __for_bool_;};
+
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
+
+    _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
+
+    template <class _Tp>
+        _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
+        operator _Tp* () const {return 0;}
+
+    template <class _Tp, class _Up>
+        _LIBCPP_ALWAYS_INLINE
+        operator _Tp _Up::* () const {return 0;}
+
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
+};
+
+inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
+
+#define nullptr _VSTD::__get_nullptr_t()
+
+#endif  // _LIBCPP_HAS_NO_NULLPTR
+
 _LIBCPP_END_NAMESPACE_STD
 
+#ifndef _LIBCPP_HAS_NO_NULLPTR
+
+namespace std
+{
+    typedef decltype(nullptr) nullptr_t;
+}
+
+#endif  // _LIBCPP_HAS_NO_NULLPTR
+
 #endif  // _LIBCPP_CSTDDEF
diff --git a/include/cstdio b/include/cstdio
index 50fdd34..d8ba6c2 100644
--- a/include/cstdio
+++ b/include/cstdio
@@ -103,6 +103,41 @@
 #pragma GCC system_header
 #endif
 
+// snprintf
+#if defined(_LIBCPP_MSVCRT)
+#include "support/win32/support.h"
+#endif
+
+#ifdef getc
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_getc(FILE* __stream) {return getc(__stream);}
+#undef getc
+inline _LIBCPP_INLINE_VISIBILITY int getc(FILE* __stream) {return __libcpp_getc(__stream);}
+#endif  // getc
+
+#ifdef putc
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_putc(int __c, FILE* __stream) {return putc(__c, __stream);}
+#undef putc
+inline _LIBCPP_INLINE_VISIBILITY int putc(int __c, FILE* __stream) {return __libcpp_putc(__c, __stream);}
+#endif  // putc
+
+#ifdef clearerr
+inline _LIBCPP_INLINE_VISIBILITY void __libcpp_clearerr(FILE* __stream) { return clearerr(__stream); }
+#undef clearerr
+inline _LIBCPP_INLINE_VISIBILITY void clearerr(FILE* __stream) { return __libcpp_clearerr(__stream); }
+#endif  // clearerr
+
+#ifdef feof
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_feof(FILE* __stream) { return feof(__stream); }
+#undef feof
+inline _LIBCPP_INLINE_VISIBILITY int feof(FILE* __stream) { return __libcpp_feof(__stream); }
+#endif  // feof
+
+#ifdef ferror
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ferror(FILE* __stream) { return ferror(__stream); }
+#undef ferror
+inline _LIBCPP_INLINE_VISIBILITY int ferror(FILE* __stream) { return __libcpp_ferror(__stream); }
+#endif  // ferror
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 using ::FILE;
diff --git a/include/cstdlib b/include/cstdlib
index 10ed231..55e15c8 100644
--- a/include/cstdlib
+++ b/include/cstdlib
@@ -84,6 +84,9 @@
 
 #include <__config>
 #include <stdlib.h>
+#ifdef _LIBCPP_MSVCRT
+#include "support/win32/locale_win32.h"
+#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -128,14 +131,20 @@
 using ::system;
 using ::bsearch;
 using ::qsort;
+#undef abs
 using ::abs;
+#undef labs
 using ::labs;
 #ifndef _LIBCPP_HAS_NO_LONG_LONG
+#undef llabs
 using ::llabs;
 #endif // _LIBCPP_HAS_NO_LONG_LONG
+#undef div
 using ::div;
+#undef ldiv
 using ::ldiv;
 #ifndef _LIBCPP_HAS_NO_LONG_LONG
+#undef lldiv
 using ::lldiv;
 #endif // _LIBCPP_HAS_NO_LONG_LONG
 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
@@ -153,6 +162,19 @@
 using ::aligned_alloc;
 #endif
 
+// MSVCRT already has the correct prototype in <stdlib.h> #ifdef __cplusplus
+#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
+inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
+inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
+#endif // _LIBCPP_HAS_NO_LONG_LONG
+
+inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
+#ifndef _LIBCPP_HAS_NO_LONG_LONG
+inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
+#endif // _LIBCPP_HAS_NO_LONG_LONG
+#endif // _LIBCPP_MSVCRT
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_CSTDLIB
diff --git a/include/cstring b/include/cstring
index d550695..d60b992 100644
--- a/include/cstring
+++ b/include/cstring
@@ -78,13 +78,30 @@
 using ::strncmp;
 using ::strcoll;
 using ::strxfrm;
+
 using ::memchr;
+
 using ::strchr;
+
 using ::strcspn;
+
 using ::strpbrk;
+
 using ::strrchr;
+
 using ::strspn;
+
 using ::strstr;
+
+// MSVCRT, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
+#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       void* memchr(      void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strstr(      char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
+#endif
+
 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
 using ::strtok;
 #endif
diff --git a/include/ctype.h b/include/ctype.h
deleted file mode 100644
index 22d6c49..0000000
--- a/include/ctype.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// -*- C++ -*-
-//===---------------------------- ctype.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_CTYPE_H
-#define _LIBCPP_CTYPE_H
-
-/*
-    ctype.h synopsis
-
-int isalnum(int c);
-int isalpha(int c);
-int isblank(int c);  // C99
-int iscntrl(int c);
-int isdigit(int c);
-int isgraph(int c);
-int islower(int c);
-int isprint(int c);
-int ispunct(int c);
-int isspace(int c);
-int isupper(int c);
-int isxdigit(int c);
-int tolower(int c);
-int toupper(int c);
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <ctype.h>
-
-#ifdef __cplusplus
-
-#if defined(_LIBCPP_MSVCRT)
-// We support including .h headers inside 'extern "C"' contexts, so switch
-// back to C++ linkage before including these C++ headers.
-extern "C++" {
-  #include "support/win32/support.h"
-  #include "support/win32/locale_win32.h"
-}
-#endif // _LIBCPP_MSVCRT
-
-#undef isalnum
-#undef isalpha
-#undef isblank
-#undef iscntrl
-#undef isdigit
-#undef isgraph
-#undef islower
-#undef isprint
-#undef ispunct
-#undef isspace
-#undef isupper
-#undef isxdigit
-#undef tolower
-#undef toupper
-
-#endif
-
-#endif  // _LIBCPP_CTYPE_H
diff --git a/include/cwchar b/include/cwchar
index 52dde9e..797a177 100644
--- a/include/cwchar
+++ b/include/cwchar
@@ -106,6 +106,9 @@
 #include <__config>
 #include <cwctype>
 #include <wchar.h>
+#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+#include <support/win32/support.h> // pull in *swprintf defines
+#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -157,11 +160,34 @@
 using ::wcscoll;
 using ::wcsncmp;
 using ::wcsxfrm;
+
+#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
+
 using ::wcschr;
 using ::wcspbrk;
 using ::wcsrchr;
 using ::wcsstr;
 using ::wmemchr;
+
+#else
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
+
+#endif
+
 using ::wcscspn;
 using ::wcslen;
 using ::wcsspn;
diff --git a/include/cwctype b/include/cwctype
index 25b2489..4f89b52 100644
--- a/include/cwctype
+++ b/include/cwctype
@@ -63,24 +63,150 @@
 using ::wint_t;
 using ::wctrans_t;
 using ::wctype_t;
+
+#ifdef iswalnum
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalnum(wint_t __wc) {return iswalnum(__wc);}
+#undef iswalnum
+inline _LIBCPP_INLINE_VISIBILITY int iswalnum(wint_t __wc) {return __libcpp_iswalnum(__wc);}
+#else  // iswalnum
 using ::iswalnum;
+#endif
+
+#ifdef iswalpha
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalpha(wint_t __wc) {return iswalpha(__wc);}
+#undef iswalpha
+inline _LIBCPP_INLINE_VISIBILITY int iswalpha(wint_t __wc) {return __libcpp_iswalpha(__wc);}
+#else  // iswalpha
 using ::iswalpha;
+#endif
+
+#ifdef iswblank
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswblank(wint_t __wc) {return iswblank(__wc);}
+#undef iswblank
+inline _LIBCPP_INLINE_VISIBILITY int iswblank(wint_t __wc) {return __libcpp_iswblank(__wc);}
+#else  // iswblank
 using ::iswblank;
+#endif
+
+#ifdef iswcntrl
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswcntrl(wint_t __wc) {return iswcntrl(__wc);}
+#undef iswcntrl
+inline _LIBCPP_INLINE_VISIBILITY int iswcntrl(wint_t __wc) {return __libcpp_iswcntrl(__wc);}
+#else  // iswcntrl
 using ::iswcntrl;
+#endif
+
+#ifdef iswdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswdigit(wint_t __wc) {return iswdigit(__wc);}
+#undef iswdigit
+inline _LIBCPP_INLINE_VISIBILITY int iswdigit(wint_t __wc) {return __libcpp_iswdigit(__wc);}
+#else  // iswdigit
 using ::iswdigit;
+#endif
+
+#ifdef iswgraph
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswgraph(wint_t __wc) {return iswgraph(__wc);}
+#undef iswgraph
+inline _LIBCPP_INLINE_VISIBILITY int iswgraph(wint_t __wc) {return __libcpp_iswgraph(__wc);}
+#else  // iswgraph
 using ::iswgraph;
+#endif
+
+#ifdef iswlower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswlower(wint_t __wc) {return iswlower(__wc);}
+#undef iswlower
+inline _LIBCPP_INLINE_VISIBILITY int iswlower(wint_t __wc) {return __libcpp_iswlower(__wc);}
+#else  // iswlower
 using ::iswlower;
+#endif
+
+#ifdef iswprint
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswprint(wint_t __wc) {return iswprint(__wc);}
+#undef iswprint
+inline _LIBCPP_INLINE_VISIBILITY int iswprint(wint_t __wc) {return __libcpp_iswprint(__wc);}
+#else  // iswprint
 using ::iswprint;
+#endif
+
+#ifdef iswpunct
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswpunct(wint_t __wc) {return iswpunct(__wc);}
+#undef iswpunct
+inline _LIBCPP_INLINE_VISIBILITY int iswpunct(wint_t __wc) {return __libcpp_iswpunct(__wc);}
+#else  // iswpunct
 using ::iswpunct;
+#endif
+
+#ifdef iswspace
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswspace(wint_t __wc) {return iswspace(__wc);}
+#undef iswspace
+inline _LIBCPP_INLINE_VISIBILITY int iswspace(wint_t __wc) {return __libcpp_iswspace(__wc);}
+#else  // iswspace
 using ::iswspace;
+#endif
+
+#ifdef iswupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswupper(wint_t __wc) {return iswupper(__wc);}
+#undef iswupper
+inline _LIBCPP_INLINE_VISIBILITY int iswupper(wint_t __wc) {return __libcpp_iswupper(__wc);}
+#else  // iswupper
 using ::iswupper;
+#endif
+
+#ifdef iswxdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswxdigit(wint_t __wc) {return iswxdigit(__wc);}
+#undef iswxdigit
+inline _LIBCPP_INLINE_VISIBILITY int iswxdigit(wint_t __wc) {return __libcpp_iswxdigit(__wc);}
+#else  // iswxdigit
 using ::iswxdigit;
+#endif
+
+#ifdef iswctype
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswctype(wint_t __w, wctype_t __d) {return iswctype(__w, __d);}
+#undef iswctype
+inline _LIBCPP_INLINE_VISIBILITY int iswctype(wint_t __w, wctype_t __d) {return __libcpp_iswctype(__w, __d);}
+#else  // iswctype
 using ::iswctype;
+#endif
+
+#ifdef wctype
+inline _LIBCPP_INLINE_VISIBILITY wctype_t __libcpp_wctype(const char* __p) {return wctype(__p);}
+#undef wctype
+inline _LIBCPP_INLINE_VISIBILITY wctype_t wctype(const char* __p) {return __libcpp_wctype(__p);}
+#else  // wctype
 using ::wctype;
+#endif
+
+#ifdef towlower
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towlower(wint_t __wc) {return towlower(__wc);}
+#undef towlower
+inline _LIBCPP_INLINE_VISIBILITY wint_t towlower(wint_t __wc) {return __libcpp_towlower(__wc);}
+#else  // towlower
 using ::towlower;
+#endif
+
+#ifdef towupper
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towupper(wint_t __wc) {return towupper(__wc);}
+#undef towupper
+inline _LIBCPP_INLINE_VISIBILITY wint_t towupper(wint_t __wc) {return __libcpp_towupper(__wc);}
+#else  // towupper
 using ::towupper;
+#endif
+
+#ifdef towctrans
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towctrans(wint_t __wc, wctype_t __d) {return towctrans(__wc, __d);}
+#undef towctrans
+inline _LIBCPP_INLINE_VISIBILITY wint_t towctrans(wint_t __wc, wctype_t __d) {return __libcpp_towctrans(__wc, __d);}
+#else  // towctrans
 using ::towctrans;
+#endif
+
+#ifdef wctrans
+inline _LIBCPP_INLINE_VISIBILITY wctrans_t __libcpp_wctrans(const char* __p) {return wctrans(__p);}
+#undef wctrans
+inline _LIBCPP_INLINE_VISIBILITY wctrans_t wctrans(const char* __p) {return __libcpp_wctrans(__p);}
+#else  // wctrans
 using ::wctrans;
+#endif
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/include/deque b/include/deque
index c6fbd51..87ff8bf 100644
--- a/include/deque
+++ b/include/deque
@@ -261,21 +261,8 @@
               __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
               __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
 
-template <class _ValueType, class _DiffType>
-struct __deque_block_size {
-  static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
-};
-
 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
-          class _DiffType, _DiffType _BS =
-#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
-// Keep template parameter to avoid changing all template declarations thoughout
-// this file.
-                               0
-#else
-                               __deque_block_size<_ValueType, _DiffType>::value
-#endif
-          >
+          class _DiffType, _DiffType _BlockSize>
 class _LIBCPP_TYPE_VIS_ONLY __deque_iterator
 {
     typedef _MapPointer __map_iterator;
@@ -286,7 +273,7 @@
     __map_iterator __m_iter_;
     pointer        __ptr_;
 
-    static const difference_type __block_size;
+    static const difference_type __block_size = _BlockSize;
 public:
     typedef _ValueType                  value_type;
     typedef random_access_iterator_tag  iterator_category;
@@ -300,7 +287,7 @@
 
     template <class _Pp, class _Rp, class _MP>
     _LIBCPP_INLINE_VISIBILITY
-    __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it,
+    __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it,
                 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT
         : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
 
@@ -533,12 +520,6 @@
                   __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
 };
 
-template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
-          class _DiffType, _DiffType _BlockSize>
-const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer,
-                                 _DiffType, _BlockSize>::__block_size =
-    __deque_block_size<_ValueType, _DiffType>::value;
-
 // copy
 
 template <class _RAIter,
@@ -551,11 +532,10 @@
 {
     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;
+        pointer __re = *__r.__m_iter_ + _B2;
         difference_type __bs = __re - __rb;
         difference_type __n = __l - __f;
         _RAIter __m = __l;
@@ -580,12 +560,11 @@
 {
     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;
+        pointer __fe = *__f.__m_iter_ + _B1;
         difference_type __bs = __fe - __fb;
         if (__bs > __n)
         {
@@ -608,12 +587,11 @@
 {
     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;
+        pointer __fe = *__f.__m_iter_ + _B1;
         difference_type __bs = __fe - __fb;
         if (__bs > __n)
         {
@@ -727,11 +705,10 @@
 {
     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;
+        pointer __re = *__r.__m_iter_ + _B2;
         difference_type __bs = __re - __rb;
         difference_type __n = __l - __f;
         _RAIter __m = __l;
@@ -756,12 +733,11 @@
 {
     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;
+        pointer __fe = *__f.__m_iter_ + _B1;
         difference_type __bs = __fe - __fb;
         if (__bs > __n)
         {
@@ -784,12 +760,11 @@
 {
     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;
+        pointer __fe = *__f.__m_iter_ + _B1;
         difference_type __bs = __fe - __fb;
         if (__bs > __n)
         {
@@ -934,7 +909,7 @@
     typedef typename __alloc_traits::pointer         pointer;
     typedef typename __alloc_traits::const_pointer   const_pointer;
 
-    static const difference_type __block_size;
+    static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
 
     typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;
     typedef allocator_traits<__pointer_allocator>        __map_traits;
@@ -944,9 +919,9 @@
     typedef __split_buffer<pointer, __pointer_allocator> __map;
 
     typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
-                             difference_type>    iterator;
+                             difference_type, __block_size>    iterator;
     typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
-                             difference_type>    const_iterator;
+                             difference_type, __block_size>    const_iterator;
 
     __map __map_;
     size_type __start_;
@@ -964,10 +939,8 @@
     _LIBCPP_INLINE_VISIBILITY
     const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
 
-    _LIBCPP_INLINE_VISIBILITY
     __deque_base()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
-    _LIBCPP_INLINE_VISIBILITY
     explicit __deque_base(const allocator_type& __a);
 public:
     ~__deque_base();
@@ -1024,11 +997,6 @@
 };
 
 template <class _Tp, class _Allocator>
-const typename __deque_base<_Tp, _Allocator>::difference_type
-    __deque_base<_Tp, _Allocator>::__block_size =
-        __deque_block_size<value_type, difference_type>::value;
-
-template <class _Tp, class _Allocator>
 bool
 __deque_base<_Tp, _Allocator>::__invariants() const
 {
@@ -1092,13 +1060,13 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __deque_base<_Tp, _Allocator>::__deque_base()
     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
     : __start_(0), __size_(0) {}
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
     : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
 
@@ -1196,9 +1164,6 @@
     typedef _Tp value_type;
     typedef _Allocator allocator_type;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
-                  "Allocator::value_type must be same type as value_type");
-
     typedef __deque_base<value_type, allocator_type> __base;
 
     typedef typename __base::__alloc_traits        __alloc_traits;
@@ -1246,11 +1211,8 @@
 #endif   // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
-    _LIBCPP_INLINE_VISIBILITY
     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<allocator_type>::value);
@@ -1269,7 +1231,6 @@
     void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-    _LIBCPP_INLINE_VISIBILITY
     allocator_type get_allocator() const _NOEXCEPT;
 
     // iterators:
@@ -1322,21 +1283,13 @@
     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:
@@ -1375,7 +1328,6 @@
     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;
@@ -1383,7 +1335,6 @@
         _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
                    __is_nothrow_swappable<allocator_type>::value);
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     void clear() _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1556,7 +1507,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 deque<_Tp, _Allocator>::deque(deque&& __c)
     _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
     : __base(_VSTD::move(__c))
@@ -1564,7 +1515,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
     : __base(_VSTD::move(__c), __a)
 {
@@ -1576,7 +1527,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 deque<_Tp, _Allocator>&
 deque<_Tp, _Allocator>::operator=(deque&& __c)
         _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
@@ -1660,7 +1611,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Allocator
 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
 {
@@ -1719,7 +1670,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::reference
 deque<_Tp, _Allocator>::operator[](size_type __i)
 {
@@ -1728,7 +1679,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::const_reference
 deque<_Tp, _Allocator>::operator[](size_type __i) const
 {
@@ -1737,7 +1688,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::reference
 deque<_Tp, _Allocator>::at(size_type __i)
 {
@@ -1748,7 +1699,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::const_reference
 deque<_Tp, _Allocator>::at(size_type __i) const
 {
@@ -1759,7 +1710,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::reference
 deque<_Tp, _Allocator>::front()
 {
@@ -1768,7 +1719,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::const_reference
 deque<_Tp, _Allocator>::front() const
 {
@@ -1777,7 +1728,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::reference
 deque<_Tp, _Allocator>::back()
 {
@@ -1786,7 +1737,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename deque<_Tp, _Allocator>::const_reference
 deque<_Tp, _Allocator>::back() const
 {
@@ -2825,7 +2776,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 deque<_Tp, _Allocator>::swap(deque& __c)
 #if _LIBCPP_STD_VER >= 14
@@ -2839,7 +2790,7 @@
 }
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 deque<_Tp, _Allocator>::clear() _NOEXCEPT
 {
diff --git a/include/errno.h b/include/errno.h
deleted file mode 100644
index ee64291..0000000
--- a/include/errno.h
+++ /dev/null
@@ -1,398 +0,0 @@
-// -*- C++ -*-
-//===-------------------------- errno.h -----------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_ERRNO_H
-#define _LIBCPP_ERRNO_H
-
-/*
-    errno.h synopsis
-
-Macros:
-
-    EDOM
-    EILSEQ  // C99
-    ERANGE
-    errno
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <errno.h>
-
-#ifdef __cplusplus
-
-#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
-
-#ifdef ELAST
-
-static const int __elast1 = ELAST+1;
-static const int __elast2 = ELAST+2;
-
-#else
-
-static const int __elast1 = 104;
-static const int __elast2 = 105;
-
-#endif
-
-#ifdef ENOTRECOVERABLE
-
-#define EOWNERDEAD __elast1
-
-#ifdef ELAST
-#undef ELAST
-#define ELAST EOWNERDEAD
-#endif
-
-#elif defined(EOWNERDEAD)
-
-#define ENOTRECOVERABLE __elast1
-#ifdef ELAST
-#undef ELAST
-#define ELAST ENOTRECOVERABLE
-#endif
-
-#else  // defined(EOWNERDEAD)
-
-#define EOWNERDEAD __elast1
-#define ENOTRECOVERABLE __elast2
-#ifdef ELAST
-#undef ELAST
-#define ELAST ENOTRECOVERABLE
-#endif
-
-#endif  // defined(EOWNERDEAD)
-
-#endif  // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
-
-//  supply errno values likely to be missing, particularly on Windows
-
-#ifndef EAFNOSUPPORT
-#define EAFNOSUPPORT 9901
-#endif
-
-#ifndef EADDRINUSE
-#define EADDRINUSE 9902
-#endif
-
-#ifndef EADDRNOTAVAIL
-#define EADDRNOTAVAIL 9903
-#endif
-
-#ifndef EISCONN
-#define EISCONN 9904
-#endif
-
-#ifndef EBADMSG
-#define EBADMSG 9905
-#endif
-
-#ifndef ECONNABORTED
-#define ECONNABORTED 9906
-#endif
-
-#ifndef EALREADY
-#define EALREADY 9907
-#endif
-
-#ifndef ECONNREFUSED
-#define ECONNREFUSED 9908
-#endif
-
-#ifndef ECONNRESET
-#define ECONNRESET 9909
-#endif
-
-#ifndef EDESTADDRREQ
-#define EDESTADDRREQ 9910
-#endif
-
-#ifndef EHOSTUNREACH
-#define EHOSTUNREACH 9911
-#endif
-
-#ifndef EIDRM
-#define EIDRM 9912
-#endif
-
-#ifndef EMSGSIZE
-#define EMSGSIZE 9913
-#endif
-
-#ifndef ENETDOWN
-#define ENETDOWN 9914
-#endif
-
-#ifndef ENETRESET
-#define ENETRESET 9915
-#endif
-
-#ifndef ENETUNREACH
-#define ENETUNREACH 9916
-#endif
-
-#ifndef ENOBUFS
-#define ENOBUFS 9917
-#endif
-
-#ifndef ENOLINK
-#define ENOLINK 9918
-#endif
-
-#ifndef ENODATA
-#define ENODATA 9919
-#endif
-
-#ifndef ENOMSG
-#define ENOMSG 9920
-#endif
-
-#ifndef ENOPROTOOPT
-#define ENOPROTOOPT 9921
-#endif
-
-#ifndef ENOSR
-#define ENOSR 9922
-#endif
-
-#ifndef ENOTSOCK
-#define ENOTSOCK 9923
-#endif
-
-#ifndef ENOSTR
-#define ENOSTR 9924
-#endif
-
-#ifndef ENOTCONN
-#define ENOTCONN 9925
-#endif
-
-#ifndef ENOTSUP
-#define ENOTSUP 9926
-#endif
-
-#ifndef ECANCELED
-#define ECANCELED 9927
-#endif
-
-#ifndef EINPROGRESS
-#define EINPROGRESS 9928
-#endif
-
-#ifndef EOPNOTSUPP
-#define EOPNOTSUPP 9929
-#endif
-
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK 9930
-#endif
-
-#ifndef EOWNERDEAD
-#define EOWNERDEAD  9931
-#endif
-
-#ifndef EPROTO
-#define EPROTO 9932
-#endif
-
-#ifndef EPROTONOSUPPORT
-#define EPROTONOSUPPORT 9933
-#endif
-
-#ifndef ENOTRECOVERABLE
-#define ENOTRECOVERABLE 9934
-#endif
-
-#ifndef ETIME
-#define ETIME 9935
-#endif
-
-#ifndef ETXTBSY
-#define ETXTBSY 9936
-#endif
-
-#ifndef ETIMEDOUT
-#define ETIMEDOUT 9938
-#endif
-
-#ifndef ELOOP
-#define ELOOP 9939
-#endif
-
-#ifndef EOVERFLOW
-#define EOVERFLOW 9940
-#endif
-
-#ifndef EPROTOTYPE
-#define EPROTOTYPE 9941
-#endif
-
-#ifndef ENOSYS
-#define ENOSYS 9942
-#endif
-
-#ifndef EINVAL
-#define EINVAL 9943
-#endif
-
-#ifndef ERANGE
-#define ERANGE 9944
-#endif
-
-#ifndef EILSEQ
-#define EILSEQ 9945
-#endif
-
-//  Windows Mobile doesn't appear to define these:
-
-#ifndef E2BIG
-#define E2BIG 9946
-#endif
-
-#ifndef EDOM
-#define EDOM 9947
-#endif
-
-#ifndef EFAULT
-#define EFAULT 9948
-#endif
-
-#ifndef EBADF
-#define EBADF 9949
-#endif
-
-#ifndef EPIPE
-#define EPIPE 9950
-#endif
-
-#ifndef EXDEV
-#define EXDEV 9951
-#endif
-
-#ifndef EBUSY
-#define EBUSY 9952
-#endif
-
-#ifndef ENOTEMPTY
-#define ENOTEMPTY 9953
-#endif
-
-#ifndef ENOEXEC
-#define ENOEXEC 9954
-#endif
-
-#ifndef EEXIST
-#define EEXIST 9955
-#endif
-
-#ifndef EFBIG
-#define EFBIG 9956
-#endif
-
-#ifndef ENAMETOOLONG
-#define ENAMETOOLONG 9957
-#endif
-
-#ifndef ENOTTY
-#define ENOTTY 9958
-#endif
-
-#ifndef EINTR
-#define EINTR 9959
-#endif
-
-#ifndef ESPIPE
-#define ESPIPE 9960
-#endif
-
-#ifndef EIO
-#define EIO 9961
-#endif
-
-#ifndef EISDIR
-#define EISDIR 9962
-#endif
-
-#ifndef ECHILD
-#define ECHILD 9963
-#endif
-
-#ifndef ENOLCK
-#define ENOLCK 9964
-#endif
-
-#ifndef ENOSPC
-#define ENOSPC 9965
-#endif
-
-#ifndef ENXIO
-#define ENXIO 9966
-#endif
-
-#ifndef ENODEV
-#define ENODEV 9967
-#endif
-
-#ifndef ENOENT
-#define ENOENT 9968
-#endif
-
-#ifndef ESRCH
-#define ESRCH 9969
-#endif
-
-#ifndef ENOTDIR
-#define ENOTDIR 9970
-#endif
-
-#ifndef ENOMEM
-#define ENOMEM 9971
-#endif
-
-#ifndef EPERM
-#define EPERM 9972
-#endif
-
-#ifndef EACCES
-#define EACCES 9973
-#endif
-
-#ifndef EROFS
-#define EROFS 9974
-#endif
-
-#ifndef EDEADLK
-#define EDEADLK 9975
-#endif
-
-#ifndef EAGAIN
-#define EAGAIN 9976
-#endif
-
-#ifndef ENFILE
-#define ENFILE 9977
-#endif
-
-#ifndef EMFILE
-#define EMFILE 9978
-#endif
-
-#ifndef EMLINK
-#define EMLINK 9979
-#endif
-
-#endif // __cplusplus
-
-#endif  // _LIBCPP_ERRNO_H
diff --git a/include/exception b/include/exception
index 186d379..5a905e7 100644
--- a/include/exception
+++ b/include/exception
@@ -80,10 +80,6 @@
 #include <__config>
 #include <cstddef>
 #include <type_traits>
-#if defined(_LIBCPP_NO_EXCEPTIONS)
-#include <cstdio>
-#include <cstdlib>
-#endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -239,7 +235,7 @@
                                    is_polymorphic<_Ep>::value
                                                    >::type* = 0)
 {
-    const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e));
+    const nested_exception* __nep = dynamic_cast<const nested_exception*>(&__e);
     if (__nep)
         __nep->rethrow_nested();
 }
@@ -255,19 +251,4 @@
 
 }  // std
 
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Exception>
-_LIBCPP_INLINE_VISIBILITY
-inline void __libcpp_throw(_Exception const& __e) {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    throw __e;
-#else
-    _VSTD::fprintf(stderr, "%s\n", __e.what());
-    _VSTD::abort();
-#endif
-}
-
-_LIBCPP_END_NAMESPACE_STD
-
 #endif  // _LIBCPP_EXCEPTION
diff --git a/include/experimental/__config b/include/experimental/__config
index 046a70a..f64a3a9 100644
--- a/include/experimental/__config
+++ b/include/experimental/__config
@@ -25,10 +25,6 @@
 #define _LIBCPP_END_NAMESPACE_LFTS  } } }
 #define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1
 
-#define _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR _LIBCPP_BEGIN_NAMESPACE_LFTS namespace pmr {
-#define _LIBCPP_END_NAMESPACE_LFTS_PMR _LIBCPP_END_NAMESPACE_LFTS }
-#define _VSTD_LFTS_PMR _VSTD_LFTS::pmr
-
 #define _LIBCPP_BEGIN_NAMESPACE_CHRONO_LFTS _LIBCPP_BEGIN_NAMESPACE_STD        \
   namespace chrono { namespace experimental { inline namespace fundamentals_v1 {
 #define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } }
diff --git a/include/experimental/__memory b/include/experimental/__memory
deleted file mode 100644
index 229fea6..0000000
--- a/include/experimental/__memory
+++ /dev/null
@@ -1,90 +0,0 @@
-// -*- 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_EXPERIMENTAL___MEMORY
-#define _LIBCPP_EXPERIMENTAL___MEMORY
-
-#include <experimental/__config>
-#include <experimental/utility> // for erased_type
-#include <__functional_base>
-#include <type_traits>
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS
-
-template <
-    class _Tp, class _Alloc
-  , bool = uses_allocator<_Tp, _Alloc>::value
-  , bool = __has_allocator_type<_Tp>::value
-  >
-struct __lfts_uses_allocator : public false_type {};
-
-template <class _Tp, class _Alloc>
-struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {};
-
-template <class _Tp, class _Alloc, bool HasAlloc>
-struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {};
-
-template <class _Tp, class _Alloc>
-struct __lfts_uses_allocator<_Tp, _Alloc, false, true>
-  : public integral_constant<bool
-    , is_convertible<_Alloc, typename _Tp::allocator_type>::value
-      || is_same<erased_type, typename _Tp::allocator_type>::value
-    >
-{};
-
-template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args>
-struct __lfts_uses_alloc_ctor_imp
-{
-    static const int value = 0;
-};
-
-template <class _Tp, class _Alloc, class ..._Args>
-struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...>
-{
-    static const bool __ic_first
-        = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
-
-    static const bool __ic_second =
-        conditional<
-            __ic_first,
-            false_type,
-            is_constructible<_Tp, _Args..., _Alloc>
-        >::type::value;
-
-    static_assert(__ic_first || __ic_second,
-                  "Request for uses allocator construction is ill-formed");
-
-    static const int value = __ic_first ? 1 : 2;
-};
-
-template <class _Tp, class _Alloc, class ..._Args>
-struct __lfts_uses_alloc_ctor
-  : integral_constant<int,
-        __lfts_uses_alloc_ctor_imp<
-            __lfts_uses_allocator<_Tp, _Alloc>::value
-          , _Tp, _Alloc, _Args...
-        >::value
-    >
-{};
-
-template <class _Tp, class _Alloc, class ..._Args>
-inline _LIBCPP_INLINE_VISIBILITY
-void __lfts_user_alloc_construct(
-    _Tp * __store, const _Alloc & __a, _Args &&... __args)
-{
-    _VSTD::__user_alloc_construct_impl(
-        typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type()
-       , __store, __a, _VSTD::forward<_Args>(__args)...
-       );
-}
-
-_LIBCPP_END_NAMESPACE_LFTS
-
-#endif /* _LIBCPP_EXPERIMENTAL___MEMORY */
diff --git a/include/experimental/algorithm b/include/experimental/algorithm
index 3902111..ffaa793 100644
--- a/include/experimental/algorithm
+++ b/include/experimental/algorithm
@@ -53,7 +53,7 @@
 template <class _ForwardIterator, class _Searcher>
 _LIBCPP_INLINE_VISIBILITY
 _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s)
-{ return __s(__f, __l).first; }
+{ return __s(__f, __l); }
 
 
 template <class _PopulationIterator, class _SampleIterator, class _Distance,
diff --git a/include/experimental/any b/include/experimental/any
index 4c73249..a38397a 100644
--- a/include/experimental/any
+++ b/include/experimental/any
@@ -82,7 +82,6 @@
 #include <typeinfo>
 #include <type_traits>
 #include <cstdlib>
-#include <cassert>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -93,6 +92,9 @@
 class _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast
 {
 public:
+     //TODO(EricWF) Enable or delete these.
+    //bad_any_cast() _NOEXCEPT;
+    //virtual ~bad_any_cast() _NOEXCEPT;
     virtual const char* what() const _NOEXCEPT;
 };
 
@@ -104,7 +106,7 @@
 #ifndef _LIBCPP_NO_EXCEPTIONS
     throw bad_any_cast();
 #else
-    assert(!"bad_any_cast");
+    _VSTD::abort();
 #endif
 }
 
@@ -113,12 +115,10 @@
 
 template <class _ValueType>
 typename add_pointer<typename add_const<_ValueType>::type>::type
-_LIBCPP_INLINE_VISIBILITY
 any_cast(any const *) _NOEXCEPT;
 
 template <class _ValueType>
 typename add_pointer<_ValueType>::type
-_LIBCPP_INLINE_VISIBILITY
 any_cast(any *) _NOEXCEPT;
 
 namespace __any_imp
@@ -187,7 +187,6 @@
       class _ValueType
     , class = __any_imp::_EnableIfNotAny<_ValueType>
     >
-  _LIBCPP_INLINE_VISIBILITY
   any(_ValueType && __value);
 
   _LIBCPP_INLINE_VISIBILITY
@@ -215,7 +214,6 @@
       class _ValueType
     , class = __any_imp::_EnableIfNotAny<_ValueType>
     >
-  _LIBCPP_INLINE_VISIBILITY
   any & operator=(_ValueType && __rhs);
 
   // 6.3.3 any modifiers
@@ -225,7 +223,6 @@
     if (__h) this->__call(_Action::_Destroy);
   }
 
-  _LIBCPP_INLINE_VISIBILITY
   void swap(any & __rhs) _NOEXCEPT;
 
   // 6.3.4 any observers
@@ -462,6 +459,7 @@
 
 
 template <class _ValueType, class>
+_LIBCPP_INLINE_VISIBILITY
 any::any(_ValueType && __v) : __h(nullptr)
 {
   typedef typename decay<_ValueType>::type _Tp;
@@ -472,6 +470,7 @@
 }
 
 template <class _ValueType, class>
+_LIBCPP_INLINE_VISIBILITY
 any & any::operator=(_ValueType && __v)
 {
   typedef typename decay<_ValueType>::type _Tp;
@@ -481,7 +480,7 @@
   return *this;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void any::swap(any & __rhs) _NOEXCEPT
 {
     if (__h && __rhs.__h) {
@@ -553,7 +552,7 @@
 }
 
 template <class _ValueType>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename add_pointer<typename add_const<_ValueType>::type>::type
 any_cast(any const * __any) _NOEXCEPT
 {
@@ -563,6 +562,7 @@
 }
 
 template <class _ValueType>
+_LIBCPP_INLINE_VISIBILITY
 typename add_pointer<_ValueType>::type
 any_cast(any * __any) _NOEXCEPT
 {
diff --git a/include/experimental/deque b/include/experimental/deque
deleted file mode 100644
index f849574..0000000
--- a/include/experimental/deque
+++ /dev/null
@@ -1,47 +0,0 @@
-// -*- 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_EXPERIMENTAL_DEQUE
-#define _LIBCPP_EXPERIMENTAL_DEQUE
-/*
-    experimental/deque synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class T>
-  using deque = std::deque<T,polymorphic_allocator<T>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <deque>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _ValueT>
-using deque = _VSTD::deque<_ValueT, polymorphic_allocator<_ValueT>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_DEQUE */
diff --git a/include/experimental/dynarray b/include/experimental/dynarray
index 4a06908..a025862 100644
--- a/include/experimental/dynarray
+++ b/include/experimental/dynarray
@@ -137,7 +137,7 @@
 private:
     size_t                  __size_;
     value_type *            __base_;
-    _LIBCPP_ALWAYS_INLINE dynarray () noexcept :  __size_(0), __base_(nullptr) {}
+    _LIBCPP_ALWAYS_INLINE dynarray () noexcept : __base_(nullptr), __size_(0) {}
     
     static inline _LIBCPP_INLINE_VISIBILITY value_type* __allocate ( size_t count )
     {
@@ -159,13 +159,9 @@
 
 public:
 
-    _LIBCPP_INLINE_VISIBILITY
     explicit dynarray(size_type __c);
-    _LIBCPP_INLINE_VISIBILITY
     dynarray(size_type __c, const value_type& __v);
-    _LIBCPP_INLINE_VISIBILITY
     dynarray(const dynarray& __d);
-    _LIBCPP_INLINE_VISIBILITY
     dynarray(initializer_list<value_type>);
 
 //  We're not implementing these right now.
@@ -180,7 +176,6 @@
 //       dynarray(allocator_arg_t, const _Alloc& __alloc, initializer_list<value_type>);
 
     dynarray& operator=(const dynarray&) = delete;
-    _LIBCPP_INLINE_VISIBILITY
     ~dynarray();
 
     // iterators:
@@ -224,7 +219,7 @@
 };
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 dynarray<_Tp>::dynarray(size_type __c) : dynarray ()
 {
     __base_ = __allocate (__c);
@@ -234,7 +229,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 dynarray<_Tp>::dynarray(size_type __c, const value_type& __v) : dynarray ()
 {
     __base_ = __allocate (__c);
@@ -244,7 +239,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 dynarray<_Tp>::dynarray(initializer_list<value_type> __il) : dynarray ()
 {
     size_t sz = __il.size();
@@ -256,7 +251,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 dynarray<_Tp>::dynarray(const dynarray& __d) : dynarray ()
 {
     size_t sz = __d.size();
@@ -268,7 +263,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 dynarray<_Tp>::~dynarray()
 { 
     value_type *__data = data () + __size_;
diff --git a/include/experimental/forward_list b/include/experimental/forward_list
deleted file mode 100644
index 55e195f..0000000
--- a/include/experimental/forward_list
+++ /dev/null
@@ -1,47 +0,0 @@
-// -*- 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_EXPERIMENTAL_FORWARD_LIST
-#define _LIBCPP_EXPERIMENTAL_FORWARD_LIST
-/*
-    experimental/forward_list synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class T>
-  using forward_list = std::forward_list<T,polymorphic_allocator<T>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <forward_list>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _ValueT>
-using forward_list = _VSTD::forward_list<_ValueT, polymorphic_allocator<_ValueT>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_FORWARD_LIST */
diff --git a/include/experimental/functional b/include/experimental/functional
index 75fc8e9..f5a905f 100644
--- a/include/experimental/functional
+++ b/include/experimental/functional
@@ -20,7 +20,7 @@
 namespace experimental {
 inline namespace fundamentals_v1 {
 
-    // See C++14 20.9.9, Function object binders
+    // See C++14 §20.9.9, Function object binders
     template <class T> constexpr bool is_bind_expression_v
       = is_bind_expression<T>::value;
     template <class T> constexpr int is_placeholder_v
@@ -89,12 +89,7 @@
 
 #include <experimental/__config>
 #include <functional>
-
 #include <algorithm>
-#include <type_traits>
-#include <vector>
-#include <array>
-#include <unordered_map>
 
 #include <__undef_min_max>
 
@@ -106,26 +101,18 @@
 
 _LIBCPP_BEGIN_NAMESPACE_LFTS
 
-#if _LIBCPP_STD_VER > 11
 // default searcher
 template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
-_LIBCPP_TYPE_VIS
 class default_searcher {
 public:
-    _LIBCPP_INLINE_VISIBILITY
     default_searcher(_ForwardIterator __f, _ForwardIterator __l, 
                        _BinaryPredicate __p = _BinaryPredicate())
         : __first_(__f), __last_(__l), __pred_(__p) {}
 
     template <typename _ForwardIterator2>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<_ForwardIterator2, _ForwardIterator2>
-    operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
-    {
-        return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
-            typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
-            typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
-    }
+    _ForwardIterator2 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const {
+        return _VSTD::search(__f, __l, __first_, __last_, __pred_);
+        }
 
 private:
     _ForwardIterator __first_;
@@ -134,325 +121,12 @@
     };
 
 template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
-_LIBCPP_INLINE_VISIBILITY
 default_searcher<_ForwardIterator, _BinaryPredicate>
 make_default_searcher( _ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate ())
 {
     return default_searcher<_ForwardIterator, _BinaryPredicate>(__f, __l, __p);
 }
 
-template<class _Key, class _Value, class _Hash, class _BinaryPredicate, bool /*useArray*/> class _BMSkipTable;
-
-//  General case for BM data searching; use a map
-template<class _Key, typename _Value, class _Hash, class _BinaryPredicate>
-class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> {
-public: // TODO private:
-    typedef _Value value_type;
-    typedef _Key   key_type;
-
-    const _Value __default_value_;
-    std::unordered_map<_Key, _Value, _Hash, _BinaryPredicate> __table;
-    
-public:
-    _LIBCPP_INLINE_VISIBILITY
-    _BMSkipTable(std::size_t __sz, _Value __default, _Hash __hf, _BinaryPredicate __pred)
-        : __default_value_(__default), __table(__sz, __hf, __pred) {}
-    
-    _LIBCPP_INLINE_VISIBILITY
-    void insert(const key_type &__key, value_type __val)
-    {
-        __table [__key] = __val;    // Would skip_.insert (val) be better here?
-    }
-
-    _LIBCPP_INLINE_VISIBILITY
-    value_type operator [](const key_type & __key) const
-    {
-        auto __it = __table.find (__key);
-        return __it == __table.end() ? __default_value_ : __it->second;
-    }
-};
-    
-
-//  Special case small numeric values; use an array
-template<class _Key, typename _Value, class _Hash, class _BinaryPredicate>
-class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, true> {
-private:
-    typedef _Value value_type;
-    typedef _Key   key_type;
-
-    typedef typename std::make_unsigned<key_type>::type unsigned_key_type;
-    typedef std::array<value_type, _VSTD::numeric_limits<unsigned_key_type>::max()> skip_map;
-    skip_map __table;
-
-public:
-    _LIBCPP_INLINE_VISIBILITY
-    _BMSkipTable(std::size_t /*__sz*/, _Value __default, _Hash /*__hf*/, _BinaryPredicate /*__pred*/)
-    {
-        std::fill_n(__table.begin(), __table.size(), __default);
-    }
-    
-    _LIBCPP_INLINE_VISIBILITY
-    void insert(key_type __key, value_type __val)
-    {
-        __table[static_cast<unsigned_key_type>(__key)] = __val;
-    }
-
-    _LIBCPP_INLINE_VISIBILITY
-    value_type operator [](key_type __key) const
-    {
-        return __table[static_cast<unsigned_key_type>(__key)];
-    }
-};
-
-
-template <class _RandomAccessIterator1, 
-          class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, 
-          class _BinaryPredicate = equal_to<>>
-_LIBCPP_TYPE_VIS
-class boyer_moore_searcher {
-private:
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type;
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type      value_type;
-    typedef _BMSkipTable<value_type, difference_type, _Hash, _BinaryPredicate,
-                    _VSTD::is_integral<value_type>::value && // what about enums?
-                    sizeof(value_type) == 1 &&
-                    is_same<_Hash, hash<value_type>>::value &&
-                    is_same<_BinaryPredicate, equal_to<>>::value
-            > skip_table_type;
-    
-public:
-    boyer_moore_searcher(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, 
-                _Hash __hf = _Hash(), _BinaryPredicate __pred = _BinaryPredicate())
-            : __first_(__f), __last_(__l), __pred_(__pred),
-              __pattern_length_(_VSTD::distance(__first_, __last_)),
-              __skip_{make_shared<skip_table_type>(__pattern_length_, -1, __hf, __pred_)},
-              __suffix_{make_shared<vector<difference_type>>(__pattern_length_ + 1)}
-        {
-    //  build the skip table
-        for ( difference_type __i = 0; __f != __l; ++__f, (void) ++__i )
-            __skip_->insert(*__f, __i);
-
-        this->__build_suffix_table ( __first_, __last_, __pred_ );
-        }
-        
-    template <typename _RandomAccessIterator2>
-    pair<_RandomAccessIterator2, _RandomAccessIterator2>
-    operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const
-    {
-        static_assert ( std::is_same<
-                typename std::decay<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type, 
-                typename std::decay<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type
-                    >::value,
-                "Corpus and Pattern iterators must point to the same type" );
-
-        if (__f      == __l )    return make_pair(__l, __l); // empty corpus
-        if (__first_ == __last_) return make_pair(__f, __f); // empty pattern
-
-    //  If the pattern is larger than the corpus, we can't find it!
-        if ( __pattern_length_ > _VSTD::distance (__f, __l)) 
-            return make_pair(__l, __l);
-
-    //  Do the search 
-        return this->__search(__f, __l);
-    }
-        
-public: // TODO private:
-    _RandomAccessIterator1               __first_;
-    _RandomAccessIterator1               __last_;
-    _BinaryPredicate                     __pred_;
-    difference_type                      __pattern_length_;
-    shared_ptr<skip_table_type>          __skip_;
-    shared_ptr<vector<difference_type>>  __suffix_;
-
-    template <typename _RandomAccessIterator2>
-    pair<_RandomAccessIterator2, _RandomAccessIterator2>
-    __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const
-    {
-        _RandomAccessIterator2 __cur = __f;
-        const _RandomAccessIterator2 __last = __l - __pattern_length_;
-        const skip_table_type &         __skip   = *__skip_.get();
-        const vector<difference_type> & __suffix = *__suffix_.get();
-        
-        while (__cur <= __last)
-        {
-
-        //  Do we match right where we are?
-            difference_type __j = __pattern_length_;
-            while (__pred_(__first_ [__j-1], __cur [__j-1])) {
-                __j--;
-            //  We matched - we're done!
-                if ( __j == 0 )
-                    return make_pair(__cur, __cur + __pattern_length_);
-                }
-            
-        //  Since we didn't match, figure out how far to skip forward
-            difference_type __k = __skip[__cur [ __j - 1 ]];
-            difference_type __m = __j - __k - 1;
-            if (__k < __j && __m > __suffix[ __j ])
-                __cur += __m;
-            else
-                __cur += __suffix[ __j ];
-        }
-    
-        return make_pair(__l, __l);     // We didn't find anything
-    }
-
-
-    template<typename _Iterator, typename _Container>
-    void __compute_bm_prefix ( _Iterator __f, _Iterator __l, _BinaryPredicate __pred, _Container &__prefix )
-    {
-        const std::size_t __count = _VSTD::distance(__f, __l);
-                        
-        __prefix[0] = 0;
-        std::size_t __k = 0;
-        for ( std::size_t __i = 1; __i < __count; ++__i )
-        {
-            while ( __k > 0 && !__pred ( __f[__k], __f[__i] ))
-                __k = __prefix [ __k - 1 ];
-                
-            if ( __pred ( __f[__k], __f[__i] ))
-                __k++;
-            __prefix [ __i ] = __k;
-        }
-    }
-
-    void __build_suffix_table(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, 
-                                                    _BinaryPredicate __pred)
-    {
-        const std::size_t __count = _VSTD::distance(__f, __l);
-        vector<difference_type> & __suffix = *__suffix_.get();
-        if (__count > 0)
-        {
-            _VSTD::vector<value_type> __scratch(__count);
-            
-            __compute_bm_prefix(__f, __l, __pred, __scratch);
-            for ( std::size_t __i = 0; __i <= __count; __i++ )
-                __suffix[__i] = __count - __scratch[__count-1];
-    
-            typedef _VSTD::reverse_iterator<_RandomAccessIterator1> _RevIter;
-            __compute_bm_prefix(_RevIter(__l), _RevIter(__f), __pred, __scratch);
-     
-            for ( std::size_t __i = 0; __i < __count; __i++ )
-            {
-                const std::size_t     __j = __count - __scratch[__i];
-                const difference_type __k = __i     - __scratch[__i] + 1;
-     
-                if (__suffix[__j] > __k)
-                    __suffix[__j] = __k;
-            }
-        }
-    }
-
-};
-
-template<class _RandomAccessIterator, 
-         class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>, 
-         class _BinaryPredicate = equal_to<>>
-_LIBCPP_INLINE_VISIBILITY
-boyer_moore_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>
-make_boyer_moore_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l, 
-                    _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ())
-{
-    return boyer_moore_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>(__f, __l, __hf, __p);
-}
-
-// boyer-moore-horspool
-template <class _RandomAccessIterator1, 
-          class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, 
-          class _BinaryPredicate = equal_to<>>
-_LIBCPP_TYPE_VIS
-class boyer_moore_horspool_searcher {
-private:
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type;
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type      value_type;
-    typedef _BMSkipTable<value_type, difference_type, _Hash, _BinaryPredicate,
-                    _VSTD::is_integral<value_type>::value && // what about enums?
-                    sizeof(value_type) == 1 &&
-                    is_same<_Hash, hash<value_type>>::value &&
-                    is_same<_BinaryPredicate, equal_to<>>::value
-            > skip_table_type;
-
-public:
-    boyer_moore_horspool_searcher(_RandomAccessIterator1 __f, _RandomAccessIterator1 __l, 
-                _Hash __hf = _Hash(), _BinaryPredicate __pred = _BinaryPredicate())
-            : __first_(__f), __last_(__l), __pred_(__pred),
-              __pattern_length_(_VSTD::distance(__first_, __last_)),
-              __skip_{_VSTD::make_shared<skip_table_type>(__pattern_length_, __pattern_length_, __hf, __pred_)}
-        {
-    //  build the skip table
-            if ( __f != __l )
-            {
-                __l = __l - 1;
-                for ( difference_type __i = 0; __f != __l; ++__f, (void) ++__i )
-                    __skip_->insert(*__f, __pattern_length_ - 1 - __i);
-            }
-        }
-            
-    template <typename _RandomAccessIterator2>
-    pair<_RandomAccessIterator2, _RandomAccessIterator2>
-    operator ()(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const
-    {
-        static_assert ( std::is_same<
-                typename std::decay<typename std::iterator_traits<_RandomAccessIterator1>::value_type>::type, 
-                typename std::decay<typename std::iterator_traits<_RandomAccessIterator2>::value_type>::type
-                    >::value,
-                "Corpus and Pattern iterators must point to the same type" );
-
-        if (__f      == __l )    return make_pair(__l, __l); // empty corpus
-        if (__first_ == __last_) return make_pair(__f, __f); // empty pattern
-
-    //  If the pattern is larger than the corpus, we can't find it!
-        if ( __pattern_length_ > _VSTD::distance (__f, __l)) 
-            return make_pair(__l, __l);
-
-    //  Do the search 
-        return this->__search(__f, __l);
-    }
-        
-private:
-    _RandomAccessIterator1      __first_;
-    _RandomAccessIterator1      __last_;
-    _BinaryPredicate            __pred_;
-    difference_type             __pattern_length_;
-    shared_ptr<skip_table_type> __skip_;
-
-    template <typename _RandomAccessIterator2>
-    pair<_RandomAccessIterator2, _RandomAccessIterator2>
-    __search ( _RandomAccessIterator2 __f, _RandomAccessIterator2 __l ) const {
-        _RandomAccessIterator2 __cur = __f;
-        const _RandomAccessIterator2 __last = __l - __pattern_length_;
-        const skip_table_type & __skip = *__skip_.get();
-
-        while (__cur <= __last)
-        {
-        //  Do we match right where we are?
-            difference_type __j = __pattern_length_;
-            while (__pred_(__first_[__j-1], __cur[__j-1]))
-            {
-                __j--;
-            //  We matched - we're done!
-                if ( __j == 0 )
-                    return make_pair(__cur, __cur + __pattern_length_);
-            }
-            __cur += __skip[__cur[__pattern_length_-1]];
-        }
-        
-        return make_pair(__l, __l);
-    }
-};
-
-template<class _RandomAccessIterator, 
-         class _Hash = hash<typename iterator_traits<_RandomAccessIterator>::value_type>, 
-         class _BinaryPredicate = equal_to<>>
-_LIBCPP_INLINE_VISIBILITY
-boyer_moore_horspool_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>
-make_boyer_moore_horspool_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l, 
-                    _Hash __hf = _Hash(), _BinaryPredicate __p = _BinaryPredicate ())
-{
-    return boyer_moore_horspool_searcher<_RandomAccessIterator, _Hash, _BinaryPredicate>(__f, __l, __hf, __p);
-}
-
-#endif // _LIBCPP_STD_VER > 11
 
 _LIBCPP_END_NAMESPACE_LFTS
 
diff --git a/include/experimental/iterator b/include/experimental/iterator
deleted file mode 100644
index da593fe..0000000
--- a/include/experimental/iterator
+++ /dev/null
@@ -1,114 +0,0 @@
-// -*- 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 DelimT, class charT = char, class traits = char_traits<charT>>
-        class ostream_joiner {
-        public:
-         typedef charT                        char_type;
-         typedef traits                       traits_type;
-         typedef basic_ostream<charT, traits> 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<typename T>  
-         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 <class charT, class traits, class DelimT>
-    ostream_joiner<decay_t<DelimT>, charT, traits>
-    make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
-
-    } // inline namespace fundamentals_v2
-  } // namespace experimental
-} // namespace std
-
-*/
-
-#include <experimental/__config>
-
-#if _LIBCPP_STD_VER > 11
-
-#include <iterator>
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS
-
-template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
-class ostream_joiner {
-public:
-
-    typedef _CharT                               char_type;
-    typedef _Traits                              traits_type;
-    typedef basic_ostream<char_type,traits_type> 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)
-        : __out(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
-        
-    ostream_joiner(ostream_type& __os, const _Delim& __d)
-        : __out(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
-    
-
-    template<typename _Tp>
-    ostream_joiner& operator=(const _Tp& __v)
-    {
-        if (!__first)
-            *__out << __delim;
-        __first = false;
-        *__out << __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*   __out;
-    _Delim          __delim;
-    bool            __first;
-};
-
-
-template <class _CharT, class _Traits, class _Delim>
-ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
-make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
-{ return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
-
-_LIBCPP_END_NAMESPACE_LFTS
-
-#endif /* _LIBCPP_STD_VER > 11 */
-
-#endif // _LIBCPP_EXPERIMENTAL_ITERATOR
diff --git a/include/experimental/list b/include/experimental/list
deleted file mode 100644
index 1678ee3..0000000
--- a/include/experimental/list
+++ /dev/null
@@ -1,47 +0,0 @@
-// -*- 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_EXPERIMENTAL_LIST
-#define _LIBCPP_EXPERIMENTAL_LIST
-/*
-    experimental/list synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class T>
-  using list = std::list<T,polymorphic_allocator<T>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <list>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _ValueT>
-using list = _VSTD::list<_ValueT, polymorphic_allocator<_ValueT>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_LIST */
diff --git a/include/experimental/map b/include/experimental/map
deleted file mode 100644
index cff2c5e..0000000
--- a/include/experimental/map
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- 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_EXPERIMENTAL_MAP
-#define _LIBCPP_EXPERIMENTAL_MAP
-/*
-    experimental/map synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class Key, class T, class Compare = less<Key>>
-  using map = std::map<Key, T, Compare,
-                       polymorphic_allocator<pair<const Key,T>>>;
-
-  template <class Key, class T, class Compare = less<Key>>
-  using multimap = std::multimap<Key, T, Compare,
-                                 polymorphic_allocator<pair<const Key,T>>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <map>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _Key, class _Value, class  _Compare = less<_Key>>
-using map = _VSTD::map<_Key, _Value, _Compare,
-                        polymorphic_allocator<pair<const _Key, _Value>>>;
-
-template <class _Key, class _Value, class  _Compare = less<_Key>>
-using multimap = _VSTD::multimap<_Key, _Value, _Compare,
-                        polymorphic_allocator<pair<const _Key, _Value>>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_MAP */
diff --git a/include/experimental/memory_resource b/include/experimental/memory_resource
deleted file mode 100644
index f54ef0b..0000000
--- a/include/experimental/memory_resource
+++ /dev/null
@@ -1,422 +0,0 @@
-// -*- C++ -*-
-//===------------------------ memory_resource -----------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE
-#define _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE
-
-/**
-    experimental/memory_resource synopsis
-
-// C++1y
-
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  class memory_resource;
-
-  bool operator==(const memory_resource& a,
-                  const memory_resource& b) noexcept;
-  bool operator!=(const memory_resource& a,
-                  const memory_resource& b) noexcept;
-
-  template <class Tp> class polymorphic_allocator;
-
-  template <class T1, class T2>
-  bool operator==(const polymorphic_allocator<T1>& a,
-                  const polymorphic_allocator<T2>& b) noexcept;
-  template <class T1, class T2>
-  bool operator!=(const polymorphic_allocator<T1>& a,
-                  const polymorphic_allocator<T2>& b) noexcept;
-
-  // The name resource_adaptor_imp is for exposition only.
-  template <class Allocator> class resource_adaptor_imp;
-
-  template <class Allocator>
-    using resource_adaptor = resource_adaptor_imp<
-      allocator_traits<Allocator>::rebind_alloc<char>>;
-
-  // Global memory resources
-  memory_resource* new_delete_resource() noexcept;
-  memory_resource* null_memory_resource() noexcept;
-
-  // The default memory resource
-  memory_resource* set_default_resource(memory_resource* r) noexcept;
-  memory_resource* get_default_resource() noexcept;
-
-  // Standard memory resources
-  struct pool_options;
-  class synchronized_pool_resource;
-  class unsynchronized_pool_resource;
-  class monotonic_buffer_resource;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <experimental/__memory>
-#include <limits>
-#include <memory>
-#include <new>
-#include <stdexcept>
-#include <tuple>
-#include <type_traits>
-#include <utility>
-#include <cstddef>
-#include <cstdlib>
-#include <__debug>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-// Round __s up to next multiple of __a.
-inline _LIBCPP_INLINE_VISIBILITY
-size_t __aligned_allocation_size(size_t __s, size_t __a) _NOEXCEPT
-{
-    _LIBCPP_ASSERT(__s + __a > __s, "aligned allocation size overflows");
-    return (__s + __a - 1) & ~(__a - 1);
-}
-
-// 8.5, memory.resource
-class _LIBCPP_TYPE_VIS_ONLY memory_resource
-{
-    static const size_t __max_align = alignof(max_align_t);
-
-// 8.5.2, memory.resource.public
-public:
-    virtual ~memory_resource() = default;
-
-    _LIBCPP_INLINE_VISIBILITY
-    void* allocate(size_t __bytes, size_t __align = __max_align)
-        { return do_allocate(__bytes, __align); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    void deallocate(void * __p, size_t __bytes, size_t __align = __max_align)
-        { do_deallocate(__p, __bytes, __align); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    bool is_equal(memory_resource const & __other) const _NOEXCEPT
-        { return do_is_equal(__other); }
-
-// 8.5.3, memory.resource.priv
-protected:
-    virtual void* do_allocate(size_t, size_t) = 0;
-    virtual void do_deallocate(void*, size_t, size_t) = 0;
-    virtual bool do_is_equal(memory_resource const &) const _NOEXCEPT = 0;
-};
-
-// 8.5.4, memory.resource.eq
-inline _LIBCPP_INLINE_VISIBILITY
-bool operator==(memory_resource const & __lhs,
-                memory_resource const & __rhs) _NOEXCEPT
-{
-    return &__lhs == &__rhs || __lhs.is_equal(__rhs);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-bool operator!=(memory_resource const & __lhs,
-                memory_resource const & __rhs) _NOEXCEPT
-{
-    return !(__lhs == __rhs);
-}
-
-_LIBCPP_FUNC_VIS
-memory_resource * new_delete_resource() _NOEXCEPT;
-
-_LIBCPP_FUNC_VIS
-memory_resource * null_memory_resource() _NOEXCEPT;
-
-_LIBCPP_FUNC_VIS
-memory_resource * get_default_resource() _NOEXCEPT;
-
-_LIBCPP_FUNC_VIS
-memory_resource * set_default_resource(memory_resource * __new_res) _NOEXCEPT;
-
-// 8.6, memory.polymorphic.allocator.class
-
-// 8.6.1, memory.polymorphic.allocator.overview
-template <class _ValueType>
-class _LIBCPP_TYPE_VIS_ONLY polymorphic_allocator
-{
-public:
-    typedef _ValueType value_type;
-
-    // 8.6.2, memory.polymorphic.allocator.ctor
-    _LIBCPP_INLINE_VISIBILITY
-    polymorphic_allocator() _NOEXCEPT
-      : __res_(_VSTD_LFTS_PMR::get_default_resource())
-    {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    polymorphic_allocator(memory_resource * __r) _NOEXCEPT
-      : __res_(__r)
-    {}
-
-    polymorphic_allocator(polymorphic_allocator const &) = default;
-
-    template <class _Tp>
-    _LIBCPP_INLINE_VISIBILITY
-    polymorphic_allocator(polymorphic_allocator<_Tp> const & __other) _NOEXCEPT
-      : __res_(__other.resource())
-    {}
-
-    polymorphic_allocator &
-    operator=(polymorphic_allocator const &) = default;
-
-    // 8.6.3, memory.polymorphic.allocator.mem
-    _LIBCPP_INLINE_VISIBILITY
-    _ValueType* allocate(size_t __n) {
-        if (__n > max_size()) {
-            __libcpp_throw(length_error(
-                "std::experimental::pmr::polymorphic_allocator<T>::allocate(size_t n)"
-                " 'n' exceeds maximum supported size"));
-        }
-        return static_cast<_ValueType*>(
-            __res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType))
-        );
-    }
-
-    _LIBCPP_INLINE_VISIBILITY
-    void deallocate(_ValueType * __p, size_t __n) _NOEXCEPT {
-        _LIBCPP_ASSERT(__n <= max_size(),
-                       "deallocate called for size which exceeds max_size()");
-        __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType));
-    }
-
-    template <class _Tp, class ..._Ts>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(_Tp* __p, _Ts &&... __args)
-    {
-        _VSTD_LFTS::__lfts_user_alloc_construct(
-            __p, resource(), _VSTD::forward<_Ts>(__args)...
-          );
-    }
-
-    template <class _T1, class _T2, class ..._Args1, class ..._Args2>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(pair<_T1, _T2>* __p, piecewise_construct_t,
-                   tuple<_Args1...> __x, tuple<_Args2...> __y)
-    {
-        ::new ((void*)__p) pair<_T1, _T2>(piecewise_construct
-          , __transform_tuple(
-              typename __lfts_uses_alloc_ctor<
-                  _T1, memory_resource*, _Args1...
-              >::type()
-            , _VSTD::move(__x)
-            , typename __make_tuple_indices<sizeof...(_Args1)>::type{}
-          )
-          , __transform_tuple(
-              typename __lfts_uses_alloc_ctor<
-                  _T2, memory_resource*, _Args2...
-              >::type()
-            , _VSTD::move(__y)
-            , typename __make_tuple_indices<sizeof...(_Args2)>::type{}
-          )
-        );
-    }
-
-    template <class _T1, class _T2>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(pair<_T1, _T2>* __p) {
-        construct(__p, piecewise_construct, tuple<>(), tuple<>());
-    }
-
-    template <class _T1, class _T2, class _Up, class _Vp>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(pair<_T1, _T2> * __p, _Up && __u, _Vp && __v) {
-        construct(__p, piecewise_construct
-          , _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__u))
-          , _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__v)));
-    }
-
-    template <class _T1, class _T2, class _U1, class _U2>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(pair<_T1, _T2> * __p, pair<_U1, _U2> const & __pr) {
-        construct(__p, piecewise_construct
-            , _VSTD::forward_as_tuple(__pr.first)
-            , _VSTD::forward_as_tuple(__pr.second));
-    }
-
-    template <class _T1, class _T2, class _U1, class _U2>
-    _LIBCPP_INLINE_VISIBILITY
-    void construct(pair<_T1, _T2> * __p, pair<_U1, _U2> && __pr){
-        construct(__p, piecewise_construct
-            , _VSTD::forward_as_tuple(_VSTD::forward<_U1>(__pr.first))
-            , _VSTD::forward_as_tuple(_VSTD::forward<_U2>(__pr.second)));
-    }
-
-    template <class _Tp>
-    _LIBCPP_INLINE_VISIBILITY
-    void destroy(_Tp * __p) _NOEXCEPT
-        { __p->~_Tp(); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    size_t max_size() const _NOEXCEPT
-        { return numeric_limits<size_t>::max() / sizeof(value_type); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    polymorphic_allocator
-    select_on_container_copy_construction() const _NOEXCEPT
-        { return polymorphic_allocator(); }
-
-    _LIBCPP_INLINE_VISIBILITY
-    memory_resource * resource() const _NOEXCEPT
-        { return __res_; }
-
-private:
-    template <class ..._Args, size_t ..._Idx>
-    _LIBCPP_INLINE_VISIBILITY
-    tuple<_Args&&...>
-    __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t,
-                      __tuple_indices<_Idx...>) const
-    {
-        return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...);
-    }
-
-    template <class ..._Args, size_t ..._Idx>
-    _LIBCPP_INLINE_VISIBILITY
-    tuple<allocator_arg_t const&, memory_resource*, _Args&&...>
-    __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t,
-                      __tuple_indices<_Idx...>) const
-    {
-        using _Tup = tuple<allocator_arg_t const&, memory_resource*, _Args&&...>;
-        return _Tup(allocator_arg, resource(),
-                    _VSTD::get<_Idx>(_VSTD::move(__t))...);
-    }
-
-    template <class ..._Args, size_t ..._Idx>
-    _LIBCPP_INLINE_VISIBILITY
-    tuple<_Args&&..., memory_resource*>
-    __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t,
-                      __tuple_indices<_Idx...>) const
-    {
-        using _Tup = tuple<_Args&&..., memory_resource*>;
-        return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., resource());
-    }
-
-    memory_resource * __res_;
-};
-
-// 8.6.4, memory.polymorphic.allocator.eq
-
-template <class _Tp, class _Up>
-inline _LIBCPP_INLINE_VISIBILITY
-bool operator==(polymorphic_allocator<_Tp> const & __lhs,
-                polymorphic_allocator<_Up> const & __rhs) _NOEXCEPT
-{
-    return *__lhs.resource() == *__rhs.resource();
-}
-
-template <class _Tp, class _Up>
-inline _LIBCPP_INLINE_VISIBILITY
-bool operator!=(polymorphic_allocator<_Tp> const & __lhs,
-                polymorphic_allocator<_Up> const & __rhs) _NOEXCEPT
-{
-    return !(__lhs == __rhs);
-}
-
-// 8.7, memory.resource.adaptor
-
-// 8.7.1, memory.resource.adaptor.overview
-template <class _CharAlloc>
-class _LIBCPP_TYPE_VIS_ONLY __resource_adaptor_imp
-  : public memory_resource
-{
-    using _CTraits = allocator_traits<_CharAlloc>;
-    static_assert(is_same<typename _CTraits::value_type, char>::value
-               && is_same<typename _CTraits::pointer, char*>::value
-               && is_same<typename _CTraits::void_pointer, void*>::value, "");
-
-    static const size_t _MaxAlign = alignof(max_align_t);
-
-    using _Alloc = typename _CTraits::template rebind_alloc<
-            typename aligned_storage<_MaxAlign, _MaxAlign>::type
-        >;
-
-    using _ValueType = typename _Alloc::value_type;
-
-    _Alloc __alloc_;
-
-public:
-    typedef _CharAlloc allocator_type;
-
-    __resource_adaptor_imp() = default;
-    __resource_adaptor_imp(__resource_adaptor_imp const &) = default;
-    __resource_adaptor_imp(__resource_adaptor_imp &&) = default;
-
-    // 8.7.2, memory.resource.adaptor.ctor
-
-    _LIBCPP_INLINE_VISIBILITY
-    explicit __resource_adaptor_imp(allocator_type const & __a)
-      : __alloc_(__a)
-    {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    explicit __resource_adaptor_imp(allocator_type && __a)
-      : __alloc_(_VSTD::move(__a))
-    {}
-
-    __resource_adaptor_imp &
-    operator=(__resource_adaptor_imp const &) = default;
-
-    _LIBCPP_INLINE_VISIBILITY
-    allocator_type get_allocator() const
-    { return __alloc_; }
-
-// 8.7.3, memory.resource.adaptor.mem
-protected:
-    virtual void * do_allocate(size_t __bytes, size_t)
-    {
-        if (__bytes > __max_size()) {
-            __libcpp_throw(length_error(
-                "std::experimental::pmr::resource_adaptor<T>::do_allocate(size_t bytes, size_t align)"
-                " 'bytes' exceeds maximum supported size"));
-        }
-        size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign;
-        return __alloc_.allocate(__s);
-    }
-
-    virtual void do_deallocate(void * __p, size_t __bytes, size_t)
-    {
-        _LIBCPP_ASSERT(__bytes <= __max_size(),
-            "do_deallocate called for size which exceeds the maximum allocation size");
-        size_t __s = __aligned_allocation_size(__bytes, _MaxAlign) / _MaxAlign;
-        __alloc_.deallocate((_ValueType*)__p, __s);
-    }
-
-    virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT {
-        __resource_adaptor_imp const * __p
-          = dynamic_cast<__resource_adaptor_imp const *>(&__other);
-        return __p  ? __alloc_ == __p->__alloc_ : false;
-    }
-
-private:
-    _LIBCPP_INLINE_VISIBILITY
-    size_t __max_size() const _NOEXCEPT {
-        return numeric_limits<size_t>::max() - _MaxAlign;
-    }
-};
-
-template <class _Alloc>
-using resource_adaptor = __resource_adaptor_imp<
-    typename allocator_traits<_Alloc>::template rebind_alloc<char>
-  >;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_MEMORY_RESOURCE */
diff --git a/include/experimental/regex b/include/experimental/regex
deleted file mode 100644
index d38891c..0000000
--- a/include/experimental/regex
+++ /dev/null
@@ -1,62 +0,0 @@
-// -*- C++ -*-
-//===----------------------------- regex ----------------------------------===//
-//
-//                     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_REGEX
-#define _LIBCPP_EXPERIMENTAL_REGEX
-/*
-    experimental/regex synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class BidirectionalIterator>
-  using match_results =
-    std::match_results<BidirectionalIterator,
-                       polymorphic_allocator<sub_match<BidirectionalIterator>>>;
-
-  typedef match_results<const char*> cmatch;
-  typedef match_results<const wchar_t*> wcmatch;
-  typedef match_results<string::const_iterator> smatch;
-  typedef match_results<wstring::const_iterator> wsmatch;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <regex>
-#include <experimental/string>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _BiDirIter>
-using match_results =
-    _VSTD::match_results<_BiDirIter,
-        polymorphic_allocator<_VSTD::sub_match<_BiDirIter>>>;
-
-typedef match_results<const char*> cmatch;
-typedef match_results<const wchar_t*> wcmatch;
-typedef match_results<_VSTD_LFTS_PMR::string::const_iterator> smatch;
-typedef match_results<_VSTD_LFTS_PMR::wstring::const_iterator> wsmatch;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_REGEX */
diff --git a/include/experimental/set b/include/experimental/set
deleted file mode 100644
index 20cf6d4..0000000
--- a/include/experimental/set
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- 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_EXPERIMENTAL_SET
-#define _LIBCPP_EXPERIMENTAL_SET
-/*
-    experimental/set synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class Key, class T, class Compare = less<Key>>
-  using set = std::set<Key, T, Compare,
-                       polymorphic_allocator<pair<const Key,T>>>;
-
-  template <class Key, class T, class Compare = less<Key>>
-  using multiset = std::multiset<Key, T, Compare,
-                                 polymorphic_allocator<pair<const Key,T>>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <set>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _Value, class  _Compare = less<_Value>>
-using set = _VSTD::set<_Value, _Compare,
-                        polymorphic_allocator<_Value>>;
-
-template <class _Value, class  _Compare = less<_Value>>
-using multiset = _VSTD::multiset<_Value, _Compare,
-                        polymorphic_allocator<_Value>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_SET */
diff --git a/include/experimental/string b/include/experimental/string
deleted file mode 100644
index 8b85451..0000000
--- a/include/experimental/string
+++ /dev/null
@@ -1,62 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- string ----------------------------------===//
-//
-//                     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_STRING
-#define _LIBCPP_EXPERIMENTAL_STRING
-/*
-    experimental/string synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  // basic_string using polymorphic allocator in namespace pmr
-  template <class charT, class traits = char_traits<charT>>
-   using basic_string =
-     std::basic_string<charT, traits, polymorphic_allocator<charT>>;
-
-  // basic_string typedef names using polymorphic allocator in namespace
-  // std::experimental::pmr
-  typedef basic_string<char> string;
-  typedef basic_string<char16_t> u16string;
-  typedef basic_string<char32_t> u32string;
-  typedef basic_string<wchar_t> wstring;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <string>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _CharT, class _Traits = char_traits<_CharT>>
-using basic_string =
-    _VSTD::basic_string<_CharT, _Traits, polymorphic_allocator<_CharT>>;
-
-typedef basic_string<char> string;
-typedef basic_string<char16_t> u16string;
-typedef basic_string<char32_t> u32string;
-typedef basic_string<wchar_t> wstring;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_STRING */
diff --git a/include/experimental/string_view b/include/experimental/string_view
index 93f77f3..2a20d7c 100644
--- a/include/experimental/string_view
+++ b/include/experimental/string_view
@@ -227,7 +227,7 @@
         basic_string_view(const _CharT* __s, size_type __len)
             : __data(__s), __size(__len)
         {
-//             _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
+//             _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): recieved nullptr");
         }
 
         _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
@@ -413,7 +413,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): recieved nullptr");
             return _VSTD::__str_find<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -428,7 +428,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): recieved nullptr");
             return _VSTD::__str_find<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -436,7 +436,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find(const _CharT* __s, size_type __pos = 0) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): recieved nullptr");
             return _VSTD::__str_find<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
@@ -445,7 +445,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): recieved nullptr");
             return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -460,7 +460,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): recieved nullptr");
             return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -468,7 +468,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type rfind(const _CharT* __s, size_type __pos=npos) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): recieved nullptr");
             return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
@@ -477,7 +477,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): recieved nullptr");
             return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -489,7 +489,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): recieved nullptr");
             return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -497,7 +497,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_of(const _CharT* __s, size_type __pos=0) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): recieved nullptr");
             return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
@@ -506,7 +506,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): recieved nullptr");
             return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -518,7 +518,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): recieved nullptr");
             return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -526,7 +526,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): recieved nullptr");
             return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
@@ -535,7 +535,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): recieved nullptr");
             return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -550,7 +550,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): recieved nullptr");
             return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -558,7 +558,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): recieved nullptr");
             return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
@@ -567,7 +567,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
         {
-            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): recieved nullptr");
             return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s.data(), __pos, __s.size());
         }
@@ -582,7 +582,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
         {
-            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): recieved nullptr");
             return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, __n);
         }
@@ -590,7 +590,7 @@
         _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
         {
-            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
+            _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): recieved nullptr");
             return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
                 (data(), size(), __s, __pos, traits_type::length(__s));
         }
diff --git a/include/experimental/tuple b/include/experimental/tuple
index e00d2ec..50d1e05 100644
--- a/include/experimental/tuple
+++ b/include/experimental/tuple
@@ -57,10 +57,9 @@
 
 template <class _Fn, class _Tuple, size_t ..._Id>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX11
 decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
                                   integer_sequence<size_t, _Id...>) {
-    return _VSTD::__invoke_constexpr(
+    return _VSTD::__invoke(
         _VSTD::forward<_Fn>(__f),
         _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...
     );
diff --git a/include/experimental/unordered_map b/include/experimental/unordered_map
deleted file mode 100644
index 1f998c2..0000000
--- a/include/experimental/unordered_map
+++ /dev/null
@@ -1,65 +0,0 @@
-// -*- C++ -*-
-//===------------------------- unordered_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_EXPERIMENTAL_UNORDERED_MAP
-#define _LIBCPP_EXPERIMENTAL_UNORDERED_MAP
-/*
-    experimental/unordered_map synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class Key, class T,
-            class Hash = hash<Key>,
-            class Pred = equal_to<Key>>
-  using unordered_map =
-    std::unordered_map<Key, T, Hash, Pred,
-                       polymorphic_allocator<pair<const Key,T>>>;
-
-  template <class Key, class T,
-            class Hash = hash<Key>,
-            class Pred = equal_to<Key>>
-  using unordered_multimap =
-    std::unordered_multimap<Key, T, Hash, Pred,
-                            polymorphic_allocator<pair<const Key,T>>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <unordered_map>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _Key, class _Value,
-          class _Hash = hash<_Key>, class _Pred = equal_to<_Key>>
-using unordered_map = _VSTD::unordered_map<_Key, _Value, _Hash, _Pred,
-                        polymorphic_allocator<pair<const _Key, _Value>>>;
-
-template <class _Key, class _Value,
-          class _Hash = hash<_Key>, class _Pred = equal_to<_Key>>
-using unordered_multimap = _VSTD::unordered_multimap<_Key, _Value, _Hash, _Pred,
-                        polymorphic_allocator<pair<const _Key, _Value>>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_UNORDERED_MAP */
diff --git a/include/experimental/unordered_set b/include/experimental/unordered_set
deleted file mode 100644
index d00a837..0000000
--- a/include/experimental/unordered_set
+++ /dev/null
@@ -1,59 +0,0 @@
-// -*- C++ -*-
-//===------------------------- unordered_set ------------------------------===//
-//
-//                     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_UNORDERED_SET
-#define _LIBCPP_EXPERIMENTAL_UNORDERED_SET
-/*
-    experimental/unordered_set synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class T, class Hash = hash<T>, class Pred = equal_to<T>>
-  using unordered_set = std::unordered_set<T, Hash, Pred,
-                       polymorphic_allocator<T>>;
-
-  template <class T, class Hash = hash<T>, class Pred = equal_to<T>>
-  using unordered_multiset = std::unordered_multiset<T, Hash, Pred,
-                       polymorphic_allocator<T>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <unordered_set>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _Value,
-          class _Hash = hash<_Value>, class _Pred = equal_to<_Value>>
-using unordered_set = _VSTD::unordered_set<_Value, _Hash, _Pred,
-                        polymorphic_allocator<_Value>>;
-
-template <class _Value,
-          class _Hash = hash<_Value>, class _Pred = equal_to<_Value>>
-using unordered_multiset = _VSTD::unordered_multiset<_Value, _Hash, _Pred,
-                        polymorphic_allocator<_Value>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_UNORDERED_SET */
diff --git a/include/experimental/vector b/include/experimental/vector
deleted file mode 100644
index bd10492..0000000
--- a/include/experimental/vector
+++ /dev/null
@@ -1,47 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- vector ------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_EXPERIMENTAL_VECTOR
-#define _LIBCPP_EXPERIMENTAL_VECTOR
-/*
-    experimental/vector synopsis
-
-// C++1z
-namespace std {
-namespace experimental {
-inline namespace fundamentals_v1 {
-namespace pmr {
-
-  template <class T>
-  using vector = std::vector<T, polymorphic_allocator<T>>;
-
-} // namespace pmr
-} // namespace fundamentals_v1
-} // namespace experimental
-} // namespace std
-
- */
-
-#include <experimental/__config>
-#include <vector>
-#include <experimental/memory_resource>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-template <class _ValueT>
-using vector = _VSTD::vector<_ValueT, polymorphic_allocator<_ValueT>>;
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
-
-#endif /* _LIBCPP_EXPERIMENTAL_VECTOR */
diff --git a/include/ext/hash_map b/include/ext/hash_map
index 5e1e9f5..31fcedf 100644
--- a/include/ext/hash_map
+++ b/include/ext/hash_map
@@ -309,7 +309,7 @@
 {
     typedef _Alloc                              allocator_type;
     typedef allocator_traits<allocator_type>    __alloc_traits;
-    typedef typename __alloc_traits::value_type::__node_value_type value_type;
+    typedef typename __alloc_traits::value_type::value_type value_type;
 public:
     typedef typename __alloc_traits::pointer    pointer;
 private:
@@ -368,6 +368,7 @@
 {
     _HashIterator __i_;
 
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
     typedef const typename _HashIterator::value_type::first_type key_type;
     typedef typename _HashIterator::value_type::second_type      mapped_type;
 public:
@@ -375,8 +376,13 @@
     typedef pair<key_type, mapped_type>                          value_type;
     typedef typename _HashIterator::difference_type              difference_type;
     typedef value_type&                                          reference;
-    typedef typename __rebind_pointer<typename _HashIterator::pointer, value_type>::type
-        pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {}
 
@@ -413,6 +419,7 @@
 {
     _HashIterator __i_;
 
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
     typedef const typename _HashIterator::value_type::first_type key_type;
     typedef typename _HashIterator::value_type::second_type      mapped_type;
 public:
@@ -420,8 +427,13 @@
     typedef pair<key_type, mapped_type>                          value_type;
     typedef typename _HashIterator::difference_type              difference_type;
     typedef const value_type&                                    reference;
-    typedef typename __rebind_pointer<typename _HashIterator::pointer, const value_type>::type
-        pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {}
 
@@ -549,7 +561,6 @@
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -670,12 +681,12 @@
     __h.get_deleter().__first_constructed = true;
     __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
     __h.get_deleter().__second_constructed = true;
-    return _LIBCPP_EXPLICIT_MOVE(__h);  // explicitly moved for C++03
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                        _InputIterator __last)
@@ -821,7 +832,6 @@
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -929,7 +939,7 @@
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                             _InputIterator __last)
diff --git a/include/ext/hash_set b/include/ext/hash_set
index 91850b5..c4bb898 100644
--- a/include/ext/hash_set
+++ b/include/ext/hash_set
@@ -282,7 +282,6 @@
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -386,7 +385,7 @@
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                     _InputIterator __last)
@@ -503,7 +502,6 @@
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -608,7 +606,7 @@
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                          _InputIterator __last)
diff --git a/include/float.h b/include/float.h
deleted file mode 100644
index 1acfdc6..0000000
--- a/include/float.h
+++ /dev/null
@@ -1,83 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- float.h ----------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_FLOAT_H
-#define _LIBCPP_FLOAT_H
-
-/*
-    float.h synopsis
-
-Macros:
-
-    FLT_ROUNDS
-    FLT_EVAL_METHOD     // C99
-    FLT_RADIX
-
-    FLT_MANT_DIG
-    DBL_MANT_DIG
-    LDBL_MANT_DIG
-
-    DECIMAL_DIG         // C99
-
-    FLT_DIG
-    DBL_DIG
-    LDBL_DIG
-
-    FLT_MIN_EXP
-    DBL_MIN_EXP
-    LDBL_MIN_EXP
-
-    FLT_MIN_10_EXP
-    DBL_MIN_10_EXP
-    LDBL_MIN_10_EXP
-
-    FLT_MAX_EXP
-    DBL_MAX_EXP
-    LDBL_MAX_EXP
-
-    FLT_MAX_10_EXP
-    DBL_MAX_10_EXP
-    LDBL_MAX_10_EXP
-
-    FLT_MAX
-    DBL_MAX
-    LDBL_MAX
-
-    FLT_EPSILON
-    DBL_EPSILON
-    LDBL_EPSILON
-
-    FLT_MIN
-    DBL_MIN
-    LDBL_MIN
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <float.h>
-
-#ifdef __cplusplus
-
-#ifndef FLT_EVAL_METHOD
-#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
-#endif
-
-#ifndef DECIMAL_DIG
-#define DECIMAL_DIG __DECIMAL_DIG__
-#endif
-
-#endif // __cplusplus
-
-#endif  // _LIBCPP_FLOAT_H
diff --git a/include/forward_list b/include/forward_list
index 18b300d..8a87fc5 100644
--- a/include/forward_list
+++ b/include/forward_list
@@ -183,77 +183,29 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp, class _VoidPtr> struct __forward_list_node;
-template <class _NodePtr> struct __forward_begin_node;
-
-
-template <class>
-struct __forward_list_node_value_type;
-
-template <class _Tp, class _VoidPtr>
-struct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > {
-  typedef _Tp type;
-};
-
-template <class _NodePtr>
-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 <class _NodePtr>
 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_);
-    }
+     _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
 };
 
 template <class _Tp, class _VoidPtr>
 struct _LIBCPP_HIDDEN __begin_node_of
 {
-    typedef __forward_begin_node<
-        typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type
-    > type;
+    typedef __forward_begin_node
+        <
+             typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                 rebind<__forward_list_node<_Tp, _VoidPtr> >
+#else
+                 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
+#endif
+         > type;
 };
 
 template <class _Tp, class _VoidPtr>
@@ -265,68 +217,49 @@
     value_type __value_;
 };
 
-
 template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY forward_list;
 template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
 
 template <class _NodePtr>
 class _LIBCPP_TYPE_VIS_ONLY __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;
+    typedef _NodePtr __node_pointer;
 
-    __iter_node_pointer __ptr_;
+    __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)) {}
+    explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 
     template<class, class> friend class _LIBCPP_TYPE_VIS_ONLY forward_list;
     template<class> friend class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
 
 public:
     typedef forward_iterator_tag                              iterator_category;
-    typedef typename __traits::__node_value_type              value_type;
+    typedef typename pointer_traits<__node_pointer>::element_type::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;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                              pointer;
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
+    reference operator*() const {return __ptr_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {
-        return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_);
-    }
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_iterator& operator++()
     {
-        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
+        __ptr_ = __ptr_->__next_;
         return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -350,49 +283,40 @@
 template <class _NodeConstPtr>
 class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator
 {
-    static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), "");
-    typedef _NodeConstPtr _NodePtr;
+    typedef _NodeConstPtr __node_const_pointer;
 
-    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_));
-    }
+    __node_const_pointer __ptr_;
 
     _LIBCPP_INLINE_VISIBILITY
-    explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
-        : __ptr_(nullptr) {}
+    explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT
+        : __ptr_(__p) {}
 
-    _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)) {}
-
+    typedef typename remove_const
+        <
+            typename pointer_traits<__node_const_pointer>::element_type
+        >::type                                               __node;
+    typedef typename pointer_traits<__node_const_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__node>
+#else
+            rebind<__node>::other
+#endif
+                                                              __node_pointer;
 
     template<class, class> friend class forward_list;
 
 public:
     typedef forward_iterator_tag                              iterator_category;
-    typedef typename __traits::__node_value_type              value_type;
+    typedef typename __node::value_type                       value_type;
     typedef const value_type&                                 reference;
-    typedef typename pointer_traits<__node_pointer>::difference_type
+    typedef typename pointer_traits<__node_const_pointer>::difference_type
                                                               difference_type;
-    typedef typename __rebind_pointer<__node_pointer, const value_type>::type
+    typedef typename pointer_traits<__node_const_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
                                                               pointer;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -402,15 +326,14 @@
         : __ptr_(__p.__ptr_) {}
 
     _LIBCPP_INLINE_VISIBILITY
-    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
+    reference operator*() const {return __ptr_->__value_;}
     _LIBCPP_INLINE_VISIBILITY
-    pointer operator->() const {return pointer_traits<pointer>::pointer_to(
-                __get_unsafe_node_pointer()->__value_);}
+    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
 
     _LIBCPP_INLINE_VISIBILITY
     __forward_list_const_iterator& operator++()
     {
-        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
+        __ptr_ = __ptr_->__next_;
         return *this;
     }
     _LIBCPP_INLINE_VISIBILITY
@@ -444,21 +367,21 @@
     typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
     typedef allocator_traits<__node_allocator>        __node_traits;
     typedef typename __node_traits::pointer           __node_pointer;
+    typedef typename __node_traits::pointer           __node_const_pointer;
 
-    typedef typename __rebind_alloc_helper<
-        allocator_traits<allocator_type>, __begin_node
-    >::type                                           __begin_node_allocator;
-    typedef typename allocator_traits<__begin_node_allocator>::pointer
-                                                      __begin_node_pointer;
+    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __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());}
+    __node_pointer        __before_begin() _NOEXCEPT
+        {return static_cast<__node_pointer>(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()));}
+    __node_const_pointer  __before_begin() const _NOEXCEPT
+        {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
+                                        pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
 
     _LIBCPP_INLINE_VISIBILITY
           __node_allocator& __alloc() _NOEXCEPT
@@ -480,10 +403,8 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 public:
-    _LIBCPP_INLINE_VISIBILITY
     __forward_list_base(__forward_list_base&& __x)
         _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
-    _LIBCPP_INLINE_VISIBILITY
     __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
@@ -508,7 +429,6 @@
               __node_traits::propagate_on_container_move_assignment::value>());}
 
 public:
-    _LIBCPP_INLINE_VISIBILITY
     void swap(__forward_list_base& __x)
 #if _LIBCPP_STD_VER >= 14
         _NOEXCEPT;
@@ -542,7 +462,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __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_))
@@ -551,7 +471,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
                                                       const allocator_type& __a)
     : __before_begin_(__begin_node(), __node_allocator(__a))
@@ -572,7 +492,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
 #if _LIBCPP_STD_VER >= 14
@@ -609,18 +529,14 @@
 {
     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;
+    typedef typename base::__node            __node;
+    typedef typename base::__node_traits     __node_traits;
+    typedef typename base::__node_pointer    __node_pointer;
 
 public:
     typedef _Tp    value_type;
     typedef _Alloc allocator_type;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::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<allocator_type>::pointer         pointer;
@@ -635,7 +551,6 @@
     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
@@ -672,14 +587,12 @@
 
     forward_list& operator=(const forward_list& __x);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     forward_list& operator=(forward_list&& __x)
         _NOEXCEPT_(
              __node_traits::propagate_on_container_move_assignment::value &&
              is_nothrow_move_assignable<allocator_type>::value);
 #endif
 #ifndef  _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     forward_list& operator=(initializer_list<value_type> __il);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
@@ -692,7 +605,6 @@
         assign(_InputIterator __f, _InputIterator __l);
     void assign(size_type __n, const value_type& __v);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     void assign(initializer_list<value_type> __il);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
@@ -823,7 +735,7 @@
     template <class _Compare> void merge(forward_list& __x, _Compare __comp);
     _LIBCPP_INLINE_VISIBILITY
     void sort() {sort(__less<value_type>());}
-    template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp);
+    template <class _Compare> void sort(_Compare __comp);
     void reverse() _NOEXCEPT;
 
 private:
@@ -846,7 +758,7 @@
 };
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
     : base(__a)
 {
@@ -860,8 +772,8 @@
         __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())
+        for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
+                                                             __p = __p->__next_)
         {
             __h.reset(__node_traits::allocate(__a, 1));
             __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
@@ -881,8 +793,8 @@
         __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())
+        for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
+                                                             __p = __p->__next_)
         {
             __h.reset(__node_traits::allocate(__a, 1));
             __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
@@ -1020,7 +932,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 forward_list<_Tp, _Alloc>&
 forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
     _NOEXCEPT_(
@@ -1037,7 +949,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 forward_list<_Tp, _Alloc>&
 forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
 {
@@ -1085,7 +997,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
 {
@@ -1158,7 +1070,7 @@
 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_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1175,7 +1087,7 @@
 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_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1191,7 +1103,7 @@
 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_pointer const __r = __p.__ptr_;
     __node_allocator& __a = base::__alloc();
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@@ -1206,7 +1118,7 @@
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
                                         const value_type& __v)
 {
-    __begin_node_pointer __r = __p.__get_begin();
+    __node_pointer __r = __p.__ptr_;
     if (__n > 0)
     {
         __node_allocator& __a = base::__alloc();
@@ -1241,7 +1153,7 @@
 #endif  // _LIBCPP_NO_EXCEPTIONS
         __last->__next_ = __r->__next_;
         __r->__next_ = __first;
-        __r = static_cast<__begin_node_pointer>(__last);
+        __r = __last;
     }
     return iterator(__r);
 }
@@ -1256,7 +1168,7 @@
 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
                                         _InputIterator __f, _InputIterator __l)
 {
-    __begin_node_pointer __r = __p.__get_begin();
+    __node_pointer __r = __p.__ptr_;
     if (__f != __l)
     {
         __node_allocator& __a = base::__alloc();
@@ -1291,7 +1203,7 @@
 #endif  // _LIBCPP_NO_EXCEPTIONS
         __last->__next_ = __r->__next_;
         __r->__next_ = __first;
-        __r = static_cast<__begin_node_pointer>(__last);
+        __r = __last;
     }
     return iterator(__r);
 }
@@ -1300,7 +1212,7 @@
 typename forward_list<_Tp, _Alloc>::iterator
 forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
 {
-    __begin_node_pointer __p = __f.__get_begin();
+    __node_pointer __p = __f.__ptr_;
     __node_pointer __n = __p->__next_;
     __p->__next_ = __n->__next_;
     __node_allocator& __a = base::__alloc();
@@ -1313,22 +1225,21 @@
 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();
+    __node_pointer __e = __l.__ptr_;
     if (__f != __l)
     {
-        __begin_node_pointer __bp = __f.__get_begin();
-
-        __node_pointer __n = __bp->__next_;
+        __node_pointer __p = __f.__ptr_;
+        __node_pointer __n = __p->__next_;
         if (__n != __e)
         {
-            __bp->__next_ = __e;
+            __p->__next_ = __e;
             __node_allocator& __a = base::__alloc();
             do
             {
-                __node_pointer __tmp = __n->__next_;
+                __p = __n->__next_;
                 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
                 __node_traits::deallocate(__a, __n, 1);
-                __n = __tmp;
+                __n = __p;
             } while (__n != __e);
         }
     }
@@ -1355,8 +1266,8 @@
             __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())
+            for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
+                                                         __ptr = __ptr->__next_)
             {
                 __h.reset(__node_traits::allocate(__a, 1));
                 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
@@ -1387,8 +1298,8 @@
             __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())
+            for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
+                                                         __ptr = __ptr->__next_)
             {
                 __h.reset(__node_traits::allocate(__a, 1));
                 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
@@ -1406,14 +1317,14 @@
 {
     if (!__x.empty())
     {
-        if (__p.__get_begin()->__next_ != nullptr)
+        if (__p.__ptr_->__next_ != nullptr)
         {
             const_iterator __lm1 = __x.before_begin();
-            while (__lm1.__get_begin()->__next_ != nullptr)
+            while (__lm1.__ptr_->__next_ != nullptr)
                 ++__lm1;
-            __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
+            __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
         }
-        __p.__get_begin()->__next_ = __x.__before_begin()->__next_;
+        __p.__ptr_->__next_ = __x.__before_begin()->__next_;
         __x.__before_begin()->__next_ = nullptr;
     }
 }
@@ -1427,9 +1338,9 @@
     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();
+        __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
+        __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
+        __p.__ptr_->__next_ = __lm1.__ptr_;
     }
 }
 
@@ -1442,13 +1353,13 @@
     if (__f != __l && __p != __f)
     {
         const_iterator __lm1 = __f;
-        while (__lm1.__get_begin()->__next_ != __l.__get_begin())
+        while (__lm1.__ptr_->__next_ != __l.__ptr_)
             ++__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();
+            __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
+            __p.__ptr_->__next_ = __f.__ptr_->__next_;
+            __f.__ptr_->__next_ = __l.__ptr_;
         }
     }
 }
@@ -1492,9 +1403,9 @@
 {
     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;)
+    for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
     {
-        if (__i.__get_begin()->__next_->__value_ == __v)
+        if (__i.__ptr_->__next_->__value_ == __v)
         {
             iterator __j = _VSTD::next(__i, 2);
             for (; __j != __e && *__j == __v; ++__j)
@@ -1515,9 +1426,9 @@
 forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
 {
     iterator __e = end();
-    for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
+    for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
     {
-        if (__pred(__i.__get_begin()->__next_->__value_))
+        if (__pred(__i.__ptr_->__next_->__value_))
         {
             iterator __j = _VSTD::next(__i, 2);
             for (; __j != __e && __pred(*__j); ++__j)
@@ -1542,7 +1453,7 @@
         iterator __j = _VSTD::next(__i);
         for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
             ;
-        if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
+        if (__i.__ptr_->__next_ != __j.__ptr_)
             erase_after(__i, __j);
         __i = __j;
     }
@@ -1609,7 +1520,7 @@
 
 template <class _Tp, class _Alloc>
 template <class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 forward_list<_Tp, _Alloc>::sort(_Compare __comp)
 {
@@ -1640,7 +1551,7 @@
     }
     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 __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
     __node_pointer __f2 = __t->__next_;
     __t->__next_ = nullptr;
     return __merge(__sort(__f1, __sz1, __comp),
diff --git a/include/fstream b/include/fstream
index d51da45..1f289ed 100644
--- a/include/fstream
+++ b/include/fstream
@@ -200,17 +200,14 @@
 
     // 27.9.1.3 Assign/swap:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _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();
@@ -343,7 +340,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_filebuf<_CharT, _Traits>&
 basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs)
 {
@@ -461,7 +458,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 basic_filebuf<_CharT, _Traits>::is_open() const
 {
@@ -550,7 +547,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_filebuf<_CharT, _Traits>*
 basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
 {
@@ -1011,35 +1008,26 @@
     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_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_ifstream(basic_ifstream&& __rhs);
 #endif
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_ifstream& operator=(basic_ifstream&& __rhs);
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     void swap(basic_ifstream& __rhs);
 
-    _LIBCPP_INLINE_VISIBILITY
     basic_filebuf<char_type, traits_type>* 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:
@@ -1047,7 +1035,7 @@
 };
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ifstream<_CharT, _Traits>::basic_ifstream()
     : basic_istream<char_type, traits_type>(&__sb_)
 {
@@ -1055,7 +1043,7 @@
 
 #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
     : basic_istream<char_type, traits_type>(&__sb_)
 {
@@ -1064,7 +1052,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
     : basic_istream<char_type, traits_type>(&__sb_)
 {
@@ -1076,7 +1064,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
     : basic_istream<char_type, traits_type>(_VSTD::move(__rhs)),
       __sb_(_VSTD::move(__rhs.__sb_))
@@ -1085,7 +1073,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ifstream<_CharT, _Traits>&
 basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs)
 {
@@ -1097,7 +1085,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs)
 {
@@ -1114,7 +1102,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_filebuf<_CharT, _Traits>*
 basic_ifstream<_CharT, _Traits>::rdbuf() const
 {
@@ -1122,7 +1110,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 basic_ifstream<_CharT, _Traits>::is_open() const
 {
@@ -1152,7 +1140,7 @@
 #endif
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_ifstream<_CharT, _Traits>::close()
 {
@@ -1173,33 +1161,24 @@
     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_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_ofstream(basic_ofstream&& __rhs);
 #endif
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_ofstream& operator=(basic_ofstream&& __rhs);
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     void swap(basic_ofstream& __rhs);
 
-    _LIBCPP_INLINE_VISIBILITY
     basic_filebuf<char_type, traits_type>* 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:
@@ -1207,7 +1186,7 @@
 };
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ofstream<_CharT, _Traits>::basic_ofstream()
     : basic_ostream<char_type, traits_type>(&__sb_)
 {
@@ -1215,7 +1194,7 @@
 
 #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
     : basic_ostream<char_type, traits_type>(&__sb_)
 {
@@ -1224,7 +1203,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
     : basic_ostream<char_type, traits_type>(&__sb_)
 {
@@ -1236,7 +1215,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
     : basic_ostream<char_type, traits_type>(_VSTD::move(__rhs)),
       __sb_(_VSTD::move(__rhs.__sb_))
@@ -1245,7 +1224,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_ofstream<_CharT, _Traits>&
 basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs)
 {
@@ -1257,7 +1236,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs)
 {
@@ -1274,7 +1253,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_filebuf<_CharT, _Traits>*
 basic_ofstream<_CharT, _Traits>::rdbuf() const
 {
@@ -1282,7 +1261,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 basic_ofstream<_CharT, _Traits>::is_open() const
 {
@@ -1312,7 +1291,7 @@
 #endif
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_ofstream<_CharT, _Traits>::close()
 {
@@ -1333,35 +1312,26 @@
     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_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_fstream(basic_fstream&& __rhs);
 #endif
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     basic_fstream& operator=(basic_fstream&& __rhs);
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     void swap(basic_fstream& __rhs);
 
-    _LIBCPP_INLINE_VISIBILITY
     basic_filebuf<char_type, traits_type>* 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:
@@ -1369,7 +1339,7 @@
 };
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_fstream<_CharT, _Traits>::basic_fstream()
     : basic_iostream<char_type, traits_type>(&__sb_)
 {
@@ -1377,7 +1347,7 @@
 
 #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
     : basic_iostream<char_type, traits_type>(&__sb_)
 {
@@ -1386,7 +1356,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
     : basic_iostream<char_type, traits_type>(&__sb_)
 {
@@ -1398,7 +1368,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
     : basic_iostream<char_type, traits_type>(_VSTD::move(__rhs)),
       __sb_(_VSTD::move(__rhs.__sb_))
@@ -1407,7 +1377,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_fstream<_CharT, _Traits>&
 basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs)
 {
@@ -1419,7 +1389,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs)
 {
@@ -1436,7 +1406,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 basic_filebuf<_CharT, _Traits>*
 basic_fstream<_CharT, _Traits>::rdbuf() const
 {
@@ -1444,7 +1414,7 @@
 }
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bool
 basic_fstream<_CharT, _Traits>::is_open() const
 {
@@ -1474,7 +1444,7 @@
 #endif
 
 template <class _CharT, class _Traits>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_fstream<_CharT, _Traits>::close()
 {
diff --git a/include/functional b/include/functional
index 4fcd4b5..6c57de0 100644
--- a/include/functional
+++ b/include/functional
@@ -407,7 +407,7 @@
     // function modifiers:
     void swap(function&) noexcept;
     template<class F, class Alloc>
-      void assign(F&&, const Alloc&);                 // Removed in C++17
+      void assign(F&&, const Alloc&);
 
     // function capacity:
     explicit operator bool() const noexcept;
@@ -1249,7 +1249,7 @@
     type __f_;
 
 public:
-    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
+    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
     // invoke
@@ -1262,109 +1262,29 @@
 #else
 
     template <class _A0>
-    _LIBCPP_INLINE_VISIBILITY
     typename __invoke_return0<type, _A0>::type
     operator() (_A0& __a0) const {
         return __invoke(__f_, __a0);
     }
 
-    template <class _A0>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return0<type, _A0 const>::type
-    operator() (_A0 const& __a0) const {
-        return __invoke(__f_, __a0);
-    }
-
     template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
     typename __invoke_return1<type, _A0, _A1>::type
     operator() (_A0& __a0, _A1& __a1) const {
         return __invoke(__f_, __a0, __a1);
     }
 
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0 const, _A1>::type
-    operator() (_A0 const& __a0, _A1& __a1) const {
-        return __invoke(__f_, __a0, __a1);
-    }
-
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0, _A1 const>::type
-    operator() (_A0& __a0, _A1 const& __a1) const {
-        return __invoke(__f_, __a0, __a1);
-    }
-
-    template <class _A0, class _A1>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return1<type, _A0 const, _A1 const>::type
-    operator() (_A0 const& __a0, _A1 const& __a1) const {
-        return __invoke(__f_, __a0, __a1);
-    }
-
     template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
     typename __invoke_return2<type, _A0, _A1, _A2>::type
     operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
         return __invoke(__f_, __a0, __a1, __a2);
     }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1, _A2>::type
-    operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1 const, _A2>::type
-    operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1, _A2 const>::type
-    operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
-    operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
-    operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
-    operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
-
-    template <class _A0, class _A1, class _A2>
-    _LIBCPP_INLINE_VISIBILITY
-    typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
-    operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
-        return __invoke(__f_, __a0, __a1, __a2);
-    }
 #endif
 };
 
 template<class _Rp, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 __mem_fn<_Rp _Tp::*>
-mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
+mem_fn(_Rp _Tp::* __pm)
 {
     return __mem_fn<_Rp _Tp::*>(__pm);
 }
@@ -1407,22 +1327,6 @@
 {
 };
 
-template <class _Fp>
-_LIBCPP_INLINE_VISIBILITY
-bool __not_null(_Fp const&) { return true; }
-
-template <class _Fp>
-_LIBCPP_INLINE_VISIBILITY
-bool __not_null(_Fp* __ptr) { return __ptr; }
-
-template <class _Ret, class _Class>
-_LIBCPP_INLINE_VISIBILITY
-bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
-
-template <class _Fp>
-_LIBCPP_INLINE_VISIBILITY
-bool __not_null(function<_Fp> const& __f) { return !!__f; }
-
 } // namespace __function
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -1564,9 +1468,27 @@
     typename aligned_storage<3*sizeof(void*)>::type __buf_;
     __base* __f_;
 
-    _LIBCPP_NO_CFI static __base *__as_base(void *p) {
-      return reinterpret_cast<__base*>(p);
-    }
+    template <class _Fp>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const _Fp&) {return true;}
+    template <class _R2, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
+    template <class _R2, class _Cp, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
+    template <class _R2, class _Cp, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
+    template <class _R2, class _Cp, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
+    template <class _R2, class _Cp, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
+    template <class _R2, class ..._Ap>
+        _LIBCPP_INLINE_VISIBILITY
+        static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;}
 
     template <class _Fp, bool = !is_same<_Fp, function>::value &&
                                 __invokable<_Fp&, _ArgTypes...>::value>
@@ -1630,13 +1552,10 @@
 
     // function modifiers:
     void swap(function&) _NOEXCEPT;
-
-#if _LIBCPP_STD_VER <= 14
     template<class _Fp, class _Alloc>
       _LIBCPP_INLINE_VISIBILITY
       void assign(_Fp&& __f, const _Alloc& __a)
         {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
-#endif
 
     // function capacity:
     _LIBCPP_INLINE_VISIBILITY
@@ -1664,9 +1583,9 @@
 {
     if (__f.__f_ == 0)
         __f_ = 0;
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
     {
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
         __f.__f_->__clone(__f_);
     }
     else
@@ -1680,9 +1599,9 @@
 {
     if (__f.__f_ == 0)
         __f_ = 0;
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
     {
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
         __f.__f_->__clone(__f_);
     }
     else
@@ -1694,9 +1613,9 @@
 {
     if (__f.__f_ == 0)
         __f_ = 0;
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (__base*)&__f.__buf_)
     {
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
         __f.__f_->__clone(__f_);
     }
     else
@@ -1713,9 +1632,9 @@
 {
     if (__f.__f_ == 0)
         __f_ = 0;
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (__base*)&__f.__buf_)
     {
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
         __f.__f_->__clone(__f_);
     }
     else
@@ -1735,12 +1654,13 @@
                                      >::type*)
     : __f_(0)
 {
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
         if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
         {
-            __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(_VSTD::move(__f));
         }
         else
         {
@@ -1761,7 +1681,7 @@
     : __f_(0)
 {
     typedef allocator_traits<_Alloc> __alloc_traits;
-    if (__function::__not_null(__f))
+    if (__not_null(__f))
     {
         typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
         typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
@@ -1769,7 +1689,8 @@
         if (sizeof(_FF) <= sizeof(__buf_) && 
             is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
         {
-            __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a));
         }
         else
         {
@@ -1793,16 +1714,16 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
 {
-    if ((void *)__f_ == &__buf_)
+    if (__f_ == (__base*)&__buf_)
         __f_->destroy();
     else if (__f_)
         __f_->destroy_deallocate();
     __f_ = 0;
     if (__f.__f_ == 0)
         __f_ = 0;
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (__base*)&__f.__buf_)
     {
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
         __f.__f_->__clone(__f_);
     }
     else
@@ -1817,7 +1738,7 @@
 function<_Rp(_ArgTypes...)>&
 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
 {
-    if ((void *)__f_ == &__buf_)
+    if (__f_ == (__base*)&__buf_)
         __f_->destroy();
     else if (__f_)
         __f_->destroy_deallocate();
@@ -1842,7 +1763,7 @@
 template<class _Rp, class ..._ArgTypes>
 function<_Rp(_ArgTypes...)>::~function()
 {
-    if ((void *)__f_ == &__buf_)
+    if (__f_ == (__base*)&__buf_)
         __f_->destroy();
     else if (__f_)
         __f_->destroy_deallocate();
@@ -1852,34 +1773,34 @@
 void
 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
 {
-    if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
+    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
     {
         typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
-        __base* __t = __as_base(&__tempbuf);
+        __base* __t = (__base*)&__tempbuf;
         __f_->__clone(__t);
         __f_->destroy();
         __f_ = 0;
-        __f.__f_->__clone(__as_base(&__buf_));
+        __f.__f_->__clone((__base*)&__buf_);
         __f.__f_->destroy();
         __f.__f_ = 0;
-        __f_ = __as_base(&__buf_);
-        __t->__clone(__as_base(&__f.__buf_));
+        __f_ = (__base*)&__buf_;
+        __t->__clone((__base*)&__f.__buf_);
         __t->destroy();
-        __f.__f_ = __as_base(&__f.__buf_);
+        __f.__f_ = (__base*)&__f.__buf_;
     }
-    else if ((void *)__f_ == &__buf_)
+    else if (__f_ == (__base*)&__buf_)
     {
-        __f_->__clone(__as_base(&__f.__buf_));
+        __f_->__clone((__base*)&__f.__buf_);
         __f_->destroy();
         __f_ = __f.__f_;
-        __f.__f_ = __as_base(&__f.__buf_);
+        __f.__f_ = (__base*)&__f.__buf_;
     }
-    else if ((void *)__f.__f_ == &__f.__buf_)
+    else if (__f.__f_ == (__base*)&__f.__buf_)
     {
-        __f.__f_->__clone(__as_base(&__buf_));
+        __f.__f_->__clone((__base*)&__buf_);
         __f.__f_->destroy();
         __f.__f_ = __f_;
-        __f_ = __as_base(&__buf_);
+        __f_ = (__base*)&__buf_;
     }
     else
         _VSTD::swap(__f_, __f.__f_);
@@ -2473,22 +2394,6 @@
 {
 };
 
-#ifndef _LIBCPP_HAS_NO_INT128
-
-template <>
-struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
-    : public __scalar_hash<__int128_t>
-{
-};
-
-template <>
-struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
-    : public __scalar_hash<__uint128_t>
-{
-};
-
-#endif
-
 template <>
 struct _LIBCPP_TYPE_VIS_ONLY hash<float>
     : public __scalar_hash<float>
diff --git a/include/future b/include/future
index 957a23c..5b5afe6 100644
--- a/include/future
+++ b/include/future
@@ -512,16 +512,6 @@
     virtual ~future_error() _NOEXCEPT;
 };
 
-inline _LIBCPP_ALWAYS_INLINE
-void __throw_future_error(future_errc _Ev)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    throw future_error(make_error_code(_Ev));
-#else
-    assert(!"future_error");
-#endif
-}
-
 class _LIBCPP_TYPE_VIS __assoc_sub_state
     : public __shared_count
 {
@@ -576,7 +566,6 @@
     void wait();
     template <class _Rep, class _Period>
         future_status
-        _LIBCPP_INLINE_VISIBILITY
         wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
     template <class _Clock, class _Duration>
         future_status
@@ -600,7 +589,7 @@
 }
 
 template <class _Rep, class _Period>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 future_status
 __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
 {
@@ -656,8 +645,10 @@
 #endif
 {
     unique_lock<mutex> __lk(this->__mut_);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (this->__has_value())
-        __throw_future_error(future_errc::promise_already_satisfied);
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
+#endif
     ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
     this->__state_ |= base::__constructed | base::ready;
     __cv_.notify_all();
@@ -673,8 +664,10 @@
 #endif
 {
     unique_lock<mutex> __lk(this->__mut_);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (this->__has_value())
-        __throw_future_error(future_errc::promise_already_satisfied);
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
+#endif
     ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
     this->__state_ |= base::__constructed;
     __thread_local_data()->__make_ready_at_thread_exit(this);
@@ -732,8 +725,10 @@
 __assoc_state<_Rp&>::set_value(_Rp& __arg)
 {
     unique_lock<mutex> __lk(this->__mut_);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (this->__has_value())
-        __throw_future_error(future_errc::promise_already_satisfied);
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
+#endif
     __value_ = _VSTD::addressof(__arg);
     this->__state_ |= base::__constructed | base::ready;
     __cv_.notify_all();
@@ -744,8 +739,10 @@
 __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
 {
     unique_lock<mutex> __lk(this->__mut_);
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (this->__has_value())
-        __throw_future_error(future_errc::promise_already_satisfied);
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
+#endif
     __value_ = _VSTD::addressof(__arg);
     this->__state_ |= base::__constructed;
     __thread_local_data()->__make_ready_at_thread_exit(this);
@@ -852,7 +849,6 @@
 
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     explicit __deferred_assoc_state(_Fp&& __f);
 #endif
 
@@ -862,7 +858,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Rp, class _Fp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
     : __func_(_VSTD::forward<_Fp>(__f))
 {
@@ -899,7 +895,6 @@
 
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     explicit __deferred_assoc_state(_Fp&& __f);
 #endif
 
@@ -909,7 +904,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Fp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
     : __func_(_VSTD::forward<_Fp>(__f))
 {
@@ -948,7 +943,6 @@
     virtual void __on_zero_shared() _NOEXCEPT;
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     explicit __async_assoc_state(_Fp&& __f);
 #endif
 
@@ -958,7 +952,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Rp, class _Fp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
     : __func_(_VSTD::forward<_Fp>(__f))
 {
@@ -1003,7 +997,6 @@
     virtual void __on_zero_shared() _NOEXCEPT;
 public:
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     explicit __async_assoc_state(_Fp&& __f);
 #endif
 
@@ -1013,7 +1006,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Fp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
     : __func_(_VSTD::forward<_Fp>(__f))
 {
@@ -1115,7 +1108,6 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~future();
-    _LIBCPP_INLINE_VISIBILITY
     shared_future<_Rp> share();
 
     // retrieving the value
@@ -1146,8 +1138,10 @@
 future<_Rp>::future(__assoc_state<_Rp>* __state)
     : __state_(__state)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_->__has_future_attached())
-        __throw_future_error(future_errc::future_already_retrieved);
+        throw future_error(make_error_code(future_errc::future_already_retrieved));
+#endif
     __state_->__add_shared();
     __state_->__set_future_attached();
 }
@@ -1218,7 +1212,6 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~future();
-    _LIBCPP_INLINE_VISIBILITY
     shared_future<_Rp&> share();
 
     // retrieving the value
@@ -1249,8 +1242,10 @@
 future<_Rp&>::future(__assoc_state<_Rp&>* __state)
     : __state_(__state)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_->__has_future_attached())
-        __throw_future_error(future_errc::future_already_retrieved);
+        throw future_error(make_error_code(future_errc::future_already_retrieved));
+#endif
     __state_->__add_shared();
     __state_->__set_future_attached();
 }
@@ -1316,7 +1311,6 @@
 public:
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~future();
-    _LIBCPP_INLINE_VISIBILITY
     shared_future<void> share();
 
     // retrieving the value
@@ -1451,8 +1445,10 @@
 future<_Rp>
 promise<_Rp>::get_future()
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     return future<_Rp>(__state_);
 }
 
@@ -1460,8 +1456,10 @@
 void
 promise<_Rp>::set_value(const _Rp& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value(__r);
 }
 
@@ -1471,8 +1469,10 @@
 void
 promise<_Rp>::set_value(_Rp&& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value(_VSTD::move(__r));
 }
 
@@ -1482,9 +1482,10 @@
 void
 promise<_Rp>::set_exception(exception_ptr __p)
 {
-    _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_exception(__p);
 }
 
@@ -1492,8 +1493,10 @@
 void
 promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value_at_thread_exit(__r);
 }
 
@@ -1503,8 +1506,10 @@
 void
 promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value_at_thread_exit(_VSTD::move(__r));
 }
 
@@ -1514,8 +1519,10 @@
 void
 promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_exception_at_thread_exit(__p);
 }
 
@@ -1612,8 +1619,10 @@
 future<_Rp&>
 promise<_Rp&>::get_future()
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     return future<_Rp&>(__state_);
 }
 
@@ -1621,8 +1630,10 @@
 void
 promise<_Rp&>::set_value(_Rp& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value(__r);
 }
 
@@ -1630,9 +1641,10 @@
 void
 promise<_Rp&>::set_exception(exception_ptr __p)
 {
-    _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_exception(__p);
 }
 
@@ -1640,8 +1652,10 @@
 void
 promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_value_at_thread_exit(__r);
 }
 
@@ -1649,8 +1663,10 @@
 void
 promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__state_ == nullptr)
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif
     __state_->set_exception_at_thread_exit(__p);
 }
 
@@ -1845,7 +1861,6 @@
 
     void swap(__packaged_task_function&) _NOEXCEPT;
 
-    _LIBCPP_INLINE_VISIBILITY
     _Rp operator()(_ArgTypes...) const;
 };
 
@@ -1985,7 +2000,7 @@
 }
 
 template<class _Rp, class ..._ArgTypes>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Rp
 __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
 {
@@ -2072,11 +2087,11 @@
 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
+    if (__p_.__state_ == nullptr)
+        throw future_error(make_error_code(future_errc::no_state));
+    if (__p_.__state_->__has_value())
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2094,11 +2109,11 @@
 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
+    if (__p_.__state_ == nullptr)
+        throw future_error(make_error_code(future_errc::no_state));
+    if (__p_.__state_->__has_value())
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2116,8 +2131,10 @@
 void
 packaged_task<_Rp(_ArgTypes...)>::reset()
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (!valid())
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif  // _LIBCPP_NO_EXCEPTIONS
     __p_ = promise<result_type>();
 }
 
@@ -2201,11 +2218,11 @@
 void
 packaged_task<void(_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
+    if (__p_.__state_ == nullptr)
+        throw future_error(make_error_code(future_errc::no_state));
+    if (__p_.__state_->__has_value())
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2224,11 +2241,11 @@
 void
 packaged_task<void(_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
+    if (__p_.__state_ == nullptr)
+        throw future_error(make_error_code(future_errc::no_state));
+    if (__p_.__state_->__has_value())
+        throw future_error(make_error_code(future_errc::promise_already_satisfied));
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
@@ -2247,8 +2264,10 @@
 void
 packaged_task<void(_ArgTypes...)>::reset()
 {
+#ifndef _LIBCPP_NO_EXCEPTIONS
     if (!valid())
-        __throw_future_error(future_errc::no_state);
+        throw future_error(make_error_code(future_errc::no_state));
+#endif  // _LIBCPP_NO_EXCEPTIONS
     __p_ = promise<result_type>();
 }
 
@@ -2573,7 +2592,7 @@
 }
 
 template <class _Rp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_future<_Rp>
 future<_Rp>::share()
 {
@@ -2581,7 +2600,7 @@
 }
 
 template <class _Rp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_future<_Rp&>
 future<_Rp&>::share()
 {
@@ -2590,7 +2609,7 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_future<void>
 future<void>::share()
 {
diff --git a/include/inttypes.h b/include/inttypes.h
deleted file mode 100644
index 5c5618b..0000000
--- a/include/inttypes.h
+++ /dev/null
@@ -1,251 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- inttypes.h -------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_INTTYPES_H
-#define _LIBCPP_INTTYPES_H
-
-/*
-    inttypes.h synopsis
-
-This entire header is C99 / C++0X
-
-#include <stdint.h>  // <cinttypes> includes <cstdint>
-
-Macros:
-
-    PRId8
-    PRId16
-    PRId32
-    PRId64
-
-    PRIdLEAST8
-    PRIdLEAST16
-    PRIdLEAST32
-    PRIdLEAST64
-
-    PRIdFAST8
-    PRIdFAST16
-    PRIdFAST32
-    PRIdFAST64
-
-    PRIdMAX
-    PRIdPTR
-
-    PRIi8
-    PRIi16
-    PRIi32
-    PRIi64
-
-    PRIiLEAST8
-    PRIiLEAST16
-    PRIiLEAST32
-    PRIiLEAST64
-
-    PRIiFAST8
-    PRIiFAST16
-    PRIiFAST32
-    PRIiFAST64
-
-    PRIiMAX
-    PRIiPTR
-
-    PRIo8
-    PRIo16
-    PRIo32
-    PRIo64
-
-    PRIoLEAST8
-    PRIoLEAST16
-    PRIoLEAST32
-    PRIoLEAST64
-
-    PRIoFAST8
-    PRIoFAST16
-    PRIoFAST32
-    PRIoFAST64
-
-    PRIoMAX
-    PRIoPTR
-
-    PRIu8
-    PRIu16
-    PRIu32
-    PRIu64
-
-    PRIuLEAST8
-    PRIuLEAST16
-    PRIuLEAST32
-    PRIuLEAST64
-
-    PRIuFAST8
-    PRIuFAST16
-    PRIuFAST32
-    PRIuFAST64
-
-    PRIuMAX
-    PRIuPTR
-
-    PRIx8
-    PRIx16
-    PRIx32
-    PRIx64
-
-    PRIxLEAST8
-    PRIxLEAST16
-    PRIxLEAST32
-    PRIxLEAST64
-
-    PRIxFAST8
-    PRIxFAST16
-    PRIxFAST32
-    PRIxFAST64
-
-    PRIxMAX
-    PRIxPTR
-
-    PRIX8
-    PRIX16
-    PRIX32
-    PRIX64
-
-    PRIXLEAST8
-    PRIXLEAST16
-    PRIXLEAST32
-    PRIXLEAST64
-
-    PRIXFAST8
-    PRIXFAST16
-    PRIXFAST32
-    PRIXFAST64
-
-    PRIXMAX
-    PRIXPTR
-
-    SCNd8
-    SCNd16
-    SCNd32
-    SCNd64
-
-    SCNdLEAST8
-    SCNdLEAST16
-    SCNdLEAST32
-    SCNdLEAST64
-
-    SCNdFAST8
-    SCNdFAST16
-    SCNdFAST32
-    SCNdFAST64
-
-    SCNdMAX
-    SCNdPTR
-
-    SCNi8
-    SCNi16
-    SCNi32
-    SCNi64
-
-    SCNiLEAST8
-    SCNiLEAST16
-    SCNiLEAST32
-    SCNiLEAST64
-
-    SCNiFAST8
-    SCNiFAST16
-    SCNiFAST32
-    SCNiFAST64
-
-    SCNiMAX
-    SCNiPTR
-
-    SCNo8
-    SCNo16
-    SCNo32
-    SCNo64
-
-    SCNoLEAST8
-    SCNoLEAST16
-    SCNoLEAST32
-    SCNoLEAST64
-
-    SCNoFAST8
-    SCNoFAST16
-    SCNoFAST32
-    SCNoFAST64
-
-    SCNoMAX
-    SCNoPTR
-
-    SCNu8
-    SCNu16
-    SCNu32
-    SCNu64
-
-    SCNuLEAST8
-    SCNuLEAST16
-    SCNuLEAST32
-    SCNuLEAST64
-
-    SCNuFAST8
-    SCNuFAST16
-    SCNuFAST32
-    SCNuFAST64
-
-    SCNuMAX
-    SCNuPTR
-
-    SCNx8
-    SCNx16
-    SCNx32
-    SCNx64
-
-    SCNxLEAST8
-    SCNxLEAST16
-    SCNxLEAST32
-    SCNxLEAST64
-
-    SCNxFAST8
-    SCNxFAST16
-    SCNxFAST32
-    SCNxFAST64
-
-    SCNxMAX
-    SCNxPTR
-
-Types:
-
-    imaxdiv_t
-
-intmax_t  imaxabs(intmax_t j);
-imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
-intmax_t  strtoimax(const char* restrict nptr, char** restrict endptr, int base);
-uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base);
-intmax_t  wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
-uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <inttypes.h>
-
-#ifdef __cplusplus
-
-#include <stdint.h>
-
-#undef imaxabs
-#undef imaxdiv
-
-#endif // __cplusplus
-
-#endif  // _LIBCPP_INTTYPES_H
diff --git a/include/ios b/include/ios
index cbea478..ff79998 100644
--- a/include/ios
+++ b/include/ios
@@ -114,9 +114,9 @@
 public:
     // types:
     typedef charT char_type;
-    typedef typename traits::int_type int_type;  // removed in C++17
-    typedef typename traits::pos_type pos_type;  // removed in C++17
-    typedef typename traits::off_type off_type;  // removed in C++17
+    typedef typename traits::int_type int_type;
+    typedef typename traits::pos_type pos_type;
+    typedef typename traits::off_type off_type;
     typedef traits traits_type;
 
     operator unspecified-bool-type() const;
@@ -216,7 +216,7 @@
 #include <__locale>
 #include <system_error>
 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 #include <atomic>     // for __xindex_
 #endif
 
@@ -231,7 +231,7 @@
 class _LIBCPP_TYPE_VIS ios_base
 {
 public:
-    class _LIBCPP_EXCEPTION_ABI failure;
+    class _LIBCPP_TYPE_VIS failure;
 
     typedef unsigned int fmtflags;
     static const fmtflags boolalpha   = 0x0001;
@@ -254,12 +254,14 @@
     static const fmtflags floatfield  = scientific | fixed;
 
     typedef unsigned int iostate;
+    typedef iostate      io_state;
     static const iostate badbit  = 0x1;
     static const iostate eofbit  = 0x2;
     static const iostate failbit = 0x4;
     static const iostate goodbit = 0x0;
 
     typedef unsigned int openmode;
+    typedef openmode     open_mode;
     static const openmode app    = 0x01;
     static const openmode ate    = 0x02;
     static const openmode binary = 0x04;
@@ -268,15 +270,10 @@
     static const openmode trunc  = 0x20;
 
     enum seekdir {beg, cur, end};
-
-#if _LIBCPP_STD_VER <= 14
-    typedef iostate      io_state;
-    typedef openmode     open_mode;
-    typedef seekdir      seek_dir;
+    typedef seekdir seek_dir;
 
     typedef _VSTD::streamoff streamoff;
     typedef _VSTD::streampos streampos;
-#endif
 
     class _LIBCPP_TYPE_VIS Init;
 
@@ -370,9 +367,7 @@
     int*            __index_;
     size_t          __event_size_;
     size_t          __event_cap_;
-// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
-// enabled with clang.
-#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
     static atomic<int> __xindex_;
 #else
     static int      __xindex_;
diff --git a/include/iosfwd b/include/iosfwd
index e4149ef..eccfd34 100644
--- a/include/iosfwd
+++ b/include/iosfwd
@@ -194,11 +194,6 @@
 typedef basic_string<char, char_traits<char>, allocator<char> > string;
 typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
 
-
-// Include other forward declarations here
-template <class _Tp, class _Alloc = allocator<_Tp> >
-class _LIBCPP_TYPE_VIS_ONLY vector;
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_IOSFWD
diff --git a/include/istream b/include/istream
index 0bcc7ee..168a4d0 100644
--- a/include/istream
+++ b/include/istream
@@ -1407,7 +1407,6 @@
     try
     {
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        this->clear(this->rdstate() & ~ios_base::eofbit);
         sentry __sen(*this, true);
         if (__sen)
         {
diff --git a/include/iterator b/include/iterator
index 15be793..9ac4351 100644
--- a/include/iterator
+++ b/include/iterator
@@ -340,10 +340,10 @@
 */
 
 #include <__config>
-#include <iosfwd> // for forward declarations of vector and string.
 #include <__functional_base>
 #include <type_traits>
 #include <cstddef>
+#include <iosfwd>
 #include <initializer_list>
 #ifdef __APPLE__
 #include <Availability.h>
@@ -437,12 +437,6 @@
 template <class _Tp>
 struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
 
-template <class _Tp>
-struct __is_exactly_input_iterator
-    : public integral_constant<bool, 
-    	 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && 
-    	!__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
-
 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
          class _Pointer = _Tp*, class _Reference = _Tp&>
 struct _LIBCPP_TYPE_VIS_ONLY iterator
@@ -519,12 +513,12 @@
     return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
 }
 
-template <class _InputIter>
+template <class _ForwardIter>
 inline _LIBCPP_INLINE_VISIBILITY
-_InputIter
-next(_InputIter __x,
-     typename iterator_traits<_InputIter>::difference_type __n = 1,
-     typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
+_ForwardIter
+next(_ForwardIter __x,
+     typename iterator_traits<_ForwardIter>::difference_type __n = 1,
+     typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
 {
     _VSTD::advance(__x, __n);
     return __x;
@@ -772,14 +766,14 @@
     _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))
+    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__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 const _Tp* operator->() const {return &(operator*());}
     _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
         {
             if (!(*__in_stream_ >> __value_))
@@ -811,9 +805,9 @@
     const char_type* __delim_;
 public:
     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
-        : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
+        : __out_stream_(&__s), __delim_(0) {}
     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
-        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
+        : __out_stream_(&__s), __delim_(__delimiter) {}
     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
         {
             *__out_stream_ << __value_;
@@ -949,14 +943,9 @@
     typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
     typedef typename iterator_traits<iterator_type>::value_type value_type;
     typedef typename iterator_traits<iterator_type>::difference_type difference_type;
-    typedef iterator_type pointer;
+    typedef typename iterator_traits<iterator_type>::pointer pointer;
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    typedef typename iterator_traits<iterator_type>::reference __reference;
-    typedef typename conditional<
-            is_reference<__reference>::value,
-            typename remove_reference<__reference>::type&&,
-            __reference
-        >::type reference;
+    typedef value_type&& reference;
 #else
     typedef typename iterator_traits<iterator_type>::reference reference;
 #endif
@@ -969,7 +958,10 @@
     _LIBCPP_INLINE_VISIBILITY reference operator*() const {
       return static_cast<reference>(*__i);
     }
-    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const { return __i;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {
+      typename iterator_traits<iterator_type>::reference __ref = *__i;
+      return &__ref;
+    }
     _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
     _LIBCPP_INLINE_VISIBILITY move_iterator  operator++(int)
         {move_iterator __tmp(*this); ++__i; return __tmp;}
@@ -1189,7 +1181,7 @@
         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
                        "Attempted to dereference a non-dereferenceable iterator");
 #endif
-        return (pointer)_VSTD::addressof(*__i);
+        return (pointer)&reinterpret_cast<const volatile char&>(*__i);
     }
     _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
     {
@@ -1414,23 +1406,6 @@
     return __x;
 }
 
-template <class _Iter>
-struct __libcpp_is_trivial_iterator
-	: public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
-	
-template <class _Iter>
-struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
-	: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
-
-template <class _Iter>
-struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
-	: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
-
-template <class _Iter>
-struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
-	: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
-
-
 template <class _Tp, size_t _Np>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp*
diff --git a/include/limits b/include/limits
index 80a1be4..ce967ea 100644
--- a/include/limits
+++ b/include/limits
@@ -237,8 +237,7 @@
     static _LIBCPP_CONSTEXPR const bool is_bounded = true;
     static _LIBCPP_CONSTEXPR const bool is_modulo = !_VSTD::is_signed<_Tp>::value;
 
-#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || \
-    defined(__wasm__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__)
     static _LIBCPP_CONSTEXPR const bool traps = true;
 #else
     static _LIBCPP_CONSTEXPR const bool traps = false;
diff --git a/include/list b/include/list
index cff0a85..14201a8 100644
--- a/include/list
+++ b/include/list
@@ -175,7 +175,6 @@
 #include <initializer_list>
 #include <iterator>
 #include <algorithm>
-#include <type_traits>
 
 #include <__undef_min_max>
 
@@ -188,66 +187,34 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp, class _VoidPtr> struct __list_node;
-template <class _Tp, class _VoidPtr> struct __list_node_base;
-
-template <class _Tp, class _VoidPtr>
-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 <class _Tp, class _VoidPtr>
 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;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node<_Tp, _VoidPtr> > pointer;
+#else
+        rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
+#endif
 
-    __link_pointer __prev_;
-    __link_pointer __next_;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node_base> __base_pointer;
+#else
+        rebind<__list_node_base>::other __base_pointer;
+#endif
+
+    pointer __prev_;
+    pointer __next_;
 
     _LIBCPP_INLINE_VISIBILITY
-    __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
-                         __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
+    __list_node_base() : __prev_(__self()), __next_(__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());
+    pointer __self()
+    {
+        return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
     }
 };
 
@@ -256,14 +223,6 @@
     : 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 _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
@@ -273,21 +232,25 @@
 template <class _Tp, class _VoidPtr>
 class _LIBCPP_TYPE_VIS_ONLY __list_iterator
 {
-    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
-    typedef typename _NodeTraits::__link_pointer __link_pointer;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
+#else
+        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
+#endif
 
-    __link_pointer __ptr_;
+    __node_pointer __ptr_;
 
 #if _LIBCPP_DEBUG_LEVEL >= 2
     _LIBCPP_INLINE_VISIBILITY
-    explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
+    explicit __list_iterator(__node_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) {}
+    explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 #endif
 
 
@@ -299,7 +262,13 @@
     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<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                             pointer;
     typedef typename pointer_traits<pointer>::difference_type difference_type;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -345,7 +314,7 @@
         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
                        "Attempted to dereference a non-dereferenceable list::iterator");
 #endif
-        return __ptr_->__as_node()->__value_;
+        return __ptr_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     pointer operator->() const
@@ -354,7 +323,7 @@
         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
                        "Attempted to dereference a non-dereferenceable list::iterator");
 #endif
-        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
+        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -396,21 +365,25 @@
 template <class _Tp, class _VoidPtr>
 class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
 {
-    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
-    typedef typename _NodeTraits::__link_pointer __link_pointer;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
+#else
+        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
+#endif
 
-    __link_pointer __ptr_;
+    __node_pointer __ptr_;
 
 #if _LIBCPP_DEBUG_LEVEL >= 2
     _LIBCPP_INLINE_VISIBILITY
-    explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
+    explicit __list_const_iterator(__node_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) {}
+    explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
 #endif
 
     template<class, class> friend class list;
@@ -419,7 +392,13 @@
     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<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                             pointer;
     typedef typename pointer_traits<pointer>::difference_type difference_type;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -472,7 +451,7 @@
         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
                        "Attempted to dereference a non-dereferenceable list::const_iterator");
 #endif
-        return __ptr_->__as_node()->__value_;
+        return __ptr_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     pointer operator->() const
@@ -481,7 +460,7 @@
         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
                        "Attempted to dereference a non-dereferenceable list::iterator");
 #endif
-        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
+        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -539,9 +518,6 @@
     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<value_type, __void_pointer> __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;
@@ -553,12 +529,6 @@
     __compressed_pair<size_type, __node_allocator> __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
@@ -570,13 +540,10 @@
     const __node_allocator& __node_alloc() const _NOEXCEPT
         {return __size_alloc_.second();}
 
-    _LIBCPP_INLINE_VISIBILITY
-    static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
+    static void __unlink_nodes(__node_pointer __f, __node_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;
@@ -605,18 +572,22 @@
     iterator end() _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        return iterator(__end_as_link(), this);
+        return iterator(static_cast<__node_pointer>(
+                pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
 #else
-        return iterator(__end_as_link());
+        return iterator(static_cast<__node_pointer>(
+                      pointer_traits<__node_base_pointer>::pointer_to(__end_)));
 #endif
     }
     _LIBCPP_INLINE_VISIBILITY
     const_iterator end() const _NOEXCEPT
     {
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        return const_iterator(__end_as_link(), this);
+        return const_iterator(static_cast<__node_const_pointer>(
+        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
 #else
-        return const_iterator(__end_as_link());
+        return const_iterator(static_cast<__node_const_pointer>(
+        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
 #endif
     }
 
@@ -669,9 +640,9 @@
 
 // Unlink nodes [__f, __l]
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
-__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
+__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
     _NOEXCEPT
 {
     __f->__prev_->__next_ = __l->__next_;
@@ -679,7 +650,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __list_imp<_Tp, _Alloc>::__list_imp()
         _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
     : __size_alloc_(0)
@@ -687,7 +658,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
     : __size_alloc_(0, __node_allocator(__a))
 {
@@ -709,16 +680,17 @@
     if (!empty())
     {
         __node_allocator& __na = __node_alloc();
-        __link_pointer __f = __end_.__next_;
-        __link_pointer __l = __end_as_link();
+        __node_pointer __f = __end_.__next_;
+        __node_pointer __l = static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
         __unlink_nodes(__f, __l->__prev_);
         __sz() = 0;
         while (__f != __l)
         {
-            __node_pointer __np = __f->__as_node();
+            __node_pointer __n = __f;
             __f = __f->__next_;
-            __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
-            __node_alloc_traits::deallocate(__na, __np, 1);
+            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+            __node_alloc_traits::deallocate(__na, __n, 1);
         }
 #if _LIBCPP_DEBUG_LEVEL >= 2
         __c_node* __c = __get_db()->__find_c_and_lock(this);
@@ -757,13 +729,13 @@
     swap(__sz(), __c.__sz());
     swap(__end_, __c.__end_);
     if (__sz() == 0)
-        __end_.__next_ = __end_.__prev_ = __end_as_link();
+        __end_.__next_ = __end_.__prev_ = __end_.__self();
     else
-        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
+        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
     if (__c.__sz() == 0)
-        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
+        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
     else
-        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
+        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
 
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __libcpp_db* __db = __get_db();
@@ -776,7 +748,8 @@
     {
         --__p;
         const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == __c.__end_as_link())
+        if (__i->__ptr_ == static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
         {
             __cn2->__add(*__p);
             if (--__cn1->end_ != __p)
@@ -789,7 +762,8 @@
     {
         --__p;
         const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
-        if (__i->__ptr_ == __end_as_link())
+        if (__i->__ptr_ == static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__end_)))
         {
             __cn1->__add(*__p);
             if (--__cn2->end_ != __p)
@@ -813,7 +787,6 @@
     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;
@@ -861,19 +834,15 @@
 
     list(const list& __c);
     list(const list& __c, const allocator_type& __a);
-    _LIBCPP_INLINE_VISIBILITY
     list& operator=(const list& __c);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     list(initializer_list<value_type> __il);
     list(initializer_list<value_type> __il, const allocator_type& __a);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     list(list&& __c)
         _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
-    _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 &&
@@ -895,7 +864,6 @@
         {assign(__il.begin(), __il.end());}
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-    _LIBCPP_INLINE_VISIBILITY
     allocator_type get_allocator() const _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -942,25 +910,25 @@
     reference front()
     {
         _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
-        return base::__end_.__next_->__as_node()->__value_;
+        return base::__end_.__next_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     const_reference front() const
     {
         _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
-        return base::__end_.__next_->__as_node()->__value_;
+        return base::__end_.__next_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     reference back()
     {
         _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
-        return base::__end_.__prev_->__as_node()->__value_;
+        return base::__end_.__prev_->__value_;
     }
     _LIBCPP_INLINE_VISIBILITY
     const_reference back() const
     {
         _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
-        return base::__end_.__prev_->__as_node()->__value_;
+        return base::__end_.__prev_->__value_;
     }
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1032,11 +1000,9 @@
 
     void remove(const value_type& __x);
     template <class _Pred> void remove_if(_Pred __pred);
-    _LIBCPP_INLINE_VISIBILITY
     void unique();
     template <class _BinaryPred>
         void unique(_BinaryPred __binary_pred);
-    _LIBCPP_INLINE_VISIBILITY
     void merge(list& __c);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
@@ -1049,10 +1015,8 @@
     _LIBCPP_INLINE_VISIBILITY
         void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     void sort();
     template <class _Comp>
-        _LIBCPP_INLINE_VISIBILITY
         void sort(_Comp __comp);
 
     void reverse() _NOEXCEPT;
@@ -1069,12 +1033,9 @@
 #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);
+    static void __link_nodes  (__node_pointer __p, __node_pointer __f, __node_pointer __l);
+    void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
+    void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
     iterator __iterator(size_type __n);
     template <class _Comp>
         static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
@@ -1086,9 +1047,9 @@
 
 // Link in nodes [__f, __l] just prior to __p
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
-list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
+list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
 {
     __p->__prev_->__next_ = __f;
     __f->__prev_ = __p->__prev_;
@@ -1098,11 +1059,11 @@
 
 // Link in nodes [__f, __l] at the front of the list
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
-list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
+list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
 {
-    __f->__prev_ = base::__end_as_link();
+    __f->__prev_ = base::__end_.__self();
     __l->__next_ = base::__end_.__next_;
     __l->__next_->__prev_ = __l;
     base::__end_.__next_ = __f;
@@ -1110,11 +1071,11 @@
 
 // Link in nodes [__f, __l] at the front of the list
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
-list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
+list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
 {
-    __l->__next_ = base::__end_as_link();
+    __l->__next_ = base::__end_.__self();
     __f->__prev_ = base::__end_.__prev_;
     __f->__prev_->__next_ = __f;
     base::__end_.__prev_ = __l;
@@ -1122,7 +1083,7 @@
 
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename list<_Tp, _Alloc>::iterator
 list<_Tp, _Alloc>::__iterator(size_type __n)
 {
@@ -1258,7 +1219,7 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 list<_Tp, _Alloc>&
 list<_Tp, _Alloc>::operator=(const list& __c)
 {
@@ -1273,7 +1234,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 list<_Tp, _Alloc>::list(list&& __c)
     _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
     : base(allocator_type(_VSTD::move(__c.__node_alloc())))
@@ -1285,7 +1246,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
     : base(__a)
 {
@@ -1302,7 +1263,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 list<_Tp, _Alloc>&
 list<_Tp, _Alloc>::operator=(list&& __c)
         _NOEXCEPT_(
@@ -1370,7 +1331,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Alloc
 list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
 {
@@ -1391,12 +1352,12 @@
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    return iterator(__hold.release()->__as_link(), this);
+    return iterator(__hold.release(), this);
 #else
-    return iterator(__hold.release()->__as_link());
+    return iterator(__hold.release());
 #endif
 }
 
@@ -1422,9 +1383,9 @@
         __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
         ++__ds;
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        __r = iterator(__hold->__as_link(), this);
+        __r = iterator(__hold.get(), this);
 #else
-        __r = iterator(__hold->__as_link());
+        __r = iterator(__hold.get());
 #endif
         __hold.release();
         iterator __e = __r;
@@ -1436,7 +1397,7 @@
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-                __e.__ptr_->__next_ = __hold->__as_link();
+                __e.__ptr_->__next_ = __hold.get();
                 __hold->__prev_ = __e.__ptr_;
                 __hold.release();
             }
@@ -1447,8 +1408,8 @@
             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);
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
                 if (__prev == 0)
                     break;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1490,9 +1451,9 @@
         __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
         ++__ds;
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        __r = iterator(__hold.get()->__as_link(), this);
+        __r = iterator(__hold.get(), this);
 #else
-        __r = iterator(__hold.get()->__as_link());
+        __r = iterator(__hold.get());
 #endif
         __hold.release();
         iterator __e = __r;
@@ -1504,7 +1465,7 @@
             {
                 __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();
+                __e.__ptr_->__next_ = __hold.get();
                 __hold->__prev_ = __e.__ptr_;
                 __hold.release();
             }
@@ -1515,8 +1476,8 @@
             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);
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
                 if (__prev == 0)
                     break;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1542,8 +1503,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_pointer __nl = __hold->__as_link();
-    __link_nodes_at_front(__nl, __nl);
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1556,7 +1516,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
-    __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1571,7 +1531,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1584,7 +1544,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1600,7 +1560,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
+    __link_nodes_at_front(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1614,8 +1574,7 @@
     typedef __allocator_destructor<__node_allocator> _Dp;
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_pointer __nl = __hold->__as_link();
-    __link_nodes_at_back(__nl, __nl);
+    __link_nodes_at_back(__hold.get(), __hold.get());
     ++base::__sz();
     __hold.release();
 }
@@ -1635,14 +1594,12 @@
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
-    __link_pointer __nl = __hold.get()->__as_link();
-    __link_nodes(__p.__ptr_, __nl, __nl);
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
-    __hold.release();
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    return iterator(__nl, this);
+    return iterator(__hold.release(), this);
 #else
-    return iterator(__nl);
+    return iterator(__hold.release());
 #endif
 }
 
@@ -1662,14 +1619,12 @@
     unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
     __hold->__prev_ = 0;
     __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
-    __link_pointer __nl = __hold->__as_link();
-    __link_nodes(__p.__ptr_, __nl, __nl);
+    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
     ++base::__sz();
-    __hold.release();
 #if _LIBCPP_DEBUG_LEVEL >= 2
-    return iterator(__nl, this);
+    return iterator(__hold.release(), this);
 #else
-    return iterator(__nl);
+    return iterator(__hold.release());
 #endif
 }
 
@@ -1681,7 +1636,7 @@
 {
     _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
     __node_allocator& __na = base::__node_alloc();
-    __link_pointer __n = base::__end_.__next_;
+    __node_pointer __n = base::__end_.__next_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1699,9 +1654,8 @@
     }
     __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);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 }
 
 template <class _Tp, class _Alloc>
@@ -1710,7 +1664,7 @@
 {
     _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
     __node_allocator& __na = base::__node_alloc();
-    __link_pointer __n = base::__end_.__prev_;
+    __node_pointer __n = base::__end_.__prev_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1728,9 +1682,8 @@
     }
     __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);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 }
 
 template <class _Tp, class _Alloc>
@@ -1745,8 +1698,8 @@
     _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_;
+    __node_pointer __n = __p.__ptr_;
+    __node_pointer __r = __n->__next_;
     base::__unlink_nodes(__n, __n);
     --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1764,9 +1717,8 @@
     }
     __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);
+    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+    __node_alloc_traits::deallocate(__na, __n, 1);
 #if _LIBCPP_DEBUG_LEVEL >= 2
     return iterator(__r, this);
 #else
@@ -1789,7 +1741,7 @@
         base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
         while (__f != __l)
         {
-            __link_pointer __n = __f.__ptr_;
+            __node_pointer __n = __f.__ptr_;
             ++__f;
             --base::__sz();
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1807,9 +1759,8 @@
             }
             __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);
+            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
+            __node_alloc_traits::deallocate(__na, __n, 1);
         }
     }
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1836,9 +1787,9 @@
         __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
         ++__ds;
 #if _LIBCPP_DEBUG_LEVEL >= 2
-        iterator __r = iterator(__hold.release()->__as_link(), this);
+        iterator __r = iterator(__hold.release(), this);
 #else
-        iterator __r = iterator(__hold.release()->__as_link());
+        iterator __r = iterator(__hold.release());
 #endif
         iterator __e = __r;
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -1849,7 +1800,7 @@
             {
                 __hold.reset(__node_alloc_traits::allocate(__na, 1));
                 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
-                __e.__ptr_->__next_ = __hold.get()->__as_link();
+                __e.__ptr_->__next_ = __hold.get();
                 __hold->__prev_ = __e.__ptr_;
                 __hold.release();
             }
@@ -1860,8 +1811,8 @@
             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);
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
                 if (__prev == 0)
                     break;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1894,11 +1845,10 @@
         __hold->__prev_ = 0;
         __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);
+        iterator __r = iterator(__hold.release(), this);
 #else
-        iterator __r = iterator(__nl);
+        iterator __r = iterator(__hold.release());
 #endif
         iterator __e = __r;
 #ifndef _LIBCPP_NO_EXCEPTIONS
@@ -1909,7 +1859,7 @@
             {
                 __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();
+                __e.__ptr_->__next_ = __hold.get();
                 __hold->__prev_ = __e.__ptr_;
                 __hold.release();
             }
@@ -1920,8 +1870,8 @@
             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);
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
                 if (__prev == 0)
                     break;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1933,7 +1883,8 @@
             throw;
         }
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
+        __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
+                         pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
         base::__sz() += __ds;
     }
 }
@@ -1951,8 +1902,8 @@
 #endif
     if (!__c.empty())
     {
-        __link_pointer __f = __c.__end_.__next_;
-        __link_pointer __l = __c.__end_.__prev_;
+        __node_pointer __f = __c.__end_.__next_;
+        __node_pointer __l = __c.__end_.__prev_;
         base::__unlink_nodes(__f, __l);
         __link_nodes(__p.__ptr_, __f, __l);
         base::__sz() += __c.__sz();
@@ -1965,7 +1916,8 @@
         {
             --__p;
             iterator* __i = static_cast<iterator*>((*__p)->__i_);
-            if (__i->__ptr_ != __c.__end_as_link())
+            if (__i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
             {
                 __cn1->__add(*__p);
                 (*__p)->__c_ = __cn1;
@@ -1995,7 +1947,7 @@
 #endif
     if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
     {
-        __link_pointer __f = __i.__ptr_;
+        __node_pointer __f = __i.__ptr_;
         base::__unlink_nodes(__f, __f);
         __link_nodes(__p.__ptr_, __f, __f);
         --__c.__sz();
@@ -2049,9 +2001,9 @@
             __c.__sz() -= __s;
             base::__sz() += __s;
         }
-        __link_pointer __first = __f.__ptr_;
+        __node_pointer __first = __f.__ptr_;
         --__l;
-        __link_pointer __last = __l.__ptr_;
+        __node_pointer __last = __l.__ptr_;
         base::__unlink_nodes(__first, __last);
         __link_nodes(__p.__ptr_, __first, __last);
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -2062,7 +2014,7 @@
         {
             --__p;
             iterator* __j = static_cast<iterator*>((*__p)->__i_);
-            for (__link_pointer __k = __f.__ptr_;
+            for (__node_pointer __k = __f.__ptr_;
                                           __k != __l.__ptr_; __k = __k->__next_)
             {
                 if (__j->__ptr_ == __k)
@@ -2123,7 +2075,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 list<_Tp, _Alloc>::unique()
 {
@@ -2146,7 +2098,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 list<_Tp, _Alloc>::merge(list& __c)
 {
@@ -2174,8 +2126,8 @@
                     ;
                 base::__sz() += __ds;
                 __c.__sz() -= __ds;
-                __link_pointer __f = __f2.__ptr_;
-                __link_pointer __l = __m2.__ptr_->__prev_;
+                __node_pointer __f = __f2.__ptr_;
+                __node_pointer __l = __m2.__ptr_->__prev_;
                 __f2 = __m2;
                 base::__unlink_nodes(__f, __l);
                 __m2 = _VSTD::next(__f1);
@@ -2194,7 +2146,8 @@
         {
             --__p;
             iterator* __i = static_cast<iterator*>((*__p)->__i_);
-            if (__i->__ptr_ != __c.__end_as_link())
+            if (__i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
             {
                 __cn1->__add(*__p);
                 (*__p)->__c_ = __cn1;
@@ -2208,7 +2161,7 @@
 }
 
 template <class _Tp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 list<_Tp, _Alloc>::sort()
 {
@@ -2217,7 +2170,7 @@
 
 template <class _Tp, class _Alloc>
 template <class _Comp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 list<_Tp, _Alloc>::sort(_Comp __comp)
 {
@@ -2237,7 +2190,7 @@
     case 2:
         if (__comp(*--__e2, *__f1))
         {
-            __link_pointer __f = __e2.__ptr_;
+            __node_pointer __f = __e2.__ptr_;
             base::__unlink_nodes(__f, __f);
             __link_nodes(__f1.__ptr_, __f, __f);
             return __e2;
@@ -2253,8 +2206,8 @@
         iterator __m2 = _VSTD::next(__f2);
         for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
             ;
-        __link_pointer __f = __f2.__ptr_;
-        __link_pointer __l = __m2.__ptr_->__prev_;
+        __node_pointer __f = __f2.__ptr_;
+        __node_pointer __l = __m2.__ptr_->__prev_;
         __r = __f2;
         __e1 = __f2 = __m2;
         base::__unlink_nodes(__f, __l);
@@ -2271,8 +2224,8 @@
             iterator __m2 = _VSTD::next(__f2);
             for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
                 ;
-            __link_pointer __f = __f2.__ptr_;
-            __link_pointer __l = __m2.__ptr_->__prev_;
+            __node_pointer __f = __f2.__ptr_;
+            __node_pointer __l = __m2.__ptr_->__prev_;
             if (__e1 == __f2)
                 __e1 = __m2;
             __f2 = __m2;
@@ -2316,7 +2269,8 @@
 bool
 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
 {
-    return __i->__ptr_ != this->__end_as_link();
+    return __i->__ptr_ != static_cast<__node_pointer>(
+                       pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
 }
 
 template <class _Tp, class _Alloc>
diff --git a/include/locale b/include/locale
index b1cac28..e683ba3 100644
--- a/include/locale
+++ b/include/locale
@@ -213,12 +213,6 @@
 #pragma GCC system_header
 #endif
 
-#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-#include <__bsd_locale_defaults.h>
-#else
-#include <__bsd_locale_fallbacks.h>
-#endif
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
@@ -234,6 +228,189 @@
 
 typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
 typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr;
+#ifndef _LIBCPP_LOCALE__L_EXTENSIONS
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
+#endif
+
+// OSX has nice foo_l() functions that let you turn off use of the global
+// locale.  Linux, not so much.  The following functions avoid the locale when
+// that's possible and otherwise do the wrong thing.  FIXME.
+#if defined(__linux__) || defined(__EMSCRIPTEN__) || defined(_AIX) || \
+    defined(_NEWLIB_VERSION) || defined(__GLIBC__)
+
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
+inline _LIBCPP_INLINE_VISIBILITY
+__mb_cur_max_l(locale_t __l)
+{
+  return MB_CUR_MAX_L(__l);
+}
+#else  // _LIBCPP_LOCALE__L_EXTENSIONS
+inline _LIBCPP_ALWAYS_INLINE
+decltype(MB_CUR_MAX) __mb_cur_max_l(locale_t __l)
+{
+  __locale_raii __current(uselocale(__l), uselocale);
+  return MB_CUR_MAX;
+}
+#endif // _LIBCPP_LOCALE__L_EXTENSIONS
+
+inline _LIBCPP_ALWAYS_INLINE
+wint_t __btowc_l(int __c, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return btowc_l(__c, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return btowc(__c);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+int __wctob_l(wint_t __c, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wctob_l(__c, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wctob(__c);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
+                      size_t __len, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wcrtomb_l(__s, __wc, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wcrtomb(__s, __wc, __ps);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
+                      size_t __len, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
+                   mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbrtowc_l(__pwc, __s, __n, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbrtowc(__pwc, __s, __n, __ps);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+int __mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbtowc_l(__pwc, __pmb, __max, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbtowc(__pwc, __pmb, __max);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbrlen_l(__s, __n, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbrlen(__s, __n, __ps);
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+lconv *__localeconv_l(locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return localeconv_l(__l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return localeconv();
+#endif
+}
+
+inline _LIBCPP_ALWAYS_INLINE
+size_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
+                     mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbsrtowcs_l(__dest, __src, __len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbsrtowcs(__dest, __src, __len, __ps);
+#endif
+}
+
+inline
+int __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vsnprintf_l(__s, __n, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vsnprintf(__s, __n, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+inline
+int __asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vasprintf_l(__s, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vasprintf(__s, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+inline
+int __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vsscanf_l(__s, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vsscanf(__s, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+#endif  // __linux__
 
 // __scan_keyword
 // Scans [__b, __e) until a match is found in the basic_strings range
@@ -1011,7 +1188,11 @@
     }
     // Stage 3
     __buf.resize(__a_end - __a);
-    if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    if (sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
+#else
+    if (__sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
+#endif
         __err = ios_base::failbit;
     // EOF checked
     if (__b == __e)
@@ -1375,9 +1556,13 @@
     this->__format_int(__fmt+1, __len, true, __iob.flags());
     const unsigned __nbuf = (numeric_limits<long>::digits / 3)
                           + ((numeric_limits<long>::digits % 3) != 0)
-                          + 2;
+                          + 1;
     char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+    int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1403,7 +1588,11 @@
                           + ((numeric_limits<long long>::digits % 3) != 0)
                           + 2;
     char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+    int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1429,7 +1618,11 @@
                           + ((numeric_limits<unsigned long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+    int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1455,7 +1648,11 @@
                           + ((numeric_limits<unsigned long long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
-    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+    int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1482,17 +1679,34 @@
     char* __nb = __nar;
     int __nc;
     if (__specify_precision)
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+        __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
                                    (int)__iob.precision(), __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
+                                   (int)__iob.precision(), __v);
+#endif
     else
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+        __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     unique_ptr<char, void(*)(void*)> __nbh(0, free);
     if (__nc > static_cast<int>(__nbuf-1))
     {
         if (__specify_precision)
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+            __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#else
+            __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#endif
         else
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+            __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+            __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#endif
         if (__nb == 0)
             __throw_bad_alloc();
         __nbh.reset(__nb);
@@ -1533,17 +1747,34 @@
     char* __nb = __nar;
     int __nc;
     if (__specify_precision)
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+        __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
                                    (int)__iob.precision(), __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
+                                   (int)__iob.precision(), __v);
+#endif
     else
-        __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+        __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     unique_ptr<char, void(*)(void*)> __nbh(0, free);
     if (__nc > static_cast<int>(__nbuf-1))
     {
         if (__specify_precision)
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+            __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#else
+            __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
+#endif
         else
-            __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+            __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+            __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
         if (__nb == 0)
             __throw_bad_alloc();
         __nbh.reset(__nb);
@@ -1579,7 +1810,11 @@
     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);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+    int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#else
+    int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar
@@ -1653,9 +1888,6 @@
     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 <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
@@ -3291,7 +3523,11 @@
     // secure memory for digit storage
     if (__n > __bs-1)
     {
-        __n = static_cast<size_t>(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+        __n = static_cast<size_t>(asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
+#else
+        __n = __asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
+#endif
         if (__bb == 0)
             __throw_bad_alloc();
         __hn.reset(__bb);
@@ -3537,14 +3773,11 @@
     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_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_ALWAYS_INLINE
     wstring_convert(wstring_convert&& __wc);
 #endif
     ~wstring_convert();
@@ -3578,7 +3811,7 @@
 };
 
 template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
-inline
+inline _LIBCPP_ALWAYS_INLINE
 wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
     wstring_convert(_Codecvt* __pcvt)
         : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0)
@@ -3586,7 +3819,7 @@
 }
 
 template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
-inline
+inline _LIBCPP_ALWAYS_INLINE
 wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
     wstring_convert(_Codecvt* __pcvt, state_type __state)
         : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0)
@@ -3605,7 +3838,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
-inline
+inline _LIBCPP_ALWAYS_INLINE
 wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
     wstring_convert(wstring_convert&& __wc)
         : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)),
@@ -4080,9 +4313,18 @@
     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)
+    // __width > 0 || __off == 0
+    switch (__way)
+    {
+    case ios_base::beg:
+        break;
+    case ios_base::cur:
+        break;
+    case ios_base::end:
+        break;
+    default:
         return pos_type(off_type(-1));
+    }
     pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
     __r.state(__st_);
     return __r;
diff --git a/include/map b/include/map
index 8dc84e7..eb6b8ed 100644
--- a/include/map
+++ b/include/map
@@ -126,11 +126,9 @@
     template <class... Args>
         iterator emplace_hint(const_iterator position, Args&&... args);
     pair<iterator, bool> insert(const value_type& v);
-    pair<iterator, bool> insert(      value_type&& v);                                // C++17
     template <class P>
         pair<iterator, bool> insert(P&& p);
     iterator insert(const_iterator position, const value_type& v);
-    iterator insert(const_iterator position,       value_type&& v);                   // C++17
     template <class P>
         iterator insert(const_iterator position, P&& p);
     template <class InputIterator>
@@ -162,7 +160,7 @@
 
     void swap(map& m)
         noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
-            is_nothrow_swappable<key_compare>::value); // C++17
+            __is_nothrow_swappable<key_compare>::value); // C++17
 
     // observers:
     allocator_type get_allocator() const noexcept;
@@ -338,11 +336,9 @@
     template <class... Args>
         iterator emplace_hint(const_iterator position, Args&&... args);
     iterator insert(const value_type& v);
-    iterator insert(      value_type&& v);                                            // C++17
     template <class P>
         iterator insert(P&& p);
     iterator insert(const_iterator position, const value_type& v);
-    iterator insert(const_iterator position,       value_type&& v);                   // C++17
     template <class P>
         iterator insert(const_iterator position, P&& p);
     template <class InputIterator>
@@ -357,7 +353,7 @@
 
     void swap(multimap& m)
         noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
-            is_nothrow_swappable<key_compare>::value); // C++17
+            __is_nothrow_swappable<key_compare>::value); // C++17
 
     // observers:
     allocator_type get_allocator() const noexcept;
@@ -564,11 +560,13 @@
 {
     typedef _Allocator                          allocator_type;
     typedef allocator_traits<allocator_type>    __alloc_traits;
-
+    typedef typename __alloc_traits::value_type::value_type value_type;
 public:
     typedef typename __alloc_traits::pointer    pointer;
-
 private:
+    typedef typename value_type::value_type::first_type     first_type;
+    typedef typename value_type::value_type::second_type    second_type;
+
     allocator_type& __na_;
 
     __map_node_destructor& operator=(const __map_node_destructor&);
@@ -613,7 +611,7 @@
     class multimap;
 template <class _TreeIterator> class __map_const_iterator;
 
-#ifndef _LIBCPP_CXX03_LANG
+#if __cplusplus >= 201103L
 
 template <class _Key, class _Tp>
 union __value_type
@@ -626,29 +624,33 @@
     value_type __cc;
     __nc_value_type __nc;
 
+    template <class ..._Args>
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(_Args&& ...__args)
+        : __cc(std::forward<_Args>(__args)...) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(const __value_type& __v)
+        : __cc(__v.__cc) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(__value_type& __v)
+        : __cc(__v.__cc) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(__value_type&& __v)
+        : __nc(std::move(__v.__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;}
+        {__nc = std::move(__v.__nc); return *this;}
 
-    template <class _ValueTp,
-              class = typename enable_if<
-                    __is_same_uncvref<_ValueTp, value_type>::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;
+    ~__value_type() {__cc.~value_type();}
 };
 
 #else
@@ -662,11 +664,18 @@
 
     value_type __cc;
 
-private:
-   __value_type();
-   __value_type(__value_type const&);
-   __value_type& operator=(__value_type const&);
-   ~__value_type();
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type() {}
+
+    template <class _A0>
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(const _A0& __a0)
+        : __cc(__a0) {}
+
+    template <class _A0, class _A1>
+    _LIBCPP_INLINE_VISIBILITY
+    __value_type(const _A0& __a0, const _A1& __a1)
+        : __cc(__a0, __a1) {}
 };
 
 #endif
@@ -684,17 +693,24 @@
 template <class _TreeIterator>
 class _LIBCPP_TYPE_VIS_ONLY __map_iterator
 {
-    typedef typename _TreeIterator::_NodeTypes                   _NodeTypes;
-    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
-
     _TreeIterator __i_;
 
+    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
+    typedef typename _TreeIterator::value_type __value_type;
+    typedef typename __extract_key_value_types<__value_type>::__key_type    __key_type;
+    typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
 public:
     typedef bidirectional_iterator_tag                           iterator_category;
-    typedef typename _NodeTypes::__map_value_type                value_type;
+    typedef pair<__key_type, __mapped_type>                      value_type;
     typedef typename _TreeIterator::difference_type              difference_type;
     typedef value_type&                                          reference;
-    typedef typename _NodeTypes::__map_value_type_pointer        pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY
     __map_iterator() _NOEXCEPT {}
@@ -743,17 +759,24 @@
 template <class _TreeIterator>
 class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator
 {
-    typedef typename _TreeIterator::_NodeTypes                   _NodeTypes;
-    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
-
     _TreeIterator __i_;
 
+    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
+    typedef typename _TreeIterator::value_type __value_type;
+    typedef typename __extract_key_value_types<__value_type>::__key_type    __key_type;
+    typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type;
 public:
     typedef bidirectional_iterator_tag                           iterator_category;
-    typedef typename _NodeTypes::__map_value_type                value_type;
+    typedef pair<__key_type, __mapped_type>                      value_type;
     typedef typename _TreeIterator::difference_type              difference_type;
     typedef const value_type&                                    reference;
-    typedef typename _NodeTypes::__const_map_value_type_pointer  pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY
     __map_const_iterator() _NOEXCEPT {}
@@ -817,9 +840,6 @@
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
-                  "Allocator::value_type must be same type as value_type");
-
     class _LIBCPP_TYPE_VIS_ONLY value_compare
         : public binary_function<value_type, value_type, bool>
     {
@@ -1026,7 +1046,7 @@
     size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
 
     mapped_type& operator[](const key_type& __k);
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     mapped_type& operator[](key_type&& __k);
 #endif
 
@@ -1040,18 +1060,18 @@
     _LIBCPP_INLINE_VISIBILITY
     value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
 
-#ifndef _LIBCPP_CXX03_LANG
-    template <class ..._Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> emplace(_Args&& ...__args) {
-        return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
-    }
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class ..._Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
-        return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
-    }
+        pair<iterator, bool>
+        emplace(_Args&& ...__args);
+
+    template <class ..._Args>
+        iterator
+        emplace_hint(const_iterator __p, _Args&& ...__args);
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
     template <class _Pp,
               class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
@@ -1065,7 +1085,7 @@
         iterator insert(const_iterator __pos, _Pp&& __p)
             {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
 
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, bool>
@@ -1076,16 +1096,6 @@
         insert(const_iterator __p, const value_type& __v)
             {return __tree_.__insert_unique(__p.__i_, __v);}
 
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool>
-    insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator insert(const_iterator __p,  value_type&& __v)
-    {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
-#endif
-
     template <class _InputIterator>
         _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __f, _InputIterator __l)
@@ -1103,45 +1113,62 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 #if _LIBCPP_STD_VER > 14
-
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> 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)...));
+        iterator __p = lower_bound(__k);
+        if ( __p != end() && !key_comp()(__k, __p->first))
+            return _VSTD::make_pair(__p, false);
+        else
+            return _VSTD::make_pair(
+                      emplace_hint(__p, 
+                        _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), 
+                        _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
+                      true);
     }
 
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> 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)...));
+        iterator __p = lower_bound(__k);
+        if ( __p != end() && !key_comp()(__k, __p->first))
+            return _VSTD::make_pair(__p, false);
+        else
+            return _VSTD::make_pair(
+                      emplace_hint(__p, 
+                        _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), 
+                        _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
+                      true);
     }
 
     template <class... _Args>
         _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)...));
+        iterator __p = lower_bound(__k);
+        if ( __p != end() && !key_comp()(__k, __p->first))
+            return __p;
+        else
+            return emplace_hint(__p, 
+                      _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), 
+                      _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
     }
 
     template <class... _Args>
         _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)...));
+        iterator __p = lower_bound(__k);
+        if ( __p != end() && !key_comp()(__k, __p->first))
+            return __p;
+        else
+            return emplace_hint(__p, 
+                      _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), 
+                      _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
     }
 
     template <class _Vp>
@@ -1156,7 +1183,7 @@
         }
         return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
     }
-
+        
     template <class _Vp>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
@@ -1195,7 +1222,8 @@
         }
         return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
      }
-
+#endif
+#endif
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1296,36 +1324,38 @@
     typedef typename __base::__node                    __node;
     typedef typename __base::__node_allocator          __node_allocator;
     typedef typename __base::__node_pointer            __node_pointer;
+    typedef typename __base::__node_const_pointer      __node_const_pointer;
     typedef typename __base::__node_base_pointer       __node_base_pointer;
-
+    typedef typename __base::__node_base_const_pointer __node_base_const_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);
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder __construct_node(_A0&& __a0);
+    __node_holder __construct_node_with_key(key_type&& __k);
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif
+    __node_holder __construct_node_with_key(const key_type& __k);
 
-    __node_base_pointer const&
-    __find_equal_key(__node_base_pointer& __parent, const key_type& __k) const;
-
-    _LIBCPP_INLINE_VISIBILITY
     __node_base_pointer&
-    __find_equal_key(__node_base_pointer& __parent, const key_type& __k) {
-        map const* __const_this = this;
-        return const_cast<__node_base_pointer&>(
-            __const_this->__find_equal_key(__parent, __k));
-    }
+        __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
+    __node_base_const_pointer
+        __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
 };
 
-
-// Find __k
-// Set __parent to parent of null leaf and
-//    return reference to null leaf iv __k does not exist.
+// Find place to insert if __k doesn't exist
+// Set __parent to parent of null leaf
+// Return reference to null leaf
 // If __k exists, set parent to node of __k and return reference to node of __k
 template <class _Key, class _Tp, class _Compare, class _Allocator>
-typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer const&
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
 map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
-                                                       const key_type& __k) const
+                                                       const key_type& __k)
 {
     __node_pointer __nd = __tree_.__root();
     if (__nd != nullptr)
@@ -1363,7 +1393,52 @@
     return __parent->__left_;
 }
 
-#ifndef _LIBCPP_CXX03_LANG
+// Find __k
+// Set __parent to parent of null leaf and
+//    return reference to null leaf iv __k does not exist.
+// If __k exists, set parent to node of __k and return reference to node of __k
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
+map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
+                                                       const key_type& __k) const
+{
+    __node_const_pointer __nd = __tree_.__root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+                }
+            }
+            else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return const_cast<const __node_base_const_pointer&>(__parent->__right_);
+                }
+            }
+            else
+            {
+                __parent = static_cast<__node_base_pointer>(__nd);
+                return __parent;
+            }
+        }
+    }
+    __parent = static_cast<__node_base_pointer>(__tree_.__end_node());
+    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
@@ -1374,14 +1449,69 @@
         const_iterator __e = cend();
         while (!__m.empty())
             __tree_.__insert_unique(__e.__i_,
-                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__nc));
+                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
     }
 }
 
-#endif  // !_LIBCPP_CXX03_LANG
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
 
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
 
-#ifdef _LIBCPP_CXX03_LANG
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(key_type&& __k)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class _A1, class ..._Args>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
@@ -1393,7 +1523,7 @@
     __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
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
@@ -1412,29 +1542,25 @@
     return __r->__value_.__cc.second;
 }
 
-#else
-
-template <class _Key, class _Tp, class _Compare, class _Allocator>
-_Tp&
-map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
-{
-    return __tree_.__emplace_unique_key_args(__k,
-        _VSTD::piecewise_construct,
-        _VSTD::forward_as_tuple(__k),
-        _VSTD::forward_as_tuple()).first->__cc.second;
-}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 _Tp&
 map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
 {
-    return __tree_.__emplace_unique_key_args(__k,
-        _VSTD::piecewise_construct,
-        _VSTD::forward_as_tuple(_VSTD::move(__k)),
-        _VSTD::forward_as_tuple()).first->__cc.second;
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal_key(__parent, __k);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
+        __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+        __r = __h.release();
+    }
+    return __r->__value_.__cc.second;
 }
 
-#endif  // !_LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 _Tp&
@@ -1453,15 +1579,43 @@
 const _Tp&
 map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
 {
-    __node_base_pointer __parent;
-    __node_base_pointer __child = __find_equal_key(__parent, __k);
+    __node_base_const_pointer __parent;
+    __node_base_const_pointer __child = __find_equal_key(__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;
+    return static_cast<__node_const_pointer>(__child)->__value_.__cc.second;
 }
 
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class ..._Args>
+pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
+map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class ..._Args>
+typename map<_Key, _Tp, _Compare, _Allocator>::iterator
+map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
+                                                   _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
+    if (__r.__i_.__ptr_ == __h.get())
+        __h.release();
+    return __r;
+}
+
+#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -1542,9 +1696,6 @@
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
-                  "Allocator::value_type must be same type as value_type");
-
     class _LIBCPP_TYPE_VIS_ONLY value_compare
         : public binary_function<value_type, value_type, bool>
     {
@@ -1759,19 +1910,18 @@
     value_compare  value_comp() const
         {return value_compare(__tree_.value_comp().key_comp());}
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
     template <class ..._Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace(_Args&& ...__args) {
-        return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
-    }
+        iterator
+        emplace(_Args&& ...__args);
 
     template <class ..._Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
-        return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
-    }
+        iterator
+        emplace_hint(const_iterator __p, _Args&& ...__args);
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
     template <class _Pp,
               class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
@@ -1785,15 +1935,7 @@
         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));}
-
-#endif  // _LIBCPP_CXX03_LANG
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
@@ -1915,12 +2057,24 @@
     typedef typename __base::__node                    __node;
     typedef typename __base::__node_allocator          __node_allocator;
     typedef typename __base::__node_pointer            __node_pointer;
-
+    typedef typename __base::__node_const_pointer      __node_const_pointer;
     typedef __map_node_destructor<__node_allocator> _Dp;
     typedef unique_ptr<__node, _Dp> __node_holder;
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
 
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
     : __tree_(_VSTD::move(__m.__tree_), __a)
@@ -1930,10 +2084,82 @@
         const_iterator __e = cend();
         while (!__m.empty())
             __tree_.__insert_multi(__e.__i_,
-                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__nc));
+                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
     }
 }
-#endif
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class _A1, class ..._Args>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class ..._Args>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
+multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class ..._Args>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
+multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
+                                                        _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 
 template <class _Key, class _Tp, class _Compare, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
diff --git a/include/math.h b/include/math.h
deleted file mode 100644
index 2020554..0000000
--- a/include/math.h
+++ /dev/null
@@ -1,1419 +0,0 @@
-// -*- C++ -*-
-//===---------------------------- math.h ----------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_MATH_H
-#define _LIBCPP_MATH_H
-
-/*
-    math.h synopsis
-
-Macros:
-
-    HUGE_VAL
-    HUGE_VALF               // C99
-    HUGE_VALL               // C99
-    INFINITY                // C99
-    NAN                     // C99
-    FP_INFINITE             // C99
-    FP_NAN                  // C99
-    FP_NORMAL               // C99
-    FP_SUBNORMAL            // C99
-    FP_ZERO                 // C99
-    FP_FAST_FMA             // C99
-    FP_FAST_FMAF            // C99
-    FP_FAST_FMAL            // C99
-    FP_ILOGB0               // C99
-    FP_ILOGBNAN             // C99
-    MATH_ERRNO              // C99
-    MATH_ERREXCEPT          // C99
-    math_errhandling        // C99
-
-Types:
-
-    float_t                 // C99
-    double_t                // C99
-
-// C90
-
-floating_point abs(floating_point x);
-
-floating_point acos (arithmetic x);
-float          acosf(float x);
-long double    acosl(long double x);
-
-floating_point asin (arithmetic x);
-float          asinf(float x);
-long double    asinl(long double x);
-
-floating_point atan (arithmetic x);
-float          atanf(float x);
-long double    atanl(long double x);
-
-floating_point atan2 (arithmetic y, arithmetic x);
-float          atan2f(float y, float x);
-long double    atan2l(long double y, long double x);
-
-floating_point ceil (arithmetic x);
-float          ceilf(float x);
-long double    ceill(long double x);
-
-floating_point cos (arithmetic x);
-float          cosf(float x);
-long double    cosl(long double x);
-
-floating_point cosh (arithmetic x);
-float          coshf(float x);
-long double    coshl(long double x);
-
-floating_point exp (arithmetic x);
-float          expf(float x);
-long double    expl(long double x);
-
-floating_point fabs (arithmetic x);
-float          fabsf(float x);
-long double    fabsl(long double x);
-
-floating_point floor (arithmetic x);
-float          floorf(float x);
-long double    floorl(long double x);
-
-floating_point fmod (arithmetic x, arithmetic y);
-float          fmodf(float x, float y);
-long double    fmodl(long double x, long double y);
-
-floating_point frexp (arithmetic value, int* exp);
-float          frexpf(float value, int* exp);
-long double    frexpl(long double value, int* exp);
-
-floating_point ldexp (arithmetic value, int exp);
-float          ldexpf(float value, int exp);
-long double    ldexpl(long double value, int exp);
-
-floating_point log (arithmetic x);
-float          logf(float x);
-long double    logl(long double x);
-
-floating_point log10 (arithmetic x);
-float          log10f(float x);
-long double    log10l(long double x);
-
-floating_point modf (floating_point value, floating_point* iptr);
-float          modff(float value, float* iptr);
-long double    modfl(long double value, long double* iptr);
-
-floating_point pow (arithmetic x, arithmetic y);
-float          powf(float x, float y);
-long double    powl(long double x, long double y);
-
-floating_point sin (arithmetic x);
-float          sinf(float x);
-long double    sinl(long double x);
-
-floating_point sinh (arithmetic x);
-float          sinhf(float x);
-long double    sinhl(long double x);
-
-floating_point sqrt (arithmetic x);
-float          sqrtf(float x);
-long double    sqrtl(long double x);
-
-floating_point tan (arithmetic x);
-float          tanf(float x);
-long double    tanl(long double x);
-
-floating_point tanh (arithmetic x);
-float          tanhf(float x);
-long double    tanhl(long double x);
-
-//  C99
-
-bool signbit(arithmetic x);
-
-int fpclassify(arithmetic x);
-
-bool isfinite(arithmetic x);
-bool isinf(arithmetic x);
-bool isnan(arithmetic x);
-bool isnormal(arithmetic x);
-
-bool isgreater(arithmetic x, arithmetic y);
-bool isgreaterequal(arithmetic x, arithmetic y);
-bool isless(arithmetic x, arithmetic y);
-bool islessequal(arithmetic x, arithmetic y);
-bool islessgreater(arithmetic x, arithmetic y);
-bool isunordered(arithmetic x, arithmetic y);
-
-floating_point acosh (arithmetic x);
-float          acoshf(float x);
-long double    acoshl(long double x);
-
-floating_point asinh (arithmetic x);
-float          asinhf(float x);
-long double    asinhl(long double x);
-
-floating_point atanh (arithmetic x);
-float          atanhf(float x);
-long double    atanhl(long double x);
-
-floating_point cbrt (arithmetic x);
-float          cbrtf(float x);
-long double    cbrtl(long double x);
-
-floating_point copysign (arithmetic x, arithmetic y);
-float          copysignf(float x, float y);
-long double    copysignl(long double x, long double y);
-
-floating_point erf (arithmetic x);
-float          erff(float x);
-long double    erfl(long double x);
-
-floating_point erfc (arithmetic x);
-float          erfcf(float x);
-long double    erfcl(long double x);
-
-floating_point exp2 (arithmetic x);
-float          exp2f(float x);
-long double    exp2l(long double x);
-
-floating_point expm1 (arithmetic x);
-float          expm1f(float x);
-long double    expm1l(long double x);
-
-floating_point fdim (arithmetic x, arithmetic y);
-float          fdimf(float x, float y);
-long double    fdiml(long double x, long double y);
-
-floating_point fma (arithmetic x, arithmetic y, arithmetic z);
-float          fmaf(float x, float y, float z);
-long double    fmal(long double x, long double y, long double z);
-
-floating_point fmax (arithmetic x, arithmetic y);
-float          fmaxf(float x, float y);
-long double    fmaxl(long double x, long double y);
-
-floating_point fmin (arithmetic x, arithmetic y);
-float          fminf(float x, float y);
-long double    fminl(long double x, long double y);
-
-floating_point hypot (arithmetic x, arithmetic y);
-float          hypotf(float x, float y);
-long double    hypotl(long double x, long double y);
-
-int ilogb (arithmetic x);
-int ilogbf(float x);
-int ilogbl(long double x);
-
-floating_point lgamma (arithmetic x);
-float          lgammaf(float x);
-long double    lgammal(long double x);
-
-long long llrint (arithmetic x);
-long long llrintf(float x);
-long long llrintl(long double x);
-
-long long llround (arithmetic x);
-long long llroundf(float x);
-long long llroundl(long double x);
-
-floating_point log1p (arithmetic x);
-float          log1pf(float x);
-long double    log1pl(long double x);
-
-floating_point log2 (arithmetic x);
-float          log2f(float x);
-long double    log2l(long double x);
-
-floating_point logb (arithmetic x);
-float          logbf(float x);
-long double    logbl(long double x);
-
-long lrint (arithmetic x);
-long lrintf(float x);
-long lrintl(long double x);
-
-long lround (arithmetic x);
-long lroundf(float x);
-long lroundl(long double x);
-
-double      nan (const char* str);
-float       nanf(const char* str);
-long double nanl(const char* str);
-
-floating_point nearbyint (arithmetic x);
-float          nearbyintf(float x);
-long double    nearbyintl(long double x);
-
-floating_point nextafter (arithmetic x, arithmetic y);
-float          nextafterf(float x, float y);
-long double    nextafterl(long double x, long double y);
-
-floating_point nexttoward (arithmetic x, long double y);
-float          nexttowardf(float x, long double y);
-long double    nexttowardl(long double x, long double y);
-
-floating_point remainder (arithmetic x, arithmetic y);
-float          remainderf(float x, float y);
-long double    remainderl(long double x, long double y);
-
-floating_point remquo (arithmetic x, arithmetic y, int* pquo);
-float          remquof(float x, float y, int* pquo);
-long double    remquol(long double x, long double y, int* pquo);
-
-floating_point rint (arithmetic x);
-float          rintf(float x);
-long double    rintl(long double x);
-
-floating_point round (arithmetic x);
-float          roundf(float x);
-long double    roundl(long double x);
-
-floating_point scalbln (arithmetic x, long ex);
-float          scalblnf(float x, long ex);
-long double    scalblnl(long double x, long ex);
-
-floating_point scalbn (arithmetic x, int ex);
-float          scalbnf(float x, int ex);
-long double    scalbnl(long double x, int ex);
-
-floating_point tgamma (arithmetic x);
-float          tgammaf(float x);
-long double    tgammal(long double x);
-
-floating_point trunc (arithmetic x);
-float          truncf(float x);
-long double    truncl(long double x);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <math.h>
-
-#ifdef __cplusplus
-
-// We support including .h headers inside 'extern "C"' contexts, so switch
-// back to C++ linkage before including these C++ headers.
-extern "C++" {
-
-#include <type_traits>
-
-#ifdef _LIBCPP_MSVCRT
-#include "support/win32/math_win32.h"
-#endif
-
-// signbit
-
-#ifdef signbit
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT
-{
-    return signbit(__lcpp_x);
-}
-
-#undef signbit
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-signbit(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // signbit
-
-// fpclassify
-
-#ifdef fpclassify
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-int
-__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT
-{
-    return fpclassify(__lcpp_x);
-}
-
-#undef fpclassify
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type
-fpclassify(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // fpclassify
-
-// isfinite
-
-#ifdef isfinite
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
-{
-    return isfinite(__lcpp_x);
-}
-
-#undef isfinite
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isfinite(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // isfinite
-
-// isinf
-
-#ifdef isinf
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
-{
-    return isinf(__lcpp_x);
-}
-
-#undef isinf
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isinf(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // isinf
-
-// isnan
-
-#ifdef isnan
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT
-{
-    return isnan(__lcpp_x);
-}
-
-#undef isnan
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isnan(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // isnan
-
-// isnormal
-
-#ifdef isnormal
-
-template <class _A1>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT
-{
-    return isnormal(__lcpp_x);
-}
-
-#undef isnormal
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
-isnormal(_A1 __lcpp_x) _NOEXCEPT
-{
-    return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x);
-}
-
-#endif  // isnormal
-
-// isgreater
-
-#ifdef isgreater
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return isgreater(__lcpp_x, __lcpp_y);
-}
-
-#undef isgreater
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // isgreater
-
-// isgreaterequal
-
-#ifdef isgreaterequal
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return isgreaterequal(__lcpp_x, __lcpp_y);
-}
-
-#undef isgreaterequal
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // isgreaterequal
-
-// isless
-
-#ifdef isless
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return isless(__lcpp_x, __lcpp_y);
-}
-
-#undef isless
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // isless
-
-// islessequal
-
-#ifdef islessequal
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return islessequal(__lcpp_x, __lcpp_y);
-}
-
-#undef islessequal
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // islessequal
-
-// islessgreater
-
-#ifdef islessgreater
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return islessgreater(__lcpp_x, __lcpp_y);
-}
-
-#undef islessgreater
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // islessgreater
-
-// isunordered
-
-#ifdef isunordered
-
-template <class _A1, class _A2>
-_LIBCPP_ALWAYS_INLINE
-bool
-__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    return isunordered(__lcpp_x, __lcpp_y);
-}
-
-#undef isunordered
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    bool
->::type
-isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type type;
-    return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y);
-}
-
-#endif  // isunordered
-
-#ifndef __sun__
-
-// abs
-
-#if !defined(_AIX)
-inline _LIBCPP_INLINE_VISIBILITY
-float
-abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-double
-abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-long double
-abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
-#endif // !defined(_AIX)
-
-// acos
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       acos(float __lcpp_x) _NOEXCEPT       {return acosf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);}
-
-// asin
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       asin(float __lcpp_x) _NOEXCEPT       {return asinf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);}
-
-// atan
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       atan(float __lcpp_x) _NOEXCEPT       {return atanf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);}
-
-// atan2
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT             {return atan2f(__lcpp_y, __lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);}
-#endif
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x);
-}
-
-// ceil
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __lcpp_x) _NOEXCEPT       {return ceilf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);}
-
-// cos
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       cos(float __lcpp_x) _NOEXCEPT       {return cosf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return cosl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-cos(_A1 __lcpp_x) _NOEXCEPT {return cos((double)__lcpp_x);}
-
-// cosh
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __lcpp_x) _NOEXCEPT       {return coshf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return coshl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-cosh(_A1 __lcpp_x) _NOEXCEPT {return cosh((double)__lcpp_x);}
-
-// exp
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       exp(float __lcpp_x) _NOEXCEPT       {return expf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return expl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-exp(_A1 __lcpp_x) _NOEXCEPT {return exp((double)__lcpp_x);}
-
-// fabs
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __lcpp_x) _NOEXCEPT       {return fabsf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-fabs(_A1 __lcpp_x) _NOEXCEPT {return fabs((double)__lcpp_x);}
-
-// floor
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       floor(float __lcpp_x) _NOEXCEPT       {return floorf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return floorl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-floor(_A1 __lcpp_x) _NOEXCEPT {return floor((double)__lcpp_x);}
-
-// fmod
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmodf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmodl(__lcpp_x, __lcpp_y);}
-#endif
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// frexp
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT       {return frexpf(__lcpp_x, __lcpp_e);}
-inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpl(__lcpp_x, __lcpp_e);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexp((double)__lcpp_x, __lcpp_e);}
-
-// ldexp
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT       {return ldexpf(__lcpp_x, __lcpp_e);}
-inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpl(__lcpp_x, __lcpp_e);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexp((double)__lcpp_x, __lcpp_e);}
-
-// log
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       log(float __lcpp_x) _NOEXCEPT       {return logf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return logl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x);}
-
-// log10
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       log10(float __lcpp_x) _NOEXCEPT       {return log10f(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return log10l(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-log10(_A1 __lcpp_x) _NOEXCEPT {return log10((double)__lcpp_x);}
-
-// modf
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT             {return modff(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return modfl(__lcpp_x, __lcpp_y);}
-#endif
-
-// pow
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return powf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return powl(__lcpp_x, __lcpp_y);}
-#endif
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return pow((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// sin
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sin(float __lcpp_x) _NOEXCEPT       {return sinf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return sinl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-sin(_A1 __lcpp_x) _NOEXCEPT {return sin((double)__lcpp_x);}
-
-// sinh
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __lcpp_x) _NOEXCEPT       {return sinhf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return sinhl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-sinh(_A1 __lcpp_x) _NOEXCEPT {return sinh((double)__lcpp_x);}
-
-// sqrt
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __lcpp_x) _NOEXCEPT       {return sqrtf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return sqrtl(__lcpp_x);}
-#endif
-
-#endif // __sun__
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-sqrt(_A1 __lcpp_x) _NOEXCEPT {return sqrt((double)__lcpp_x);}
-#ifndef __sun__
-
-// tan
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       tan(float __lcpp_x) _NOEXCEPT       {return tanf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return tanl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-tan(_A1 __lcpp_x) _NOEXCEPT {return tan((double)__lcpp_x);}
-
-// tanh
-
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX))
-inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __lcpp_x) _NOEXCEPT       {return tanhf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return tanhl(__lcpp_x);}
-#endif
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-tanh(_A1 __lcpp_x) _NOEXCEPT {return tanh((double)__lcpp_x);}
-
-// acosh
-
-#ifndef _LIBCPP_MSVCRT
-inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __lcpp_x) _NOEXCEPT       {return acoshf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-acosh(_A1 __lcpp_x) _NOEXCEPT {return acosh((double)__lcpp_x);}
-#endif
-
-// asinh
-
-#ifndef _LIBCPP_MSVCRT
-inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __lcpp_x) _NOEXCEPT       {return asinhf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-asinh(_A1 __lcpp_x) _NOEXCEPT {return asinh((double)__lcpp_x);}
-#endif
-
-// atanh
-
-#ifndef _LIBCPP_MSVCRT
-inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __lcpp_x) _NOEXCEPT       {return atanhf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-atanh(_A1 __lcpp_x) _NOEXCEPT {return atanh((double)__lcpp_x);}
-#endif
-
-// cbrt
-
-#ifndef _LIBCPP_MSVCRT
-inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __lcpp_x) _NOEXCEPT       {return cbrtf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-cbrt(_A1 __lcpp_x) _NOEXCEPT {return cbrt((double)__lcpp_x);}
-#endif
-
-// copysign
-
-#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
-inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
-                                                float __lcpp_y) _NOEXCEPT {
-  return copysignf(__lcpp_x, __lcpp_y);
-}
-inline _LIBCPP_INLINE_VISIBILITY long double
-copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
-  return copysignl(__lcpp_x, __lcpp_y);
-}
-#endif
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-#ifndef _LIBCPP_MSVCRT
-
-// erf
-
-inline _LIBCPP_INLINE_VISIBILITY float       erf(float __lcpp_x) _NOEXCEPT       {return erff(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return erfl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-erf(_A1 __lcpp_x) _NOEXCEPT {return erf((double)__lcpp_x);}
-
-// erfc
-
-inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __lcpp_x) _NOEXCEPT       {return erfcf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return erfcl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-erfc(_A1 __lcpp_x) _NOEXCEPT {return erfc((double)__lcpp_x);}
-
-// exp2
-
-inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __lcpp_x) _NOEXCEPT       {return exp2f(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return exp2l(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-exp2(_A1 __lcpp_x) _NOEXCEPT {return exp2((double)__lcpp_x);}
-
-// expm1
-
-inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __lcpp_x) _NOEXCEPT       {return expm1f(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return expm1l(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-expm1(_A1 __lcpp_x) _NOEXCEPT {return expm1((double)__lcpp_x);}
-
-// fdim
-
-inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fdimf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fdiml(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// fma
-
-inline _LIBCPP_INLINE_VISIBILITY float       fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT                   {return fmaf(__lcpp_x, __lcpp_y, __lcpp_z);}
-inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return fmal(__lcpp_x, __lcpp_y, __lcpp_z);}
-
-template <class _A1, class _A2, class _A3>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value &&
-    std::is_arithmetic<_A3>::value,
-    std::__promote<_A1, _A2, _A3>
->::type
-fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value &&
-                     std::is_same<_A3, __result_type>::value)), "");
-    return fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
-}
-
-// fmax
-
-inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fmaxf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmaxl(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// fmin
-
-inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return fminf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fminl(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// hypot
-
-inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return hypotf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return hypotl(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// ilogb
-
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT       {return ilogbf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ilogbl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, int>::type
-ilogb(_A1 __lcpp_x) _NOEXCEPT {return ilogb((double)__lcpp_x);}
-
-// lgamma
-
-inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __lcpp_x) _NOEXCEPT       {return lgammaf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return lgammal(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-lgamma(_A1 __lcpp_x) _NOEXCEPT {return lgamma((double)__lcpp_x);}
-
-// llrint
-
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT       {return llrintf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return llrintl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, long long>::type
-llrint(_A1 __lcpp_x) _NOEXCEPT {return llrint((double)__lcpp_x);}
-
-// llround
-
-inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT       {return llroundf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return llroundl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, long long>::type
-llround(_A1 __lcpp_x) _NOEXCEPT {return llround((double)__lcpp_x);}
-
-// log1p
-
-inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __lcpp_x) _NOEXCEPT       {return log1pf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return log1pl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-log1p(_A1 __lcpp_x) _NOEXCEPT {return log1p((double)__lcpp_x);}
-
-// log2
-
-inline _LIBCPP_INLINE_VISIBILITY float       log2(float __lcpp_x) _NOEXCEPT       {return log2f(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return log2l(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-log2(_A1 __lcpp_x) _NOEXCEPT {return log2((double)__lcpp_x);}
-
-// logb
-
-inline _LIBCPP_INLINE_VISIBILITY float       logb(float __lcpp_x) _NOEXCEPT       {return logbf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return logbl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-logb(_A1 __lcpp_x) _NOEXCEPT {return logb((double)__lcpp_x);}
-
-// lrint
-
-inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT       {return lrintf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return lrintl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, long>::type
-lrint(_A1 __lcpp_x) _NOEXCEPT {return lrint((double)__lcpp_x);}
-
-// lround
-
-inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT       {return lroundf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return lroundl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, long>::type
-lround(_A1 __lcpp_x) _NOEXCEPT {return lround((double)__lcpp_x);}
-
-// nan
-
-// nearbyint
-
-inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __lcpp_x) _NOEXCEPT       {return nearbyintf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return nearbyintl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-nearbyint(_A1 __lcpp_x) _NOEXCEPT {return nearbyint((double)__lcpp_x);}
-
-// nextafter
-
-inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return nextafterf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nextafterl(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// nexttoward
-
-inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT       {return nexttowardf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardl(__lcpp_x, __lcpp_y);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttoward((double)__lcpp_x, __lcpp_y);}
-
-// remainder
-
-inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT             {return remainderf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return remainderl(__lcpp_x, __lcpp_y);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y);
-}
-
-// remquo
-
-inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT             {return remquof(__lcpp_x, __lcpp_y, __lcpp_z);}
-inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquol(__lcpp_x, __lcpp_y, __lcpp_z);}
-
-template <class _A1, class _A2>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::__lazy_enable_if
-<
-    std::is_arithmetic<_A1>::value &&
-    std::is_arithmetic<_A2>::value,
-    std::__promote<_A1, _A2>
->::type
-remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT
-{
-    typedef typename std::__promote<_A1, _A2>::type __result_type;
-    static_assert((!(std::is_same<_A1, __result_type>::value &&
-                     std::is_same<_A2, __result_type>::value)), "");
-    return remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z);
-}
-
-// rint
-
-inline _LIBCPP_INLINE_VISIBILITY float       rint(float __lcpp_x) _NOEXCEPT       {return rintf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return rintl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-rint(_A1 __lcpp_x) _NOEXCEPT {return rint((double)__lcpp_x);}
-
-// round
-
-inline _LIBCPP_INLINE_VISIBILITY float       round(float __lcpp_x) _NOEXCEPT       {return roundf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return roundl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-round(_A1 __lcpp_x) _NOEXCEPT {return round((double)__lcpp_x);}
-
-// scalbln
-
-inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT       {return scalblnf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnl(__lcpp_x, __lcpp_y);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalbln((double)__lcpp_x, __lcpp_y);}
-
-// scalbn
-
-inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT       {return scalbnf(__lcpp_x, __lcpp_y);}
-inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnl(__lcpp_x, __lcpp_y);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbn((double)__lcpp_x, __lcpp_y);}
-
-// tgamma
-
-inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __lcpp_x) _NOEXCEPT       {return tgammaf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return tgammal(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-tgamma(_A1 __lcpp_x) _NOEXCEPT {return tgamma((double)__lcpp_x);}
-
-// trunc
-
-inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __lcpp_x) _NOEXCEPT       {return truncf(__lcpp_x);}
-inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return truncl(__lcpp_x);}
-
-template <class _A1>
-inline _LIBCPP_INLINE_VISIBILITY
-typename std::enable_if<std::is_integral<_A1>::value, double>::type
-trunc(_A1 __lcpp_x) _NOEXCEPT {return trunc((double)__lcpp_x);}
-
-#endif // !_LIBCPP_MSVCRT
-#endif // __sun__
-
-} // extern "C++"
-
-#endif // __cplusplus
-
-#endif  // _LIBCPP_MATH_H
diff --git a/include/memory b/include/memory
index 7627248..df35a07 100644
--- a/include/memory
+++ b/include/memory
@@ -607,13 +607,12 @@
 #include <__functional_base>
 #include <iosfwd>
 #include <tuple>
-#include <stdexcept>
 #include <cstring>
 #if defined(_LIBCPP_NO_EXCEPTIONS)
     #include <cassert>
 #endif
 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 #  include <atomic>
 #endif
 
@@ -933,15 +932,6 @@
         {return _VSTD::addressof(__r);}
 };
 
-template <class _From, class _To>
-struct __rebind_pointer {
-#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
-    typedef typename pointer_traits<_From>::template rebind<_To>        type;
-#else
-    typedef typename pointer_traits<_From>::template rebind<_To>::other type;
-#endif
-};
-
 // allocator_traits
 
 namespace __has_pointer_type_imp
@@ -1679,7 +1669,7 @@
             {return __a.max_size();}
     _LIBCPP_INLINE_VISIBILITY
     static size_type __max_size(false_type, const allocator_type&)
-            {return numeric_limits<size_type>::max() / sizeof(value_type);}
+            {return numeric_limits<size_type>::max();}
 
     _LIBCPP_INLINE_VISIBILITY
     static allocator_type
@@ -1727,12 +1717,7 @@
     _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
         {return _VSTD::addressof(__x);}
     _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
-        {
-        if (__n > max_size())
-            __libcpp_throw(length_error("allocator<T>::allocate(size_t n)"
-                                      " 'n' exceeds maximum supported size"));
-        return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
-        }
+        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
         {_VSTD::__deallocate((void*)__p);}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
@@ -1823,12 +1808,7 @@
     _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
         {return _VSTD::addressof(__x);}
     _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
-    {
-        if (__n > max_size())
-            __libcpp_throw(length_error("allocator<const T>::allocate(size_t n)"
-                                      " 'n' exceeds maximum supported size"));
-        return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
-    }
+        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
         {_VSTD::__deallocate((void*)__p);}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
@@ -1920,10 +1900,6 @@
     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
         {::new(&*__x_) _Tp(__element); return *this;}
-#if _LIBCPP_STD_VER >= 14
-    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
-        {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
-#endif
     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
     _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
         {raw_storage_iterator __t(*this); ++__x_; return __t;}
@@ -2559,7 +2535,7 @@
                          typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
         {
             static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
-            static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
+            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
             delete [] __ptr;
         }
 };
@@ -2683,17 +2659,10 @@
         : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
 
     template <class _Up, class _Ep>
-    _LIBCPP_INLINE_VISIBILITY
-    typename enable_if<
-        !is_array<_Up>::value &&
-        is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
-        is_assignable<deleter_type&, _Ep&>::value,
-        unique_ptr&
-    >::type
-    operator=(unique_ptr<_Up, _Ep> __u)
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
     {
         reset(__u.release());
-        __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
+        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
         return *this;
     }
 
@@ -2929,6 +2898,7 @@
         return __t;
     }
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _Pp>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
@@ -2939,13 +2909,29 @@
         if (__tmp)
             __ptr_.second()(__tmp);
     }
-    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
+    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
     {
         pointer __tmp = __ptr_.first();
         __ptr_.first() = nullptr;
         if (__tmp)
             __ptr_.second()(__tmp);
     }
+    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = nullptr;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = __p;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
 private:
@@ -2969,10 +2955,7 @@
 
 template <class _Tp, class _Dp>
 inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Dp>::value,
-    void
->::type
+void
 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
 
 template <class _T1, class _D1, class _T2, class _D2>
@@ -3164,6 +3147,8 @@
 
 #endif  // _LIBCPP_STD_VER > 11
 
+template <class _Tp> struct hash;
+
 template <class _Size>
 inline _LIBCPP_INLINE_VISIBILITY
 _Size
@@ -3189,7 +3174,7 @@
 // murmur2
 template <class _Size>
 _Size
-__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 
+__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
 {
     const _Size __m = 0x5bd1e995;
     const _Size __r = 24;
@@ -3339,7 +3324,7 @@
 // cityhash64
 template <class _Size>
 _Size
-__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 
+__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
 {
   const char* __s = static_cast<const char*>(__key);
   if (__len <= 32) {
@@ -3869,9 +3854,7 @@
 
     struct __nat {int __for_bool_;};
 public:
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
     template<class _Yp>
         explicit shared_ptr(_Yp* __p,
@@ -3884,18 +3867,15 @@
                    typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
     template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
     template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
+    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
     shared_ptr(const shared_ptr& __r) _NOEXCEPT;
     template<class _Yp>
-        _LIBCPP_INLINE_VISIBILITY
         shared_ptr(const shared_ptr<_Yp>& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
                        _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     shared_ptr(shared_ptr&& __r) _NOEXCEPT;
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY  shared_ptr(shared_ptr<_Yp>&& __r,
+    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
                        _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -3952,7 +3932,6 @@
 
     ~shared_ptr();
 
-    _LIBCPP_INLINE_VISIBILITY
     shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
     template<class _Yp>
         typename enable_if
@@ -3960,10 +3939,8 @@
             is_convertible<_Yp*, element_type*>::value,
             shared_ptr&
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
     template<class _Yp>
         typename enable_if
@@ -3971,10 +3948,8 @@
             is_convertible<_Yp*, element_type*>::value,
             shared_ptr<_Tp>&
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         operator=(shared_ptr<_Yp>&& __r);
     template<class _Yp>
-        _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         <
             !is_array<_Yp>::value &&
@@ -3984,7 +3959,6 @@
         operator=(auto_ptr<_Yp>&& __r);
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template<class _Yp>
-        _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         <
             !is_array<_Yp>::value &&
@@ -4001,16 +3975,12 @@
             shared_ptr&
         >::type
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-        _LIBCPP_INLINE_VISIBILITY
         operator=(unique_ptr<_Yp, _Dp>&& __r);
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-        _LIBCPP_INLINE_VISIBILITY
         operator=(unique_ptr<_Yp, _Dp> __r);
 #endif
 
-    _LIBCPP_INLINE_VISIBILITY
     void swap(shared_ptr& __r) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     void reset() _NOEXCEPT;
     template<class _Yp>
         typename enable_if
@@ -4018,7 +3988,6 @@
             is_convertible<_Yp*, element_type*>::value,
             void
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         reset(_Yp* __p);
     template<class _Yp, class _Dp>
         typename enable_if
@@ -4026,7 +3995,6 @@
             is_convertible<_Yp*, element_type*>::value,
             void
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         reset(_Yp* __p, _Dp __d);
     template<class _Yp, class _Dp, class _Alloc>
         typename enable_if
@@ -4034,7 +4002,6 @@
             is_convertible<_Yp*, element_type*>::value,
             void
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         reset(_Yp* __p, _Dp __d, _Alloc __a);
 
     _LIBCPP_INLINE_VISIBILITY
@@ -4136,7 +4103,7 @@
 };
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
     : __ptr_(0),
@@ -4145,7 +4112,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
     : __ptr_(0),
@@ -4268,7 +4235,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
     : __ptr_(__p),
       __cntrl_(__r.__cntrl_)
@@ -4278,7 +4245,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -4289,7 +4256,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
                             typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
          _NOEXCEPT
@@ -4303,7 +4270,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -4314,7 +4281,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
                             typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
          _NOEXCEPT
@@ -4601,7 +4568,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>&
 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
 {
@@ -4611,7 +4578,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -4626,7 +4593,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 shared_ptr<_Tp>&
 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
 {
@@ -4636,7 +4603,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -4650,7 +4617,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     !is_array<_Yp>::value &&
@@ -4665,7 +4632,7 @@
 
 template<class _Tp>
 template <class _Yp, class _Dp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     !is_array<_Yp>::value &&
@@ -4713,7 +4680,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
 {
@@ -4722,7 +4689,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 shared_ptr<_Tp>::reset() _NOEXCEPT
 {
@@ -4731,7 +4698,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -4744,7 +4711,7 @@
 
 template<class _Tp>
 template<class _Yp, class _Dp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -4757,7 +4724,7 @@
 
 template<class _Tp>
 template<class _Yp, class _Dp, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -5074,27 +5041,23 @@
     __shared_weak_count* __cntrl_;
 
 public:
-    _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
+    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
                         _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     weak_ptr(weak_ptr const& __r) _NOEXCEPT;
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
+    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
                          _NOEXCEPT;
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     weak_ptr(weak_ptr&& __r) _NOEXCEPT;
-    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
+    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
                    typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
                          _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     ~weak_ptr();
 
-    _LIBCPP_INLINE_VISIBILITY
     weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
     template<class _Yp>
         typename enable_if
@@ -5102,12 +5065,10 @@
             is_convertible<_Yp*, element_type*>::value,
             weak_ptr&
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-    _LIBCPP_INLINE_VISIBILITY
     weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
     template<class _Yp>
         typename enable_if
@@ -5115,7 +5076,6 @@
             is_convertible<_Yp*, element_type*>::value,
             weak_ptr&
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -5126,12 +5086,9 @@
             is_convertible<_Yp*, element_type*>::value,
             weak_ptr&
         >::type
-        _LIBCPP_INLINE_VISIBILITY
         operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
 
-    _LIBCPP_INLINE_VISIBILITY
     void swap(weak_ptr& __r) _NOEXCEPT;
-    _LIBCPP_INLINE_VISIBILITY
     void reset() _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -5155,7 +5112,7 @@
 };
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR
 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
     : __ptr_(0),
@@ -5164,7 +5121,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -5175,7 +5132,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
                         typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
                          _NOEXCEPT
@@ -5188,7 +5145,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
                         typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
          _NOEXCEPT
@@ -5202,7 +5159,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
     : __ptr_(__r.__ptr_),
       __cntrl_(__r.__cntrl_)
@@ -5213,7 +5170,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
                         typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
          _NOEXCEPT
@@ -5234,7 +5191,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>&
 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
 {
@@ -5244,7 +5201,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -5259,7 +5216,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 weak_ptr<_Tp>&
 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
 {
@@ -5269,7 +5226,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -5285,7 +5242,7 @@
 
 template<class _Tp>
 template<class _Yp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     is_convertible<_Yp*, _Tp*>::value,
@@ -5298,7 +5255,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
 {
@@ -5315,7 +5272,7 @@
 }
 
 template<class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 weak_ptr<_Tp>::reset() _NOEXCEPT
 {
@@ -5348,11 +5305,7 @@
     return __r;
 }
 
-#if _LIBCPP_STD_VER > 14
-template <class _Tp = void> struct owner_less;
-#else
 template <class _Tp> struct owner_less;
-#endif
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
@@ -5386,30 +5339,6 @@
         {return __x.owner_before(__y);}
 };
 
-#if _LIBCPP_STD_VER > 14
-template <>
-struct _LIBCPP_TYPE_VIS_ONLY owner_less<void>
-{
-    template <class _Tp, class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
-        {return __x.owner_before(__y);}
-    template <class _Tp, class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()( shared_ptr<_Tp> const& __x,  weak_ptr<_Up> const& __y) const
-        {return __x.owner_before(__y);}
-    template <class _Tp, class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(   weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
-        {return __x.owner_before(__y);}
-    template <class _Tp, class _Up>
-    _LIBCPP_INLINE_VISIBILITY
-    bool operator()(   weak_ptr<_Tp> const& __x,   weak_ptr<_Up> const& __y) const
-        {return __x.owner_before(__y);}
-    typedef void is_transparent;
-};
-#endif
-
 template<class _Tp>
 class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
 {
@@ -5452,9 +5381,7 @@
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
 
-// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
-// enabled with clang.
-#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 
 class _LIBCPP_TYPE_VIS __sp_mut
 {
@@ -5541,17 +5468,14 @@
 bool
 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
 {
-    shared_ptr<_Tp> __temp;
     __sp_mut& __m = __get_sp_mut(__p);
     __m.lock();
     if (__p->__owner_equivalent(*__v))
     {
-        _VSTD::swap(__temp, *__p);
         *__p = __w;
         __m.unlock();
         return true;
     }
-    _VSTD::swap(__temp, *__v);
     *__v = *__p;
     __m.unlock();
     return false;
@@ -5583,7 +5507,7 @@
     return atomic_compare_exchange_weak(__p, __v, __w);
 }
 
-#endif  // defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
+#endif  // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
 
 //enum class
 struct _LIBCPP_TYPE_VIS pointer_safety
@@ -5621,7 +5545,7 @@
 
 // --- Helper for container swap --
 template <typename _Alloc>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY
 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
 #if _LIBCPP_STD_VER >= 14
     _NOEXCEPT
@@ -5647,18 +5571,9 @@
 }
 
 template <typename _Alloc>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY
 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
 
-template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
-struct __noexcept_move_assign_container : public integral_constant<bool, 
-    _Traits::propagate_on_container_move_assignment::value
-#if _LIBCPP_STD_VER > 14
-        || _Traits::is_always_equal::value
-#else
-        && is_nothrow_move_assignable<_Alloc>::value
-#endif
-    > {};
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/include/module.modulemap b/include/module.modulemap
index 3fb7428..3c0700e 100644
--- a/include/module.modulemap
+++ b/include/module.modulemap
@@ -455,13 +455,9 @@
     export *
   }
 
-  // FIXME: We don't have modules for the <foo.h> headers, because they might
-  // be included from the C library's headers, and that would create a #include
-  // cycle. For the same reason, we don't have a module for __config.
-  //module __config { header "__config" export * }
-
   // FIXME: These should be private.
   module __bit_reference { header "__bit_reference" export * }
+  module __config { header "__config" export * }
   module __debug { header "__debug" export * }
   module __functional_base { header "__functional_base" export * }
   module __hash_table { header "__hash_table" export * }
diff --git a/include/mutex b/include/mutex
index 4d288ae..373d75b 100644
--- a/include/mutex
+++ b/include/mutex
@@ -179,7 +179,7 @@
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 #include <tuple>
 #endif
-#include <__threading_support>
+#include <sched.h>
 
 #include <__undef_min_max>
 
@@ -193,7 +193,7 @@
 
 class _LIBCPP_TYPE_VIS recursive_mutex
 {
-    __libcpp_mutex_t __m_;
+    pthread_mutex_t __m_;
 
 public:
      recursive_mutex();
@@ -208,7 +208,7 @@
     bool try_lock() _NOEXCEPT;
     void unlock()  _NOEXCEPT;
 
-    typedef __libcpp_mutex_t* native_handle_type;
+    typedef pthread_mutex_t* native_handle_type;
     _LIBCPP_INLINE_VISIBILITY
     native_handle_type native_handle() {return &__m_;}
 };
@@ -260,7 +260,7 @@
     mutex              __m_;
     condition_variable __cv_;
     size_t             __count_;
-    __libcpp_thread_id __id_;
+    pthread_t          __id_;
 public:
      recursive_timed_mutex();
      ~recursive_timed_mutex();
@@ -286,9 +286,9 @@
 recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
 {
     using namespace chrono;
-    __libcpp_thread_id __id = __libcpp_thread_get_current_id();
+    pthread_t __id = pthread_self();
     unique_lock<mutex> lk(__m_);
-    if (__libcpp_thread_id_equal(__id, __id_))
+    if (pthread_equal(__id, __id_))
     {
         if (__count_ == numeric_limits<size_t>::max())
             return false;
@@ -360,7 +360,7 @@
                 break;
             }
         }
-        __libcpp_thread_yield();
+        sched_yield();
         {
             unique_lock<_L1> __u1(__l1);
             if (__l0.try_lock())
@@ -369,7 +369,7 @@
                 break;
             }
         }
-        __libcpp_thread_yield();
+        sched_yield();
     }
 }
 
@@ -394,7 +394,7 @@
                 }
             }
             ++__i;
-            __libcpp_thread_yield();
+            sched_yield();
             break;
         case 1:
             {
@@ -410,7 +410,7 @@
                 __i = 0;
             else
                 __i += 2;
-            __libcpp_thread_yield();
+            sched_yield();
             break;
         default:
             __lock_first(__i - 2, __l2, __l3..., __l0, __l1);
diff --git a/include/queue b/include/queue
index c657b52..6f49c87 100644
--- a/include/queue
+++ b/include/queue
@@ -66,7 +66,7 @@
     template <class... Args> void emplace(Args&&... args);
     void pop();
 
-    void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
+    void swap(queue& q) noexcept(noexcept(swap(c, q.c)));
 };
 
 template <class T, class Container>
@@ -153,8 +153,7 @@
     void pop();
 
     void swap(priority_queue& q)
-        noexcept(is_nothrow_swappable_v<Container> &&
-                 is_nothrow_swappable_v<Comp>)
+        noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp)));
 };
 
 template <class T, class Container, class Compare>
@@ -199,7 +198,6 @@
     typedef typename container_type::reference       reference;
     typedef typename container_type::const_reference const_reference;
     typedef typename container_type::size_type       size_type;
-    static_assert((is_same<_Tp, value_type>::value), "" );
 
 protected:
     container_type c;
@@ -370,10 +368,7 @@
 
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Container>::value,
-    void
->::type
+void
 swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
@@ -397,7 +392,6 @@
     typedef typename container_type::reference       reference;
     typedef typename container_type::const_reference const_reference;
     typedef typename container_type::size_type       size_type;
-    static_assert((is_same<_Tp, value_type>::value), "" );
 
 protected:
     container_type c;
@@ -436,56 +430,45 @@
     _LIBCPP_INLINE_VISIBILITY
     explicit priority_queue(const value_compare& __comp)
         : c(), comp(__comp) {}
-    _LIBCPP_INLINE_VISIBILITY
     priority_queue(const value_compare& __comp, const container_type& __c);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     explicit priority_queue(const value_compare& __comp, container_type&& __c);
 #endif
     template <class _InputIter>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp = value_compare());
     template <class _InputIter>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp, const container_type& __c);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _InputIter>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(_InputIter __f, _InputIter __l,
                        const value_compare& __comp, container_type&& __c);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         explicit priority_queue(const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, const container_type& __c,
                        const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(const priority_queue& __q, const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(const value_compare& __comp, container_type&& __c,
                        const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
     template <class _Alloc>
-        _LIBCPP_INLINE_VISIBILITY
         priority_queue(priority_queue&& __q, const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type* = 0);
@@ -498,26 +481,22 @@
     _LIBCPP_INLINE_VISIBILITY
     const_reference top() const   {return c.front();}
 
-    _LIBCPP_INLINE_VISIBILITY
     void push(const value_type& __v);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     void push(value_type&& __v);
 #ifndef _LIBCPP_HAS_NO_VARIADICS
-    template <class... _Args> _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args);
+    template <class... _Args> void emplace(_Args&&... __args);
 #endif
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     void pop();
 
-    _LIBCPP_INLINE_VISIBILITY
     void swap(priority_queue& __q)
         _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
                    __is_nothrow_swappable<value_compare>::value);
 };
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
                                                           const container_type& __c)
     : c(__c),
@@ -529,7 +508,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           container_type&& __c)
     : c(_VSTD::move(__c)),
@@ -542,7 +521,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _InputIter>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp)
     : c(__f, __l),
@@ -553,7 +532,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _InputIter>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp,
                                                           const container_type& __c)
@@ -568,7 +547,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _InputIter>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
                                                           const value_compare& __comp,
                                                           container_type&& __c)
@@ -583,7 +562,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
                                                          _Alloc>::value>::type*)
@@ -593,7 +572,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
@@ -605,7 +584,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           const container_type& __c,
                                                           const _Alloc& __a,
@@ -619,7 +598,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
                                                           const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
@@ -634,7 +613,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
                                                           container_type&& __c,
                                                           const _Alloc& __a,
@@ -648,7 +627,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
                                                           const _Alloc& __a,
                        typename enable_if<uses_allocator<container_type,
@@ -662,7 +641,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
 {
@@ -673,7 +652,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
 {
@@ -685,7 +664,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 template <class... _Args>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
 {
@@ -697,7 +676,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 priority_queue<_Tp, _Container, _Compare>::pop()
 {
@@ -706,7 +685,7 @@
 }
 
 template <class _Tp, class _Container, class _Compare>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
         _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
@@ -719,11 +698,7 @@
 
 template <class _Tp, class _Container, class _Compare>
 inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Container>::value
-    && __is_swappable<_Compare>::value,
-    void
->::type
+void
 swap(priority_queue<_Tp, _Container, _Compare>& __x,
      priority_queue<_Tp, _Container, _Compare>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
diff --git a/include/random b/include/random
index 794bf7b..c8341ef 100644
--- a/include/random
+++ b/include/random
@@ -3119,7 +3119,6 @@
                independent_bits_engine<_Eng, _Wp, _UI>& __x);
 
 private:
-    _LIBCPP_INLINE_VISIBILITY
     result_type __eval(false_type);
     result_type __eval(true_type);
 
@@ -3145,7 +3144,7 @@
 };
 
 template<class _Engine, size_t __w, class _UIntType>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _UIntType
 independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
 {
@@ -3736,7 +3735,7 @@
         _LIBCPP_INLINE_VISIBILITY
         result_type operator()(_URNG& __g)
         {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
@@ -3766,7 +3765,7 @@
 
 template<class _RealType>
 template<class _URNG>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename uniform_real_distribution<_RealType>::result_type
 uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
 {
@@ -3852,7 +3851,7 @@
         _LIBCPP_INLINE_VISIBILITY
         result_type operator()(_URNG& __g)
         {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
@@ -3879,7 +3878,7 @@
 };
 
 template<class _URNG>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 bernoulli_distribution::result_type
 bernoulli_distribution::operator()(_URNG& __g, const param_type& __p)
 {
@@ -5523,7 +5522,7 @@
         _LIBCPP_INLINE_VISIBILITY
         result_type operator()(_URNG& __g)
         {return (*this)(__g, __p_);}
-    template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p);
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
 
     // property functions
     _LIBCPP_INLINE_VISIBILITY
@@ -5553,7 +5552,7 @@
 
 template <class _RealType>
 template<class _URNG>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _RealType
 cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
 {
diff --git a/include/ratio b/include/ratio
index 8f708ce..f623a06 100644
--- a/include/ratio
+++ b/include/ratio
@@ -62,19 +62,6 @@
 typedef ratio<   1000000000000000000000, 1> zetta;  // not supported
 typedef ratio<1000000000000000000000000, 1> yotta;  // not supported
 
-  // 20.11.5, ratio comparison
-  template <class R1, class R2> constexpr bool ratio_equal_v
-    = ratio_equal<R1, R2>::value;                                       // C++17
-  template <class R1, class R2> constexpr bool ratio_not_equal_v
-    = ratio_not_equal<R1, R2>::value;                                   // C++17
-  template <class R1, class R2> constexpr bool ratio_less_v
-    = ratio_less<R1, R2>::value;                                        // C++17
-  template <class R1, class R2> constexpr bool ratio_less_equal_v
-    = ratio_less_equal<R1, R2>::value;                                  // C++17
-  template <class R1, class R2> constexpr bool ratio_greater_v
-    = ratio_greater<R1, R2>::value;                                     // C++17
-  template <class R1, class R2> constexpr bool ratio_greater_equal_v
-    = ratio_greater_equal<R1, R2>::value;                               // C++17
 }
 */
 
@@ -498,26 +485,6 @@
                   __static_lcm<_R1::den, _R2::den>::value> type;
 };
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_equal_v
-    = ratio_equal<_R1, _R2>::value;
-
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_not_equal_v
-    = ratio_not_equal<_R1, _R2>::value;
-
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_v
-    = ratio_less<_R1, _R2>::value;
-
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_less_equal_v
-    = ratio_less_equal<_R1, _R2>::value;
-
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_v
-    = ratio_greater<_R1, _R2>::value;
-
-template <class _R1, class _R2> _LIBCPP_CONSTEXPR bool ratio_greater_equal_v
-    = ratio_greater_equal<_R1, _R2>::value;
-#endif
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_RATIO
diff --git a/include/regex b/include/regex
index 3724204..c270cab 100644
--- a/include/regex
+++ b/include/regex
@@ -762,7 +762,6 @@
 #include <memory>
 #include <vector>
 #include <deque>
-#include <cassert>
 
 #include <__undef_min_max>
 
@@ -961,9 +960,7 @@
 void __throw_regex_error()
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
-    throw regex_error(_Ev);
-#else
-    assert(!"regex_error");
+	throw regex_error(_Ev);
 #endif
 }
 
@@ -982,8 +979,6 @@
 
 #ifdef __ANDROID__
     static const char_class_type __regex_word = 0x8000;
-#elif defined(__mips__) && defined(__GLIBC__)
-    static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
 #else
     static const char_class_type __regex_word = 0x80;
 #endif
@@ -1059,7 +1054,6 @@
     _LIBCPP_INLINE_VISIBILITY
     int __regex_traits_value(char __ch, int __radix) const
         {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
-    _LIBCPP_INLINE_VISIBILITY
     int __regex_traits_value(wchar_t __ch, int __radix) const;
 };
 
@@ -1282,7 +1276,7 @@
 }
 
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 int
 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
 {
@@ -1745,8 +1739,6 @@
 void
 __back_ref<_CharT>::__exec(__state& __s) const
 {
-    if (__mexp_ > __s.__sub_matches_.size())
-        __throw_regex_error<regex_constants::error_backref>();
     sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
     if (__sm.matched)
     {
@@ -4276,9 +4268,6 @@
     if (__first != __last && *__first == '\\')
     {
         _ForwardIterator __t1 = _VSTD::next(__first);
-        if (__t1 == __last)
-            __throw_regex_error<regex_constants::error_escape>();
-
         _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
         if (__t2 != __t1)
             __first = __t2;
@@ -5398,8 +5387,8 @@
                 if ('0' <= *__fmt_first && *__fmt_first <= '9')
                 {
                     size_t __i = *__fmt_first - '0';
-                    __out = _VSTD::copy((*this)[__i].first,
-                                        (*this)[__i].second, __out);
+                    __out = _VSTD::copy(__matches_[__i].first,
+                                       __matches_[__i].second, __out);
                 }
                 else
                 {
@@ -5450,8 +5439,8 @@
                             ++__fmt_first;
                             __i = 10 * __i + *__fmt_first - '0';
                         }
-                        __out = _VSTD::copy((*this)[__i].first,
-                                            (*this)[__i].second, __out);
+                        __out = _VSTD::copy(__matches_[__i].first,
+                                           __matches_[__i].second, __out);
                     }
                     else
                     {
diff --git a/include/scoped_allocator b/include/scoped_allocator
index 9436dac..cd4987a 100644
--- a/include/scoped_allocator
+++ b/include/scoped_allocator
@@ -58,8 +58,6 @@
     template <class OuterA2>
         scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
 
-    scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
-    scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
     ~scoped_allocator_adaptor();
 
     inner_allocator_type& inner_allocator() noexcept;
@@ -459,8 +457,6 @@
             scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
                 : base(_VSTD::move(__other)) {}
 
-    // scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
-    // scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
     // ~scoped_allocator_adaptor() = default;
 
     _LIBCPP_INLINE_VISIBILITY
diff --git a/include/set b/include/set
index ac69e08..9d64a52 100644
--- a/include/set
+++ b/include/set
@@ -409,9 +409,6 @@
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
-                  "Allocator::value_type must be same type as value_type");
-
 private:
     typedef __tree<value_type, value_compare, allocator_type> __base;
     typedef allocator_traits<allocator_type>                  __alloc_traits;
@@ -822,9 +819,6 @@
     typedef value_type&                              reference;
     typedef const value_type&                        const_reference;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
-                  "Allocator::value_type must be same type as value_type");
-
 private:
     typedef __tree<value_type, value_compare, allocator_type> __base;
     typedef allocator_traits<allocator_type>                  __alloc_traits;
diff --git a/include/setjmp.h b/include/setjmp.h
deleted file mode 100644
index 464b4a5..0000000
--- a/include/setjmp.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- setjmp.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SETJMP_H
-#define _LIBCPP_SETJMP_H
-
-/*
-    setjmp.h synopsis
-
-Macros:
-
-    setjmp
-
-Types:
-
-    jmp_buf
-
-void longjmp(jmp_buf env, int val);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <setjmp.h>
-
-#ifdef __cplusplus
-
-#ifndef setjmp
-#define setjmp(env) setjmp(env)
-#endif
-
-#endif // __cplusplus
-
-#endif  // _LIBCPP_SETJMP_H
diff --git a/include/shared_mutex b/include/shared_mutex
index 923fe07..dcb9394 100644
--- a/include/shared_mutex
+++ b/include/shared_mutex
@@ -319,25 +319,25 @@
 
     _LIBCPP_INLINE_VISIBILITY
     explicit shared_lock(mutex_type& __m)
-        : __m_(_VSTD::addressof(__m)),
+        : __m_(&__m),
           __owns_(true)
         {__m_->lock_shared();}
 
     _LIBCPP_INLINE_VISIBILITY
     shared_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
-        : __m_(_VSTD::addressof(__m)),
+        : __m_(&__m),
           __owns_(false)
         {}
 
     _LIBCPP_INLINE_VISIBILITY
     shared_lock(mutex_type& __m, try_to_lock_t)
-        : __m_(_VSTD::addressof(__m)),
+        : __m_(&__m),
           __owns_(__m.try_lock_shared())
         {}
 
     _LIBCPP_INLINE_VISIBILITY
     shared_lock(mutex_type& __m, adopt_lock_t)
-        : __m_(_VSTD::addressof(__m)),
+        : __m_(&__m),
           __owns_(true)
         {}
 
@@ -345,7 +345,7 @@
         _LIBCPP_INLINE_VISIBILITY
         shared_lock(mutex_type& __m,
                     const chrono::time_point<_Clock, _Duration>& __abs_time)
-            : __m_(_VSTD::addressof(__m)),
+            : __m_(&__m),
               __owns_(__m.try_lock_shared_until(__abs_time))
             {}
 
@@ -353,7 +353,7 @@
         _LIBCPP_INLINE_VISIBILITY
         shared_lock(mutex_type& __m,
                     const chrono::duration<_Rep, _Period>& __rel_time)
-            : __m_(_VSTD::addressof(__m)),
+            : __m_(&__m),
               __owns_(__m.try_lock_shared_for(__rel_time))
             {}
 
diff --git a/include/stack b/include/stack
index 48b3b0d..2992b09 100644
--- a/include/stack
+++ b/include/stack
@@ -58,7 +58,7 @@
     template <class... Args> void emplace(Args&&... args);
     void pop();
 
-    void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>)
+    void swap(stack& c) noexcept(noexcept(swap(c, q.c)));
 };
 
 template <class T, class Container>
@@ -112,8 +112,7 @@
     typedef typename container_type::reference       reference;
     typedef typename container_type::const_reference const_reference;
     typedef typename container_type::size_type       size_type;
-    static_assert((is_same<_Tp, value_type>::value), "" );
-    
+
 protected:
     container_type c;
 
@@ -275,10 +274,7 @@
 
 template <class _Tp, class _Container>
 inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Container>::value,
-    void
->::type
+void
 swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
     _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
 {
diff --git a/include/stdbool.h b/include/stdbool.h
deleted file mode 100644
index 86a127f..0000000
--- a/include/stdbool.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- stdbool.h --------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef _LIBCPP_STDBOOL_H
-#define _LIBCPP_STDBOOL_H
-
-
-/*
-    stdbool.h synopsis
-
-Macros:
-
-    __bool_true_false_are_defined
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stdbool.h>
-
-#ifdef __cplusplus
-#undef bool
-#undef true
-#undef false
-#undef __bool_true_false_are_defined
-#define __bool_true_false_are_defined 1
-#endif
-
-#endif  // _LIBCPP_STDBOOL_H
diff --git a/include/stddef.h b/include/stddef.h
deleted file mode 100644
index 8841bbe..0000000
--- a/include/stddef.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- stddef.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(__need_ptrdiff_t) || defined(__need_size_t) || \
-    defined(__need_wchar_t) || defined(__need_NULL) || defined(__need_wint_t)
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stddef.h>
-
-#elif !defined(_LIBCPP_STDDEF_H)
-#define _LIBCPP_STDDEF_H
-
-/*
-    stddef.h synopsis
-
-Macros:
-
-    offsetof(type,member-designator)
-    NULL
-
-Types:
-
-    ptrdiff_t
-    size_t
-    max_align_t
-    nullptr_t
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stddef.h>
-
-#ifdef __cplusplus
-
-extern "C++" {
-#include <__nullptr>
-using std::nullptr_t;
-}
-
-// Re-use the compiler's <stddef.h> max_align_t where possible.
-#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T)
-typedef long double max_align_t;
-#endif
-
-#endif
-
-#endif  // _LIBCPP_STDDEF_H
diff --git a/include/stdexcept b/include/stdexcept
index 4218b13..f251806 100644
--- a/include/stdexcept
+++ b/include/stdexcept
@@ -53,11 +53,7 @@
 #ifndef _LIBCPP___REFSTRING
 _LIBCPP_BEGIN_NAMESPACE_STD
 class _LIBCPP_HIDDEN __libcpp_refstring {
-#ifdef __clang__
-    const char *__imp_ __attribute__((__unused__)); // only clang emits a warning
-#else
-    const char *__imp_;
-#endif
+    const char *__imp_ _LIBCPP_UNUSED;
 };
 _LIBCPP_END_NAMESPACE_STD
 #endif
diff --git a/include/stdio.h b/include/stdio.h
deleted file mode 100644
index 56fb2d8..0000000
--- a/include/stdio.h
+++ /dev/null
@@ -1,127 +0,0 @@
-// -*- C++ -*-
-//===---------------------------- stdio.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(__need_FILE) || defined(__need___FILE)
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stdio.h>
-
-#elif !defined(_LIBCPP_STDIO_H)
-#define _LIBCPP_STDIO_H
-
-/*
-    stdio.h synopsis
-
-Macros:
-
-    BUFSIZ
-    EOF
-    FILENAME_MAX
-    FOPEN_MAX
-    L_tmpnam
-    NULL
-    SEEK_CUR
-    SEEK_END
-    SEEK_SET
-    TMP_MAX
-    _IOFBF
-    _IOLBF
-    _IONBF
-    stderr
-    stdin
-    stdout
-
-Types:
-
-FILE
-fpos_t
-size_t
-
-int remove(const char* filename);
-int rename(const char* old, const char* new);
-FILE* tmpfile(void);
-char* tmpnam(char* s);
-int fclose(FILE* stream);
-int fflush(FILE* stream);
-FILE* fopen(const char* restrict filename, const char* restrict mode);
-FILE* freopen(const char* restrict filename, const char * restrict mode,
-              FILE * restrict stream);
-void setbuf(FILE* restrict stream, char* restrict buf);
-int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size);
-int fprintf(FILE* restrict stream, const char* restrict format, ...);
-int fscanf(FILE* restrict stream, const char * restrict format, ...);
-int printf(const char* restrict format, ...);
-int scanf(const char* restrict format, ...);
-int snprintf(char* restrict s, size_t n, const char* restrict format, ...);    // C99
-int sprintf(char* restrict s, const char* restrict format, ...);
-int sscanf(const char* restrict s, const char* restrict format, ...);
-int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg);
-int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg);  // C99
-int vprintf(const char* restrict format, va_list arg);
-int vscanf(const char* restrict format, va_list arg);                          // C99
-int vsnprintf(char* restrict s, size_t n, const char* restrict format,         // C99
-              va_list arg);
-int vsprintf(char* restrict s, const char* restrict format, va_list arg);
-int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99
-int fgetc(FILE* stream);
-char* fgets(char* restrict s, int n, FILE* restrict stream);
-int fputc(int c, FILE* stream);
-int fputs(const char* restrict s, FILE* restrict stream);
-int getc(FILE* stream);
-int getchar(void);
-char* gets(char* s);  // removed in C++14
-int putc(int c, FILE* stream);
-int putchar(int c);
-int puts(const char* s);
-int ungetc(int c, FILE* stream);
-size_t fread(void* restrict ptr, size_t size, size_t nmemb,
-             FILE* restrict stream);
-size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb,
-              FILE* restrict stream);
-int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
-int fseek(FILE* stream, long offset, int whence);
-int fsetpos(FILE*stream, const fpos_t* pos);
-long ftell(FILE* stream);
-void rewind(FILE* stream);
-void clearerr(FILE* stream);
-int feof(FILE* stream);
-int ferror(FILE* stream);
-void perror(const char* s);
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stdio.h>
-
-#ifdef __cplusplus
-
-// snprintf
-#if defined(_LIBCPP_MSVCRT)
-extern "C++" {
-#include "support/win32/support.h"
-}
-#endif
-
-#undef getc
-#undef putc
-#undef clearerr
-#undef feof
-#undef ferror
-
-#endif
-
-#endif  // _LIBCPP_STDIO_H
diff --git a/include/stdlib.h b/include/stdlib.h
deleted file mode 100644
index 12fd676..0000000
--- a/include/stdlib.h
+++ /dev/null
@@ -1,130 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- stdlib.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(__need_malloc_and_calloc)
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stdlib.h>
-
-#elif !defined(_LIBCPP_STDLIB_H)
-#define _LIBCPP_STDLIB_H
-
-/*
-    stdlib.h synopsis
-
-Macros:
-
-    EXIT_FAILURE
-    EXIT_SUCCESS
-    MB_CUR_MAX
-    NULL
-    RAND_MAX
-
-Types:
-
-    size_t
-    div_t
-    ldiv_t
-    lldiv_t                                                               // C99
-
-double    atof (const char* nptr);
-int       atoi (const char* nptr);
-long      atol (const char* nptr);
-long long atoll(const char* nptr);                                        // C99
-double             strtod  (const char* restrict nptr, char** restrict endptr);
-float              strtof  (const char* restrict nptr, char** restrict endptr); // C99
-long double        strtold (const char* restrict nptr, char** restrict endptr); // C99
-long               strtol  (const char* restrict nptr, char** restrict endptr, int base);
-long long          strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
-unsigned long      strtoul (const char* restrict nptr, char** restrict endptr, int base);
-unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
-int rand(void);
-void srand(unsigned int seed);
-void* calloc(size_t nmemb, size_t size);
-void free(void* ptr);
-void* malloc(size_t size);
-void* realloc(void* ptr, size_t size);
-void abort(void);
-int atexit(void (*func)(void));
-void exit(int status);
-void _Exit(int status);
-char* getenv(const char* name);
-int system(const char* string);
-void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
-              int (*compar)(const void *, const void *));
-void qsort(void* base, size_t nmemb, size_t size,
-           int (*compar)(const void *, const void *));
-int         abs(      int j);
-long        abs(     long j);
-long long   abs(long long j);                                             // C++0X
-long       labs(     long j);
-long long llabs(long long j);                                             // C99
-div_t     div(      int numer,       int denom);
-ldiv_t    div(     long numer,      long denom);
-lldiv_t   div(long long numer, long long denom);                          // C++0X
-ldiv_t   ldiv(     long numer,      long denom);
-lldiv_t lldiv(long long numer, long long denom);                          // C99
-int mblen(const char* s, size_t n);
-int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
-int wctomb(char* s, wchar_t wchar);
-size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
-size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
-int at_quick_exit(void (*func)(void))                                     // C++11
-void quick_exit(int status);                                              // C++11
-void *aligned_alloc(size_t alignment, size_t size);                       // C11
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <stdlib.h>
-
-#ifdef __cplusplus
-
-extern "C++" {
-
-#ifdef _LIBCPP_MSVCRT
-#include "support/win32/locale_win32.h"
-#endif // _LIBCPP_MSVCRT
-
-#undef abs
-#undef div
-#undef labs
-#undef ldiv
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef llabs
-#undef lldiv
-#endif
-
-// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
-inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-
-inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
-
-}  // extern "C++"
-
-#endif  // __cplusplus
-
-#endif  // _LIBCPP_STDLIB_H
diff --git a/include/string b/include/string
index 786735f..2c677ce 100644
--- a/include/string
+++ b/include/string
@@ -98,10 +98,8 @@
     basic_string(const basic_string& str);
     basic_string(basic_string&& str)
         noexcept(is_nothrow_move_constructible<allocator_type>::value);
-    basic_string(const basic_string& str, size_type pos,
+    basic_string(const basic_string& str, size_type pos, size_type n = npos,
                  const allocator_type& a = allocator_type());
-    basic_string(const basic_string& str, size_type pos, size_type n,
-                 const Allocator& a = Allocator());             
     basic_string(const value_type* s, const allocator_type& a = allocator_type());
     basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
     basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
@@ -117,8 +115,8 @@
     basic_string& operator=(const basic_string& str);
     basic_string& operator=(basic_string&& str)
         noexcept(
-             allocator_type::propagate_on_container_move_assignment::value ||
-             allocator_type::is_always_equal::value ); // C++17
+             allocator_type::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value);
     basic_string& operator=(const value_type* s);
     basic_string& operator=(value_type c);
     basic_string& operator=(initializer_list<value_type>);
@@ -227,7 +225,6 @@
 
     const value_type* c_str() const noexcept;
     const value_type* data() const noexcept;
-          value_type* data()       noexcept;   // C++17
 
     allocator_type get_allocator() const noexcept;
 
@@ -520,14 +517,10 @@
         {return __c1 < __c2;}
 
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static size_t           length(const char_type* __s);
-    _LIBCPP_INLINE_VISIBILITY
     static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
     static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
     static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
@@ -557,7 +550,7 @@
 }
 
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 char_traits<_CharT>::length(const char_type* __s)
 {
@@ -568,7 +561,7 @@
 }
 
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const _CharT*
 char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
 {
@@ -602,7 +595,7 @@
 }
 
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _CharT*
 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -614,7 +607,7 @@
 }
 
 template <class _CharT>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _CharT*
 char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
 {
@@ -733,17 +726,11 @@
     static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
-    _LIBCPP_INLINE_VISIBILITY
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static size_t           length(const char_type* __s);
-    _LIBCPP_INLINE_VISIBILITY
     static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
     static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
@@ -758,7 +745,7 @@
         {return int_type(0xFFFF);}
 };
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 int
 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -772,7 +759,7 @@
     return 0;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 char_traits<char16_t>::length(const char_type* __s)
 {
@@ -782,7 +769,7 @@
     return __len;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const char16_t*
 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
 {
@@ -795,7 +782,7 @@
     return 0;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char16_t*
 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -815,7 +802,7 @@
     return __r;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char16_t*
 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -826,7 +813,7 @@
     return __r;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char16_t*
 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
 {
@@ -852,17 +839,11 @@
     static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
         {return __c1 < __c2;}
 
-    _LIBCPP_INLINE_VISIBILITY
     static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static size_t           length(const char_type* __s);
-    _LIBCPP_INLINE_VISIBILITY
     static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
     static char_type*       assign(char_type* __s, size_t __n, char_type __a);
 
     static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
@@ -877,7 +858,7 @@
         {return int_type(0xFFFFFFFF);}
 };
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 int
 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -891,7 +872,7 @@
     return 0;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 size_t
 char_traits<char32_t>::length(const char_type* __s)
 {
@@ -901,7 +882,7 @@
     return __len;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const char32_t*
 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
 {
@@ -914,7 +895,7 @@
     return 0;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char32_t*
 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -934,7 +915,7 @@
     return __r;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char32_t*
 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
 {
@@ -945,7 +926,7 @@
     return __r;
 }
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 char32_t*
 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
 {
@@ -961,7 +942,7 @@
 
 // __str_find
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find(const _CharT *__p, _SizeT __sz, 
              _CharT __c, _SizeT __pos) _NOEXCEPT
 {
@@ -974,7 +955,7 @@
 }
 
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find(const _CharT *__p, _SizeT __sz, 
        const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
 {
@@ -985,7 +966,7 @@
     const _CharT* __r = 
         _VSTD::__search(__p + __pos, __p + __sz,
                         __s, __s + __n, _Traits::eq,
-                        random_access_iterator_tag(), random_access_iterator_tag()).first;
+                        random_access_iterator_tag(), random_access_iterator_tag());
     if (__r == __p + __sz)
         return __npos;
     return static_cast<_SizeT>(__r - __p);
@@ -995,7 +976,7 @@
 // __str_rfind
 
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_rfind(const _CharT *__p, _SizeT __sz, 
               _CharT __c, _SizeT __pos) _NOEXCEPT
 {
@@ -1014,7 +995,7 @@
 }
 
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_rfind(const _CharT *__p, _SizeT __sz, 
         const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
 {
@@ -1033,7 +1014,7 @@
 
 // __str_find_first_of
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find_first_of(const _CharT *__p, _SizeT __sz,
                 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
 {
@@ -1049,7 +1030,7 @@
 
 // __str_find_last_of
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 
 __str_find_last_of(const _CharT *__p, _SizeT __sz,
                const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
     {
@@ -1072,7 +1053,7 @@
 
 // __str_find_first_not_of
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
                     const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
 {
@@ -1088,7 +1069,7 @@
 
 
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
                           _CharT __c, _SizeT __pos) _NOEXCEPT
 {
@@ -1105,7 +1086,7 @@
 
 // __str_find_last_not_of
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
                    const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
 {
@@ -1121,7 +1102,7 @@
 
 
 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
-inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
                          _CharT __c, _SizeT __pos) _NOEXCEPT
 {
@@ -1204,31 +1185,7 @@
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
 
-#ifdef _LIBCPP_NO_EXCEPTIONS
-template <class _Iter>
-struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
-#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
-template <class _Iter>
-struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
-#else
-template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
-struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
-    noexcept(++(declval<_Iter&>())) && 
-    is_nothrow_assignable<_Iter&, _Iter>::value && 
-    noexcept(declval<_Iter>() == declval<_Iter>()) && 
-    noexcept(*declval<_Iter>())
-)) {};
-
-template <class _Iter> 
-struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
-#endif
-
-
-template <class _Iter>
-struct __libcpp_string_gets_noexcept_iterator
-    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
-
-#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
 
 template <class _CharT, size_t = sizeof(_CharT)>
 struct __padding
@@ -1241,7 +1198,7 @@
 {
 };
 
-#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
 
 template<class _CharT, class _Traits, class _Allocator>
 class _LIBCPP_TYPE_VIS_ONLY basic_string
@@ -1277,7 +1234,7 @@
 
 private:
 
-#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
 
     struct __long
     {
@@ -1337,7 +1294,7 @@
         value_type __data_[__min_cap];
     };
 
-#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
 
     union __ulx{__long __lx; __short __lxx;};
 
@@ -1399,10 +1356,7 @@
     basic_string(size_type __n, value_type __c);
     _LIBCPP_INLINE_VISIBILITY
     basic_string(size_type __n, value_type __c, const allocator_type& __a);
-    basic_string(const basic_string& __str, size_type __pos, size_type __n,
-                 const allocator_type& __a = allocator_type());
-    _LIBCPP_INLINE_VISIBILITY
-    basic_string(const basic_string& __str, size_type __pos,
+    basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
                  const allocator_type& __a = allocator_type());
     template<class _InputIterator>
         _LIBCPP_INLINE_VISIBILITY
@@ -1423,7 +1377,8 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     basic_string& operator=(basic_string&& __str)
-        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
+        _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
+                   is_nothrow_move_assignable<allocator_type>::value);
 #endif
     _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
     basic_string& operator=(value_type __c);
@@ -1490,8 +1445,7 @@
     _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
-        {return (__is_long() ? __get_long_cap()
-                             : static_cast<size_type>(__min_cap)) - 1;}
+        {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
 
     void resize(size_type __n, value_type __c);
     _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
@@ -1525,16 +1479,15 @@
     template<class _InputIterator>
         typename enable_if
         <
-            __is_exactly_input_iterator<_InputIterator>::value
-                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
             basic_string&
         >::type
         append(_InputIterator __first, _InputIterator __last);
     template<class _ForwardIterator>
         typename enable_if
         <
-            __is_forward_iterator<_ForwardIterator>::value
-                && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+            __is_forward_iterator<_ForwardIterator>::value,
             basic_string&
         >::type
         append(_ForwardIterator __first, _ForwardIterator __last);
@@ -1552,11 +1505,10 @@
     _LIBCPP_INLINE_VISIBILITY const_reference back() const;
 
     _LIBCPP_INLINE_VISIBILITY
-    basic_string& assign(const basic_string& __str) { return *this = __str; }
+    basic_string& assign(const basic_string& __str);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     basic_string& assign(basic_string&& str)
-        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
         {*this = _VSTD::move(str); return *this;}
 #endif
     basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
@@ -1566,16 +1518,15 @@
     template<class _InputIterator>
         typename enable_if
         <
-           __is_exactly_input_iterator<_InputIterator>::value
-                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
             basic_string&
         >::type
         assign(_InputIterator __first, _InputIterator __last);
     template<class _ForwardIterator>
         typename enable_if
         <
-            __is_forward_iterator<_ForwardIterator>::value
-                 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+            __is_forward_iterator<_ForwardIterator>::value,
             basic_string&
         >::type
         assign(_ForwardIterator __first, _ForwardIterator __last);
@@ -1596,16 +1547,15 @@
     template<class _InputIterator>
         typename enable_if
         <
-           __is_exactly_input_iterator<_InputIterator>::value
-                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
             iterator
         >::type
         insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
     template<class _ForwardIterator>
         typename enable_if
         <
-            __is_forward_iterator<_ForwardIterator>::value
-                 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+            __is_forward_iterator<_ForwardIterator>::value,
             iterator
         >::type
         insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
@@ -1665,10 +1615,6 @@
     const value_type* c_str() const _NOEXCEPT {return data();}
     _LIBCPP_INLINE_VISIBILITY
     const value_type* data() const _NOEXCEPT  {return _VSTD::__to_raw_pointer(__get_pointer());}
-#if _LIBCPP_STD_VER > 14
-    _LIBCPP_INLINE_VISIBILITY
-    value_type* data()             _NOEXCEPT  {return _VSTD::__to_raw_pointer(__get_pointer());}
-#endif
 
     _LIBCPP_INLINE_VISIBILITY
     allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
@@ -1751,7 +1697,7 @@
     const allocator_type& __alloc() const _NOEXCEPT
         {return __r_.second();}
 
-#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_short_size(size_type __s) _NOEXCEPT
@@ -1769,7 +1715,7 @@
         {return __r_.first().__s.__size_;}
 #   endif
 
-#else  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#else  // _LIBCPP_ALTERNATE_STRING_LAYOUT
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_short_size(size_type __s) _NOEXCEPT
@@ -1787,7 +1733,7 @@
         {return __r_.first().__s.__size_ >> 1;}
 #   endif
 
-#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_long_size(size_type __s) _NOEXCEPT
@@ -1839,11 +1785,11 @@
     template <size_type __a> static
         _LIBCPP_INLINE_VISIBILITY
         size_type __align_it(size_type __s) _NOEXCEPT
-            {return (__s + (__a-1)) & ~(__a-1);}
+            {return __s + (__a-1) & ~(__a-1);}
     enum {__alignment = 16};
     static _LIBCPP_INLINE_VISIBILITY
     size_type __recommend(size_type __s) _NOEXCEPT
-        {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
+        {return (__s < __min_cap ? __min_cap :
                  __align_it<sizeof(value_type) < __alignment ?
                             __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
 
@@ -1854,7 +1800,8 @@
     template <class _InputIterator>
     typename enable_if
     <
-        __is_exactly_input_iterator<_InputIterator>::value,
+         __is_input_iterator  <_InputIterator>::value &&
+        !__is_forward_iterator<_InputIterator>::value,
         void
     >::type
     __init(_InputIterator __first, _InputIterator __last);
@@ -1898,16 +1845,11 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
-    void __move_assign(basic_string& __str, false_type)
-        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
+    void __move_assign(basic_string& __str, false_type);
     _LIBCPP_INLINE_VISIBILITY
     void __move_assign(basic_string& __str, true_type)
-#if _LIBCPP_STD_VER > 14
-        _NOEXCEPT;
-#else
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
 #endif
-#endif
 
     _LIBCPP_INLINE_VISIBILITY
     void
@@ -2228,25 +2170,11 @@
 }
 
 template <class _CharT, class _Traits, class _Allocator>
-inline _LIBCPP_INLINE_VISIBILITY
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
-                                                        const allocator_type& __a)
-    : __r_(__a)
-{
-    size_type __str_sz = __str.size();
-    if (__pos > __str_sz)
-        this->__throw_out_of_range();
-    __init(__str.data() + __pos, __str_sz - __pos);
-#if _LIBCPP_DEBUG_LEVEL >= 2
-    __get_db()->__insert_c(this);
-#endif
-}
-
-template <class _CharT, class _Traits, class _Allocator>
 template <class _InputIterator>
 typename enable_if
 <
-    __is_exactly_input_iterator<_InputIterator>::value,
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
     void
 >::type
 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
@@ -2491,7 +2419,7 @@
     if (this != &__str)
     {
         __copy_assign_alloc(__str);
-        assign(__str.data(), __str.size());
+        assign(__str);
     }
     return *this;
 }
@@ -2502,7 +2430,6 @@
 inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
-    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
 {
     if (__alloc() != __str.__alloc())
         assign(__str);
@@ -2514,11 +2441,7 @@
 inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
-#if _LIBCPP_STD_VER > 14
-    _NOEXCEPT
-#else
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
-#endif
 {
     clear();
     shrink_to_fit();
@@ -2531,7 +2454,8 @@
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
-    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
+    _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
+               is_nothrow_move_assignable<allocator_type>::value)
 {
     __move_assign(__str, integral_constant<bool,
           __alloc_traits::propagate_on_container_move_assignment::value>());
@@ -2544,14 +2468,15 @@
 template<class _InputIterator>
 typename enable_if
 <
-     __is_exactly_input_iterator <_InputIterator>::value
-          || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
 >::type
 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
 {
-    basic_string __temp(__first, __last, __alloc());
-    assign(__temp.data(), __temp.size());
+    clear();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
     return *this;
 }
 
@@ -2559,8 +2484,7 @@
 template<class _ForwardIterator>
 typename enable_if
 <
-    __is_forward_iterator<_ForwardIterator>::value
-         && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+    __is_forward_iterator<_ForwardIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
 >::type
 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
@@ -2583,6 +2507,14 @@
 }
 
 template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
+{
+    return assign(__str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
 basic_string<_CharT, _Traits, _Allocator>&
 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
 {
@@ -2685,14 +2617,14 @@
 template<class _InputIterator>
 typename enable_if
 <
-    __is_exactly_input_iterator<_InputIterator>::value
-             || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
 >::type
 basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
 {
-	basic_string __temp (__first, __last, __alloc());
-	append(__temp.data(), __temp.size());
+    for (; __first != __last; ++__first)
+        push_back(*__first);
     return *this;
 }
 
@@ -2700,8 +2632,7 @@
 template<class _ForwardIterator>
 typename enable_if
 <
-    __is_forward_iterator<_ForwardIterator>::value
-          && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+    __is_forward_iterator<_ForwardIterator>::value,
     basic_string<_CharT, _Traits, _Allocator>&
 >::type
 basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
@@ -2817,9 +2748,9 @@
 template<class _InputIterator>
 typename enable_if
 <
-   __is_exactly_input_iterator<_InputIterator>::value
-        || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
-   typename basic_string<_CharT, _Traits, _Allocator>::iterator
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    typename basic_string<_CharT, _Traits, _Allocator>::iterator
 >::type
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
 {
@@ -2828,16 +2759,24 @@
         "string::insert(iterator, range) called with an iterator not"
         " referring to this string");
 #endif
-    basic_string __temp(__first, __last, __alloc());
-    return insert(__pos, __temp.data(), __temp.data() + __temp.size());
+    size_type __old_sz = size();
+    difference_type __ip = __pos - begin();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+    pointer __p = __get_pointer();
+    _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator(this, __p + __ip);
+#else
+    return iterator(__p + __ip);
+#endif
 }
 
 template <class _CharT, class _Traits, class _Allocator>
 template<class _ForwardIterator>
 typename enable_if
 <
-    __is_forward_iterator<_ForwardIterator>::value
-        && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
+    __is_forward_iterator<_ForwardIterator>::value,
     typename basic_string<_CharT, _Traits, _Allocator>::iterator
 >::type
 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
@@ -3040,8 +2979,22 @@
 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
                                                    _InputIterator __j1, _InputIterator __j2)
 {
-    basic_string __temp(__j1, __j2, __alloc());
-    return this->replace(__i1, __i2, __temp);
+    for (; true; ++__i1, ++__j1)
+    {
+        if (__i1 == __i2)
+        {
+            if (__j1 != __j2)
+                insert(__i1, __j1, __j2);
+            break;
+        }
+        if (__j1 == __j2)
+        {
+            erase(__i1, __i2);
+            break;
+        }
+        traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
+    }
+    return *this;
 }
 
 template <class _CharT, class _Traits, class _Allocator>
@@ -3834,11 +3787,7 @@
 operator==(const _CharT* __lhs,
            const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
 {
-    typedef basic_string<_CharT, _Traits, _Allocator> _String;
-    _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
-    size_t __lhs_len = _Traits::length(__lhs);
-    if (__lhs_len != __rhs.size()) return false;
-    return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
+    return __rhs.compare(__lhs) == 0;
 }
 
 template<class _CharT, class _Traits, class _Allocator>
@@ -3847,11 +3796,7 @@
 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
            const _CharT* __rhs) _NOEXCEPT
 {
-    typedef basic_string<_CharT, _Traits, _Allocator> _String;
-    _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
-    size_t __rhs_len = _Traits::length(__rhs);
-    if (__rhs_len != __lhs.size()) return false;
-    return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
+    return __lhs.compare(__rhs) == 0;
 }
 
 // operator!=
diff --git a/include/string.h b/include/string.h
deleted file mode 100644
index a1ce56c..0000000
--- a/include/string.h
+++ /dev/null
@@ -1,110 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- string.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_STRING_H
-#define _LIBCPP_STRING_H
-
-/*
-    string.h synopsis
-
-Macros:
-
-    NULL
-
-Types:
-
-    size_t
-
-void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
-void* memmove(void* s1, const void* s2, size_t n);
-char* strcpy (char* restrict s1, const char* restrict s2);
-char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
-char* strcat (char* restrict s1, const char* restrict s2);
-char* strncat(char* restrict s1, const char* restrict s2, size_t n);
-int memcmp(const void* s1, const void* s2, size_t n);
-int strcmp (const char* s1, const char* s2);
-int strncmp(const char* s1, const char* s2, size_t n);
-int strcoll(const char* s1, const char* s2);
-size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
-const void* memchr(const void* s, int c, size_t n);
-      void* memchr(      void* s, int c, size_t n);
-const char* strchr(const char* s, int c);
-      char* strchr(      char* s, int c);
-size_t strcspn(const char* s1, const char* s2);
-const char* strpbrk(const char* s1, const char* s2);
-      char* strpbrk(      char* s1, const char* s2);
-const char* strrchr(const char* s, int c);
-      char* strrchr(      char* s, int c);
-size_t strspn(const char* s1, const char* s2);
-const char* strstr(const char* s1, const char* s2);
-      char* strstr(      char* s1, const char* s2);
-char* strtok(char* restrict s1, const char* restrict s2);
-void* memset(void* s, int c, size_t n);
-char* strerror(int errnum);
-size_t strlen(const char* s);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <string.h>
-
-// MSVCRT, GNU libc and its derivates may already have the correct prototype in
-// <string.h>. This macro can be defined by users if their C library provides
-// the right signature.
-#if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \
-    defined(__sun__) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
-#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
-#endif
-
-#if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
-extern "C++" {
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strpbrk(const char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strpbrk(      char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strrchr(const char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strrchr(      char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strstr(const char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strstr(      char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
-}
-#endif
-
-#endif  // _LIBCPP_STRING_H
diff --git a/include/support/android/locale_bionic.h b/include/support/android/locale_bionic.h
index 1365563..3a020da 100644
--- a/include/support/android/locale_bionic.h
+++ b/include/support/android/locale_bionic.h
@@ -24,8 +24,8 @@
 }
 #endif
 
-#include <support/xlocale/__posix_l_fallback.h>
-#include <support/xlocale/__strtonum_fallback.h>
+// Share implementation with Newlib
+#include <support/xlocale/xlocale.h>
 
 #endif // defined(__ANDROID__)
 #endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H
diff --git a/include/support/ibm/locale_mgmt_aix.h b/include/support/ibm/locale_mgmt_aix.h
deleted file mode 100644
index e3b7a78..0000000
--- a/include/support/ibm/locale_mgmt_aix.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// -*- C++ -*-
-//===------------------- support/ibm/locale_mgmt_aix.h --------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
-#define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
-
-#if defined(_AIX)
-#include "cstdlib"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if !defined(_AIX71)
-// AIX 7.1 and higher has these definitions.  Definitions and stubs
-// are provied here as a temporary workaround on AIX 6.1.
-
-#define LC_COLLATE_MASK         1
-#define LC_CTYPE_MASK           2
-#define LC_MESSAGES_MASK        4
-#define LC_MONETARY_MASK        8
-#define LC_NUMERIC_MASK         16
-#define LC_TIME_MASK            32
-#define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
-                                 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
-                                 LC_NUMERIC_MASK | LC_TIME_MASK)
-
-typedef void* locale_t;
-
-// The following are stubs.  They are not supported on AIX 6.1.
-static inline
-locale_t newlocale(int category_mask, const char *locale, locale_t base)
-{
-  _LC_locale_t *newloc, *loc;
-  if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
-  {
-    errno = EINVAL;
-    return (locale_t)0;
-  }
-  if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
-  {
-    errno = ENOMEM;
-    return (locale_t)0;
-  }
-  if (!base)
-    base = (_LC_locale_t *)__xopen_locale("C");
-  memcpy(newloc, base, sizeof (_LC_locale_t));
-  if (category_mask & LC_COLLATE_MASK)
-    newloc->lc_collate = loc->lc_collate;
-  if (category_mask & LC_CTYPE_MASK)
-    newloc->lc_ctype = loc->lc_ctype;
-  //if (category_mask & LC_MESSAGES_MASK)
-  //  newloc->lc_messages = loc->lc_messages;
-  if (category_mask & LC_MONETARY_MASK)
-    newloc->lc_monetary = loc->lc_monetary;
-  if (category_mask & LC_TIME_MASK)
-    newloc->lc_time = loc->lc_time;
-  if (category_mask & LC_NUMERIC_MASK)
-    newloc->lc_numeric = loc->lc_numeric;
-  return (locale_t)newloc;
-}
-static inline
-void freelocale(locale_t locobj)
-{
-  free(locobj);
-}
-static inline
-locale_t uselocale(locale_t newloc)
-{
-  return (locale_t)0;
-}
-#endif // !defined(_AIX71)
-
-#ifdef __cplusplus
-}
-#endif
-#endif // defined(_AIX)
-#endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
diff --git a/include/support/ibm/xlocale.h b/include/support/ibm/xlocale.h
index f39c0ba..8d99a5c 100644
--- a/include/support/ibm/xlocale.h
+++ b/include/support/ibm/xlocale.h
@@ -10,7 +10,6 @@
 
 #ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
 #define _LIBCPP_SUPPORT_IBM_XLOCALE_H
-#include <support/ibm/locale_mgmt_aix.h>
 
 #if defined(_AIX)
 #include "cstdlib"
@@ -22,6 +21,62 @@
 #if !defined(_AIX71)
 // AIX 7.1 and higher has these definitions.  Definitions and stubs
 // are provied here as a temporary workaround on AIX 6.1.
+
+#define LC_COLLATE_MASK         1
+#define LC_CTYPE_MASK           2
+#define LC_MESSAGES_MASK        4
+#define LC_MONETARY_MASK        8
+#define LC_NUMERIC_MASK         16
+#define LC_TIME_MASK            32
+#define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
+                                 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
+                                 LC_NUMERIC_MASK | LC_TIME_MASK)
+
+typedef void* locale_t;
+
+// The following are stubs.  They are not supported on AIX 6.1.
+static inline
+locale_t newlocale(int category_mask, const char *locale, locale_t base)
+{
+  _LC_locale_t *newloc, *loc;
+  if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
+  {
+    errno = EINVAL;
+    return (locale_t)0;
+  }
+  if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
+  {
+    errno = ENOMEM;
+    return (locale_t)0;
+  }
+  if (!base)
+    base = (_LC_locale_t *)__xopen_locale("C");
+  memcpy(newloc, base, sizeof (_LC_locale_t));
+  if (category_mask & LC_COLLATE_MASK) 
+    newloc->lc_collate = loc->lc_collate;
+  if (category_mask & LC_CTYPE_MASK)
+    newloc->lc_ctype = loc->lc_ctype;
+  //if (category_mask & LC_MESSAGES_MASK)
+  //  newloc->lc_messages = loc->lc_messages;
+  if (category_mask & LC_MONETARY_MASK)
+    newloc->lc_monetary = loc->lc_monetary;
+  if (category_mask & LC_TIME_MASK)
+    newloc->lc_time = loc->lc_time;
+  if (category_mask & LC_NUMERIC_MASK)
+    newloc->lc_numeric = loc->lc_numeric;
+  return (locale_t)newloc; 
+}
+static inline
+void freelocale(locale_t locobj)
+{
+  free(locobj);
+}
+static inline
+locale_t uselocale(locale_t newloc)
+{
+  return (locale_t)0;
+}
+
 static inline
 int isalnum_l(int c, locale_t locale)
 {
diff --git a/include/support/musl/xlocale.h b/include/support/musl/xlocale.h
deleted file mode 100644
index 3e31c99..0000000
--- a/include/support/musl/xlocale.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// -*- C++ -*-
-//===------------------- support/musl/xlocale.h ------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// This adds support for the extended locale functions that are currently
-// missing from the Musl C library.
-//
-// This only works when the specified locale is "C" or "POSIX", but that's
-// about as good as we can do without implementing full xlocale support
-// in Musl.
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_MUSL_XLOCALE_H
-#define _LIBCPP_SUPPORT_MUSL_XLOCALE_H
-
-#include <cstdlib>
-#include <cwchar>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static inline long long strtoll_l(const char *nptr, char **endptr, int base,
-                                  locale_t) {
-  return strtoll(nptr, endptr, base);
-}
-
-static inline unsigned long long strtoull_l(const char *nptr, char **endptr,
-                                            int base, locale_t) {
-  return strtoull(nptr, endptr, base);
-}
-
-static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr,
-                                  int base, locale_t) {
-  return wcstoll(nptr, endptr, base);
-}
-
-static inline unsigned long long wcstoull_l(const wchar_t *nptr,
-                                            wchar_t **endptr, int base,
-                                            locale_t) {
-  return wcstoull(nptr, endptr, base);
-}
-
-static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr,
-                                    locale_t) {
-  return wcstold(nptr, endptr);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _LIBCPP_SUPPORT_MUSL_XLOCALE_H
diff --git a/include/support/newlib/xlocale.h b/include/support/newlib/xlocale.h
index 4e4b23b..d067cf8 100644
--- a/include/support/newlib/xlocale.h
+++ b/include/support/newlib/xlocale.h
@@ -16,9 +16,47 @@
 #include <clocale>
 #include <cwctype>
 #include <ctype.h>
-#include <support/xlocale/__nop_locale_mgmt.h>
-#include <support/xlocale/__posix_l_fallback.h>
-#include <support/xlocale/__strtonum_fallback.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Patch over newlib's lack of extended locale support
+typedef void *locale_t;
+static inline locale_t duplocale(locale_t) {
+  return NULL;
+}
+
+static inline void freelocale(locale_t) {
+}
+
+static inline locale_t newlocale(int, const char *, locale_t) {
+  return NULL;
+}
+
+static inline locale_t uselocale(locale_t) {
+  return NULL;
+}
+
+#define LC_COLLATE_MASK  (1 << LC_COLLATE)
+#define LC_CTYPE_MASK    (1 << LC_CTYPE)
+#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
+#define LC_MONETARY_MASK (1 << LC_MONETARY)
+#define LC_NUMERIC_MASK  (1 << LC_NUMERIC)
+#define LC_TIME_MASK     (1 << LC_TIME)
+#define LC_ALL_MASK (LC_COLLATE_MASK|\
+                     LC_CTYPE_MASK|\
+                     LC_MONETARY_MASK|\
+                     LC_NUMERIC_MASK|\
+                     LC_TIME_MASK|\
+                     LC_MESSAGES_MASK)
+
+// Share implementation with Android's Bionic
+#include <support/xlocale/xlocale.h>
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
 
 #endif // _NEWLIB_VERSION
 
diff --git a/include/support/win32/locale_mgmt_win32.h b/include/support/win32/locale_mgmt_win32.h
deleted file mode 100644
index b3316d6..0000000
--- a/include/support/win32/locale_mgmt_win32.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// -*- C++ -*-
-//===----------------- support/win32/locale_mgmt_win32.h ------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
-#define _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
-
-#include <xlocinfo.h> // _locale_t
-#define locale_t _locale_t
-#define LC_COLLATE_MASK _M_COLLATE
-#define LC_CTYPE_MASK _M_CTYPE
-#define LC_MONETARY_MASK _M_MONETARY
-#define LC_NUMERIC_MASK _M_NUMERIC
-#define LC_TIME_MASK _M_TIME
-#define LC_MESSAGES_MASK _M_MESSAGES
-#define LC_ALL_MASK (  LC_COLLATE_MASK \
-                     | LC_CTYPE_MASK \
-                     | LC_MESSAGES_MASK \
-                     | LC_MONETARY_MASK \
-                     | LC_NUMERIC_MASK \
-                     | LC_TIME_MASK )
-#define freelocale _free_locale
-// FIXME: base currently unused. Needs manual work to construct the new locale
-locale_t newlocale( int mask, const char * locale, locale_t base );
-locale_t uselocale( locale_t newloc );
-
-#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
diff --git a/include/support/win32/locale_win32.h b/include/support/win32/locale_win32.h
index 7f3710e..f728d23 100644
--- a/include/support/win32/locale_win32.h
+++ b/include/support/win32/locale_win32.h
@@ -15,10 +15,26 @@
 extern "C" unsigned short  __declspec(dllimport) _ctype[];
 
 #include "support/win32/support.h"
-#include "support/win32/locale_mgmt_win32.h"
 #include <stdio.h>
 #include <memory>
-
+#include <xlocinfo.h> // _locale_t
+#define locale_t _locale_t
+#define LC_COLLATE_MASK _M_COLLATE
+#define LC_CTYPE_MASK _M_CTYPE
+#define LC_MONETARY_MASK _M_MONETARY
+#define LC_NUMERIC_MASK _M_NUMERIC
+#define LC_TIME_MASK _M_TIME
+#define LC_MESSAGES_MASK _M_MESSAGES
+#define LC_ALL_MASK (  LC_COLLATE_MASK \
+                     | LC_CTYPE_MASK \
+                     | LC_MESSAGES_MASK \
+                     | LC_MONETARY_MASK \
+                     | LC_NUMERIC_MASK \
+                     | LC_TIME_MASK )
+#define freelocale _free_locale
+// FIXME: base currently unused. Needs manual work to construct the new locale
+locale_t newlocale( int mask, const char * locale, locale_t base );
+locale_t uselocale( locale_t newloc );
 lconv *localeconv_l( locale_t loc );
 size_t mbrlen_l( const char *__restrict s, size_t n,
                  mbstate_t *__restrict ps, locale_t loc);
diff --git a/include/support/xlocale/__nop_locale_mgmt.h b/include/support/xlocale/__nop_locale_mgmt.h
deleted file mode 100644
index 0d3f23a..0000000
--- a/include/support/xlocale/__nop_locale_mgmt.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// -*- C++ -*-
-//===------------  support/xlocale/__nop_locale_mgmt.h -----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H
-#define _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Patch over lack of extended locale support
-typedef void *locale_t;
-static inline locale_t duplocale(locale_t) {
-  return NULL;
-}
-
-static inline void freelocale(locale_t) {
-}
-
-static inline locale_t newlocale(int, const char *, locale_t) {
-  return NULL;
-}
-
-static inline locale_t uselocale(locale_t) {
-  return NULL;
-}
-
-#define LC_COLLATE_MASK  (1 << LC_COLLATE)
-#define LC_CTYPE_MASK    (1 << LC_CTYPE)
-#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
-#define LC_MONETARY_MASK (1 << LC_MONETARY)
-#define LC_NUMERIC_MASK  (1 << LC_NUMERIC)
-#define LC_TIME_MASK     (1 << LC_TIME)
-#define LC_ALL_MASK (LC_COLLATE_MASK|\
-                     LC_CTYPE_MASK|\
-                     LC_MONETARY_MASK|\
-                     LC_NUMERIC_MASK|\
-                     LC_TIME_MASK|\
-                     LC_MESSAGES_MASK)
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // _LIBCPP_SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H
diff --git a/include/support/xlocale/__posix_l_fallback.h b/include/support/xlocale/__posix_l_fallback.h
deleted file mode 100644
index 8bf9567..0000000
--- a/include/support/xlocale/__posix_l_fallback.h
+++ /dev/null
@@ -1,165 +0,0 @@
-// -*- C++ -*-
-//===--------------- support/xlocale/__posix_l_fallback.h -----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// These are reimplementations of some extended locale functions ( *_l ) that
-// are normally part of POSIX.  This shared implementation provides parts of the
-// extended locale support for libc's that normally don't have any (like
-// Android's bionic and Newlib).
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
-#define _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-inline _LIBCPP_ALWAYS_INLINE int isalnum_l(int c, locale_t) {
-  return ::isalnum(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isalpha_l(int c, locale_t) {
-  return ::isalpha(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isblank_l(int c, locale_t) {
-  return ::isblank(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iscntrl_l(int c, locale_t) {
-  return ::iscntrl(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isdigit_l(int c, locale_t) {
-  return ::isdigit(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isgraph_l(int c, locale_t) {
-  return ::isgraph(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int islower_l(int c, locale_t) {
-  return ::islower(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isprint_l(int c, locale_t) {
-  return ::isprint(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int ispunct_l(int c, locale_t) {
-  return ::ispunct(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isspace_l(int c, locale_t) {
-  return ::isspace(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isupper_l(int c, locale_t) {
-  return ::isupper(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int isxdigit_l(int c, locale_t) {
-  return ::isxdigit(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswalnum_l(wint_t c, locale_t) {
-  return ::iswalnum(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswalpha_l(wint_t c, locale_t) {
-  return ::iswalpha(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswblank_l(wint_t c, locale_t) {
-  return ::iswblank(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswcntrl_l(wint_t c, locale_t) {
-  return ::iswcntrl(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswdigit_l(wint_t c, locale_t) {
-  return ::iswdigit(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswgraph_l(wint_t c, locale_t) {
-  return ::iswgraph(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswlower_l(wint_t c, locale_t) {
-  return ::iswlower(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswprint_l(wint_t c, locale_t) {
-  return ::iswprint(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswpunct_l(wint_t c, locale_t) {
-  return ::iswpunct(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswspace_l(wint_t c, locale_t) {
-  return ::iswspace(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswupper_l(wint_t c, locale_t) {
-  return ::iswupper(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int iswxdigit_l(wint_t c, locale_t) {
-  return ::iswxdigit(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int toupper_l(int c, locale_t) {
-  return ::toupper(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int tolower_l(int c, locale_t) {
-  return ::tolower(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int towupper_l(int c, locale_t) {
-  return ::towupper(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int towlower_l(int c, locale_t) {
-  return ::towlower(c);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int strcoll_l(const char *s1, const char *s2,
-                                           locale_t) {
-  return ::strcoll(s1, s2);
-}
-
-inline _LIBCPP_ALWAYS_INLINE size_t strxfrm_l(char *dest, const char *src,
-                                              size_t n, locale_t) {
-  return ::strxfrm(dest, src, n);
-}
-
-inline _LIBCPP_ALWAYS_INLINE size_t strftime_l(char *s, size_t max,
-                                               const char *format,
-                                               const struct tm *tm, locale_t) {
-  return ::strftime(s, max, format, tm);
-}
-
-inline _LIBCPP_ALWAYS_INLINE int wcscoll_l(const wchar_t *ws1,
-                                           const wchar_t *ws2, locale_t) {
-  return ::wcscoll(ws1, ws2);
-}
-
-inline _LIBCPP_ALWAYS_INLINE size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src,
-                                              size_t n, locale_t) {
-  return ::wcsxfrm(dest, src, n);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
diff --git a/include/support/xlocale/__strtonum_fallback.h b/include/support/xlocale/__strtonum_fallback.h
deleted file mode 100644
index b060f75..0000000
--- a/include/support/xlocale/__strtonum_fallback.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// -*- C++ -*-
-//===-------------- support/xlocale/__strtonum_fallback.h -----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// These are reimplementations of some extended locale functions ( *_l ) that
-// aren't part of POSIX.  They are widely available though (GLIBC, BSD, maybe
-// others).  The unifying aspect in this case is that all of these functions
-// convert strings to some numeric type.
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
-#define _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-inline _LIBCPP_ALWAYS_INLINE long double strtold_l(const char *nptr,
-                                                   char **endptr, locale_t) {
-  return ::strtold(nptr, endptr);
-}
-
-inline _LIBCPP_ALWAYS_INLINE long long
-strtoll_l(const char *nptr, char **endptr, int base, locale_t) {
-  return ::strtoll(nptr, endptr, base);
-}
-
-inline _LIBCPP_ALWAYS_INLINE unsigned long long
-strtoull_l(const char *nptr, char **endptr, int base, locale_t) {
-  return ::strtoull(nptr, endptr, base);
-}
-
-inline _LIBCPP_ALWAYS_INLINE long long
-wcstoll_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
-  return ::wcstoll(nptr, endptr, base);
-}
-
-inline _LIBCPP_ALWAYS_INLINE unsigned long long
-wcstoull_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
-  return ::wcstoull(nptr, endptr, base);
-}
-
-inline _LIBCPP_ALWAYS_INLINE long double wcstold_l(const wchar_t *nptr,
-                                                   wchar_t **endptr, locale_t) {
-  return ::wcstold(nptr, endptr);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
diff --git a/include/support/xlocale/xlocale.h b/include/support/xlocale/xlocale.h
index e69de29..99f710e 100644
--- a/include/support/xlocale/xlocale.h
+++ b/include/support/xlocale/xlocale.h
@@ -0,0 +1,194 @@
+// -*- C++ -*-
+//===------------------- support/xlocale/xlocale.h ------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// This is a shared implementation of a shim to provide extended locale support
+// on top of libc's that don't support it (like Android's bionic, and Newlib).
+//
+// The 'illusion' only works when the specified locale is "C" or "POSIX", but
+// that's about as good as we can do without implementing full xlocale support
+// in the underlying libc.
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
+#define _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline int isalnum_l(int c, locale_t) {
+  return isalnum(c);
+}
+
+static inline int isalpha_l(int c, locale_t) {
+  return isalpha(c);
+}
+
+static inline int isblank_l(int c, locale_t) {
+  return isblank(c);
+}
+
+static inline int iscntrl_l(int c, locale_t) {
+  return iscntrl(c);
+}
+
+static inline int isdigit_l(int c, locale_t) {
+  return isdigit(c);
+}
+
+static inline int isgraph_l(int c, locale_t) {
+  return isgraph(c);
+}
+
+static inline int islower_l(int c, locale_t) {
+  return islower(c);
+}
+
+static inline int isprint_l(int c, locale_t) {
+  return isprint(c);
+}
+
+static inline int ispunct_l(int c, locale_t) {
+  return ispunct(c);
+}
+
+static inline int isspace_l(int c, locale_t) {
+  return isspace(c);
+}
+
+static inline int isupper_l(int c, locale_t) {
+  return isupper(c);
+}
+
+static inline int isxdigit_l(int c, locale_t) {
+  return isxdigit(c);
+}
+
+static inline int iswalnum_l(wint_t c, locale_t) {
+  return iswalnum(c);
+}
+
+static inline int iswalpha_l(wint_t c, locale_t) {
+  return iswalpha(c);
+}
+
+static inline int iswblank_l(wint_t c, locale_t) {
+  return iswblank(c);
+}
+
+static inline int iswcntrl_l(wint_t c, locale_t) {
+  return iswcntrl(c);
+}
+
+static inline int iswdigit_l(wint_t c, locale_t) {
+  return iswdigit(c);
+}
+
+static inline int iswgraph_l(wint_t c, locale_t) {
+  return iswgraph(c);
+}
+
+static inline int iswlower_l(wint_t c, locale_t) {
+  return iswlower(c);
+}
+
+static inline int iswprint_l(wint_t c, locale_t) {
+  return iswprint(c);
+}
+
+static inline int iswpunct_l(wint_t c, locale_t) {
+  return iswpunct(c);
+}
+
+static inline int iswspace_l(wint_t c, locale_t) {
+  return iswspace(c);
+}
+
+static inline int iswupper_l(wint_t c, locale_t) {
+  return iswupper(c);
+}
+
+static inline int iswxdigit_l(wint_t c, locale_t) {
+  return iswxdigit(c);
+}
+
+static inline int toupper_l(int c, locale_t) {
+  return toupper(c);
+}
+
+static inline int tolower_l(int c, locale_t) {
+  return tolower(c);
+}
+
+static inline int towupper_l(int c, locale_t) {
+  return towupper(c);
+}
+
+static inline int towlower_l(int c, locale_t) {
+  return towlower(c);
+}
+
+static inline int strcoll_l(const char *s1, const char *s2, locale_t) {
+  return strcoll(s1, s2);
+}
+
+static inline size_t strxfrm_l(char *dest, const char *src, size_t n,
+                               locale_t) {
+  return strxfrm(dest, src, n);
+}
+
+static inline size_t strftime_l(char *s, size_t max, const char *format,
+                                const struct tm *tm, locale_t) {
+  return strftime(s, max, format, tm);
+}
+
+static inline int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t) {
+  return wcscoll(ws1, ws2);
+}
+
+static inline size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n,
+                               locale_t) {
+  return wcsxfrm(dest, src, n);
+}
+
+static inline long double strtold_l(const char *nptr, char **endptr, locale_t) {
+  return strtold(nptr, endptr);
+}
+
+static inline long long strtoll_l(const char *nptr, char **endptr, int base,
+                                  locale_t) {
+  return strtoll(nptr, endptr, base);
+}
+
+static inline unsigned long long strtoull_l(const char *nptr, char **endptr,
+                                            int base, locale_t) {
+  return strtoull(nptr, endptr, base);
+}
+
+static inline long long wcstoll_l(const wchar_t *nptr, wchar_t **endptr,
+                                  int base, locale_t) {
+  return wcstoll(nptr, endptr, base);
+}
+
+static inline unsigned long long wcstoull_l(const wchar_t *nptr,
+                                            wchar_t **endptr, int base,
+                                            locale_t) {
+  return wcstoull(nptr, endptr, base);
+}
+
+static inline long double wcstold_l(const wchar_t *nptr, wchar_t **endptr,
+                                    locale_t) {
+  return wcstold(nptr, endptr);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _LIBCPP_SUPPORT_XLOCALE_XLOCALE_H
diff --git a/include/system_error b/include/system_error
index 134bb32..66bf6d6 100644
--- a/include/system_error
+++ b/include/system_error
@@ -371,7 +371,7 @@
     error_category() _NOEXCEPT;
 #else
     _LIBCPP_ALWAYS_INLINE
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT;
 #endif
 private:
     error_category(const error_category&);// = delete;
diff --git a/include/thread b/include/thread
index 3ce32fc..8a30102 100644
--- a/include/thread
+++ b/include/thread
@@ -98,7 +98,8 @@
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 #include <tuple>
 #endif
-#include <__threading_support>
+#include <pthread.h>
+#include <sched.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -112,37 +113,10 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp> class __thread_specific_ptr;
-class _LIBCPP_TYPE_VIS __thread_struct;
-class _LIBCPP_HIDDEN __thread_struct_imp;
-class __assoc_sub_state;
-
-_LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data();
-
-class _LIBCPP_TYPE_VIS __thread_struct
-{
-    __thread_struct_imp* __p_;
-
-    __thread_struct(const __thread_struct&);
-    __thread_struct& operator=(const __thread_struct&);
-public:
-    __thread_struct();
-    ~__thread_struct();
-
-    void notify_all_at_thread_exit(condition_variable*, mutex*);
-    void __make_ready_at_thread_exit(__assoc_sub_state*);
-};
-
 template <class _Tp>
 class __thread_specific_ptr
 {
-    __libcpp_tl_key __key_;
-
-     // Only __thread_local_data() may construct a __thread_specific_ptr
-     // and only with _Tp == __thread_struct.
-    static_assert((is_same<_Tp, __thread_struct>::value), "");
-    __thread_specific_ptr();
-    friend _LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data();
+    pthread_key_t __key_;
 
     __thread_specific_ptr(const __thread_specific_ptr&);
     __thread_specific_ptr& operator=(const __thread_specific_ptr&);
@@ -151,10 +125,11 @@
 public:
     typedef _Tp* pointer;
 
+    __thread_specific_ptr();
     ~__thread_specific_ptr();
 
     _LIBCPP_INLINE_VISIBILITY
-    pointer get() const {return static_cast<_Tp*>(__libcpp_tl_get(__key_));}
+    pointer get() const {return static_cast<_Tp*>(pthread_getspecific(__key_));}
     _LIBCPP_INLINE_VISIBILITY
     pointer operator*() const {return *get();}
     _LIBCPP_INLINE_VISIBILITY
@@ -173,9 +148,7 @@
 template <class _Tp>
 __thread_specific_ptr<_Tp>::__thread_specific_ptr()
 {
-    int __ec = __libcpp_tl_create(
-        &__key_,
-        &__thread_specific_ptr::__at_thread_exit);
+    int __ec = pthread_key_create(&__key_, &__thread_specific_ptr::__at_thread_exit);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (__ec)
         throw system_error(error_code(__ec, system_category()),
@@ -186,10 +159,7 @@
 template <class _Tp>
 __thread_specific_ptr<_Tp>::~__thread_specific_ptr()
 {
-    // __thread_specific_ptr is only created with a static storage duration
-    // so this destructor is only invoked during program termination. Invoking
-    // pthread_key_delete(__key_) may prevent other threads from deleting their
-    // thread local data. For this reason we leak the key.
+    pthread_key_delete(__key_);
 }
 
 template <class _Tp>
@@ -197,7 +167,7 @@
 __thread_specific_ptr<_Tp>::release()
 {
     pointer __p = get();
-    __libcpp_tl_set(__key_, nullptr);
+    pthread_setspecific(__key_, 0);
     return __p;
 }
 
@@ -206,7 +176,7 @@
 __thread_specific_ptr<_Tp>::reset(pointer __p)
 {
     pointer __p_old = get();
-    __libcpp_tl_set(__key_, __p);
+    pthread_setspecific(__key_, __p);
     delete __p_old;
 }
 
@@ -220,14 +190,14 @@
 
 }  // this_thread
 
-template<> struct hash<__thread_id>;
+template<> struct _LIBCPP_TYPE_VIS_ONLY hash<__thread_id>;
 
 class _LIBCPP_TYPE_VIS_ONLY __thread_id
 {
     // FIXME: pthread_t is a pointer on Darwin but a long on Linux.
     // NULL is the no-thread value on Darwin.  Someone needs to check
     // on other platforms.  We assume 0 works everywhere for now.
-    __libcpp_thread_id __id_;
+    pthread_t __id_;
 
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -235,13 +205,13 @@
 
     friend _LIBCPP_INLINE_VISIBILITY
         bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
-        {return __libcpp_thread_id_equal(__x.__id_, __y.__id_);}
+        {return __x.__id_ == __y.__id_;}
     friend _LIBCPP_INLINE_VISIBILITY
         bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return !(__x == __y);}
     friend _LIBCPP_INLINE_VISIBILITY
         bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
-        {return  __libcpp_thread_id_less(__x.__id_, __y.__id_);}
+        {return __x.__id_ < __y.__id_;}
     friend _LIBCPP_INLINE_VISIBILITY
         bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
         {return !(__y < __x);}
@@ -261,7 +231,7 @@
 
 private:
     _LIBCPP_INLINE_VISIBILITY
-    __thread_id(__libcpp_thread_id __id) : __id_(__id) {}
+    __thread_id(pthread_t __id) : __id_(__id) {}
 
     friend __thread_id this_thread::get_id() _NOEXCEPT;
     friend class _LIBCPP_TYPE_VIS thread;
@@ -275,7 +245,7 @@
     _LIBCPP_INLINE_VISIBILITY
     size_t operator()(__thread_id __v) const
     {
-        return hash<__libcpp_thread_id>()(__v.__id_);
+        return hash<pthread_t>()(__v.__id_);
     }
 };
 
@@ -286,20 +256,20 @@
 __thread_id
 get_id() _NOEXCEPT
 {
-    return __libcpp_thread_get_current_id();
+    return pthread_self();
 }
 
 }  // this_thread
 
 class _LIBCPP_TYPE_VIS thread
 {
-    __libcpp_thread_t __t_;
+    pthread_t __t_;
 
     thread(const thread&);
     thread& operator=(const thread&);
 public:
     typedef __thread_id id;
-    typedef __libcpp_thread_t native_handle_type;
+    typedef pthread_t native_handle_type;
 
     _LIBCPP_INLINE_VISIBILITY
     thread() _NOEXCEPT : __t_(0) {}
@@ -319,7 +289,6 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = 0;}
-    _LIBCPP_INLINE_VISIBILITY
     thread& operator=(thread&& __t) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
@@ -331,30 +300,50 @@
     void join();
     void detach();
     _LIBCPP_INLINE_VISIBILITY
-    id get_id() const _NOEXCEPT {return __libcpp_thread_get_id(&__t_);}
+    id get_id() const _NOEXCEPT {return __t_;}
     _LIBCPP_INLINE_VISIBILITY
     native_handle_type native_handle() _NOEXCEPT {return __t_;}
 
     static unsigned hardware_concurrency() _NOEXCEPT;
 };
 
+class __assoc_sub_state;
+
+class _LIBCPP_HIDDEN __thread_struct_imp;
+
+class _LIBCPP_TYPE_VIS __thread_struct
+{
+    __thread_struct_imp* __p_;
+
+    __thread_struct(const __thread_struct&);
+    __thread_struct& operator=(const __thread_struct&);
+public:
+    __thread_struct();
+    ~__thread_struct();
+
+    void notify_all_at_thread_exit(condition_variable*, mutex*);
+    void __make_ready_at_thread_exit(__assoc_sub_state*);
+};
+
+_LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data();
+
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 
-template <class _TSp, class _Fp, class ..._Args, size_t ..._Indices>
+template <class _Fp, class ..._Args, size_t ..._Indices>
 inline _LIBCPP_INLINE_VISIBILITY
 void
-__thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>)
+__thread_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>)
 {
-    __invoke(_VSTD::move(_VSTD::get<1>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
+    __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
 }
 
 template <class _Fp>
-void* __thread_proxy(void* __vp)
+void*
+__thread_proxy(void* __vp)
 {
-    // _Fp = std::tuple< unique_ptr<__thread_struct>, Functor, Args...>
+    __thread_local_data().reset(new __thread_struct);
     std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
-    __thread_local_data().reset(_VSTD::get<0>(*__p).release());
-    typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 2>::type _Index;
+    typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
     __thread_execute(*__p, _Index());
     return nullptr;
 }
@@ -364,14 +353,10 @@
          >
 thread::thread(_Fp&& __f, _Args&&... __args)
 {
-    typedef unique_ptr<__thread_struct> _TSPtr;
-    _TSPtr __tsp(new __thread_struct);
-    typedef tuple<_TSPtr, typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp;
-    _VSTD::unique_ptr<_Gp> __p(
-            new _Gp(std::move(__tsp),
-                    __decay_copy(_VSTD::forward<_Fp>(__f)),
-                    __decay_copy(_VSTD::forward<_Args>(__args))...));
-    int __ec = __libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get());
+    typedef tuple<typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp;
+    _VSTD::unique_ptr<_Gp> __p(new _Gp(__decay_copy(_VSTD::forward<_Fp>(__f)),
+                                __decay_copy(_VSTD::forward<_Args>(__args))...));
+    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get());
     if (__ec == 0)
         __p.release();
     else
@@ -381,34 +366,22 @@
 #else  // _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Fp>
-struct __thread_invoke_pair {
-    // This type is used to pass memory for thread local storage and a functor
-    // to a newly created thread because std::pair doesn't work with
-    // std::unique_ptr in C++03.
-    __thread_invoke_pair(_Fp& __f) : __tsp_(new __thread_struct), __fn_(__f) {}
-    unique_ptr<__thread_struct> __tsp_;
-    _Fp __fn_;
-};
-
-template <class _Fp>
-void* __thread_proxy_cxx03(void* __vp)
+void*
+__thread_proxy(void* __vp)
 {
+    __thread_local_data().reset(new __thread_struct);
     std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
-    __thread_local_data().reset(__p->__tsp_.release());
-    (__p->__fn_)();
+    (*__p)();
     return nullptr;
 }
 
 template <class _Fp>
 thread::thread(_Fp __f)
 {
-
-    typedef __thread_invoke_pair<_Fp> _InvokePair;
-    typedef std::unique_ptr<_InvokePair> _PairPtr;
-    _PairPtr __pp(new _InvokePair(__f));
-    int __ec = __libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get());
+    std::unique_ptr<_Fp> __p(new _Fp(__f));
+    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Fp>, __p.get());
     if (__ec == 0)
-        __pp.release();
+        __p.release();
     else
         __throw_system_error(__ec, "thread constructor failed");
 }
@@ -417,7 +390,7 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 thread&
 thread::operator=(thread&& __t) _NOEXCEPT
 {
@@ -481,7 +454,7 @@
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-void yield() _NOEXCEPT {__libcpp_thread_yield();}
+void yield() _NOEXCEPT {sched_yield();}
 
 }  // this_thread
 
diff --git a/include/tuple b/include/tuple
index 73f42a0..3a22aa5 100644
--- a/include/tuple
+++ b/include/tuple
@@ -80,33 +80,28 @@
 // 20.4.1.4, tuple helper classes:
 template <class T> class tuple_size; // undefined
 template <class... T> class tuple_size<tuple<T...>>;
-template <size_t I, class T> class tuple_element; // undefined
-template <size_t I, class... T> class tuple_element<I, tuple<T...>>;
-template <size_t I, class T>
-  using tuple_element_t = typename tuple_element <I, T>::type; // C++14
+template <intsize_t I, class T> class tuple_element; // undefined
+template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
+template <size_t _Ip, class ..._Tp>
+  using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; // C++14
 
 // 20.4.1.5, element access:
-template <size_t I, class... T>
+template <intsize_t I, class... T>
     typename tuple_element<I, tuple<T...>>::type&
     get(tuple<T...>&) noexcept; // constexpr in C++14
-template <size_t I, class... T>
-    const typename tuple_element<I, tuple<T...>>::type&
+template <intsize_t I, class... T>
+    typename const tuple_element<I, tuple<T...>>::type &
     get(const tuple<T...>&) noexcept; // constexpr in C++14
-template <size_t I, class... T>
+template <intsize_t I, class... T>
     typename tuple_element<I, tuple<T...>>::type&&
     get(tuple<T...>&&) noexcept; // constexpr in C++14
-template <size_t I, class... T>
-    const typename tuple_element<I, tuple<T...>>::type&&
-    get(const tuple<T...>&&) noexcept; // constexpr in C++14
 
 template <class T1, class... T>
     constexpr T1& get(tuple<T...>&) noexcept;  // C++14
 template <class T1, class... T>
-    constexpr const T1& get(const tuple<T...>&) noexcept;   // C++14
+    constexpr T1 const& get(const tuple<T...>&) noexcept;   // C++14
 template <class T1, class... T>
     constexpr T1&& get(tuple<T...>&&) noexcept;   // C++14
-template <class T1, class... T>
-    constexpr const T1&& get(const tuple<T...>&&) noexcept;   // C++14
 
 // 20.4.1.6, relational operators:
 template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
@@ -384,9 +379,6 @@
     : is_same<__all<_Pred...>, __all<(_Pred, true)...>>
 { };
 
-template <class ..._Tp>
-struct __lazy_all : __all<_Tp::value...> {};
-
 template <class _Tp>
 struct __all_default_constructible;
 
@@ -449,7 +441,7 @@
     template <class _Alloc, class _Tuple,
               class = typename enable_if
                       <
-                         __tuple_constructible<_Tuple, tuple<_Tp...> >::value
+                         __tuple_convertible<_Tuple, tuple<_Tp...> >::value
                       >::type
              >
         _LIBCPP_INLINE_VISIBILITY
@@ -502,28 +494,6 @@
     }
 };
 
-template <bool _IsTuple, class _SizeTrait, size_t _Expected>
-struct __tuple_like_with_size_imp : false_type {};
-
-template <class _SizeTrait, size_t _Expected>
-struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
-    : integral_constant<bool, _SizeTrait::value == _Expected> {};
-
-template <class _Tuple, size_t _ExpectedSize,
-          class _RawTuple = typename __uncvref<_Tuple>::type>
-using __tuple_like_with_size = __tuple_like_with_size_imp<
-                                   __tuple_like<_RawTuple>::value,
-                                   tuple_size<_RawTuple>, _ExpectedSize
-                              >;
-
-
-struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
-    template <class ...>
-    static constexpr bool __enable_explicit() { return false; }
-    template <class ...>
-    static constexpr bool __enable_implicit() { return false; }
-};
-
 template <class ..._Tp>
 class _LIBCPP_TYPE_VIS_ONLY tuple
 {
@@ -531,126 +501,12 @@
 
     base base_;
 
-    template <class ..._Args>
-    struct _PackExpandsToThisTuple : false_type {};
-
-    template <class _Arg>
-    struct _PackExpandsToThisTuple<_Arg>
-        : is_same<typename __uncvref<_Arg>::type, tuple> {};
-
-    template <bool _MaybeEnable, class _Dummy = void>
-    struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
-
-    template <class _Dummy>
-    struct _CheckArgsConstructor<true, _Dummy>
-    {
-        template <class ..._Args>
-        static constexpr bool __enable_explicit() {
-            return
-                __tuple_constructible<
-                    tuple<_Args...>,
-                    typename __make_tuple_types<tuple,
-                             sizeof...(_Args) < sizeof...(_Tp) ?
-                                 sizeof...(_Args) :
-                                 sizeof...(_Tp)>::type
-                >::value &&
-                !__tuple_convertible<
-                    tuple<_Args...>,
-                    typename __make_tuple_types<tuple,
-                             sizeof...(_Args) < sizeof...(_Tp) ?
-                                 sizeof...(_Args) :
-                                 sizeof...(_Tp)>::type
-                >::value &&
-                __all_default_constructible<
-                    typename __make_tuple_types<tuple, sizeof...(_Tp),
-                             sizeof...(_Args) < sizeof...(_Tp) ?
-                                 sizeof...(_Args) :
-                                 sizeof...(_Tp)>::type
-                >::value;
-        }
-
-        template <class ..._Args>
-        static constexpr bool __enable_implicit() {
-            return
-                __tuple_convertible<
-                    tuple<_Args...>,
-                    typename __make_tuple_types<tuple,
-                             sizeof...(_Args) < sizeof...(_Tp) ?
-                                 sizeof...(_Args) :
-                                 sizeof...(_Tp)>::type
-                >::value &&
-                __all_default_constructible<
-                    typename __make_tuple_types<tuple, sizeof...(_Tp),
-                             sizeof...(_Args) < sizeof...(_Tp) ?
-                                 sizeof...(_Args) :
-                                 sizeof...(_Tp)>::type
-                >::value;
-        }
-    };
-
-    template <bool _MaybeEnable,
-              bool = sizeof...(_Tp) == 1,
-              class _Dummy = void>
-    struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
-
-    template <class _Dummy>
-    struct _CheckTupleLikeConstructor<true, false, _Dummy>
-    {
-        template <class _Tuple>
-        static constexpr bool __enable_implicit() {
-            return __tuple_convertible<_Tuple, tuple>::value;
-        }
-
-        template <class _Tuple>
-        static constexpr bool __enable_explicit() {
-            return __tuple_constructible<_Tuple, tuple>::value
-               && !__tuple_convertible<_Tuple, tuple>::value;
-        }
-    };
-
-    template <class _Dummy>
-    struct _CheckTupleLikeConstructor<true, true, _Dummy>
-    {
-        // This trait is used to disable the tuple-like constructor when
-        // the UTypes... constructor should be selected instead.
-        // See LWG issue #2549.
-        template <class _Tuple>
-        using _PreferTupleLikeConstructor = __lazy_or<
-            // Don't attempt the two checks below if the tuple we are given
-            // has the same type as this tuple.
-            is_same<typename __uncvref<_Tuple>::type, tuple>,
-            __lazy_and<
-                __lazy_not<is_constructible<_Tp..., _Tuple>>,
-                __lazy_not<is_convertible<_Tuple, _Tp...>>
-            >
-        >;
-
-        template <class _Tuple>
-        static constexpr bool __enable_implicit() {
-            return __lazy_and<
-                __tuple_convertible<_Tuple, tuple>,
-                _PreferTupleLikeConstructor<_Tuple>
-            >::value;
-        }
-
-        template <class _Tuple>
-        static constexpr bool __enable_explicit() {
-            return __lazy_and<
-                __tuple_constructible<_Tuple, tuple>,
-                _PreferTupleLikeConstructor<_Tuple>,
-                __lazy_not<__tuple_convertible<_Tuple, tuple>>
-            >::value;
-        }
-    };
-
     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
         typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
         const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
     template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
         typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
-    template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
-        const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
 public:
 
     template <bool _Dummy = true, class = typename enable_if<
@@ -660,30 +516,8 @@
     _LIBCPP_CONSTEXPR tuple()
         _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
 
-    template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if<
-        __lazy_and<
-            is_base_of<allocator_arg_t, _AllocArgT>,
-            __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>
-       >::value
-    >::type>
-    _LIBCPP_INLINE_VISIBILITY
-    tuple(_AllocArgT, _Alloc const& __a)
-      : base_(allocator_arg_t(), __a,
-                    __tuple_indices<>(), __tuple_types<>(),
-                    typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
-                    __tuple_types<_Tp...>()) {}
-
-    template <bool _Dummy = true,
-              typename enable_if
-                      <
-                         _CheckArgsConstructor<
-                            _Dummy
-                         >::template __enable_implicit<_Tp...>(),
-                         bool
-                      >::type = false
-        >
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-    tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
+    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value)) 
         : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
                 typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
                 typename __make_tuple_indices<0>::type(),
@@ -691,33 +525,7 @@
                 __t...
                ) {}
 
-    template <bool _Dummy = true,
-              typename enable_if
-                      <
-                         _CheckArgsConstructor<
-                            _Dummy
-                         >::template __enable_explicit<_Tp...>(),
-                         bool
-                      >::type = false
-        >
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-    explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
-        : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
-                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
-                typename __make_tuple_indices<0>::type(),
-                typename __make_tuple_types<tuple, 0>::type(),
-                __t...
-               ) {}
-
-    template <class _Alloc, bool _Dummy = true,
-              typename enable_if
-                      <
-                         _CheckArgsConstructor<
-                            _Dummy
-                         >::template __enable_implicit<_Tp...>(),
-                         bool
-                      >::type = false
-        >
+    template <class _Alloc>
       _LIBCPP_INLINE_VISIBILITY
       tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
         : base_(allocator_arg_t(), __a,
@@ -728,33 +536,24 @@
                 __t...
                ) {}
 
-    template <class _Alloc, bool _Dummy = true,
-              typename enable_if
-                      <
-                         _CheckArgsConstructor<
-                            _Dummy
-                         >::template __enable_explicit<_Tp...>(),
-                         bool
-                      >::type = false
-        >
-      _LIBCPP_INLINE_VISIBILITY
-      explicit
-      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
-        : base_(allocator_arg_t(), __a,
-                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
-                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
-                typename __make_tuple_indices<0>::type(),
-                typename __make_tuple_types<tuple, 0>::type(),
-                __t...
-               ) {}
-
     template <class ..._Up,
               typename enable_if
                       <
-                         _CheckArgsConstructor<
-                             sizeof...(_Up) <= sizeof...(_Tp)
-                             && !_PackExpandsToThisTuple<_Up...>::value
-                         >::template __enable_implicit<_Up...>(),
+                         sizeof...(_Up) <= sizeof...(_Tp) &&
+                         __tuple_convertible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value &&
+                         __all_default_constructible<
+                            typename __make_tuple_types<tuple, sizeof...(_Tp),
+                                sizeof...(_Up) < sizeof...(_Tp) ?
+                                    sizeof...(_Up) :
+                                    sizeof...(_Tp)>::type
+                         >::value,
                          bool
                       >::type = false
              >
@@ -778,12 +577,31 @@
     template <class ..._Up,
               typename enable_if
                       <
-                         _CheckArgsConstructor<
-                             sizeof...(_Up) <= sizeof...(_Tp)
-                             && !_PackExpandsToThisTuple<_Up...>::value
-                         >::template __enable_explicit<_Up...>(),
+                         sizeof...(_Up) <= sizeof...(_Tp) &&
+                         __tuple_constructible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value &&
+                         !__tuple_convertible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value &&
+                         __all_default_constructible<
+                            typename __make_tuple_types<tuple, sizeof...(_Tp),
+                                sizeof...(_Up) < sizeof...(_Tp) ?
+                                    sizeof...(_Up) :
+                                    sizeof...(_Tp)>::type
+                         >::value,
                          bool
-                      >::type = false
+                      >::type =false
              >
         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
         explicit
@@ -804,14 +622,24 @@
                     _VSTD::forward<_Up>(__u)...) {}
 
     template <class _Alloc, class ..._Up,
-              typename enable_if
+              class = typename enable_if
                       <
-                         _CheckArgsConstructor<
-                             sizeof...(_Up) == sizeof...(_Tp) &&
-                             !_PackExpandsToThisTuple<_Up...>::value
-                         >::template __enable_implicit<_Up...>(),
-                         bool
-                      >::type = false
+                         sizeof...(_Up) <= sizeof...(_Tp) &&
+                         __tuple_convertible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value &&
+                         __all_default_constructible<
+                            typename __make_tuple_types<tuple, sizeof...(_Tp),
+                                sizeof...(_Up) < sizeof...(_Tp) ?
+                                    sizeof...(_Up) :
+                                    sizeof...(_Tp)>::type
+                         >::value
+                      >::type
              >
         _LIBCPP_INLINE_VISIBILITY
         tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
@@ -822,33 +650,10 @@
                     typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
                     _VSTD::forward<_Up>(__u)...) {}
 
-    template <class _Alloc, class ..._Up,
-              typename enable_if
-                      <
-                         _CheckArgsConstructor<
-                             sizeof...(_Up) == sizeof...(_Tp) &&
-                             !_PackExpandsToThisTuple<_Up...>::value
-                         >::template __enable_explicit<_Up...>(),
-                         bool
-                      >::type = false
-             >
-        _LIBCPP_INLINE_VISIBILITY
-        explicit
-        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
-            : base_(allocator_arg_t(), __a,
-                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
-                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
-                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
-                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
-                    _VSTD::forward<_Up>(__u)...) {}
-
     template <class _Tuple,
               typename enable_if
                       <
-                         _CheckTupleLikeConstructor<
-                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
-                             && !_PackExpandsToThisTuple<_Tuple>::value
-                         >::template __enable_implicit<_Tuple>(),
+                         __tuple_convertible<_Tuple, tuple>::value,
                          bool
                       >::type = false
              >
@@ -859,10 +664,8 @@
     template <class _Tuple,
               typename enable_if
                       <
-                         _CheckTupleLikeConstructor<
-                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
-                             && !_PackExpandsToThisTuple<_Tuple>::value
-                         >::template __enable_explicit<_Tuple>(),
+                         __tuple_constructible<_Tuple, tuple>::value &&
+                         !__tuple_convertible<_Tuple, tuple>::value,
                          bool
                       >::type = false
              >
@@ -872,32 +675,15 @@
             : base_(_VSTD::forward<_Tuple>(__t)) {}
 
     template <class _Alloc, class _Tuple,
-              typename enable_if
+              class = typename enable_if
                       <
-                         _CheckTupleLikeConstructor<
-                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
-                         >::template __enable_implicit<_Tuple>(),
-                         bool
-                      >::type = false
+                         __tuple_convertible<_Tuple, tuple>::value
+                      >::type
              >
         _LIBCPP_INLINE_VISIBILITY
         tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
             : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
 
-    template <class _Alloc, class _Tuple,
-              typename enable_if
-                      <
-                         _CheckTupleLikeConstructor<
-                             __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
-                         >::template __enable_explicit<_Tuple>(),
-                         bool
-                      >::type = false
-             >
-        _LIBCPP_INLINE_VISIBILITY
-        explicit
-        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
-            : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
-
     template <class _Tuple,
               class = typename enable_if
                       <
@@ -980,16 +766,6 @@
              static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get());
 }
 
-template <size_t _Ip, class ..._Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
-get(const tuple<_Tp...>&& __t) _NOEXCEPT
-{
-    typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type;
-    return static_cast<const type&&>(
-             static_cast<const __tuple_leaf<_Ip, type>&&>(__t.base_).get());
-}
-
 #if _LIBCPP_STD_VER > 11
 // get by type
 template <typename _T1, size_t _Idx, typename... _Args>
@@ -1046,13 +822,6 @@
     return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
 }
 
-template <class _T1, class... _Args>
-inline _LIBCPP_INLINE_VISIBILITY
-constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
-{
-    return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
-}
-
 #endif
 
 // tie
diff --git a/include/type_traits b/include/type_traits
index a8b0bd0..f0defaf 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -105,8 +105,6 @@
     template <class T, class U>       struct is_assignable;
     template <class T>                struct is_copy_assignable;
     template <class T>                struct is_move_assignable;
-    template <class T, class U>       struct is_swappable_with;       // C++17
-    template <class T>                struct is_swappable;            // C++17
     template <class T>                struct is_destructible;
 
     template <class T, class... Args> struct is_trivially_constructible;
@@ -125,8 +123,6 @@
     template <class T, class U>       struct is_nothrow_assignable;
     template <class T>                struct is_nothrow_copy_assignable;
     template <class T>                struct is_nothrow_move_assignable;
-    template <class T, class U>       struct is_nothrow_swappable_with; // C++17
-    template <class T>                struct is_nothrow_swappable;      // C++17
     template <class T>                struct is_nothrow_destructible;
 
     template <class T> struct has_virtual_destructor;
@@ -136,14 +132,6 @@
     template <class Base, class Derived> struct is_base_of;
     template <class From, class To> struct is_convertible;
 
-    template <class, class R = void> struct is_callable; // not defined
-    template <class Fn, class... ArgTypes, class R>
-      struct is_callable<Fn(ArgTypes...), R>;
-
-    template <class, class R = void> struct is_nothrow_callable; // not defined
-    template <class Fn, class... ArgTypes, class R>
-      struct is_nothrow_callable<Fn(ArgTypes...), R>;
-
     // Alignment properties and transformations:
     template <class T> struct alignment_of;
     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
@@ -215,172 +203,8 @@
       using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
 
     template <class...>
-      using void_t = void;   // C++17
-      
-      // See C++14 20.10.4.1, primary type categories
-      template <class T> constexpr bool is_void_v
-        = is_void<T>::value;                                             // C++17
-      template <class T> constexpr bool is_null_pointer_v
-        = is_null_pointer<T>::value;                                     // C++17
-      template <class T> constexpr bool is_integral_v
-        = is_integral<T>::value;                                         // C++17
-      template <class T> constexpr bool is_floating_point_v
-        = is_floating_point<T>::value;                                   // C++17
-      template <class T> constexpr bool is_array_v
-        = is_array<T>::value;                                            // C++17
-      template <class T> constexpr bool is_pointer_v
-        = is_pointer<T>::value;                                          // C++17
-      template <class T> constexpr bool is_lvalue_reference_v
-        = is_lvalue_reference<T>::value;                                 // C++17
-      template <class T> constexpr bool is_rvalue_reference_v
-        = is_rvalue_reference<T>::value;                                 // C++17
-      template <class T> constexpr bool is_member_object_pointer_v
-        = is_member_object_pointer<T>::value;                            // C++17
-      template <class T> constexpr bool is_member_function_pointer_v
-        = is_member_function_pointer<T>::value;                          // C++17
-      template <class T> constexpr bool is_enum_v
-        = is_enum<T>::value;                                             // C++17
-      template <class T> constexpr bool is_union_v
-        = is_union<T>::value;                                            // C++17
-      template <class T> constexpr bool is_class_v
-        = is_class<T>::value;                                            // C++17
-      template <class T> constexpr bool is_function_v
-        = is_function<T>::value;                                         // C++17
-
-      // See C++14 20.10.4.2, composite type categories
-      template <class T> constexpr bool is_reference_v
-        = is_reference<T>::value;                                        // C++17
-      template <class T> constexpr bool is_arithmetic_v
-        = is_arithmetic<T>::value;                                       // C++17
-      template <class T> constexpr bool is_fundamental_v
-        = is_fundamental<T>::value;                                      // C++17
-      template <class T> constexpr bool is_object_v
-        = is_object<T>::value;                                           // C++17
-      template <class T> constexpr bool is_scalar_v
-        = is_scalar<T>::value;                                           // C++17
-      template <class T> constexpr bool is_compound_v
-        = is_compound<T>::value;                                         // C++17
-      template <class T> constexpr bool is_member_pointer_v
-        = is_member_pointer<T>::value;                                   // C++17
-
-      // See C++14 20.10.4.3, type properties
-      template <class T> constexpr bool is_const_v
-        = is_const<T>::value;                                            // C++17
-      template <class T> constexpr bool is_volatile_v
-        = is_volatile<T>::value;                                         // C++17
-      template <class T> constexpr bool is_trivial_v
-        = is_trivial<T>::value;                                          // C++17
-      template <class T> constexpr bool is_trivially_copyable_v
-        = is_trivially_copyable<T>::value;                               // C++17
-      template <class T> constexpr bool is_standard_layout_v
-        = is_standard_layout<T>::value;                                  // C++17
-      template <class T> constexpr bool is_pod_v
-        = is_pod<T>::value;                                              // C++17
-      template <class T> constexpr bool is_literal_type_v
-        = is_literal_type<T>::value;                                     // C++17
-      template <class T> constexpr bool is_empty_v
-        = is_empty<T>::value;                                            // C++17
-      template <class T> constexpr bool is_polymorphic_v
-        = is_polymorphic<T>::value;                                      // C++17
-      template <class T> constexpr bool is_abstract_v
-        = is_abstract<T>::value;                                         // C++17
-      template <class T> constexpr bool is_final_v
-        = is_final<T>::value;                                            // C++17
-      template <class T> constexpr bool is_signed_v
-        = is_signed<T>::value;                                           // C++17
-      template <class T> constexpr bool is_unsigned_v
-        = is_unsigned<T>::value;                                         // C++17
-      template <class T, class... Args> constexpr bool is_constructible_v
-        = is_constructible<T, Args...>::value;                           // C++17
-      template <class T> constexpr bool is_default_constructible_v
-        = is_default_constructible<T>::value;                            // C++17
-      template <class T> constexpr bool is_copy_constructible_v
-        = is_copy_constructible<T>::value;                               // C++17
-      template <class T> constexpr bool is_move_constructible_v
-        = is_move_constructible<T>::value;                               // C++17
-      template <class T, class U> constexpr bool is_assignable_v
-        = is_assignable<T, U>::value;                                    // C++17
-      template <class T> constexpr bool is_copy_assignable_v
-        = is_copy_assignable<T>::value;                                  // C++17
-      template <class T> constexpr bool is_move_assignable_v
-        = is_move_assignable<T>::value;                                  // C++17
-      template <class T, class U> constexpr bool is_swappable_with_v
-        = is_swappable_with<T, U>::value;                                // C++17
-      template <class T> constexpr bool is_swappable_v
-        = is_swappable<T>::value;                                        // C++17
-      template <class T> constexpr bool is_destructible_v
-        = is_destructible<T>::value;                                     // C++17
-      template <class T, class... Args> constexpr bool is_trivially_constructible_v
-        = is_trivially_constructible<T, Args...>::value;                 // C++17
-      template <class T> constexpr bool is_trivially_default_constructible_v
-        = is_trivially_default_constructible<T>::value;                  // C++17
-      template <class T> constexpr bool is_trivially_copy_constructible_v
-        = is_trivially_copy_constructible<T>::value;                     // C++17
-      template <class T> constexpr bool is_trivially_move_constructible_v
-        = is_trivially_move_constructible<T>::value;                     // C++17
-      template <class T, class U> constexpr bool is_trivially_assignable_v
-        = is_trivially_assignable<T, U>::value;                          // C++17
-      template <class T> constexpr bool is_trivially_copy_assignable_v
-        = is_trivially_copy_assignable<T>::value;                        // C++17
-      template <class T> constexpr bool is_trivially_move_assignable_v
-        = is_trivially_move_assignable<T>::value;                        // C++17
-      template <class T> constexpr bool is_trivially_destructible_v
-        = is_trivially_destructible<T>::value;                           // C++17
-      template <class T, class... Args> constexpr bool is_nothrow_constructible_v
-        = is_nothrow_constructible<T, Args...>::value;                   // C++17
-      template <class T> constexpr bool is_nothrow_default_constructible_v
-        = is_nothrow_default_constructible<T>::value;                    // C++17
-      template <class T> constexpr bool is_nothrow_copy_constructible_v
-        = is_nothrow_copy_constructible<T>::value;                       // C++17
-      template <class T> constexpr bool is_nothrow_move_constructible_v
-        = is_nothrow_move_constructible<T>::value;                       // C++17
-      template <class T, class U> constexpr bool is_nothrow_assignable_v
-        = is_nothrow_assignable<T, U>::value;                            // C++17
-      template <class T> constexpr bool is_nothrow_copy_assignable_v
-        = is_nothrow_copy_assignable<T>::value;                          // C++17
-      template <class T> constexpr bool is_nothrow_move_assignable_v
-        = is_nothrow_move_assignable<T>::value;                          // C++17
-      template <class T, class U> constexpr bool is_nothrow_swappable_with_v
-        = is_nothrow_swappable_with<T, U>::value;                       // C++17
-      template <class T> constexpr bool is_nothrow_swappable_v
-        = is_nothrow_swappable<T>::value;                               // C++17
-      template <class T> constexpr bool is_nothrow_destructible_v
-        = is_nothrow_destructible<T>::value;                             // C++17
-      template <class T> constexpr bool has_virtual_destructor_v
-        = has_virtual_destructor<T>::value;                              // C++17
-
-      // See C++14 20.10.5, type property queries
-      template <class T> constexpr size_t alignment_of_v
-        = alignment_of<T>::value;                                        // C++17
-      template <class T> constexpr size_t rank_v
-        = rank<T>::value;                                                // C++17
-      template <class T, unsigned I = 0> constexpr size_t extent_v
-        = extent<T, I>::value;                                           // C++17
-
-      // See C++14 20.10.6, type relations
-      template <class T, class U> constexpr bool is_same_v
-        = is_same<T, U>::value;                                          // C++17
-      template <class Base, class Derived> constexpr bool is_base_of_v
-        = is_base_of<Base, Derived>::value;                              // C++17
-      template <class From, class To> constexpr bool is_convertible_v
-        = is_convertible<From, To>::value;                               // C++17
-      template <class T, class R = void> constexpr bool is_callable_v
-        = is_callable<T, R>::value;                                      // C++17
-      template <class T, class R = void> constexpr bool is_nothrow_callable_v
-        = is_nothrow_callable<T, R>::value;                              // C++17
-
-      // [meta.logical], logical operator traits:
-      template<class... B> struct conjunction;                           // C++17
-      template<class... B> 
-        constexpr bool conjunction_v = conjunction<B...>::value;         // C++17
-      template<class... B> struct disjunction;                           // C++17
-      template<class... B>
-        constexpr bool disjunction_v = disjunction<B...>::value;         // C++17
-      template<class B> struct negation;                                 // C++17
-      template<class B> 
-        constexpr bool negation_v = negation<B>::value;                  // C++17
-
-}
+      using void_t = void;
+}  // C++17
 
 */
 #include <__config>
@@ -392,10 +216,6 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair;
-template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
-template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
-
 template <class>
 struct __void_t { typedef void type; };
 
@@ -424,69 +244,6 @@
 template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
 #endif
 
-// addressof
-#if __has_builtin(__builtin_addressof)
-
-template <class _Tp>
-inline _LIBCPP_CONSTEXPR_AFTER_CXX14
-_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
-_Tp*
-addressof(_Tp& __x) _NOEXCEPT
-{
-    return __builtin_addressof(__x);
-}
-
-#else
-
-template <class _Tp>
-inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
-_Tp*
-addressof(_Tp& __x) _NOEXCEPT
-{
-    return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
-}
-
-#endif // __has_builtin(__builtin_addressof)
-
-#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
-// Objective-C++ Automatic Reference Counting uses qualified pointers
-// that require special addressof() signatures. When
-// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
-// itself is providing these definitions. Otherwise, we provide them.
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-__strong _Tp*
-addressof(__strong _Tp& __x) _NOEXCEPT
-{
-  return &__x;
-}
-
-#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-__weak _Tp*
-addressof(__weak _Tp& __x) _NOEXCEPT
-{
-  return &__x;
-}
-#endif
-
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-__autoreleasing _Tp*
-addressof(__autoreleasing _Tp& __x) _NOEXCEPT
-{
-  return &__x;
-}
-
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-__unsafe_unretained _Tp*
-addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
-{
-  return &__x;
-}
-#endif
 
 struct __two {char __lx[2];};
 
@@ -512,111 +269,24 @@
 #if _LIBCPP_STD_VER > 14
 template <bool __b>
 using bool_constant = integral_constant<bool, __b>;
-#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
+#define	_LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
 #else
-#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
+#define	_LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
 #endif
 
 typedef _LIBCPP_BOOL_CONSTANT(true)  true_type;
 typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
 
-#if !defined(_LIBCPP_HAS_NO_VARIADICS)
-
-// __lazy_and
-
-template <bool _Last, class ..._Preds>
-struct __lazy_and_impl;
-
-template <class ..._Preds>
-struct __lazy_and_impl<false, _Preds...> : false_type {};
-
-template <>
-struct __lazy_and_impl<true> : true_type {};
-
-template <class _Pred>
-struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {};
-
-template <class _Hp, class ..._Tp>
-struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {};
-
-template <class _P1, class ..._Pr>
-struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {};
-
-// __lazy_or
-
-template <bool _List, class ..._Preds>
-struct __lazy_or_impl;
-
-template <class ..._Preds>
-struct __lazy_or_impl<true, _Preds...> : true_type {};
-
-template <>
-struct __lazy_or_impl<false> : false_type {};
-
-template <class _Hp, class ..._Tp>
-struct __lazy_or_impl<false, _Hp, _Tp...>
-        : __lazy_or_impl<_Hp::type::value, _Tp...> {};
-
-template <class _P1, class ..._Pr>
-struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {};
-
-// __lazy_not
-
-template <class _Pred>
-struct __lazy_not : integral_constant<bool, !_Pred::type::value> {};
-
-// __and_
-template<class...> struct __and_;
-template<> struct __and_<> : true_type {};
-
-template<class _B0> struct __and_<_B0> : _B0 {};
-
-template<class _B0, class _B1>
-struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {};
-
-template<class _B0, class _B1, class _B2, class... _Bn>
-struct __and_<_B0, _B1, _B2, _Bn...> 
-        : conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {};
-
-// __or_
-template<class...> struct __or_;
-template<> struct __or_<> : false_type {};
-
-template<class _B0> struct __or_<_B0> : _B0 {};
-
-template<class _B0, class _B1>
-struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {};
-
-template<class _B0, class _B1, class _B2, class... _Bn>
-struct __or_<_B0, _B1, _B2, _Bn...> 
-        : conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {};
-
-// __not_
-template<class _Tp> 
-struct __not_ : conditional<_Tp::value, false_type, true_type>::type {};
-
-#endif // !defined(_LIBCPP_HAS_NO_VARIADICS)
-
 // is_const
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const            : public false_type {};
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const<_Tp const> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_const_v
-    = is_const<_Tp>::value;
-#endif
-
 // is_volatile
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile               : public false_type {};
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile<_Tp volatile> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_volatile_v
-    = is_volatile<_Tp>::value;
-#endif
-
 // remove_const
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const            {typedef _Tp type;};
@@ -649,11 +319,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void
     : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_void_v
-    = is_void<_Tp>::value;
-#endif
-
 // __is_nullptr_t
 
 template <class _Tp> struct __is_nullptr_t_impl       : public false_type {};
@@ -665,11 +330,6 @@
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_null_pointer
     : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
-
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_null_pointer_v
-    = is_null_pointer<_Tp>::value;
-#endif
 #endif
 
 // is_integral
@@ -700,11 +360,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral
     : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_integral_v
-    = is_integral<_Tp>::value;
-#endif
-
 // is_floating_point
 
 template <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
@@ -715,11 +370,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_floating_point
     : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_floating_point_v
-    = is_floating_point<_Tp>::value;
-#endif
-
 // is_array
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array
@@ -729,11 +379,6 @@
 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[_Np]>
     : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_array_v
-    = is_array<_Tp>::value;
-#endif
-
 // is_pointer
 
 template <class _Tp> struct __libcpp_is_pointer       : public false_type {};
@@ -742,11 +387,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pointer
     : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_pointer_v
-    = is_pointer<_Tp>::value;
-#endif
-
 // is_reference
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference       : public false_type {};
@@ -763,16 +403,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {};
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_reference_v
-    = is_reference<_Tp>::value;
-
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_lvalue_reference_v
-    = is_lvalue_reference<_Tp>::value;
-
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
-    = is_rvalue_reference<_Tp>::value;
-#endif
 // is_union
 
 #if __has_feature(is_union) || (_GNUC_VER >= 403)
@@ -788,11 +418,6 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_union_v
-    = is_union<_Tp>::value;
-#endif
-
 // is_class
 
 #if __has_feature(is_class) || (_GNUC_VER >= 403)
@@ -813,21 +438,11 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_class_v
-    = is_class<_Tp>::value;
-#endif
-
 // is_same
 
 template <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS_ONLY is_same           : public false_type {};
 template <class _Tp>            struct _LIBCPP_TYPE_VIS_ONLY is_same<_Tp, _Tp> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp, class _Up> _LIBCPP_CONSTEXPR bool is_same_v
-    = is_same<_Tp, _Up>::value;
-#endif
-
 // is_function
 
 namespace __libcpp_is_function_imp
@@ -853,11 +468,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_function
     : public __libcpp_is_function<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_function_v
-    = is_function<_Tp>::value;
-#endif
-
 // is_member_function_pointer
 
 // template <class _Tp> struct            __libcpp_is_member_function_pointer             : public false_type {};
@@ -880,11 +490,6 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_function_pointer
     : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type>::type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
-    = is_member_function_pointer<_Tp>::value;
-#endif
-
 // is_member_pointer
 
 template <class _Tp>            struct __libcpp_is_member_pointer             : public false_type {};
@@ -893,22 +498,12 @@
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_pointer
     : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_pointer_v
-    = is_member_pointer<_Tp>::value;
-#endif
-
 // is_member_object_pointer
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer
     : public integral_constant<bool, is_member_pointer<_Tp>::value &&
                                     !is_member_function_pointer<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
-    = is_member_object_pointer<_Tp>::value;
-#endif
-
 // is_enum
 
 #if __has_feature(is_enum) || (_GNUC_VER >= 403)
@@ -932,22 +527,12 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_enum_v
-    = is_enum<_Tp>::value;
-#endif
-
 // is_arithmetic
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_arithmetic
     : public integral_constant<bool, is_integral<_Tp>::value      ||
                                      is_floating_point<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_arithmetic_v
-    = is_arithmetic<_Tp>::value;
-#endif
-
 // is_fundamental
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_fundamental
@@ -955,11 +540,6 @@
                                      __is_nullptr_t<_Tp>::value ||
                                      is_arithmetic<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_fundamental_v
-    = is_fundamental<_Tp>::value;
-#endif
-
 // is_scalar
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_scalar
@@ -971,11 +551,6 @@
 
 template <> struct _LIBCPP_TYPE_VIS_ONLY is_scalar<nullptr_t> : public true_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_scalar_v
-    = is_scalar<_Tp>::value;
-#endif
-
 // is_object
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_object
@@ -984,34 +559,11 @@
                                      is_union<_Tp>::value  ||
                                      is_class<_Tp>::value  > {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_object_v
-    = is_object<_Tp>::value;
-#endif
-
 // is_compound
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_compound
     : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_compound_v
-    = is_compound<_Tp>::value;
-#endif
-
-
-// __is_referenceable  [defns.referenceable]
-
-struct __is_referenceable_impl {
-    template <class _Tp> static _Tp& __test(int);
-    template <class _Tp> static __two __test(...);
-};
-
-template <class _Tp>
-struct __is_referenceable : integral_constant<bool,
-    !is_same<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
-
-
 // add_const
 
 template <class _Tp, bool = is_reference<_Tp>::value ||
@@ -1069,11 +621,12 @@
 
 // add_lvalue_reference
 
-template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl            { typedef _Tp  type; };
-template <class _Tp                                       > struct __add_lvalue_reference_impl<_Tp, true> { typedef _Tp& type; };
-
-template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference
-{typedef typename __add_lvalue_reference_impl<_Tp>::type type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference                      {typedef _Tp& type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<void>                {typedef void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const void>          {typedef const void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const volatile void> {typedef const volatile void type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
@@ -1081,11 +634,11 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl            { typedef _Tp   type; };
-template <class _Tp                                       > struct __add_rvalue_reference_impl<_Tp, true> { typedef _Tp&& type; };
-
-template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference
-{typedef typename __add_rvalue_reference_impl<_Tp>::type type;};
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY  add_rvalue_reference                     {typedef _Tp&& type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<void>                {typedef void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const void>          {typedef const void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const volatile void> {typedef const volatile void type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
@@ -1095,11 +648,8 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-template <class _Tp> _Tp&& __declval(int);
-template <class _Tp> _Tp   __declval(long);
-
 template <class _Tp>
-decltype(_VSTD::__declval<_Tp>(0))
+typename add_rvalue_reference<_Tp>::type
 declval() _NOEXCEPT;
 
 #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1110,24 +660,6 @@
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
-// __uncvref
-
-template <class _Tp>
-struct __uncvref  {
-    typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type;
-};
-
-template <class _Tp>
-struct __unconstref {
-    typedef typename remove_const<typename remove_reference<_Tp>::type>::type type;
-};
-
-// __is_same_uncvref
-
-template <class _Tp, class _Up>
-struct __is_same_uncvref : is_same<typename __uncvref<_Tp>::type,
-                                   typename __uncvref<_Up>::type> {};
-
 struct __any
 {
     __any(...);
@@ -1147,16 +679,8 @@
 
 // add_pointer
 
-template <class _Tp, 
-        bool = __is_referenceable<_Tp>::value || 
-                is_same<typename remove_cv<_Tp>::type, void>::value>
-struct __add_pointer_impl
-    {typedef typename remove_reference<_Tp>::type* type;};
-template <class _Tp> struct __add_pointer_impl<_Tp, false> 
-    {typedef _Tp type;};
-
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_pointer
-    {typedef typename __add_pointer_impl<_Tp>::type type;};
+    {typedef typename remove_reference<_Tp>::type* type;};
 
 #if _LIBCPP_STD_VER > 11
 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
@@ -1177,11 +701,6 @@
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __libcpp_is_signed<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_signed_v
-    = is_signed<_Tp>::value;
-#endif
-
 // is_unsigned
 
 template <class _Tp, bool = is_integral<_Tp>::value>
@@ -1197,11 +716,6 @@
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __libcpp_is_unsigned<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_unsigned_v
-    = is_unsigned<_Tp>::value;
-#endif
-
 // rank
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank
@@ -1211,11 +725,6 @@
 template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[_Np]>
     : public integral_constant<size_t, rank<_Tp>::value + 1> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR size_t rank_v
-    = rank<_Tp>::value;
-#endif
-
 // extent
 
 template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS_ONLY extent
@@ -1229,11 +738,6 @@
 template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], _Ip>
     : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp, unsigned _Ip = 0> _LIBCPP_CONSTEXPR size_t extent_v
-    = extent<_Tp, _Ip>::value;
-#endif
-
 // remove_extent
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent
@@ -1300,11 +804,6 @@
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_abstract<_Tp> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_abstract_v
-    = is_abstract<_Tp>::value;
-#endif
-
 // is_final
 
 #if defined(_LIBCPP_HAS_IS_FINAL)
@@ -1320,11 +819,6 @@
 is_final : public integral_constant<bool, __is_final(_Tp)> {};
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_final_v
-    = is_final<_Tp>::value;
-#endif
-
 // is_base_of
 
 #ifdef _LIBCPP_HAS_IS_BASE_OF
@@ -1360,11 +854,6 @@
 
 #endif  // _LIBCPP_HAS_IS_BASE_OF
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Bp, class _Dp> _LIBCPP_CONSTEXPR bool is_base_of_v
-    = is_base_of<_Bp, _Dp>::value;
-#endif
-
 // is_convertible
 
 #if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
@@ -1384,9 +873,16 @@
 
 template <class _From, class _To>
 struct __is_convertible_test<_From, _To,
-    decltype(_VSTD::__is_convertible_imp::__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type
+    decltype(__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type
 {};
 
+template <class _Tp> __two __test(...);
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+template <class _Tp> _Tp&& __source();
+#else
+template <class _Tp> typename remove_reference<_Tp>::type& __source();
+#endif
+
 template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
                      bool _IsFunction = is_function<_Tp>::value,
                      bool _IsVoid =     is_void<_Tp>::value>
@@ -1426,6 +922,41 @@
     >
 {};
 
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
+
+template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<const _T1, const _T1&, 1, 0> : true_type {};
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
+#endif
+template <class _T1>            struct __is_convertible<_T1, _T1&, 2, 0>               : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
+
 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
 template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
@@ -1450,11 +981,6 @@
 
 #endif  // __has_feature(is_convertible_to)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _From, class _To> _LIBCPP_CONSTEXPR bool is_convertible_v
-    = is_convertible<_From, _To>::value;
-#endif
-
 // is_empty
 
 #if __has_feature(is_empty) || (_GNUC_VER >= 407)
@@ -1486,11 +1012,6 @@
 
 #endif  // __has_feature(is_empty)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_empty_v
-    = is_empty<_Tp>::value;
-#endif
-
 // is_polymorphic
 
 #if __has_feature(is_polymorphic) || defined(_LIBCPP_MSVC)
@@ -1511,11 +1032,6 @@
 
 #endif // __has_feature(is_polymorphic)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_polymorphic_v
-    = is_polymorphic<_Tp>::value;
-#endif
-
 // has_virtual_destructor
 
 #if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403)
@@ -1530,21 +1046,11 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
-    = has_virtual_destructor<_Tp>::value;
-#endif
-
 // alignment_of
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY alignment_of
     : public integral_constant<size_t, __alignof__(_Tp)> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR size_t alignment_of_v
-    = alignment_of<_Tp>::value;
-#endif
-
 // aligned_storage
 
 template <class _Hp, class _Tp>
@@ -1637,7 +1143,7 @@
     union type
     {
         _Aligner __align;
-        unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
+        unsigned char __data[_Len];
     };
 };
 
@@ -1652,7 +1158,7 @@
 {\
     struct _ALIGNAS(n) type\
     {\
-        unsigned char __lx[(_Len + n - 1)/n * n];\
+        unsigned char __lx[_Len];\
     };\
 }
 
@@ -1784,6 +1290,18 @@
 template <class _A1, class _A2 = void, class _A3 = void>
 class __promote : public __promote_imp<_A1, _A2, _A3> {};
 
+#ifdef _LIBCPP_STORE_AS_OPTIMIZATION
+
+// __transform
+
+template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
+template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
+template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
+template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
+template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
+
+#endif  // _LIBCPP_STORE_AS_OPTIMIZATION
+
 // make_signed / make_unsigned
 
 typedef
@@ -1964,19 +1482,21 @@
 template <class _Tp, class _Up>
 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, void>
 {
-    typedef typename decay<decltype(
-        true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
-      )>::type type;
+private:
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    static _Tp&& __t();
+    static _Up&& __u();
+#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    static _Tp __t();
+    static _Up __u();
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+public:
+    typedef typename remove_reference<decltype(true ? __t() : __u())>::type type;
 };
 
 #else  // _LIBCPP_HAS_NO_VARIADICS
 
-// bullet 1 - sizeof...(Tp) == 0
-
-template <class ..._Tp>
-struct _LIBCPP_TYPE_VIS_ONLY common_type {};
-
-// bullet 2 - sizeof...(Tp) == 1
+template <class ..._Tp> struct common_type;
 
 template <class _Tp>
 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp>
@@ -1984,45 +1504,22 @@
     typedef typename decay<_Tp>::type type;
 };
 
-// bullet 3 - sizeof...(Tp) == 2
-
-template <class _Tp, class _Up, class = void>
-struct __common_type2 {};
-
-template <class _Tp, class _Up>
-struct __common_type2<_Tp, _Up,
-    typename __void_t<decltype(
-        true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
-    )>::type>
-{
-    typedef typename decay<decltype(
-        true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
-    )>::type type;
-};
-
 template <class _Tp, class _Up>
 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up>
-    : __common_type2<_Tp, _Up> {};
-
-// bullet 4 - sizeof...(Tp) > 2
-
-template <class ...Tp> struct __common_types;
-
-template <class, class = void>
-struct __common_type_impl {};
-
-template <class _Tp, class _Up, class ..._Vp>
-struct __common_type_impl<__common_types<_Tp, _Up, _Vp...>,
-    typename __void_t<typename common_type<_Tp, _Up>::type>::type>
 {
-    typedef typename common_type<
-        typename common_type<_Tp, _Up>::type, _Vp...
-    >::type type;
+private:
+    static _Tp&& __t();
+    static _Up&& __u();
+    static bool __f();
+public:
+    typedef typename decay<decltype(__f() ? __t() : __u())>::type type;
 };
 
 template <class _Tp, class _Up, class ..._Vp>
 struct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, _Vp...>
-    : __common_type_impl<__common_types<_Tp, _Up, _Vp...> > {};
+{
+    typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
+};
 
 #if _LIBCPP_STD_VER > 11
 template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
@@ -2067,22 +1564,12 @@
 struct is_assignable
     : public __is_assignable_imp<_Tp, _Arg> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_assignable_v
-    = is_assignable<_Tp, _Arg>::value;
-#endif
-
 // is_copy_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
     : public is_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_assignable_v
-    = is_copy_assignable<_Tp>::value;
-#endif
-
 // is_move_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_move_assignable
@@ -2093,11 +1580,6 @@
     : public is_copy_assignable<_Tp> {};
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_assignable_v
-    = is_move_assignable<_Tp>::value;
-#endif
-
 // is_destructible
 
 //  if it's a reference, return true
@@ -2156,11 +1638,6 @@
 struct is_destructible<void>
     : public _VSTD::false_type {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_destructible_v
-    = is_destructible<_Tp>::value;
-#endif
-
 // move
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -2177,7 +1654,7 @@
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp&&
-forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
+forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
 {
     return static_cast<_Tp&&>(__t);
 }
@@ -2185,9 +1662,9 @@
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
 _Tp&&
-forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
+forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT
 {
-    static_assert(!is_lvalue_reference<_Tp>::value,
+    static_assert(!std::is_lvalue_reference<_Tp>::value,
                   "Can not forward an rvalue as an lvalue.");
     return static_cast<_Tp&&>(__t);
 }
@@ -2213,7 +1690,7 @@
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 _Tp&
-forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
+forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
 {
     return __t;
 }
@@ -2732,15 +2209,6 @@
 //     typedef ... _FnType;
 };
 
-
-template <class _DecayedFp>
-struct __member_pointer_class_type {};
-
-template <class _Ret, class _ClassType>
-struct __member_pointer_class_type<_Ret _ClassType::*> {
-  typedef _ClassType type;
-};
-
 // result_of
 
 template <class _Callable> class result_of;
@@ -3204,11 +2672,6 @@
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // __has_feature(is_constructible)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
-template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_constructible_v
-    = is_constructible<_Tp, _Args...>::value;
-#endif
-
 // is_default_constructible
 
 template <class _Tp>
@@ -3216,11 +2679,6 @@
     : public is_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_default_constructible_v
-    = is_default_constructible<_Tp>::value;
-#endif
-
 // is_copy_constructible
 
 template <class _Tp>
@@ -3228,11 +2686,6 @@
     : public is_constructible<_Tp, 
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_copy_constructible_v
-    = is_copy_constructible<_Tp>::value;
-#endif
-
 // is_move_constructible
 
 template <class _Tp>
@@ -3244,11 +2697,6 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_move_constructible_v
-    = is_move_constructible<_Tp>::value;
-#endif
-
 // is_trivially_constructible
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -3376,33 +2824,18 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
-template <class _Tp, class... _Args> _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
-    = is_trivially_constructible<_Tp, _Args...>::value;
-#endif
-
 // is_trivially_default_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_default_constructible
     : public is_trivially_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
-    = is_trivially_default_constructible<_Tp>::value;
-#endif
-
 // is_trivially_copy_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_constructible
     : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
-    = is_trivially_copy_constructible<_Tp>::value;
-#endif
-
 // is_trivially_move_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructible
@@ -3413,11 +2846,6 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
-    = is_trivially_move_constructible<_Tp>::value;
-#endif
-
 // is_trivially_assignable
 
 #if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
@@ -3456,22 +2884,12 @@
 
 #endif  // !__has_feature(is_trivially_assignable)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
-    = is_trivially_assignable<_Tp, _Arg>::value;
-#endif
-
 // is_trivially_copy_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
     : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
-    = is_trivially_copy_assignable<_Tp>::value;
-#endif
-
 // is_trivially_move_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable
@@ -3483,11 +2901,6 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
-    = is_trivially_move_assignable<_Tp>::value;
-#endif
-
 // is_trivially_destructible
 
 #if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
@@ -3509,11 +2922,6 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
-    = is_trivially_destructible<_Tp>::value;
-#endif
-
 // is_nothrow_constructible
 
 #if 0
@@ -3674,33 +3082,18 @@
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // __has_feature(is_nothrow_constructible)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
-template <class _Tp, class ..._Args> _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
-    = is_nothrow_constructible<_Tp, _Args...>::value;
-#endif
-
 // is_nothrow_default_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructible
     : public is_nothrow_constructible<_Tp>
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
-    = is_nothrow_default_constructible<_Tp>::value;
-#endif
-
 // is_nothrow_copy_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
     : public is_nothrow_constructible<_Tp,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
-    = is_nothrow_copy_constructible<_Tp>::value;
-#endif
-
 // is_nothrow_move_constructible
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible
@@ -3711,11 +3104,6 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v
-    = is_nothrow_move_constructible<_Tp>::value;
-#endif
-
 // is_nothrow_assignable
 
 #if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
@@ -3784,22 +3172,12 @@
 
 #endif  // __has_feature(cxx_noexcept)
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp, class _Arg> _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
-    = is_nothrow_assignable<_Tp, _Arg>::value;
-#endif
-
 // is_nothrow_copy_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
     : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
                   typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
-    = is_nothrow_copy_assignable<_Tp>::value;
-#endif
-
 // is_nothrow_move_assignable
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable
@@ -3811,11 +3189,6 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
-    = is_nothrow_move_assignable<_Tp>::value;
-#endif
-
 // is_nothrow_destructible
 
 #if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
@@ -3877,11 +3250,6 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
-    = is_nothrow_destructible<_Tp>::value;
-#endif
-
 // is_pod
 
 #if __has_feature(is_pod) || (_GNUC_VER >= 403)
@@ -3899,11 +3267,6 @@
 
 #endif
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_pod_v
-    = is_pod<_Tp>::value;
-#endif
-
 // is_literal_type;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type
@@ -3915,11 +3278,6 @@
 #endif
     {};
     
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_literal_type_v
-    = is_literal_type<_Tp>::value;
-#endif
-
 // is_standard_layout;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout
@@ -3930,11 +3288,6 @@
 #endif
     {};
     
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_standard_layout_v
-    = is_standard_layout<_Tp>::value;
-#endif
-
 // is_trivially_copyable;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable
@@ -3947,11 +3300,6 @@
 #endif
     {};
     
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
-    = is_trivially_copyable<_Tp>::value;
-#endif
-
 // is_trivial;
 
 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial
@@ -3963,17 +3311,7 @@
 #endif
     {};
 
-#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
-template <class _Tp> _LIBCPP_CONSTEXPR bool is_trivial_v
-    = is_trivial<_Tp>::value;
-#endif
-
-template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
-template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
-template <class _Tp> struct __is_reference_wrapper
-    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
-
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_VARIADICS
 
 // Check for complete types
 
@@ -4061,6 +3399,8 @@
 {
 };
 
+#if __has_feature(cxx_reference_qualified_functions)
+
 template <class _Rp, class _Class, class ..._Param>
 struct __check_complete<_Rp (_Class::*)(_Param...) &>
     : private __check_complete<_Class>
@@ -4109,257 +3449,125 @@
 {
 };
 
+#endif
+
 template <class _Rp, class _Class>
 struct __check_complete<_Rp _Class::*>
     : private __check_complete<_Class>
 {
 };
 
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type,
-         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
-using __enable_if_bullet1 = typename enable_if
-    <
-        is_member_function_pointer<_DecayFp>::value
-        && is_base_of<_ClassT, _DecayA0>::value
-    >::type;
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type>
-using __enable_if_bullet2 = typename enable_if
-    <
-        is_member_function_pointer<_DecayFp>::value
-        && __is_reference_wrapper<_DecayA0>::value
-    >::type;
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type,
-         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
-using __enable_if_bullet3 = typename enable_if
-    <
-        is_member_function_pointer<_DecayFp>::value
-        && !is_base_of<_ClassT, _DecayA0>::value
-        && !__is_reference_wrapper<_DecayA0>::value
-    >::type;
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type,
-         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
-using __enable_if_bullet4 = typename enable_if
-    <
-        is_member_object_pointer<_DecayFp>::value
-        && is_base_of<_ClassT, _DecayA0>::value
-    >::type;
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type>
-using __enable_if_bullet5 = typename enable_if
-    <
-        is_member_object_pointer<_DecayFp>::value
-        && __is_reference_wrapper<_DecayA0>::value
-    >::type;
-
-template <class _Fp, class _A0,
-         class _DecayFp = typename decay<_Fp>::type,
-         class _DecayA0 = typename decay<_A0>::type,
-         class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
-using __enable_if_bullet6 = typename enable_if
-    <
-        is_member_object_pointer<_DecayFp>::value
-        && !is_base_of<_ClassT, _DecayA0>::value
-        && !__is_reference_wrapper<_DecayA0>::value
-    >::type;
-
 // __invoke forward declarations
 
 // fall back - none of the bullets
 
-#define _LIBCPP_INVOKE_RETURN(...) \
-    noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
-    { return __VA_ARGS__; }
-
 template <class ..._Args>
-auto __invoke(__any, _Args&& ...__args) -> __nat;
+auto
+__invoke(__any, _Args&& ...__args)
+    -> __nat;
 
-template <class ..._Args>
-auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
-
-// bullets 1, 2 and 3
+// bullets 1 and 2
 
 template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet1<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
+            class = typename enable_if
+            <
+                is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
+                is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
+    -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...));
 
 template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet1<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
-
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet2<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
+            class = typename enable_if
+            <
+                is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
+                !is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
+    -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
 
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet2<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
-
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet3<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-auto
-__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
-
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet3<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
-
-// bullets 4, 5 and 6
+// bullets 3 and 4
 
 template <class _Fp, class _A0,
-          class = __enable_if_bullet4<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
+            class = typename enable_if
+            <
+                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
+                is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
+    -> decltype(_VSTD::forward<_A0>(__a0).*__f);
 
 template <class _Fp, class _A0,
-          class = __enable_if_bullet4<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
-
-template <class _Fp, class _A0,
-          class = __enable_if_bullet5<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
+            class = typename enable_if
+            <
+                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
+                !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
+                           typename remove_reference<_A0>::type>::value
+            >::type
+         >
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
+    -> decltype((*_VSTD::forward<_A0>(__a0)).*__f);
 
-template <class _Fp, class _A0,
-          class = __enable_if_bullet5<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
-
-template <class _Fp, class _A0,
-          class = __enable_if_bullet6<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-auto
-__invoke(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
-
-template <class _Fp, class _A0,
-          class = __enable_if_bullet6<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
-
-// bullet 7
+// bullet 5
 
 template <class _Fp, class ..._Args>
-inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY
 auto
 __invoke(_Fp&& __f, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
-
-template <class _Fp, class ..._Args>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
-_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
-
-#undef _LIBCPP_INVOKE_RETURN
+    -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...));
 
 // __invokable
 
-template <class _Ret, class _Fp, class ..._Args>
-struct __invokable_r
+template <class _Fp, class ..._Args>
+struct __invokable_imp
     : private __check_complete<_Fp>
 {
-    using _Result = decltype(
-        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
-
-    static const bool value =
-        conditional<
-            !is_same<_Result, __nat>::value,
-            typename conditional<
-                is_void<_Ret>::value,
-                true_type,
-                is_convertible<_Result, _Ret>
-            >::type,
-            false_type
-        >::type::value;
+    typedef decltype(
+            __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
+                    ) type;
+    static const bool value = !is_same<type, __nat>::value;
 };
 
 template <class _Fp, class ..._Args>
-using __invokable = __invokable_r<void, _Fp, _Args...>;
-
-template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
-struct __nothrow_invokable_r_imp {
-  static const bool value = false;
-};
-
-template <class _Ret, class _Fp, class ..._Args>
-struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
+struct __invokable
+    : public integral_constant<bool,
+          __invokable_imp<_Fp, _Args...>::value>
 {
-    typedef __nothrow_invokable_r_imp _ThisT;
-
-    template <class _Tp>
-    static void __test_noexcept(_Tp) noexcept;
-
-    static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
-        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)));
 };
 
-template <class _Ret, class _Fp, class ..._Args>
-struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
+// __invoke_of
+
+template <bool _Invokable, class _Fp, class ..._Args>
+struct __invoke_of_imp  // false
 {
-    static const bool value = noexcept(
-        _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
 };
 
-template <class _Ret, class _Fp, class ..._Args>
-using __nothrow_invokable_r =
-    __nothrow_invokable_r_imp<
-            __invokable_r<_Ret, _Fp, _Args...>::value,
-            is_void<_Ret>::value,
-            _Ret, _Fp, _Args...
-    >;
+template <class _Fp, class ..._Args>
+struct __invoke_of_imp<true, _Fp, _Args...>
+{
+    typedef typename __invokable_imp<_Fp, _Args...>::type type;
+};
 
 template <class _Fp, class ..._Args>
 struct __invoke_of
-    : public enable_if<
-        __invokable<_Fp, _Args...>::value,
-        typename __invokable_r<void, _Fp, _Args...>::_Result>
+    : public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...>
 {
 };
 
-// result_of
-
 template <class _Fp, class ..._Args>
 class _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)>
     : public __invoke_of<_Fp, _Args...>
@@ -4370,39 +3578,7 @@
 template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
 #endif
 
-#if _LIBCPP_STD_VER > 14
-
-// is_callable
-
-template <class _Fn, class _Ret = void>
-struct _LIBCPP_TYPE_VIS_ONLY is_callable;
-
-template <class _Fn, class ..._Args, class _Ret>
-struct _LIBCPP_TYPE_VIS_ONLY is_callable<_Fn(_Args...), _Ret>
-    : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
-
-template <class _Fn, class _Ret = void>
-constexpr bool is_callable_v = is_callable<_Fn, _Ret>::value;
-
-// is_nothrow_callable
-
-template <class _Fn, class _Ret = void>
-struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable;
-
-template <class _Fn, class ..._Args, class _Ret>
-struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable<_Fn(_Args...), _Ret>
-    : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value>
-{};
-
-template <class _Fn, class _Ret = void>
-constexpr bool is_nothrow_callable_v = is_nothrow_callable<_Fn, _Ret>::value;
-
-#endif // _LIBCPP_STD_VER > 14
-
-#endif  // !defined(_LIBCPP_CXX03_LANG)
-
-template <class _Tp> struct __is_swappable;
-template <class _Tp> struct __is_nothrow_swappable;
+#endif  // _LIBCPP_HAS_NO_VARIADICS
 
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -4423,13 +3599,6 @@
     __y = _VSTD::move(__t);
 }
 
-template<class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Tp>::value
->::type
-swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
-
 template <class _ForwardIterator1, class _ForwardIterator2>
 inline _LIBCPP_INLINE_VISIBILITY
 void
@@ -4445,103 +3614,55 @@
 
 namespace __detail
 {
-// ALL generic swap overloads MUST already have a declaration available at this point.
+
 using _VSTD::swap;
 __nat swap(__any, __any);
 
-template <class _Tp, class _Up = _Tp,
-          bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
-struct __swappable_with
+template <class _Tp>
+struct __swappable
 {
-    typedef decltype(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>())) __swap1;
-    typedef decltype(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>())) __swap2;
-
-    static const bool value = !is_same<__swap1, __nat>::value
-                           && !is_same<__swap2, __nat>::value;
+    typedef decltype(swap(_VSTD::declval<_Tp&>(), _VSTD::declval<_Tp&>())) type;
+    static const bool value = !is_same<type, __nat>::value;
 };
 
-template <class _Tp, class _Up>
-struct __swappable_with<_Tp, _Up,  false> : false_type {};
-
-template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
-struct __nothrow_swappable_with {
-  static const bool value =
-#ifndef _LIBCPP_HAS_NO_NOEXCEPT
-      noexcept(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>()))
-  &&  noexcept(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>()));
-#else
-      false;
-#endif
-};
-
-template <class _Tp, class _Up>
-struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
-
 }  // __detail
 
 template <class _Tp>
 struct __is_swappable
-    : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
+    : public integral_constant<bool, __detail::__swappable<_Tp>::value>
+{
+};
+
+#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
+
+template <bool, class _Tp>
+struct __is_nothrow_swappable_imp
+    : public integral_constant<bool, noexcept(swap(_VSTD::declval<_Tp&>(),
+                                                   _VSTD::declval<_Tp&>()))>
+{
+};
+
+template <class _Tp>
+struct __is_nothrow_swappable_imp<false, _Tp>
+    : public false_type
 {
 };
 
 template <class _Tp>
 struct __is_nothrow_swappable
-    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
+    : public __is_nothrow_swappable_imp<__is_swappable<_Tp>::value, _Tp>
 {
 };
 
-#if _LIBCPP_STD_VER > 14
-
-template <class _Tp, class _Up>
-struct _LIBCPP_TYPE_VIS_ONLY is_swappable_with
-    : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
-{
-};
+#else  // __has_feature(cxx_noexcept)
 
 template <class _Tp>
-struct _LIBCPP_TYPE_VIS_ONLY is_swappable
-    : public conditional<
-        __is_referenceable<_Tp>::value,
-        is_swappable_with<
-            typename add_lvalue_reference<_Tp>::type,
-            typename add_lvalue_reference<_Tp>::type>,
-        false_type
-    >::type
+struct __is_nothrow_swappable
+    : public false_type
 {
 };
 
-template <class _Tp, class _Up>
-struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_swappable_with
-    : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
-{
-};
-
-template <class _Tp>
-struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_swappable
-    : public conditional<
-        __is_referenceable<_Tp>::value,
-        is_nothrow_swappable_with<
-            typename add_lvalue_reference<_Tp>::type,
-            typename add_lvalue_reference<_Tp>::type>,
-        false_type
-    >::type
-{
-};
-
-template <class _Tp, class _Up>
-constexpr bool is_swappable_with_v = is_swappable_with<_Tp, _Up>::value;
-
-template <class _Tp>
-constexpr bool is_swappable_v = is_swappable<_Tp>::value;
-
-template <class _Tp, class _Up>
-constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<_Tp, _Up>::value;
-
-template <class _Tp>
-constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<_Tp>::value;
-
-#endif // _LIBCPP_STD_VER > 14
+#endif  // __has_feature(cxx_noexcept)
 
 #ifdef _LIBCPP_UNDERLYING_TYPE
 
@@ -4568,7 +3689,7 @@
 #endif // _LIBCPP_UNDERLYING_TYPE
 
 
-template <class _Tp, bool = is_enum<_Tp>::value>
+template <class _Tp, bool = std::is_enum<_Tp>::value>
 struct __sfinae_underlying_type
 {
     typedef typename underlying_type<_Tp>::type type;
@@ -4578,34 +3699,34 @@
 template <class _Tp>
 struct __sfinae_underlying_type<_Tp, false> {};
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 int __convert_to_integral(int __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 unsigned __convert_to_integral(unsigned __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 long __convert_to_integral(long __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 unsigned long __convert_to_integral(unsigned long __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 long long __convert_to_integral(long long __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
 
 #ifndef _LIBCPP_HAS_NO_INT128
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 __int128_t __convert_to_integral(__int128_t __val) { return __val; }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 __uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
 #endif
 
 template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
 typename __sfinae_underlying_type<_Tp>::__promoted_type
 __convert_to_integral(_Tp __val) { return __val; }
 
@@ -4645,53 +3766,6 @@
 
 #if _LIBCPP_STD_VER > 14
 template <class...> using void_t = void;
-
-# ifndef _LIBCPP_HAS_NO_VARIADICS
-template <class... _Args>
-struct conjunction : __and_<_Args...> {};
-template<class... _Args> constexpr bool conjunction_v = conjunction<_Args...>::value;
-
-template <class... _Args>
-struct disjunction : __or_<_Args...> {};
-template<class... _Args> constexpr bool disjunction_v = disjunction<_Args...>::value;
-
-template <class _Tp>
-struct negation : __not_<_Tp> {};
-template<class _Tp> constexpr bool negation_v = negation<_Tp>::value;
-# endif // _LIBCPP_HAS_NO_VARIADICS
-#endif  // _LIBCPP_STD_VER > 14
-
-// These traits are used in __tree and __hash_table
-#ifndef _LIBCPP_CXX03_LANG
-struct __extract_key_fail_tag {};
-struct __extract_key_self_tag {};
-struct __extract_key_first_tag {};
-
-template <class _ValTy, class _Key,
-          class _RawValTy = typename __unconstref<_ValTy>::type>
-struct __can_extract_key
-    : conditional<is_same<_RawValTy, _Key>::value, __extract_key_self_tag,
-                  __extract_key_fail_tag>::type {};
-
-template <class _Pair, class _Key, class _First, class _Second>
-struct __can_extract_key<_Pair, _Key, pair<_First, _Second>>
-    : conditional<is_same<typename remove_const<_First>::type, _Key>::value,
-                  __extract_key_first_tag, __extract_key_fail_tag>::type {};
-
-// __can_extract_map_key uses true_type/false_type instead of the tags.
-// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
-// and _ValTy == _Key.
-template <class _ValTy, class _Key, class _ContainerValueTy,
-          class _RawValTy = typename __unconstref<_ValTy>::type>
-struct __can_extract_map_key
-    : integral_constant<bool, is_same<_RawValTy, _Key>::value> {};
-
-// This specialization returns __extract_key_fail_tag for non-map containers
-// because _Key == _ContainerValueTy
-template <class _ValTy, class _Key, class _RawValTy>
-struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
-    : false_type {};
-
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/include/unordered_map b/include/unordered_map
index 319c71e..cf70ab6 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -369,7 +369,6 @@
 #include <__hash_table>
 #include <functional>
 #include <stdexcept>
-#include <tuple>
 
 #include <__debug>
 
@@ -414,6 +413,7 @@
 class __unordered_map_hasher<_Key, _Cp, _Hash, false>
 {
     _Hash __hash_;
+
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_hasher()
@@ -487,6 +487,7 @@
 class __unordered_map_equal<_Key, _Cp, _Pred, false>
 {
     _Pred __pred_;
+
 public:
     _LIBCPP_INLINE_VISIBILITY
     __unordered_map_equal()
@@ -530,11 +531,12 @@
 {
     typedef _Alloc                              allocator_type;
     typedef allocator_traits<allocator_type>    __alloc_traits;
-
+    typedef typename __alloc_traits::value_type::value_type value_type;
 public:
-
-    typedef typename __alloc_traits::pointer       pointer;
+    typedef typename __alloc_traits::pointer    pointer;
 private:
+    typedef typename value_type::value_type::first_type     first_type;
+    typedef typename value_type::value_type::second_type    second_type;
 
     allocator_type& __na_;
 
@@ -584,7 +586,8 @@
     }
 };
 
-#ifndef _LIBCPP_CXX03_LANG
+#if __cplusplus >= 201103L
+
 template <class _Key, class _Tp>
 union __hash_value_type
 {
@@ -596,6 +599,19 @@
     value_type __cc;
     __nc_value_type __nc;
 
+    template <class ..._Args>
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type(_Args&& ...__args)
+        : __cc(std::forward<_Args>(__args)...) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type(const __hash_value_type& __v)
+        : __cc(__v.__cc) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type(__hash_value_type&& __v)
+        : __nc(_VSTD::move(__v.__nc)) {}
+
     _LIBCPP_INLINE_VISIBILITY
     __hash_value_type& operator=(const __hash_value_type& __v)
         {__nc = __v.__cc; return *this;}
@@ -604,23 +620,8 @@
     __hash_value_type& operator=(__hash_value_type&& __v)
         {__nc = _VSTD::move(__v.__nc); return *this;}
 
-    template <class _ValueTp,
-              class = typename enable_if<
-                    __is_same_uncvref<_ValueTp, value_type>::value
-                 >::type
-             >
     _LIBCPP_INLINE_VISIBILITY
-    __hash_value_type& operator=(_ValueTp&& __v) {
-        __nc = _VSTD::forward<_ValueTp>(__v); return *this;
-    }
-
-private:
-    __hash_value_type(const __hash_value_type& __v) = delete;
-    __hash_value_type(__hash_value_type&& __v) = delete;
-    template <class ..._Args>
-    explicit __hash_value_type(_Args&& ...__args) = delete;
-
-    ~__hash_value_type() = delete;
+    ~__hash_value_type() {__cc.~value_type();}
 };
 
 #else
@@ -634,8 +635,18 @@
 
     value_type __cc;
 
-private:
-   ~__hash_value_type();
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type() {}
+
+    template <class _A0>
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type(const _A0& __a0)
+        : __cc(__a0) {}
+
+    template <class _A0, class _A1>
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_value_type(const _A0& __a0, const _A1& __a1)
+        : __cc(__a0, __a1) {}
 };
 
 #endif
@@ -645,14 +656,21 @@
 {
     _HashIterator __i_;
 
-    typedef  __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
-
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::value_type::second_type      mapped_type;
 public:
     typedef forward_iterator_tag                                 iterator_category;
-    typedef typename _NodeTypes::__map_value_type                value_type;
-    typedef typename _NodeTypes::difference_type                 difference_type;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::difference_type              difference_type;
     typedef value_type&                                          reference;
-    typedef typename _NodeTypes::__map_value_type_pointer       pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_map_iterator() _NOEXCEPT {}
@@ -694,14 +712,21 @@
 {
     _HashIterator __i_;
 
-    typedef  __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
-
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::value_type::second_type      mapped_type;
 public:
     typedef forward_iterator_tag                                 iterator_category;
-    typedef typename _NodeTypes::__map_value_type                value_type;
-    typedef typename _NodeTypes::difference_type                 difference_type;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::difference_type              difference_type;
     typedef const value_type&                                    reference;
-    typedef typename _NodeTypes::__const_map_value_type_pointer  pointer;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                                 pointer;
 
     _LIBCPP_INLINE_VISIBILITY
     __hash_map_const_iterator() _NOEXCEPT {}
@@ -772,7 +797,6 @@
 
     __table __table_;
 
-    typedef typename __table::_NodeTypes                   _NodeTypes;
     typedef typename __table::__node_pointer               __node_pointer;
     typedef typename __table::__node_const_pointer         __node_const_pointer;
     typedef typename __table::__node_traits                __node_traits;
@@ -781,14 +805,11 @@
     typedef __hash_map_node_destructor<__node_allocator>   _Dp;
     typedef unique_ptr<__node, _Dp>                         __node_holder;
     typedef allocator_traits<allocator_type>               __alloc_traits;
-
-    static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
-    static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
 public:
     typedef typename __alloc_traits::pointer         pointer;
     typedef typename __alloc_traits::const_pointer   const_pointer;
-    typedef typename __table::size_type              size_type;
-    typedef typename __table::difference_type        difference_type;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
 
     typedef __hash_map_iterator<typename __table::iterator>       iterator;
     typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
@@ -819,12 +840,10 @@
                       size_type __n, const hasher& __hf,
                       const key_equal& __eql,
                       const allocator_type& __a);
-    _LIBCPP_INLINE_VISIBILITY
     explicit unordered_map(const allocator_type& __a);
     unordered_map(const unordered_map& __u);
     unordered_map(const unordered_map& __u, const allocator_type& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_map(unordered_map&& __u)
         _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
     unordered_map(unordered_map&& __u, const allocator_type& __a);
@@ -880,12 +899,10 @@
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_map& operator=(unordered_map&& __u)
         _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
 #endif
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     unordered_map& operator=(initializer_list<value_type> __il);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
@@ -913,162 +930,189 @@
     _LIBCPP_INLINE_VISIBILITY
     const_iterator cend()   const _NOEXCEPT {return __table_.end();}
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+    template <class... _Args>
+        pair<iterator, bool> emplace(_Args&&... __args);
+
+    template <class... _Args>
+        _LIBCPP_INLINE_VISIBILITY
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        iterator emplace_hint(const_iterator __p, _Args&&... __args)
+        {
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+                "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
+                " referring to this unordered_map");
+            return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
+        }
+#else
+        iterator emplace_hint(const_iterator, _Args&&... __args)
+            {return emplace(_VSTD::forward<_Args>(__args)...).first;}
+#endif
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     pair<iterator, bool> insert(const value_type& __x)
         {return __table_.__insert_unique(__x);}
-
-    iterator insert(const_iterator __p, const value_type& __x) {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
-            " referring to this unordered_map");
-#endif
-        return insert(__x).first;
-    }
-
-    template <class _InputIterator>
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _Pp,
+              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
         _LIBCPP_INLINE_VISIBILITY
+        pair<iterator, bool> insert(_Pp&& __x)
+            {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    _LIBCPP_INLINE_VISIBILITY
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    iterator insert(const_iterator __p, const value_type& __x)
+        {
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+                "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
+                " referring to this unordered_map");
+            return insert(__x).first;
+        }
+#else
+    iterator insert(const_iterator, const value_type& __x)
+        {return insert(__x).first;}
+#endif
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _Pp,
+              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
+        _LIBCPP_INLINE_VISIBILITY
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        iterator insert(const_iterator __p, _Pp&& __x)
+        {
+            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+                "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
+                " referring to this unordered_map");
+            return insert(_VSTD::forward<_Pp>(__x)).first;
+        }
+#else
+        iterator insert(const_iterator, _Pp&& __x)
+            {return insert(_VSTD::forward<_Pp>(__x)).first;}
+#endif
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _InputIterator>
         void insert(_InputIterator __first, _InputIterator __last);
-
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
     void insert(initializer_list<value_type> __il)
         {insert(__il.begin(), __il.end());}
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> insert(value_type&& __x)
-        {return __table_.__insert_unique(_VSTD::move(__x));}
-
-    iterator insert(const_iterator __p, value_type&& __x) {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
-            " referring to this unordered_map");
-#endif
-        return __table_.__insert_unique(_VSTD::move(__x)).first;
-    }
-
-    template <class _Pp,
-              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        pair<iterator, bool> insert(_Pp&& __x)
-            {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
-
-    template <class _Pp,
-              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        iterator insert(const_iterator __p, _Pp&& __x)
-        {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-                "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
-                " referring to this unordered_map");
-#endif
-            return insert(_VSTD::forward<_Pp>(__x)).first;
-        }
-
-    template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, bool> emplace(_Args&&... __args) {
-        return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
-    }
-
-    template <class... _Args>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator emplace_hint(const_iterator __p, _Args&&... __args) {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
-            " referring to this unordered_map");
-#endif
-        return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
-    }
-
-#endif  // _LIBCPP_CXX03_LANG
-
 #if _LIBCPP_STD_VER > 14
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
     {
-        return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
-            _VSTD::forward_as_tuple(__k),
-            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+            return _VSTD::make_pair(__p, false);
+        else
+            return _VSTD::make_pair(
+                      emplace_hint(__p, 
+                        _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), 
+                        _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
+                      true);
     }
 
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
     {
-        return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
-            _VSTD::forward_as_tuple(_VSTD::move(__k)),
-            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+            return _VSTD::make_pair(__p, false);
+        else
+            return _VSTD::make_pair(
+                      emplace_hint(__p, 
+                        _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), 
+                        _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
+                      true);
     }
 
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
-            " referring to this unordered_map");
-#endif
-            return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+            return __p;
+        else
+            return emplace_hint(__h, 
+                      _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), 
+                      _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
     }
 
     template <class... _Args>
         _LIBCPP_INLINE_VISIBILITY
         iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
     {
-#if _LIBCPP_DEBUG_LEVEL >= 2
-        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
-            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
-            " referring to this unordered_map");
-#endif
-        return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+            return __p;
+        else
+            return emplace_hint(__h, 
+                      _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), 
+                      _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
     }
 
     template <class _Vp>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
     {
-        pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
-            __k, _VSTD::forward<_Vp>(__v));
-        if (!__res.second) {
-            __res.first->second = _VSTD::forward<_Vp>(__v);
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+        {
+            __p->second = _VSTD::move(__v);
+            return _VSTD::make_pair(__p, false);
         }
-        return __res;
+        return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
     }
-
+        
     template <class _Vp>
         _LIBCPP_INLINE_VISIBILITY
         pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
     {
-        pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
-            _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
-        if (!__res.second) {
-            __res.first->second = _VSTD::forward<_Vp>(__v);
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+        {
+            __p->second = _VSTD::move(__v);
+            return _VSTD::make_pair(__p, false);
         }
-        return __res;
+        return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
     }
 
     template <class _Vp>
         _LIBCPP_INLINE_VISIBILITY
         iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
      {
-          return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+        {
+            __p->second = _VSTD::move(__v);
+            return __p;
+        }
+        return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
      }
 
     template <class _Vp>
         _LIBCPP_INLINE_VISIBILITY
         iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
      {
-        return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
+        iterator __p = __table_.find(__k);
+        if ( __p != end())
+        {
+            __p->second = _VSTD::move(__v);
+            return __p;
+        }
+        return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
      }
 #endif
+#endif
+#endif
 
     _LIBCPP_INLINE_VISIBILITY
     iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
@@ -1108,7 +1152,7 @@
         {return __table_.__equal_range_unique(__k);}
 
     mapped_type& operator[](const key_type& __k);
-#ifndef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     mapped_type& operator[](key_type&& __k);
 #endif
 
@@ -1164,10 +1208,18 @@
 #endif  // _LIBCPP_DEBUG_LEVEL >= 2
 
 private:
-
-#ifdef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
+    __node_holder __construct_node_with_key(key_type&& __k);
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     __node_holder __construct_node_with_key(const key_type& __k);
-#endif
 };
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -1194,7 +1246,7 @@
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         const allocator_type& __a)
     : __table_(__a)
@@ -1270,7 +1322,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
         unordered_map&& __u)
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
@@ -1293,10 +1345,10 @@
     if (__a != __u.get_allocator())
     {
         iterator __i = __u.begin();
-        while (__u.size() != 0) {
-            __table_.__emplace_unique(_VSTD::move(
-                __u.__table_.remove((__i++).__i_)->__value_.__nc));
-        }
+        while (__u.size() != 0)
+            __table_.__insert_unique(
+                _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
+                                    );
     }
 #if _LIBCPP_DEBUG_LEVEL >= 2
     else
@@ -1349,7 +1401,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
     _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
@@ -1363,7 +1415,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
         initializer_list<value_type> __il)
@@ -1374,7 +1426,81 @@
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-#ifdef _LIBCPP_CXX03_LANG
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class _A1, class ..._Args>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
+                                                                 _A1&& __a1,
+                                                                 _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class... _Args>
+pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
@@ -1385,13 +1511,12 @@
     __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
+    return _VSTD::move(__h);  // explicitly moved for C++03
 }
-#endif
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                        _InputIterator __last)
@@ -1400,7 +1525,6 @@
         __table_.__insert_unique(*__first);
 }
 
-#ifdef _LIBCPP_CXX03_LANG
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 _Tp&
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
@@ -1413,27 +1537,23 @@
     __h.release();
     return __r.first->second;
 }
-#else
 
-template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-_Tp&
-unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
-{
-    return __table_.__emplace_unique_key_args(__k,
-        std::piecewise_construct, std::forward_as_tuple(__k),
-                                  std::forward_as_tuple()).first->__cc.second;
-}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 _Tp&
 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
 {
-    return __table_.__emplace_unique_key_args(__k,
-        std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
-                                  std::forward_as_tuple()).first->__cc.second;
+    iterator __i = find(__k);
+    if (__i != end())
+        return __i->second;
+    __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    __h.release();
+    return __r.first->second;
 }
 
-#endif  // !_LIBCPP_CXX03_MODE
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 _Tp&
@@ -1527,21 +1647,17 @@
 
     __table __table_;
 
-    typedef typename __table::_NodeTypes                   _NodeTypes;
     typedef typename __table::__node_traits                __node_traits;
     typedef typename __table::__node_allocator             __node_allocator;
     typedef typename __table::__node                       __node;
     typedef __hash_map_node_destructor<__node_allocator>   _Dp;
     typedef unique_ptr<__node, _Dp>                         __node_holder;
     typedef allocator_traits<allocator_type>               __alloc_traits;
-    static_assert((is_same<typename __node_traits::size_type,
-                          typename __alloc_traits::size_type>::value),
-                 "Allocator uses different size_type for different types");
 public:
     typedef typename __alloc_traits::pointer         pointer;
     typedef typename __alloc_traits::const_pointer   const_pointer;
-    typedef typename __table::size_type              size_type;
-    typedef typename __table::difference_type        difference_type;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
 
     typedef __hash_map_iterator<typename __table::iterator>       iterator;
     typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
@@ -1572,12 +1688,10 @@
                       size_type __n, const hasher& __hf,
                       const key_equal& __eql,
                       const allocator_type& __a);
-    _LIBCPP_INLINE_VISIBILITY
     explicit unordered_multimap(const allocator_type& __a);
     unordered_multimap(const unordered_multimap& __u);
     unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_multimap(unordered_multimap&& __u)
         _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
     unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
@@ -1634,12 +1748,10 @@
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_multimap& operator=(unordered_multimap&& __u)
         _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
 #endif
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     unordered_multimap& operator=(initializer_list<value_type> __il);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
@@ -1667,55 +1779,43 @@
     _LIBCPP_INLINE_VISIBILITY
     const_iterator cend()   const _NOEXCEPT {return __table_.end();}
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+    template <class... _Args>
+        iterator emplace(_Args&&... __args);
+
+    template <class... _Args>
+        iterator emplace_hint(const_iterator __p, _Args&&... __args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
-
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _Pp,
+              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
+        _LIBCPP_INLINE_VISIBILITY
+        iterator insert(_Pp&& __x)
+            {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     iterator insert(const_iterator __p, const value_type& __x)
         {return __table_.__insert_multi(__p.__i_, __x);}
-
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    template <class _Pp,
+              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
+        _LIBCPP_INLINE_VISIBILITY
+        iterator insert(const_iterator __p, _Pp&& __x)
+            {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _InputIterator>
-    _LIBCPP_INLINE_VISIBILITY
-    void insert(_InputIterator __first, _InputIterator __last);
-
+        void insert(_InputIterator __first, _InputIterator __last);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
     void insert(initializer_list<value_type> __il)
         {insert(__il.begin(), __il.end());}
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
-#ifndef _LIBCPP_CXX03_LANG
-    _LIBCPP_INLINE_VISIBILITY
-    iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
-
-    _LIBCPP_INLINE_VISIBILITY
-    iterator insert(const_iterator __p, value_type&& __x)
-        {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
-
-    template <class _Pp,
-              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator insert(_Pp&& __x)
-        {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
-
-    template <class _Pp,
-              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator insert(const_iterator __p, _Pp&& __x)
-        {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
-
-    template <class... _Args>
-    iterator emplace(_Args&&... __args) {
-        return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
-    }
-
-    template <class... _Args>
-    iterator emplace_hint(const_iterator __p, _Args&&... __args) {
-        return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
-    }
-#endif  // _LIBCPP_CXX03_LANG
-
-
     _LIBCPP_INLINE_VISIBILITY
     iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
     _LIBCPP_INLINE_VISIBILITY
@@ -1802,7 +1902,17 @@
 
 #endif  // _LIBCPP_DEBUG_LEVEL >= 2
 
-
+private:
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __node_holder __construct_node();
+    template <class _A0>
+        __node_holder
+         __construct_node(_A0&& __a0);
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _A0, class _A1, class ..._Args>
+        __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -1868,7 +1978,7 @@
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         const allocator_type& __a)
     : __table_(__a)
@@ -1905,7 +2015,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
         unordered_multimap&& __u)
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
@@ -1931,7 +2041,7 @@
         while (__u.size() != 0)
         {
             __table_.__insert_multi(
-                      _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
+                _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
                                    );
         }
     }
@@ -1986,7 +2096,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
     _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
@@ -2000,7 +2110,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
         initializer_list<value_type> __il)
@@ -2011,11 +2121,81 @@
 
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class _A1, class ..._Args>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
+        _A0&& __a0, _A1&& __a1, _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
+                             _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
+                             _VSTD::forward<_Args>(__args)...);
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class... _Args>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __table_.__node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class... _Args>
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
+        const_iterator __p, _Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                             _InputIterator __last)
diff --git a/include/unordered_set b/include/unordered_set
index fb38b64..f6ccdc3 100644
--- a/include/unordered_set
+++ b/include/unordered_set
@@ -404,12 +404,10 @@
                       size_type __n, const hasher& __hf, const allocator_type& __a)
             : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     explicit unordered_set(const allocator_type& __a);
     unordered_set(const unordered_set& __u);
     unordered_set(const unordered_set& __u, const allocator_type& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_set(unordered_set&& __u)
         _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
     unordered_set(unordered_set&& __u, const allocator_type& __a);
@@ -441,12 +439,10 @@
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_set& operator=(unordered_set&& __u)
         _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
 #endif
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     unordered_set& operator=(initializer_list<value_type> __il);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
@@ -531,7 +527,6 @@
 #endif
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
@@ -683,7 +678,7 @@
 }
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         const allocator_type& __a)
     : __table_(__a)
@@ -720,7 +715,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
         unordered_set&& __u)
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
@@ -797,7 +792,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_set<_Value, _Hash, _Pred, _Alloc>&
 unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
     _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
@@ -811,7 +806,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_set<_Value, _Hash, _Pred, _Alloc>&
 unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
         initializer_list<value_type> __il)
@@ -824,7 +819,7 @@
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                     _InputIterator __last)
@@ -945,12 +940,10 @@
                        size_type __n, const hasher& __hf, const allocator_type& __a)
         : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
 #endif
-    _LIBCPP_INLINE_VISIBILITY
     explicit unordered_multiset(const allocator_type& __a);
     unordered_multiset(const unordered_multiset& __u);
     unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_multiset(unordered_multiset&& __u)
         _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
     unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
@@ -980,7 +973,6 @@
         return *this;
     }
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     unordered_multiset& operator=(unordered_multiset&& __u)
         _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
 #endif
@@ -1037,7 +1029,6 @@
         {return __table_.__insert_multi(__p, _VSTD::move(__x));}
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     template <class _InputIterator>
-        _LIBCPP_INLINE_VISIBILITY
         void insert(_InputIterator __first, _InputIterator __last);
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
@@ -1190,7 +1181,7 @@
 }
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         const allocator_type& __a)
     : __table_(__a)
@@ -1227,7 +1218,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
         unordered_multiset&& __u)
     _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
@@ -1304,7 +1295,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
         unordered_multiset&& __u)
@@ -1332,7 +1323,7 @@
 
 template <class _Value, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
                                                          _InputIterator __last)
diff --git a/include/utility b/include/utility
index 27b81a0..54cfc8b 100644
--- a/include/utility
+++ b/include/utility
@@ -52,9 +52,6 @@
     >::type
     move_if_noexcept(T& x) noexcept; // constexpr in C++14
 
-template <class T> constexpr add_const<T>_t& as_const(T& t) noexcept;      // C++17
-template <class T>                      void as_const(const T&&) = delete; // C++17
-
 template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
 
 template <class T1, class T2>
@@ -82,8 +79,8 @@
                                        is_nothrow_move_assignable<T2>::value);
     template <class U, class V> pair& operator=(pair<U, V>&& p);
 
-    void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
-                                is_nothrow_swappable_v<T2>);
+    void swap(pair& p) noexcept(noexcept(swap(first, p.first)) &&
+                                noexcept(swap(second, p.second)));
 };
 
 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
@@ -113,41 +110,22 @@
     get(pair<T1, T2>&) noexcept; // constexpr in C++14
 
 template<size_t I, class T1, class T2>
-    const typename tuple_element<I, pair<T1, T2> >::type&
+    const typename const tuple_element<I, pair<T1, T2> >::type&
     get(const pair<T1, T2>&) noexcept; // constexpr in C++14
 
 template<size_t I, class T1, class T2>
     typename tuple_element<I, pair<T1, T2> >::type&&
     get(pair<T1, T2>&&) noexcept; // constexpr in C++14
 
-template<size_t I, class T1, class T2>
-    const typename tuple_element<I, pair<T1, T2> >::type&&
-    get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
-
 template<class T1, class T2>
     constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
 
-template<class T1, class T2>
-    constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
+template<size_t I, class T1, class T2>
+    constexpr T1 const& get(pair<T1, T2> const &) noexcept; // C++14
 
-template<class T1, class T2>
+template<size_t I, class T1, class T2>
     constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
 
-template<class T1, class T2>
-    constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
-
-template<class T1, class T2>
-    constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
-
-template<class T1, class T2>
-    constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
-
-template<class T1, class T2>
-    constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
-
-template<class T1, class T2>
-    constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
-
 // C++14
 
 template<class T, T... I>
@@ -178,7 +156,6 @@
 #include <__config>
 #include <__tuple>
 #include <type_traits>
-#include <initializer_list>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -225,6 +202,10 @@
 
 // swap_ranges
 
+// forward
+template<class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
 
 template <class _ForwardIterator1, class _ForwardIterator2>
 inline _LIBCPP_INLINE_VISIBILITY
@@ -236,12 +217,9 @@
     return __first2;
 }
 
-// forward declared in <type_traits>
 template<class _Tp, size_t _Np>
 inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<
-    __is_swappable<_Tp>::value
->::type
+void
 swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
 {
     _VSTD::swap_ranges(__a, __a + _Np, __b);
@@ -264,11 +242,6 @@
     return _VSTD::move(__x);
 }
 
-#if _LIBCPP_STD_VER > 14
-template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
-template <class _Tp>                        void as_const(const _Tp&&) = delete;
-#endif
-
 struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { };
 #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY)
 extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
@@ -288,12 +261,6 @@
     // pair(const pair&) = default;
     // pair(pair&&) = default;
 
-#ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS
-    template <bool _Dummy = true, class = typename enable_if<
-        __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
-        __dependent_type<is_default_constructible<_T2>, _Dummy>::value
-      >::type>
-#endif
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
@@ -421,9 +388,8 @@
     swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
                                __is_nothrow_swappable<second_type>::value)
     {
-        using _VSTD::swap;
-        swap(first,  __p.first);
-        swap(second, __p.second);
+        _VSTD::iter_swap(&first, &__p.first);
+        _VSTD::iter_swap(&second, &__p.second);
     }
 private:
 
@@ -501,6 +467,7 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
+template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY reference_wrapper;
 
 template <class _Tp>
 struct __make_pair_return_impl
@@ -584,12 +551,6 @@
     _T1&&
     get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
 
-    template <class _T1, class _T2>
-    static
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-    const _T1&&
-    get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
-
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
 
@@ -616,12 +577,6 @@
     _T2&&
     get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
 
-    template <class _T1, class _T2>
-    static
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-    const _T2&&
-    get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
-
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 };
 
@@ -651,14 +606,6 @@
     return __get_pair<_Ip>::get(_VSTD::move(__p));
 }
 
-template <size_t _Ip, class _T1, class _T2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
-get(const pair<_T1, _T2>&& __p) _NOEXCEPT
-{
-    return __get_pair<_Ip>::get(_VSTD::move(__p));
-}
-
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 #if _LIBCPP_STD_VER > 11
@@ -685,13 +632,6 @@
 
 template <class _T1, class _T2>
 inline _LIBCPP_INLINE_VISIBILITY
-constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
-{
-    return __get_pair<0>::get(_VSTD::move(__p));
-}
-
-template <class _T1, class _T2>
-inline _LIBCPP_INLINE_VISIBILITY
 constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
 {
     return __get_pair<1>::get(__p);
@@ -711,13 +651,6 @@
     return __get_pair<1>::get(_VSTD::move(__p));
 }
 
-template <class _T1, class _T2>
-inline _LIBCPP_INLINE_VISIBILITY
-constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
-{
-    return __get_pair<1>::get(_VSTD::move(__p));
-}
-
 #endif
 
 #if _LIBCPP_STD_VER > 11
@@ -738,16 +671,6 @@
 template<size_t... _Ip>
     using index_sequence = integer_sequence<size_t, _Ip...>;
 
-#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
-
-template <class _Tp, _Tp _Ep>
-struct __make_integer_sequence
-{
-    typedef __make_integer_seq<integer_sequence, _Tp, _Ep> type;
-};
-
-#else
-
 namespace __detail {
 
 template<typename _Tp, size_t ..._Extra> struct __repeat;
@@ -801,14 +724,10 @@
 {
     static_assert(is_integral<_Tp>::value,
                   "std::make_integer_sequence can only be instantiated with an integral type" );
-    static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
-    // Workaround GCC bug by preventing bad installations when 0 <= _Ep
-    // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
-    typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
+    static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
+    typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
 };
 
-#endif
-
 template<class _Tp, _Tp _Np>
     using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
 
diff --git a/include/valarray b/include/valarray
index bde644e..bdaa588 100644
--- a/include/valarray
+++ b/include/valarray
@@ -802,14 +802,11 @@
     // construct/destroy:
     _LIBCPP_INLINE_VISIBILITY
     valarray() : __begin_(0), __end_(0) {}
-    _LIBCPP_INLINE_VISIBILITY
-    inline explicit valarray(size_t __n);
-    _LIBCPP_INLINE_VISIBILITY
+    explicit valarray(size_t __n);
     valarray(const value_type& __x, size_t __n);
     valarray(const value_type* __p, size_t __n);
     valarray(const valarray& __v);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     valarray(valarray&& __v) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -819,31 +816,22 @@
     valarray(const gslice_array<value_type>& __ga);
     valarray(const mask_array<value_type>& __ma);
     valarray(const indirect_array<value_type>& __ia);
-    inline _LIBCPP_INLINE_VISIBILITY
     ~valarray();
 
     // assignment:
     valarray& operator=(const valarray& __v);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(valarray&& __v) _NOEXCEPT;
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(initializer_list<value_type>);
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(const slice_array<value_type>& __sa);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(const gslice_array<value_type>& __ga);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(const mask_array<value_type>& __ma);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator=(const indirect_array<value_type>& __ia);
     template <class _ValExpr>
-        _LIBCPP_INLINE_VISIBILITY
         valarray& operator=(const __val_expr<_ValExpr>& __v);
 
     // element access:
@@ -854,38 +842,24 @@
     value_type&       operator[](size_t __i)       {return __begin_[__i];}
 
     // subset operations:
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__slice_expr<const valarray&> >    operator[](slice __s) const;
-    _LIBCPP_INLINE_VISIBILITY
     slice_array<value_type>                       operator[](slice __s);
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
-    _LIBCPP_INLINE_VISIBILITY
     gslice_array<value_type>   operator[](const gslice& __gs);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
-    _LIBCPP_INLINE_VISIBILITY
     gslice_array<value_type>                      operator[](gslice&& __gs);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__mask_expr<const valarray&> >     operator[](const valarray<bool>& __vb) const;
-    _LIBCPP_INLINE_VISIBILITY
     mask_array<value_type>                        operator[](const valarray<bool>& __vb);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__mask_expr<const valarray&> >     operator[](valarray<bool>&& __vb) const;
-    _LIBCPP_INLINE_VISIBILITY
     mask_array<value_type>                        operator[](valarray<bool>&& __vb);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
-    _LIBCPP_INLINE_VISIBILITY
     indirect_array<value_type>                    operator[](const valarray<size_t>& __vs);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
-    _LIBCPP_INLINE_VISIBILITY
     indirect_array<value_type>                    operator[](valarray<size_t>&& __vs);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
@@ -896,25 +870,15 @@
     valarray<bool> operator!() const;
 
     // computed assignment:
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator*= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator/= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator%= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator+= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator-= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator^= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator&= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator|= (const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator<<=(const value_type& __x);
-    _LIBCPP_INLINE_VISIBILITY
     valarray& operator>>=(const value_type& __x);
 
     template <class _Expr>
@@ -923,7 +887,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator*= (const _Expr& __v);
 
     template <class _Expr>
@@ -932,7 +895,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator/= (const _Expr& __v);
 
     template <class _Expr>
@@ -941,7 +903,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator%= (const _Expr& __v);
 
     template <class _Expr>
@@ -950,7 +911,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator+= (const _Expr& __v);
 
     template <class _Expr>
@@ -959,7 +919,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator-= (const _Expr& __v);
 
     template <class _Expr>
@@ -968,7 +927,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator^= (const _Expr& __v);
 
     template <class _Expr>
@@ -977,7 +935,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator|= (const _Expr& __v);
 
     template <class _Expr>
@@ -986,7 +943,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator&= (const _Expr& __v);
 
     template <class _Expr>
@@ -995,7 +951,6 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator<<= (const _Expr& __v);
 
     template <class _Expr>
@@ -1004,21 +959,16 @@
         __is_val_expr<_Expr>::value,
         valarray&
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator>>= (const _Expr& __v);
 
     // member functions:
-    _LIBCPP_INLINE_VISIBILITY
     void swap(valarray& __v) _NOEXCEPT;
 
     _LIBCPP_INLINE_VISIBILITY
     size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
 
-    _LIBCPP_INLINE_VISIBILITY
     value_type sum() const;
-    _LIBCPP_INLINE_VISIBILITY
     value_type min() const;
-    _LIBCPP_INLINE_VISIBILITY
     value_type max() const;
 
     valarray shift (int __i) const;
@@ -1164,7 +1114,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1173,7 +1122,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator*=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1182,7 +1130,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator/=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1191,7 +1138,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator%=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1200,7 +1146,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator+=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1209,7 +1154,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator-=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1218,7 +1162,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator^=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1227,7 +1170,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator&=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1236,7 +1178,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator|=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1245,7 +1186,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator<<=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1254,13 +1194,10 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator>>=(const _Expr& __v) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     const slice_array& operator=(const slice_array& __sa) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     void operator=(const value_type& __x) const;
 
 private:
@@ -1276,7 +1213,7 @@
 };
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const slice_array<_Tp>&
 slice_array<_Tp>::operator=(const slice_array& __sa) const
 {
@@ -1289,7 +1226,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1304,7 +1241,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1319,7 +1256,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1334,7 +1271,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1349,7 +1286,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1364,7 +1301,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1379,7 +1316,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1394,7 +1331,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1409,7 +1346,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1424,7 +1361,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1439,7 +1376,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1453,7 +1390,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 slice_array<_Tp>::operator=(const value_type& __x) const
 {
@@ -1547,7 +1484,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1556,7 +1492,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator*=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1565,7 +1500,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator/=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1574,7 +1508,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator%=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1583,7 +1516,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator+=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1592,7 +1524,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator-=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1601,7 +1532,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator^=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1610,7 +1540,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator&=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1619,7 +1548,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator|=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1628,7 +1556,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator<<=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1637,13 +1564,10 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator>>=(const _Expr& __v) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     const gslice_array& operator=(const gslice_array& __ga) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     void operator=(const value_type& __x) const;
 
 //  gslice_array(const gslice_array&)            = default;
@@ -1652,16 +1576,20 @@
 //  gslice_array& operator=(gslice_array&&)      = default;
 
 private:
+    _LIBCPP_INLINE_VISIBILITY
     gslice_array(const gslice& __gs, const valarray<value_type>& __v)
         : __vp_(const_cast<value_type*>(__v.__begin_)),
           __1d_(__gs.__1d_)
         {}
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    _LIBCPP_INLINE_VISIBILITY
     gslice_array(gslice&& __gs, const valarray<value_type>& __v)
         : __vp_(const_cast<value_type*>(__v.__begin_)),
           __1d_(move(__gs.__1d_))
         {}
+
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
     template <class> friend class valarray;
@@ -1669,7 +1597,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1685,7 +1613,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1701,7 +1629,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1717,7 +1645,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1733,7 +1661,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1749,7 +1677,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1765,7 +1693,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1781,7 +1709,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1797,7 +1725,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1813,7 +1741,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1829,7 +1757,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -1844,7 +1772,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const gslice_array<_Tp>&
 gslice_array<_Tp>::operator=(const gslice_array& __ga) const
 {
@@ -1857,7 +1785,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 gslice_array<_Tp>::operator=(const value_type& __x) const
 {
@@ -1885,7 +1813,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1894,7 +1821,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator*=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1903,7 +1829,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator/=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1912,7 +1837,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator%=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1921,7 +1845,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator+=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1930,7 +1853,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator-=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1939,7 +1861,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator^=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1948,7 +1869,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator&=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1957,7 +1877,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator|=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1966,7 +1885,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator<<=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -1975,13 +1893,10 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator>>=(const _Expr& __v) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     const mask_array& operator=(const mask_array& __ma) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     void operator=(const value_type& __x) const;
 
 //  mask_array(const mask_array&)            = default;
@@ -2006,7 +1921,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2021,7 +1936,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2036,7 +1951,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2051,7 +1966,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2066,7 +1981,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2081,7 +1996,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2096,7 +2011,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2111,7 +2026,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2126,7 +2041,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2141,7 +2056,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2156,7 +2071,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2170,7 +2085,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const mask_array<_Tp>&
 mask_array<_Tp>::operator=(const mask_array& __ma) const
 {
@@ -2181,7 +2096,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 mask_array<_Tp>::operator=(const value_type& __x) const
 {
@@ -2243,7 +2158,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2252,7 +2166,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator*=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2261,7 +2174,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator/=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2270,7 +2182,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator%=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2279,7 +2190,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator+=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2288,7 +2198,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator-=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2297,7 +2206,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator^=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2306,7 +2214,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator&=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2315,7 +2222,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator|=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2324,7 +2230,6 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator<<=(const _Expr& __v) const;
 
     template <class _Expr>
@@ -2333,13 +2238,10 @@
         __is_val_expr<_Expr>::value,
         void
     >::type
-    _LIBCPP_INLINE_VISIBILITY
     operator>>=(const _Expr& __v) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     const indirect_array& operator=(const indirect_array& __ia) const;
 
-    _LIBCPP_INLINE_VISIBILITY
     void operator=(const value_type& __x) const;
 
 //  indirect_array(const indirect_array&)            = default;
@@ -2369,7 +2271,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2384,7 +2286,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2399,7 +2301,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2414,7 +2316,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2429,7 +2331,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2444,7 +2346,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2459,7 +2361,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2474,7 +2376,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2489,7 +2391,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2504,7 +2406,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2519,7 +2421,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -2533,7 +2435,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 const indirect_array<_Tp>&
 indirect_array<_Tp>::operator=(const indirect_array& __ia) const
 {
@@ -2546,7 +2448,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 indirect_array<_Tp>::operator=(const value_type& __x) const
 {
@@ -2748,7 +2650,7 @@
 // valarray
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>::valarray(size_t __n)
     : __begin_(0),
       __end_(0)
@@ -2757,7 +2659,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>::valarray(const value_type& __x, size_t __n)
     : __begin_(0),
       __end_(0)
@@ -2818,7 +2720,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
     : __begin_(__v.__begin_),
       __end_(__v.__end_)
@@ -2972,7 +2874,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>::~valarray()
 {
     resize(0);
@@ -2994,7 +2896,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
 {
@@ -3011,7 +2913,7 @@
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(initializer_list<value_type> __il)
 {
@@ -3024,7 +2926,7 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const value_type& __x)
 {
@@ -3033,7 +2935,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
 {
@@ -3045,7 +2947,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
 {
@@ -3059,7 +2961,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
 {
@@ -3073,7 +2975,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
 {
@@ -3088,7 +2990,7 @@
 
 template <class _Tp>
 template <class _ValExpr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
 {
@@ -3102,7 +3004,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__slice_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](slice __s) const
 {
@@ -3110,7 +3012,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 slice_array<_Tp>
 valarray<_Tp>::operator[](slice __s)
 {
@@ -3118,7 +3020,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__indirect_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](const gslice& __gs) const
 {
@@ -3126,7 +3028,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 gslice_array<_Tp>
 valarray<_Tp>::operator[](const gslice& __gs)
 {
@@ -3136,7 +3038,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__indirect_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](gslice&& __gs) const
 {
@@ -3144,7 +3046,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 gslice_array<_Tp>
 valarray<_Tp>::operator[](gslice&& __gs)
 {
@@ -3154,7 +3056,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__mask_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](const valarray<bool>& __vb) const
 {
@@ -3162,7 +3064,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 mask_array<_Tp>
 valarray<_Tp>::operator[](const valarray<bool>& __vb)
 {
@@ -3172,7 +3074,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__mask_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](valarray<bool>&& __vb) const
 {
@@ -3180,7 +3082,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 mask_array<_Tp>
 valarray<_Tp>::operator[](valarray<bool>&& __vb)
 {
@@ -3190,7 +3092,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__indirect_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
 {
@@ -3198,7 +3100,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 indirect_array<_Tp>
 valarray<_Tp>::operator[](const valarray<size_t>& __vs)
 {
@@ -3208,7 +3110,7 @@
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 __val_expr<__indirect_expr<const valarray<_Tp>&> >
 valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
 {
@@ -3216,7 +3118,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 indirect_array<_Tp>
 valarray<_Tp>::operator[](valarray<size_t>&& __vs)
 {
@@ -3294,7 +3196,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator*=(const value_type& __x)
 {
@@ -3304,7 +3206,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator/=(const value_type& __x)
 {
@@ -3314,7 +3216,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator%=(const value_type& __x)
 {
@@ -3324,7 +3226,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator+=(const value_type& __x)
 {
@@ -3334,7 +3236,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator-=(const value_type& __x)
 {
@@ -3344,7 +3246,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator^=(const value_type& __x)
 {
@@ -3354,7 +3256,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator&=(const value_type& __x)
 {
@@ -3364,7 +3266,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator|=(const value_type& __x)
 {
@@ -3374,7 +3276,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator<<=(const value_type& __x)
 {
@@ -3384,7 +3286,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 valarray<_Tp>&
 valarray<_Tp>::operator>>=(const value_type& __x)
 {
@@ -3395,7 +3297,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3411,7 +3313,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3427,7 +3329,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3443,7 +3345,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3459,7 +3361,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3475,7 +3377,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3491,7 +3393,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3507,7 +3409,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3523,7 +3425,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3539,7 +3441,7 @@
 
 template <class _Tp>
 template <class _Expr>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
     __is_val_expr<_Expr>::value,
@@ -3554,7 +3456,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
 {
@@ -3563,7 +3465,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Tp
 valarray<_Tp>::sum() const
 {
@@ -3577,7 +3479,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Tp
 valarray<_Tp>::min() const
 {
@@ -3587,7 +3489,7 @@
 }
 
 template <class _Tp>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 _Tp
 valarray<_Tp>::max() const
 {
diff --git a/include/vector b/include/vector
index 81c514e..049d3c8 100644
--- a/include/vector
+++ b/include/vector
@@ -51,8 +51,8 @@
     vector& operator=(const vector& x);
     vector& operator=(vector&& x)
         noexcept(
-             allocator_type::propagate_on_container_move_assignment::value ||
-             allocator_type::is_always_equal::value); // C++17
+             allocator_type::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value);
     vector& operator=(initializer_list<value_type> il);
     template <class InputIterator>
         void assign(InputIterator first, InputIterator last);
@@ -175,8 +175,8 @@
     vector& operator=(const vector& x);
     vector& operator=(vector&& x)
         noexcept(
-             allocator_type::propagate_on_container_move_assignment::value ||
-             allocator_type::is_always_equal::value); // C++17
+             allocator_type::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value);
     vector& operator=(initializer_list<value_type> il);
     template <class InputIterator>
         void assign(InputIterator first, InputIterator last);
@@ -262,7 +262,6 @@
 */
 
 #include <__config>
-#include <iosfwd> // for forward declaration of vector
 #include <__bit_reference>
 #include <type_traits>
 #include <climits>
@@ -454,7 +453,7 @@
     }
 }
 
-template <class _Tp, class _Allocator /* = allocator<_Tp> */>
+template <class _Tp, class _Allocator = allocator<_Tp> >
 class _LIBCPP_TYPE_VIS_ONLY vector
     : private __vector_base<_Tp, _Allocator>
 {
@@ -563,7 +562,9 @@
     vector(vector&& __x, const allocator_type& __a);
     _LIBCPP_INLINE_VISIBILITY
     vector& operator=(vector&& __x)
-        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
+        _NOEXCEPT_(
+             __alloc_traits::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
@@ -686,11 +687,9 @@
     _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
 #ifndef _LIBCPP_HAS_NO_VARIADICS
     template <class... _Args>
-        _LIBCPP_INLINE_VISIBILITY
         void emplace_back(_Args&&... __args);
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-    _LIBCPP_INLINE_VISIBILITY
     void pop_back();
 
     iterator insert(const_iterator __position, const_reference __x);
@@ -769,7 +768,6 @@
     void deallocate() _NOEXCEPT;
     _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
     void __construct_at_end(size_type __n);
-    _LIBCPP_INLINE_VISIBILITY
     void __construct_at_end(size_type __n, const_reference __x);
     template <class _ForwardIterator>
         typename enable_if
@@ -789,8 +787,7 @@
     void __move_range(pointer __from_s, pointer __from_e, pointer __to);
     void __move_assign(vector& __c, true_type)
         _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
-    void __move_assign(vector& __c, false_type)
-        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
+    void __move_assign(vector& __c, false_type);
     _LIBCPP_INLINE_VISIBILITY
     void __destruct_at_end(pointer __new_last) _NOEXCEPT
     {
@@ -994,7 +991,7 @@
 //  Postcondition:  size() == old size() + __n
 //  Postcondition:  [i] == __x for all i in [size() - __n, __n)
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
 {
@@ -1306,7 +1303,9 @@
 inline _LIBCPP_INLINE_VISIBILITY
 vector<_Tp, _Allocator>&
 vector<_Tp, _Allocator>::operator=(vector&& __x)
-    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
+        _NOEXCEPT_(
+             __alloc_traits::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value)
 {
     __move_assign(__x, integral_constant<bool,
           __alloc_traits::propagate_on_container_move_assignment::value>());
@@ -1316,7 +1315,6 @@
 template <class _Tp, class _Allocator>
 void
 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
-    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
 {
     if (__base::__alloc() != __c.__alloc())
     {
@@ -1631,7 +1629,7 @@
 
 template <class _Tp, class _Allocator>
 template <class... _Args>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
 {
@@ -1652,7 +1650,7 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class _Tp, class _Allocator>
-inline
+inline _LIBCPP_INLINE_VISIBILITY
 void
 vector<_Tp, _Allocator>::pop_back()
 {
@@ -2215,7 +2213,9 @@
     vector(vector&& __v, const allocator_type& __a);
     _LIBCPP_INLINE_VISIBILITY
     vector& operator=(vector&& __v)
-        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
+        _NOEXCEPT_(
+             __alloc_traits::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     _LIBCPP_INLINE_VISIBILITY
@@ -2363,7 +2363,6 @@
         _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 
                     __is_nothrow_swappable<allocator_type>::value);
 #endif
-    static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
 
     void resize(size_type __sz, value_type __x = false);
     void flip() _NOEXCEPT;
@@ -2839,7 +2838,9 @@
 inline _LIBCPP_INLINE_VISIBILITY
 vector<bool, _Allocator>&
 vector<bool, _Allocator>::operator=(vector&& __v)
-    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
+        _NOEXCEPT_(
+             __alloc_traits::propagate_on_container_move_assignment::value &&
+             is_nothrow_move_assignable<allocator_type>::value)
 {
     __move_assign(__v, integral_constant<bool,
           __storage_traits::propagate_on_container_move_assignment::value>());
diff --git a/include/wchar.h b/include/wchar.h
deleted file mode 100644
index c0c6ef7..0000000
--- a/include/wchar.h
+++ /dev/null
@@ -1,175 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- wchar.h ----------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(__need_wint_t) || defined(__need_mbstate_t)
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <wchar.h>
-
-#elif !defined(_LIBCPP_WCHAR_H)
-#define _LIBCPP_WCHAR_H
-
-/*
-    wchar.h synopsis
-
-Macros:
-
-    NULL
-    WCHAR_MAX
-    WCHAR_MIN
-    WEOF
-
-Types:
-
-    mbstate_t
-    size_t
-    tm
-    wint_t
-
-int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
-int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
-int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...);
-int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
-int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);
-int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);  // C99
-int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg);
-int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg);  // C99
-int vwprintf(const wchar_t* restrict format, va_list arg);
-int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
-int wprintf(const wchar_t* restrict format, ...);
-int wscanf(const wchar_t* restrict format, ...);
-wint_t fgetwc(FILE* stream);
-wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
-wint_t fputwc(wchar_t c, FILE* stream);
-int fputws(const wchar_t* restrict s, FILE* restrict stream);
-int fwide(FILE* stream, int mode);
-wint_t getwc(FILE* stream);
-wint_t getwchar();
-wint_t putwc(wchar_t c, FILE* stream);
-wint_t putwchar(wchar_t c);
-wint_t ungetwc(wint_t c, FILE* stream);
-double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
-float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr);         // C99
-long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr);  // C99
-long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
-long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
-unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
-unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
-wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
-wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2);
-wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-int wcscmp(const wchar_t* s1, const wchar_t* s2);
-int wcscoll(const wchar_t* s1, const wchar_t* s2);
-int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n);
-size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-const wchar_t* wcschr(const wchar_t* s, wchar_t c);
-      wchar_t* wcschr(      wchar_t* s, wchar_t c);
-size_t wcscspn(const wchar_t* s1, const wchar_t* s2);
-size_t wcslen(const wchar_t* s);
-const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2);
-      wchar_t* wcspbrk(      wchar_t* s1, const wchar_t* s2);
-const wchar_t* wcsrchr(const wchar_t* s, wchar_t c);
-      wchar_t* wcsrchr(      wchar_t* s, wchar_t c);
-size_t wcsspn(const wchar_t* s1, const wchar_t* s2);
-const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2);
-      wchar_t* wcsstr(      wchar_t* s1, const wchar_t* s2);
-wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr);
-const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n);
-      wchar_t* wmemchr(      wchar_t* s, wchar_t c, size_t n);
-int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
-wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
-size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format,
-                const tm* restrict timeptr);
-wint_t btowc(int c);
-int wctob(wint_t c);
-int mbsinit(const mbstate_t* ps);
-size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps);
-size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps);
-size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps);
-size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len,
-                 mbstate_t* restrict ps);
-size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
-                 mbstate_t* restrict ps);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#ifdef __cplusplus
-#define __CORRECT_ISO_CPP_WCHAR_H_PROTO
-#endif
-
-#include_next <wchar.h>
-
-// Determine whether we have const-correct overloads for wcschr and friends.
-#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
-#  define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
-#elif defined(__GLIBC_PREREQ)
-#  if __GLIBC_PREREQ(2, 10)
-#    define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
-#  endif
-#endif
-
-#if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
-extern "C++" {
-inline _LIBCPP_INLINE_VISIBILITY
-wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return (wchar_t*)wmemchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
-}
-#endif
-
-#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT) || defined(__MINGW32__))
-extern "C++" {
-#include <support/win32/support.h> // pull in *swprintf defines
-}  // extern "C++"
-#endif  // __cplusplus && _LIBCPP_MSVCRT
-
-#endif  // _LIBCPP_WCHAR_H
diff --git a/include/wctype.h b/include/wctype.h
deleted file mode 100644
index f9c5a47..0000000
--- a/include/wctype.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// -*- C++ -*-
-//===--------------------------- wctype.h ---------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_WCTYPE_H
-#define _LIBCPP_WCTYPE_H
-
-/*
-    wctype.h synopsis
-
-Macros:
-
-    WEOF
-
-Types:
-
-    wint_t
-    wctrans_t
-    wctype_t
-
-int iswalnum(wint_t wc);
-int iswalpha(wint_t wc);
-int iswblank(wint_t wc);  // C99
-int iswcntrl(wint_t wc);
-int iswdigit(wint_t wc);
-int iswgraph(wint_t wc);
-int iswlower(wint_t wc);
-int iswprint(wint_t wc);
-int iswpunct(wint_t wc);
-int iswspace(wint_t wc);
-int iswupper(wint_t wc);
-int iswxdigit(wint_t wc);
-int iswctype(wint_t wc, wctype_t desc);
-wctype_t wctype(const char* property);
-wint_t towlower(wint_t wc);
-wint_t towupper(wint_t wc);
-wint_t towctrans(wint_t wc, wctrans_t desc);
-wctrans_t wctrans(const char* property);
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next <wctype.h>
-
-#ifdef __cplusplus
-
-#undef iswalnum
-#undef iswalpha
-#undef iswblank
-#undef iswcntrl
-#undef iswdigit
-#undef iswgraph
-#undef iswlower
-#undef iswprint
-#undef iswpunct
-#undef iswspace
-#undef iswupper
-#undef iswxdigit
-#undef iswctype
-#undef wctype
-#undef towlower
-#undef towupper
-#undef towctrans
-#undef wctrans
-
-#endif  // __cplusplus
-
-#endif  // _LIBCPP_WCTYPE_H