Creating release candidate rc1 from release_360 branch

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_360@226110 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/rc1/.arcconfig b/rc1/.arcconfig
new file mode 100644
index 0000000..6d07e82
--- /dev/null
+++ b/rc1/.arcconfig
@@ -0,0 +1,4 @@
+{
+  "project_id" : "libcxx",
+  "conduit_uri" : "http://reviews.llvm.org/"
+}
diff --git a/rc1/.gitignore b/rc1/.gitignore
new file mode 100644
index 0000000..b26d5f7
--- /dev/null
+++ b/rc1/.gitignore
@@ -0,0 +1,54 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+#lib/ # We actually have things checked in to lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
diff --git a/rc1/CMakeLists.txt b/rc1/CMakeLists.txt
new file mode 100644
index 0000000..99a4a33
--- /dev/null
+++ b/rc1/CMakeLists.txt
@@ -0,0 +1,298 @@
+# See www/CMake.html for instructions on how to build libcxx with CMake.
+
+#===============================================================================
+# Setup Project
+#===============================================================================
+
+project(libcxx CXX C)
+cmake_minimum_required(VERSION 2.8)
+
+set(PACKAGE_NAME libcxx)
+set(PACKAGE_VERSION trunk-svn)
+set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
+
+# Add path for custom modules
+set(CMAKE_MODULE_PATH
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+  ${CMAKE_MODULE_PATH}
+  )
+
+# Require out of source build.
+include(MacroEnsureOutOfSourceBuild)
+MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
+ "${PROJECT_NAME} requires an out of source build. Please create a separate
+ build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
+ )
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  set(LIBCXX_LIBDIR_SUFFIX "" CACHE STRING
+      "Define suffix of library directory name (32/64)")
+
+  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+
+  set(LIBCXX_BUILT_STANDALONE 1)
+else()
+  set(LIBCXX_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
+endif()
+
+#===============================================================================
+# Setup CMake Options
+#===============================================================================
+
+# Define options.
+option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON)
+option(LIBCXX_ENABLE_RTTI "Use run time type information." ON)
+option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
+option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
+option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
+option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF)
+option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
+option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
+option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++" OFF)
+option(LIBCXX_ENABLE_MONOTONIC_CLOCK
+  "Build libc++ with support for a monotonic clock.
+   This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON)
+option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
+option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
+if (LIBCXX_BUILT_STANDALONE)
+  set(LLVM_USE_SANITIZER "" CACHE STRING
+      "Define the sanitizer used to build the library and tests")
+endif()
+
+set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++)
+if (NOT LIBCXX_CXX_ABI)
+  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+      IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
+    set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
+    set(LIBCXX_LIBCXXABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
+    set(LIBCXX_CXX_ABI_INTREE 1)
+  else ()
+    set(LIBCXX_CXX_ABI_LIBNAME "none")
+  endif ()
+else ()
+  set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}")
+endif ()
+set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING
+    "Specify C++ ABI library to use." FORCE)
+set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
+
+#===============================================================================
+# Configure System
+#===============================================================================
+
+# Get triples.
+include(GetTriple)
+get_host_triple(LIBCXX_HOST_TRIPLE
+  LIBCXX_HOST_ARCH
+  LIBCXX_HOST_VENDOR
+  LIBCXX_HOST_OS
+  )
+set(LIBCXX_HOST_TRIPLE ${LIBCXX_HOST_TRIPLE} CACHE STRING "Host triple.")
+get_target_triple(LIBCXX_TARGET_TRIPLE
+  LIBCXX_TARGET_ARCH
+  LIBCXX_TARGET_VENDOR
+  LIBCXX_TARGET_OS
+  )
+set(LIBCXX_TARGET_TRIPLE ${LIBCXX_TARGET_TRIPLE} CACHE STRING "Target triple.")
+
+set(LIBCXX_COMPILER    ${CMAKE_CXX_COMPILER})
+set(LIBCXX_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
+set(LIBCXX_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
+set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
+
+# Declare libc++ configuration variables.
+# They are intended for use as follows:
+# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
+# LIBCXX_COMPILE_FLAGS: Compile only flags.
+# LIBCXX_LINK_FLAGS: Linker only flags.
+set(LIBCXX_CXX_FLAGS "")
+set(LIBCXX_COMPILE_FLAGS "")
+set(LIBCXX_LINK_FLAGS "")
+
+# Configure compiler.
+include(config-ix)
+# Configure ABI library
+include(HandleLibCXXABI)
+
+#===============================================================================
+# Setup Compiler Flags
+#===============================================================================
+
+# Get required flags.
+# On all systems the system c++ standard library headers need to be excluded.
+if (MSVC)
+  # MSVC only has -X, which disables all default includes; including the crt.
+  # Thus, we do nothing and hope we don't accidentally include any of the C++
+  # headers.
+else()
+  if (LIBCXX_HAS_NOSTDINCXX_FLAG)
+    list(APPEND LIBCXX_COMPILE_FLAGS -nostdinc++)
+    string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+    string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+  endif()
+  # If c++1y has been enabled then attempt to use it. Fail if it is no supported
+  # by the compiler. Otherwise choose c++11 and ensure the compiler supports it.
+  if (LIBCXX_ENABLE_CXX1Y)
+    if (LIBCXX_HAS_STDCXX1Y_FLAG)
+      set(LIBCXX_STD_VERSION c++1y)
+    else()
+      message(FATAL_ERROR "c++1y was enabled but the compiler does not support it.")
+    endif()
+  else()
+    if (LIBCXX_HAS_STDCXX11_FLAG)
+      set(LIBCXX_STD_VERSION c++11)
+    else()
+      message(FATAL_ERROR "c++11 is required by libc++ but is not supported by the compiler")
+    endif()
+  endif()
+  # LIBCXX_STD_VERSION should always be set at this point.
+  list(APPEND LIBCXX_CXX_FLAGS "-std=${LIBCXX_STD_VERSION}")
+endif()
+
+macro(append_if list condition var)
+  if (${condition})
+    list(APPEND ${list} ${var})
+  endif()
+endmacro()
+
+# Get warning flags
+if (NOT MSVC)
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WALL_FLAG -Wall)
+  list(APPEND LIBCXX_COMPILE_FLAGS -Werror=return-type)
+endif()
+
+append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_W_FLAG -W)
+append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter)
+append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
+append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long)
+if (LIBCXX_ENABLE_WERROR)
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror)
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WX_FLAG -WX)
+else()
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error)
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-)
+endif()
+if (LIBCXX_ENABLE_PEDANTIC)
+  append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic)
+endif()
+
+# Get feature flags.
+# Exceptions
+if (LIBCXX_ENABLE_EXCEPTIONS)
+  # Catches C++ exceptions only and tells the compiler to assume that extern C
+  # functions never throw a C++ exception.
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc)
+else()
+  list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_EXCEPTIONS)
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-)
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-)
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions)
+endif()
+# RTTI
+if (NOT LIBCXX_ENABLE_RTTI)
+  list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_RTTI)
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-)
+  append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti)
+endif()
+# Assert
+string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
+if (LIBCXX_ENABLE_ASSERTIONS)
+  # MSVC doesn't like _DEBUG on release builds. See PR 4379.
+  if (NOT MSVC)
+    list(APPEND LIBCXX_COMPILE_FLAGS -D_DEBUG)
+  endif()
+  # On Release builds cmake automatically defines NDEBUG, so we
+  # explicitly undefine it:
+  if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
+    list(APPEND LIBCXX_COMPILE_FLAGS -UNDEBUG)
+  endif()
+else()
+  if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
+    list(APPEND LIBCXX_COMPILE_FLAGS -DNDEBUG)
+  endif()
+endif()
+# Static library
+if (NOT LIBCXX_ENABLE_SHARED)
+  list(APPEND LIBCXX_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
+endif()
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
+  if (LIBCXX_BUILD_32_BITS)
+    message(STATUS "Building 32 bits executables and libraries.")
+    list(APPEND LIBCXX_CXX_FLAGS "-m32")
+  endif()
+elseif(LIBCXX_BUILD_32_BITS)
+  message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.")
+endif()
+# This is the _ONLY_ place where add_definitions is called.
+if (MSVC)
+  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+endif()
+
+# LIBCXX_ENABLE_THREADS configuration
+if (NOT LIBCXX_ENABLE_THREADS)
+  add_definitions(-D_LIBCPP_HAS_NO_THREADS)
+  if (NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
+    add_definitions(-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
+  endif()
+# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON.
+elseif(NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
+  message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
+                      " when LIBCXX_ENABLE_THREADS is also set to OFF.")
+endif()
+
+# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
+if (LIBCXX_BUILT_STANDALONE)
+  # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
+  # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
+  if (LLVM_USE_SANITIZER AND NOT MSVC)
+    append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG
+              "-fno-omit-frame-pointer")
+    if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
+        NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
+      append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG
+                "-gline-tables-only")
+    endif()
+    if (LLVM_USE_SANITIZER STREQUAL "Address")
+      list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=address")
+    elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
+      list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=memory")
+      if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
+        list(APPEND LIBCXX_CXX_FLAGS "-fsanitize-memory-track-origins")
+      endif()
+    elseif (LLVM_USE_SANITIZER STREQUAL "Undefined")
+      list(APPEND LIBCXX_CXX_FLAGS
+          "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover")
+    elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
+      list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=thread")
+    else()
+      message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
+    endif()
+  elseif(MSVC)
+    message(WARNING "LLVM_USE_SANITIZER is not supported with MSVC")
+  endif()
+endif()
+
+string(REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FLAGS}")
+
+#===============================================================================
+# Setup Source Code
+#===============================================================================
+
+include_directories(include)
+add_subdirectory(include)
+
+# Add source code. This also contains all of the logic for deciding linker flags
+# soname, etc...
+add_subdirectory(lib)
+
+#===============================================================================
+# Setup Tests
+#===============================================================================
+
+add_subdirectory(test)
diff --git a/rc1/CREDITS.TXT b/rc1/CREDITS.TXT
new file mode 100644
index 0000000..7a28ada
--- /dev/null
+++ b/rc1/CREDITS.TXT
@@ -0,0 +1,127 @@
+This file is a partial list of people who have contributed to the LLVM/libc++
+project.  If you have contributed a patch or made some other contribution to
+LLVM/libc++, please submit a patch to this file to add yourself, and it will be
+done!
+
+The list is sorted by surname and formatted to allow easy grepping and
+beautification by scripts.  The fields are: name (N), email (E), web-address
+(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
+(S).
+
+N: Saleem Abdulrasool
+E: compnerd@compnerd.org
+D: Minor patches and Linux fixes.
+
+N: Dimitry Andric
+E: dimitry@andric.com
+D: Visibility fixes, minor FreeBSD portability patches.
+
+N: Holger Arnold
+E: holgerar@gmail.com
+D: Minor fix.
+
+N: Ruben Van Boxem
+E: vanboxem dot ruben at gmail dot com
+D: Initial Windows patches.
+
+N: David Chisnall
+E: theraven at theravensnest dot org
+D: FreeBSD and Solaris ports, libcxxrt support, some atomics work.
+
+N: Marshall Clow
+E: mclow.lists@gmail.com
+E: marshall@idio.com
+D: C++14 support, patches and bug fixes.
+
+N: Eric Fiselier
+E: eric@efcs.ca
+D: LFTS support, patches and bug fixes.
+
+N: Bill Fisher
+E: william.w.fisher@gmail.com
+D: Regex bug fixes.
+
+N: Matthew Dempsky
+E: matthew@dempsky.org
+D: Minor patches and bug fixes.
+
+N: Google Inc.
+D: Copyright owner and contributor of the CityHash algorithm
+
+N: Howard Hinnant
+E: hhinnant@apple.com
+D: Architect and primary author of libc++
+
+N: Hyeon-bin Jeong
+E: tuhertz@gmail.com
+D: Minor patches and bug fixes.
+
+N: Argyrios Kyrtzidis
+E: kyrtzidis@apple.com
+D: Bug fixes.
+
+N: Bruce Mitchener, Jr.
+E: bruce.mitchener@gmail.com
+D: Emscripten-related changes.
+
+N: Michel Morin
+E: mimomorin@gmail.com
+D: Minor patches to is_convertible.
+
+N: Andrew Morrow
+E: andrew.c.morrow@gmail.com
+D: Minor patches and Linux fixes.
+
+N: Arvid Picciani
+E: aep at exys dot org
+D: Minor patches and musl port.
+
+N: Bjorn Reese
+E: breese@users.sourceforge.net
+D: Initial regex prototype
+
+N: Nico Rieck
+E: nico.rieck@gmail.com
+D: Windows fixes
+
+N: Jonathan Sauer
+D: Minor patches, mostly related to constexpr
+
+N: Craig Silverstein
+E: csilvers@google.com
+D: Implemented Cityhash as the string hash function on 64-bit machines
+
+N: Richard Smith
+D: Minor patches.
+
+N: Joerg Sonnenberger
+E: joerg@NetBSD.org
+D: NetBSD port.
+
+N: Stephan Tolksdorf
+E: st@quanttec.com
+D: Minor <atomic> fix
+
+N: Michael van der Westhuizen
+E: r1mikey at gmail dot com
+
+N: Klaas de Vries
+E: klaas at klaasgaaf dot nl
+D: Minor bug fix.
+
+N: Zhang Xiongpang
+E: zhangxiongpang@gmail.com
+D: Minor patches and bug fixes.
+
+N: Xing Xue
+E: xingxue@ca.ibm.com
+D: AIX port
+
+N: Zhihao Yuan
+E: lichray@gmail.com
+D: Standard compatibility fixes.
+
+N: Jeffrey Yasskin
+E: jyasskin@gmail.com
+E: jyasskin@google.com
+D: Linux fixes.
diff --git a/rc1/LICENSE.TXT b/rc1/LICENSE.TXT
new file mode 100644
index 0000000..41ca5d1
--- /dev/null
+++ b/rc1/LICENSE.TXT
@@ -0,0 +1,76 @@
+==============================================================================
+libc++ License
+==============================================================================
+
+The libc++ library is dual licensed under both the University of Illinois
+"BSD-Like" license and the MIT license.  As a user of this code you may choose
+to use it under either license.  As a contributor, you agree to allow your code
+to be used under both.
+
+Full text of the relevant licenses is included below.
+
+==============================================================================
+
+University of Illinois/NCSA
+Open Source License
+
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
+
+All rights reserved.
+
+Developed by:
+
+    LLVM Team
+
+    University of Illinois at Urbana-Champaign
+
+    http://llvm.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal with
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimers.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimers in the
+      documentation and/or other materials provided with the distribution.
+
+    * Neither the names of the LLVM Team, University of Illinois at
+      Urbana-Champaign, nor the names of its contributors may be used to
+      endorse or promote products derived from this Software without specific
+      prior written permission.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+SOFTWARE.
+
+==============================================================================
+
+Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/rc1/Makefile b/rc1/Makefile
new file mode 100644
index 0000000..ab7b5b6
--- /dev/null
+++ b/rc1/Makefile
@@ -0,0 +1,56 @@
+##
+# libc++ Makefile
+##
+
+SRCDIRS = .
+DESTDIR = $(DSTROOT)
+
+OBJROOT=.
+SYMROOT=.
+export TRIPLE=-apple-
+
+ifeq (,$(RC_INDIGO))
+	INSTALL_PREFIX=""
+else
+	INSTALL_PREFIX="$(SDKROOT)"
+endif
+INSTALL_DIR=$(DSTROOT)/$(INSTALL_PREFIX)
+
+.PHONY: help installsrc clean installheaders install
+
+help::
+	@echo "Use make install DSTROOT=<destination>"
+
+installsrc:: $(SRCROOT)
+
+	ditto $(SRCDIRS)/include $(SRCROOT)/include
+	ditto $(SRCDIRS)/lib $(SRCROOT)/lib
+	ditto $(SRCDIRS)/src $(SRCROOT)/src
+	ditto $(SRCDIRS)/Makefile $(SRCROOT)/Makefile
+
+clean::
+
+# The installheaders target is used by clang's runtime/libcxx makefile.
+installheaders::
+	mkdir -p $(HEADER_DIR)/c++/v1/ext
+	(cd $(SRCDIRS)/include && \
+	  tar cf - --exclude=".*" --exclude=support \
+	           --exclude=CMakeLists.txt *) | \
+	  (cd $(HEADER_DIR)/c++/v1 && tar xf -)
+	chmod 755 $(HEADER_DIR)/c++/v1
+	chmod 644 $(HEADER_DIR)/c++/v1/*
+	chmod 755 $(HEADER_DIR)/c++/v1/ext
+	chmod 644 $(HEADER_DIR)/c++/v1/ext/*
+	chmod 755 $(HEADER_DIR)/c++/v1/experimental
+	chmod 644 $(HEADER_DIR)/c++/v1/experimental/*
+
+install::
+
+	cd lib && ./buildit
+	ditto lib/libc++.1.dylib $(SYMROOT)/usr/lib/libc++.1.dylib
+	cd lib && dsymutil -o $(SYMROOT)/libc++.1.dylib.dSYM \
+	  $(SYMROOT)/usr/lib/libc++.1.dylib
+	mkdir -p $(INSTALL_DIR)/usr/lib
+	strip -S -o $(INSTALL_DIR)/usr/lib/libc++.1.dylib \
+	  $(SYMROOT)/usr/lib/libc++.1.dylib
+	cd $(INSTALL_DIR)/usr/lib && ln -s libc++.1.dylib libc++.dylib
diff --git a/rc1/cmake/Modules/GetTriple.cmake b/rc1/cmake/Modules/GetTriple.cmake
new file mode 100644
index 0000000..c555931
--- /dev/null
+++ b/rc1/cmake/Modules/GetTriple.cmake
@@ -0,0 +1,53 @@
+# Define functions to get the host and target triple.
+
+function(get_host_triple out out_arch out_vendor out_os)
+  # Get the architecture.
+  set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})
+  if (arch STREQUAL "x86")
+    set(arch "i686")
+  endif()
+  # Get the vendor.
+  if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
+    set(vendor "apple")
+  else()
+    set(vendor "pc")
+  endif()
+  # Get os.
+  if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
+    set(os "win32")
+  else()
+    string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} os)
+  endif()
+  set(triple "${arch}-${vendor}-${os}")
+  set(${out} ${triple} PARENT_SCOPE)
+  set(${out_arch} ${arch} PARENT_SCOPE)
+  set(${out_vendor} ${vendor} PARENT_SCOPE)
+  set(${out_os} ${os} PARENT_SCOPE)
+  message(STATUS "Host triple: ${triple}")
+endfunction()
+
+function(get_target_triple out out_arch out_vendor out_os)
+  # Get the architecture.
+  set(arch ${CMAKE_SYSTEM_PROCESSOR})
+  if (arch STREQUAL "x86")
+    set(arch "i686")
+  endif()
+  # Get the vendor.
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+    set(vendor "apple")
+  else()
+    set(vendor "pc")
+  endif()
+  # Get os.
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+    set(os "win32")
+  else()
+    string(TOLOWER ${CMAKE_SYSTEM_NAME} os)
+  endif()
+  set(triple "${arch}-${vendor}-${os}")
+  set(${out} ${triple} PARENT_SCOPE)
+  set(${out_arch} ${arch} PARENT_SCOPE)
+  set(${out_vendor} ${vendor} PARENT_SCOPE)
+  set(${out_os} ${os} PARENT_SCOPE)
+  message(STATUS "Target triple: ${triple}")
+endfunction()
diff --git a/rc1/cmake/Modules/HandleLibCXXABI.cmake b/rc1/cmake/Modules/HandleLibCXXABI.cmake
new file mode 100644
index 0000000..4d2a869
--- /dev/null
+++ b/rc1/cmake/Modules/HandleLibCXXABI.cmake
@@ -0,0 +1,98 @@
+
+#===============================================================================
+# Add an ABI library if appropriate
+#===============================================================================
+
+#
+# _setup_abi: Set up the build to use an ABI library
+#
+# Parameters:
+#   abidefines: A list of defines needed to compile libc++ with the ABI library
+#   abilib    : The ABI library to link against.
+#   abifiles  : A list of files (which may be relative paths) to copy into the
+#               libc++ build tree for the build.  These files will also be
+#               installed alongside the libc++ headers.
+#   abidirs   : A list of relative paths to create under an include directory
+#               in the libc++ build directory.
+#
+macro(setup_abi_lib abipathvar abidefines abilib abifiles abidirs)
+  list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
+  set(${abipathvar} "${${abipathvar}}"
+    CACHE PATH
+    "Paths to C++ ABI header directories separated by ';'." FORCE
+    )
+
+  set(LIBCXX_CXX_ABI_LIBRARY ${abilib})
+
+  set(LIBCXX_ABILIB_FILES ${abifiles})
+
+  file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
+  foreach(_d ${abidirs})
+    file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}")
+  endforeach()
+
+  foreach(fpath ${LIBCXX_ABILIB_FILES})
+    set(found FALSE)
+    foreach(incpath ${${abipathvar}})
+      if (EXISTS "${incpath}/${fpath}")
+        set(found TRUE)
+        get_filename_component(dstdir ${fpath} PATH)
+        get_filename_component(ifile ${fpath} NAME)
+        file(COPY "${incpath}/${fpath}"
+          DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}"
+          )
+        install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
+          DESTINATION include/c++/v1/${dstdir}
+          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+          )
+        list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}")
+      endif()
+    endforeach()
+    if (NOT found)
+      message(FATAL_ERROR "Failed to find ${fpath}")
+    endif()
+  endforeach()
+
+  add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers})
+  include_directories("${CMAKE_BINARY_DIR}/include")
+
+endmacro()
+
+if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
+    "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
+  set(_LIBSUPCXX_INCLUDE_FILES
+    cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
+    bits/cxxabi_tweaks.h bits/cxxabi_forced.h
+    )
+  if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
+    set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
+    set(_LIBSUPCXX_LIBNAME stdc++)
+  else()
+    set(_LIBSUPCXX_DEFINES "")
+    set(_LIBSUPCXX_LIBNAME supc++)
+  endif()
+  setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS"
+    "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
+    "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
+    )
+elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
+  if (LIBCXX_CXX_ABI_INTREE)
+    # Link against just-built "cxxabi" target.
+    set(CXXABI_LIBNAME cxxabi)
+  else()
+    # Assume c++abi is installed in the system, rely on -lc++abi link flag.
+    set(CXXABI_LIBNAME "c++abi")
+  endif()
+  setup_abi_lib("LIBCXX_LIBCXXABI_INCLUDE_PATHS" ""
+    ${CXXABI_LIBNAME} "cxxabi.h" ""
+    )
+elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
+  setup_abi_lib("LIBCXX_LIBCXXRT_INCLUDE_PATHS" "-DLIBCXXRT"
+    "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
+    )
+elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
+  message(FATAL_ERROR
+    "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are "
+    "supported for c++ abi."
+    )
+endif ()
\ No newline at end of file
diff --git a/rc1/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake b/rc1/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
new file mode 100644
index 0000000..a066936
--- /dev/null
+++ b/rc1/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
@@ -0,0 +1,18 @@
+# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+
+macro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage )
+
+string( COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource )
+if( _insource )
+ message( SEND_ERROR "${_errorMessage}" )
+ message( FATAL_ERROR
+ "In-source builds are not allowed.
+ CMake would overwrite the makefiles distributed with Compiler-RT.
+ Please create a directory and run cmake from there, passing the path
+ to this source directory as the last argument.
+ This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
+ Please delete them."
+ )
+endif( _insource )
+
+endmacro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD )
diff --git a/rc1/cmake/config-ix.cmake b/rc1/cmake/config-ix.cmake
new file mode 100644
index 0000000..428d737
--- /dev/null
+++ b/rc1/cmake/config-ix.cmake
@@ -0,0 +1,35 @@
+include(CheckLibraryExists)
+include(CheckCXXCompilerFlag)
+
+# Check compiler flags
+check_cxx_compiler_flag(-std=c++11              LIBCXX_HAS_STDCXX11_FLAG)
+check_cxx_compiler_flag(-std=c++1y              LIBCXX_HAS_STDCXX1Y_FLAG)
+check_cxx_compiler_flag(-fPIC                   LIBCXX_HAS_FPIC_FLAG)
+check_cxx_compiler_flag(-fno-omit-frame-pointer LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG)
+check_cxx_compiler_flag(-nodefaultlibs          LIBCXX_HAS_NODEFAULTLIBS_FLAG)
+check_cxx_compiler_flag(-nostdinc++             LIBCXX_HAS_NOSTDINCXX_FLAG)
+check_cxx_compiler_flag(-Wall                   LIBCXX_HAS_WALL_FLAG)
+check_cxx_compiler_flag(-W                      LIBCXX_HAS_W_FLAG)
+check_cxx_compiler_flag(-Wno-unused-parameter   LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG)
+check_cxx_compiler_flag(-Wwrite-strings         LIBCXX_HAS_WWRITE_STRINGS_FLAG)
+check_cxx_compiler_flag(-Wno-long-long          LIBCXX_HAS_WNO_LONG_LONG_FLAG)
+check_cxx_compiler_flag(-pedantic               LIBCXX_HAS_PEDANTIC_FLAG)
+check_cxx_compiler_flag(-Werror                 LIBCXX_HAS_WERROR_FLAG)
+check_cxx_compiler_flag(-Wno-error              LIBCXX_HAS_WNO_ERROR_FLAG)
+check_cxx_compiler_flag(-fno-exceptions         LIBCXX_HAS_FNO_EXCEPTIONS_FLAG)
+check_cxx_compiler_flag(-fno-rtti               LIBCXX_HAS_FNO_RTTI_FLAG)
+check_cxx_compiler_flag(-gline-tables-only      LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG)
+check_cxx_compiler_flag(/WX                     LIBCXX_HAS_WX_FLAG)
+check_cxx_compiler_flag(/WX-                    LIBCXX_HAS_NO_WX_FLAG)
+check_cxx_compiler_flag(/EHsc                   LIBCXX_HAS_EHSC_FLAG)
+check_cxx_compiler_flag(/EHs-                   LIBCXX_HAS_NO_EHS_FLAG)
+check_cxx_compiler_flag(/EHa-                   LIBCXX_HAS_NO_EHA_FLAG)
+check_cxx_compiler_flag(/GR-                    LIBCXX_HAS_NO_GR_FLAG)
+
+# Check libraries
+check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
+check_library_exists(c printf "" LIBCXX_HAS_C_LIB)
+check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
+check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
+check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
+
diff --git a/rc1/include/CMakeLists.txt b/rc1/include/CMakeLists.txt
new file mode 100644
index 0000000..95206bf
--- /dev/null
+++ b/rc1/include/CMakeLists.txt
@@ -0,0 +1,24 @@
+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
+  ${LIBCXX_SUPPORT_HEADER_PATTERN}
+  )
+
+file(COPY .
+  DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1"
+  FILES_MATCHING
+  ${LIBCXX_HEADER_PATTERN}
+  )
+
+if (LIBCXX_INSTALL_HEADERS)
+  install(DIRECTORY .
+    DESTINATION include/c++/v1
+    FILES_MATCHING
+    ${LIBCXX_HEADER_PATTERN}
+    PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+  )
+endif()
diff --git a/rc1/include/__bit_reference b/rc1/include/__bit_reference
new file mode 100644
index 0000000..4938f44
--- /dev/null
+++ b/rc1/include/__bit_reference
@@ -0,0 +1,1287 @@
+// -*- 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___BIT_REFERENCE
+#define _LIBCPP___BIT_REFERENCE
+
+#include <__config>
+#include <algorithm>
+
+#include <__undef_min_max>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
+template <class _Cp> class __bit_const_reference;
+
+template <class _Tp>
+struct __has_storage_type
+{
+    static const bool value = false;
+};
+
+template <class _Cp, bool = __has_storage_type<_Cp>::value>
+class __bit_reference
+{
+    typedef typename _Cp::__storage_type    __storage_type;
+    typedef typename _Cp::__storage_pointer __storage_pointer;
+
+    __storage_pointer __seg_;
+    __storage_type    __mask_;
+
+#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
+    friend typename _Cp::__self;
+#else
+    friend class _Cp::__self;
+#endif
+    friend class __bit_const_reference<_Cp>;
+    friend class __bit_iterator<_Cp, false>;
+public:
+    _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
+        {return static_cast<bool>(*__seg_ & __mask_);}
+    _LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT
+        {return !static_cast<bool>(*this);}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference& operator=(bool __x) _NOEXCEPT
+    {
+        if (__x)
+            *__seg_ |= __mask_;
+        else
+            *__seg_ &= ~__mask_;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT
+        {return operator=(static_cast<bool>(__x));}
+
+    _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;}
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT
+        {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
+        : __seg_(__s), __mask_(__m) {}
+};
+
+template <class _Cp>
+class __bit_reference<_Cp, false>
+{
+};
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _Cp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _Cp>
+class __bit_const_reference
+{
+    typedef typename _Cp::__storage_type          __storage_type;
+    typedef typename _Cp::__const_storage_pointer __storage_pointer;
+
+    __storage_pointer        __seg_;
+    __storage_type __mask_;
+
+#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
+    friend typename _Cp::__self;
+#else
+    friend class _Cp::__self;
+#endif
+    friend class __bit_iterator<_Cp, true>;
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
+        : __seg_(__x.__seg_), __mask_(__x.__mask_) {}
+
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
+        {return static_cast<bool>(*__seg_ & __mask_);}
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
+        {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_CONSTEXPR
+    __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
+        : __seg_(__s), __mask_(__m) {}
+
+    __bit_const_reference& operator=(const __bit_const_reference& __x);
+};
+
+// find
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _It;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __storage_type __b = *__first.__seg_ & __m;
+        if (__b)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+        if (__n == __dn)
+            return __first + __n;
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
+        if (*__first.__seg_)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(*__first.__seg_)));
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __storage_type __b = *__first.__seg_ & __m;
+        if (__b)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+    }
+    return _It(__first.__seg_, static_cast<unsigned>(__n));
+}
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _It;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __storage_type __b = ~*__first.__seg_ & __m;
+        if (__b)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+        if (__n == __dn)
+            return __first + __n;
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
+    {
+        __storage_type __b = ~*__first.__seg_;
+        if (__b)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+    }
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __storage_type __b = ~*__first.__seg_ & __m;
+        if (__b)
+            return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+    }
+    return _It(__first.__seg_, static_cast<unsigned>(__n));
+}
+
+template <class _Cp, bool _IsConst, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_Cp, _IsConst>
+find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
+{
+    if (static_cast<bool>(__value_))
+        return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
+    return __find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
+}
+
+// count
+
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _It;
+    typedef typename _It::__storage_type __storage_type;
+    typedef typename _It::difference_type difference_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    difference_type __r = 0;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __r = _VSTD::__pop_count(*__first.__seg_ & __m);
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
+        __r += _VSTD::__pop_count(*__first.__seg_);
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __r += _VSTD::__pop_count(*__first.__seg_ & __m);
+    }
+    return __r;
+}
+
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _It;
+    typedef typename _It::__storage_type __storage_type;
+    typedef typename _It::difference_type difference_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    difference_type __r = 0;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __r = _VSTD::__pop_count(~*__first.__seg_ & __m);
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
+        __r += _VSTD::__pop_count(~*__first.__seg_);
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __r += _VSTD::__pop_count(~*__first.__seg_ & __m);
+    }
+    return __r;
+}
+
+template <class _Cp, bool _IsConst, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
+{
+    if (static_cast<bool>(__value_))
+        return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
+    return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
+}
+
+// fill_n
+
+template <class _Cp>
+void
+__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, false> _It;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        *__first.__seg_ &= ~__m;
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    __storage_type __nw = __n / __bits_per_word;
+    _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type));
+    __n -= __nw * __bits_per_word;
+    // do last partial word
+    if (__n > 0)
+    {
+        __first.__seg_ += __nw;
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        *__first.__seg_ &= ~__m;
+    }
+}
+
+template <class _Cp>
+void
+__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+{
+    typedef __bit_iterator<_Cp, false> _It;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    // do first partial word
+    if (__first.__ctz_ != 0)
+    {
+        __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
+        __storage_type __dn = _VSTD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        *__first.__seg_ |= __m;
+        __n -= __dn;
+        ++__first.__seg_;
+    }
+    // do middle whole words
+    __storage_type __nw = __n / __bits_per_word;
+    _VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type));
+    __n -= __nw * __bits_per_word;
+    // do last partial word
+    if (__n > 0)
+    {
+        __first.__seg_ += __nw;
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        *__first.__seg_ |= __m;
+    }
+}
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_)
+{
+    if (__n > 0)
+    {
+        if (__value_)
+            __fill_n_true(__first, __n);
+        else
+            __fill_n_false(__first, __n);
+    }
+}
+
+// fill
+
+template <class _Cp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_)
+{
+    _VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value_);
+}
+
+// copy
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, false>
+__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
+                                                     __bit_iterator<_Cp, false> __result)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _In;
+    typedef  typename _In::difference_type difference_type;
+    typedef typename _In::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _In::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first.__ctz_ != 0)
+        {
+            unsigned __clz = __bits_per_word - __first.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
+            __storage_type __b = *__first.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b;
+            __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_)  % __bits_per_word);
+            ++__first.__seg_;
+            // __first.__ctz_ = 0;
+        }
+        // __first.__ctz_ == 0;
+        // do middle words
+        __storage_type __nw = __n / __bits_per_word;
+        _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
+                       _VSTD::__to_raw_pointer(__first.__seg_),
+                       __nw * sizeof(__storage_type));
+        __n -= __nw * __bits_per_word;
+        __result.__seg_ += __nw;
+        // do last word
+        if (__n > 0)
+        {
+            __first.__seg_ += __nw;
+            __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            __storage_type __b = *__first.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b;
+            __result.__ctz_ = static_cast<unsigned>(__n);
+        }
+    }
+    return __result;
+}
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, false>
+__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
+                                                       __bit_iterator<_Cp, false> __result)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _In;
+    typedef  typename _In::difference_type difference_type;
+    typedef typename _In::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _In::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first.__ctz_ != 0)
+        {
+            unsigned __clz_f = __bits_per_word - __first.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+            __storage_type __b = *__first.__seg_ & __m;
+            unsigned __clz_r = __bits_per_word - __result.__ctz_;
+            __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
+            __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
+            *__result.__seg_ &= ~__m;
+            if (__result.__ctz_ > __first.__ctz_)
+                *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
+            else
+                *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
+            __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_)  % __bits_per_word);
+            __dn -= __ddn;
+            if (__dn > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __dn);
+                *__result.__seg_ &= ~__m;
+                *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
+                __result.__ctz_ = static_cast<unsigned>(__dn);
+            }
+            ++__first.__seg_;
+            // __first.__ctz_ = 0;
+        }
+        // __first.__ctz_ == 0;
+        // do middle words
+        unsigned __clz_r = __bits_per_word - __result.__ctz_;
+        __storage_type __m = ~__storage_type(0) << __result.__ctz_;
+        for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
+        {
+            __storage_type __b = *__first.__seg_;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b << __result.__ctz_;
+            ++__result.__seg_;
+            *__result.__seg_ &= __m;
+            *__result.__seg_ |= __b >> __clz_r;
+        }
+        // do last word
+        if (__n > 0)
+        {
+            __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            __storage_type __b = *__first.__seg_ & __m;
+            __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
+            __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b << __result.__ctz_;
+            __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_)  % __bits_per_word);
+            __n -= __dn;
+            if (__n > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __n);
+                *__result.__seg_ &= ~__m;
+                *__result.__seg_ |= __b >> __dn;
+                __result.__ctz_ = static_cast<unsigned>(__n);
+            }
+        }
+    }
+    return __result;
+}
+
+template <class _Cp, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_Cp, false>
+copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
+{
+    if (__first.__ctz_ == __result.__ctz_)
+        return __copy_aligned(__first, __last, __result);
+    return __copy_unaligned(__first, __last, __result);
+}
+
+// copy_backward
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, false>
+__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
+                                                     __bit_iterator<_Cp, false> __result)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _In;
+    typedef  typename _In::difference_type difference_type;
+    typedef typename _In::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _In::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__last.__ctz_ != 0)
+        {
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
+            __n -= __dn;
+            unsigned __clz = __bits_per_word - __last.__ctz_;
+            __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz);
+            __storage_type __b = *__last.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b;
+            __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
+                                                       __result.__ctz_)  % __bits_per_word);
+            // __last.__ctz_ = 0
+         }
+        // __last.__ctz_ == 0 || __n == 0
+        // __result.__ctz_ == 0 || __n == 0
+        // do middle words
+        __storage_type __nw = __n / __bits_per_word;
+        __result.__seg_ -= __nw;
+        __last.__seg_ -= __nw;
+        _VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
+                       _VSTD::__to_raw_pointer(__last.__seg_),
+                       __nw * sizeof(__storage_type));
+        __n -= __nw * __bits_per_word;
+        // do last word
+        if (__n > 0)
+        {
+            __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n);
+            __storage_type __b = *--__last.__seg_ & __m;
+            *--__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b;
+            __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
+        }
+    }
+    return __result;
+}
+
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, false>
+__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
+                                                       __bit_iterator<_Cp, false> __result)
+{
+    typedef __bit_iterator<_Cp, _IsConst> _In;
+    typedef  typename _In::difference_type difference_type;
+    typedef typename _In::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _In::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__last.__ctz_ != 0)
+        {
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
+            __n -= __dn;
+            unsigned __clz_l = __bits_per_word - __last.__ctz_;
+            __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l);
+            __storage_type __b = *__last.__seg_ & __m;
+            unsigned __clz_r = __bits_per_word - __result.__ctz_;
+            __storage_type __ddn = _VSTD::min(__dn, static_cast<difference_type>(__result.__ctz_));
+            if (__ddn > 0)
+            {
+                __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r);
+                *__result.__seg_ &= ~__m;
+                if (__result.__ctz_ > __last.__ctz_)
+                    *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
+                else
+                    *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
+                __result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) +
+                                                         __result.__ctz_)  % __bits_per_word);
+                __dn -= __ddn;
+            }
+            if (__dn > 0)
+            {
+                // __result.__ctz_ == 0
+                --__result.__seg_;
+                __result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
+                __m = ~__storage_type(0) << __result.__ctz_;
+                *__result.__seg_ &= ~__m;
+                __last.__ctz_ -= __dn + __ddn;
+                *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
+            }
+            // __last.__ctz_ = 0
+         }
+        // __last.__ctz_ == 0 || __n == 0
+        // __result.__ctz_ != 0 || __n == 0
+        // do middle words
+        unsigned __clz_r = __bits_per_word - __result.__ctz_;
+        __storage_type __m = ~__storage_type(0) >> __clz_r;
+        for (; __n >= __bits_per_word; __n -= __bits_per_word)
+        {
+            __storage_type __b = *--__last.__seg_;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b >> __clz_r;
+            *--__result.__seg_ &= __m;
+            *__result.__seg_ |= __b << __result.__ctz_;
+        }
+        // do last word
+        if (__n > 0)
+        {
+            __m = ~__storage_type(0) << (__bits_per_word - __n);
+            __storage_type __b = *--__last.__seg_ & __m;
+            __clz_r = __bits_per_word - __result.__ctz_;
+            __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__result.__ctz_));
+            __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
+            __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
+                                                     __result.__ctz_)  % __bits_per_word);
+            __n -= __dn;
+            if (__n > 0)
+            {
+                // __result.__ctz_ == 0
+                --__result.__seg_;
+                __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
+                __m = ~__storage_type(0) << __result.__ctz_;
+                *__result.__seg_ &= ~__m;
+                *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
+            }
+        }
+    }
+    return __result;
+}
+
+template <class _Cp, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_Cp, false>
+copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
+{
+    if (__last.__ctz_ == __result.__ctz_)
+        return __copy_backward_aligned(__first, __last, __result);
+    return __copy_backward_unaligned(__first, __last, __result);
+}
+
+// move
+
+template <class _Cp, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_Cp, false>
+move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
+{
+    return _VSTD::copy(__first, __last, __result);
+}
+
+// move_backward
+
+template <class _Cp, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_Cp, false>
+move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
+{
+    return _VSTD::copy_backward(__first, __last, __result);
+}
+
+// swap_ranges
+
+template <class __C1, class __C2>
+__bit_iterator<__C2, false>
+__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
+                      __bit_iterator<__C2, false> __result)
+{
+    typedef __bit_iterator<__C1, false> _I1;
+    typedef  typename _I1::difference_type difference_type;
+    typedef typename _I1::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _I1::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first.__ctz_ != 0)
+        {
+            unsigned __clz = __bits_per_word - __first.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
+            __storage_type __b1 = *__first.__seg_ & __m;
+            *__first.__seg_ &= ~__m;
+            __storage_type __b2 = *__result.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b1;
+            *__first.__seg_  |= __b2;
+            __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_)  % __bits_per_word);
+            ++__first.__seg_;
+            // __first.__ctz_ = 0;
+        }
+        // __first.__ctz_ == 0;
+        // do middle words
+        for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_)
+            swap(*__first.__seg_, *__result.__seg_);
+        // do last word
+        if (__n > 0)
+        {
+            __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            __storage_type __b1 = *__first.__seg_ & __m;
+            *__first.__seg_ &= ~__m;
+            __storage_type __b2 = *__result.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b1;
+            *__first.__seg_  |= __b2;
+            __result.__ctz_ = static_cast<unsigned>(__n);
+        }
+    }
+    return __result;
+}
+
+template <class __C1, class __C2>
+__bit_iterator<__C2, false>
+__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
+                        __bit_iterator<__C2, false> __result)
+{
+    typedef __bit_iterator<__C1, false> _I1;
+    typedef  typename _I1::difference_type difference_type;
+    typedef typename _I1::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _I1::__bits_per_word;
+    difference_type __n = __last - __first;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first.__ctz_ != 0)
+        {
+            unsigned __clz_f = __bits_per_word - __first.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+            __storage_type __b1 = *__first.__seg_ & __m;
+            *__first.__seg_ &= ~__m;
+            unsigned __clz_r = __bits_per_word - __result.__ctz_;
+            __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
+            __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
+            __storage_type __b2 = *__result.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            if (__result.__ctz_ > __first.__ctz_)
+            {
+                unsigned __s = __result.__ctz_ - __first.__ctz_;
+                *__result.__seg_ |= __b1 << __s;
+                *__first.__seg_  |= __b2 >> __s;
+            }
+            else
+            {
+                unsigned __s = __first.__ctz_ - __result.__ctz_;
+                *__result.__seg_ |= __b1 >> __s;
+                *__first.__seg_  |= __b2 << __s;
+            }
+            __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_)  % __bits_per_word);
+            __dn -= __ddn;
+            if (__dn > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __dn);
+                __b2 = *__result.__seg_ & __m;
+                *__result.__seg_ &= ~__m;
+                unsigned __s = __first.__ctz_ + __ddn;
+                *__result.__seg_ |= __b1 >> __s;
+                *__first.__seg_  |= __b2 << __s;
+                __result.__ctz_ = static_cast<unsigned>(__dn);
+            }
+            ++__first.__seg_;
+            // __first.__ctz_ = 0;
+        }
+        // __first.__ctz_ == 0;
+        // do middle words
+        __storage_type __m = ~__storage_type(0) << __result.__ctz_;
+        unsigned __clz_r = __bits_per_word - __result.__ctz_;
+        for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
+        {
+            __storage_type __b1 = *__first.__seg_;
+            __storage_type __b2 = *__result.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b1 << __result.__ctz_;
+            *__first.__seg_  = __b2 >> __result.__ctz_;
+            ++__result.__seg_;
+            __b2 = *__result.__seg_ & ~__m;
+            *__result.__seg_ &= __m;
+            *__result.__seg_ |= __b1 >> __clz_r;
+            *__first.__seg_  |= __b2 << __clz_r;
+        }
+        // do last word
+        if (__n > 0)
+        {
+            __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            __storage_type __b1 = *__first.__seg_ & __m;
+            *__first.__seg_ &= ~__m;
+            __storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r);
+            __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
+            __storage_type __b2 = *__result.__seg_ & __m;
+            *__result.__seg_ &= ~__m;
+            *__result.__seg_ |= __b1 << __result.__ctz_;
+            *__first.__seg_  |= __b2 >> __result.__ctz_;
+            __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
+            __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_)  % __bits_per_word);
+            __n -= __dn;
+            if (__n > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __n);
+                __b2 = *__result.__seg_ & __m;
+                *__result.__seg_ &= ~__m;
+                *__result.__seg_ |= __b1 >> __dn;
+                *__first.__seg_  |= __b2 << __dn;
+                __result.__ctz_ = static_cast<unsigned>(__n);
+            }
+        }
+    }
+    return __result;
+}
+
+template <class __C1, class __C2>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<__C2, false>
+swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1,
+            __bit_iterator<__C2, false> __first2)
+{
+    if (__first1.__ctz_ == __first2.__ctz_)
+        return __swap_ranges_aligned(__first1, __last1, __first2);
+    return __swap_ranges_unaligned(__first1, __last1, __first2);
+}
+
+// rotate
+
+template <class _Cp>
+struct __bit_array
+{
+    typedef typename _Cp::difference_type difference_type;
+    typedef typename _Cp::__storage_type  __storage_type;
+    typedef typename _Cp::__storage_pointer __storage_pointer;
+    typedef typename _Cp::iterator        iterator;
+    static const unsigned __bits_per_word = _Cp::__bits_per_word;
+    static const unsigned _Np = 4;
+
+    difference_type __size_;
+    __storage_type __word_[_Np];
+
+    _LIBCPP_INLINE_VISIBILITY static difference_type capacity()
+        {return static_cast<difference_type>(_Np * __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
+    _LIBCPP_INLINE_VISIBILITY iterator begin()
+    {
+        return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
+    }
+    _LIBCPP_INLINE_VISIBILITY iterator end()
+    {
+        return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
+                                                  static_cast<unsigned>(__size_ % __bits_per_word));
+    }
+};
+
+template <class _Cp>
+__bit_iterator<_Cp, false>
+rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last)
+{
+    typedef __bit_iterator<_Cp, false> _I1;
+    typedef  typename _I1::difference_type difference_type;
+    typedef typename _I1::__storage_type __storage_type;
+    difference_type __d1 = __middle - __first;
+    difference_type __d2 = __last - __middle;
+    _I1 __r = __first + __d2;
+    while (__d1 != 0 && __d2 != 0)
+    {
+        if (__d1 <= __d2)
+        {
+            if (__d1 <= __bit_array<_Cp>::capacity())
+            {
+                __bit_array<_Cp> __b(__d1);
+                _VSTD::copy(__first, __middle, __b.begin());
+                _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first));
+                break;
+            }
+            else
+            {
+                __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle);
+                __first = __middle;
+                __middle = __mp;
+                __d2 -= __d1;
+            }
+        }
+        else
+        {
+            if (__d2 <= __bit_array<_Cp>::capacity())
+            {
+                __bit_array<_Cp> __b(__d2);
+                _VSTD::copy(__middle, __last, __b.begin());
+                _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last));
+                break;
+            }
+            else
+            {
+                __bit_iterator<_Cp, false> __mp = __first + __d2;
+                _VSTD::swap_ranges(__first, __mp, __middle);
+                __first = __mp;
+                __d1 -= __d2;
+            }
+        }
+    }
+    return __r;
+}
+
+// equal
+
+template <class _Cp, bool _IC1, bool _IC2>
+bool
+__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
+                  __bit_iterator<_Cp, _IC2> __first2)
+{
+    typedef __bit_iterator<_Cp, _IC1> _It;
+    typedef  typename _It::difference_type difference_type;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    difference_type __n = __last1 - __first1;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first1.__ctz_ != 0)
+        {
+            unsigned __clz_f = __bits_per_word - __first1.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+            __storage_type __b = *__first1.__seg_ & __m;
+            unsigned __clz_r = __bits_per_word - __first2.__ctz_;
+            __storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
+            __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
+            if (__first2.__ctz_ > __first1.__ctz_)
+            {
+                if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_)))
+                    return false;
+            }
+            else
+            {
+                if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_)))
+                    return false;
+            }
+            __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word;
+            __first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_)  % __bits_per_word);
+            __dn -= __ddn;
+            if (__dn > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __dn);
+                if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn)))
+                    return false;
+                __first2.__ctz_ = static_cast<unsigned>(__dn);
+            }
+            ++__first1.__seg_;
+            // __first1.__ctz_ = 0;
+        }
+        // __first1.__ctz_ == 0;
+        // do middle words
+        unsigned __clz_r = __bits_per_word - __first2.__ctz_;
+        __storage_type __m = ~__storage_type(0) << __first2.__ctz_;
+        for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_)
+        {
+            __storage_type __b = *__first1.__seg_;
+            if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
+                return false;
+            ++__first2.__seg_;
+            if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r))
+                return false;
+        }
+        // do last word
+        if (__n > 0)
+        {
+            __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            __storage_type __b = *__first1.__seg_ & __m;
+            __storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
+            __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
+            if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
+                return false;
+            __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word;
+            __first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_)  % __bits_per_word);
+            __n -= __dn;
+            if (__n > 0)
+            {
+                __m = ~__storage_type(0) >> (__bits_per_word - __n);
+                if ((*__first2.__seg_ & __m) != (__b >> __dn))
+                    return false;
+            }
+        }
+    }
+    return true;
+}
+
+template <class _Cp, bool _IC1, bool _IC2>
+bool
+__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
+                __bit_iterator<_Cp, _IC2> __first2)
+{
+    typedef __bit_iterator<_Cp, _IC1> _It;
+    typedef  typename _It::difference_type difference_type;
+    typedef typename _It::__storage_type __storage_type;
+    static const unsigned __bits_per_word = _It::__bits_per_word;
+    difference_type __n = __last1 - __first1;
+    if (__n > 0)
+    {
+        // do first word
+        if (__first1.__ctz_ != 0)
+        {
+            unsigned __clz = __bits_per_word - __first1.__ctz_;
+            difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
+            __n -= __dn;
+            __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
+            if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
+                return false;
+            ++__first2.__seg_;
+            ++__first1.__seg_;
+            // __first1.__ctz_ = 0;
+            // __first2.__ctz_ = 0;
+        }
+        // __first1.__ctz_ == 0;
+        // __first2.__ctz_ == 0;
+        // do middle words
+        for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_)
+            if (*__first2.__seg_ != *__first1.__seg_)
+                return false;
+        // do last word
+        if (__n > 0)
+        {
+            __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+            if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
+                return false;
+        }
+    }
+    return true;
+}
+
+template <class _Cp, bool _IC1, bool _IC2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2)
+{
+    if (__first1.__ctz_ == __first2.__ctz_)
+        return __equal_aligned(__first1, __last1, __first2);
+    return __equal_unaligned(__first1, __last1, __first2);
+}
+
+template <class _Cp, bool _IsConst,
+          typename _Cp::__storage_type>
+class __bit_iterator
+{
+public:
+    typedef typename _Cp::difference_type                                                          difference_type;
+    typedef bool                                                                                  value_type;
+    typedef __bit_iterator                                                                        pointer;
+    typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference;
+    typedef random_access_iterator_tag                                                            iterator_category;
+
+private:
+    typedef typename _Cp::__storage_type                                           __storage_type;
+    typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer,
+                                           typename _Cp::__storage_pointer>::type  __storage_pointer;
+    static const unsigned __bits_per_word = _Cp::__bits_per_word;
+
+    __storage_pointer __seg_;
+    unsigned          __ctz_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT
+#if _LIBCPP_STD_VER > 11
+    : __seg_(nullptr), __ctz_(0)
+#endif
+    {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
+        : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
+        {return reference(__seg_, __storage_type(1) << __ctz_);}
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++()
+    {
+        if (__ctz_ != __bits_per_word-1)
+            ++__ctz_;
+        else
+        {
+            __ctz_ = 0;
+            ++__seg_;
+        }
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int)
+    {
+        __bit_iterator __tmp = *this;
+        ++(*this);
+        return __tmp;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--()
+    {
+        if (__ctz_ != 0)
+            --__ctz_;
+        else
+        {
+            __ctz_ = __bits_per_word - 1;
+            --__seg_;
+        }
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int)
+    {
+        __bit_iterator __tmp = *this;
+        --(*this);
+        return __tmp;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n)
+    {
+        if (__n >= 0)
+            __seg_ += (__n + __ctz_) / __bits_per_word;
+        else
+            __seg_ += static_cast<difference_type>(__n - __bits_per_word + __ctz_ + 1)
+                    / static_cast<difference_type>(__bits_per_word);
+        __n &= (__bits_per_word - 1);
+        __ctz_ = static_cast<unsigned>((__n + __ctz_)  % __bits_per_word);
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n)
+    {
+        return *this += -__n;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const
+    {
+        __bit_iterator __t(*this);
+        __t += __n;
+        return __t;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const
+    {
+        __bit_iterator __t(*this);
+        __t -= __n;
+        return __t;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return !(__x == __y);}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return __y < __x;}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return !(__y < __x);}
+
+    _LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y)
+        {return !(__x < __y);}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
+        : __seg_(__s), __ctz_(__ctz) {}
+
+#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
+    friend typename _Cp::__self;
+#else
+    friend class _Cp::__self;
+#endif
+    friend class __bit_reference<_Cp>;
+    friend class __bit_const_reference<_Cp>;
+    friend class __bit_iterator<_Cp, true>;
+    template <class _Dp> friend struct __bit_array;
+    template <class _Dp> friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
+    template <class _Dp> friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first,
+                                                                                  __bit_iterator<_Dp, _IC> __last,
+                                                                                  __bit_iterator<_Dp, false> __result);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first,
+                                                                                    __bit_iterator<_Dp, _IC> __last,
+                                                                                    __bit_iterator<_Dp, false> __result);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first,
+                                                                        __bit_iterator<_Dp, _IC> __last,
+                                                                        __bit_iterator<_Dp, false> __result);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first,
+                                                                                           __bit_iterator<_Dp, _IC> __last,
+                                                                                           __bit_iterator<_Dp, false> __result);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first,
+                                                                                             __bit_iterator<_Dp, _IC> __last,
+                                                                                             __bit_iterator<_Dp, false> __result);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
+                                                                                 __bit_iterator<_Dp, _IC> __last,
+                                                                                 __bit_iterator<_Dp, false> __result);
+    template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
+                                                                                           __bit_iterator<__C1, false>,
+                                                                                           __bit_iterator<__C2, false>);
+    template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>,
+                                                                                             __bit_iterator<__C1, false>,
+                                                                                             __bit_iterator<__C2, false>);
+    template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
+                                                                                 __bit_iterator<__C1, false>,
+                                                                                 __bit_iterator<__C2, false>);
+    template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
+                                                                __bit_iterator<_Dp, false>,
+                                                                __bit_iterator<_Dp, false>);
+    template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
+                                                    __bit_iterator<_Dp, _IC1>,
+                                                    __bit_iterator<_Dp, _IC2>);
+    template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
+                                                      __bit_iterator<_Dp, _IC1>,
+                                                      __bit_iterator<_Dp, _IC2>);
+    template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
+                                                                __bit_iterator<_Dp, _IC1>,
+                                                                __bit_iterator<_Dp, _IC2>);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
+                                                                          typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
+                                                                           typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___BIT_REFERENCE
diff --git a/rc1/include/__config b/rc1/include/__config
new file mode 100644
index 0000000..00ade4e
--- /dev/null
+++ b/rc1/include/__config
@@ -0,0 +1,705 @@
+// -*- C++ -*-
+//===--------------------------- __config ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CONFIG
+#define _LIBCPP_CONFIG
+
+#if !defined(_MSC_VER) || defined(__clang__)
+#pragma GCC system_header
+#endif
+
+#ifdef __GNUC__
+#define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
+#endif
+
+#if !_WIN32
+#include <unistd.h>
+#endif
+
+#define _LIBCPP_VERSION 1101
+
+#define _LIBCPP_ABI_VERSION 1
+
+#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
+#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
+
+#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
+
+#ifdef __LITTLE_ENDIAN__
+#if __LITTLE_ENDIAN__
+#define _LIBCPP_LITTLE_ENDIAN 1
+#define _LIBCPP_BIG_ENDIAN    0
+#endif  // __LITTLE_ENDIAN__
+#endif  // __LITTLE_ENDIAN__
+
+#ifdef __BIG_ENDIAN__
+#if __BIG_ENDIAN__
+#define _LIBCPP_LITTLE_ENDIAN 0
+#define _LIBCPP_BIG_ENDIAN    1
+#endif  // __BIG_ENDIAN__
+#endif  // __BIG_ENDIAN__
+
+#ifdef __FreeBSD__
+# include <sys/endian.h>
+#  if _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 1
+#   define _LIBCPP_BIG_ENDIAN    0
+# else  // _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 0
+#   define _LIBCPP_BIG_ENDIAN    1
+# endif  // _BYTE_ORDER == _LITTLE_ENDIAN
+# ifndef __LONG_LONG_SUPPORTED
+#  define _LIBCPP_HAS_NO_LONG_LONG
+# endif  // __LONG_LONG_SUPPORTED
+#endif  // __FreeBSD__
+
+#ifdef __NetBSD__
+# include <sys/endian.h>
+#  if _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 1
+#   define _LIBCPP_BIG_ENDIAN    0
+# else  // _BYTE_ORDER == _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 0
+#   define _LIBCPP_BIG_ENDIAN    1
+# endif  // _BYTE_ORDER == _LITTLE_ENDIAN
+# define _LIBCPP_HAS_QUICK_EXIT
+#endif  // __NetBSD__
+
+#ifdef _WIN32
+#  define _LIBCPP_LITTLE_ENDIAN 1
+#  define _LIBCPP_BIG_ENDIAN    0
+// Compiler intrinsics (GCC or MSVC)
+#  if defined(__clang__) \
+   || (defined(_MSC_VER) && _MSC_VER >= 1400) \
+   || (defined(__GNUC__) && _GNUC_VER > 403)
+#    define _LIBCPP_HAS_IS_BASE_OF
+#  endif
+#  if defined(_MSC_VER) && !defined(__clang__)
+#    define _LIBCPP_MSVC // Using Microsoft Visual C++ compiler
+#    define _LIBCPP_TOSTRING2(x) #x
+#    define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
+#    define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
+#  endif
+#  // If mingw not explicitly detected, assume using MS C runtime only.
+#  ifndef __MINGW32__
+#    define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
+#  endif
+#endif  // _WIN32
+
+#ifdef __linux__
+#  if defined(__GNUC__) && _GNUC_VER >= 403
+#    define _LIBCPP_HAS_IS_BASE_OF
+#  endif
+#endif
+
+#ifdef __sun__
+# include <sys/isa_defs.h>
+# ifdef _LITTLE_ENDIAN
+#   define _LIBCPP_LITTLE_ENDIAN 1
+#   define _LIBCPP_BIG_ENDIAN    0
+# else
+#   define _LIBCPP_LITTLE_ENDIAN 0
+#   define _LIBCPP_BIG_ENDIAN    1
+# endif
+#endif // __sun__
+
+#if defined(__native_client__)
+  // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
+  // including accesses to the special files under /dev. C++11's
+  // std::random_device is instead exposed through a NaCl syscall.
+# define _LIBCPP_USING_NACL_RANDOM
+#endif // defined(__native_client__)
+
+#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+# include <endian.h>
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define _LIBCPP_LITTLE_ENDIAN 1
+#  define _LIBCPP_BIG_ENDIAN    0
+# elif __BYTE_ORDER == __BIG_ENDIAN
+#  define _LIBCPP_LITTLE_ENDIAN 0
+#  define _LIBCPP_BIG_ENDIAN    1
+# else  // __BYTE_ORDER == __BIG_ENDIAN
+#  error unable to determine endian
+# endif
+#endif  // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+
+#ifdef _WIN32
+
+// only really useful for a DLL
+#ifdef _LIBCPP_DLL // this should be a compiler builtin define ideally...
+# ifdef cxx_EXPORTS
+#  define _LIBCPP_HIDDEN
+#  define _LIBCPP_FUNC_VIS __declspec(dllexport)
+#  define _LIBCPP_TYPE_VIS __declspec(dllexport)
+# else
+#  define _LIBCPP_HIDDEN
+#  define _LIBCPP_FUNC_VIS __declspec(dllimport)
+#  define _LIBCPP_TYPE_VIS __declspec(dllimport)
+# endif
+#else
+# define _LIBCPP_HIDDEN
+# define _LIBCPP_FUNC_VIS
+# define _LIBCPP_TYPE_VIS
+#endif
+
+#define _LIBCPP_TYPE_VIS_ONLY
+#define _LIBCPP_FUNC_VIS_ONLY
+
+#ifndef _LIBCPP_INLINE_VISIBILITY
+# ifdef _LIBCPP_MSVC
+#  define _LIBCPP_INLINE_VISIBILITY __forceinline
+# else // MinGW GCC and Clang
+#  define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__))
+# endif
+#endif
+
+#ifndef _LIBCPP_EXCEPTION_ABI
+#define _LIBCPP_EXCEPTION_ABI _LIBCPP_TYPE_VIS
+#endif
+
+#ifndef _LIBCPP_ALWAYS_INLINE
+# ifdef _LIBCPP_MSVC
+#  define _LIBCPP_ALWAYS_INLINE __forceinline
+# endif
+#endif
+
+#endif // _WIN32
+
+#ifndef __has_attribute
+#define __has_attribute(__x) 0
+#endif
+
+#ifndef _LIBCPP_HIDDEN
+#define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
+#endif
+
+#ifndef _LIBCPP_FUNC_VIS
+#define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
+#endif
+
+#ifndef _LIBCPP_TYPE_VIS
+#  if __has_attribute(__type_visibility__)
+#    define _LIBCPP_TYPE_VIS __attribute__ ((__type_visibility__("default")))
+#  else
+#    define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
+#  endif
+#endif
+
+#ifndef _LIBCPP_TYPE_VIS_ONLY
+# define _LIBCPP_TYPE_VIS_ONLY _LIBCPP_TYPE_VIS
+#endif
+
+#ifndef _LIBCPP_FUNC_VIS_ONLY
+# define _LIBCPP_FUNC_VIS_ONLY _LIBCPP_FUNC_VIS
+#endif
+
+#ifndef _LIBCPP_INLINE_VISIBILITY
+#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
+#endif
+
+#ifndef _LIBCPP_EXCEPTION_ABI
+#define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
+#endif
+
+#ifndef _LIBCPP_ALWAYS_INLINE
+#define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), __always_inline__))
+#endif
+
+#if defined(__clang__)
+
+#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&        \
+    !defined(__arm__)
+#define _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif
+
+#if __has_feature(cxx_alignas)
+#  define _ALIGNAS_TYPE(x) alignas(x)
+#  define _ALIGNAS(x) alignas(x)
+#else
+#  define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
+#  define _ALIGNAS(x) __attribute__((__aligned__(x)))
+#endif
+
+#if !__has_feature(cxx_alias_templates)
+#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+#endif
+
+#if __cplusplus < 201103L
+typedef __char16_t char16_t;
+typedef __char32_t char32_t;
+#endif
+
+#if !(__has_feature(cxx_exceptions))
+#define _LIBCPP_NO_EXCEPTIONS
+#endif
+
+#if !(__has_feature(cxx_rtti))
+#define _LIBCPP_NO_RTTI
+#endif
+
+#if !(__has_feature(cxx_strong_enums))
+#define _LIBCPP_HAS_NO_STRONG_ENUMS
+#endif
+
+#if !(__has_feature(cxx_decltype))
+#define _LIBCPP_HAS_NO_DECLTYPE
+#endif
+
+#if __has_feature(cxx_attributes)
+#  define _LIBCPP_NORETURN [[noreturn]]
+#else
+#  define _LIBCPP_NORETURN __attribute__ ((noreturn))
+#endif
+
+#if !(__has_feature(cxx_defaulted_functions))
+#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#endif  // !(__has_feature(cxx_defaulted_functions))
+
+#if !(__has_feature(cxx_deleted_functions))
+#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+#endif  // !(__has_feature(cxx_deleted_functions))
+
+#if !(__has_feature(cxx_lambdas))
+#define _LIBCPP_HAS_NO_LAMBDAS
+#endif
+
+#if !(__has_feature(cxx_nullptr))
+#define _LIBCPP_HAS_NO_NULLPTR
+#endif
+
+#if !(__has_feature(cxx_rvalue_references))
+#define _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#endif
+
+#if !(__has_feature(cxx_static_assert))
+#define _LIBCPP_HAS_NO_STATIC_ASSERT
+#endif
+
+#if !(__has_feature(cxx_auto_type))
+#define _LIBCPP_HAS_NO_AUTO_TYPE
+#endif
+
+#if !(__has_feature(cxx_access_control_sfinae)) || !__has_feature(cxx_trailing_return)
+#define _LIBCPP_HAS_NO_ADVANCED_SFINAE
+#endif
+
+#if !(__has_feature(cxx_variadic_templates))
+#define _LIBCPP_HAS_NO_VARIADICS
+#endif
+
+#if !(__has_feature(cxx_trailing_return))
+#define _LIBCPP_HAS_NO_TRAILING_RETURN
+#endif
+
+#if !(__has_feature(cxx_generalized_initializers))
+#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+#endif
+
+#if __has_feature(is_base_of)
+#  define _LIBCPP_HAS_IS_BASE_OF
+#endif
+
+// Objective-C++ features (opt-in)
+#if __has_feature(objc_arc)
+#define _LIBCPP_HAS_OBJC_ARC
+#endif
+
+#if __has_feature(objc_arc_weak)
+#define _LIBCPP_HAS_OBJC_ARC_WEAK
+#define _LIBCPP_HAS_NO_STRONG_ENUMS
+#endif
+
+#if !(__has_feature(cxx_constexpr))
+#define _LIBCPP_HAS_NO_CONSTEXPR
+#endif
+
+#if !(__has_feature(cxx_relaxed_constexpr))
+#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
+#endif
+
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
+#if defined(__FreeBSD__)
+#define _LIBCPP_HAS_QUICK_EXIT
+#define _LIBCPP_HAS_C11_FEATURES
+#elif defined(__ANDROID__)
+#define _LIBCPP_HAS_QUICK_EXIT
+#elif defined(__linux__)
+#include <features.h>
+#if __GLIBC_PREREQ(2, 15)
+#define _LIBCPP_HAS_QUICK_EXIT
+#endif
+#if __GLIBC_PREREQ(2, 17)
+#define _LIBCPP_HAS_C11_FEATURES
+#endif
+#endif
+#endif
+
+#if (__has_feature(cxx_noexcept))
+#  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)
+#  define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T)
+#endif
+
+#if __has_feature(is_literal)
+#  define _LIBCPP_IS_LITERAL(T) __is_literal(T)
+#endif
+
+// Inline namespaces are available in Clang regardless of C++ dialect.
+#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE {
+#define _LIBCPP_END_NAMESPACE_STD  } }
+#define _VSTD std::_LIBCPP_NAMESPACE
+
+namespace std {
+  inline namespace _LIBCPP_NAMESPACE {
+  }
+}
+
+#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer)
+#define _LIBCPP_HAS_NO_ASAN
+#endif
+
+#elif defined(__GNUC__)
+
+#define _ALIGNAS(x) __attribute__((__aligned__(x)))
+#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
+
+#define _LIBCPP_NORETURN __attribute__((noreturn))
+
+#if _GNUC_VER >= 407
+#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T)
+#define _LIBCPP_IS_LITERAL(T) __is_literal_type(T)
+#endif
+
+#if !__EXCEPTIONS
+#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
+// Can only use constexpr in c++11 mode.
+#elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
+#define _LIBCPP_HAS_NO_CONSTEXPR
+#endif
+
+// No version of GCC supports relaxed constexpr rules
+#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
+
+#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_DEFAULTED_FUNCTIONS
+#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+#define _LIBCPP_HAS_NO_NULLPTR
+#define _LIBCPP_HAS_NO_STATIC_ASSERT
+#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
+
+#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_RVALUE_REFERENCES
+#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_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_NULLPTR
+#endif
+
+#if _GNUC_VER < 407
+#define _LIBCPP_HAS_NO_ADVANCED_SFINAE
+#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#endif
+
+#endif  // __GXX_EXPERIMENTAL_CXX0X__
+
+#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace _LIBCPP_NAMESPACE {
+#define _LIBCPP_END_NAMESPACE_STD  } }
+#define _VSTD std::_LIBCPP_NAMESPACE
+
+namespace std {
+namespace _LIBCPP_NAMESPACE {
+}
+using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
+}
+
+#if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__)
+#define _LIBCPP_HAS_NO_ASAN
+#endif
+
+#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_UNICODE_CHARS
+#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#define __alignof__ __alignof
+#define _LIBCPP_NORETURN __declspec(noreturn)
+#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  }
+#define _VSTD std
+
+#  define _LIBCPP_WEAK
+namespace std {
+}
+
+#define _LIBCPP_HAS_NO_ASAN
+
+#elif defined(__IBMCPP__)
+
+#define _ALIGNAS(x) __attribute__((__aligned__(x)))
+#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
+#define _ATTRIBUTE(x) __attribute__((x))
+#define _LIBCPP_NORETURN __attribute__((noreturn))
+
+#define _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_NULLPTR
+#define _LIBCPP_HAS_NO_UNICODE_CHARS
+#define _LIBCPP_HAS_IS_BASE_OF
+
+#if defined(_AIX)
+#define __MULTILOCALE_API
+#endif
+
+#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE {
+#define _LIBCPP_END_NAMESPACE_STD  } }
+#define _VSTD std::_LIBCPP_NAMESPACE
+
+namespace std {
+  inline namespace _LIBCPP_NAMESPACE {
+  }
+}
+
+#define _LIBCPP_HAS_NO_ASAN
+
+#endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__
+
+#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
+typedef unsigned short char16_t;
+typedef unsigned int   char32_t;
+#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
+
+#ifndef __SIZEOF_INT128__
+#define _LIBCPP_HAS_NO_INT128
+#endif
+
+#ifdef _LIBCPP_HAS_NO_STATIC_ASSERT
+
+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__)
+
+#endif  // _LIBCPP_HAS_NO_STATIC_ASSERT
+
+#ifdef _LIBCPP_HAS_NO_DECLTYPE
+#define decltype(x) __typeof__(x)
+#endif
+
+#ifdef _LIBCPP_HAS_NO_CONSTEXPR
+#define _LIBCPP_CONSTEXPR
+#else
+#define _LIBCPP_CONSTEXPR constexpr
+#endif
+
+#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+#define _LIBCPP_DEFAULT {}
+#else
+#define _LIBCPP_DEFAULT = default;
+#endif
+
+#ifdef __GNUC__
+#define _NOALIAS __attribute__((__malloc__))
+#else
+#define _NOALIAS
+#endif
+
+#ifndef __has_feature
+#define __has_feature(__x) 0
+#endif
+
+#ifndef __has_builtin
+#define __has_builtin(__x) 0
+#endif
+
+#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
+#   define _LIBCPP_EXPLICIT explicit
+#else
+#   define _LIBCPP_EXPLICIT
+#endif
+
+#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
+#   define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
+#endif
+
+#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
+#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
+#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
+    __lx __v_; \
+    _LIBCPP_ALWAYS_INLINE x(__lx __v) : __v_(__v) {} \
+    _LIBCPP_ALWAYS_INLINE explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
+    _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \
+    };
+#else  // _LIBCPP_HAS_NO_STRONG_ENUMS
+#define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_TYPE_VIS x
+#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
+#endif  // _LIBCPP_HAS_NO_STRONG_ENUMS
+
+#ifdef _LIBCPP_DEBUG
+#   if _LIBCPP_DEBUG == 0
+#       define _LIBCPP_DEBUG_LEVEL 1
+#   elif _LIBCPP_DEBUG == 1
+#       define _LIBCPP_DEBUG_LEVEL 2
+#   else
+#       error Supported values for _LIBCPP_DEBUG are 0 and 1
+#   endif
+#   define _LIBCPP_EXTERN_TEMPLATE(...)
+#endif
+
+#ifndef _LIBCPP_EXTERN_TEMPLATE
+#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
+#endif
+
+#ifndef _LIBCPP_EXTERN_TEMPLATE2
+#define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__;
+#endif
+
+#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
+#define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63)
+#endif
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) || defined(__NetBSD__)
+#define _LIBCPP_LOCALE__L_EXTENSIONS 1
+#endif
+
+#ifdef __FreeBSD__
+#define _DECLARE_C99_LDBL_MATH 1
+#endif
+
+#if defined(__APPLE__) || defined(__FreeBSD__)
+#define _LIBCPP_HAS_DEFAULTRUNELOCALE
+#endif
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
+#define _LIBCPP_WCTYPE_IS_MASK
+#endif
+
+#ifndef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
+#  define _LIBCPP_TRIVIAL_PAIR_COPY_CTOR 1
+#endif
+
+#ifndef _LIBCPP_STD_VER
+#  if  __cplusplus <= 201103L
+#    define _LIBCPP_STD_VER 11
+#  elif __cplusplus <= 201402L
+#    define _LIBCPP_STD_VER 14
+#  else
+#    define _LIBCPP_STD_VER 15  // current year, or date of c++17 ratification
+#  endif
+#endif  // _LIBCPP_STD_VER
+
+#if _LIBCPP_STD_VER > 11
+#define _LIBCPP_DEPRECATED [[deprecated]]
+#else
+#define _LIBCPP_DEPRECATED
+#endif
+
+#if _LIBCPP_STD_VER <= 11
+#define _LIBCPP_EXPLICIT_AFTER_CXX11
+#define _LIBCPP_DEPRECATED_AFTER_CXX11
+#else
+#define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
+#define _LIBCPP_DEPRECATED_AFTER_CXX11 [[deprecated]]
+#endif
+
+#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
+#define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
+#else
+#define _LIBCPP_CONSTEXPR_AFTER_CXX11
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ASAN
+extern "C" void __sanitizer_annotate_contiguous_container(
+  const void *, const void *, const void *, const void *);
+#endif
+
+// Try to find out if RTTI is disabled.
+// g++ and cl.exe have RTTI on by default and define a macro when it is.
+// g++ only defines the macro in 4.3.2 and onwards.
+#if !defined(_LIBCPP_NO_RTTI)
+#  if defined(__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)
+#    define _LIBCPP_NO_RTTI
+#  endif
+#endif
+
+#ifndef _LIBCPP_WEAK
+#  define _LIBCPP_WEAK __attribute__((__weak__))
+#endif
+
+#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
+#  error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
+         _LIBCPP_HAS_NO_THREADS is defined.
+#endif
+
+#endif  // _LIBCPP_CONFIG
diff --git a/rc1/include/__debug b/rc1/include/__debug
new file mode 100644
index 0000000..c151224
--- /dev/null
+++ b/rc1/include/__debug
@@ -0,0 +1,222 @@
+// -*- C++ -*-
+//===--------------------------- __debug ----------------------------------===//
+//
+//                     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_DEBUG_H
+#define _LIBCPP_DEBUG_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#if _LIBCPP_DEBUG_LEVEL >= 1
+#   include <cstdlib>
+#   include <cstdio>
+#   include <cstddef>
+#   ifndef _LIBCPP_ASSERT
+#      define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#   endif
+#endif
+
+#ifndef _LIBCPP_ASSERT
+#   define _LIBCPP_ASSERT(x, m) ((void)0)
+#endif
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct _LIBCPP_TYPE_VIS __c_node;
+
+struct _LIBCPP_TYPE_VIS __i_node
+{
+    void* __i_;
+    __i_node* __next_;
+    __c_node* __c_;
+
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+    __i_node(const __i_node&) = delete;
+    __i_node& operator=(const __i_node&) = delete;
+#else
+private:
+    __i_node(const __i_node&);
+    __i_node& operator=(const __i_node&);
+public:
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    __i_node(void* __i, __i_node* __next, __c_node* __c)
+        : __i_(__i), __next_(__next), __c_(__c) {}
+    ~__i_node();
+};
+
+struct _LIBCPP_TYPE_VIS __c_node
+{
+    void* __c_;
+    __c_node* __next_;
+    __i_node** beg_;
+    __i_node** end_;
+    __i_node** cap_;
+
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+    __c_node(const __c_node&) = delete;
+    __c_node& operator=(const __c_node&) = delete;
+#else
+private:
+    __c_node(const __c_node&);
+    __c_node& operator=(const __c_node&);
+public:
+#endif
+    _LIBCPP_INLINE_VISIBILITY
+    __c_node(void* __c, __c_node* __next)
+        : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
+    virtual ~__c_node();
+
+    virtual bool __dereferenceable(const void*) const = 0;
+    virtual bool __decrementable(const void*) const = 0;
+    virtual bool __addable(const void*, ptrdiff_t) const = 0;
+    virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
+
+    void __add(__i_node* __i);
+    _LIBCPP_HIDDEN void __remove(__i_node* __i);
+};
+
+template <class _Cont>
+struct _C_node
+    : public __c_node
+{
+    _C_node(void* __c, __c_node* __n)
+        : __c_node(__c, __n) {}
+
+    virtual bool __dereferenceable(const void*) const;
+    virtual bool __decrementable(const void*) const;
+    virtual bool __addable(const void*, ptrdiff_t) const;
+    virtual bool __subscriptable(const void*, ptrdiff_t) const;
+};
+
+template <class _Cont>
+bool
+_C_node<_Cont>::__dereferenceable(const void* __i) const
+{
+    typedef typename _Cont::const_iterator iterator;
+    const iterator* __j = static_cast<const iterator*>(__i);
+    _Cont* _Cp = static_cast<_Cont*>(__c_);
+    return _Cp->__dereferenceable(__j);
+}
+
+template <class _Cont>
+bool
+_C_node<_Cont>::__decrementable(const void* __i) const
+{
+    typedef typename _Cont::const_iterator iterator;
+    const iterator* __j = static_cast<const iterator*>(__i);
+    _Cont* _Cp = static_cast<_Cont*>(__c_);
+    return _Cp->__decrementable(__j);
+}
+
+template <class _Cont>
+bool
+_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
+{
+    typedef typename _Cont::const_iterator iterator;
+    const iterator* __j = static_cast<const iterator*>(__i);
+    _Cont* _Cp = static_cast<_Cont*>(__c_);
+    return _Cp->__addable(__j, __n);
+}
+
+template <class _Cont>
+bool
+_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
+{
+    typedef typename _Cont::const_iterator iterator;
+    const iterator* __j = static_cast<const iterator*>(__i);
+    _Cont* _Cp = static_cast<_Cont*>(__c_);
+    return _Cp->__subscriptable(__j, __n);
+}
+
+class _LIBCPP_TYPE_VIS __libcpp_db
+{
+    __c_node** __cbeg_;
+    __c_node** __cend_;
+    size_t   __csz_;
+    __i_node** __ibeg_;
+    __i_node** __iend_;
+    size_t   __isz_;
+
+    __libcpp_db();
+public:
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+    __libcpp_db(const __libcpp_db&) = delete;
+    __libcpp_db& operator=(const __libcpp_db&) = delete;
+#else
+private:
+    __libcpp_db(const __libcpp_db&);
+    __libcpp_db& operator=(const __libcpp_db&);
+public:
+#endif
+    ~__libcpp_db();
+
+    class __db_c_iterator;
+    class __db_c_const_iterator;
+    class __db_i_iterator;
+    class __db_i_const_iterator;
+
+    __db_c_const_iterator __c_end() const;
+    __db_i_const_iterator __i_end() const;
+
+    template <class _Cont>
+    _LIBCPP_INLINE_VISIBILITY
+    void __insert_c(_Cont* __c)
+    {
+        __c_node* __n = __insert_c(static_cast<void*>(__c));
+        ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
+    }
+
+    void __insert_i(void* __i);
+    __c_node* __insert_c(void* __c);
+    void __erase_c(void* __c);
+
+    void __insert_ic(void* __i, const void* __c);
+    void __iterator_copy(void* __i, const void* __i0);
+    void __erase_i(void* __i);
+
+    void* __find_c_from_i(void* __i) const;
+    void __invalidate_all(void* __c);
+    __c_node* __find_c_and_lock(void* __c) const;
+    __c_node* __find_c(void* __c) const;
+    void unlock() const;
+
+    void swap(void* __c1, void* __c2);
+
+
+    bool __dereferenceable(const void* __i) const;
+    bool __decrementable(const void* __i) const;
+    bool __addable(const void* __i, ptrdiff_t __n) const;
+    bool __subscriptable(const void* __i, ptrdiff_t __n) const;
+    bool __less_than_comparable(const void* __i, const void* __j) const;
+private:
+    _LIBCPP_HIDDEN
+    __i_node* __insert_iterator(void* __i);
+    _LIBCPP_HIDDEN
+    __i_node* __find_iterator(const void* __i) const;
+
+    friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
+};
+
+_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
+_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
+
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif
+
+#endif  // _LIBCPP_DEBUG_H
+
diff --git a/rc1/include/__functional_03 b/rc1/include/__functional_03
new file mode 100644
index 0000000..d8a9f05
--- /dev/null
+++ b/rc1/include/__functional_03
@@ -0,0 +1,2135 @@
+// -*- 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_FUNCTIONAL_03
+#define _LIBCPP_FUNCTIONAL_03
+
+// manual variadic expansion for <functional>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+template <class _Tp>
+class __mem_fn
+    : public __weak_result_type<_Tp>
+{
+public:
+    // types
+    typedef _Tp type;
+private:
+    type __f_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
+
+    // invoke
+
+    typename __invoke_return<type>::type
+       operator() () const
+       {
+           return __invoke(__f_);
+       }
+
+    template <class _A0>
+       typename __invoke_return0<type, _A0>::type
+          operator() (_A0& __a0) const
+          {
+              return __invoke(__f_, __a0);
+          }
+
+    template <class _A0, class _A1>
+       typename __invoke_return1<type, _A0, _A1>::type
+          operator() (_A0& __a0, _A1& __a1) const
+          {
+              return __invoke(__f_, __a0, __a1);
+          }
+
+    template <class _A0, class _A1, class _A2>
+       typename __invoke_return2<type, _A0, _A1, _A2>::type
+          operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
+          {
+              return __invoke(__f_, __a0, __a1, __a2);
+          }
+};
+
+template<class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp _Tp::*>
+mem_fn(_Rp _Tp::* __pm)
+{
+    return __mem_fn<_Rp _Tp::*>(__pm);
+}
+
+template<class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)()>
+mem_fn(_Rp (_Tp::* __pm)())
+{
+    return __mem_fn<_Rp (_Tp::*)()>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0)>
+mem_fn(_Rp (_Tp::* __pm)(_A0))
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1)>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1))
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2))
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm);
+}
+
+template<class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)() const>
+mem_fn(_Rp (_Tp::* __pm)() const)
+{
+    return __mem_fn<_Rp (_Tp::*)() const>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0) const>
+mem_fn(_Rp (_Tp::* __pm)(_A0) const)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0) const>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1) const>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>(__pm);
+}
+
+template<class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)() volatile>
+mem_fn(_Rp (_Tp::* __pm)() volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)() volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0) volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0) volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0) volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>(__pm);
+}
+
+template<class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)() const volatile>
+mem_fn(_Rp (_Tp::* __pm)() const volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)() const volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0) const volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0) const volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0) const volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>(__pm);
+}
+
+template<class _Rp, class _Tp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>
+mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile)
+{
+    return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>(__pm);
+}
+
+// bad_function_call
+
+class _LIBCPP_EXCEPTION_ABI bad_function_call
+    : public exception
+{
+};
+
+template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
+
+namespace __function
+{
+
+template<class _Fp>
+struct __maybe_derive_from_unary_function
+{
+};
+
+template<class _Rp, class _A1>
+struct __maybe_derive_from_unary_function<_Rp(_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template<class _Fp>
+struct __maybe_derive_from_binary_function
+{
+};
+
+template<class _Rp, class _A1, class _A2>
+struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template<class _Fp> class __base;
+
+template<class _Rp>
+class __base<_Rp()>
+{
+    __base(const __base&);
+    __base& operator=(const __base&);
+public:
+    __base() {}
+    virtual ~__base() {}
+    virtual __base* __clone() const = 0;
+    virtual void __clone(__base*) const = 0;
+    virtual void destroy() = 0;
+    virtual void destroy_deallocate() = 0;
+    virtual _Rp operator()() = 0;
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0>
+class __base<_Rp(_A0)>
+{
+    __base(const __base&);
+    __base& operator=(const __base&);
+public:
+    __base() {}
+    virtual ~__base() {}
+    virtual __base* __clone() const = 0;
+    virtual void __clone(__base*) const = 0;
+    virtual void destroy() = 0;
+    virtual void destroy_deallocate() = 0;
+    virtual _Rp operator()(_A0) = 0;
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0, class _A1>
+class __base<_Rp(_A0, _A1)>
+{
+    __base(const __base&);
+    __base& operator=(const __base&);
+public:
+    __base() {}
+    virtual ~__base() {}
+    virtual __base* __clone() const = 0;
+    virtual void __clone(__base*) const = 0;
+    virtual void destroy() = 0;
+    virtual void destroy_deallocate() = 0;
+    virtual _Rp operator()(_A0, _A1) = 0;
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0, class _A1, class _A2>
+class __base<_Rp(_A0, _A1, _A2)>
+{
+    __base(const __base&);
+    __base& operator=(const __base&);
+public:
+    __base() {}
+    virtual ~__base() {}
+    virtual __base* __clone() const = 0;
+    virtual void __clone(__base*) const = 0;
+    virtual void destroy() = 0;
+    virtual void destroy_deallocate() = 0;
+    virtual _Rp operator()(_A0, _A1, _A2) = 0;
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _FD, class _Alloc, class _FB> class __func;
+
+template<class _Fp, class _Alloc, class _Rp>
+class __func<_Fp, _Alloc, _Rp()>
+    : public  __base<_Rp()>
+{
+    __compressed_pair<_Fp, _Alloc> __f_;
+public:
+    explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
+    explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
+    virtual __base<_Rp()>* __clone() const;
+    virtual void __clone(__base<_Rp()>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _Rp operator()();
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Fp, class _Alloc, class _Rp>
+__base<_Rp()>*
+__func<_Fp, _Alloc, _Rp()>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    typedef __allocator_destructor<_Ap> _Dp;
+    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _Fp, class _Alloc, class _Rp>
+void
+__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _Fp, class _Alloc, class _Rp>
+void
+__func<_Fp, _Alloc, _Rp()>::destroy()
+{
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+}
+
+template<class _Fp, class _Alloc, class _Rp>
+void
+__func<_Fp, _Alloc, _Rp()>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _Fp, class _Alloc, class _Rp>
+_Rp
+__func<_Fp, _Alloc, _Rp()>::operator()()
+{
+    return __invoke(__f_.first());
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp>
+const void*
+__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_Fp))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _Fp, class _Alloc, class _Rp>
+const std::type_info&
+__func<_Fp, _Alloc, _Rp()>::target_type() const
+{
+    return typeid(_Fp);
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+class __func<_Fp, _Alloc, _Rp(_A0)>
+    : public  __base<_Rp(_A0)>
+{
+    __compressed_pair<_Fp, _Alloc> __f_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
+        : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
+    virtual __base<_Rp(_A0)>* __clone() const;
+    virtual void __clone(__base<_Rp(_A0)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _Rp operator()(_A0);
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+__base<_Rp(_A0)>*
+__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    typedef __allocator_destructor<_Ap> _Dp;
+    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+void
+__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+void
+__func<_Fp, _Alloc, _Rp(_A0)>::destroy()
+{
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+void
+__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+_Rp
+__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0)
+{
+    return __invoke(__f_.first(), __a0);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+const void*
+__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_Fp))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0>
+const std::type_info&
+__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const
+{
+    return typeid(_Fp);
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+class __func<_Fp, _Alloc, _Rp(_A0, _A1)>
+    : public  __base<_Rp(_A0, _A1)>
+{
+    __compressed_pair<_Fp, _Alloc> __f_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
+        : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
+    virtual __base<_Rp(_A0, _A1)>* __clone() const;
+    virtual void __clone(__base<_Rp(_A0, _A1)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _Rp operator()(_A0, _A1);
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+__base<_Rp(_A0, _A1)>*
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    typedef __allocator_destructor<_Ap> _Dp;
+    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy()
+{
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+_Rp
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1)
+{
+    return __invoke(__f_.first(), __a0, __a1);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+const void*
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_Fp))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
+const std::type_info&
+__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const
+{
+    return typeid(_Fp);
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>
+    : public  __base<_Rp(_A0, _A1, _A2)>
+{
+    __compressed_pair<_Fp, _Alloc> __f_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a)
+        : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
+    virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const;
+    virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _Rp operator()(_A0, _A1, _A2);
+#ifndef _LIBCPP_NO_RTTI
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+__base<_Rp(_A0, _A1, _A2)>*
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    typedef __allocator_destructor<_Ap> _Dp;
+    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy()
+{
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+void
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _Ap;
+    _Ap __a(__f_.second());
+    __f_.~__compressed_pair<_Fp, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+_Rp
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2)
+{
+    return __invoke(__f_.first(), __a0, __a1, __a2);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+const void*
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_Fp))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
+const std::type_info&
+__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
+{
+    return typeid(_Fp);
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+}  // __function
+
+template<class _Rp>
+class _LIBCPP_TYPE_VIS_ONLY function<_Rp()>
+{
+    typedef __function::__base<_Rp()> __base;
+    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;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
+    _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _Fp>
+      function(_Fp,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&) : __f_(0) {}
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
+    template<class _Alloc>
+      function(allocator_arg_t, const _Alloc&, const function&);
+    template<class _Fp, class _Alloc>
+      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _Fp>
+      typename enable_if
+      <
+        !is_integral<_Fp>::value,
+        function&
+      >::type
+      operator=(_Fp);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+    template<class _Fp, class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      void assign(_Fp __f, const _Alloc& __a)
+        {function(allocator_arg, __a, __f).swap(*this);}
+
+    // 20.7.16.2.3, function capacity:
+    _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+
+private:
+    // deleted overloads close possible hole in the type system
+    template<class _R2>
+      bool operator==(const function<_R2()>&) const;// = delete;
+    template<class _R2>
+      bool operator!=(const function<_R2()>&) const;// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _Rp operator()() const;
+
+#ifndef _LIBCPP_NO_RTTI
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _Tp> _Tp* target();
+    template <typename _Tp> const _Tp* target() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp>
+function<_Rp()>::function(const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp>
+template<class _Alloc>
+function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp>
+template <class _Fp>
+function<_Rp()>::function(_Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _Ap;
+            _Ap __a;
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp>
+template <class _Fp, class _Alloc>
+function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    typedef allocator_traits<_Alloc> __alloc_traits;
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<_FF>
+#else
+                rebind_alloc<_FF>::other
+#endif
+                                                         _Ap;
+            _Ap __a(__a0);
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, _Alloc(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp>
+function<_Rp()>&
+function<_Rp()>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _Rp>
+function<_Rp()>&
+function<_Rp()>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _Rp>
+template <class _Fp>
+typename enable_if
+<
+    !is_integral<_Fp>::value,
+    function<_Rp()>&
+>::type
+function<_Rp()>::operator=(_Fp __f)
+{
+    function(_VSTD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _Rp>
+function<_Rp()>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _Rp>
+void
+function<_Rp()>::swap(function& __f)
+{
+    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
+    {
+        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+        __base* __t = (__base*)&__tempbuf;
+        __f_->__clone(__t);
+        __f_->destroy();
+        __f_ = 0;
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = 0;
+        __f_ = (__base*)&__buf_;
+        __t->__clone((__base*)&__f.__buf_);
+        __t->destroy();
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f_ == (__base*)&__buf_)
+    {
+        __f_->__clone((__base*)&__f.__buf_);
+        __f_->destroy();
+        __f_ = __f.__f_;
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = __f_;
+        __f_ = (__base*)&__buf_;
+    }
+    else
+        _VSTD::swap(__f_, __f.__f_);
+}
+
+template<class _Rp>
+_Rp
+function<_Rp()>::operator()() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__f_ == 0)
+        throw bad_function_call();
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    return (*__f_)();
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Rp>
+const std::type_info&
+function<_Rp()>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _Rp>
+template <typename _Tp>
+_Tp*
+function<_Rp()>::target()
+{
+    if (__f_ == 0)
+        return (_Tp*)0;
+    return (_Tp*)__f_->target(typeid(_Tp));
+}
+
+template<class _Rp>
+template <typename _Tp>
+const _Tp*
+function<_Rp()>::target() const
+{
+    if (__f_ == 0)
+        return (const _Tp*)0;
+    return (const _Tp*)__f_->target(typeid(_Tp));
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0>
+class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)>
+    : public unary_function<_A0, _Rp>
+{
+    typedef __function::__base<_Rp(_A0)> __base;
+    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;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
+    _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _Fp>
+      function(_Fp,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&) : __f_(0) {}
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
+    template<class _Alloc>
+      function(allocator_arg_t, const _Alloc&, const function&);
+    template<class _Fp, class _Alloc>
+      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _Fp>
+      typename enable_if
+      <
+        !is_integral<_Fp>::value,
+        function&
+      >::type
+      operator=(_Fp);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+    template<class _Fp, class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      void assign(_Fp __f, const _Alloc& __a)
+        {function(allocator_arg, __a, __f).swap(*this);}
+
+    // 20.7.16.2.3, function capacity:
+    _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+
+private:
+    // deleted overloads close possible hole in the type system
+    template<class _R2, class _B0>
+      bool operator==(const function<_R2(_B0)>&) const;// = delete;
+    template<class _R2, class _B0>
+      bool operator!=(const function<_R2(_B0)>&) const;// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _Rp operator()(_A0) const;
+
+#ifndef _LIBCPP_NO_RTTI
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _Tp> _Tp* target();
+    template <typename _Tp> const _Tp* target() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0>
+function<_Rp(_A0)>::function(const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0>
+template<class _Alloc>
+function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0>
+template <class _Fp>
+function<_Rp(_A0)>::function(_Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _Ap;
+            _Ap __a;
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0>
+template <class _Fp, class _Alloc>
+function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    typedef allocator_traits<_Alloc> __alloc_traits;
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<_FF>
+#else
+                rebind_alloc<_FF>::other
+#endif
+                                                         _Ap;
+            _Ap __a(__a0);
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, _Alloc(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0>
+function<_Rp(_A0)>&
+function<_Rp(_A0)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0>
+function<_Rp(_A0)>&
+function<_Rp(_A0)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _Rp, class _A0>
+template <class _Fp>
+typename enable_if
+<
+    !is_integral<_Fp>::value,
+    function<_Rp(_A0)>&
+>::type
+function<_Rp(_A0)>::operator=(_Fp __f)
+{
+    function(_VSTD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0>
+function<_Rp(_A0)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _Rp, class _A0>
+void
+function<_Rp(_A0)>::swap(function& __f)
+{
+    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
+    {
+        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+        __base* __t = (__base*)&__tempbuf;
+        __f_->__clone(__t);
+        __f_->destroy();
+        __f_ = 0;
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = 0;
+        __f_ = (__base*)&__buf_;
+        __t->__clone((__base*)&__f.__buf_);
+        __t->destroy();
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f_ == (__base*)&__buf_)
+    {
+        __f_->__clone((__base*)&__f.__buf_);
+        __f_->destroy();
+        __f_ = __f.__f_;
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = __f_;
+        __f_ = (__base*)&__buf_;
+    }
+    else
+        _VSTD::swap(__f_, __f.__f_);
+}
+
+template<class _Rp, class _A0>
+_Rp
+function<_Rp(_A0)>::operator()(_A0 __a0) const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__f_ == 0)
+        throw bad_function_call();
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    return (*__f_)(__a0);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0>
+const std::type_info&
+function<_Rp(_A0)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _Rp, class _A0>
+template <typename _Tp>
+_Tp*
+function<_Rp(_A0)>::target()
+{
+    if (__f_ == 0)
+        return (_Tp*)0;
+    return (_Tp*)__f_->target(typeid(_Tp));
+}
+
+template<class _Rp, class _A0>
+template <typename _Tp>
+const _Tp*
+function<_Rp(_A0)>::target() const
+{
+    if (__f_ == 0)
+        return (const _Tp*)0;
+    return (const _Tp*)__f_->target(typeid(_Tp));
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0, class _A1>
+class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)>
+    : public binary_function<_A0, _A1, _Rp>
+{
+    typedef __function::__base<_Rp(_A0, _A1)> __base;
+    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;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
+    _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _Fp>
+      function(_Fp,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&) : __f_(0) {}
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
+    template<class _Alloc>
+      function(allocator_arg_t, const _Alloc&, const function&);
+    template<class _Fp, class _Alloc>
+      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _Fp>
+      typename enable_if
+      <
+        !is_integral<_Fp>::value,
+        function&
+      >::type
+      operator=(_Fp);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+    template<class _Fp, class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      void assign(_Fp __f, const _Alloc& __a)
+        {function(allocator_arg, __a, __f).swap(*this);}
+
+    // 20.7.16.2.3, function capacity:
+    operator bool() const {return __f_;}
+
+private:
+    // deleted overloads close possible hole in the type system
+    template<class _R2, class _B0, class _B1>
+      bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
+    template<class _R2, class _B0, class _B1>
+      bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _Rp operator()(_A0, _A1) const;
+
+#ifndef _LIBCPP_NO_RTTI
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _Tp> _Tp* target();
+    template <typename _Tp> const _Tp* target() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0, class _A1>
+function<_Rp(_A0, _A1)>::function(const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0, class _A1>
+template<class _Alloc>
+function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0, class _A1>
+template <class _Fp>
+function<_Rp(_A0, _A1)>::function(_Fp __f,
+                                 typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _Ap;
+            _Ap __a;
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0, class _A1>
+template <class _Fp, class _Alloc>
+function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
+                                 typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    typedef allocator_traits<_Alloc> __alloc_traits;
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<_FF>
+#else
+                rebind_alloc<_FF>::other
+#endif
+                                                         _Ap;
+            _Ap __a(__a0);
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, _Alloc(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0, class _A1>
+function<_Rp(_A0, _A1)>&
+function<_Rp(_A0, _A1)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0, class _A1>
+function<_Rp(_A0, _A1)>&
+function<_Rp(_A0, _A1)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _Rp, class _A0, class _A1>
+template <class _Fp>
+typename enable_if
+<
+    !is_integral<_Fp>::value,
+    function<_Rp(_A0, _A1)>&
+>::type
+function<_Rp(_A0, _A1)>::operator=(_Fp __f)
+{
+    function(_VSTD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0, class _A1>
+function<_Rp(_A0, _A1)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _Rp, class _A0, class _A1>
+void
+function<_Rp(_A0, _A1)>::swap(function& __f)
+{
+    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
+    {
+        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+        __base* __t = (__base*)&__tempbuf;
+        __f_->__clone(__t);
+        __f_->destroy();
+        __f_ = 0;
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = 0;
+        __f_ = (__base*)&__buf_;
+        __t->__clone((__base*)&__f.__buf_);
+        __t->destroy();
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f_ == (__base*)&__buf_)
+    {
+        __f_->__clone((__base*)&__f.__buf_);
+        __f_->destroy();
+        __f_ = __f.__f_;
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = __f_;
+        __f_ = (__base*)&__buf_;
+    }
+    else
+        _VSTD::swap(__f_, __f.__f_);
+}
+
+template<class _Rp, class _A0, class _A1>
+_Rp
+function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__f_ == 0)
+        throw bad_function_call();
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    return (*__f_)(__a0, __a1);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0, class _A1>
+const std::type_info&
+function<_Rp(_A0, _A1)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _Rp, class _A0, class _A1>
+template <typename _Tp>
+_Tp*
+function<_Rp(_A0, _A1)>::target()
+{
+    if (__f_ == 0)
+        return (_Tp*)0;
+    return (_Tp*)__f_->target(typeid(_Tp));
+}
+
+template<class _Rp, class _A0, class _A1>
+template <typename _Tp>
+const _Tp*
+function<_Rp(_A0, _A1)>::target() const
+{
+    if (__f_ == 0)
+        return (const _Tp*)0;
+    return (const _Tp*)__f_->target(typeid(_Tp));
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0, class _A1, class _A2>
+class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)>
+{
+    typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
+    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;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {}
+    _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _Fp>
+      function(_Fp,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&) : __f_(0) {}
+    template<class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
+    template<class _Alloc>
+      function(allocator_arg_t, const _Alloc&, const function&);
+    template<class _Fp, class _Alloc>
+      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
+               typename enable_if<!is_integral<_Fp>::value>::type* = 0);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _Fp>
+      typename enable_if
+      <
+        !is_integral<_Fp>::value,
+        function&
+      >::type
+      operator=(_Fp);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+    template<class _Fp, class _Alloc>
+      _LIBCPP_INLINE_VISIBILITY
+      void assign(_Fp __f, const _Alloc& __a)
+        {function(allocator_arg, __a, __f).swap(*this);}
+
+    // 20.7.16.2.3, function capacity:
+    _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+
+private:
+    // deleted overloads close possible hole in the type system
+    template<class _R2, class _B0, class _B1, class _B2>
+      bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
+    template<class _R2, class _B0, class _B1, class _B2>
+      bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _Rp operator()(_A0, _A1, _A2) const;
+
+#ifndef _LIBCPP_NO_RTTI
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _Tp> _Tp* target();
+    template <typename _Tp> const _Tp* target() const;
+#endif  // _LIBCPP_NO_RTTI
+};
+
+template<class _Rp, class _A0, class _A1, class _A2>
+function<_Rp(_A0, _A1, _A2)>::function(const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template<class _Alloc>
+function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
+                                      const function& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (const __base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+        __f_ = __f.__f_->__clone();
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template <class _Fp>
+function<_Rp(_A0, _A1, _A2)>::function(_Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _Ap;
+            _Ap __a;
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template <class _Fp, class _Alloc>
+function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
+                                     typename enable_if<!is_integral<_Fp>::value>::type*)
+    : __f_(0)
+{
+    typedef allocator_traits<_Alloc> __alloc_traits;
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<_FF>
+#else
+                rebind_alloc<_FF>::other
+#endif
+                                                         _Ap;
+            _Ap __a(__a0);
+            typedef __allocator_destructor<_Ap> _Dp;
+            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
+            ::new (__hold.get()) _FF(__f, _Alloc(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+function<_Rp(_A0, _A1, _A2)>&
+function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+function<_Rp(_A0, _A1, _A2)>&
+function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template <class _Fp>
+typename enable_if
+<
+    !is_integral<_Fp>::value,
+    function<_Rp(_A0, _A1, _A2)>&
+>::type
+function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f)
+{
+    function(_VSTD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+function<_Rp(_A0, _A1, _A2)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+void
+function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
+{
+    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
+    {
+        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+        __base* __t = (__base*)&__tempbuf;
+        __f_->__clone(__t);
+        __f_->destroy();
+        __f_ = 0;
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = 0;
+        __f_ = (__base*)&__buf_;
+        __t->__clone((__base*)&__f.__buf_);
+        __t->destroy();
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f_ == (__base*)&__buf_)
+    {
+        __f_->__clone((__base*)&__f.__buf_);
+        __f_->destroy();
+        __f_ = __f.__f_;
+        __f.__f_ = (__base*)&__f.__buf_;
+    }
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f.__f_->__clone((__base*)&__buf_);
+        __f.__f_->destroy();
+        __f.__f_ = __f_;
+        __f_ = (__base*)&__buf_;
+    }
+    else
+        _VSTD::swap(__f_, __f.__f_);
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+_Rp
+function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__f_ == 0)
+        throw bad_function_call();
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    return (*__f_)(__a0, __a1, __a2);
+}
+
+#ifndef _LIBCPP_NO_RTTI
+
+template<class _Rp, class _A0, class _A1, class _A2>
+const std::type_info&
+function<_Rp(_A0, _A1, _A2)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template <typename _Tp>
+_Tp*
+function<_Rp(_A0, _A1, _A2)>::target()
+{
+    if (__f_ == 0)
+        return (_Tp*)0;
+    return (_Tp*)__f_->target(typeid(_Tp));
+}
+
+template<class _Rp, class _A0, class _A1, class _A2>
+template <typename _Tp>
+const _Tp*
+function<_Rp(_A0, _A1, _A2)>::target() const
+{
+    if (__f_ == 0)
+        return (const _Tp*)0;
+    return (const _Tp*)__f_->target(typeid(_Tp));
+}
+
+#endif  // _LIBCPP_NO_RTTI
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const function<_Fp>& __f, nullptr_t) {return !__f;}
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const function<_Fp>& __f) {return !__f;}
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;}
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;}
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(function<_Fp>& __x, function<_Fp>& __y)
+{return __x.swap(__y);}
+
+template<class _Tp> struct __is_bind_expression : public false_type {};
+template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
+    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
+
+template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
+template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
+    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
+
+namespace placeholders
+{
+
+template <int _Np> struct __ph {};
+
+extern __ph<1>   _1;
+extern __ph<2>   _2;
+extern __ph<3>   _3;
+extern __ph<4>   _4;
+extern __ph<5>   _5;
+extern __ph<6>   _6;
+extern __ph<7>   _7;
+extern __ph<8>   _8;
+extern __ph<9>   _9;
+extern __ph<10> _10;
+
+}  // placeholders
+
+template<int _Np>
+struct __is_placeholder<placeholders::__ph<_Np> >
+    : public integral_constant<int, _Np> {};
+
+template <class _Tp, class _Uj>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp&
+__mu(reference_wrapper<_Tp> __t, _Uj&)
+{
+    return __t.get();
+}
+/*
+template <bool _IsBindExpr, class _Ti, class ..._Uj>
+struct __mu_return1 {};
+
+template <class _Ti, class ..._Uj>
+struct __mu_return1<true, _Ti, _Uj...>
+{
+    typedef typename result_of<_Ti(_Uj...)>::type type;
+};
+
+template <class _Ti, class ..._Uj, size_t ..._Indx>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __mu_return1<true, _Ti, _Uj...>::type
+__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
+{
+    __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...);
+}
+
+template <class _Ti, class ..._Uj>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_bind_expression<_Ti>::value,
+    typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
+>::type
+__mu(_Ti& __ti, tuple<_Uj...>& __uj)
+{
+    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
+    return  __mu_expand(__ti, __uj, __indices());
+}
+
+template <bool IsPh, class _Ti, class _Uj>
+struct __mu_return2 {};
+
+template <class _Ti, class _Uj>
+struct __mu_return2<true, _Ti, _Uj>
+{
+    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
+};
+
+template <class _Ti, class _Uj>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    0 < is_placeholder<_Ti>::value,
+    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
+>::type
+__mu(_Ti&, _Uj& __uj)
+{
+    const size_t _Indx = is_placeholder<_Ti>::value - 1;
+    // compiler bug workaround
+    typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj);
+    return __t;
+//    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
+}
+
+template <class _Ti, class _Uj>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_bind_expression<_Ti>::value &&
+    is_placeholder<_Ti>::value == 0 &&
+    !__is_reference_wrapper<_Ti>::value,
+    _Ti&
+>::type
+__mu(_Ti& __ti, _Uj& __uj)
+{
+    return __ti;
+}
+
+template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
+struct ____mu_return;
+
+template <class _Ti, class ..._Uj>
+struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
+{
+    typedef typename result_of<_Ti(_Uj...)>::type type;
+};
+
+template <class _Ti, class _TupleUj>
+struct ____mu_return<_Ti, false, true, _TupleUj>
+{
+    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
+                                   _TupleUj>::type&& type;
+};
+
+template <class _Ti, class _TupleUj>
+struct ____mu_return<_Ti, false, false, _TupleUj>
+{
+    typedef _Ti& type;
+};
+
+template <class _Ti, class _TupleUj>
+struct __mu_return
+    : public ____mu_return<_Ti,
+                           is_bind_expression<_Ti>::value,
+                           0 < is_placeholder<_Ti>::value,
+                           _TupleUj>
+{
+};
+
+template <class _Ti, class _TupleUj>
+struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
+{
+    typedef _Ti& type;
+};
+
+template <class _Fp, class _BoundArgs, class _TupleUj>
+struct __bind_return;
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __ref_return
+    <
+        _Fp&,
+        typename __mu_return
+        <
+            _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __ref_return
+    <
+        _Fp&,
+        typename __mu_return
+        <
+            const _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __bind_return<_Fp, _BoundArgs, _Args>::type
+__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
+                _Args&& __args)
+{
+    return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
+}
+
+template<class _Fp, class ..._BoundArgs>
+class __bind
+{
+    _Fp __f_;
+    tuple<_BoundArgs...> __bound_args_;
+
+    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
+public:
+    template <class _Gp, class ..._BA>
+      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
+        : __f_(_VSTD::forward<_Gp>(__f)),
+          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
+        operator()(_Args&& ...__args)
+        {
+            // compiler bug workaround
+            return __apply_functor(__f_, __bound_args_, __indices(),
+                                  tuple<_Args&&...>(__args...));
+        }
+
+    template <class ..._Args>
+        typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
+        operator()(_Args&& ...__args) const
+        {
+            return __apply_functor(__f_, __bound_args_, __indices(),
+                                   tuple<_Args&&...>(__args...));
+        }
+};
+
+template<class _Fp, class ..._BoundArgs>
+struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
+
+template<class _Rp, class _Fp, class ..._BoundArgs>
+class __bind_r
+    : public __bind<_Fp, _BoundArgs...>
+{
+    typedef __bind<_Fp, _BoundArgs...> base;
+public:
+    typedef _Rp result_type;
+
+    template <class _Gp, class ..._BA>
+      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
+        : base(_VSTD::forward<_Gp>(__f),
+               _VSTD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args)
+        {
+            return base::operator()(_VSTD::forward<_Args>(__args)...);
+        }
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args) const
+        {
+            return base::operator()(_VSTD::forward<_Args>(__args)...);
+        }
+};
+
+template<class _Rp, class _Fp, class ..._BoundArgs>
+struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
+
+template<class _Fp, class ..._BoundArgs>
+inline _LIBCPP_INLINE_VISIBILITY
+__bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
+bind(_Fp&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
+}
+
+template<class _Rp, class _Fp, class ..._BoundArgs>
+inline _LIBCPP_INLINE_VISIBILITY
+__bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...>
+bind(_Fp&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
+}
+*/
+
+#endif  // _LIBCPP_FUNCTIONAL_03
diff --git a/rc1/include/__functional_base b/rc1/include/__functional_base
new file mode 100644
index 0000000..6766793
--- /dev/null
+++ b/rc1/include/__functional_base
@@ -0,0 +1,615 @@
+// -*- 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_FUNCTIONAL_BASE
+#define _LIBCPP_FUNCTIONAL_BASE
+
+#include <__config>
+#include <type_traits>
+#include <typeinfo>
+#include <exception>
+#include <new>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Arg, class _Result>
+struct _LIBCPP_TYPE_VIS_ONLY unary_function
+{
+    typedef _Arg    argument_type;
+    typedef _Result result_type;
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+struct _LIBCPP_TYPE_VIS_ONLY binary_function
+{
+    typedef _Arg1   first_argument_type;
+    typedef _Arg2   second_argument_type;
+    typedef _Result result_type;
+};
+
+template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
+
+template <class _Tp>
+struct __has_result_type
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::result_type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+#if _LIBCPP_STD_VER > 11
+template <class _Tp = void>
+#else
+template <class _Tp>
+#endif
+struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 
+    bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x < __y;}
+};
+
+#if _LIBCPP_STD_VER > 11
+template <>
+struct _LIBCPP_TYPE_VIS_ONLY less<void>
+{
+    template <class _T1, class _T2> 
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+    auto operator()(_T1&& __t, _T2&& __u) const
+        { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
+    typedef void is_transparent;
+};
+#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
+
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
+#include <__functional_base_03>
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+// __weak_result_type
+
+template <class _Tp>
+struct __derives_from_unary_function
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    static __two __test(...);
+    template <class _Ap, class _Rp>
+        static unary_function<_Ap, _Rp>
+        __test(const volatile unary_function<_Ap, _Rp>*);
+public:
+    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
+    typedef decltype(__test((_Tp*)0)) type;
+};
+
+template <class _Tp>
+struct __derives_from_binary_function
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    static __two __test(...);
+    template <class _A1, class _A2, class _Rp>
+        static binary_function<_A1, _A2, _Rp>
+        __test(const volatile binary_function<_A1, _A2, _Rp>*);
+public:
+    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
+    typedef decltype(__test((_Tp*)0)) type;
+};
+
+template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
+struct __maybe_derive_from_unary_function  // bool is true
+    : public __derives_from_unary_function<_Tp>::type
+{
+};
+
+template <class _Tp>
+struct __maybe_derive_from_unary_function<_Tp, false>
+{
+};
+
+template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
+struct __maybe_derive_from_binary_function  // bool is true
+    : public __derives_from_binary_function<_Tp>::type
+{
+};
+
+template <class _Tp>
+struct __maybe_derive_from_binary_function<_Tp, false>
+{
+};
+
+template <class _Tp, bool = __has_result_type<_Tp>::value>
+struct __weak_result_type_imp // bool is true
+    : public __maybe_derive_from_unary_function<_Tp>,
+      public __maybe_derive_from_binary_function<_Tp>
+{
+    typedef typename _Tp::result_type result_type;
+};
+
+template <class _Tp>
+struct __weak_result_type_imp<_Tp, false>
+    : public __maybe_derive_from_unary_function<_Tp>,
+      public __maybe_derive_from_binary_function<_Tp>
+{
+};
+
+template <class _Tp>
+struct __weak_result_type
+    : public __weak_result_type_imp<_Tp>
+{
+};
+
+// 0 argument case
+
+template <class _Rp>
+struct __weak_result_type<_Rp ()>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp>
+struct __weak_result_type<_Rp (&)()>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp>
+struct __weak_result_type<_Rp (*)()>
+{
+    typedef _Rp result_type;
+};
+
+// 1 argument case
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (&)(_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (*)(_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)()>
+    : public unary_function<_Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() const>
+    : public unary_function<const _Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() volatile>
+    : public unary_function<volatile _Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() const volatile>
+    : public unary_function<const volatile _Cp*, _Rp>
+{
+};
+
+// 2 argument case
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (*)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (&)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1)>
+    : public binary_function<_Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
+    : public binary_function<const _Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
+    : public binary_function<volatile _Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
+    : public binary_function<const volatile _Cp*, _A1, _Rp>
+{
+};
+
+// 3 or more arguments
+
+template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
+{
+    typedef _Rp result_type;
+};
+
+// __invoke
+
+// 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;
+};
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
+    : public __weak_result_type<_Tp>
+{
+public:
+    // types
+    typedef _Tp type;
+private:
+    type* __f_;
+
+public:
+    // construct/copy/destroy
+    _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
+        : __f_(_VSTD::addressof(__f)) {}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
+#endif
+
+    // access
+    _LIBCPP_INLINE_VISIBILITY operator type&    () const _NOEXCEPT {return *__f_;}
+    _LIBCPP_INLINE_VISIBILITY          type& get() const _NOEXCEPT {return *__f_;}
+
+    // invoke
+    template <class... _ArgTypes>
+       _LIBCPP_INLINE_VISIBILITY
+       typename __invoke_of<type&, _ArgTypes...>::type
+          operator() (_ArgTypes&&... __args) const
+          {
+              return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
+          }
+};
+
+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
+reference_wrapper<_Tp>
+ref(_Tp& __t) _NOEXCEPT
+{
+    return reference_wrapper<_Tp>(__t);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<_Tp>
+ref(reference_wrapper<_Tp> __t) _NOEXCEPT
+{
+    return ref(__t.get());
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<const _Tp>
+cref(const _Tp& __t) _NOEXCEPT
+{
+    return reference_wrapper<const _Tp>(__t);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<const _Tp>
+cref(reference_wrapper<_Tp> __t) _NOEXCEPT
+{
+    return cref(__t.get());
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+
+template <class _Tp> void ref(const _Tp&&) = delete;
+template <class _Tp> void cref(const _Tp&&) = delete;
+
+#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+
+template <class _Tp> void ref(const _Tp&&);// = delete;
+template <class _Tp> void cref(const _Tp&&);// = delete;
+
+#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+#if _LIBCPP_STD_VER > 11
+template <class _Tp1, class _Tp2 = void>
+struct __is_transparent
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::is_transparent* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp1>(0)) == 1;
+};
+#endif
+
+// allocator_arg_t
+
+struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
+
+#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
+extern const allocator_arg_t allocator_arg;
+#else
+constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+#endif
+
+// uses_allocator
+
+template <class _Tp>
+struct __has_allocator_type
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::allocator_type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
+struct __uses_allocator
+    : public integral_constant<bool,
+        is_convertible<_Alloc, typename _Tp::allocator_type>::value>
+{
+};
+
+template <class _Tp, class _Alloc>
+struct __uses_allocator<_Tp, _Alloc, false>
+    : public false_type
+{
+};
+
+template <class _Tp, class _Alloc>
+struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
+    : public __uses_allocator<_Tp, _Alloc>
+{
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+// allocator construction
+
+template <class _Tp, class _Alloc, class ..._Args>
+struct __uses_alloc_ctor_imp
+{
+    static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
+    static const bool __ic =
+        is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
+    static const int value = __ua ? 2 - __ic : 0;
+};
+
+template <class _Tp, class _Alloc, class ..._Args>
+struct __uses_alloc_ctor
+    : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
+    {};
+
+template <class _Tp, class _Allocator, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
+{
+    new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
+}
+
+template <class _Tp, class _Allocator, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
+{
+    new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
+}
+
+template <class _Tp, class _Allocator, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
+{
+    new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
+}
+
+template <class _Tp, class _Allocator, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
+{ 
+    __user_alloc_construct_impl( 
+             __uses_alloc_ctor<_Tp, _Allocator>(), 
+             __storage, __a, _VSTD::forward<_Args>(__args)...
+        );
+}
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FUNCTIONAL_BASE
diff --git a/rc1/include/__functional_base_03 b/rc1/include/__functional_base_03
new file mode 100644
index 0000000..22c06ad
--- /dev/null
+++ b/rc1/include/__functional_base_03
@@ -0,0 +1,1087 @@
+// -*- 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_FUNCTIONAL_BASE_03
+#define _LIBCPP_FUNCTIONAL_BASE_03
+
+// manual variadic expansion for <functional>
+
+// __weak_result_type
+
+template <class _Tp>
+struct __derives_from_unary_function
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    static __two __test(...);
+    template <class _Ap, class _Rp>
+        static unary_function<_Ap, _Rp>
+        __test(const volatile unary_function<_Ap, _Rp>*);
+public:
+    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
+    typedef decltype(__test((_Tp*)0)) type;
+};
+
+template <class _Tp>
+struct __derives_from_binary_function
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    static __two __test(...);
+    template <class _A1, class _A2, class _Rp>
+        static binary_function<_A1, _A2, _Rp>
+        __test(const volatile binary_function<_A1, _A2, _Rp>*);
+public:
+    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
+    typedef decltype(__test((_Tp*)0)) type;
+};
+
+template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
+struct __maybe_derive_from_unary_function  // bool is true
+    : public __derives_from_unary_function<_Tp>::type
+{
+};
+
+template <class _Tp>
+struct __maybe_derive_from_unary_function<_Tp, false>
+{
+};
+
+template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
+struct __maybe_derive_from_binary_function  // bool is true
+    : public __derives_from_binary_function<_Tp>::type
+{
+};
+
+template <class _Tp>
+struct __maybe_derive_from_binary_function<_Tp, false>
+{
+};
+
+template <class _Tp, bool = __has_result_type<_Tp>::value>
+struct __weak_result_type_imp // bool is true
+    : public __maybe_derive_from_unary_function<_Tp>,
+      public __maybe_derive_from_binary_function<_Tp>
+{
+    typedef typename _Tp::result_type result_type;
+};
+
+template <class _Tp>
+struct __weak_result_type_imp<_Tp, false>
+    : public __maybe_derive_from_unary_function<_Tp>,
+      public __maybe_derive_from_binary_function<_Tp>
+{
+};
+
+template <class _Tp>
+struct __weak_result_type
+    : public __weak_result_type_imp<typename remove_reference<_Tp>::type>
+{
+};
+
+// 0 argument case
+
+template <class _Rp>
+struct __weak_result_type<_Rp ()>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp>
+struct __weak_result_type<_Rp (&)()>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp>
+struct __weak_result_type<_Rp (*)()>
+{
+    typedef _Rp result_type;
+};
+
+// 1 argument case
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (&)(_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _A1>
+struct __weak_result_type<_Rp (*)(_A1)>
+    : public unary_function<_A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)()>
+    : public unary_function<_Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() const>
+    : public unary_function<const _Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() volatile>
+    : public unary_function<volatile _Cp*, _Rp>
+{
+};
+
+template <class _Rp, class _Cp>
+struct __weak_result_type<_Rp (_Cp::*)() const volatile>
+    : public unary_function<const volatile _Cp*, _Rp>
+{
+};
+
+// 2 argument case
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (*)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _A1, class _A2>
+struct __weak_result_type<_Rp (&)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1)>
+    : public binary_function<_Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
+    : public binary_function<const _Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
+    : public binary_function<volatile _Cp*, _A1, _Rp>
+{
+};
+
+template <class _Rp, class _Cp, class _A1>
+struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
+    : public binary_function<const volatile _Cp*, _A1, _Rp>
+{
+};
+
+// 3 or more arguments
+
+template <class _Rp, class _A1, class _A2, class _A3>
+struct __weak_result_type<_Rp (_A1, _A2, _A3)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _A1, class _A2, class _A3>
+struct __weak_result_type<_Rp (&)(_A1, _A2, _A3)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _A1, class _A2, class _A3>
+struct __weak_result_type<_Rp (*)(_A1, _A2, _A3)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2)>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) const>
+{
+    typedef _Rp result_type;
+};
+
+template <class _Rp, class _Cp, class _A1, class _A2>
+struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) volatile>
+{
+    typedef _Rp result_type;
+};
+
+// __invoke
+
+// __ref_return0
+//
+// template <class _Tp, bool _HasResultType>
+// struct ________ref_return0  // _HasResultType is true
+// {
+//     typedef typename _Tp::result_type type;
+// };
+//
+// template <class _Tp>
+// struct ________ref_return0<_Tp, false>
+// {
+//     typedef void type;
+// };
+//
+// template <class _Tp, bool _IsClass>
+// struct ____ref_return0  // _IsClass is true
+//     : public ________ref_return0<_Tp, __has_result_type<typename remove_cv<_Tp>::type>::value>
+// {
+// };
+//
+// template <class _Tp, bool _HasResultType>
+// struct ______ref_return0  // _HasResultType is true
+// {
+//     typedef typename __callable_type<_Tp>::result_type type;
+// };
+//
+// template <class _Tp>
+// struct ______ref_return0<_Tp, false>  // pointer to member data
+// {
+//     typedef void type;
+// };
+//
+// template <class _Tp>
+// struct ____ref_return0<_Tp, false>
+//     : public ______ref_return0<typename remove_cv<_Tp>::type,
+//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value>
+// {
+// };
+//
+// template <class _Tp>
+// struct __ref_return0
+//     : public ____ref_return0<typename remove_reference<_Tp>::type,
+//                    is_class<typename remove_reference<_Tp>::type>::value>
+// {
+// };
+//
+// __ref_return1
+//
+// template <class _Tp, bool _IsClass, class _A0>
+// struct ____ref_return1  // _IsClass is true
+// {
+//     typedef typename result_of<_Tp(_A0)>::type type;
+// };
+//
+// template <class _Tp, bool _HasResultType, class _A0>
+// struct ______ref_return1  // _HasResultType is true
+// {
+//     typedef typename __callable_type<_Tp>::result_type type;
+// };
+//
+// template <class _Tp, class _A0, bool>
+// struct __ref_return1_member_data1;
+//
+// template <class _Rp, class _Cp, class _A0>
+// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, true>
+// {
+//     typedef typename __apply_cv<_A0, _Rp>::type& type;
+// };
+//
+// template <class _Rp, class _Cp, class _A0>
+// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, false>
+// {
+//     static _A0 __a;
+//     typedef typename __apply_cv<decltype(*__a), _Rp>::type& type;
+// };
+//
+// template <class _Tp, class _A0>
+// struct __ref_return1_member_data;
+//
+// template <class _Rp, class _Cp, class _A0>
+// struct __ref_return1_member_data<_Rp _Cp::*, _A0>
+//     : public __ref_return1_member_data1<_Rp _Cp::*, _A0,
+//                 is_same<typename remove_cv<_Cp>::type,
+//                         typename remove_cv<typename remove_reference<_A0>::type>::type>::value>
+// {
+// };
+//
+// template <class _Tp, class _A0>
+// struct ______ref_return1<_Tp, false, _A0>  // pointer to member data
+//     : public __ref_return1_member_data<typename remove_cv<_Tp>::type, _A0>
+// {
+// };
+//
+// template <class _Tp, class _A0>
+// struct ____ref_return1<_Tp, false, _A0>
+//     : public ______ref_return1<typename remove_cv<_Tp>::type,
+//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0>
+// {
+// };
+//
+// template <class _Tp, class _A0>
+// struct __ref_return1
+//     : public ____ref_return1<typename remove_reference<_Tp>::type,
+//                    is_class<typename remove_reference<_Tp>::type>::value, _A0>
+// {
+// };
+//
+// __ref_return2
+//
+// template <class _Tp, bool _IsClass, class _A0, class _A1>
+// struct ____ref_return2  // _IsClass is true
+// {
+//     typedef typename result_of<_Tp(_A0, _A1)>::type type;
+// };
+//
+// template <class _Tp, bool _HasResultType, class _A0, class _A1>
+// struct ______ref_return2  // _HasResultType is true
+// {
+//     typedef typename __callable_type<_Tp>::result_type type;
+// };
+//
+// template <class _Tp>
+// struct ______ref_return2<_Tp, false, class _A0, class _A1>  // pointer to member data
+// {
+//     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
+//                          " to member data with too many arguments.");
+// };
+//
+// template <class _Tp, class _A0, class _A1>
+// struct ____ref_return2<_Tp, false, _A0, _A1>
+//     : public ______ref_return2<typename remove_cv<_Tp>::type,
+//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1>
+// {
+// };
+//
+// template <class _Tp, class _A0, class _A1>
+// struct __ref_return2
+//     : public ____ref_return2<typename remove_reference<_Tp>::type,
+//                    is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1>
+// {
+// };
+//
+// __ref_return3
+//
+// template <class _Tp, bool _IsClass, class _A0, class _A1, class _A2>
+// struct ____ref_return3  // _IsClass is true
+// {
+//     typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type;
+// };
+//
+// template <class _Tp, bool _HasResultType, class _A0, class _A1, class _A2>
+// struct ______ref_return3  // _HasResultType is true
+// {
+//     typedef typename __callable_type<_Tp>::result_type type;
+// };
+//
+// template <class _Tp>
+// struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2>  // pointer to member data
+// {
+//     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
+//                          " to member data with too many arguments.");
+// };
+//
+// template <class _Tp, class _A0, class _A1, class _A2>
+// struct ____ref_return3<_Tp, false, _A0, _A1, _A2>
+//     : public ______ref_return3<typename remove_cv<_Tp>::type,
+//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1, _A2>
+// {
+// };
+//
+// template <class _Tp, class _A0, class _A1, class _A2>
+// struct __ref_return3
+//     : public ____ref_return3<typename remove_reference<_Tp>::type,
+//                    is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1, _A2>
+// {
+// };
+
+// first 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 _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), _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), _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), _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, _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 _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), _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), _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), _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, _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_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+    typename __apply_cv<_T1, _Rp>::type&
+>::type
+__invoke(_Rp _Tp::* __f, _T1& __t1)
+{
+    return __t1.*__f;
+}
+
+template <class _Rp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__invoke(_Rp _Tp::*)
+{
+}
+
+// template <class _Dp, class _Rp, class _Tp, class _T1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+//     typename __ref_return1<_Rp _Tp::*, _T1>::type
+// >::type
+// __invoke(_Rp _Tp::* __f, _T1& __t1)
+// {
+//     return __t1.*__f;
+// }
+
+// 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 __4th_helper<_T1, _Rp,
+                      !is_base_of<_Tp,
+                                  typename remove_reference<_T1>::type
+                                 >::value
+                     >::type&
+__invoke(_Rp _Tp::* __f, _T1& __t1)
+{
+    return (*__t1).*__f;
+}
+
+// template <class _Dp, class _Rp, class _Tp, class _T1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
+//     typename __ref_return1<_Rp _Tp::*, _T1>::type
+// >::type
+// __invoke(_Rp _Tp::* __f, _T1 __t1)
+// {
+//     return (*__t1).*__f;
+// }
+
+// fifth bullet
+
+template <class _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+decltype(declval<_Fp>()())
+__invoke(_Fp __f)
+{
+    return __f();
+}
+
+template <class _Fp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+decltype(declval<_Fp>()(declval<_A0&>()))
+__invoke(_Fp __f, _A0& __a0)
+{
+    return __f(__a0);
+}
+
+template <class _Fp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>()))
+__invoke(_Fp __f, _A0& __a0, _A1& __a1)
+{
+    return __f(__a0, __a1);
+}
+
+template <class _Fp, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>()))
+__invoke(_Fp __f, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return __f(__a0, __a1, __a2);
+}
+
+// template <class _Rp, class _Fp>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _Rp
+// __invoke(_Fp& __f)
+// {
+//     return __f();
+// }
+//
+// template <class _Rp, class _Fp, class _A0>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     !is_member_pointer<_Fp>::value,
+//     _Rp
+// >::type
+// __invoke(_Fp& __f, _A0& __a0)
+// {
+//     return __f(__a0);
+// }
+//
+// template <class _Rp, class _Fp, class _A0, class _A1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _Rp
+// __invoke(_Fp& __f, _A0& __a0, _A1& __a1)
+// {
+//     return __f(__a0, __a1);
+// }
+//
+// template <class _Rp, class _Fp, class _A0, class _A1, class _A2>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _Rp
+// __invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
+// {
+//     return __f(__a0, __a1, __a2);
+// }
+
+template <class _Tp>
+struct __has_type
+{
+private:
+    struct __two {char __lx; char __lxx;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
+struct __invoke_return
+{
+    typedef typename __weak_result_type<_Fp>::result_type type;
+};
+
+template <class _Fp>
+struct __invoke_return<_Fp, false>
+{
+    typedef decltype(__invoke(_VSTD::declval<_Fp>())) type;
+};
+
+template <class _Tp, class _A0>
+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>
+{
+    typedef typename __apply_cv<_A0, _Rp>::type& type;
+};
+
+template <class _Rp, class _Tp, class _A0>
+struct __invoke_return0<_Rp _Tp::*, _A0*>
+{
+    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 _Tp, class _A0, class _A1, class _A2>
+struct __invoke_return2
+{
+    typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
+                                                    _VSTD::declval<_A1>(),
+                                                    _VSTD::declval<_A2>())) type;
+};
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
+    : public __weak_result_type<_Tp>
+{
+public:
+    // types
+    typedef _Tp type;
+private:
+    type* __f_;
+
+public:
+    // construct/copy/destroy
+    _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {}
+
+    // access
+    _LIBCPP_INLINE_VISIBILITY operator type&    () const {return *__f_;}
+    _LIBCPP_INLINE_VISIBILITY          type& get() const {return *__f_;}
+
+    // invoke
+
+    _LIBCPP_INLINE_VISIBILITY
+    typename __invoke_return<type&>::type
+       operator() () const
+       {
+           return __invoke(get());
+       }
+
+    template <class _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<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<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2);
+          }
+};
+
+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
+reference_wrapper<_Tp>
+ref(_Tp& __t)
+{
+    return reference_wrapper<_Tp>(__t);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<_Tp>
+ref(reference_wrapper<_Tp> __t)
+{
+    return ref(__t.get());
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<const _Tp>
+cref(const _Tp& __t)
+{
+    return reference_wrapper<const _Tp>(__t);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+reference_wrapper<const _Tp>
+cref(reference_wrapper<_Tp> __t)
+{
+    return cref(__t.get());
+}
+
+#endif  // _LIBCPP_FUNCTIONAL_BASE_03
diff --git a/rc1/include/__hash_table b/rc1/include/__hash_table
new file mode 100644
index 0000000..7c954b6
--- /dev/null
+++ b/rc1/include/__hash_table
@@ -0,0 +1,2453 @@
+// -*- 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__HASH_TABLE
+#define _LIBCPP__HASH_TABLE
+
+#include <__config>
+#include <initializer_list>
+#include <memory>
+#include <iterator>
+#include <algorithm>
+#include <cmath>
+
+#include <__undef_min_max>
+
+#include <__debug>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_FUNC_VIS
+size_t __next_prime(size_t __n);
+
+template <class _NodePtr>
+struct __hash_node_base
+{
+    typedef __hash_node_base __first_node;
+
+    _NodePtr    __next_;
+
+    _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
+};
+
+template <class _Tp, class _VoidPtr>
+struct __hash_node
+    : public __hash_node_base
+             <
+                 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 value_type;
+
+    size_t     __hash_;
+    value_type __value_;
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__is_power2(size_t __bc)
+{
+    return __bc > 2 && !(__bc & (__bc - 1));
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__constrain_hash(size_t __h, size_t __bc)
+{
+    return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : __h % __bc;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__next_pow2(size_t __n)
+{
+    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 _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_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 _NodePtr>
+class _LIBCPP_TYPE_VIS_ONLY __hash_iterator
+{
+    typedef _NodePtr __node_pointer;
+
+    __node_pointer            __node_;
+
+public:
+    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
+    : __node_(nullptr)
+#endif
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__insert_i(this);
+#endif
+    }
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator(const __hash_iterator& __i)
+        : __node_(__i.__node_)
+    {
+        __get_db()->__iterator_copy(this, &__i);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    ~__hash_iterator()
+    {
+        __get_db()->__erase_i(this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator& operator=(const __hash_iterator& __i)
+    {
+        if (this != &__i)
+        {
+            __get_db()->__iterator_copy(this, &__i);
+            __node_ = __i.__node_;
+        }
+        return *this;
+    }
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+        reference operator*() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container iterator");
+#endif
+            return __node_->__value_;
+        }
+    _LIBCPP_INLINE_VISIBILITY
+        pointer operator->() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container iterator");
+#endif
+            return pointer_traits<pointer>::pointer_to(__node_->__value_);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator& operator++()
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to increment non-incrementable unordered container iterator");
+#endif
+        __node_ = __node_->__next_;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator operator++(int)
+    {
+        __hash_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
+    {
+        return __x.__node_ == __y.__node_;
+    }
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
+        : __node_(__node)
+        {
+            __get_db()->__insert_ic(this, __c);
+        }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_iterator(__node_pointer __node) _NOEXCEPT
+        : __node_(__node)
+        {}
+#endif
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
+};
+
+template <class _ConstNodePtr>
+class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator
+{
+    typedef _ConstNodePtr __node_pointer;
+
+    __node_pointer         __node_;
+
+    typedef typename remove_const<
+        typename pointer_traits<__node_pointer>::element_type
+                                 >::type __node;
+
+public:
+    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
+    : __node_(nullptr)
+#endif
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__insert_i(this);
+#endif
+    }
+    _LIBCPP_INLINE_VISIBILITY 
+    __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
+        : __node_(__x.__node_)
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__iterator_copy(this, &__x);
+#endif
+    }
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator(const __hash_const_iterator& __i)
+        : __node_(__i.__node_)
+    {
+        __get_db()->__iterator_copy(this, &__i);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    ~__hash_const_iterator()
+    {
+        __get_db()->__erase_i(this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator& operator=(const __hash_const_iterator& __i)
+    {
+        if (this != &__i)
+        {
+            __get_db()->__iterator_copy(this, &__i);
+            __node_ = __i.__node_;
+        }
+        return *this;
+    }
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+        reference operator*() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container const_iterator");
+#endif
+            return __node_->__value_;
+        }
+    _LIBCPP_INLINE_VISIBILITY
+        pointer operator->() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container const_iterator");
+#endif
+            return pointer_traits<pointer>::pointer_to(__node_->__value_);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator& operator++()
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to increment non-incrementable unordered container const_iterator");
+#endif
+        __node_ = __node_->__next_;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator operator++(int)
+    {
+        __hash_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
+    {
+        return __x.__node_ == __y.__node_;
+    }
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
+        : __node_(__node)
+        {
+            __get_db()->__insert_ic(this, __c);
+        }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_iterator(__node_pointer __node) _NOEXCEPT
+        : __node_(__node)
+        {}
+#endif
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
+};
+
+template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
+
+template <class _NodePtr>
+class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator
+{
+    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 __pointer_traits::element_type::value_type value_type;
+    typedef typename __pointer_traits::difference_type          difference_type;
+    typedef value_type&                                         reference;
+    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
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__insert_i(this);
+#endif
+    }
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator(const __hash_local_iterator& __i)
+        : __node_(__i.__node_),
+          __bucket_(__i.__bucket_),
+          __bucket_count_(__i.__bucket_count_)
+    {
+        __get_db()->__iterator_copy(this, &__i);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    ~__hash_local_iterator()
+    {
+        __get_db()->__erase_i(this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator& operator=(const __hash_local_iterator& __i)
+    {
+        if (this != &__i)
+        {
+            __get_db()->__iterator_copy(this, &__i);
+            __node_ = __i.__node_;
+            __bucket_ = __i.__bucket_;
+            __bucket_count_ = __i.__bucket_count_;
+        }
+        return *this;
+    }
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+        reference operator*() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container local_iterator");
+#endif
+            return __node_->__value_;
+        }
+    _LIBCPP_INLINE_VISIBILITY
+        pointer operator->() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container local_iterator");
+#endif
+            return pointer_traits<pointer>::pointer_to(__node_->__value_);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator& operator++()
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to increment non-incrementable unordered container local_iterator");
+#endif
+        __node_ = __node_->__next_;
+        if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
+            __node_ = nullptr;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator operator++(int)
+    {
+        __hash_local_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
+    {
+        return __x.__node_ == __y.__node_;
+    }
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator(__node_pointer __node, size_t __bucket,
+                          size_t __bucket_count, const void* __c) _NOEXCEPT
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            __get_db()->__insert_ic(this, __c);
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_local_iterator(__node_pointer __node, size_t __bucket,
+                          size_t __bucket_count) _NOEXCEPT
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+#endif
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
+};
+
+template <class _ConstNodePtr>
+class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator
+{
+    typedef _ConstNodePtr __node_pointer;
+
+    __node_pointer         __node_;
+    size_t                 __bucket_;
+    size_t                 __bucket_count_;
+
+    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 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;
+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
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__insert_i(this);
+#endif
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
+        : __node_(__x.__node_),
+          __bucket_(__x.__bucket_),
+          __bucket_count_(__x.__bucket_count_)
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __get_db()->__iterator_copy(this, &__x);
+#endif
+    }
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator(const __hash_const_local_iterator& __i)
+        : __node_(__i.__node_),
+          __bucket_(__i.__bucket_),
+          __bucket_count_(__i.__bucket_count_)
+    {
+        __get_db()->__iterator_copy(this, &__i);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    ~__hash_const_local_iterator()
+    {
+        __get_db()->__erase_i(this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
+    {
+        if (this != &__i)
+        {
+            __get_db()->__iterator_copy(this, &__i);
+            __node_ = __i.__node_;
+            __bucket_ = __i.__bucket_;
+            __bucket_count_ = __i.__bucket_count_;
+        }
+        return *this;
+    }
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+
+    _LIBCPP_INLINE_VISIBILITY
+        reference operator*() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
+#endif
+            return __node_->__value_;
+        }
+    _LIBCPP_INLINE_VISIBILITY
+        pointer operator->() const
+        {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+            _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                           "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
+#endif
+            return pointer_traits<pointer>::pointer_to(__node_->__value_);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator& operator++()
+    {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
+                       "Attempted to increment non-incrementable unordered container const_local_iterator");
+#endif
+        __node_ = __node_->__next_;
+        if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
+            __node_ = nullptr;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator operator++(int)
+    {
+        __hash_const_local_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
+    {
+        return __x.__node_ == __y.__node_;
+    }
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
+                                size_t __bucket_count, const void* __c) _NOEXCEPT
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            __get_db()->__insert_ic(this, __c);
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+#else
+    _LIBCPP_INLINE_VISIBILITY
+    __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
+                                size_t __bucket_count) _NOEXCEPT
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+#endif
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
+};
+
+template <class _Alloc>
+class __bucket_list_deallocator
+{
+    typedef _Alloc                                          allocator_type;
+    typedef allocator_traits<allocator_type>                __alloc_traits;
+    typedef typename __alloc_traits::size_type              size_type;
+
+    __compressed_pair<size_type, allocator_type> __data_;
+public:
+    typedef typename __alloc_traits::pointer pointer;
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bucket_list_deallocator()
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
+        : __data_(0) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bucket_list_deallocator(const allocator_type& __a, size_type __size)
+        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
+        : __data_(__size, __a) {}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bucket_list_deallocator(__bucket_list_deallocator&& __x)
+        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
+        : __data_(_VSTD::move(__x.__data_))
+    {
+        __x.size() = 0;
+    }
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type& size() _NOEXCEPT {return __data_.first();}
+    _LIBCPP_INLINE_VISIBILITY
+    size_type  size() const _NOEXCEPT {return __data_.first();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+    const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void operator()(pointer __p) _NOEXCEPT
+    {
+        __alloc_traits::deallocate(__alloc(), __p, size());
+    }
+};
+
+template <class _Alloc> class __hash_map_node_destructor;
+
+template <class _Alloc>
+class __hash_node_destructor
+{
+    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:
+
+    allocator_type& __na_;
+
+    __hash_node_destructor& operator=(const __hash_node_destructor&);
+
+public:
+    bool __value_constructed;
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __hash_node_destructor(allocator_type& __na,
+                                    bool __constructed = false) _NOEXCEPT
+        : __na_(__na),
+          __value_constructed(__constructed)
+        {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void operator()(pointer __p) _NOEXCEPT
+    {
+        if (__value_constructed)
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_));
+        if (__p)
+            __alloc_traits::deallocate(__na_, __p, 1);
+    }
+
+    template <class> friend class __hash_map_node_destructor;
+};
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+class __hash_table
+{
+public:
+    typedef _Tp    value_type;
+    typedef _Hash  hasher;
+    typedef _Equal key_equal;
+    typedef _Alloc allocator_type;
+
+private:
+    typedef allocator_traits<allocator_type> __alloc_traits;
+public:
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+    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:
+    // Create __node
+    typedef __hash_node<value_type, typename __alloc_traits::void_pointer> __node;
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__node>
+#else
+            rebind_alloc<__node>::other
+#endif
+                                                     __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 __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:
+
+    typedef typename __node_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__node_pointer>
+#else
+            rebind_alloc<__node_pointer>::other
+#endif
+                                                            __pointer_allocator;
+    typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
+    typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list;
+    typedef allocator_traits<__pointer_allocator>          __pointer_alloc_traits;
+    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_;
+    // --- Member data end ---
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type& size() _NOEXCEPT {return __p2_.first();}
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    size_type  size() const _NOEXCEPT {return __p2_.first();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    hasher& hash_function() _NOEXCEPT {return __p2_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+    const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    float& max_load_factor() _NOEXCEPT {return __p3_.first();}
+    _LIBCPP_INLINE_VISIBILITY
+    float  max_load_factor() const _NOEXCEPT {return __p3_.first();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+    const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+    const __node_allocator& __node_alloc() const _NOEXCEPT
+        {return __p1_.second();}
+
+public:
+    typedef __hash_iterator<__node_pointer>                   iterator;
+    typedef __hash_const_iterator<__node_pointer>             const_iterator;
+    typedef __hash_local_iterator<__node_pointer>             local_iterator;
+    typedef __hash_const_local_iterator<__node_pointer>       const_local_iterator;
+
+    __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);
+    __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_HAS_NO_RVALUE_REFERENCES
+    __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);
+    __hash_table(__hash_table&& __u, const allocator_type& __a);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    ~__hash_table();
+
+    __hash_table& operator=(const __hash_table& __u);
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __hash_table& operator=(__hash_table&& __u)
+        _NOEXCEPT_(
+            __node_traits::propagate_on_container_move_assignment::value &&
+            is_nothrow_move_assignable<__node_allocator>::value &&
+            is_nothrow_move_assignable<hasher>::value &&
+            is_nothrow_move_assignable<key_equal>::value);
+#endif
+    template <class _InputIterator>
+        void __assign_unique(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        void __assign_multi(_InputIterator __first, _InputIterator __last);
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type max_size() const _NOEXCEPT
+    {
+        return allocator_traits<__pointer_allocator>::max_size(
+            __bucket_list_.get_deleter().__alloc());
+    }
+
+    pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
+    iterator             __node_insert_multi(__node_pointer __nd);
+    iterator             __node_insert_multi(const_iterator __p,
+                                             __node_pointer __nd);
+
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+    template <class... _Args>
+        pair<iterator, bool> __emplace_unique(_Args&&... __args);
+    template <class... _Args>
+        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)
+
+    pair<iterator, bool> __insert_unique(const value_type& __x);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    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);
+    _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
+        {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type bucket_count() const _NOEXCEPT
+    {
+        return __bucket_list_.get_deleter().size();
+    }
+
+    iterator       begin() _NOEXCEPT;
+    iterator       end() _NOEXCEPT;
+    const_iterator begin() const _NOEXCEPT;
+    const_iterator end() const _NOEXCEPT;
+
+    template <class _Key>
+        _LIBCPP_INLINE_VISIBILITY
+        size_type bucket(const _Key& __k) const
+        {
+            _LIBCPP_ASSERT(bucket_count() > 0,
+                "unordered container::bucket(key) called when bucket_count() == 0");
+            return __constrain_hash(hash_function()(__k), bucket_count());
+        }
+
+    template <class _Key>
+        iterator       find(const _Key& __x);
+    template <class _Key>
+        const_iterator find(const _Key& __x) const;
+
+    typedef __hash_node_destructor<__node_allocator> _Dp;
+    typedef unique_ptr<__node, _Dp> __node_holder;
+
+    iterator erase(const_iterator __p);
+    iterator erase(const_iterator __first, const_iterator __last);
+    template <class _Key>
+        size_type __erase_unique(const _Key& __k);
+    template <class _Key>
+        size_type __erase_multi(const _Key& __k);
+    __node_holder remove(const_iterator __p) _NOEXCEPT;
+
+    template <class _Key>
+        size_type __count_unique(const _Key& __k) const;
+    template <class _Key>
+        size_type __count_multi(const _Key& __k) const;
+
+    template <class _Key>
+        pair<iterator, iterator>
+        __equal_range_unique(const _Key& __k);
+    template <class _Key>
+        pair<const_iterator, const_iterator>
+        __equal_range_unique(const _Key& __k) const;
+
+    template <class _Key>
+        pair<iterator, iterator>
+        __equal_range_multi(const _Key& __k);
+    template <class _Key>
+        pair<const_iterator, const_iterator>
+        __equal_range_multi(const _Key& __k) const;
+
+    void swap(__hash_table& __u)
+        _NOEXCEPT_(
+            (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
+             __is_nothrow_swappable<__pointer_allocator>::value) &&
+            (!__node_traits::propagate_on_container_swap::value ||
+             __is_nothrow_swappable<__node_allocator>::value) &&
+            __is_nothrow_swappable<hasher>::value &&
+            __is_nothrow_swappable<key_equal>::value);
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type max_bucket_count() const _NOEXCEPT
+        {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());}
+    size_type bucket_size(size_type __n) const;
+    _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
+    {
+        size_type __bc = bucket_count();
+        return __bc != 0 ? (float)size() / __bc : 0.f;
+    }
+    _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
+    {
+        _LIBCPP_ASSERT(__mlf > 0,
+            "unordered container::max_load_factor(lf) called with lf <= 0");
+        max_load_factor() = _VSTD::max(__mlf, load_factor());
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    local_iterator
+    begin(size_type __n)
+    {
+        _LIBCPP_ASSERT(__n < bucket_count(),
+            "unordered container::begin(n) called with n >= bucket_count()");
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
+#else
+        return local_iterator(__bucket_list_[__n], __n, bucket_count());
+#endif
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    local_iterator
+    end(size_type __n)
+    {
+        _LIBCPP_ASSERT(__n < bucket_count(),
+            "unordered container::end(n) called with n >= bucket_count()");
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        return local_iterator(nullptr, __n, bucket_count(), this);
+#else
+        return local_iterator(nullptr, __n, bucket_count());
+#endif
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    const_local_iterator
+    cbegin(size_type __n) const
+    {
+        _LIBCPP_ASSERT(__n < bucket_count(),
+            "unordered container::cbegin(n) called with n >= bucket_count()");
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
+#else
+        return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
+#endif
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    const_local_iterator
+    cend(size_type __n) const
+    {
+        _LIBCPP_ASSERT(__n < bucket_count(),
+            "unordered container::cend(n) called with n >= bucket_count()");
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        return const_local_iterator(nullptr, __n, bucket_count(), this);
+#else
+        return const_local_iterator(nullptr, __n, bucket_count());
+#endif
+    }
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+    bool __dereferenceable(const const_iterator* __i) const;
+    bool __decrementable(const const_iterator* __i) const;
+    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
+    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+
+private:
+    void __rehash(size_type __n);
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class ..._Args>
+        __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)
+        {__copy_assign_alloc(__u, integral_constant<bool,
+             __node_traits::propagate_on_container_copy_assignment::value>());}
+    void __copy_assign_alloc(const __hash_table& __u, true_type);
+    _LIBCPP_INLINE_VISIBILITY
+        void __copy_assign_alloc(const __hash_table&, false_type) {}
+
+    void __move_assign(__hash_table& __u, false_type);
+    void __move_assign(__hash_table& __u, true_type)
+        _NOEXCEPT_(
+            is_nothrow_move_assignable<__node_allocator>::value &&
+            is_nothrow_move_assignable<hasher>::value &&
+            is_nothrow_move_assignable<key_equal>::value);
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__hash_table& __u)
+        _NOEXCEPT_(
+            !__node_traits::propagate_on_container_move_assignment::value ||
+            (is_nothrow_move_assignable<__pointer_allocator>::value &&
+             is_nothrow_move_assignable<__node_allocator>::value))
+        {__move_assign_alloc(__u, integral_constant<bool,
+             __node_traits::propagate_on_container_move_assignment::value>());}
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__hash_table& __u, true_type)
+        _NOEXCEPT_(
+            is_nothrow_move_assignable<__pointer_allocator>::value &&
+            is_nothrow_move_assignable<__node_allocator>::value)
+    {
+        __bucket_list_.get_deleter().__alloc() =
+                _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
+        __node_alloc() = _VSTD::move(__u.__node_alloc());
+    }
+    _LIBCPP_INLINE_VISIBILITY
+        void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
+
+    template <class _Ap>
+    _LIBCPP_INLINE_VISIBILITY
+    static
+    void
+    __swap_alloc(_Ap& __x, _Ap& __y)
+        _NOEXCEPT_(
+            !allocator_traits<_Ap>::propagate_on_container_swap::value ||
+            __is_nothrow_swappable<_Ap>::value)
+    {
+        __swap_alloc(__x, __y,
+                     integral_constant<bool,
+                        allocator_traits<_Ap>::propagate_on_container_swap::value
+                                      >());
+    }
+
+    template <class _Ap>
+    _LIBCPP_INLINE_VISIBILITY
+    static
+    void
+    __swap_alloc(_Ap& __x, _Ap& __y, true_type)
+        _NOEXCEPT_(__is_nothrow_swappable<_Ap>::value)
+    {
+        using _VSTD::swap;
+        swap(__x, __y);
+    }
+
+    template <class _Ap>
+    _LIBCPP_INLINE_VISIBILITY
+    static
+    void
+    __swap_alloc(_Ap&, _Ap&, false_type) _NOEXCEPT {}
+
+    void __deallocate(__node_pointer __np) _NOEXCEPT;
+    __node_pointer __detach() _NOEXCEPT;
+
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
+    template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
+};
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+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<hasher>::value &&
+        is_nothrow_default_constructible<key_equal>::value)
+    : __p2_(0),
+      __p3_(1.0f)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+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()),
+      __p1_(),
+      __p2_(0, __hf),
+      __p3_(1.0f, __eql)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
+                                                       const key_equal& __eql,
+                                                       const allocator_type& __a)
+    : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
+      __p1_(__node_allocator(__a)),
+      __p2_(0, __hf),
+      __p3_(1.0f, __eql)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
+    : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
+      __p1_(__node_allocator(__a)),
+      __p2_(0),
+      __p3_(1.0f)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
+    : __bucket_list_(nullptr,
+          __bucket_list_deleter(allocator_traits<__pointer_allocator>::
+              select_on_container_copy_construction(
+                  __u.__bucket_list_.get_deleter().__alloc()), 0)),
+      __p1_(allocator_traits<__node_allocator>::
+          select_on_container_copy_construction(__u.__node_alloc())),
+      __p2_(0, __u.hash_function()),
+      __p3_(__u.__p3_)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
+                                                       const allocator_type& __a)
+    : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
+      __p1_(__node_allocator(__a)),
+      __p2_(0, __u.hash_function()),
+      __p3_(__u.__p3_)
+{
+}
+
+#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<hasher>::value &&
+            is_nothrow_move_constructible<key_equal>::value)
+    : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
+      __p1_(_VSTD::move(__u.__p1_)),
+      __p2_(_VSTD::move(__u.__p2_)),
+      __p3_(_VSTD::move(__u.__p3_))
+{
+    if (size() > 0)
+    {
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+        __u.__p1_.first().__next_ = nullptr;
+        __u.size() = 0;
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
+                                                       const allocator_type& __a)
+    : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
+      __p1_(__node_allocator(__a)),
+      __p2_(0, _VSTD::move(__u.hash_function())),
+      __p3_(_VSTD::move(__u.__p3_))
+{
+    if (__a == allocator_type(__u.__node_alloc()))
+    {
+        __bucket_list_.reset(__u.__bucket_list_.release());
+        __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
+        __u.__bucket_list_.get_deleter().size() = 0;
+        if (__u.size() > 0)
+        {
+            __p1_.first().__next_ = __u.__p1_.first().__next_;
+            __u.__p1_.first().__next_ = nullptr;
+            __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+                static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+            size() = __u.size();
+            __u.size() = 0;
+        }
+    }
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
+{
+    __deallocate(__p1_.first().__next_);
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __get_db()->__erase_c(this);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
+        const __hash_table& __u, true_type)
+{
+    if (__node_alloc() != __u.__node_alloc())
+    {
+        clear();
+        __bucket_list_.reset();
+        __bucket_list_.get_deleter().size() = 0;
+    }
+    __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
+    __node_alloc() = __u.__node_alloc();
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>&
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
+{
+    if (this != &__u)
+    {
+        __copy_assign_alloc(__u);
+        hash_function() = __u.hash_function();
+        key_eq() = __u.key_eq();
+        max_load_factor() = __u.max_load_factor();
+        __assign_multi(__u.begin(), __u.end());
+    }
+    return *this;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np)
+    _NOEXCEPT
+{
+    __node_allocator& __na = __node_alloc();
+    while (__np != nullptr)
+    {
+        __node_pointer __next = __np->__next_;
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        __c_node* __c = __get_db()->__find_c_and_lock(this);
+        for (__i_node** __p = __c->end_; __p != __c->beg_; )
+        {
+            --__p;
+            iterator* __i = static_cast<iterator*>((*__p)->__i_);
+            if (__i->__node_ == __np)
+            {
+                (*__p)->__c_ = nullptr;
+                if (--__c->end_ != __p)
+                    memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+            }
+        }
+        __get_db()->unlock();
+#endif
+        __node_traits::destroy(__na, _VSTD::addressof(__np->__value_));
+        __node_traits::deallocate(__na, __np, 1);
+        __np = __next;
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
+{
+    size_type __bc = bucket_count();
+    for (size_type __i = 0; __i < __bc; ++__i)
+        __bucket_list_[__i] = nullptr;
+    size() = 0;
+    __node_pointer __cache = __p1_.first().__next_;
+    __p1_.first().__next_ = nullptr;
+    return __cache;
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
+        __hash_table& __u, true_type)
+    _NOEXCEPT_(
+        is_nothrow_move_assignable<__node_allocator>::value &&
+        is_nothrow_move_assignable<hasher>::value &&
+        is_nothrow_move_assignable<key_equal>::value)
+{
+    clear();
+    __bucket_list_.reset(__u.__bucket_list_.release());
+    __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
+    __u.__bucket_list_.get_deleter().size() = 0;
+    __move_assign_alloc(__u);
+    size() = __u.size();
+    hash_function() = _VSTD::move(__u.hash_function());
+    max_load_factor() = __u.max_load_factor();
+    key_eq() = _VSTD::move(__u.key_eq());
+    __p1_.first().__next_ = __u.__p1_.first().__next_;
+    if (size() > 0)
+    {
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+        __u.__p1_.first().__next_ = nullptr;
+        __u.size() = 0;
+    }
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __get_db()->swap(this, &__u);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
+        __hash_table& __u, false_type)
+{
+    if (__node_alloc() == __u.__node_alloc())
+        __move_assign(__u, true_type());
+    else
+    {
+        hash_function() = _VSTD::move(__u.hash_function());
+        key_eq() = _VSTD::move(__u.key_eq());
+        max_load_factor() = __u.max_load_factor();
+        if (bucket_count() != 0)
+        {
+            __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            try
+            {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+                const_iterator __i = __u.begin();
+                while (__cache != nullptr && __u.size() != 0)
+                {
+                    __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_);
+                    __node_pointer __next = __cache->__next_;
+                    __node_insert_multi(__cache);
+                    __cache = __next;
+                }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            }
+            catch (...)
+            {
+                __deallocate(__cache);
+                throw;
+            }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            __deallocate(__cache);
+        }
+        const_iterator __i = __u.begin();
+        while (__u.size() != 0)
+        {
+            __node_holder __h =
+                    __construct_node(_VSTD::move(__u.remove(__i++)->__value_));
+            __node_insert_multi(__h.get());
+            __h.release();
+        }
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+__hash_table<_Tp, _Hash, _Equal, _Alloc>&
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
+    _NOEXCEPT_(
+        __node_traits::propagate_on_container_move_assignment::value &&
+        is_nothrow_move_assignable<__node_allocator>::value &&
+        is_nothrow_move_assignable<hasher>::value &&
+        is_nothrow_move_assignable<key_equal>::value)
+{
+    __move_assign(__u, integral_constant<bool,
+                  __node_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _InputIterator>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
+                                                          _InputIterator __last)
+{
+    if (bucket_count() != 0)
+    {
+        __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __cache->__next_;
+                __node_insert_unique(__cache);
+                __cache = __next;
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __deallocate(__cache);
+            throw;
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+        __deallocate(__cache);
+    }
+    for (; __first != __last; ++__first)
+        __insert_unique(*__first);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _InputIterator>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
+                                                         _InputIterator __last)
+{
+    if (bucket_count() != 0)
+    {
+        __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __cache->__next_;
+                __node_insert_multi(__cache);
+                __cache = __next;
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __deallocate(__cache);
+            throw;
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+        __deallocate(__cache);
+    }
+    for (; __first != __last; ++__first)
+        __insert_multi(*__first);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator(__p1_.first().__next_, this);
+#else
+    return iterator(__p1_.first().__next_);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator(nullptr, this);
+#else
+    return iterator(nullptr);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return const_iterator(__p1_.first().__next_, this);
+#else
+    return const_iterator(__p1_.first().__next_);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return const_iterator(nullptr, this);
+#else
+    return const_iterator(nullptr);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
+{
+    if (size() > 0)
+    {
+        __deallocate(__p1_.first().__next_);
+        __p1_.first().__next_ = nullptr;
+        size_type __bc = bucket_count();
+        for (size_type __i = 0; __i < __bc; ++__i)
+            __bucket_list_[__i] = nullptr;
+        size() = 0;
+    }
+}
+
+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>::__node_insert_unique(__node_pointer __nd)
+{
+    __nd->__hash_ = hash_function()(__nd->__value_);
+    size_type __bc = bucket_count();
+    bool __inserted = false;
+    __node_pointer __ndptr;
+    size_t __chash;
+    if (__bc != 0)
+    {
+        __chash = __constrain_hash(__nd->__hash_, __bc);
+        __ndptr = __bucket_list_[__chash];
+        if (__ndptr != nullptr)
+        {
+            for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
+                                             __constrain_hash(__ndptr->__hash_, __bc) == __chash;
+                                                     __ndptr = __ndptr->__next_)
+            {
+                if (key_eq()(__ndptr->__value_, __nd->__value_))
+                    goto __done;
+            }
+        }
+    }
+    {
+        if (size()+1 > __bc * max_load_factor() || __bc == 0)
+        {
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+            __chash = __constrain_hash(__nd->__hash_, __bc);
+        }
+        // insert_after __bucket_list_[__chash], or __first_node if bucket is null
+        __node_pointer __pn = __bucket_list_[__chash];
+        if (__pn == nullptr)
+        {
+            __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+            __nd->__next_ = __pn->__next_;
+            __pn->__next_ = __nd;
+            // fix up __bucket_list_
+            __bucket_list_[__chash] = __pn;
+            if (__nd->__next_ != nullptr)
+                __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd;
+        }
+        else
+        {
+            __nd->__next_ = __pn->__next_;
+            __pn->__next_ = __nd;
+        }
+        __ndptr = __nd;
+        // increment size
+        ++size();
+        __inserted = true;
+    }
+__done:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
+#else
+    return pair<iterator, bool>(iterator(__ndptr), __inserted);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
+{
+    __cp->__hash_ = hash_function()(__cp->__value_);
+    size_type __bc = bucket_count();
+    if (size()+1 > __bc * max_load_factor() || __bc == 0)
+    {
+        rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
+                       size_type(ceil(float(size() + 1) / max_load_factor()))));
+        __bc = bucket_count();
+    }
+    size_t __chash = __constrain_hash(__cp->__hash_, __bc);
+    __node_pointer __pn = __bucket_list_[__chash];
+    if (__pn == nullptr)
+    {
+        __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+        __cp->__next_ = __pn->__next_;
+        __pn->__next_ = __cp;
+        // fix up __bucket_list_
+        __bucket_list_[__chash] = __pn;
+        if (__cp->__next_ != nullptr)
+            __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp;
+    }
+    else
+    {
+        for (bool __found = false; __pn->__next_ != nullptr &&
+                                   __constrain_hash(__pn->__next_->__hash_, __bc) == __chash;
+                                                           __pn = __pn->__next_)
+        {
+            //      __found    key_eq()     action
+            //      false       false       loop
+            //      true        true        loop
+            //      false       true        set __found to true
+            //      true        false       break
+            if (__found != (__pn->__next_->__hash_ == __cp->__hash_ &&
+                            key_eq()(__pn->__next_->__value_, __cp->__value_)))
+            {
+                if (!__found)
+                    __found = true;
+                else
+                    break;
+            }
+        }
+        __cp->__next_ = __pn->__next_;
+        __pn->__next_ = __cp;
+        if (__cp->__next_ != nullptr)
+        {
+            size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc);
+            if (__nhash != __chash)
+                __bucket_list_[__nhash] = __cp;
+        }
+    }
+    ++size();
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator(__cp, this);
+#else
+    return iterator(__cp);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
+        const_iterator __p, __node_pointer __cp)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
+        " referring to this unordered container");
+#endif
+    if (__p != end() && key_eq()(*__p, __cp->__value_))
+    {
+        __node_pointer __np = __p.__node_;
+        __cp->__hash_ = __np->__hash_;
+        size_type __bc = bucket_count();
+        if (size()+1 > __bc * max_load_factor() || __bc == 0)
+        {
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+        }
+        size_t __chash = __constrain_hash(__cp->__hash_, __bc);
+        __node_pointer __pp = __bucket_list_[__chash];
+        while (__pp->__next_ != __np)
+            __pp = __pp->__next_;
+        __cp->__next_ = __np;
+        __pp->__next_ = __cp;
+        ++size();
+#if _LIBCPP_DEBUG_LEVEL >= 2
+        return iterator(__cp, this);
+#else
+        return iterator(__cp);
+#endif
+    }
+    return __node_insert_multi(__cp);
+}
+
+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(const value_type& __x)
+{
+    size_t __hash = hash_function()(__x);
+    size_type __bc = bucket_count();
+    bool __inserted = false;
+    __node_pointer __nd;
+    size_t __chash;
+    if (__bc != 0)
+    {
+        __chash = __constrain_hash(__hash, __bc);
+        __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                       __constrain_hash(__nd->__hash_, __bc) == __chash;
+                                                           __nd = __nd->__next_)
+            {
+                if (key_eq()(__nd->__value_, __x))
+                    goto __done;
+            }
+        }
+    }
+    {
+        __node_holder __h = __construct_node(__x, __hash);
+        if (size()+1 > __bc * max_load_factor() || __bc == 0)
+        {
+            rehash(_VSTD::max<size_type>(2 * __bc + !__is_power2(__bc),
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+            __chash = __constrain_hash(__hash, __bc);
+        }
+        // insert_after __bucket_list_[__chash], or __first_node if bucket is null
+        __node_pointer __pn = __bucket_list_[__chash];
+        if (__pn == nullptr)
+        {
+            __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_
+            __bucket_list_[__chash] = __pn;
+            if (__h->__next_ != nullptr)
+                __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get();
+        }
+        else
+        {
+            __h->__next_ = __pn->__next_;
+            __pn->__next_ = __h.get();
+        }
+        __nd = __h.release();
+        // increment size
+        ++size();
+        __inserted = true;
+    }
+__done:
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return pair<iterator, bool>(iterator(__nd, this), __inserted);
+#else
+    return pair<iterator, bool>(iterator(__nd), __inserted);
+#endif
+}
+
+#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(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    pair<iterator, bool> __r = __node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class... _Args>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class... _Args>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
+        const_iterator __p, _Args&&... __args)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
+        " referring to this unordered container");
+#endif
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+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 value_type& __x)
+{
+    __node_holder __h = __construct_node(__x);
+    iterator __r = __node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+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 value_type& __x)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "unordered container::insert(const_iterator, lvalue) called with an iterator not"
+        " referring to this unordered container");
+#endif
+    __node_holder __h = __construct_node(__x);
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
+{
+    if (__n == 1)
+        __n = 2;
+    else if (__n & (__n - 1))
+        __n = __next_prime(__n);
+    size_type __bc = bucket_count();
+    if (__n > __bc)
+        __rehash(__n);
+    else if (__n < __bc)
+    {
+        __n = _VSTD::max<size_type>
+              (
+                  __n,
+                  __is_power2(__bc) ? __next_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
+                                      __next_prime(size_t(ceil(float(size()) / max_load_factor())))
+              );
+        if (__n < __bc)
+            __rehash(__n);
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __get_db()->__invalidate_all(this);
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+    __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
+    __bucket_list_.reset(__nbc > 0 ?
+                      __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
+    __bucket_list_.get_deleter().size() = __nbc;
+    if (__nbc > 0)
+    {
+        for (size_type __i = 0; __i < __nbc; ++__i)
+            __bucket_list_[__i] = nullptr;
+        __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
+        __node_pointer __cp = __pp->__next_;
+        if (__cp != nullptr)
+        {
+            size_type __chash = __constrain_hash(__cp->__hash_, __nbc);
+            __bucket_list_[__chash] = __pp;
+            size_type __phash = __chash;
+            for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
+                                                           __cp = __pp->__next_)
+            {
+                __chash = __constrain_hash(__cp->__hash_, __nbc);
+                if (__chash == __phash)
+                    __pp = __cp;
+                else
+                {
+                    if (__bucket_list_[__chash] == nullptr)
+                    {
+                        __bucket_list_[__chash] = __pp;
+                        __pp = __cp;
+                        __phash = __chash;
+                    }
+                    else
+                    {
+                        __node_pointer __np = __cp;
+                        for (; __np->__next_ != nullptr &&
+                               key_eq()(__cp->__value_, __np->__next_->__value_);
+                                                           __np = __np->__next_)
+                            ;
+                        __pp->__next_ = __np->__next_;
+                        __np->__next_ = __bucket_list_[__chash]->__next_;
+                        __bucket_list_[__chash]->__next_ = __cp;
+
+                    }
+                }
+            }
+        }
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
+{
+    size_t __hash = hash_function()(__k);
+    size_type __bc = bucket_count();
+    if (__bc != 0)
+    {
+        size_t __chash = __constrain_hash(__hash, __bc);
+        __node_pointer __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                       __constrain_hash(__nd->__hash_, __bc) == __chash;
+                                                           __nd = __nd->__next_)
+            {
+                if (key_eq()(__nd->__value_, __k))
+#if _LIBCPP_DEBUG_LEVEL >= 2
+                    return iterator(__nd, this);
+#else
+                    return iterator(__nd);
+#endif
+            }
+        }
+    }
+    return end();
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
+{
+    size_t __hash = hash_function()(__k);
+    size_type __bc = bucket_count();
+    if (__bc != 0)
+    {
+        size_t __chash = __constrain_hash(__hash, __bc);
+        __node_const_pointer __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                           __constrain_hash(__nd->__hash_, __bc) == __chash;
+                                                           __nd = __nd->__next_)
+            {
+                if (key_eq()(__nd->__value_, __k))
+#if _LIBCPP_DEBUG_LEVEL >= 2
+                    return const_iterator(__nd, this);
+#else
+                    return const_iterator(__nd);
+#endif
+            }
+        }
+
+    }
+    return end();
+}
+
+#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)
+{
+    __node_allocator& __na = __node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __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>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(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, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = __hash;
+    __h->__next_ = nullptr;
+    return __h;
+}
+
+#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 value_type& __v)
+{
+    __node_allocator& __na = __node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __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 _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(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, _VSTD::addressof(__h->__value_), __v);
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = __hash;
+    __h->__next_ = nullptr;
+    return _VSTD::move(__h);  // explicitly moved for C++03
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
+{
+    __node_pointer __np = __p.__node_;
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+        "unordered container erase(iterator) called with an iterator not"
+        " referring to this container");
+    _LIBCPP_ASSERT(__p != end(),
+        "unordered container erase(iterator) called with a non-dereferenceable iterator");
+    iterator __r(__np, this);
+#else
+    iterator __r(__np);
+#endif
+    ++__r;
+    remove(__p);
+    return __r;
+}
+
+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 __first,
+                                                const_iterator __last)
+{
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
+        "unodered container::erase(iterator, iterator) called with an iterator not"
+        " referring to this unodered container");
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
+        "unodered container::erase(iterator, iterator) called with an iterator not"
+        " referring to this unodered container");
+#endif
+    for (const_iterator __p = __first; __first != __last; __p = __first)
+    {
+        ++__first;
+        erase(__p);
+    }
+    __node_pointer __np = __last.__node_;
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    return iterator (__np, this);
+#else
+    return iterator (__np);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
+{
+    iterator __i = find(__k);
+    if (__i == end())
+        return 0;
+    erase(__i);
+    return 1;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
+{
+    size_type __r = 0;
+    iterator __i = find(__k);
+    if (__i != end())
+    {
+        iterator __e = end();
+        do
+        {
+            erase(__i++);
+            ++__r;
+        } while (__i != __e && key_eq()(*__i, __k));
+    }
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
+{
+    // current node
+    __node_pointer __cn = __p.__node_;
+    size_type __bc = bucket_count();
+    size_t __chash = __constrain_hash(__cn->__hash_, __bc);
+    // find previous node
+    __node_pointer __pn = __bucket_list_[__chash];
+    for (; __pn->__next_ != __cn; __pn = __pn->__next_)
+        ;
+    // Fix up __bucket_list_
+        // if __pn is not in same bucket (before begin is not in same bucket) &&
+        //    if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
+    if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))
+                            || __constrain_hash(__pn->__hash_, __bc) != __chash)
+    {
+        if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash)
+            __bucket_list_[__chash] = nullptr;
+    }
+        // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
+    if (__cn->__next_ != nullptr)
+    {
+        size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc);
+        if (__nhash != __chash)
+            __bucket_list_[__nhash] = __pn;
+    }
+    // remove __cn
+    __pn->__next_ = __cn->__next_;
+    __cn->__next_ = nullptr;
+    --size();
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __c_node* __c = __get_db()->__find_c_and_lock(this);
+    for (__i_node** __p = __c->end_; __p != __c->beg_; )
+    {
+        --__p;
+        iterator* __i = static_cast<iterator*>((*__p)->__i_);
+        if (__i->__node_ == __cn)
+        {
+            (*__p)->__c_ = nullptr;
+            if (--__c->end_ != __p)
+                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+        }
+    }
+    __get_db()->unlock();
+#endif
+    return __node_holder(__cn, _Dp(__node_alloc(), true));
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+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
+{
+    return static_cast<size_type>(find(__k) != end());
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
+{
+    size_type __r = 0;
+    const_iterator __i = find(__k);
+    if (__i != end())
+    {
+        const_iterator __e = end();
+        do
+        {
+            ++__i;
+            ++__r;
+        } while (__i != __e && key_eq()(*__i, __k));
+    }
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
+     typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
+        const _Key& __k)
+{
+    iterator __i = find(__k);
+    iterator __j = __i;
+    if (__i != end())
+        ++__j;
+    return pair<iterator, iterator>(__i, __j);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
+     typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
+        const _Key& __k) const
+{
+    const_iterator __i = find(__k);
+    const_iterator __j = __i;
+    if (__i != end())
+        ++__j;
+    return pair<const_iterator, const_iterator>(__i, __j);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
+     typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
+        const _Key& __k)
+{
+    iterator __i = find(__k);
+    iterator __j = __i;
+    if (__i != end())
+    {
+        iterator __e = end();
+        do
+        {
+            ++__j;
+        } while (__j != __e && key_eq()(*__j, __k));
+    }
+    return pair<iterator, iterator>(__i, __j);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
+     typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
+        const _Key& __k) const
+{
+    const_iterator __i = find(__k);
+    const_iterator __j = __i;
+    if (__i != end())
+    {
+        const_iterator __e = end();
+        do
+        {
+            ++__j;
+        } while (__j != __e && key_eq()(*__j, __k));
+    }
+    return pair<const_iterator, const_iterator>(__i, __j);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
+    _NOEXCEPT_(
+        (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
+         __is_nothrow_swappable<__pointer_allocator>::value) &&
+        (!__node_traits::propagate_on_container_swap::value ||
+         __is_nothrow_swappable<__node_allocator>::value) &&
+        __is_nothrow_swappable<hasher>::value &&
+        __is_nothrow_swappable<key_equal>::value)
+{
+    {
+    __node_pointer_pointer __npp = __bucket_list_.release();
+    __bucket_list_.reset(__u.__bucket_list_.release());
+    __u.__bucket_list_.reset(__npp);
+    }
+    _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
+    __swap_alloc(__bucket_list_.get_deleter().__alloc(),
+             __u.__bucket_list_.get_deleter().__alloc());
+    __swap_alloc(__node_alloc(), __u.__node_alloc());
+    _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
+    __p2_.swap(__u.__p2_);
+    __p3_.swap(__u.__p3_);
+    if (size() > 0)
+        __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
+    if (__u.size() > 0)
+        __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] =
+            static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first()));
+#if _LIBCPP_DEBUG_LEVEL >= 2
+    __get_db()->swap(this, &__u);
+#endif
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
+{
+    _LIBCPP_ASSERT(__n < bucket_count(),
+        "unordered container::bucket_size(n) called with n >= bucket_count()");
+    __node_const_pointer __np = __bucket_list_[__n];
+    size_type __bc = bucket_count();
+    size_type __r = 0;
+    if (__np != nullptr)
+    {
+        for (__np = __np->__next_; __np != nullptr &&
+                                   __constrain_hash(__np->__hash_, __bc) == __n;
+                                                    __np = __np->__next_, ++__r)
+            ;
+    }
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
+     __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
+    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
+{
+    __x.swap(__y);
+}
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+bool
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
+{
+    return __i->__node_ != nullptr;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+bool
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
+{
+    return false;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+bool
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
+{
+    return false;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+bool
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
+{
+    return false;
+}
+
+#endif  // _LIBCPP_DEBUG_LEVEL >= 2
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP__HASH_TABLE
diff --git a/rc1/include/__locale b/rc1/include/__locale
new file mode 100644
index 0000000..42cf4d9
--- /dev/null
+++ b/rc1/include/__locale
@@ -0,0 +1,1463 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___LOCALE
+#define _LIBCPP___LOCALE
+
+#include <__config>
+#include <string>
+#include <memory>
+#include <utility>
+#include <mutex>
+#include <cstdint>
+#include <cctype>
+#include <locale.h>
+#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+# include <support/win32/locale_win32.h>
+#elif defined(_AIX)
+# include <support/ibm/xlocale.h>
+#elif defined(__ANDROID__)
+// Android gained the locale aware functions in L (API level 21)
+# include <android/api-level.h>
+# if __ANDROID_API__ <= 20
+#  include <support/android/locale_bionic.h>
+# endif
+#elif defined(__sun__)
+# include <support/solaris/xlocale.h>
+#elif defined(_NEWLIB_VERSION)
+# include <support/newlib/xlocale.h>
+#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
+    || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+# include <xlocale.h>
+#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_TYPE_VIS locale;
+
+template <class _Facet>
+_LIBCPP_INLINE_VISIBILITY
+bool
+has_facet(const locale&) _NOEXCEPT;
+
+template <class _Facet>
+_LIBCPP_INLINE_VISIBILITY
+const _Facet&
+use_facet(const locale&);
+
+class _LIBCPP_TYPE_VIS locale
+{
+public:
+    // types:
+    class _LIBCPP_TYPE_VIS facet;
+    class _LIBCPP_TYPE_VIS id;
+
+    typedef int category;
+    static const category // values assigned here are for exposition only
+        none     = 0,
+        collate  = LC_COLLATE_MASK,
+        ctype    = LC_CTYPE_MASK,
+        monetary = LC_MONETARY_MASK,
+        numeric  = LC_NUMERIC_MASK,
+        time     = LC_TIME_MASK,
+        messages = LC_MESSAGES_MASK,
+        all = collate | ctype | monetary | numeric | time | messages;
+
+    // construct/copy/destroy:
+    locale()  _NOEXCEPT;
+    locale(const locale&)  _NOEXCEPT;
+    explicit locale(const char*);
+    explicit locale(const string&);
+    locale(const locale&, const char*, category);
+    locale(const locale&, const string&, category);
+    template <class _Facet>
+        _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
+    locale(const locale&, const locale&, category);
+
+    ~locale();
+
+    const locale& operator=(const locale&)  _NOEXCEPT;
+
+    template <class _Facet> locale combine(const locale&) const;
+
+    // locale operations:
+    string name() const;
+    bool operator==(const locale&) const;
+    bool operator!=(const locale& __y) const {return !(*this == __y);}
+    template <class _CharT, class _Traits, class _Allocator>
+      bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
+                      const basic_string<_CharT, _Traits, _Allocator>&) const;
+
+    // global locale objects:
+    static locale global(const locale&);
+    static const locale& classic();
+
+private:
+    class __imp;
+    __imp* __locale_;
+
+    void __install_ctor(const locale&, facet*, long);
+    static locale& __global();
+    bool has_facet(id&) const;
+    const facet* use_facet(id&) const;
+
+    template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
+    template <class _Facet> friend const _Facet& use_facet(const locale&);
+};
+
+class _LIBCPP_TYPE_VIS locale::facet
+    : public __shared_count
+{
+protected:
+    _LIBCPP_INLINE_VISIBILITY
+    explicit facet(size_t __refs = 0)
+        : __shared_count(static_cast<long>(__refs)-1) {}
+
+    virtual ~facet();
+
+//    facet(const facet&) = delete;     // effectively done in __shared_count
+//    void operator=(const facet&) = delete;
+private:
+    virtual void __on_zero_shared() _NOEXCEPT;
+};
+
+class _LIBCPP_TYPE_VIS locale::id
+{
+    once_flag      __flag_;
+    int32_t        __id_;
+
+    static int32_t __next_id;
+public:
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
+private:
+    void __init();
+    void operator=(const id&); // = delete;
+    id(const id&); // = delete;
+public:  // only needed for tests
+    long __get();
+
+    friend class locale;
+    friend class locale::__imp;
+};
+
+template <class _Facet>
+inline _LIBCPP_INLINE_VISIBILITY
+locale::locale(const locale& __other, _Facet* __f)
+{
+    __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
+}
+
+template <class _Facet>
+locale
+locale::combine(const locale& __other) const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (!_VSTD::has_facet<_Facet>(__other))
+        throw runtime_error("locale::combine: locale missing facet");
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
+}
+
+template <class _Facet>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+has_facet(const locale& __l)  _NOEXCEPT
+{
+    return __l.has_facet(_Facet::id);
+}
+
+template <class _Facet>
+inline _LIBCPP_INLINE_VISIBILITY
+const _Facet&
+use_facet(const locale& __l)
+{
+    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
+}
+
+// template <class _CharT> class collate;
+
+template <class _CharT>
+class _LIBCPP_TYPE_VIS_ONLY collate
+    : public locale::facet
+{
+public:
+    typedef _CharT char_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit collate(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    int compare(const char_type* __lo1, const char_type* __hi1,
+                const char_type* __lo2, const char_type* __hi2) const
+    {
+        return do_compare(__lo1, __hi1, __lo2, __hi2);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    string_type transform(const char_type* __lo, const char_type* __hi) const
+    {
+        return do_transform(__lo, __hi);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    long hash(const char_type* __lo, const char_type* __hi) const
+    {
+        return do_hash(__lo, __hi);
+    }
+
+    static locale::id id;
+
+protected:
+    ~collate();
+    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
+                           const char_type* __lo2, const char_type* __hi2) const;
+    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
+        {return string_type(__lo, __hi);}
+    virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
+};
+
+template <class _CharT> locale::id collate<_CharT>::id;
+
+template <class _CharT>
+collate<_CharT>::~collate()
+{
+}
+
+template <class _CharT>
+int
+collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
+                            const char_type* __lo2, const char_type* __hi2) const
+{
+    for (; __lo2 != __hi2; ++__lo1, ++__lo2)
+    {
+        if (__lo1 == __hi1 || *__lo1 < *__lo2)
+            return -1;
+        if (*__lo2 < *__lo1)
+            return 1;
+    }
+    return __lo1 != __hi1;
+}
+
+template <class _CharT>
+long
+collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
+{
+    size_t __h = 0;
+    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
+    const size_t __mask = size_t(0xF) << (__sr + 4);
+    for(const char_type* __p = __lo; __p != __hi; ++__p)
+    {
+        __h = (__h << 4) + static_cast<size_t>(*__p);
+        size_t __g = __h & __mask;
+        __h ^= __g | (__g >> __sr);
+    }
+    return static_cast<long>(__h);
+}
+
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<char>)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<wchar_t>)
+
+// template <class CharT> class collate_byname;
+
+template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY collate_byname;
+
+template <>
+class _LIBCPP_TYPE_VIS collate_byname<char>
+    : public collate<char>
+{
+    locale_t __l;
+public:
+    typedef char char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit collate_byname(const char* __n, size_t __refs = 0);
+    explicit collate_byname(const string& __n, size_t __refs = 0);
+
+protected:
+    ~collate_byname();
+    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
+                           const char_type* __lo2, const char_type* __hi2) const;
+    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
+};
+
+template <>
+class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
+    : public collate<wchar_t>
+{
+    locale_t __l;
+public:
+    typedef wchar_t char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit collate_byname(const char* __n, size_t __refs = 0);
+    explicit collate_byname(const string& __n, size_t __refs = 0);
+
+protected:
+    ~collate_byname();
+
+    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
+                           const char_type* __lo2, const char_type* __hi2) const;
+    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+bool
+locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
+                   const basic_string<_CharT, _Traits, _Allocator>& __y) const
+{
+    return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
+                                       __x.data(), __x.data() + __x.size(),
+                                       __y.data(), __y.data() + __y.size()) < 0;
+}
+
+// template <class charT> class ctype
+
+class _LIBCPP_TYPE_VIS ctype_base
+{
+public:
+#ifdef __GLIBC__
+    typedef unsigned short mask;
+    static const mask space  = _ISspace;
+    static const mask print  = _ISprint;
+    static const mask cntrl  = _IScntrl;
+    static const mask upper  = _ISupper;
+    static const mask lower  = _ISlower;
+    static const mask alpha  = _ISalpha;
+    static const mask digit  = _ISdigit;
+    static const mask punct  = _ISpunct;
+    static const mask xdigit = _ISxdigit;
+    static const mask blank  = _ISblank;
+#elif defined(_WIN32)
+    typedef unsigned short mask;
+    static const mask space  = _SPACE;
+    static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
+    static const mask cntrl  = _CONTROL;
+    static const mask upper  = _UPPER;
+    static const mask lower  = _LOWER;
+    static const mask alpha  = _ALPHA;
+    static const mask digit  = _DIGIT;
+    static const mask punct  = _PUNCT;
+    static const mask xdigit = _HEX;
+    static const mask blank  = _BLANK;
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__ANDROID__)
+#ifdef __APPLE__
+    typedef __uint32_t mask;
+#elif defined(__FreeBSD__)
+    typedef unsigned long mask;
+#elif defined(__EMSCRIPTEN__) ||  defined(__NetBSD__)
+    typedef unsigned short mask;
+#elif defined(__ANDROID__)
+    typedef unsigned char mask;
+#endif
+    static const mask space  = _CTYPE_S;
+    static const mask print  = _CTYPE_R;
+    static const mask cntrl  = _CTYPE_C;
+    static const mask upper  = _CTYPE_U;
+    static const mask lower  = _CTYPE_L;
+    static const mask alpha  = _CTYPE_A;
+    static const mask digit  = _CTYPE_D;
+    static const mask punct  = _CTYPE_P;
+# if defined(__ANDROID__)
+    static const mask xdigit = _CTYPE_X | _CTYPE_D;
+# else
+    static const mask xdigit = _CTYPE_X;
+# endif
+
+# if defined(__NetBSD__)
+    static const mask blank  = _CTYPE_BL;
+# else
+    static const mask blank  = _CTYPE_B;
+# endif
+#elif defined(__sun__) || defined(_AIX)
+    typedef unsigned int mask;
+    static const mask space  = _ISSPACE;
+    static const mask print  = _ISPRINT;
+    static const mask cntrl  = _ISCNTRL;
+    static const mask upper  = _ISUPPER;
+    static const mask lower  = _ISLOWER;
+    static const mask alpha  = _ISALPHA;
+    static const mask digit  = _ISDIGIT;
+    static const mask punct  = _ISPUNCT;
+    static const mask xdigit = _ISXDIGIT;
+    static const mask blank  = _ISBLANK;
+#else  // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __EMSCRIPTEN__ || __sun__
+    typedef unsigned long mask;
+    static const mask space  = 1<<0;
+    static const mask print  = 1<<1;
+    static const mask cntrl  = 1<<2;
+    static const mask upper  = 1<<3;
+    static const mask lower  = 1<<4;
+    static const mask alpha  = 1<<5;
+    static const mask digit  = 1<<6;
+    static const mask punct  = 1<<7;
+    static const mask xdigit = 1<<8;
+    static const mask blank  = 1<<9;
+#endif  // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
+    static const mask alnum  = alpha | digit;
+    static const mask graph  = alnum | punct;
+
+    _LIBCPP_ALWAYS_INLINE ctype_base() {}
+};
+
+template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype;
+
+template <>
+class _LIBCPP_TYPE_VIS ctype<wchar_t>
+    : public locale::facet,
+      public ctype_base
+{
+public:
+    typedef wchar_t char_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit ctype(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    bool is(mask __m, char_type __c) const
+    {
+        return do_is(__m, __c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
+    {
+        return do_is(__low, __high, __vec);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
+    {
+        return do_scan_is(__m, __low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
+    {
+        return do_scan_not(__m, __low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type toupper(char_type __c) const
+    {
+        return do_toupper(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* toupper(char_type* __low, const char_type* __high) const
+    {
+        return do_toupper(__low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type tolower(char_type __c) const
+    {
+        return do_tolower(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* tolower(char_type* __low, const char_type* __high) const
+    {
+        return do_tolower(__low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type widen(char __c) const
+    {
+        return do_widen(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char* widen(const char* __low, const char* __high, char_type* __to) const
+    {
+        return do_widen(__low, __high, __to);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char narrow(char_type __c, char __dfault) const
+    {
+        return do_narrow(__c, __dfault);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
+    {
+        return do_narrow(__low, __high, __dfault, __to);
+    }
+
+    static locale::id id;
+
+protected:
+    ~ctype();
+    virtual bool do_is(mask __m, char_type __c) const;
+    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
+    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
+    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
+    virtual char_type do_toupper(char_type) const;
+    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
+    virtual char_type do_tolower(char_type) const;
+    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
+    virtual char_type do_widen(char) const;
+    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
+    virtual char do_narrow(char_type, char __dfault) const;
+    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
+};
+
+template <>
+class _LIBCPP_TYPE_VIS ctype<char>
+    : public locale::facet, public ctype_base
+{
+    const mask* __tab_;
+    bool        __del_;
+public:
+    typedef char char_type;
+
+    explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
+
+    _LIBCPP_ALWAYS_INLINE
+    bool is(mask __m, char_type __c) const
+    {
+        return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
+    {
+        for (; __low != __high; ++__low, ++__vec)
+            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
+        return __low;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
+    {
+        for (; __low != __high; ++__low)
+            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
+                break;
+        return __low;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
+    {
+        for (; __low != __high; ++__low)
+            if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
+                break;
+        return __low;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type toupper(char_type __c) const
+    {
+        return do_toupper(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* toupper(char_type* __low, const char_type* __high) const
+    {
+        return do_toupper(__low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type tolower(char_type __c) const
+    {
+        return do_tolower(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char_type* tolower(char_type* __low, const char_type* __high) const
+    {
+        return do_tolower(__low, __high);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char_type widen(char __c) const
+    {
+        return do_widen(__c);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char* widen(const char* __low, const char* __high, char_type* __to) const
+    {
+        return do_widen(__low, __high, __to);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    char narrow(char_type __c, char __dfault) const
+    {
+        return do_narrow(__c, __dfault);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
+    {
+        return do_narrow(__low, __high, __dfault, __to);
+    }
+
+    static locale::id id;
+
+#ifdef _CACHED_RUNES
+    static const size_t table_size = _CACHED_RUNES;
+#else
+    static const size_t table_size = 256;  // FIXME: Don't hardcode this.
+#endif
+    _LIBCPP_ALWAYS_INLINE const mask* table() const  _NOEXCEPT {return __tab_;}
+    static const mask* classic_table()  _NOEXCEPT;
+#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
+    static const int* __classic_upper_table() _NOEXCEPT;
+    static const int* __classic_lower_table() _NOEXCEPT;
+#endif
+#if defined(__NetBSD__)
+    static const short* __classic_upper_table() _NOEXCEPT;
+    static const short* __classic_lower_table() _NOEXCEPT;
+#endif
+
+protected:
+    ~ctype();
+    virtual char_type do_toupper(char_type __c) const;
+    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
+    virtual char_type do_tolower(char_type __c) const;
+    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
+    virtual char_type do_widen(char __c) const;
+    virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
+    virtual char do_narrow(char_type __c, char __dfault) const;
+    virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
+};
+
+// template <class CharT> class ctype_byname;
+
+template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype_byname;
+
+template <>
+class _LIBCPP_TYPE_VIS ctype_byname<char>
+    : public ctype<char>
+{
+    locale_t __l;
+
+public:
+    explicit ctype_byname(const char*, size_t = 0);
+    explicit ctype_byname(const string&, size_t = 0);
+
+protected:
+    ~ctype_byname();
+    virtual char_type do_toupper(char_type) const;
+    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
+    virtual char_type do_tolower(char_type) const;
+    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
+};
+
+template <>
+class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
+    : public ctype<wchar_t>
+{
+    locale_t __l;
+
+public:
+    explicit ctype_byname(const char*, size_t = 0);
+    explicit ctype_byname(const string&, size_t = 0);
+
+protected:
+    ~ctype_byname();
+    virtual bool do_is(mask __m, char_type __c) const;
+    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
+    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
+    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
+    virtual char_type do_toupper(char_type) const;
+    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
+    virtual char_type do_tolower(char_type) const;
+    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
+    virtual char_type do_widen(char) const;
+    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
+    virtual char do_narrow(char_type, char __dfault) const;
+    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
+};
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isspace(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isprint(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+iscntrl(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isupper(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+islower(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isalpha(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isdigit(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+ispunct(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isxdigit(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isalnum(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+isgraph(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT
+toupper(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).toupper(__c);
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT
+tolower(_CharT __c, const locale& __loc)
+{
+    return use_facet<ctype<_CharT> >(__loc).tolower(__c);
+}
+
+// codecvt_base
+
+class _LIBCPP_TYPE_VIS codecvt_base
+{
+public:
+    _LIBCPP_ALWAYS_INLINE codecvt_base() {}
+    enum result {ok, partial, error, noconv};
+};
+
+// template <class internT, class externT, class stateT> class codecvt;
+
+template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
+
+// template <> class codecvt<char, char, mbstate_t>
+
+template <>
+class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
+    : public locale::facet,
+      public codecvt_base
+{
+public:
+    typedef char      intern_type;
+    typedef char      extern_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result out(state_type& __st,
+               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result unshift(state_type& __st,
+                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_unshift(__st, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result in(state_type& __st,
+              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
+    {
+        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int encoding() const  _NOEXCEPT
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const  _NOEXCEPT
+    {
+        return do_always_noconv();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
+    {
+        return do_length(__st, __frm, __end, __mx);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int max_length() const  _NOEXCEPT
+    {
+        return do_max_length();
+    }
+
+    static locale::id id;
+
+protected:
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(const char*, size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    ~codecvt();
+
+    virtual result do_out(state_type& __st,
+                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual result do_in(state_type& __st,
+                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
+    virtual result do_unshift(state_type& __st,
+                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual int do_encoding() const  _NOEXCEPT;
+    virtual bool do_always_noconv() const  _NOEXCEPT;
+    virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const  _NOEXCEPT;
+};
+
+// template <> class codecvt<wchar_t, char, mbstate_t>
+
+template <>
+class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
+    : public locale::facet,
+      public codecvt_base
+{
+    locale_t __l;
+public:
+    typedef wchar_t   intern_type;
+    typedef char      extern_type;
+    typedef mbstate_t state_type;
+
+    explicit codecvt(size_t __refs = 0);
+
+    _LIBCPP_ALWAYS_INLINE
+    result out(state_type& __st,
+               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result unshift(state_type& __st,
+                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_unshift(__st, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result in(state_type& __st,
+              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
+    {
+        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int encoding() const  _NOEXCEPT
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const  _NOEXCEPT
+    {
+        return do_always_noconv();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
+    {
+        return do_length(__st, __frm, __end, __mx);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int max_length() const  _NOEXCEPT
+    {
+        return do_max_length();
+    }
+
+    static locale::id id;
+
+protected:
+    explicit codecvt(const char*, size_t __refs = 0);
+
+    ~codecvt();
+
+    virtual result do_out(state_type& __st,
+                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual result do_in(state_type& __st,
+                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
+    virtual result do_unshift(state_type& __st,
+                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual int do_encoding() const  _NOEXCEPT;
+    virtual bool do_always_noconv() const  _NOEXCEPT;
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const  _NOEXCEPT;
+};
+
+// template <> class codecvt<char16_t, char, mbstate_t>
+
+template <>
+class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
+    : public locale::facet,
+      public codecvt_base
+{
+public:
+    typedef char16_t  intern_type;
+    typedef char      extern_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result out(state_type& __st,
+               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result unshift(state_type& __st,
+                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_unshift(__st, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result in(state_type& __st,
+              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
+    {
+        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int encoding() const  _NOEXCEPT
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const  _NOEXCEPT
+    {
+        return do_always_noconv();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
+    {
+        return do_length(__st, __frm, __end, __mx);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int max_length() const  _NOEXCEPT
+    {
+        return do_max_length();
+    }
+
+    static locale::id id;
+
+protected:
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(const char*, size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    ~codecvt();
+
+    virtual result do_out(state_type& __st,
+                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual result do_in(state_type& __st,
+                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
+    virtual result do_unshift(state_type& __st,
+                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual int do_encoding() const  _NOEXCEPT;
+    virtual bool do_always_noconv() const  _NOEXCEPT;
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const  _NOEXCEPT;
+};
+
+// template <> class codecvt<char32_t, char, mbstate_t>
+
+template <>
+class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
+    : public locale::facet,
+      public codecvt_base
+{
+public:
+    typedef char32_t  intern_type;
+    typedef char      extern_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result out(state_type& __st,
+               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result unshift(state_type& __st,
+                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
+    {
+        return do_unshift(__st, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result in(state_type& __st,
+              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
+    {
+        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int encoding() const  _NOEXCEPT
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const  _NOEXCEPT
+    {
+        return do_always_noconv();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
+    {
+        return do_length(__st, __frm, __end, __mx);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int max_length() const  _NOEXCEPT
+    {
+        return do_max_length();
+    }
+
+    static locale::id id;
+
+protected:
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt(const char*, size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    ~codecvt();
+
+    virtual result do_out(state_type& __st,
+                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
+                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual result do_in(state_type& __st,
+                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
+                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
+    virtual result do_unshift(state_type& __st,
+                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
+    virtual int do_encoding() const  _NOEXCEPT;
+    virtual bool do_always_noconv() const  _NOEXCEPT;
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const  _NOEXCEPT;
+};
+
+// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
+
+template <class _InternT, class _ExternT, class _StateT>
+class _LIBCPP_TYPE_VIS_ONLY codecvt_byname
+    : public codecvt<_InternT, _ExternT, _StateT>
+{
+public:
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
+        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
+    _LIBCPP_ALWAYS_INLINE
+    explicit codecvt_byname(const string& __nm, size_t __refs = 0)
+        : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
+protected:
+    ~codecvt_byname();
+};
+
+template <class _InternT, class _ExternT, class _StateT>
+codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
+{
+}
+
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
+
+_LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
+
+template <size_t _Np>
+struct __narrow_to_utf8
+{
+    template <class _OutputIterator, class _CharT>
+    _OutputIterator
+    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
+};
+
+template <>
+struct __narrow_to_utf8<8>
+{
+    template <class _OutputIterator, class _CharT>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
+    {
+        for (; __wb < __we; ++__wb, ++__s)
+            *__s = *__wb;
+        return __s;
+    }
+};
+
+template <>
+struct __narrow_to_utf8<16>
+    : public codecvt<char16_t, char, mbstate_t>
+{
+    _LIBCPP_ALWAYS_INLINE
+    __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
+
+    ~__narrow_to_utf8();
+
+    template <class _OutputIterator, class _CharT>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
+    {
+        result __r = ok;
+        mbstate_t __mb;
+        while (__wb < __we && __r != error)
+        {
+            const int __sz = 32;
+            char __buf[__sz];
+            char* __bn;
+            const char16_t* __wn = (const char16_t*)__wb;
+            __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
+                         __buf, __buf+__sz, __bn);
+            if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
+                __throw_runtime_error("locale not supported");
+            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
+                *__s = *__p;
+            __wb = (const _CharT*)__wn;
+        }
+        return __s;
+    }
+};
+
+template <>
+struct __narrow_to_utf8<32>
+    : public codecvt<char32_t, char, mbstate_t>
+{
+    _LIBCPP_ALWAYS_INLINE
+    __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
+
+    ~__narrow_to_utf8();
+
+    template <class _OutputIterator, class _CharT>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
+    {
+        result __r = ok;
+        mbstate_t __mb;
+        while (__wb < __we && __r != error)
+        {
+            const int __sz = 32;
+            char __buf[__sz];
+            char* __bn;
+            const char32_t* __wn = (const char32_t*)__wb;
+            __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
+                         __buf, __buf+__sz, __bn);
+            if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
+                __throw_runtime_error("locale not supported");
+            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
+                *__s = *__p;
+            __wb = (const _CharT*)__wn;
+        }
+        return __s;
+    }
+};
+
+template <size_t _Np>
+struct __widen_from_utf8
+{
+    template <class _OutputIterator>
+    _OutputIterator
+    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
+};
+
+template <>
+struct __widen_from_utf8<8>
+{
+    template <class _OutputIterator>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
+    {
+        for (; __nb < __ne; ++__nb, ++__s)
+            *__s = *__nb;
+        return __s;
+    }
+};
+
+template <>
+struct __widen_from_utf8<16>
+    : public codecvt<char16_t, char, mbstate_t>
+{
+    _LIBCPP_ALWAYS_INLINE
+    __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
+
+    ~__widen_from_utf8();
+
+    template <class _OutputIterator>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
+    {
+        result __r = ok;
+        mbstate_t __mb;
+        while (__nb < __ne && __r != error)
+        {
+            const int __sz = 32;
+            char16_t __buf[__sz];
+            char16_t* __bn;
+            const char* __nn = __nb;
+            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
+                        __buf, __buf+__sz, __bn);
+            if (__r == codecvt_base::error || __nn == __nb)
+                __throw_runtime_error("locale not supported");
+            for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
+                *__s = (wchar_t)*__p;
+            __nb = __nn;
+        }
+        return __s;
+    }
+};
+
+template <>
+struct __widen_from_utf8<32>
+    : public codecvt<char32_t, char, mbstate_t>
+{
+    _LIBCPP_ALWAYS_INLINE
+    __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
+
+    ~__widen_from_utf8();
+
+    template <class _OutputIterator>
+    _LIBCPP_ALWAYS_INLINE
+    _OutputIterator
+    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
+    {
+        result __r = ok;
+        mbstate_t __mb;
+        while (__nb < __ne && __r != error)
+        {
+            const int __sz = 32;
+            char32_t __buf[__sz];
+            char32_t* __bn;
+            const char* __nn = __nb;
+            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
+                        __buf, __buf+__sz, __bn);
+            if (__r == codecvt_base::error || __nn == __nb)
+                __throw_runtime_error("locale not supported");
+            for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
+                *__s = (wchar_t)*__p;
+            __nb = __nn;
+        }
+        return __s;
+    }
+};
+
+// template <class charT> class numpunct
+
+template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct;
+
+template <>
+class _LIBCPP_TYPE_VIS numpunct<char>
+    : public locale::facet
+{
+public:
+    typedef char char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit numpunct(size_t __refs = 0);
+
+    _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
+    _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
+    _LIBCPP_ALWAYS_INLINE string grouping() const         {return do_grouping();}
+    _LIBCPP_ALWAYS_INLINE string_type truename() const    {return do_truename();}
+    _LIBCPP_ALWAYS_INLINE string_type falsename() const   {return do_falsename();}
+
+    static locale::id id;
+
+protected:
+    ~numpunct();
+    virtual char_type do_decimal_point() const;
+    virtual char_type do_thousands_sep() const;
+    virtual string do_grouping() const;
+    virtual string_type do_truename() const;
+    virtual string_type do_falsename() const;
+
+    char_type __decimal_point_;
+    char_type __thousands_sep_;
+    string __grouping_;
+};
+
+template <>
+class _LIBCPP_TYPE_VIS numpunct<wchar_t>
+    : public locale::facet
+{
+public:
+    typedef wchar_t char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit numpunct(size_t __refs = 0);
+
+    _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
+    _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
+    _LIBCPP_ALWAYS_INLINE string grouping() const         {return do_grouping();}
+    _LIBCPP_ALWAYS_INLINE string_type truename() const    {return do_truename();}
+    _LIBCPP_ALWAYS_INLINE string_type falsename() const   {return do_falsename();}
+
+    static locale::id id;
+
+protected:
+    ~numpunct();
+    virtual char_type do_decimal_point() const;
+    virtual char_type do_thousands_sep() const;
+    virtual string do_grouping() const;
+    virtual string_type do_truename() const;
+    virtual string_type do_falsename() const;
+
+    char_type __decimal_point_;
+    char_type __thousands_sep_;
+    string __grouping_;
+};
+
+// template <class charT> class numpunct_byname
+
+template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct_byname;
+
+template <>
+class _LIBCPP_TYPE_VIS numpunct_byname<char>
+: public numpunct<char>
+{
+public:
+    typedef char char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
+    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
+
+protected:
+    ~numpunct_byname();
+
+private:
+    void __init(const char*);
+};
+
+template <>
+class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
+: public numpunct<wchar_t>
+{
+public:
+    typedef wchar_t char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
+    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
+
+protected:
+    ~numpunct_byname();
+
+private:
+    void __init(const char*);
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___LOCALE
diff --git a/rc1/include/__mutex_base b/rc1/include/__mutex_base
new file mode 100644
index 0000000..d5ece7c
--- /dev/null
+++ b/rc1/include/__mutex_base
@@ -0,0 +1,407 @@
+// -*- 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___MUTEX_BASE
+#define _LIBCPP___MUTEX_BASE
+
+#include <__config>
+#include <chrono>
+#include <system_error>
+#include <pthread.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+class _LIBCPP_TYPE_VIS mutex
+{
+    pthread_mutex_t __m_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+     constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
+#else
+     mutex() _NOEXCEPT {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
+#endif
+     ~mutex();
+
+private:
+    mutex(const mutex&);// = delete;
+    mutex& operator=(const mutex&);// = delete;
+
+public:
+    void lock();
+    bool try_lock() _NOEXCEPT;
+    void unlock() _NOEXCEPT;
+
+    typedef pthread_mutex_t* native_handle_type;
+    _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
+};
+
+struct _LIBCPP_TYPE_VIS defer_lock_t {};
+struct _LIBCPP_TYPE_VIS try_to_lock_t {};
+struct _LIBCPP_TYPE_VIS adopt_lock_t {};
+
+#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MUTEX)
+
+extern const defer_lock_t  defer_lock;
+extern const try_to_lock_t try_to_lock;
+extern const adopt_lock_t  adopt_lock;
+
+#else
+
+constexpr defer_lock_t  defer_lock  = defer_lock_t();
+constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+constexpr adopt_lock_t  adopt_lock  = adopt_lock_t();
+
+#endif
+
+template <class _Mutex>
+class _LIBCPP_TYPE_VIS_ONLY lock_guard
+{
+public:
+    typedef _Mutex mutex_type;
+
+private:
+    mutex_type& __m_;
+public:
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit lock_guard(mutex_type& __m)
+        : __m_(__m) {__m_.lock();}
+    _LIBCPP_INLINE_VISIBILITY
+    lock_guard(mutex_type& __m, adopt_lock_t)
+        : __m_(__m) {}
+    _LIBCPP_INLINE_VISIBILITY
+    ~lock_guard() {__m_.unlock();}
+
+private:
+    lock_guard(lock_guard const&);// = delete;
+    lock_guard& operator=(lock_guard const&);// = delete;
+};
+
+template <class _Mutex>
+class _LIBCPP_TYPE_VIS_ONLY unique_lock
+{
+public:
+    typedef _Mutex mutex_type;
+
+private:
+    mutex_type* __m_;
+    bool __owns_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
+    _LIBCPP_INLINE_VISIBILITY
+    explicit unique_lock(mutex_type& __m)
+        : __m_(&__m), __owns_(true) {__m_->lock();}
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
+        : __m_(&__m), __owns_(false) {}
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock(mutex_type& __m, try_to_lock_t)
+        : __m_(&__m), __owns_(__m.try_lock()) {}
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock(mutex_type& __m, adopt_lock_t)
+        : __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_(&__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_(&__m), __owns_(__m.try_lock_for(__d)) {}
+    _LIBCPP_INLINE_VISIBILITY
+    ~unique_lock()
+    {
+        if (__owns_)
+            __m_->unlock();
+    }
+
+private:
+    unique_lock(unique_lock const&); // = delete;
+    unique_lock& operator=(unique_lock const&); // = delete;
+
+public:
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock(unique_lock&& __u) _NOEXCEPT
+        : __m_(__u.__m_), __owns_(__u.__owns_)
+        {__u.__m_ = nullptr; __u.__owns_ = false;}
+    _LIBCPP_INLINE_VISIBILITY
+    unique_lock& operator=(unique_lock&& __u) _NOEXCEPT
+        {
+            if (__owns_)
+                __m_->unlock();
+            __m_ = __u.__m_;
+            __owns_ = __u.__owns_;
+            __u.__m_ = nullptr;
+            __u.__owns_ = false;
+            return *this;
+        }
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    void lock();
+    bool try_lock();
+
+    template <class _Rep, class _Period>
+        bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
+    template <class _Clock, class _Duration>
+        bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+
+    void unlock();
+
+    _LIBCPP_INLINE_VISIBILITY
+    void swap(unique_lock& __u) _NOEXCEPT
+    {
+        _VSTD::swap(__m_, __u.__m_);
+        _VSTD::swap(__owns_, __u.__owns_);
+    }
+    _LIBCPP_INLINE_VISIBILITY
+    mutex_type* release() _NOEXCEPT
+    {
+        mutex_type* __m = __m_;
+        __m_ = nullptr;
+        __owns_ = false;
+        return __m;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    bool owns_lock() const _NOEXCEPT {return __owns_;}
+    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_EXPLICIT
+        operator bool () const _NOEXCEPT {return __owns_;}
+    _LIBCPP_INLINE_VISIBILITY
+    mutex_type* mutex() const _NOEXCEPT {return __m_;}
+};
+
+template <class _Mutex>
+void
+unique_lock<_Mutex>::lock()
+{
+    if (__m_ == nullptr)
+        __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
+    if (__owns_)
+        __throw_system_error(EDEADLK, "unique_lock::lock: already locked");
+    __m_->lock();
+    __owns_ = true;
+}
+
+template <class _Mutex>
+bool
+unique_lock<_Mutex>::try_lock()
+{
+    if (__m_ == nullptr)
+        __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
+    if (__owns_)
+        __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
+    __owns_ = __m_->try_lock();
+    return __owns_;
+}
+
+template <class _Mutex>
+template <class _Rep, class _Period>
+bool
+unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d)
+{
+    if (__m_ == nullptr)
+        __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
+    if (__owns_)
+        __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
+    __owns_ = __m_->try_lock_for(__d);
+    return __owns_;
+}
+
+template <class _Mutex>
+template <class _Clock, class _Duration>
+bool
+unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
+{
+    if (__m_ == nullptr)
+        __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
+    if (__owns_)
+        __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
+    __owns_ = __m_->try_lock_until(__t);
+    return __owns_;
+}
+
+template <class _Mutex>
+void
+unique_lock<_Mutex>::unlock()
+{
+    if (!__owns_)
+        __throw_system_error(EPERM, "unique_lock::unlock: not locked");
+    __m_->unlock();
+    __owns_ = false;
+}
+
+template <class _Mutex>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT
+    {__x.swap(__y);}
+
+//enum class cv_status
+_LIBCPP_DECLARE_STRONG_ENUM(cv_status)
+{
+    no_timeout,
+    timeout
+};
+_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status)
+
+class _LIBCPP_TYPE_VIS condition_variable
+{
+    pthread_cond_t __cv_;
+public:
+    _LIBCPP_INLINE_VISIBILITY
+#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+    constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}
+#else
+    condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
+#endif
+    ~condition_variable();
+
+private:
+    condition_variable(const condition_variable&); // = delete;
+    condition_variable& operator=(const condition_variable&); // = delete;
+
+public:
+    void notify_one() _NOEXCEPT;
+    void notify_all() _NOEXCEPT;
+
+    void wait(unique_lock<mutex>& __lk) _NOEXCEPT;
+    template <class _Predicate>
+        void wait(unique_lock<mutex>& __lk, _Predicate __pred);
+
+    template <class _Clock, class _Duration>
+        cv_status
+        wait_until(unique_lock<mutex>& __lk,
+                   const chrono::time_point<_Clock, _Duration>& __t);
+
+    template <class _Clock, class _Duration, class _Predicate>
+        bool
+        wait_until(unique_lock<mutex>& __lk,
+                   const chrono::time_point<_Clock, _Duration>& __t,
+                   _Predicate __pred);
+
+    template <class _Rep, class _Period>
+        cv_status
+        wait_for(unique_lock<mutex>& __lk,
+                 const chrono::duration<_Rep, _Period>& __d);
+
+    template <class _Rep, class _Period, class _Predicate>
+        bool
+        wait_for(unique_lock<mutex>& __lk,
+                 const chrono::duration<_Rep, _Period>& __d,
+                 _Predicate __pred);
+
+    typedef pthread_cond_t* native_handle_type;
+    _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;}
+
+private:
+    void __do_timed_wait(unique_lock<mutex>& __lk,
+       chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
+};
+#endif // !_LIBCPP_HAS_NO_THREADS
+
+template <class _To, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    chrono::__is_duration<_To>::value,
+    _To
+>::type
+__ceil(chrono::duration<_Rep, _Period> __d)
+{
+    using namespace chrono;
+    _To __r = duration_cast<_To>(__d);
+    if (__r < __d)
+        ++__r;
+    return __r;
+}
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+template <class _Predicate>
+void
+condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred)
+{
+    while (!__pred())
+        wait(__lk);
+}
+
+template <class _Clock, class _Duration>
+cv_status
+condition_variable::wait_until(unique_lock<mutex>& __lk,
+                               const chrono::time_point<_Clock, _Duration>& __t)
+{
+    using namespace chrono;
+    wait_for(__lk, __t - _Clock::now());
+    return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
+}
+
+template <class _Clock, class _Duration, class _Predicate>
+bool
+condition_variable::wait_until(unique_lock<mutex>& __lk,
+                   const chrono::time_point<_Clock, _Duration>& __t,
+                   _Predicate __pred)
+{
+    while (!__pred())
+    {
+        if (wait_until(__lk, __t) == cv_status::timeout)
+            return __pred();
+    }
+    return true;
+}
+
+template <class _Rep, class _Period>
+cv_status
+condition_variable::wait_for(unique_lock<mutex>& __lk,
+                             const chrono::duration<_Rep, _Period>& __d)
+{
+    using namespace chrono;
+    if (__d <= __d.zero())
+        return cv_status::timeout;
+    typedef time_point<system_clock, duration<long double, nano> > __sys_tpf;
+    typedef time_point<system_clock, nanoseconds> __sys_tpi;
+    __sys_tpf _Max = __sys_tpi::max();
+    system_clock::time_point __s_now = system_clock::now();
+    steady_clock::time_point __c_now = steady_clock::now();
+    if (_Max - __d > __s_now)
+        __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));
+    else
+        __do_timed_wait(__lk, __sys_tpi::max());
+    return steady_clock::now() - __c_now < __d ? cv_status::no_timeout :
+                                                 cv_status::timeout;
+}
+
+template <class _Rep, class _Period, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+condition_variable::wait_for(unique_lock<mutex>& __lk,
+                             const chrono::duration<_Rep, _Period>& __d,
+                             _Predicate __pred)
+{
+    return wait_until(__lk, chrono::steady_clock::now() + __d,
+                      _VSTD::move(__pred));
+}
+
+#endif // !_LIBCPP_HAS_NO_THREADS
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___MUTEX_BASE
diff --git a/rc1/include/__refstring b/rc1/include/__refstring
new file mode 100644
index 0000000..6866bf1
--- /dev/null
+++ b/rc1/include/__refstring
@@ -0,0 +1,139 @@
+//===------------------------ __refstring ---------------------------------===//
+//
+//                     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___REFSTRING
+#define _LIBCPP___REFSTRING
+
+#include <__config>
+#include <cstddef>
+#include <cstring>
+#if __APPLE__
+#include <dlfcn.h>
+#include <mach-o/dyld.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_HIDDEN __libcpp_refstring
+{
+private:
+    const char* str_;
+
+    typedef int count_t;
+
+    struct _Rep_base
+    {
+        std::size_t len;
+        std::size_t cap;
+        count_t     count;
+    };
+
+    static
+    _Rep_base*
+    rep_from_data(const char *data_) _NOEXCEPT
+    {
+        char *data = const_cast<char *>(data_);
+        return reinterpret_cast<_Rep_base *>(data - sizeof(_Rep_base));
+    }
+    static
+    char *
+    data_from_rep(_Rep_base *rep) _NOEXCEPT
+    {
+        char *data = reinterpret_cast<char *>(rep);
+        return data + sizeof(*rep);
+    }
+
+#if __APPLE__
+    static
+    const char*
+    compute_gcc_empty_string_storage() _NOEXCEPT
+    {
+        void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
+        if (handle == nullptr)
+            return nullptr;
+        void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
+        if (sym == nullptr)
+            return nullptr;
+        return data_from_rep(reinterpret_cast<_Rep_base *>(sym));
+    }
+
+    static
+    const char*
+    get_gcc_empty_string_storage() _NOEXCEPT
+    {
+        static const char* p = compute_gcc_empty_string_storage();
+        return p;
+    }
+
+    bool
+    uses_refcount() const
+    {
+        return str_ != get_gcc_empty_string_storage();
+    }
+#else
+    bool
+    uses_refcount() const
+    {
+        return true;
+    }
+#endif
+
+public:
+    explicit __libcpp_refstring(const char* msg) {
+        std::size_t len = strlen(msg);
+        _Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1));
+        rep->len = len;
+        rep->cap = len;
+        rep->count = 0;
+        char *data = data_from_rep(rep);
+        std::memcpy(data, msg, len + 1);
+        str_ = data;
+    }
+
+    __libcpp_refstring(const __libcpp_refstring& s) _NOEXCEPT : str_(s.str_)
+    {
+        if (uses_refcount())
+            __sync_add_and_fetch(&rep_from_data(str_)->count, 1);
+    }
+
+    __libcpp_refstring& operator=(const __libcpp_refstring& s) _NOEXCEPT
+    {
+        bool adjust_old_count = uses_refcount();
+        struct _Rep_base *old_rep = rep_from_data(str_);
+        str_ = s.str_;
+        if (uses_refcount())
+            __sync_add_and_fetch(&rep_from_data(str_)->count, 1);
+        if (adjust_old_count)
+        {
+            if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+            {
+                ::operator delete(old_rep);
+            }
+        }
+        return *this;
+    }
+
+    ~__libcpp_refstring()
+    {
+        if (uses_refcount())
+        {
+            _Rep_base* rep = rep_from_data(str_);
+            if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0)
+            {
+                ::operator delete(rep);
+            }
+        }
+    }
+
+    const char* c_str() const _NOEXCEPT {return str_;}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif //_LIBCPP___REFSTRING
diff --git a/rc1/include/__split_buffer b/rc1/include/__split_buffer
new file mode 100644
index 0000000..1d529cb
--- /dev/null
+++ b/rc1/include/__split_buffer
@@ -0,0 +1,654 @@
+// -*- C++ -*-
+#ifndef _LIBCPP_SPLIT_BUFFER
+#define _LIBCPP_SPLIT_BUFFER
+
+#include <__config>
+#include <type_traits>
+#include <algorithm>
+
+#include <__undef_min_max>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <bool>
+class __split_buffer_common
+{
+protected:
+    void __throw_length_error() const;
+    void __throw_out_of_range() const;
+};
+
+template <class _Tp, class _Allocator = allocator<_Tp> >
+struct __split_buffer
+    : private __split_buffer_common<true>
+{
+private:
+    __split_buffer(const __split_buffer&);
+    __split_buffer& operator=(const __split_buffer&);
+public:
+    typedef _Tp                                             value_type;
+    typedef _Allocator                                      allocator_type;
+    typedef typename remove_reference<allocator_type>::type __alloc_rr;
+    typedef allocator_traits<__alloc_rr>                    __alloc_traits;
+    typedef value_type&                                     reference;
+    typedef const value_type&                               const_reference;
+    typedef typename __alloc_traits::size_type              size_type;
+    typedef typename __alloc_traits::difference_type        difference_type;
+    typedef typename __alloc_traits::pointer                pointer;
+    typedef typename __alloc_traits::const_pointer          const_pointer;
+    typedef pointer                                         iterator;
+    typedef const_pointer                                   const_iterator;
+
+    pointer                                         __first_;
+    pointer                                         __begin_;
+    pointer                                         __end_;
+    __compressed_pair<pointer, allocator_type> __end_cap_;
+
+    typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref;
+    typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref;
+
+    _LIBCPP_INLINE_VISIBILITY __alloc_rr&           __alloc() _NOEXCEPT         {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY const __alloc_rr&     __alloc() const _NOEXCEPT   {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY pointer&              __end_cap() _NOEXCEPT       {return __end_cap_.first();}
+    _LIBCPP_INLINE_VISIBILITY const pointer&        __end_cap() const _NOEXCEPT {return __end_cap_.first();}
+
+    __split_buffer()
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
+    explicit __split_buffer(__alloc_rr& __a);
+    explicit __split_buffer(const __alloc_rr& __a);
+    __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
+    ~__split_buffer();
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __split_buffer(__split_buffer&& __c)
+        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
+    __split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
+    __split_buffer& operator=(__split_buffer&& __c)
+        _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
+                is_nothrow_move_assignable<allocator_type>::value) ||
+               !__alloc_traits::propagate_on_container_move_assignment::value);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    _LIBCPP_INLINE_VISIBILITY       iterator begin() _NOEXCEPT       {return __begin_;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;}
+    _LIBCPP_INLINE_VISIBILITY       iterator end() _NOEXCEPT         {return __end_;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT   {return __end_;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void clear() _NOEXCEPT
+        {__destruct_at_end(__begin_);}
+    _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);}
+    _LIBCPP_INLINE_VISIBILITY bool empty()     const {return __end_ == __begin_;}
+    _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);}
+    _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);}
+    _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);}
+
+    _LIBCPP_INLINE_VISIBILITY       reference front()       {return *__begin_;}
+    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;}
+    _LIBCPP_INLINE_VISIBILITY       reference back()        {return *(__end_ - 1);}
+    _LIBCPP_INLINE_VISIBILITY const_reference back() const  {return *(__end_ - 1);}
+
+    void reserve(size_type __n);
+    void shrink_to_fit() _NOEXCEPT;
+    void push_front(const_reference __x);
+    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
+    void push_front(value_type&& __x);
+    void push_back(value_type&& __x);
+#if !defined(_LIBCPP_HAS_NO_VARIADICS)
+    template <class... _Args>
+        void emplace_back(_Args&&... __args);
+#endif  // !defined(_LIBCPP_HAS_NO_VARIADICS)
+#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
+
+    _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);}
+    _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);}
+
+    void __construct_at_end(size_type __n);
+    void __construct_at_end(size_type __n, const_reference __x);
+    template <class _InputIter>
+        typename enable_if
+        <
+            __is_input_iterator<_InputIter>::value &&
+           !__is_forward_iterator<_InputIter>::value,
+            void
+        >::type
+        __construct_at_end(_InputIter __first, _InputIter __last);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            void
+        >::type
+        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
+
+    _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
+        {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());}
+        void __destruct_at_begin(pointer __new_begin, false_type);
+        void __destruct_at_begin(pointer __new_begin, true_type);
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __destruct_at_end(pointer __new_last) _NOEXCEPT
+        {__destruct_at_end(__new_last, false_type());}
+    _LIBCPP_INLINE_VISIBILITY
+        void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT;
+    _LIBCPP_INLINE_VISIBILITY
+        void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT;
+
+    void swap(__split_buffer& __x)
+        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
+                   __is_nothrow_swappable<__alloc_rr>::value);
+
+    bool __invariants() const;
+
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__split_buffer& __c, true_type)
+        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
+        {
+            __alloc() = _VSTD::move(__c.__alloc());
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
+        {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y)
+        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
+                   __is_nothrow_swappable<__alloc_rr>::value)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_swap::value>());}
+
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, true_type)
+        _NOEXCEPT_(__is_nothrow_swappable<__alloc_rr>::value)
+        {
+            using _VSTD::swap;
+            swap(__x, __y);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__alloc_rr&, __alloc_rr&, false_type) _NOEXCEPT
+        {}
+};
+
+template <class _Tp, class _Allocator>
+bool
+__split_buffer<_Tp, _Allocator>::__invariants() const
+{
+    if (__first_ == nullptr)
+    {
+        if (__begin_ != nullptr)
+            return false;
+        if (__end_ != nullptr)
+            return false;
+        if (__end_cap() != nullptr)
+            return false;
+    }
+    else
+    {
+        if (__begin_ < __first_)
+            return false;
+        if (__end_ < __begin_)
+            return false;
+        if (__end_cap() < __end_)
+            return false;
+    }
+    return true;
+}
+
+//  Default constructs __n objects starting at __end_
+//  throws if construction throws
+//  Precondition:  __n > 0
+//  Precondition:  size() + __n <= capacity()
+//  Postcondition:  size() == size() + __n
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
+{
+    __alloc_rr& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+//  Copy constructs __n objects starting at __end_ from __x
+//  throws if construction throws
+//  Precondition:  __n > 0
+//  Precondition:  size() + __n <= capacity()
+//  Postcondition:  size() == old size() + __n
+//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
+{
+    __alloc_rr& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIter>
+typename enable_if
+<
+     __is_input_iterator<_InputIter>::value &&
+    !__is_forward_iterator<_InputIter>::value,
+    void
+>::type
+__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last)
+{
+    __alloc_rr& __a = this->__alloc();
+    for (; __first != __last; ++__first)
+    {
+        if (__end_ == __end_cap())
+        {
+            size_type __old_cap = __end_cap() - __first_;
+            size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8);
+            __split_buffer __buf(__new_cap, 0, __a);
+            for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_)
+                __alloc_traits::construct(__buf.__alloc(),
+                        _VSTD::__to_raw_pointer(__buf.__end_), _VSTD::move(*__p));
+            swap(__buf);
+        }
+        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
+        ++this->__end_;
+    }
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    void
+>::type
+__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
+{
+    __alloc_rr& __a = this->__alloc();
+    for (; __first != __last; ++__first)
+    {
+        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
+        ++this->__end_;
+    }
+}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
+{
+    while (__begin_ != __new_begin)
+        __alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++));
+}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
+{
+    __begin_ = __new_begin;
+}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
+{
+    while (__new_last != __end_)
+        __alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_));
+}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT
+{
+    __end_ = __new_last;
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
+    : __end_cap_(nullptr, __a)
+{
+    __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
+    __begin_ = __end_ = __first_ + __start;
+    __end_cap() = __first_ + __cap;
+}
+
+template <class _Tp, class _Allocator>
+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)
+{
+}
+
+template <class _Tp, class _Allocator>
+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 _LIBCPP_INLINE_VISIBILITY
+__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
+    : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
+{
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::~__split_buffer()
+{
+    clear();
+    if (__first_)
+        __alloc_traits::deallocate(__alloc(), __first_, capacity());
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
+    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
+    : __first_(_VSTD::move(__c.__first_)),
+      __begin_(_VSTD::move(__c.__begin_)),
+      __end_(_VSTD::move(__c.__end_)),
+      __end_cap_(_VSTD::move(__c.__end_cap_))
+{
+    __c.__first_ = nullptr;
+    __c.__begin_ = nullptr;
+    __c.__end_ = nullptr;
+    __c.__end_cap() = nullptr;
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
+    : __end_cap_(__a)
+{
+    if (__a == __c.__alloc())
+    {
+        __first_ = __c.__first_;
+        __begin_ = __c.__begin_;
+        __end_ = __c.__end_;
+        __end_cap() = __c.__end_cap();
+        __c.__first_ = nullptr;
+        __c.__begin_ = nullptr;
+        __c.__end_ = nullptr;
+        __c.__end_cap() = nullptr;
+    }
+    else
+    {
+        size_type __cap = __c.size();
+        __first_ = __alloc_traits::allocate(__alloc(), __cap);
+        __begin_ = __end_ = __first_;
+        __end_cap() = __first_ + __cap;
+        typedef move_iterator<iterator> _Ip;
+        __construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
+    }
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>&
+__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
+    _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
+                is_nothrow_move_assignable<allocator_type>::value) ||
+               !__alloc_traits::propagate_on_container_move_assignment::value)
+{
+    clear();
+    shrink_to_fit();
+    __first_ = __c.__first_;
+    __begin_ = __c.__begin_;
+    __end_ = __c.__end_;
+    __end_cap() = __c.__end_cap();
+    __move_assign_alloc(__c,
+        integral_constant<bool,
+                          __alloc_traits::propagate_on_container_move_assignment::value>());
+    __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
+    return *this;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
+        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
+                   __is_nothrow_swappable<__alloc_rr>::value)
+{
+    _VSTD::swap(__first_, __x.__first_);
+    _VSTD::swap(__begin_, __x.__begin_);
+    _VSTD::swap(__end_, __x.__end_);
+    _VSTD::swap(__end_cap(), __x.__end_cap());
+    __swap_alloc(__alloc(), __x.__alloc());
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::reserve(size_type __n)
+{
+    if (__n < capacity())
+    {
+        __split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc());
+        __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                               move_iterator<pointer>(__end_));
+        _VSTD::swap(__first_, __t.__first_);
+        _VSTD::swap(__begin_, __t.__begin_);
+        _VSTD::swap(__end_, __t.__end_);
+        _VSTD::swap(__end_cap(), __t.__end_cap());
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
+{
+    if (capacity() > size())
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            __t.__end_ = __t.__begin_ + (__end_ - __begin_);
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::push_front(const_reference __x)
+{
+    if (__begin_ == __first_)
+    {
+        if (__end_ < __end_cap())
+        {
+            difference_type __d = __end_cap() - __end_;
+            __d = (__d + 1) / 2;
+            __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
+            __end_ += __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), __x);
+    --__begin_;
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x)
+{
+    if (__begin_ == __first_)
+    {
+        if (__end_ < __end_cap())
+        {
+            difference_type __d = __end_cap() - __end_;
+            __d = (__d + 1) / 2;
+            __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
+            __end_ += __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1),
+            _VSTD::move(__x));
+    --__begin_;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__split_buffer<_Tp, _Allocator>::push_back(const_reference __x)
+{
+    if (__end_ == __end_cap())
+    {
+        if (__begin_ > __first_)
+        {
+            difference_type __d = __begin_ - __first_;
+            __d = (__d + 1) / 2;
+            __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), __x);
+    ++__end_;
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x)
+{
+    if (__end_ == __end_cap())
+    {
+        if (__begin_ > __first_)
+        {
+            difference_type __d = __begin_ - __first_;
+            __d = (__d + 1) / 2;
+            __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_),
+            _VSTD::move(__x));
+    ++__end_;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+void
+__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args)
+{
+    if (__end_ == __end_cap())
+    {
+        if (__begin_ > __first_)
+        {
+            difference_type __d = __begin_ - __first_;
+            __d = (__d + 1) / 2;
+            __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _VSTD::swap(__first_, __t.__first_);
+            _VSTD::swap(__begin_, __t.__begin_);
+            _VSTD::swap(__end_, __t.__end_);
+            _VSTD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_),
+                              _VSTD::forward<_Args>(__args)...);
+    ++__end_;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y)
+        _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
+{
+    __x.swap(__y);
+}
+
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_SPLIT_BUFFER
diff --git a/rc1/include/__sso_allocator b/rc1/include/__sso_allocator
new file mode 100644
index 0000000..645f2ba
--- /dev/null
+++ b/rc1/include/__sso_allocator
@@ -0,0 +1,77 @@
+// -*- 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___SSO_ALLOCATOR
+#define _LIBCPP___SSO_ALLOCATOR
+
+#include <__config>
+#include <type_traits>
+#include <new>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, size_t _Np> class _LIBCPP_HIDDEN __sso_allocator;
+
+template <size_t _Np>
+class _LIBCPP_HIDDEN __sso_allocator<void, _Np>
+{
+public:
+    typedef const void*       const_pointer;
+    typedef void              value_type;
+};
+
+template <class _Tp, size_t _Np>
+class _LIBCPP_HIDDEN __sso_allocator
+{
+    typename aligned_storage<sizeof(_Tp) * _Np>::type buf_;
+    bool __allocated_;
+public:
+    typedef size_t            size_type;
+    typedef _Tp*              pointer;
+    typedef _Tp               value_type;
+
+    _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
+    _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
+         : __allocated_(false) {}
+private:
+    __sso_allocator& operator=(const __sso_allocator&);
+public:
+    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = 0)
+    {
+        if (!__allocated_ && __n <= _Np)
+        {
+            __allocated_ = true;
+            return (pointer)&buf_;
+        }
+        return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
+    }
+    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
+    {
+        if (__p == (pointer)&buf_)
+            __allocated_ = false;
+        else
+            _VSTD::__deallocate(__p);
+    }
+    _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
+
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___SSO_ALLOCATOR
diff --git a/rc1/include/__std_stream b/rc1/include/__std_stream
new file mode 100644
index 0000000..5403ada
--- /dev/null
+++ b/rc1/include/__std_stream
@@ -0,0 +1,359 @@
+// -*- 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___STD_STREAM
+#define _LIBCPP___STD_STREAM
+
+#include <__config>
+#include <ostream>
+#include <istream>
+#include <__locale>
+#include <cstdio>
+
+#include <__undef_min_max>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+static const int __limit = 8;
+
+// __stdinbuf
+
+template <class _CharT>
+class _LIBCPP_HIDDEN __stdinbuf
+    : public basic_streambuf<_CharT, char_traits<_CharT> >
+{
+public:
+    typedef _CharT                           char_type;
+    typedef char_traits<char_type>           traits_type;
+    typedef typename traits_type::int_type   int_type;
+    typedef typename traits_type::pos_type   pos_type;
+    typedef typename traits_type::off_type   off_type;
+    typedef typename traits_type::state_type state_type;
+
+    __stdinbuf(FILE* __fp, state_type* __st);
+
+protected:
+    virtual int_type underflow();
+    virtual int_type uflow();
+    virtual int_type pbackfail(int_type __c = traits_type::eof());
+    virtual void imbue(const locale& __loc);
+
+private:
+
+    FILE* __file_;
+    const codecvt<char_type, char, state_type>* __cv_;
+    state_type* __st_;
+    int __encoding_;
+    int_type __last_consumed_;
+    bool __last_consumed_is_next_;
+    bool __always_noconv_;
+
+    __stdinbuf(const __stdinbuf&);
+    __stdinbuf& operator=(const __stdinbuf&);
+
+    int_type __getchar(bool __consume);
+};
+
+template <class _CharT>
+__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st)
+    : __file_(__fp),
+      __st_(__st),
+      __last_consumed_(traits_type::eof()),
+      __last_consumed_is_next_(false)
+{
+    imbue(this->getloc());
+}
+
+template <class _CharT>
+void
+__stdinbuf<_CharT>::imbue(const locale& __loc)
+{
+    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
+    __encoding_ = __cv_->encoding();
+    __always_noconv_ = __cv_->always_noconv();
+    if (__encoding_ > __limit)
+        __throw_runtime_error("unsupported locale for standard input");
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type
+__stdinbuf<_CharT>::underflow()
+{
+    return __getchar(false);
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type
+__stdinbuf<_CharT>::uflow()
+{
+    return __getchar(true);
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type
+__stdinbuf<_CharT>::__getchar(bool __consume)
+{
+    if (__last_consumed_is_next_)
+    {
+        int_type __result = __last_consumed_;
+        if (__consume)
+        {
+            __last_consumed_ = traits_type::eof();
+            __last_consumed_is_next_ = false;
+        }
+        return __result;
+    }
+    char __extbuf[__limit];
+    int __nread = _VSTD::max(1, __encoding_);
+    for (int __i = 0; __i < __nread; ++__i)
+    {
+        int __c = getc(__file_);
+        if (__c == EOF)
+            return traits_type::eof();
+        __extbuf[__i] = static_cast<char>(__c);
+    }
+    char_type __1buf;
+    if (__always_noconv_)
+        __1buf = static_cast<char_type>(__extbuf[0]);
+    else
+    {
+        const char* __enxt;
+        char_type* __inxt;
+        codecvt_base::result __r;
+        do
+        {
+            state_type __sv_st = *__st_;
+            __r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt,
+                                   &__1buf, &__1buf + 1, __inxt);
+            switch (__r)
+            {
+            case _VSTD::codecvt_base::ok:
+                break;
+            case codecvt_base::partial:
+                *__st_ = __sv_st;
+                if (__nread == sizeof(__extbuf))
+                    return traits_type::eof();
+                {
+                    int __c = getc(__file_);
+                    if (__c == EOF)
+                        return traits_type::eof();
+                    __extbuf[__nread] = static_cast<char>(__c);
+                }
+                ++__nread;
+                break;
+            case codecvt_base::error:
+                return traits_type::eof();
+            case _VSTD::codecvt_base::noconv:
+                __1buf = static_cast<char_type>(__extbuf[0]);
+                break;
+            }
+        } while (__r == _VSTD::codecvt_base::partial);
+    }
+    if (!__consume)
+    {
+        for (int __i = __nread; __i > 0;)
+        {
+            if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF)
+                return traits_type::eof();
+        }
+    }
+    else
+        __last_consumed_ = traits_type::to_int_type(__1buf);
+    return traits_type::to_int_type(__1buf);
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type
+__stdinbuf<_CharT>::pbackfail(int_type __c)
+{
+    if (traits_type::eq_int_type(__c, traits_type::eof()))
+    {
+        if (!__last_consumed_is_next_)
+        {
+            __c = __last_consumed_;
+            __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_,
+                                                                 traits_type::eof());
+        }
+        return __c;
+    }
+    if (__last_consumed_is_next_)
+    {
+        char __extbuf[__limit];
+        char* __enxt;
+        const char_type __ci = traits_type::to_char_type(__last_consumed_);
+        const char_type* __inxt;
+        switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt,
+                                  __extbuf, __extbuf + sizeof(__extbuf), __enxt))
+        {
+        case _VSTD::codecvt_base::ok:
+            break;
+        case _VSTD::codecvt_base::noconv:
+            __extbuf[0] = static_cast<char>(__last_consumed_);
+            __enxt = __extbuf + 1;
+            break;
+        case codecvt_base::partial:
+        case codecvt_base::error:
+            return traits_type::eof();
+        }
+        while (__enxt > __extbuf)
+            if (ungetc(*--__enxt, __file_) == EOF)
+                return traits_type::eof();
+    }
+    __last_consumed_ = __c;
+    __last_consumed_is_next_ = true;
+    return __c;
+}
+
+// __stdoutbuf
+
+template <class _CharT>
+class _LIBCPP_HIDDEN __stdoutbuf
+    : public basic_streambuf<_CharT, char_traits<_CharT> >
+{
+public:
+    typedef _CharT                           char_type;
+    typedef char_traits<char_type>           traits_type;
+    typedef typename traits_type::int_type   int_type;
+    typedef typename traits_type::pos_type   pos_type;
+    typedef typename traits_type::off_type   off_type;
+    typedef typename traits_type::state_type state_type;
+
+    __stdoutbuf(FILE* __fp, state_type* __st);
+
+protected:
+    virtual int_type overflow (int_type __c = traits_type::eof());
+    virtual streamsize xsputn(const char_type* __s, streamsize __n);
+    virtual int sync();
+    virtual void imbue(const locale& __loc);
+
+private:
+    FILE* __file_;
+    const codecvt<char_type, char, state_type>* __cv_;
+    state_type* __st_;
+    bool __always_noconv_;
+
+    __stdoutbuf(const __stdoutbuf&);
+    __stdoutbuf& operator=(const __stdoutbuf&);
+};
+
+template <class _CharT>
+__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st)
+    : __file_(__fp),
+      __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
+      __st_(__st),
+      __always_noconv_(__cv_->always_noconv())
+{
+}
+
+template <class _CharT>
+typename __stdoutbuf<_CharT>::int_type
+__stdoutbuf<_CharT>::overflow(int_type __c)
+{
+    char __extbuf[__limit];
+    char_type __1buf;
+    if (!traits_type::eq_int_type(__c, traits_type::eof()))
+    {
+        __1buf = traits_type::to_char_type(__c);
+        if (__always_noconv_)
+        {
+            if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1)
+                return traits_type::eof();
+        }
+        else
+        {
+            char* __extbe = __extbuf;
+            codecvt_base::result __r;
+            char_type* pbase = &__1buf;
+            char_type* pptr = pbase + 1;
+            char_type* epptr = pptr;
+            do
+            {
+                const char_type* __e;
+                __r = __cv_->out(*__st_, pbase, pptr, __e,
+                                        __extbuf,
+                                        __extbuf + sizeof(__extbuf),
+                                        __extbe);
+                if (__e == pbase)
+                    return traits_type::eof();
+                if (__r == codecvt_base::noconv)
+                {
+                    if (fwrite(pbase, 1, 1, __file_) != 1)
+                        return traits_type::eof();
+                }
+                else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
+                {
+                    size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
+                    if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
+                        return traits_type::eof();
+                    if (__r == codecvt_base::partial)
+                    {
+                        pbase = (char_type*)__e;
+                    }
+                }
+                else
+                    return traits_type::eof();
+            } while (__r == codecvt_base::partial);
+        }
+    }
+    return traits_type::not_eof(__c);
+}
+
+template <class _CharT>
+streamsize
+__stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n)
+{
+    if (__always_noconv_)
+        return fwrite(__s, sizeof(char_type), __n, __file_);
+    streamsize __i = 0;
+    for (; __i < __n; ++__i, ++__s)
+        if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
+            break;
+    return __i;
+}
+
+template <class _CharT>
+int
+__stdoutbuf<_CharT>::sync()
+{
+    char __extbuf[__limit];
+    codecvt_base::result __r;
+    do
+    {
+        char* __extbe;
+        __r = __cv_->unshift(*__st_, __extbuf,
+                                    __extbuf + sizeof(__extbuf),
+                                    __extbe);
+        size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
+        if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
+            return -1;
+    } while (__r == codecvt_base::partial);
+    if (__r == codecvt_base::error)
+        return -1;
+    if (fflush(__file_))
+        return -1;
+    return 0;
+}
+
+template <class _CharT>
+void
+__stdoutbuf<_CharT>::imbue(const locale& __loc)
+{
+    sync();
+    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
+    __always_noconv_ = __cv_->always_noconv();
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___STD_STREAM
diff --git a/rc1/include/__tree b/rc1/include/__tree
new file mode 100644
index 0000000..8e5447a
--- /dev/null
+++ b/rc1/include/__tree
@@ -0,0 +1,2309 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TREE
+#define _LIBCPP___TREE
+
+#include <__config>
+#include <iterator>
+#include <memory>
+#include <stdexcept>
+#include <algorithm>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Compare, class _Allocator> class __tree;
+template <class _Tp, class _NodePtr, class _DiffType>
+    class _LIBCPP_TYPE_VIS_ONLY __tree_iterator;
+template <class _Tp, class _ConstNodePtr, class _DiffType>
+    class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+    class _LIBCPP_TYPE_VIS_ONLY map;
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+    class _LIBCPP_TYPE_VIS_ONLY multimap;
+template <class _Key, class _Compare, class _Allocator>
+    class _LIBCPP_TYPE_VIS_ONLY set;
+template <class _Key, class _Compare, class _Allocator>
+    class _LIBCPP_TYPE_VIS_ONLY multiset;
+
+/*
+
+_NodePtr algorithms
+
+The algorithms taking _NodePtr are red black tree algorithms.  Those
+algorithms taking a parameter named __root should assume that __root
+points to a proper red black tree (unless otherwise specified).
+
+Each algorithm herein assumes that __root->__parent_ points to a non-null
+structure which has a member __left_ which points back to __root.  No other
+member is read or written to at __root->__parent_.
+
+__root->__parent_ will be referred to below (in comments only) as end_node.
+end_node->__left_ is an externably accessible lvalue for __root, and can be
+changed by node insertion and removal (without explicit reference to end_node).
+
+All nodes (with the exception of end_node), even the node referred to as
+__root, have a non-null __parent_ field.
+
+*/
+
+// Returns:  true if __x is a left child of its parent, else false
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__tree_is_left_child(_NodePtr __x) _NOEXCEPT
+{
+    return __x == __x->__parent_->__left_;
+}
+
+// Determintes if the subtree rooted at __x is a proper red black subtree.  If
+//    __x is a proper subtree, returns the black height (null counts as 1).  If
+//    __x is an improper subtree, returns 0.
+template <class _NodePtr>
+unsigned
+__tree_sub_invariant(_NodePtr __x)
+{
+    if (__x == nullptr)
+        return 1;
+    // parent consistency checked by caller
+    // check __x->__left_ consistency
+    if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x)
+        return 0;
+    // check __x->__right_ consistency
+    if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x)
+        return 0;
+    // check __x->__left_ != __x->__right_ unless both are nullptr
+    if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr)
+        return 0;
+    // If this is red, neither child can be red
+    if (!__x->__is_black_)
+    {
+        if (__x->__left_ && !__x->__left_->__is_black_)
+            return 0;
+        if (__x->__right_ && !__x->__right_->__is_black_)
+            return 0;
+    }
+    unsigned __h = __tree_sub_invariant(__x->__left_);
+    if (__h == 0)
+        return 0;  // invalid left subtree
+    if (__h != __tree_sub_invariant(__x->__right_))
+        return 0;  // invalid or different height right subtree
+    return __h + __x->__is_black_;  // return black height of this node
+}
+
+// Determintes if the red black tree rooted at __root is a proper red black tree.
+//    __root == nullptr is a proper tree.  Returns true is __root is a proper
+//    red black tree, else returns false.
+template <class _NodePtr>
+bool
+__tree_invariant(_NodePtr __root)
+{
+    if (__root == nullptr)
+        return true;
+    // check __x->__parent_ consistency
+    if (__root->__parent_ == nullptr)
+        return false;
+    if (!__tree_is_left_child(__root))
+        return false;
+    // root must be black
+    if (!__root->__is_black_)
+        return false;
+    // do normal node checks
+    return __tree_sub_invariant(__root) != 0;
+}
+
+// Returns:  pointer to the left-most node under __x.
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+inline _LIBCPP_INLINE_VISIBILITY
+_NodePtr
+__tree_min(_NodePtr __x) _NOEXCEPT
+{
+    while (__x->__left_ != nullptr)
+        __x = __x->__left_;
+    return __x;
+}
+
+// Returns:  pointer to the right-most node under __x.
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+inline _LIBCPP_INLINE_VISIBILITY
+_NodePtr
+__tree_max(_NodePtr __x) _NOEXCEPT
+{
+    while (__x->__right_ != nullptr)
+        __x = __x->__right_;
+    return __x;
+}
+
+// Returns:  pointer to the next in-order node after __x.
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+_NodePtr
+__tree_next(_NodePtr __x) _NOEXCEPT
+{
+    if (__x->__right_ != nullptr)
+        return __tree_min(__x->__right_);
+    while (!__tree_is_left_child(__x))
+        __x = __x->__parent_;
+    return __x->__parent_;
+}
+
+// Returns:  pointer to the previous in-order node before __x.
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+_NodePtr
+__tree_prev(_NodePtr __x) _NOEXCEPT
+{
+    if (__x->__left_ != nullptr)
+        return __tree_max(__x->__left_);
+    while (__tree_is_left_child(__x))
+        __x = __x->__parent_;
+    return __x->__parent_;
+}
+
+// Returns:  pointer to a node which has no children
+// Precondition:  __x != nullptr.
+template <class _NodePtr>
+_NodePtr
+__tree_leaf(_NodePtr __x) _NOEXCEPT
+{
+    while (true)
+    {
+        if (__x->__left_ != nullptr)
+        {
+            __x = __x->__left_;
+            continue;
+        }
+        if (__x->__right_ != nullptr)
+        {
+            __x = __x->__right_;
+            continue;
+        }
+        break;
+    }
+    return __x;
+}
+
+// Effects:  Makes __x->__right_ the subtree root with __x as its left child
+//           while preserving in-order order.
+// Precondition:  __x->__right_ != nullptr
+template <class _NodePtr>
+void
+__tree_left_rotate(_NodePtr __x) _NOEXCEPT
+{
+    _NodePtr __y = __x->__right_;
+    __x->__right_ = __y->__left_;
+    if (__x->__right_ != nullptr)
+        __x->__right_->__parent_ = __x;
+    __y->__parent_ = __x->__parent_;
+    if (__tree_is_left_child(__x))
+        __x->__parent_->__left_ = __y;
+    else
+        __x->__parent_->__right_ = __y;
+    __y->__left_ = __x;
+    __x->__parent_ = __y;
+}
+
+// Effects:  Makes __x->__left_ the subtree root with __x as its right child
+//           while preserving in-order order.
+// Precondition:  __x->__left_ != nullptr
+template <class _NodePtr>
+void
+__tree_right_rotate(_NodePtr __x) _NOEXCEPT
+{
+    _NodePtr __y = __x->__left_;
+    __x->__left_ = __y->__right_;
+    if (__x->__left_ != nullptr)
+        __x->__left_->__parent_ = __x;
+    __y->__parent_ = __x->__parent_;
+    if (__tree_is_left_child(__x))
+        __x->__parent_->__left_ = __y;
+    else
+        __x->__parent_->__right_ = __y;
+    __y->__right_ = __x;
+    __x->__parent_ = __y;
+}
+
+// Effects:  Rebalances __root after attaching __x to a leaf.
+// Precondition:  __root != nulptr && __x != nullptr.
+//                __x has no children.
+//                __x == __root or == a direct or indirect child of __root.
+//                If __x were to be unlinked from __root (setting __root to
+//                  nullptr if __root == __x), __tree_invariant(__root) == true.
+// Postcondition: __tree_invariant(end_node->__left_) == true.  end_node->__left_
+//                may be different than the value passed in as __root.
+template <class _NodePtr>
+void
+__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT
+{
+    __x->__is_black_ = __x == __root;
+    while (__x != __root && !__x->__parent_->__is_black_)
+    {
+        // __x->__parent_ != __root because __x->__parent_->__is_black == false
+        if (__tree_is_left_child(__x->__parent_))
+        {
+            _NodePtr __y = __x->__parent_->__parent_->__right_;
+            if (__y != nullptr && !__y->__is_black_)
+            {
+                __x = __x->__parent_;
+                __x->__is_black_ = true;
+                __x = __x->__parent_;
+                __x->__is_black_ = __x == __root;
+                __y->__is_black_ = true;
+            }
+            else
+            {
+                if (!__tree_is_left_child(__x))
+                {
+                    __x = __x->__parent_;
+                    __tree_left_rotate(__x);
+                }
+                __x = __x->__parent_;
+                __x->__is_black_ = true;
+                __x = __x->__parent_;
+                __x->__is_black_ = false;
+                __tree_right_rotate(__x);
+                break;
+            }
+        }
+        else
+        {
+            _NodePtr __y = __x->__parent_->__parent_->__left_;
+            if (__y != nullptr && !__y->__is_black_)
+            {
+                __x = __x->__parent_;
+                __x->__is_black_ = true;
+                __x = __x->__parent_;
+                __x->__is_black_ = __x == __root;
+                __y->__is_black_ = true;
+            }
+            else
+            {
+                if (__tree_is_left_child(__x))
+                {
+                    __x = __x->__parent_;
+                    __tree_right_rotate(__x);
+                }
+                __x = __x->__parent_;
+                __x->__is_black_ = true;
+                __x = __x->__parent_;
+                __x->__is_black_ = false;
+                __tree_left_rotate(__x);
+                break;
+            }
+        }
+    }
+}
+
+// Precondition:  __root != nullptr && __z != nullptr.
+//                __tree_invariant(__root) == true.
+//                __z == __root or == a direct or indirect child of __root.
+// Effects:  unlinks __z from the tree rooted at __root, rebalancing as needed.
+// Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_
+//                nor any of its children refer to __z.  end_node->__left_
+//                may be different than the value passed in as __root.
+template <class _NodePtr>
+void
+__tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT
+{
+    // __z will be removed from the tree.  Client still needs to destruct/deallocate it
+    // __y is either __z, or if __z has two children, __tree_next(__z).
+    // __y will have at most one child.
+    // __y will be the initial hole in the tree (make the hole at a leaf)
+    _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ?
+                    __z : __tree_next(__z);
+    // __x is __y's possibly null single child
+    _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_;
+    // __w is __x's possibly null uncle (will become __x's sibling)
+    _NodePtr __w = nullptr;
+    // link __x to __y's parent, and find __w
+    if (__x != nullptr)
+        __x->__parent_ = __y->__parent_;
+    if (__tree_is_left_child(__y))
+    {
+        __y->__parent_->__left_ = __x;
+        if (__y != __root)
+            __w = __y->__parent_->__right_;
+        else
+            __root = __x;  // __w == nullptr
+    }
+    else
+    {
+        __y->__parent_->__right_ = __x;
+        // __y can't be root if it is a right child
+        __w = __y->__parent_->__left_;
+    }
+    bool __removed_black = __y->__is_black_;
+    // If we didn't remove __z, do so now by splicing in __y for __z,
+    //    but copy __z's color.  This does not impact __x or __w.
+    if (__y != __z)
+    {
+        // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr
+        __y->__parent_ = __z->__parent_;
+        if (__tree_is_left_child(__z))
+            __y->__parent_->__left_ = __y;
+        else
+            __y->__parent_->__right_ = __y;
+        __y->__left_ = __z->__left_;
+        __y->__left_->__parent_ = __y;
+        __y->__right_ = __z->__right_;
+        if (__y->__right_ != nullptr)
+            __y->__right_->__parent_ = __y;
+        __y->__is_black_ = __z->__is_black_;
+        if (__root == __z)
+            __root = __y;
+    }
+    // There is no need to rebalance if we removed a red, or if we removed
+    //     the last node.
+    if (__removed_black && __root != nullptr)
+    {
+        // Rebalance:
+        // __x has an implicit black color (transferred from the removed __y)
+        //    associated with it, no matter what its color is.
+        // If __x is __root (in which case it can't be null), it is supposed
+        //    to be black anyway, and if it is doubly black, then the double
+        //    can just be ignored.
+        // If __x is red (in which case it can't be null), then it can absorb
+        //    the implicit black just by setting its color to black.
+        // Since __y was black and only had one child (which __x points to), __x
+        //   is either red with no children, else null, otherwise __y would have
+        //   different black heights under left and right pointers.
+        // if (__x == __root || __x != nullptr && !__x->__is_black_)
+        if (__x != nullptr)
+            __x->__is_black_ = true;
+        else
+        {
+            //  Else __x isn't root, and is "doubly black", even though it may
+            //     be null.  __w can not be null here, else the parent would
+            //     see a black height >= 2 on the __x side and a black height
+            //     of 1 on the __w side (__w must be a non-null black or a red
+            //     with a non-null black child).
+            while (true)
+            {
+                if (!__tree_is_left_child(__w))  // if x is left child
+                {
+                    if (!__w->__is_black_)
+                    {
+                        __w->__is_black_ = true;
+                        __w->__parent_->__is_black_ = false;
+                        __tree_left_rotate(__w->__parent_);
+                        // __x is still valid
+                        // reset __root only if necessary
+                        if (__root == __w->__left_)
+                            __root = __w;
+                        // reset sibling, and it still can't be null
+                        __w = __w->__left_->__right_;
+                    }
+                    // __w->__is_black_ is now true, __w may have null children
+                    if ((__w->__left_  == nullptr || __w->__left_->__is_black_) &&
+                        (__w->__right_ == nullptr || __w->__right_->__is_black_))
+                    {
+                        __w->__is_black_ = false;
+                        __x = __w->__parent_;
+                        // __x can no longer be null
+                        if (__x == __root || !__x->__is_black_)
+                        {
+                            __x->__is_black_ = true;
+                            break;
+                        }
+                        // reset sibling, and it still can't be null
+                        __w = __tree_is_left_child(__x) ?
+                                    __x->__parent_->__right_ :
+                                    __x->__parent_->__left_;
+                        // continue;
+                    }
+                    else  // __w has a red child
+                    {
+                        if (__w->__right_ == nullptr || __w->__right_->__is_black_)
+                        {
+                            // __w left child is non-null and red
+                            __w->__left_->__is_black_ = true;
+                            __w->__is_black_ = false;
+                            __tree_right_rotate(__w);
+                            // __w is known not to be root, so root hasn't changed
+                            // reset sibling, and it still can't be null
+                            __w = __w->__parent_;
+                        }
+                        // __w has a right red child, left child may be null
+                        __w->__is_black_ = __w->__parent_->__is_black_;
+                        __w->__parent_->__is_black_ = true;
+                        __w->__right_->__is_black_ = true;
+                        __tree_left_rotate(__w->__parent_);
+                        break;
+                    }
+                }
+                else
+                {
+                    if (!__w->__is_black_)
+                    {
+                        __w->__is_black_ = true;
+                        __w->__parent_->__is_black_ = false;
+                        __tree_right_rotate(__w->__parent_);
+                        // __x is still valid
+                        // reset __root only if necessary
+                        if (__root == __w->__right_)
+                            __root = __w;
+                        // reset sibling, and it still can't be null
+                        __w = __w->__right_->__left_;
+                    }
+                    // __w->__is_black_ is now true, __w may have null children
+                    if ((__w->__left_  == nullptr || __w->__left_->__is_black_) &&
+                        (__w->__right_ == nullptr || __w->__right_->__is_black_))
+                    {
+                        __w->__is_black_ = false;
+                        __x = __w->__parent_;
+                        // __x can no longer be null
+                        if (!__x->__is_black_ || __x == __root)
+                        {
+                            __x->__is_black_ = true;
+                            break;
+                        }
+                        // reset sibling, and it still can't be null
+                        __w = __tree_is_left_child(__x) ?
+                                    __x->__parent_->__right_ :
+                                    __x->__parent_->__left_;
+                        // continue;
+                    }
+                    else  // __w has a red child
+                    {
+                        if (__w->__left_ == nullptr || __w->__left_->__is_black_)
+                        {
+                            // __w right child is non-null and red
+                            __w->__right_->__is_black_ = true;
+                            __w->__is_black_ = false;
+                            __tree_left_rotate(__w);
+                            // __w is known not to be root, so root hasn't changed
+                            // reset sibling, and it still can't be null
+                            __w = __w->__parent_;
+                        }
+                        // __w has a left red child, right child may be null
+                        __w->__is_black_ = __w->__parent_->__is_black_;
+                        __w->__parent_->__is_black_ = true;
+                        __w->__left_->__is_black_ = true;
+                        __tree_right_rotate(__w->__parent_);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+}
+
+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:
+
+    allocator_type& __na_;
+
+    __tree_node_destructor& operator=(const __tree_node_destructor&);
+
+public:
+    bool __value_constructed;
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __tree_node_destructor(allocator_type& __na) _NOEXCEPT
+        : __na_(__na),
+          __value_constructed(false)
+        {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void operator()(pointer __p) _NOEXCEPT
+    {
+        if (__value_constructed)
+            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_));
+        if (__p)
+            __alloc_traits::deallocate(__na_, __p, 1);
+    }
+
+    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 _NodePtr                                              __node_pointer;
+    typedef typename pointer_traits<__node_pointer>::element_type __node;
+    typedef typename __node::base                                 __node_base;
+    typedef typename __node_base::pointer                         __node_base_pointer;
+
+    __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 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
+    : __ptr_(nullptr)
+#endif
+    {}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const
+        {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_iterator& operator++()
+        {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_iterator operator++(int)
+        {__tree_iterator __t(*this); ++(*this); return __t;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_iterator& operator--()
+        {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_iterator operator--(int)
+        {__tree_iterator __t(*this); --(*this); return __t;}
+
+    friend _LIBCPP_INLINE_VISIBILITY 
+        bool operator==(const __tree_iterator& __x, const __tree_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
+    template <class, class, class> friend class __tree;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_iterator;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY set;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multiset;
+};
+
+template <class _Tp, class _ConstNodePtr, class _DiffType>
+class _LIBCPP_TYPE_VIS_ONLY __tree_const_iterator
+{
+    typedef _ConstNodePtr                                         __node_pointer;
+    typedef typename pointer_traits<__node_pointer>::element_type __node;
+    typedef typename __node::base                                 __node_base;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__node_base>
+#else
+            rebind<__node_base>::other
+#endif
+                                                                  __node_base_pointer;
+
+    __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 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
+    : __ptr_(nullptr)
+#endif
+    {}
+
+private:
+    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
+        : __ptr_(__p.__ptr_) {}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const
+        {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_const_iterator& operator++()
+        {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_const_iterator operator++(int)
+        {__tree_const_iterator __t(*this); ++(*this); return __t;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_const_iterator& operator--()
+        {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    _LIBCPP_INLINE_VISIBILITY
+    __tree_const_iterator operator--(int)
+        {__tree_const_iterator __t(*this); --(*this); return __t;}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend _LIBCPP_INLINE_VISIBILITY
+        bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT
+        : __ptr_(__p) {}
+    template <class, class, class> friend class __tree;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY set;
+    template <class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multiset;
+    template <class> friend class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator;
+};
+
+template <class _Tp, class _Compare, class _Allocator>
+class __tree
+{
+public:
+    typedef _Tp                                      value_type;
+    typedef _Compare                                 value_compare;
+    typedef _Allocator                               allocator_type;
+    typedef allocator_traits<allocator_type>         __alloc_traits;
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+
+    typedef typename __alloc_traits::void_pointer  __void_pointer;
+
+    typedef __tree_node<value_type, __void_pointer> __node;
+    typedef __tree_node_base<__void_pointer>        __node_base;
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__node>
+#else
+            rebind_alloc<__node>::other
+#endif
+                                                     __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 __node_base::pointer            __node_base_pointer;
+    typedef typename __node_base::pointer            __node_base_const_pointer;
+private:
+    typedef typename __node_base::base __end_node_t;
+    typedef typename pointer_traits<__node_pointer>::template
+#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;
+
+    __node_pointer                                          __begin_node_;
+    __compressed_pair<__end_node_t, __node_allocator>  __pair1_;
+    __compressed_pair<size_type, value_compare>        __pair3_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    __node_pointer __end_node() _NOEXCEPT
+    {
+        return static_cast<__node_pointer>
+               (
+                   pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
+               );
+    }
+    _LIBCPP_INLINE_VISIBILITY
+    __node_const_pointer __end_node() const _NOEXCEPT
+    {
+        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();}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    const __node_allocator& __node_alloc() const _NOEXCEPT
+        {return __pair1_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+          __node_pointer& __begin_node() _NOEXCEPT {return __begin_node_;}
+    _LIBCPP_INLINE_VISIBILITY
+    const __node_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;}
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    allocator_type __alloc() const _NOEXCEPT
+        {return allocator_type(__node_alloc());}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+          size_type& size() _NOEXCEPT {return __pair3_.first();}
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    const size_type& size() const _NOEXCEPT {return __pair3_.first();}
+    _LIBCPP_INLINE_VISIBILITY
+          value_compare& value_comp() _NOEXCEPT {return __pair3_.second();}
+    _LIBCPP_INLINE_VISIBILITY
+    const value_compare& value_comp() const _NOEXCEPT
+        {return __pair3_.second();}
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    __node_pointer __root() _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;
+
+    explicit __tree(const value_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<__node_allocator>::value &&
+            is_nothrow_copy_constructible<value_compare>::value);
+    explicit __tree(const allocator_type& __a);
+    __tree(const value_compare& __comp, const allocator_type& __a);
+    __tree(const __tree& __t);
+    __tree& operator=(const __tree& __t);
+    template <class _InputIterator>
+        void __assign_unique(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        void __assign_multi(_InputIterator __first, _InputIterator __last);
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    __tree(__tree&& __t)
+        _NOEXCEPT_(
+            is_nothrow_move_constructible<__node_allocator>::value &&
+            is_nothrow_move_constructible<value_compare>::value);
+    __tree(__tree&& __t, const allocator_type& __a);
+    __tree& operator=(__tree&& __t)
+        _NOEXCEPT_(
+            __node_traits::propagate_on_container_move_assignment::value &&
+            is_nothrow_move_assignable<value_compare>::value &&
+            is_nothrow_move_assignable<__node_allocator>::value);
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+    ~__tree();
+
+    _LIBCPP_INLINE_VISIBILITY
+          iterator begin()  _NOEXCEPT {return       iterator(__begin_node());}
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());}
+    _LIBCPP_INLINE_VISIBILITY
+          iterator end() _NOEXCEPT {return       iterator(__end_node());}
+    _LIBCPP_INLINE_VISIBILITY
+    const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());}
+
+    _LIBCPP_INLINE_VISIBILITY
+    size_type max_size() const _NOEXCEPT
+        {return __node_traits::max_size(__node_alloc());}
+
+    void clear() _NOEXCEPT;
+
+    void swap(__tree& __t)
+        _NOEXCEPT_(
+            __is_nothrow_swappable<value_compare>::value &&
+            (!__node_traits::propagate_on_container_swap::value ||
+             __is_nothrow_swappable<__node_allocator>::value));
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class... _Args>
+        pair<iterator, bool>
+        __emplace_unique(_Args&&... __args);
+    template <class... _Args>
+        iterator
+        __emplace_multi(_Args&&... __args);
+
+    template <class... _Args>
+        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>
+        pair<iterator, bool> __insert_unique(_Vp&& __v);
+    template <class _Vp>
+        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
+
+    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,
+                                              __node_pointer __nd);
+
+    iterator __node_insert_multi(__node_pointer __nd);
+    iterator __node_insert_multi(const_iterator __p, __node_pointer __nd);
+
+    iterator erase(const_iterator __p);
+    iterator erase(const_iterator __f, const_iterator __l);
+    template <class _Key>
+        size_type __erase_unique(const _Key& __k);
+    template <class _Key>
+        size_type __erase_multi(const _Key& __k);
+
+    void __insert_node_at(__node_base_pointer __parent,
+                          __node_base_pointer& __child,
+                          __node_base_pointer __new_node);
+
+    template <class _Key>
+        iterator find(const _Key& __v);
+    template <class _Key>
+        const_iterator find(const _Key& __v) const;
+
+    template <class _Key>
+        size_type __count_unique(const _Key& __k) const;
+    template <class _Key>
+        size_type __count_multi(const _Key& __k) const;
+
+    template <class _Key>
+        _LIBCPP_INLINE_VISIBILITY
+        iterator lower_bound(const _Key& __v)
+            {return __lower_bound(__v, __root(), __end_node());}
+    template <class _Key>
+        iterator __lower_bound(const _Key& __v,
+                               __node_pointer __root,
+                               __node_pointer __result);
+    template <class _Key>
+        _LIBCPP_INLINE_VISIBILITY
+        const_iterator lower_bound(const _Key& __v) const
+            {return __lower_bound(__v, __root(), __end_node());}
+    template <class _Key>
+        const_iterator __lower_bound(const _Key& __v,
+                                     __node_const_pointer __root,
+                                     __node_const_pointer __result) const;
+    template <class _Key>
+        _LIBCPP_INLINE_VISIBILITY
+        iterator upper_bound(const _Key& __v)
+            {return __upper_bound(__v, __root(), __end_node());}
+    template <class _Key>
+        iterator __upper_bound(const _Key& __v,
+                               __node_pointer __root,
+                               __node_pointer __result);
+    template <class _Key>
+        _LIBCPP_INLINE_VISIBILITY
+        const_iterator upper_bound(const _Key& __v) const
+            {return __upper_bound(__v, __root(), __end_node());}
+    template <class _Key>
+        const_iterator __upper_bound(const _Key& __v,
+                                     __node_const_pointer __root,
+                                     __node_const_pointer __result) const;
+    template <class _Key>
+        pair<iterator, iterator>
+        __equal_range_unique(const _Key& __k);
+    template <class _Key>
+        pair<const_iterator, const_iterator>
+        __equal_range_unique(const _Key& __k) const;
+
+    template <class _Key>
+        pair<iterator, iterator>
+        __equal_range_multi(const _Key& __k);
+    template <class _Key>
+        pair<const_iterator, const_iterator>
+        __equal_range_multi(const _Key& __k) const;
+
+    typedef __tree_node_destructor<__node_allocator> _Dp;
+    typedef unique_ptr<__node, _Dp> __node_holder;
+
+    __node_holder remove(const_iterator __p) _NOEXCEPT;
+private:
+    typename __node_base::pointer&
+        __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 value_type& __v);
+    typename __node_base::pointer&
+        __find_leaf(const_iterator __hint,
+                    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);
+    template <class _Key>
+        typename __node_base::pointer&
+        __find_equal(const_iterator __hint, typename __node_base::pointer& __parent,
+                     const _Key& __v);
+
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+    template <class ..._Args>
+        __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;
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __copy_assign_alloc(const __tree& __t)
+        {__copy_assign_alloc(__t, integral_constant<bool,
+             __node_traits::propagate_on_container_copy_assignment::value>());}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __copy_assign_alloc(const __tree& __t, true_type)
+        {__node_alloc() = __t.__node_alloc();}
+    _LIBCPP_INLINE_VISIBILITY
+    void __copy_assign_alloc(const __tree& __t, false_type) {}
+
+    void __move_assign(__tree& __t, false_type);
+    void __move_assign(__tree& __t, true_type)
+        _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
+                   is_nothrow_move_assignable<__node_allocator>::value);
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__tree& __t)
+        _NOEXCEPT_(
+            !__node_traits::propagate_on_container_move_assignment::value ||
+            is_nothrow_move_assignable<__node_allocator>::value)
+        {__move_assign_alloc(__t, integral_constant<bool,
+             __node_traits::propagate_on_container_move_assignment::value>());}
+
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__tree& __t, true_type)
+        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
+        {__node_alloc() = _VSTD::move(__t.__node_alloc());}
+    _LIBCPP_INLINE_VISIBILITY
+    void __move_assign_alloc(__tree& __t, false_type) _NOEXCEPT {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
+        _NOEXCEPT_(
+            !__node_traits::propagate_on_container_swap::value ||
+            __is_nothrow_swappable<__node_allocator>::value)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __node_traits::propagate_on_container_swap::value>());}
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
+        _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
+        {
+            using _VSTD::swap;
+            swap(__x, __y);
+        }
+    _LIBCPP_INLINE_VISIBILITY
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
+        _NOEXCEPT
+        {}
+
+    __node_pointer __detach();
+    static __node_pointer __detach(__node_pointer);
+
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY map;
+    template <class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY multimap;
+};
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp)
+        _NOEXCEPT_(
+            is_nothrow_default_constructible<__node_allocator>::value &&
+            is_nothrow_copy_constructible<value_compare>::value)
+    : __pair3_(0, __comp)
+{
+    __begin_node() = __end_node();
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
+    : __pair1_(__node_allocator(__a)),
+      __begin_node_(__node_pointer()),
+      __pair3_(0)
+{
+    __begin_node() = __end_node();
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp,
+                                           const allocator_type& __a)
+    : __pair1_(__node_allocator(__a)),
+      __begin_node_(__node_pointer()),
+      __pair3_(0, __comp)
+{
+    __begin_node() = __end_node();
+}
+
+// Precondition:  size() != 0
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
+__tree<_Tp, _Compare, _Allocator>::__detach()
+{
+    __node_pointer __cache = __begin_node();
+    __begin_node() = __end_node();
+    __end_node()->__left_->__parent_ = nullptr;
+    __end_node()->__left_ = nullptr;
+    size() = 0;
+    // __cache->__left_ == nullptr
+    if (__cache->__right_ != nullptr)
+        __cache = static_cast<__node_pointer>(__cache->__right_);
+    // __cache->__left_ == nullptr
+    // __cache->__right_ == nullptr
+    return __cache;
+}
+
+// Precondition:  __cache != nullptr
+//    __cache->left_ == nullptr
+//    __cache->right_ == nullptr
+//    This is no longer a red-black tree
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
+__tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache)
+{
+    if (__cache->__parent_ == nullptr)
+        return nullptr;
+    if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache)))
+    {
+        __cache->__parent_->__left_ = nullptr;
+        __cache = static_cast<__node_pointer>(__cache->__parent_);
+        if (__cache->__right_ == nullptr)
+            return __cache;
+        return static_cast<__node_pointer>(__tree_leaf(__cache->__right_));
+    }
+    // __cache is right child
+    __cache->__parent_->__right_ = nullptr;
+    __cache = static_cast<__node_pointer>(__cache->__parent_);
+    if (__cache->__left_ == nullptr)
+        return __cache;
+    return static_cast<__node_pointer>(__tree_leaf(__cache->__left_));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>&
+__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t)
+{
+    if (this != &__t)
+    {
+        value_comp() = __t.value_comp();
+        __copy_assign_alloc(__t);
+        __assign_multi(__t.begin(), __t.end());
+    }
+    return *this;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _InputIterator>
+void
+__tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _InputIterator __last)
+{
+    if (size() != 0)
+    {
+        __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __detach(__cache);
+                __node_insert_unique(__cache);
+                __cache = __next;
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+            throw;
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+        if (__cache != nullptr)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+        }
+    }
+    for (; __first != __last; ++__first)
+        __insert_unique(*__first);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _InputIterator>
+void
+__tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last)
+{
+    if (size() != 0)
+    {
+        __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __detach(__cache);
+                __node_insert_multi(__cache);
+                __cache = __next;
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+            throw;
+        }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+        if (__cache != nullptr)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+        }
+    }
+    for (; __first != __last; ++__first)
+        __insert_multi(*__first);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
+    : __begin_node_(__node_pointer()),
+      __pair1_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
+      __pair3_(0, __t.value_comp())
+{
+    __begin_node() = __end_node();
+}
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t)
+    _NOEXCEPT_(
+        is_nothrow_move_constructible<__node_allocator>::value &&
+        is_nothrow_move_constructible<value_compare>::value)
+    : __begin_node_(_VSTD::move(__t.__begin_node_)),
+      __pair1_(_VSTD::move(__t.__pair1_)),
+      __pair3_(_VSTD::move(__t.__pair3_))
+{
+    if (size() == 0)
+        __begin_node() = __end_node();
+    else
+    {
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
+        __t.__begin_node() = __t.__end_node();
+        __t.__end_node()->__left_ = nullptr;
+        __t.size() = 0;
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
+    : __pair1_(__node_allocator(__a)),
+      __pair3_(0, _VSTD::move(__t.value_comp()))
+{
+    if (__a == __t.__alloc())
+    {
+        if (__t.size() == 0)
+            __begin_node() = __end_node();
+        else
+        {
+            __begin_node() = __t.__begin_node();
+            __end_node()->__left_ = __t.__end_node()->__left_;
+            __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
+            size() = __t.size();
+            __t.__begin_node() = __t.__end_node();
+            __t.__end_node()->__left_ = nullptr;
+            __t.size() = 0;
+        }
+    }
+    else
+    {
+        __begin_node() = __end_node();
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type)
+    _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
+               is_nothrow_move_assignable<__node_allocator>::value)
+{
+    destroy(static_cast<__node_pointer>(__end_node()->__left_));
+    __begin_node_ = __t.__begin_node_;
+    __pair1_.first() = __t.__pair1_.first();
+    __move_assign_alloc(__t);
+    __pair3_ = _VSTD::move(__t.__pair3_);
+    if (size() == 0)
+        __begin_node() = __end_node();
+    else
+    {
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
+        __t.__begin_node() = __t.__end_node();
+        __t.__end_node()->__left_ = nullptr;
+        __t.size() = 0;
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type)
+{
+    if (__node_alloc() == __t.__node_alloc())
+        __move_assign(__t, true_type());
+    else
+    {
+        value_comp() = _VSTD::move(__t.value_comp());
+        const_iterator __e = end();
+        if (size() != 0)
+        {
+            __node_pointer __cache = __detach();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            try
+            {
+#endif  // _LIBCPP_NO_EXCEPTIONS
+                while (__cache != nullptr && __t.size() != 0)
+                {
+                    __cache->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_);
+                    __node_pointer __next = __detach(__cache);
+                    __node_insert_multi(__cache);
+                    __cache = __next;
+                }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            }
+            catch (...)
+            {
+                while (__cache->__parent_ != nullptr)
+                    __cache = static_cast<__node_pointer>(__cache->__parent_);
+                destroy(__cache);
+                throw;
+            }
+#endif  // _LIBCPP_NO_EXCEPTIONS
+            if (__cache != nullptr)
+            {
+                while (__cache->__parent_ != nullptr)
+                    __cache = static_cast<__node_pointer>(__cache->__parent_);
+                destroy(__cache);
+            }
+        }
+        while (__t.size() != 0)
+            __insert_multi(__e, _VSTD::move(__t.remove(__t.begin())->__value_));
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>&
+__tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
+    _NOEXCEPT_(
+        __node_traits::propagate_on_container_move_assignment::value &&
+        is_nothrow_move_assignable<value_compare>::value &&
+        is_nothrow_move_assignable<__node_allocator>::value)
+        
+{
+    __move_assign(__t, integral_constant<bool,
+                  __node_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::~__tree()
+{
+    destroy(__root());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT
+{
+    if (__nd != nullptr)
+    {
+        destroy(static_cast<__node_pointer>(__nd->__left_));
+        destroy(static_cast<__node_pointer>(__nd->__right_));
+        __node_allocator& __na = __node_alloc();
+        __node_traits::destroy(__na, _VSTD::addressof(__nd->__value_));
+        __node_traits::deallocate(__na, __nd, 1);
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
+    _NOEXCEPT_(
+        __is_nothrow_swappable<value_compare>::value &&
+        (!__node_traits::propagate_on_container_swap::value ||
+         __is_nothrow_swappable<__node_allocator>::value))
+{
+    using _VSTD::swap;
+    swap(__begin_node_, __t.__begin_node_);
+    swap(__pair1_.first(), __t.__pair1_.first());
+    __swap_alloc(__node_alloc(), __t.__node_alloc());
+    __pair3_.swap(__t.__pair3_);
+    if (size() == 0)
+        __begin_node() = __end_node();
+    else
+        __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node());
+    if (__t.size() == 0)
+        __t.__begin_node() = __t.__end_node();
+    else
+        __t.__end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__t.__end_node());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT
+{
+    destroy(__root());
+    size() = 0;
+    __begin_node() = __end_node();
+    __end_node()->__left_ = nullptr;
+}
+
+// Find lower_bound place to insert
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+template <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 value_type& __v)
+{
+    __node_pointer __nd = __root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (value_comp()(__nd->__value_, __v))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__right_;
+                }
+            }
+            else
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__left_;
+                }
+            }
+        }
+    }
+    __parent = static_cast<__node_base_pointer>(__end_node());
+    return __parent->__left_;
+}
+
+// Find upper_bound place to insert
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+template <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 value_type& __v)
+{
+    __node_pointer __nd = __root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (value_comp()(__v, __nd->__value_))
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__left_;
+                }
+            }
+            else
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__right_;
+                }
+            }
+        }
+    }
+    __parent = static_cast<__node_base_pointer>(__end_node());
+    return __parent->__left_;
+}
+
+// Find leaf place to insert closest to __hint
+// First check prior to __hint.
+// Next check after __hint.
+// Next do O(log N) search.
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
+__tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint,
+                                               typename __node_base::pointer& __parent,
+                                               const value_type& __v)
+{
+    if (__hint == end() || !value_comp()(*__hint, __v))  // check before
+    {
+        // __v <= *__hint
+        const_iterator __prior = __hint;
+        if (__prior == begin() || !value_comp()(__v, *--__prior))
+        {
+            // *prev(__hint) <= __v <= *__hint
+            if (__hint.__ptr_->__left_ == nullptr)
+            {
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
+                return __parent->__left_;
+            }
+            else
+            {
+                __parent = static_cast<__node_base_pointer>(__prior.__ptr_);
+                return __parent->__right_;
+            }
+        }
+        // __v < *prev(__hint)
+        return __find_leaf_high(__parent, __v);
+    }
+    // else __v > *__hint
+    return __find_leaf_low(__parent, __v);
+}
+
+// Find place to insert if __v doesn't exist
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+// If __v exists, set parent to node of __v and return reference to node of __v
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
+__tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& __parent,
+                                                const _Key& __v)
+{
+    __node_pointer __nd = __root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (value_comp()(__v, __nd->__value_))
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__left_;
+                }
+            }
+            else if (value_comp()(__nd->__value_, __v))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = static_cast<__node_base_pointer>(__nd);
+                    return __parent->__right_;
+                }
+            }
+            else
+            {
+                __parent = static_cast<__node_base_pointer>(__nd);
+                return __parent;
+            }
+        }
+    }
+    __parent = static_cast<__node_base_pointer>(__end_node());
+    return __parent->__left_;
+}
+
+// Find place to insert if __v doesn't exist
+// First check prior to __hint.
+// Next check after __hint.
+// Next do O(log N) search.
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+// If __v exists, set parent to node of __v and return reference to node of __v
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::__node_base::pointer&
+__tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint,
+                                                typename __node_base::pointer& __parent,
+                                                const _Key& __v)
+{
+    if (__hint == end() || value_comp()(__v, *__hint))  // check before
+    {
+        // __v < *__hint
+        const_iterator __prior = __hint;
+        if (__prior == begin() || value_comp()(*--__prior, __v))
+        {
+            // *prev(__hint) < __v < *__hint
+            if (__hint.__ptr_->__left_ == nullptr)
+            {
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
+                return __parent->__left_;
+            }
+            else
+            {
+                __parent = static_cast<__node_base_pointer>(__prior.__ptr_);
+                return __parent->__right_;
+            }
+        }
+        // __v <= *prev(__hint)
+        return __find_equal(__parent, __v);
+    }
+    else if (value_comp()(*__hint, __v))  // check after
+    {
+        // *__hint < __v
+        const_iterator __next = _VSTD::next(__hint);
+        if (__next == end() || value_comp()(__v, *__next))
+        {
+            // *__hint < __v < *_VSTD::next(__hint)
+            if (__hint.__ptr_->__right_ == nullptr)
+            {
+                __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
+                return __parent->__right_;
+            }
+            else
+            {
+                __parent = static_cast<__node_base_pointer>(__next.__ptr_);
+                return __parent->__left_;
+            }
+        }
+        // *next(__hint) <= __v
+        return __find_equal(__parent, __v);
+    }
+    // else __v == *__hint
+    __parent = static_cast<__node_base_pointer>(__hint.__ptr_);
+    return __parent;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::__insert_node_at(__node_base_pointer __parent,
+                                                    __node_base_pointer& __child,
+                                                    __node_base_pointer __new_node)
+{
+    __new_node->__left_   = nullptr;
+    __new_node->__right_  = nullptr;
+    __new_node->__parent_ = __parent;
+    __child = __new_node;
+    if (__begin_node()->__left_ != nullptr)
+        __begin_node() = static_cast<__node_pointer>(__begin_node()->__left_);
+    __tree_balance_after_insert(__end_node()->__left_, __child);
+    ++size();
+}
+
+#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)
+{
+    __node_allocator& __na = __node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __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(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal(__parent, __h->__value_);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    bool __inserted = false;
+    if (__child == nullptr)
+    {
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+        __r = __h.release();
+        __inserted = true;
+    }
+    return pair<iterator, bool>(iterator(__r), __inserted);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class... _Args>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__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;
+    __node_base_pointer& __child = __find_equal(__p, __parent, __h->__value_);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+        __r = __h.release();
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class... _Args>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+    return iterator(static_cast<__node_pointer>(__h.release()));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class... _Args>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p,
+                                                        _Args&&... __args)
+{
+    __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
+    __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(static_cast<__node_pointer>(__h.release()));
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+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 value_type& __v)
+{
+    __node_allocator& __na = __node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
+    __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
+    __h.get_deleter().__value_constructed = true;
+    return _VSTD::move(__h);  // explicitly moved for C++03
+}
+
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Compare, class _Allocator>
+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_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());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__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, __v);
+    __node_holder __h = __construct_node(__v);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
+    return iterator(__h.release());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
+__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal(__parent, __nd->__value_);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    bool __inserted = false;
+    if (__child == nullptr)
+    {
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
+        __r = __nd;
+        __inserted = true;
+    }
+    return pair<iterator, bool>(iterator(__r), __inserted);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p,
+                                                        __node_pointer __nd)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal(__p, __parent, __nd->__value_);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
+        __r = __nd;
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
+    return iterator(__nd);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p,
+                                                       __node_pointer __nd)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_);
+    __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
+    return iterator(__nd);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p)
+{
+    __node_pointer __np = __p.__ptr_;
+    iterator __r(__np);
+    ++__r;
+    if (__begin_node() == __np)
+        __begin_node() = __r.__ptr_;
+    --size();
+    __node_allocator& __na = __node_alloc();
+    __tree_remove(__end_node()->__left_,
+                  static_cast<__node_base_pointer>(__np));
+    __node_traits::destroy(__na, const_cast<value_type*>(_VSTD::addressof(*__p)));
+    __node_traits::deallocate(__na, __np, 1);
+    return __r;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l)
+{
+    while (__f != __l)
+        __f = erase(__f);
+    return iterator(__l.__ptr_);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::size_type
+__tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k)
+{
+    iterator __i = find(__k);
+    if (__i == end())
+        return 0;
+    erase(__i);
+    return 1;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::size_type
+__tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k)
+{
+    pair<iterator, iterator> __p = __equal_range_multi(__k);
+    size_type __r = 0;
+    for (; __p.first != __p.second; ++__r)
+        __p.first = erase(__p.first);
+    return __r;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v)
+{
+    iterator __p = __lower_bound(__v, __root(), __end_node());
+    if (__p != end() && !value_comp()(__v, *__p))
+        return __p;
+    return end();
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::const_iterator
+__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const
+{
+    const_iterator __p = __lower_bound(__v, __root(), __end_node());
+    if (__p != end() && !value_comp()(__v, *__p))
+        return __p;
+    return end();
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::size_type
+__tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const
+{
+    __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_const_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+        else
+            return 1;
+    }
+    return 0;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::size_type
+__tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const
+{
+    typedef pair<const_iterator, const_iterator> _Pp;
+    __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_const_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+        else
+            return _VSTD::distance(
+                __lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
+                __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result)
+            );
+    }
+    return 0;
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v,
+                                                 __node_pointer __root,
+                                                 __node_pointer __result)
+{
+    while (__root != nullptr)
+    {
+        if (!value_comp()(__root->__value_, __v))
+        {
+            __result = __root;
+            __root = static_cast<__node_pointer>(__root->__left_);
+        }
+        else
+            __root = static_cast<__node_pointer>(__root->__right_);
+    }
+    return iterator(__result);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::const_iterator
+__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v,
+                                                 __node_const_pointer __root,
+                                                 __node_const_pointer __result) const
+{
+    while (__root != nullptr)
+    {
+        if (!value_comp()(__root->__value_, __v))
+        {
+            __result = __root;
+            __root = static_cast<__node_const_pointer>(__root->__left_);
+        }
+        else
+            __root = static_cast<__node_const_pointer>(__root->__right_);
+    }
+    return const_iterator(__result);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v,
+                                                 __node_pointer __root,
+                                                 __node_pointer __result)
+{
+    while (__root != nullptr)
+    {
+        if (value_comp()(__v, __root->__value_))
+        {
+            __result = __root;
+            __root = static_cast<__node_pointer>(__root->__left_);
+        }
+        else
+            __root = static_cast<__node_pointer>(__root->__right_);
+    }
+    return iterator(__result);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+typename __tree<_Tp, _Compare, _Allocator>::const_iterator
+__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v,
+                                                 __node_const_pointer __root,
+                                                 __node_const_pointer __result) const
+{
+    while (__root != nullptr)
+    {
+        if (value_comp()(__v, __root->__value_))
+        {
+            __result = __root;
+            __root = static_cast<__node_const_pointer>(__root->__left_);
+        }
+        else
+            __root = static_cast<__node_const_pointer>(__root->__right_);
+    }
+    return const_iterator(__result);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator,
+     typename __tree<_Tp, _Compare, _Allocator>::iterator>
+__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k)
+{
+    typedef pair<iterator, iterator> _Pp;
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
+    while (__rt != nullptr)
+    {
+        if (value_comp()(__k, __rt->__value_))
+        {
+            __result = __rt;
+            __rt = static_cast<__node_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_pointer>(__rt->__right_);
+        else
+            return _Pp(iterator(__rt),
+                      iterator(
+                          __rt->__right_ != nullptr ?
+                              static_cast<__node_pointer>(__tree_min(__rt->__right_))
+                            : __result));
+    }
+    return _Pp(iterator(__result), iterator(__result));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator,
+     typename __tree<_Tp, _Compare, _Allocator>::const_iterator>
+__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const
+{
+    typedef pair<const_iterator, const_iterator> _Pp;
+    __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_const_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+        else
+            return _Pp(const_iterator(__rt),
+                      const_iterator(
+                          __rt->__right_ != nullptr ?
+                              static_cast<__node_const_pointer>(__tree_min(__rt->__right_))
+                            : __result));
+    }
+    return _Pp(const_iterator(__result), const_iterator(__result));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator,
+     typename __tree<_Tp, _Compare, _Allocator>::iterator>
+__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k)
+{
+    typedef pair<iterator, iterator> _Pp;
+    __node_pointer __result = __end_node();
+    __node_pointer __rt = __root();
+    while (__rt != nullptr)
+    {
+        if (value_comp()(__k, __rt->__value_))
+        {
+            __result = __rt;
+            __rt = static_cast<__node_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_pointer>(__rt->__right_);
+        else
+            return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
+                      __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
+    }
+    return _Pp(iterator(__result), iterator(__result));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _Key>
+pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator,
+     typename __tree<_Tp, _Compare, _Allocator>::const_iterator>
+__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const
+{
+    typedef pair<const_iterator, const_iterator> _Pp;
+    __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_const_pointer>(__rt->__left_);
+        }
+        else if (value_comp()(__rt->__value_, __k))
+            __rt = static_cast<__node_const_pointer>(__rt->__right_);
+        else
+            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));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+typename __tree<_Tp, _Compare, _Allocator>::__node_holder
+__tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT
+{
+    __node_pointer __np = __p.__ptr_;
+    if (__begin_node() == __np)
+    {
+        if (__np->__right_ != nullptr)
+            __begin_node() = static_cast<__node_pointer>(__np->__right_);
+        else
+            __begin_node() = static_cast<__node_pointer>(__np->__parent_);
+    }
+    --size();
+    __tree_remove(__end_node()->__left_,
+                  static_cast<__node_base_pointer>(__np));
+    return __node_holder(__np, _Dp(__node_alloc()));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__tree<_Tp, _Compare, _Allocator>& __x,
+     __tree<_Tp, _Compare, _Allocator>& __y)
+    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___TREE
diff --git a/rc1/include/__tuple b/rc1/include/__tuple
new file mode 100644
index 0000000..bffb95c
--- /dev/null
+++ b/rc1/include/__tuple
@@ -0,0 +1,361 @@
+// -*- 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___TUPLE
+#define _LIBCPP___TUPLE
+
+#include <__config>
+#include <cstddef>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
+#include <__tuple_03>
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// __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> {};
+
+
+template <class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_size;
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<const _Tp>
+    : public tuple_size<_Tp> {};
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<volatile _Tp>
+    : public tuple_size<_Tp> {};
+
+template <class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<const volatile _Tp>
+    : public tuple_size<_Tp> {};
+
+template <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_element;
+
+template <size_t _Ip, class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const _Tp>
+{
+public:
+    typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
+};
+
+template <size_t _Ip, class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, volatile _Tp>
+{
+public:
+    typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
+};
+
+template <size_t _Ip, class _Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const volatile _Tp>
+{
+public:
+    typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
+};
+
+template <class ..._Tp> class _LIBCPP_TYPE_VIS_ONLY tuple;
+template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair;
+template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array;
+
+template <class _Tp> struct __tuple_like : false_type {};
+
+template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {};
+template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {};
+template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {};
+
+template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {};
+template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
+template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
+
+template <size_t _Ip, class ..._Tp>
+_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;
+
+template <size_t _Ip, class ..._Tp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+typename tuple_element<_Ip, tuple<_Tp...> >::type&&
+get(tuple<_Tp...>&&) _NOEXCEPT;
+
+template <size_t _Ip, class _T1, class _T2>
+_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;
+
+template <size_t _Ip, class _T1, class _T2>
+_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 _Tp, size_t _Size>
+_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;
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_Tp&&
+get(array<_Tp, _Size>&&) _NOEXCEPT;
+
+// __make_tuple_indices
+
+template <size_t...> struct __tuple_indices {};
+
+template <size_t _Sp, class _IntTuple, size_t _Ep>
+struct __make_indices_imp;
+
+template <size_t _Sp, size_t ..._Indices, size_t _Ep>
+struct __make_indices_imp<_Sp, __tuple_indices<_Indices...>, _Ep>
+{
+    typedef typename __make_indices_imp<_Sp+1, __tuple_indices<_Indices..., _Sp>, _Ep>::type type;
+};
+
+template <size_t _Ep, size_t ..._Indices>
+struct __make_indices_imp<_Ep, __tuple_indices<_Indices...>, _Ep>
+{
+    typedef __tuple_indices<_Indices...> type;
+};
+
+template <size_t _Ep, size_t _Sp = 0>
+struct __make_tuple_indices
+{
+    static_assert(_Sp <= _Ep, "__make_tuple_indices input error");
+    typedef typename __make_indices_imp<_Sp, __tuple_indices<>, _Ep>::type type;
+};
+
+// __tuple_types
+
+template <class ..._Tp> struct __tuple_types {};
+
+template <size_t _Ip>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<> >
+{
+public:
+    static_assert(_Ip == 0, "tuple_element index out of range");
+    static_assert(_Ip != 0, "tuple_element index out of range");
+};
+
+template <class _Hp, class ..._Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, __tuple_types<_Hp, _Tp...> >
+{
+public:
+    typedef _Hp type;
+};
+
+template <size_t _Ip, class _Hp, class ..._Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<_Hp, _Tp...> >
+{
+public:
+    typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type;
+};
+
+template <class ..._Tp>
+class _LIBCPP_TYPE_VIS_ONLY tuple_size<__tuple_types<_Tp...> >
+    : public integral_constant<size_t, sizeof...(_Tp)>
+{
+};
+
+template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {};
+
+// __make_tuple_types
+
+// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a
+// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep).
+// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>.  If _Tuple is a
+// lvalue_reference type, then __tuple_types<_Types&...> is the result.
+
+template <class _TupleTypes, class _Tp, size_t _Sp, size_t _Ep>
+struct __make_tuple_types_imp;
+
+template <class ..._Types, class _Tp, size_t _Sp, size_t _Ep>
+struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep>
+{
+    typedef typename remove_reference<_Tp>::type _Tpr;
+    typedef typename __make_tuple_types_imp<__tuple_types<_Types...,
+                                            typename conditional<is_lvalue_reference<_Tp>::value,
+                                                typename tuple_element<_Sp, _Tpr>::type&,
+                                                typename tuple_element<_Sp, _Tpr>::type>::type>,
+                                            _Tp, _Sp+1, _Ep>::type type;
+};
+
+template <class ..._Types, class _Tp, size_t _Ep>
+struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep>
+{
+    typedef __tuple_types<_Types...> type;
+};
+
+template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value, size_t _Sp = 0>
+struct __make_tuple_types
+{
+    static_assert(_Sp <= _Ep, "__make_tuple_types input error");
+    typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type;
+};
+
+// __tuple_convertible
+
+template <class, class>
+struct __tuple_convertible_imp : public false_type {};
+
+template <class _Tp0, class ..._Tp, class _Up0, class ..._Up>
+struct __tuple_convertible_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> >
+    : public integral_constant<bool,
+                               is_convertible<_Tp0, _Up0>::value &&
+                               __tuple_convertible_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {};
+
+template <>
+struct __tuple_convertible_imp<__tuple_types<>, __tuple_types<> >
+    : public true_type {};
+
+template <bool, class, class>
+struct __tuple_convertible_apply : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_convertible_apply<true, _Tp, _Up>
+  : public __tuple_convertible_imp<
+      typename __make_tuple_types<_Tp>::type
+    , typename __make_tuple_types<_Up>::type
+    >
+{};
+
+template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
+                                bool = __tuple_like<_Up>::value>
+struct __tuple_convertible
+    : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_convertible<_Tp, _Up, true, true>
+    : public __tuple_convertible_apply<tuple_size<typename remove_reference<_Tp>::type>::value ==
+                                     tuple_size<_Up>::value, _Tp, _Up>
+{};
+
+// __tuple_constructible
+
+template <class, class>
+struct __tuple_constructible_imp : public false_type {};
+
+template <class _Tp0, class ..._Tp, class _Up0, class ..._Up>
+struct __tuple_constructible_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> >
+    : public integral_constant<bool,
+                               is_constructible<_Up0, _Tp0>::value &&
+                               __tuple_constructible_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {};
+
+template <>
+struct __tuple_constructible_imp<__tuple_types<>, __tuple_types<> >
+    : public true_type {};
+
+template <bool _SameSize, class, class>
+struct __tuple_constructible_apply : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_constructible_apply<true, _Tp, _Up>
+  : public __tuple_constructible_imp<
+      typename __make_tuple_types<_Tp>::type
+    , typename __make_tuple_types<_Up>::type
+    >
+{};
+
+template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
+                                bool = __tuple_like<_Up>::value>
+struct __tuple_constructible
+    : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_constructible<_Tp, _Up, true, true>
+    : public __tuple_constructible_apply<tuple_size<typename remove_reference<_Tp>::type>::value ==
+                                     tuple_size<_Up>::value, _Tp, _Up>
+{};
+
+// __tuple_assignable
+
+template <class, class>
+struct __tuple_assignable_imp : public false_type {};
+
+template <class _Tp0, class ..._Tp, class _Up0, class ..._Up>
+struct __tuple_assignable_imp<__tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> >
+    : public integral_constant<bool,
+                               is_assignable<_Up0&, _Tp0>::value &&
+                               __tuple_assignable_imp<__tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {};
+
+template <>
+struct __tuple_assignable_imp<__tuple_types<>, __tuple_types<> >
+    : public true_type {};
+
+template <bool, class, class>
+struct __tuple_assignable_apply : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_assignable_apply<true, _Tp, _Up>
+  : __tuple_assignable_imp<
+      typename __make_tuple_types<_Tp>::type
+    , typename __make_tuple_types<_Up>::type
+    >
+{};
+
+template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
+                                bool = __tuple_like<_Up>::value>
+struct __tuple_assignable
+    : public false_type {};
+
+template <class _Tp, class _Up>
+struct __tuple_assignable<_Tp, _Up, true, true>
+    : public __tuple_assignable_apply<tuple_size<typename remove_reference<_Tp>::type>::value ==
+                                    tuple_size<_Up>::value, _Tp, _Up>
+{};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+#endif  // _LIBCPP___TUPLE
diff --git a/rc1/include/__tuple_03 b/rc1/include/__tuple_03
new file mode 100644
index 0000000..b91c2cd
--- /dev/null
+++ b/rc1/include/__tuple_03