libcxx initial import

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__bit_reference b/include/__bit_reference
new file mode 100644
index 0000000..25c171a
--- /dev/null
+++ b/include/__bit_reference
@@ -0,0 +1,1224 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___BIT_REFERENCE
+#define _LIBCPP___BIT_REFERENCE
+
+#include <__config>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _C, bool _IsConst> class __bit_iterator;
+template <class _C> class __bit_const_reference;
+
+template <class _C>
+class __bit_reference
+{
+    typedef typename _C::__storage_type    __storage_type;
+    typedef typename _C::__storage_pointer __storage_pointer;
+
+    __storage_pointer __seg_;
+    __storage_type    __mask_;
+
+#if defined(__clang__)
+    friend typename _C::__self;
+#else
+    friend class _C::__self;
+#endif
+    friend class __bit_const_reference<_C>;
+    friend class __bit_iterator<_C, false>;
+public:
+    _LIBCPP_INLINE_VISIBILITY operator bool() const {return static_cast<bool>(*__seg_ & __mask_);}
+    _LIBCPP_INLINE_VISIBILITY bool operator ~() const {return !static_cast<bool>(*this);}
+
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference& operator=(bool __x)
+    {
+        if (__x)
+            *__seg_ |= __mask_;
+        else
+            *__seg_ &= ~__mask_;
+        return *this;
+    }
+    
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference& operator=(const __bit_reference& __x) {return operator=(static_cast<bool>(__x));}
+
+    _LIBCPP_INLINE_VISIBILITY void flip() {*__seg_ ^= __mask_;}
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, false> operator&() const
+        {return __bit_iterator<_C, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_reference(__storage_pointer __s, __storage_type __m) : __seg_(__s), __mask_(__m) {}
+};
+
+template <class _C, class _D>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(__bit_reference<_C> __x, __bit_reference<_D> __y)
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _C>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(__bit_reference<_C> __x, bool& __y)
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _C>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(bool& __x, __bit_reference<_C> __y)
+{
+    bool __t = __x;
+    __x = __y;
+    __y = __t;
+}
+
+template <class _C>
+class __bit_const_reference
+{
+    typedef typename _C::__storage_type          __storage_type;
+    typedef typename _C::__const_storage_pointer __storage_pointer;
+
+    __storage_pointer        __seg_;
+    __storage_type __mask_;
+
+#if defined(__clang__)
+    friend typename _C::__self;
+#else
+    friend class _C::__self;
+#endif
+    friend class __bit_iterator<_C, true>;
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_const_reference(const __bit_reference<_C>& __x)
+        : __seg_(__x.__seg_), __mask_(__x.__mask_) {}
+
+    _LIBCPP_INLINE_VISIBILITY operator bool() const {return static_cast<bool>(*__seg_ & __mask_);}
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, true> operator&() const
+        {return __bit_iterator<_C, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));}
+private:
+    _LIBCPP_INLINE_VISIBILITY
+    __bit_const_reference(__storage_pointer __s, __storage_type __m) : __seg_(__s), __mask_(__m) {}
+
+    __bit_const_reference& operator=(const __bit_const_reference& __x);
+};
+
+// find
+
+template <class _C>
+__bit_iterator<_C, false>
+__find_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, 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 = _STD::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>(_STD::__ctz(__b)));
+        __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>(_STD::__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>(_STD::__ctz(__b)));
+    }
+    return _It(__first.__seg_, static_cast<unsigned>(__n));
+}
+
+template <class _C>
+__bit_iterator<_C, false>
+__find_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, 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 = _STD::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>(_STD::__ctz(__b)));
+        __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>(_STD::__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>(_STD::__ctz(__b)));
+    }
+    return _It(__first.__seg_, static_cast<unsigned>(__n));
+}
+
+template <class _C, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_C, false>
+find(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value)
+{
+    if (static_cast<bool>(__value))
+        return __find_bool_true(__first, static_cast<typename _C::size_type>(__last - __first));
+    return __find_bool_false(__first, static_cast<typename _C::size_type>(__last - __first));
+}
+
+// count
+
+template <class _C>
+typename __bit_iterator<_C, false>::difference_type
+__count_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, false> _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 = _STD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __r = _STD::__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 += _STD::__pop_count(*__first.__seg_);
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __r += _STD::__pop_count(*__first.__seg_ & __m);
+    }
+    return __r;
+}
+
+template <class _C>
+typename __bit_iterator<_C, false>::difference_type
+__count_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, false> _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 = _STD::min(__clz_f, __n);
+        __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
+        __r = _STD::__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 += _STD::__pop_count(~*__first.__seg_);
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __r += _STD::__pop_count(~(*__first.__seg_ & __m));
+    }
+    return __r;
+}
+
+template <class _C, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __bit_iterator<_C, false>::difference_type
+count(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value)
+{
+    if (static_cast<bool>(__value))
+        return __count_bool_true(__first, static_cast<typename _C::size_type>(__last - __first));
+    return __count_bool_false(__first, static_cast<typename _C::size_type>(__last - __first));
+}
+
+// fill_n
+
+template <class _C>
+void
+__fill_n_false(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, 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 = _STD::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;
+    _STD::memset(__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 _C>
+void
+__fill_n_true(__bit_iterator<_C, false> __first, typename _C::size_type __n)
+{
+    typedef __bit_iterator<_C, 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 = _STD::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;
+    _STD::memset(__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 _C>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+fill_n(__bit_iterator<_C, false> __first, typename _C::size_type __n, bool __value)
+{
+    if (__n > 0)
+    {
+        if (__value)
+            __fill_n_true(__first, __n);
+        else
+            __fill_n_false(__first, __n);
+    }
+}
+
+// fill
+
+template <class _C>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+fill(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, bool __value)
+{
+    _STD::fill_n(__first, static_cast<typename _C::size_type>(__last - __first), __value);
+}
+
+// copy
+
+template <class _C, bool _IsConst>
+__bit_iterator<_C, false>
+__copy_aligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last,
+                                                     __bit_iterator<_C, false> __result)
+{
+    typedef __bit_iterator<_C, _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 = _STD::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;
+        _STD::memmove(__result.__seg_, __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 _C, bool _IsConst>
+__bit_iterator<_C, false>
+__copy_unaligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last,
+                                                       __bit_iterator<_C, false> __result)
+{
+    typedef __bit_iterator<_C, _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 = _STD::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 = _STD::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 = _STD::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 _C, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_C, false>
+copy(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result)
+{
+    if (__first.__ctz_ == __result.__ctz_)
+        return __copy_aligned(__first, __last, __result);
+    return __copy_unaligned(__first, __last, __result);
+}
+
+// copy_backward
+
+template <class _C, bool _IsConst>
+__bit_iterator<_C, false>
+__copy_backward_aligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last,
+                                                     __bit_iterator<_C, false> __result)
+{
+    typedef __bit_iterator<_C, _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 = _STD::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;
+        _STD::memmove(__result.__seg_, __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 _C, bool _IsConst>
+__bit_iterator<_C, false>
+__copy_backward_unaligned(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last,
+                                                       __bit_iterator<_C, false> __result)
+{
+    typedef __bit_iterator<_C, _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 = _STD::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 = _STD::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;
+            unsigned __clz_r = __bits_per_word - __result.__ctz_;
+            __storage_type __dn = _STD::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 _C, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_C, false>
+copy_backward(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result)
+{
+    if (__last.__ctz_ == __result.__ctz_)
+        return __copy_backward_aligned(__first, __last, __result);
+    return __copy_backward_unaligned(__first, __last, __result);
+}
+
+// move
+
+template <class _C, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_C, false>
+move(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result)
+{
+    return _STD::copy(__first, __last, __result);
+}
+
+// move_backward
+
+template <class _C, bool _IsConst>
+inline _LIBCPP_INLINE_VISIBILITY
+__bit_iterator<_C, false>
+move_backward(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst> __last, __bit_iterator<_C, false> __result)
+{
+    return _STD::copy(__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 = _STD::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 = _STD::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 = _STD::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 = _STD::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 _C>
+struct __bit_array
+{
+    typedef typename _C::difference_type difference_type;
+    typedef typename _C::__storage_type  __storage_type;
+    typedef typename _C::iterator        iterator;
+    static const unsigned __bits_per_word = _C::__bits_per_word;
+    static const unsigned _N = 4;
+
+    difference_type __size_;
+    __storage_type __word_[_N];
+
+    _LIBCPP_INLINE_VISIBILITY static difference_type capacity()
+        {return static_cast<difference_type>(_N * __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
+    _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(__word_, 0);}
+    _LIBCPP_INLINE_VISIBILITY iterator end()   {return iterator(__word_ + __size_ / __bits_per_word,
+                                                  static_cast<unsigned>(__size_ % __bits_per_word));}
+};
+
+template <class _C>
+__bit_iterator<_C, false>
+rotate(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __middle, __bit_iterator<_C, false> __last)
+{
+    typedef __bit_iterator<_C, 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 __d1 = __middle - __first;
+    difference_type __d2 = __last - __middle;
+    _I1 __r = __first + __d2;
+    while (__d1 != 0 && __d2 != 0)
+    {
+        if (__d1 <= __d2)
+        {
+            if (__d1 <= __bit_array<_C>::capacity())
+            {
+                __bit_array<_C> __b(__d1);
+                _STD::copy(__first, __middle, __b.begin());
+                _STD::copy(__b.begin(), __b.end(), _STD::copy(__middle, __last, __first));
+                break;
+            }
+            else
+            {
+                __bit_iterator<_C, false> __mp = _STD::swap_ranges(__first, __middle, __middle);
+                __first = __middle;
+                __middle = __mp;
+                __d2 -= __d1;
+            }
+        }
+        else
+        {
+            if (__d2 <= __bit_array<_C>::capacity())
+            {
+                __bit_array<_C> __b(__d2);
+                _STD::copy(__middle, __last, __b.begin());
+                _STD::copy_backward(__b.begin(), __b.end(), _STD::copy_backward(__first, __middle, __last));
+                break;
+            }
+            else
+            {
+                __bit_iterator<_C, false> __mp = __first + __d2;
+                _STD::swap_ranges(__first, __mp, __middle);
+                __first = __mp;
+                __d1 -= __d2;
+            }
+        }
+    }
+    return __r;
+}
+
+// equal
+
+template <class _C>
+bool
+__equal_unaligned(__bit_iterator<_C, true> __first1, __bit_iterator<_C, true> __last1,
+                  __bit_iterator<_C, true> __first2)
+{
+    typedef __bit_iterator<_C, true> _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 = _STD::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 = _STD::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 = _STD::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 _C>
+bool
+__equal_aligned(__bit_iterator<_C, true> __first1, __bit_iterator<_C, true> __last1,
+                __bit_iterator<_C, true> __first2)
+{
+    typedef __bit_iterator<_C, true> _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 = _STD::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 _C, bool _IC1, bool _IC2>
+bool
+equal(__bit_iterator<_C, _IC1> __first1, __bit_iterator<_C, _IC1> __last1, __bit_iterator<_C, _IC2> __first2)
+{
+    if (__first1.__ctz_ == __first2.__ctz_)
+        return __equal_aligned(__first1, __last1, __first2);
+    return __equal_unaligned(__first1, __last1, __first2);
+}
+
+template <class _C, bool _IsConst>
+class __bit_iterator
+{
+public:
+    typedef typename _C::difference_type                                                          difference_type;
+    typedef bool                                                                                  value_type;
+    typedef __bit_iterator                                                                        pointer;
+    typedef typename conditional<_IsConst, __bit_const_reference<_C>, __bit_reference<_C> >::type reference;
+    typedef random_access_iterator_tag                                                            iterator_category;
+
+private:
+    typedef typename _C::__storage_type                                           __storage_type;
+    typedef typename conditional<_IsConst, typename _C::__const_storage_pointer,
+                                           typename _C::__storage_pointer>::type  __storage_pointer;
+    static const unsigned __bits_per_word = _C::__bits_per_word;
+
+    __storage_pointer __seg_;
+    unsigned          __ctz_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator() {}
+
+    _LIBCPP_INLINE_VISIBILITY __bit_iterator(const __bit_iterator<_C, false>& __it)
+        : __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {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) : __seg_(__s), __ctz_(__ctz) {}
+
+#if defined(__clang__)
+    friend typename _C::__self;
+#else
+    friend class _C::__self;
+#endif
+    friend class __bit_reference<_C>;
+    friend class __bit_const_reference<_C>;
+    friend class __bit_iterator<_C, true>;
+    template <class _D> friend struct __bit_array;
+    template <class _D> friend void __fill_n_false(__bit_iterator<_D, false> __first, typename _D::size_type __n);
+    template <class _D> friend void __fill_n_true(__bit_iterator<_D, false> __first, typename _D::size_type __n);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> __copy_aligned(__bit_iterator<_D, _IC> __first,
+                                                                                  __bit_iterator<_D, _IC> __last,
+                                                                                  __bit_iterator<_D, false> __result);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> __copy_unaligned(__bit_iterator<_D, _IC> __first,
+                                                                                    __bit_iterator<_D, _IC> __last,
+                                                                                    __bit_iterator<_D, false> __result);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> copy(__bit_iterator<_D, _IC> __first,
+                                                                        __bit_iterator<_D, _IC> __last,
+                                                                        __bit_iterator<_D, false> __result);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> __copy_backward_aligned(__bit_iterator<_D, _IC> __first,
+                                                                                           __bit_iterator<_D, _IC> __last,
+                                                                                           __bit_iterator<_D, false> __result);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> __copy_backward_unaligned(__bit_iterator<_D, _IC> __first,
+                                                                                             __bit_iterator<_D, _IC> __last,
+                                                                                             __bit_iterator<_D, false> __result);
+    template <class _D, bool _IC> friend __bit_iterator<_D, false> copy_backward(__bit_iterator<_D, _IC> __first,
+                                                                                 __bit_iterator<_D, _IC> __last,
+                                                                                 __bit_iterator<_D, 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 _D> friend __bit_iterator<_D, false> rotate(__bit_iterator<_D, false>,
+                                                                __bit_iterator<_D, false>,
+                                                                __bit_iterator<_D, false>);
+    template <class _D> friend bool __equal_aligned(__bit_iterator<_D, true>,
+                                                    __bit_iterator<_D, true>,
+                                                    __bit_iterator<_D, true>);
+    template <class _D> friend bool __equal_unaligned(__bit_iterator<_D, true>,
+                                                      __bit_iterator<_D, true>,
+                                                      __bit_iterator<_D, true>);
+    template <class _D, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_D, _IC1>,
+                                                                __bit_iterator<_D, _IC1>,
+                                                                __bit_iterator<_D, _IC2>);
+    template <class _D> friend __bit_iterator<_D, false> __find_bool_true(__bit_iterator<_D, false>,
+                                                                          typename _D::size_type);
+    template <class _D> friend __bit_iterator<_D, false> __find_bool_false(__bit_iterator<_D, false>,
+                                                                           typename _D::size_type);
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___BIT_REFERENCE
diff --git a/include/__config b/include/__config
new file mode 100644
index 0000000..b37b119
--- /dev/null
+++ b/include/__config
@@ -0,0 +1,136 @@
+// -*- C++ -*-
+//===--------------------------- __config ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CONFIG
+#define _LIBCPP_CONFIG
+
+#pragma GCC system_header
+
+#define _LIBCPP_VERSION 1000
+
+#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
+#endif
+
+#ifdef __BIG_ENDIAN__
+#if __BIG_ENDIAN__
+#define _LIBCPP_LITTLE_ENDIAN 0
+#define _LIBCPP_BIG_ENDIAN    1
+#endif
+#endif
+
+#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+#error unable to determine endian
+#endif
+
+#ifndef _LIBCPP_VISIBILITY_TAG
+#define _LIBCPP_VISIBILITY_TAG 1
+#endif
+
+#if _LIBCPP_VISIBILITY_TAG
+#define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
+#define _LIBCPP_VISIBLE __attribute__ ((__visibility__("default")))
+#else
+#define _LIBCPP_HIDDEN
+#define _LIBCPP_VISIBLE
+#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
+
+#define _LIBCPP_CANTTHROW __attribute__ ((__nothrow__))
+
+#define _LIBCPP_ALWAYS_INLINE  __attribute__((__always_inline__))
+
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
+#define _LIBCPP_MOVE
+#endif
+
+#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+#define _LIBCPP_HAS_NO_STATIC_ASSERT
+#endif
+
+#define _LIBCPP_HAS_NO_NULLPTR
+
+#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
+#define _LIBCPP_HAS_NO_VARIADICS
+#define _LIBCPP_HAS_NO_DECLTYPE
+#endif
+
+#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
+#define _LIBCPP_HAS_NO_UNICODE_CHARS
+#define _LIBCPP_HAS_NO_ADVANCED_SFINAE
+#endif
+
+#if defined(__clang__)
+#define _LIBCPP_HAS_NO_STRONG_USING
+#endif
+
+#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+
+#ifdef _LIBCPP_HAS_NO_STRONG_USING
+#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {
+#define _LIBCPP_END_NAMESPACE_STD }
+#define _STD std
+#else
+#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace _LIBCPP_NAMESPACE {
+#define _LIBCPP_END_NAMESPACE_STD  } }
+
+namespace std {
+namespace _LIBCPP_NAMESPACE {
+}
+using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
+}
+
+#define _STD std::_LIBCPP_NAMESPACE
+#endif
+
+#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
+    typedef unsigned short char16_t;
+    typedef unsigned int   char32_t;
+#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
+
+#ifdef _LIBCPP_HAS_NO_DECLTYPE
+
+#define decltype(x) __typeof__(x)
+
+#endif
+
+#if !__EXCEPTIONS
+#define _LIBCPP_NO_EXCEPTIONS
+#endif
+
+#endif  // _LIBCPP_CONFIG
diff --git a/include/__functional_03 b/include/__functional_03
new file mode 100644
index 0000000..4063851
--- /dev/null
+++ b/include/__functional_03
@@ -0,0 +1,1836 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FUNCTIONAL_03
+#define _LIBCPP_FUNCTIONAL_03
+
+// manual variadic expansion for <functional>
+
+#pragma GCC system_header
+
+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() ()
+       {
+           return __invoke(__f_);
+       }
+
+    template <class _A0>
+       typename __invoke_return0<type, _A0>::type
+          operator() (_A0& __a0)
+          {
+              return __invoke(__f_, __a0);
+          }
+
+    template <class _A0, class _A1>
+       typename __invoke_return1<type, _A0, _A1>::type
+          operator() (_A0& __a0, _A1& __a1)
+          {
+              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)
+          {
+              return __invoke(__f_, __a0, __a1, __a2);
+          }
+};
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R _T::*>
+mem_fn(_R _T::* __pm)
+{
+    return __mem_fn<_R _T::*>(__pm);
+}
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)()>
+mem_fn(_R (_T::* __pm)())
+{
+    return __mem_fn<_R (_T::*)()>(__pm);
+}
+
+template<class _R, class _T, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0)>
+mem_fn(_R (_T::* __pm)(_A0))
+{
+    return __mem_fn<_R (_T::*)(_A0)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1)>
+mem_fn(_R (_T::* __pm)(_A0, _A1))
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1, _A2)>
+mem_fn(_R (_T::* __pm)(_A0, _A1, _A2))
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm);
+}
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)()>
+mem_fn(_R (_T::* __pm)() const)
+{
+    return __mem_fn<_R (_T::*)()>(__pm);
+}
+
+template<class _R, class _T, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0)>
+mem_fn(_R (_T::* __pm)(_A0) const)
+{
+    return __mem_fn<_R (_T::*)(_A0)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1)>
+mem_fn(_R (_T::* __pm)(_A0, _A1) const)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1, _A2)>
+mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm);
+}
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)()>
+mem_fn(_R (_T::* __pm)() volatile)
+{
+    return __mem_fn<_R (_T::*)()>(__pm);
+}
+
+template<class _R, class _T, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0)>
+mem_fn(_R (_T::* __pm)(_A0) volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1)>
+mem_fn(_R (_T::* __pm)(_A0, _A1) volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1, _A2)>
+mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm);
+}
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)()>
+mem_fn(_R (_T::* __pm)() const volatile)
+{
+    return __mem_fn<_R (_T::*)()>(__pm);
+}
+
+template<class _R, class _T, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0)>
+mem_fn(_R (_T::* __pm)(_A0) const volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1)>
+mem_fn(_R (_T::* __pm)(_A0, _A1) const volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm);
+}
+
+template<class _R, class _T, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_A0, _A1, _A2)>
+mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const volatile)
+{
+    return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm);
+}
+
+// bad_function_call
+
+class bad_function_call
+    : public exception
+{
+};
+
+template<class _Fp> class function; // undefined
+
+namespace __function
+{
+
+template<class _F>
+struct __maybe_derive_from_unary_function
+{
+};
+
+template<class _R, class _A1>
+struct __maybe_derive_from_unary_function<_R(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template<class _F>
+struct __maybe_derive_from_binary_function
+{
+};
+
+template<class _R, class _A1, class _A2>
+struct __maybe_derive_from_binary_function<_R(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template<class _Fp> class __base;
+
+template<class _R>
+class __base<_R()>
+{
+    __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 _R operator()() = 0;
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+};
+
+template<class _R, class _A0>
+class __base<_R(_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 _R operator()(_A0) = 0;
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+};
+
+template<class _R, class _A0, class _A1>
+class __base<_R(_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 _R operator()(_A0, _A1) = 0;
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+};
+
+template<class _R, class _A0, class _A1, class _A2>
+class __base<_R(_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 _R operator()(_A0, _A1, _A2) = 0;
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+};
+
+template<class _FD, class _Alloc, class _FB> class __func;
+
+template<class _F, class _Alloc, class _R>
+class __func<_F, _Alloc, _R()>
+    : public  __base<_R()>
+{
+    __compressed_pair<_F, _Alloc> __f_;
+public:
+    explicit __func(_F __f) : __f_(_STD::move(__f)) {}
+    explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
+    virtual __base<_R()>* __clone() const;
+    virtual void __clone(__base<_R()>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _R operator()();
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+};
+
+template<class _F, class _Alloc, class _R>
+__base<_R()>*
+__func<_F, _Alloc, _R()>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    typedef __allocator_destructor<_A> _D;
+    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _F, class _Alloc, class _R>
+void
+__func<_F, _Alloc, _R()>::__clone(__base<_R()>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _F, class _Alloc, class _R>
+void
+__func<_F, _Alloc, _R()>::destroy()
+{
+    __f_.~__compressed_pair<_F, _Alloc>();
+}
+
+template<class _F, class _Alloc, class _R>
+void
+__func<_F, _Alloc, _R()>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    __f_.~__compressed_pair<_F, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _F, class _Alloc, class _R>
+_R
+__func<_F, _Alloc, _R()>::operator()()
+{
+    return __invoke<_R>(__f_.first());
+}
+
+template<class _F, class _Alloc, class _R>
+const void*
+__func<_F, _Alloc, _R()>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_F))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _F, class _Alloc, class _R>
+const std::type_info&
+__func<_F, _Alloc, _R()>::target_type() const
+{
+    return typeid(_F);
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+class __func<_F, _Alloc, _R(_A0)>
+    : public  __base<_R(_A0)>
+{
+    __compressed_pair<_F, _Alloc> __f_;
+public:
+    explicit __func(_F __f) : __f_(_STD::move(__f)) {}
+    explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
+    virtual __base<_R(_A0)>* __clone() const;
+    virtual void __clone(__base<_R(_A0)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _R operator()(_A0);
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+};
+
+template<class _F, class _Alloc, class _R, class _A0>
+__base<_R(_A0)>*
+__func<_F, _Alloc, _R(_A0)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    typedef __allocator_destructor<_A> _D;
+    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+void
+__func<_F, _Alloc, _R(_A0)>::__clone(__base<_R(_A0)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+void
+__func<_F, _Alloc, _R(_A0)>::destroy()
+{
+    __f_.~__compressed_pair<_F, _Alloc>();
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+void
+__func<_F, _Alloc, _R(_A0)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    __f_.~__compressed_pair<_F, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+_R
+__func<_F, _Alloc, _R(_A0)>::operator()(_A0 __a0)
+{
+    return __invoke(__f_.first(), __a0);
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+const void*
+__func<_F, _Alloc, _R(_A0)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_F))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _F, class _Alloc, class _R, class _A0>
+const std::type_info&
+__func<_F, _Alloc, _R(_A0)>::target_type() const
+{
+    return typeid(_F);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+class __func<_F, _Alloc, _R(_A0, _A1)>
+    : public  __base<_R(_A0, _A1)>
+{
+    __compressed_pair<_F, _Alloc> __f_;
+public:
+    explicit __func(_F __f) : __f_(_STD::move(__f)) {}
+    explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
+    virtual __base<_R(_A0, _A1)>* __clone() const;
+    virtual void __clone(__base<_R(_A0, _A1)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _R operator()(_A0, _A1);
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+};
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+__base<_R(_A0, _A1)>*
+__func<_F, _Alloc, _R(_A0, _A1)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    typedef __allocator_destructor<_A> _D;
+    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+void
+__func<_F, _Alloc, _R(_A0, _A1)>::__clone(__base<_R(_A0, _A1)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+void
+__func<_F, _Alloc, _R(_A0, _A1)>::destroy()
+{
+    __f_.~__compressed_pair<_F, _Alloc>();
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+void
+__func<_F, _Alloc, _R(_A0, _A1)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    __f_.~__compressed_pair<_F, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+_R
+__func<_F, _Alloc, _R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1)
+{
+    return __invoke(__f_.first(), __a0, __a1);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+const void*
+__func<_F, _Alloc, _R(_A0, _A1)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_F))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1>
+const std::type_info&
+__func<_F, _Alloc, _R(_A0, _A1)>::target_type() const
+{
+    return typeid(_F);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+class __func<_F, _Alloc, _R(_A0, _A1, _A2)>
+    : public  __base<_R(_A0, _A1, _A2)>
+{
+    __compressed_pair<_F, _Alloc> __f_;
+public:
+    explicit __func(_F __f) : __f_(_STD::move(__f)) {}
+    explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
+    virtual __base<_R(_A0, _A1, _A2)>* __clone() const;
+    virtual void __clone(__base<_R(_A0, _A1, _A2)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _R operator()(_A0, _A1, _A2);
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+};
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+__base<_R(_A0, _A1, _A2)>*
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    typedef __allocator_destructor<_A> _D;
+    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+void
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone(__base<_R(_A0, _A1, _A2)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+void
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy()
+{
+    __f_.~__compressed_pair<_F, _Alloc>();
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+void
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    __f_.~__compressed_pair<_F, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+_R
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2)
+{
+    return __invoke(__f_.first(), __a0, __a1, __a2);
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+const void*
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_F))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2>
+const std::type_info&
+__func<_F, _Alloc, _R(_A0, _A1, _A2)>::target_type() const
+{
+    return typeid(_F);
+}
+
+}  // __function
+
+template<class _R>
+class function<_R()>
+{
+    typedef __function::__base<_R()> __base;
+    aligned_storage<3*sizeof(void*)>::type __buf_;
+    __base* __f_;
+
+    template <class _F>
+        static bool __not_null(const _F&) {return true;}
+    template <class _R2>
+        static bool __not_null(const function<_R()>& __p) {return __p;}
+public:
+    typedef _R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function() : __f_(0) {}
+    function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _F>
+      function(_F,
+               typename enable_if<!is_integral<_F>::value>::type* = 0);
+
+//     template<class _Alloc>
+//       function(allocator_arg_t, const _Alloc&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, nullptr_t);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, const function&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, function&&);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _F>
+      typename enable_if
+      <
+        !is_integral<_F>::value,
+        function&
+      >::type
+      operator=(_F);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+//     template<class _F, class _Alloc>
+//       void assign(_F, const _Alloc&);
+
+    // 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>
+      bool operator==(const function<_R2()>&);// = delete;
+    template<class _R2>
+      bool operator!=(const function<_R2()>&);// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _R operator()() const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _T> _T* target();
+    template <typename _T> const _T* target() const;
+};
+
+template<class _R>
+function<_R()>::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 _R>
+template <class _F>
+function<_R()>::function(_F __f,
+                                     typename enable_if<!is_integral<_F>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_F, allocator<_F>, _R()> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _A;
+            _A __a;
+            typedef __allocator_destructor<_A> _D;
+            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_F>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _R>
+function<_R()>&
+function<_R()>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _R>
+function<_R()>&
+function<_R()>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _R>
+template <class _F>
+typename enable_if
+<
+    !is_integral<_F>::value,
+    function<_R()>&
+>::type
+function<_R()>::operator=(_F __f)
+{
+    function(_STD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _R>
+function<_R()>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _R>
+void
+function<_R()>::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
+        _STD::swap(__f_, __f.__f_);
+}
+
+template<class _R>
+_R
+function<_R()>::operator()() const
+{
+    if (__f_ == 0)
+        throw bad_function_call();
+    return (*__f_)();
+}
+
+template<class _R>
+const std::type_info&
+function<_R()>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _R>
+template <typename _T>
+_T*
+function<_R()>::target()
+{
+    if (__f_ == 0)
+        return (_T*)0;
+    return (_T*)__f_->target(typeid(_T));
+}
+
+template<class _R>
+template <typename _T>
+const _T*
+function<_R()>::target() const
+{
+    if (__f_ == 0)
+        return (const _T*)0;
+    return (const _T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0>
+class function<_R(_A0)>
+    : public unary_function<_A0, _R>
+{
+    typedef __function::__base<_R(_A0)> __base;
+    aligned_storage<3*sizeof(void*)>::type __buf_;
+    __base* __f_;
+
+    template <class _F>
+        static bool __not_null(const _F&) {return true;}
+    template <class _R2, class _B0>
+        static bool __not_null(_R2 (*__p)(_B0)) {return __p;}
+    template <class _R2, class _C>
+        static bool __not_null(_R2 (_C::*__p)()) {return __p;}
+    template <class _R2, class _C>
+        static bool __not_null(_R2 (_C::*__p)() const) {return __p;}
+    template <class _R2, class _C>
+        static bool __not_null(_R2 (_C::*__p)() volatile) {return __p;}
+    template <class _R2, class _C>
+        static bool __not_null(_R2 (_C::*__p)() const volatile) {return __p;}
+    template <class _R2, class _B0>
+        static bool __not_null(const function<_R(_B0)>& __p) {return __p;}
+public:
+    typedef _R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function() : __f_(0) {}
+    function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _F>
+      function(_F,
+               typename enable_if<!is_integral<_F>::value>::type* = 0);
+
+//     template<class _Alloc>
+//       function(allocator_arg_t, const _Alloc&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, nullptr_t);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, const function&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, function&&);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _F>
+      typename enable_if
+      <
+        !is_integral<_F>::value,
+        function&
+      >::type
+      operator=(_F);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+//     template<class _F, class _Alloc>
+//       void assign(_F, const _Alloc&);
+
+    // 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>
+      bool operator==(const function<_R2(_B0)>&);// = delete;
+    template<class _R2, class _B0>
+      bool operator!=(const function<_R2(_B0)>&);// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _R operator()(_A0) const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _T> _T* target();
+    template <typename _T> const _T* target() const;
+};
+
+template<class _R, class _A0>
+function<_R(_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 _R, class _A0>
+template <class _F>
+function<_R(_A0)>::function(_F __f,
+                                     typename enable_if<!is_integral<_F>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_F, allocator<_F>, _R(_A0)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _A;
+            _A __a;
+            typedef __allocator_destructor<_A> _D;
+            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_F>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _R, class _A0>
+function<_R(_A0)>&
+function<_R(_A0)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0>
+function<_R(_A0)>&
+function<_R(_A0)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _R, class _A0>
+template <class _F>
+typename enable_if
+<
+    !is_integral<_F>::value,
+    function<_R(_A0)>&
+>::type
+function<_R(_A0)>::operator=(_F __f)
+{
+    function(_STD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0>
+function<_R(_A0)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _R, class _A0>
+void
+function<_R(_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
+        _STD::swap(__f_, __f.__f_);
+}
+
+template<class _R, class _A0>
+_R
+function<_R(_A0)>::operator()(_A0 __a0) const
+{
+    if (__f_ == 0)
+        throw bad_function_call();
+    return (*__f_)(__a0);
+}
+
+template<class _R, class _A0>
+const std::type_info&
+function<_R(_A0)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _R, class _A0>
+template <typename _T>
+_T*
+function<_R(_A0)>::target()
+{
+    if (__f_ == 0)
+        return (_T*)0;
+    return (_T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0>
+template <typename _T>
+const _T*
+function<_R(_A0)>::target() const
+{
+    if (__f_ == 0)
+        return (const _T*)0;
+    return (const _T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0, class _A1>
+class function<_R(_A0, _A1)>
+    : public binary_function<_A0, _A1, _R>
+{
+    typedef __function::__base<_R(_A0, _A1)> __base;
+    aligned_storage<3*sizeof(void*)>::type __buf_;
+    __base* __f_;
+
+    template <class _F>
+        static bool __not_null(const _F&) {return true;}
+    template <class _R2, class _B0, class _B1>
+        static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;}
+    template <class _R2, class _C, class _B1>
+        static bool __not_null(_R2 (_C::*__p)(_B1)) {return __p;}
+    template <class _R2, class _C, class _B1>
+        static bool __not_null(_R2 (_C::*__p)(_B1) const) {return __p;}
+    template <class _R2, class _C, class _B1>
+        static bool __not_null(_R2 (_C::*__p)(_B1) volatile) {return __p;}
+    template <class _R2, class _C, class _B1>
+        static bool __not_null(_R2 (_C::*__p)(_B1) const volatile) {return __p;}
+    template <class _R2, class _B0, class _B1>
+        static bool __not_null(const function<_R(_B0, _B1)>& __p) {return __p;}
+public:
+    typedef _R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function() : __f_(0) {}
+    function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _F>
+      function(_F,
+               typename enable_if<!is_integral<_F>::value>::type* = 0);
+
+//     template<class _Alloc>
+//       function(allocator_arg_t, const _Alloc&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, nullptr_t);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, const function&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, function&&);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _F>
+      typename enable_if
+      <
+        !is_integral<_F>::value,
+        function&
+      >::type
+      operator=(_F);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+//     template<class _F, class _Alloc>
+//       void assign(_F, const _Alloc&);
+
+    // 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)>&);// = delete;
+    template<class _R2, class _B0, class _B1>
+      bool operator!=(const function<_R2(_B0, _B1)>&);// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _R operator()(_A0, _A1) const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _T> _T* target();
+    template <typename _T> const _T* target() const;
+};
+
+template<class _R, class _A0, class _A1>
+function<_R(_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 _R, class _A0, class _A1>
+template <class _F>
+function<_R(_A0, _A1)>::function(_F __f,
+                                     typename enable_if<!is_integral<_F>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _A;
+            _A __a;
+            typedef __allocator_destructor<_A> _D;
+            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_F>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _R, class _A0, class _A1>
+function<_R(_A0, _A1)>&
+function<_R(_A0, _A1)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0, class _A1>
+function<_R(_A0, _A1)>&
+function<_R(_A0, _A1)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _R, class _A0, class _A1>
+template <class _F>
+typename enable_if
+<
+    !is_integral<_F>::value,
+    function<_R(_A0, _A1)>&
+>::type
+function<_R(_A0, _A1)>::operator=(_F __f)
+{
+    function(_STD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0, class _A1>
+function<_R(_A0, _A1)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _R, class _A0, class _A1>
+void
+function<_R(_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
+        _STD::swap(__f_, __f.__f_);
+}
+
+template<class _R, class _A0, class _A1>
+_R
+function<_R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
+{
+    if (__f_ == 0)
+        throw bad_function_call();
+    return (*__f_)(__a0, __a1);
+}
+
+template<class _R, class _A0, class _A1>
+const std::type_info&
+function<_R(_A0, _A1)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _R, class _A0, class _A1>
+template <typename _T>
+_T*
+function<_R(_A0, _A1)>::target()
+{
+    if (__f_ == 0)
+        return (_T*)0;
+    return (_T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0, class _A1>
+template <typename _T>
+const _T*
+function<_R(_A0, _A1)>::target() const
+{
+    if (__f_ == 0)
+        return (const _T*)0;
+    return (const _T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+class function<_R(_A0, _A1, _A2)>
+{
+    typedef __function::__base<_R(_A0, _A1, _A2)> __base;
+    aligned_storage<3*sizeof(void*)>::type __buf_;
+    __base* __f_;
+
+    template <class _F>
+        static bool __not_null(const _F&) {return true;}
+    template <class _R2, class _B0, class _B1, class _B2>
+        static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;}
+    template <class _R2, class _C, class _B1, class _B2>
+        static bool __not_null(_R2 (_C::*__p)(_B1, _B2)) {return __p;}
+    template <class _R2, class _C, class _B1, class _B2>
+        static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const) {return __p;}
+    template <class _R2, class _C, class _B1, class _B2>
+        static bool __not_null(_R2 (_C::*__p)(_B1, _B2) volatile) {return __p;}
+    template <class _R2, class _C, class _B1, class _B2>
+        static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const volatile) {return __p;}
+    template <class _R2, class _B0, class _B1, class _B2>
+        static bool __not_null(const function<_R(_B0, _B1, _B2)>& __p) {return __p;}
+public:
+    typedef _R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function() : __f_(0) {}
+    function(nullptr_t) : __f_(0) {}
+    function(const function&);
+    template<class _F>
+      function(_F,
+               typename enable_if<!is_integral<_F>::value>::type* = 0);
+
+//     template<class _Alloc>
+//       function(allocator_arg_t, const _Alloc&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, nullptr_t);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, const function&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, function&&);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F);
+
+    function& operator=(const function&);
+    function& operator=(nullptr_t);
+    template<class _F>
+      typename enable_if
+      <
+        !is_integral<_F>::value,
+        function&
+      >::type
+      operator=(_F);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+//     template<class _F, class _Alloc>
+//       void assign(_F, const _Alloc&);
+
+    // 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, class _B2>
+      bool operator==(const function<_R2(_B0, _B1, _B2)>&);// = delete;
+    template<class _R2, class _B0, class _B1, class _B2>
+      bool operator!=(const function<_R2(_B0, _B1, _B2)>&);// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _R operator()(_A0, _A1, _A2) const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _T> _T* target();
+    template <typename _T> const _T* target() const;
+};
+
+template<class _R, class _A0, class _A1, class _A2>
+function<_R(_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 _R, class _A0, class _A1, class _A2>
+template <class _F>
+function<_R(_A0, _A1, _A2)>::function(_F __f,
+                                     typename enable_if<!is_integral<_F>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1, _A2)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(__f);
+        }
+        else
+        {
+            typedef allocator<_FF> _A;
+            _A __a;
+            typedef __allocator_destructor<_A> _D;
+            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
+            ::new (__hold.get()) _FF(__f, allocator<_F>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+function<_R(_A0, _A1, _A2)>&
+function<_R(_A0, _A1, _A2)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+function<_R(_A0, _A1, _A2)>&
+function<_R(_A0, _A1, _A2)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+template <class _F>
+typename enable_if
+<
+    !is_integral<_F>::value,
+    function<_R(_A0, _A1, _A2)>&
+>::type
+function<_R(_A0, _A1, _A2)>::operator=(_F __f)
+{
+    function(_STD::move(__f)).swap(*this);
+    return *this;
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+function<_R(_A0, _A1, _A2)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+void
+function<_R(_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
+        _STD::swap(__f_, __f.__f_);
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+_R
+function<_R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
+{
+    if (__f_ == 0)
+        throw bad_function_call();
+    return (*__f_)(__a0, __a1, __a2);
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+const std::type_info&
+function<_R(_A0, _A1, _A2)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+template <typename _T>
+_T*
+function<_R(_A0, _A1, _A2)>::target()
+{
+    if (__f_ == 0)
+        return (_T*)0;
+    return (_T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class _A0, class _A1, class _A2>
+template <typename _T>
+const _T*
+function<_R(_A0, _A1, _A2)>::target() const
+{
+    if (__f_ == 0)
+        return (const _T*)0;
+    return (const _T*)__f_->target(typeid(_T));
+}
+
+template <class _F> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const function<_F>& __f, nullptr_t) {return !__f;}
+
+template <class _F> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const function<_F>& __f) {return !__f;}
+
+template <class _F> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const function<_F>& __f, nullptr_t) {return (bool)__f;}
+
+template <class _F> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const function<_F>& __f) {return (bool)__f;}
+
+template <class _F> 
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(function<_F>& __x, function<_F>& __y)
+{return __x.swap(__y);}
+
+template<class _Tp> struct __is_bind_expression : public false_type {};
+template<class _Tp> struct 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 is_placeholder
+    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
+
+namespace placeholders
+{
+
+template <int _N> 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 _N>
+struct __is_placeholder<placeholders::__ph<_N> >
+    : public integral_constant<int, _N> {};
+
+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(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(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 = get<_Indx>(__uj);
+    return __t;
+//    return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(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 _F, class _BoundArgs, class _TupleUj>
+struct __bind_return;
+
+template <class _F, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __ref_return
+    <
+        _F&,
+        typename __mu_return
+        <
+            _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _F, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __ref_return
+    <
+        _F&,
+        typename __mu_return
+        <
+            const _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __bind_return<_F, _BoundArgs, _Args>::type
+__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
+                _Args&& __args)
+{
+    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
+}
+
+template<class _F, class ..._BoundArgs> 
+class __bind
+{
+    _F __f_;
+    tuple<_BoundArgs...> __bound_args_;
+
+    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
+public:
+    template <class _G, class ..._BA>
+      explicit __bind(_G&& __f, _BA&& ...__bound_args)
+        : __f_(_STD::forward<_G>(__f)),
+          __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        typename __bind_return<_F, 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<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
+        operator()(_Args&& ...__args) const
+        {
+            return __apply_functor(__f_, __bound_args_, __indices(), 
+                                   tuple<_Args&&...>(__args...));
+        }
+};
+
+template<class _F, class ..._BoundArgs> 
+struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
+
+template<class _R, class _F, class ..._BoundArgs> 
+class __bind_r
+    : public __bind<_F, _BoundArgs...>
+{
+    typedef __bind<_F, _BoundArgs...> base;
+public:
+    typedef _R result_type;
+
+    template <class _G, class ..._BA>
+      explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
+        : base(_STD::forward<_G>(__f),
+               _STD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args)
+        {
+            return base::operator()(_STD::forward<_Args>(__args)...);
+        }
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args) const
+        {
+            return base::operator()(_STD::forward<_Args>(__args)...);
+        }
+};
+
+template<class _R, class _F, class ..._BoundArgs> 
+struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
+
+template<class _F, class ..._BoundArgs> 
+inline _LIBCPP_INLINE_VISIBILITY
+__bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...>
+bind(_F&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
+}
+
+template<class _R, class _F, class ..._BoundArgs> 
+inline _LIBCPP_INLINE_VISIBILITY
+__bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...>
+bind(_F&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
+}
+*/
+
+#endif
diff --git a/include/__functional_base b/include/__functional_base
new file mode 100644
index 0000000..d28c97f
--- /dev/null
+++ b/include/__functional_base
@@ -0,0 +1,523 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FUNCTIONAL_BASE
+#define _LIBCPP_FUNCTIONAL_BASE
+
+#include <__config>
+#include <type_traits>
+#include <typeinfo>
+#include <exception>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Arg, class _Result>
+struct unary_function
+{
+    typedef _Arg    argument_type;
+    typedef _Result result_type;
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+struct binary_function
+{
+    typedef _Arg1   first_argument_type;
+    typedef _Arg2   second_argument_type;
+    typedef _Result result_type;
+};
+
+template <class _Tp> struct hash;
+
+template <class _Tp>
+struct __has_result_type
+{
+private:
+    struct __two {char _; char __;};
+    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;
+};
+
+#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 _; char __;};
+    static __two __test(...);
+    template <class _A, class _R>
+        static unary_function<_A, _R>
+        __test(const volatile unary_function<_A, _R>*);
+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 _; char __;};
+    static __two __test(...);
+    template <class _A1, class _A2, class _R>
+        static binary_function<_A1, _A2, _R>
+        __test(const volatile binary_function<_A1, _A2, _R>*);
+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 _R>
+struct __weak_result_type<_R ()>
+{
+    typedef _R result_type;
+};
+
+template <class _R>
+struct __weak_result_type<_R (&)()>
+{
+    typedef _R result_type;
+};
+
+template <class _R>
+struct __weak_result_type<_R (*)()>
+{
+    typedef _R result_type;
+};
+
+// 1 argument case
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (&)(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (*)(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)()>
+    : public unary_function<_C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() const>
+    : public unary_function<const _C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() volatile>
+    : public unary_function<volatile _C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() const volatile>
+    : public unary_function<const volatile _C*, _R>
+{
+};
+
+// 2 argument case
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (*)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (&)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1)>
+    : public binary_function<_C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) const>
+    : public binary_function<const _C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) volatile>
+    : public binary_function<volatile _C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) const volatile>
+    : public binary_function<const volatile _C*, _A1, _R>
+{
+};
+
+// 3 or more arguments
+
+template <class _R, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_R (_A1, _A2, _A3, _A4...)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_R (&)(_A1, _A2, _A3, _A4...)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _A1, class _A2, class _A3, class ..._A4>
+struct __weak_result_type<_R (*)(_A1, _A2, _A3, _A4...)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) volatile>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2, class ..._A3>
+struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const volatile>
+{
+    typedef _R result_type;
+};
+
+// __invoke
+
+// first bullet
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...), _T1&& __t1, _Arg&& ...__arg)
+{
+    return (_STD::forward<_T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) const, _T1&& __t1, _Arg&& ...__arg)
+{
+    return (_STD::forward<_T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) volatile, _T1&& __t1, _Arg&& ...__arg)
+{
+    return (_STD::forward<_T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) const volatile, _T1&& __t1, _Arg&& ...__arg)
+{
+    return (_STD::forward<_T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+// second bullet
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...), _T1&& __t1, _Arg&& ...__arg)
+{
+    return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) const, _T1&& __t1, _Arg&& ...__arg)
+{
+    return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) volatile, _T1&& __t1, _Arg&& ...__arg)
+{
+    return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+template <class _R, class _T, class _T1, class ..._Param, class ..._Arg>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    sizeof...(_Param) == sizeof...(_Arg) &&
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_Param...) const volatile, _T1&& __t1, _Arg&& ...__arg)
+{
+    return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...);
+}
+
+// third bullet
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    typename __apply_cv<_T1, _R>::type&&
+>::type
+__invoke(_R _T::* __f, _T1&& __t1)
+{
+    return _STD::forward<_T1>(__t1).*__f;
+}
+
+// forth bullet
+
+template <class _T1, class _R, bool>
+struct __4th_helper
+{
+};
+
+template <class _T1, class _R>
+struct __4th_helper<_T1, _R, true>
+{
+    typedef typename __apply_cv<decltype(*_STD::declval<_T1>()), _R>::type type;
+};
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __4th_helper<_T1, _R,
+                      !is_base_of<_T,
+                                  typename remove_reference<_T1>::type
+                                 >::value
+                     >::type&&
+__invoke(_R _T::* __f, _T1&& __t1)
+{
+    return (*_STD::forward<_T1>(__t1)).*__f;
+}
+
+// fifth bullet
+
+template <class _F, class ..._T>
+inline _LIBCPP_INLINE_VISIBILITY
+typename result_of<_F(_T...)>::type
+__invoke(_F&& __f, _T&& ...__t)
+{
+    return _STD::forward<_F>(__f)(_STD::forward<_T>(__t)...);
+}
+
+template <class _Tp, class ..._Args>
+struct __invoke_return
+{
+    typedef decltype(__invoke(_STD::declval<_Tp>(), _STD::declval<_Args>()...)) type;
+};
+
+template <class _Tp>
+class 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) {}
+#ifdef _LIBCPP_MOVE
+    private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
+#endif
+
+    // access
+    _LIBCPP_INLINE_VISIBILITY operator type&    () const {return *__f_;}
+    _LIBCPP_INLINE_VISIBILITY          type& get() const {return *__f_;}
+
+    // invoke
+    template <class... _ArgTypes>
+       typename __invoke_return<type&, _ArgTypes...>::type
+          operator() (_ArgTypes&&... __args) const
+          {
+              return __invoke(get(), _STD::forward<_ArgTypes>(__args)...);
+          }
+};
+
+template <class _Tp> struct ____is_reference_wrapper : public false_type {};
+template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
+template <class _Tp> struct __is_reference_wrapper
+    : public ____is_reference_wrapper<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());
+}
+
+#ifdef _LIBCPP_MOVE
+template <class _Tp> void ref(const _Tp&& __t);// = delete; // LWG 688
+template <class _Tp> void cref(const _Tp&& __t);// = delete; // LWG 688
+#endif
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FUNCTIONAL_BASE
diff --git a/include/__functional_base_03 b/include/__functional_base_03
new file mode 100644
index 0000000..6b9a0c1
--- /dev/null
+++ b/include/__functional_base_03
@@ -0,0 +1,1084 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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 _; char __;};
+    static __two __test(...);
+    template <class _A, class _R>
+        static unary_function<_A, _R>
+        __test(const volatile unary_function<_A, _R>*);
+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 _; char __;};
+    static __two __test(...);
+    template <class _A1, class _A2, class _R>
+        static binary_function<_A1, _A2, _R>
+        __test(const volatile binary_function<_A1, _A2, _R>*);
+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 _R>
+struct __weak_result_type<_R ()>
+{
+    typedef _R result_type;
+};
+
+template <class _R>
+struct __weak_result_type<_R (&)()>
+{
+    typedef _R result_type;
+};
+
+template <class _R>
+struct __weak_result_type<_R (*)()>
+{
+    typedef _R result_type;
+};
+
+// 1 argument case
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (&)(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _A1>
+struct __weak_result_type<_R (*)(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)()>
+    : public unary_function<_C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() const>
+    : public unary_function<const _C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() volatile>
+    : public unary_function<volatile _C*, _R>
+{
+};
+
+template <class _R, class _C>
+struct __weak_result_type<_R (_C::*)() const volatile>
+    : public unary_function<const volatile _C*, _R>
+{
+};
+
+// 2 argument case
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (*)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _A1, class _A2>
+struct __weak_result_type<_R (&)(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1)>
+    : public binary_function<_C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) const>
+    : public binary_function<const _C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) volatile>
+    : public binary_function<volatile _C*, _A1, _R>
+{
+};
+
+template <class _R, class _C, class _A1>
+struct __weak_result_type<_R (_C::*)(_A1) const volatile>
+    : public binary_function<const volatile _C*, _A1, _R>
+{
+};
+
+// 3 or more arguments
+
+template <class _R, class _A1, class _A2, class _A3>
+struct __weak_result_type<_R (_A1, _A2, _A3)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _A1, class _A2, class _A3>
+struct __weak_result_type<_R (&)(_A1, _A2, _A3)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _A1, class _A2, class _A3>
+struct __weak_result_type<_R (*)(_A1, _A2, _A3)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2>
+struct __weak_result_type<_R (_C::*)(_A1, _A2)>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2>
+struct __weak_result_type<_R (_C::*)(_A1, _A2) const>
+{
+    typedef _R result_type;
+};
+
+template <class _R, class _C, class _A1, class _A2>
+struct __weak_result_type<_R (_C::*)(_A1, _A2) volatile>
+{
+    typedef _R 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 _R, class _C, class _A0>
+// struct __ref_return1_member_data1<_R _C::*, _A0, true>
+// {
+//     typedef typename __apply_cv<_A0, _R>::type& type;
+// };
+// 
+// template <class _R, class _C, class _A0>
+// struct __ref_return1_member_data1<_R _C::*, _A0, false>
+// {
+//     static _A0 __a;
+//     typedef typename __apply_cv<decltype(*__a), _R>::type& type;
+// };
+// 
+// template <class _Tp, class _A0>
+// struct __ref_return1_member_data;
+// 
+// template <class _R, class _C, class _A0>
+// struct __ref_return1_member_data<_R _C::*, _A0>
+//     : public __ref_return1_member_data1<_R _C::*, _A0,
+//                 is_same<typename remove_cv<_C>::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 _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(), _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0), _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() const, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) const, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() volatile, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) volatile, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() const volatile, _T1& __t1)
+{
+    return (__t1.*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0)
+{
+    return (__t1.*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1)
+{
+    return (__t1.*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return (__t1.*__f)(__a0, __a1, __a2);
+}
+
+// second bullet
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(), _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0), _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() const, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) const, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() volatile, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) volatile, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)() const volatile, _T1 __t1)
+{
+    return ((*__t1).*__f)();
+}
+
+template <class _R, class _T, class _T1, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0)
+{
+    return ((*__t1).*__f)(__a0);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1)
+{
+    return ((*__t1).*__f)(__a0, __a1);
+}
+
+template <class _R, class _T, class _T1, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    _R
+>::type
+__invoke(_R (_T::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return ((*__t1).*__f)(__a0, __a1, __a2);
+}
+
+// third bullet
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_base_of<_T, typename remove_reference<_T1>::type>::value,
+    typename __apply_cv<_T1, _R>::type&
+>::type
+__invoke(_R _T::* __f, _T1& __t1)
+{
+    return __t1.*__f;
+}
+
+template <class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__invoke(_R _T::*)
+{
+}
+
+// template <class _D, class _R, class _T, class _T1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     is_base_of<_T, typename remove_reference<_T1>::type>::value,
+//     typename __ref_return1<_R _T::*, _T1>::type
+// >::type
+// __invoke(_R _T::* __f, _T1& __t1)
+// {
+//     return __t1.*__f;
+// }
+
+// forth bullet
+
+template <class _T1, class _R, bool>
+struct __4th_helper
+{
+};
+
+template <class _T1, class _R>
+struct __4th_helper<_T1, _R, true>
+{
+    typedef typename __apply_cv<decltype(*_STD::declval<_T1>()), _R>::type type;
+};
+
+template <class _R, class _T, class _T1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __4th_helper<_T1, _R,
+                      !is_base_of<_T,
+                                  typename remove_reference<_T1>::type
+                                 >::value
+                     >::type&
+__invoke(_R _T::* __f, _T1& __t1)
+{
+    return (*__t1).*__f;
+}
+
+// template <class _D, class _R, class _T, class _T1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     !is_base_of<_T, typename remove_reference<_T1>::type>::value,
+//     typename __ref_return1<_R _T::*, _T1>::type
+// >::type
+// __invoke(_R _T::* __f, _T1 __t1)
+// {
+//     return (*__t1).*__f;
+// }
+
+// fifth bullet
+
+template <class _F>
+inline _LIBCPP_INLINE_VISIBILITY
+typename result_of<_F()>::type
+__invoke(_F __f)
+{
+    return __f();
+}
+
+template <class _F, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+typename result_of<_F(_A0)>::type
+__invoke(_F __f, _A0& __a0)
+{
+    return __f(__a0);
+}
+
+template <class _F, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+typename result_of<_F(_A0, _A1)>::type
+__invoke(_F __f, _A0& __a0, _A1& __a1)
+{
+    return __f(__a0, __a1);
+}
+
+template <class _F, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename result_of<_F(_A0, _A1, _A2)>::type
+__invoke(_F __f, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return __f(__a0, __a1, __a2);
+}
+
+// template <class _R, class _F>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _R
+// __invoke(_F& __f)
+// {
+//     return __f();
+// }
+// 
+// template <class _R, class _F, class _A0>
+// inline _LIBCPP_INLINE_VISIBILITY
+// typename enable_if
+// <
+//     !is_member_pointer<_F>::value,
+//     _R
+// >::type
+// __invoke(_F& __f, _A0& __a0)
+// {
+//     return __f(__a0);
+// }
+// 
+// template <class _R, class _F, class _A0, class _A1>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _R
+// __invoke(_F& __f, _A0& __a0, _A1& __a1)
+// {
+//     return __f(__a0, __a1);
+// }
+// 
+// template <class _R, class _F, class _A0, class _A1, class _A2>
+// inline _LIBCPP_INLINE_VISIBILITY
+// _R
+// __invoke(_F& __f, _A0& __a0, _A1& __a1, _A2& __a2)
+// {
+//     return __f(__a0, __a1, __a2);
+// }
+
+template <class _Tp>
+struct __has_type
+{
+private:
+    struct __two {char _; char __;};
+    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 _F, bool = __has_result_type<__weak_result_type<_F> >::value>
+struct __invoke_return
+{
+    typedef typename __weak_result_type<_F>::result_type type;
+};
+
+template <class _F>
+struct __invoke_return<_F, false>
+{
+    typedef decltype(__invoke(_STD::declval<_F>())) type;
+};
+
+template <class _Tp, class _A0>
+struct __invoke_return0
+{
+    typedef decltype(__invoke(_STD::declval<_Tp>(), _STD::declval<_A0>())) type;
+};
+
+template <class _R, class _T, class _A0>
+struct __invoke_return0<_R _T::*, _A0>
+{
+    typedef typename __apply_cv<_A0, _R>::type& type;
+};
+
+template <class _R, class _T, class _A0>
+struct __invoke_return0<_R _T::*, _A0*>
+{
+    typedef typename __apply_cv<_A0, _R>::type& type;
+};
+
+template <class _Tp, class _A0, class _A1>
+struct __invoke_return1
+{
+    typedef decltype(__invoke(_STD::declval<_Tp>(), _STD::declval<_A0>(),
+                                                    _STD::declval<_A1>())) type;
+};
+
+template <class _Tp, class _A0, class _A1, class _A2>
+struct __invoke_return2
+{
+    typedef decltype(__invoke(_STD::declval<_Tp>(), _STD::declval<_A0>(),
+                                                    _STD::declval<_A1>(),
+                                                    _STD::declval<_A2>())) type;
+};
+
+template <class _Tp>
+class 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
+
+    typename __invoke_return<type&>::type
+       operator() () const
+       {
+           return __invoke(get());
+       }
+
+    template <class _A0>
+       typename __invoke_return0<type&, _A0>::type
+          operator() (_A0& __a0) const
+          {
+              return __invoke(get(), __a0);
+          }
+
+    template <class _A0, class _A1>
+       typename __invoke_return1<type&, _A0, _A1>::type
+          operator() (_A0& __a0, _A1& __a1) const
+          {
+              return __invoke(get(), __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(get(), __a0, __a1, __a2);
+          }
+};
+
+template <class _Tp> struct ____is_reference_wrapper : public false_type {};
+template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
+template <class _Tp> struct __is_reference_wrapper
+    : public ____is_reference_wrapper<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
diff --git a/include/__hash_table b/include/__hash_table
new file mode 100644
index 0000000..f1327d5
--- /dev/null
+++ b/include/__hash_table
@@ -0,0 +1,1761 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+size_t __next_prime(size_t);
+
+template <class _NodePtr>
+struct __hash_node_base
+{
+    typedef __hash_node_base __first_node;
+    typedef _NodePtr pointer;
+
+    pointer    __next_;
+
+    __hash_node_base() : __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_;
+};
+
+template <class, class, class, class> class __hash_table;
+template <class> class __hash_const_iterator;
+template <class> class __hash_map_iterator;
+template <class> class __hash_map_const_iterator;
+template <class, class, class, class, class> class unordered_map;
+
+template <class _NodePtr>
+class __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;
+
+    __hash_iterator() {}
+
+    reference operator*() const {return __node_->__value_;}
+    pointer operator->() const {return addressof(__node_->__value_);}
+
+    __hash_iterator& operator++()
+    {
+        __node_ = __node_->__next_;
+        return *this;
+    }
+
+    __hash_iterator operator++(int)
+    {
+        __hash_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
+        {return __x.__node_ == __y.__node_;}
+    friend bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
+        {return __x.__node_ != __y.__node_;}
+
+private:
+    __hash_iterator(__node_pointer __node)
+        : __node_(__node)
+        {}
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class __hash_const_iterator;
+    template <class> friend class __hash_map_iterator;
+    template <class, class, class, class, class> friend class unordered_map;
+    template <class, class, class, class, class> friend class unordered_multimap;
+};
+
+template <class _ConstNodePtr>
+class __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;
+
+    __hash_const_iterator() {}
+    __hash_const_iterator(const __non_const_iterator& __x)
+        : __node_(__x.__node_)
+        {}
+
+    reference operator*() const {return __node_->__value_;}
+    pointer operator->() const {return addressof(__node_->__value_);}
+
+    __hash_const_iterator& operator++()
+    {
+        __node_ = __node_->__next_;
+        return *this;
+    }
+
+    __hash_const_iterator operator++(int)
+    {
+        __hash_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
+        {return __x.__node_ == __y.__node_;}
+    friend bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
+        {return __x.__node_ != __y.__node_;}
+
+private:
+    __hash_const_iterator(__node_pointer __node)
+        : __node_(__node)
+        {}
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class __hash_map_const_iterator;
+    template <class, class, class, class, class> friend class unordered_map;
+    template <class, class, class, class, class> friend class unordered_multimap;
+};
+
+template <class> class __hash_const_local_iterator;
+
+template <class _NodePtr>
+class __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;
+
+    __hash_local_iterator() {}
+
+    reference operator*() const {return __node_->__value_;}
+    pointer operator->() const {return &__node_->__value_;}
+
+    __hash_local_iterator& operator++()
+    {
+        __node_ = __node_->__next_;
+        if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_)
+            __node_ = nullptr;
+        return *this;
+    }
+
+    __hash_local_iterator operator++(int)
+    {
+        __hash_local_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
+        {return __x.__node_ == __y.__node_;}
+    friend bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
+        {return __x.__node_ != __y.__node_;}
+
+private:
+    __hash_local_iterator(__node_pointer __node, size_t __bucket,
+                          size_t __bucket_count)
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class __hash_const_local_iterator;
+    template <class> friend class __hash_map_iterator;
+};
+
+template <class _ConstNodePtr>
+class __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;
+
+    __hash_const_local_iterator() {}
+    __hash_const_local_iterator(const __non_const_iterator& __x)
+        : __node_(__x.__node_),
+          __bucket_(__x.__bucket_),
+          __bucket_count_(__x.__bucket_count_)
+        {}
+
+    reference operator*() const {return __node_->__value_;}
+    pointer operator->() const {return &__node_->__value_;}
+
+    __hash_const_local_iterator& operator++()
+    {
+        __node_ = __node_->__next_;
+        if (__node_ != nullptr && __node_->__hash_ % __bucket_count_ != __bucket_)
+            __node_ = nullptr;
+        return *this;
+    }
+
+    __hash_const_local_iterator operator++(int)
+    {
+        __hash_const_local_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
+        {return __x.__node_ == __y.__node_;}
+    friend bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
+        {return __x.__node_ != __y.__node_;}
+
+private:
+    __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
+                                size_t __bucket_count)
+        : __node_(__node),
+          __bucket_(__bucket),
+          __bucket_count_(__bucket_count)
+        {
+            if (__node_ != nullptr)
+                __node_ = __node_->__next_;
+        }
+
+    template <class, class, class, class> friend class __hash_table;
+    template <class> friend class __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;
+
+    __bucket_list_deallocator()
+        : __data_(0) {}
+    __bucket_list_deallocator(const allocator_type& __a, size_type __size)
+        : __data_(__size, __a) {}
+
+#ifdef _LIBCPP_MOVE
+
+    __bucket_list_deallocator(__bucket_list_deallocator&& __x)
+        : __data_(_STD::move(__x.__data_))
+    {
+        __x.size() = 0;
+    }
+
+#endif
+
+    size_type& size()       {return __data_.first();}
+    size_type  size() const {return __data_.first();}
+
+    allocator_type&       __alloc()       {return __data_.second();}
+    const allocator_type& __alloc() const {return __data_.second();}
+
+    void operator()(pointer __p)
+    {
+        __alloc_traits::deallocate(__alloc(), __p, size());
+    }
+};
+
+template <class> 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;
+
+    explicit __hash_node_destructor(allocator_type& __na)
+        : __na_(__na),
+          __value_constructed(false)
+        {}
+
+    void operator()(pointer __p)
+    {
+        if (__value_constructed)
+            __alloc_traits::destroy(__na_, 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 __node::__first_node                            __first_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::const_pointer    __node_const_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 ---
+
+    size_type& size()       {return __p2_.first();}
+public:
+    size_type  size() const {return __p2_.first();}
+
+          hasher& hash_function()       {return __p2_.second();}
+    const hasher& hash_function() const {return __p2_.second();}
+
+    float& max_load_factor()       {return __p3_.first();}
+    float  max_load_factor() const {return __p3_.first();}
+
+          key_equal& key_eq()       {return __p3_.second();}
+    const key_equal& key_eq() const {return __p3_.second();}
+
+    __node_allocator&       __node_alloc()       {return __p1_.second();}
+    const __node_allocator& __node_alloc() const {return __p1_.second();}
+
+public:
+    typedef __hash_iterator<__node_pointer>                   iterator;
+    typedef __hash_const_iterator<__node_const_pointer>       const_iterator;
+    typedef __hash_local_iterator<__node_pointer>             local_iterator;
+    typedef __hash_const_local_iterator<__node_const_pointer> const_local_iterator;
+
+    __hash_table();
+    __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);
+#ifdef _LIBCPP_MOVE
+    __hash_table(__hash_table&& __u);
+    __hash_table(__hash_table&& __u, const allocator_type& __a);
+#endif
+    ~__hash_table();
+
+    __hash_table& operator=(const __hash_table& __u);
+#ifdef _LIBCPP_MOVE
+    __hash_table& operator=(__hash_table&& __u);
+#endif
+    template <class _InputIterator>
+        void __assign_unique(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        void __assign_multi(_InputIterator __first, _InputIterator __last);
+
+    size_type max_size() const
+    {
+        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);
+
+#ifdef _LIBCPP_MOVE
+    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
+
+    pair<iterator, bool> __insert_unique(const value_type& __x);
+
+#ifdef _LIBCPP_MOVE
+    template <class _P>
+        pair<iterator, bool> __insert_unique(_P&& __x);
+#endif
+
+#ifdef _LIBCPP_MOVE
+    template <class _P>
+        iterator __insert_multi(_P&& __x);
+    template <class _P>
+        iterator __insert_multi(const_iterator __p, _P&& __x);
+#else
+    iterator __insert_multi(const value_type& __x);
+    iterator __insert_multi(const_iterator __p, const value_type& __x);
+#endif
+
+    void clear();
+    void rehash(size_type __n);
+    void reserve(size_type __n)
+        {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
+    size_type bucket_count() const
+    {
+        return __bucket_list_.get_deleter().size();
+    }
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin() const;
+    const_iterator end() const;
+
+    template <class _Key>
+        size_type bucket(const _Key& __k) const
+            {return 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> _D;
+    typedef unique_ptr<__node, _D> __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);
+
+    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);
+
+    size_type max_bucket_count() const
+        {return __bucket_list_.get_deleter().__alloc().max_size();}
+    size_type bucket_size(size_type __n) const;
+    float load_factor() const
+    {
+        size_type __bc = bucket_count();
+        return __bc != 0 ? (float)size() / __bc : 0.f;
+    }
+    void max_load_factor(float __mlf)
+        {max_load_factor() = _STD::max(__mlf, load_factor());}
+
+    local_iterator       begin(size_type __n)
+        {return local_iterator(__bucket_list_[__n], __n, bucket_count());}
+    local_iterator       end(size_type __n)
+        {return local_iterator(nullptr, __n, bucket_count());}
+    const_local_iterator cbegin(size_type __n) const
+        {return const_local_iterator(__bucket_list_[__n], __n, bucket_count());}
+    const_local_iterator cend(size_type __n) const
+        {return const_local_iterator(nullptr, __n, bucket_count());}
+private:
+    void __rehash(size_type __n);
+
+#ifdef _LIBCPP_MOVE
+    template <class ..._Args>
+        __node_holder __construct_node(_Args&& ...__args);
+    __node_holder __construct_node(value_type&& __v, size_t __hash);
+#else
+    __node_holder __construct_node(const value_type& __v);
+#endif
+    __node_holder __construct_node(const value_type& __v, size_t __hash);
+
+    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);
+    void __copy_assign_alloc(const __hash_table& __u, false_type) {}
+
+    void __move_assign(__hash_table& __u, false_type);
+    void __move_assign(__hash_table& __u, true_type);
+    void __move_assign_alloc(__hash_table& __u)
+        {__move_assign_alloc(__u, integral_constant<bool,
+             __node_traits::propagate_on_container_move_assignment::value>());}
+    void __move_assign_alloc(__hash_table& __u, true_type)
+    {
+        __bucket_list_.get_deleter().__alloc() =
+                _STD::move(__u.__bucket_list_.get_deleter().__alloc());
+        __node_alloc() = _STD::move(__u.__node_alloc());
+    }
+    void __move_assign_alloc(__hash_table&, false_type) {}
+
+    template <class _A>
+    static
+    void
+    __swap_alloc(_A& __x, _A& __y)
+    {
+        __swap_alloc(__x, __y,
+                     integral_constant<bool,
+                        allocator_traits<_A>::propagate_on_container_swap::value
+                                      >());
+    }
+
+    template <class _A>
+    static
+    void
+    __swap_alloc(_A& __x, _A& __y, true_type)
+    {
+        using _STD::swap;
+        swap(__x, __y);
+    }
+
+    template <class _A>
+    static
+    void
+    __swap_alloc(_A& __x, _A& __y, false_type) {}
+
+    void __deallocate(__node_pointer __np);
+    __node_pointer __detach();
+};
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
+    : __p2_(0),
+      __p3_(1.0f)
+{
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+__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_)
+{
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
+    : __bucket_list_(_STD::move(__u.__bucket_list_)),
+      __p1_(_STD::move(__u.__p1_)),
+      __p2_(_STD::move(__u.__p2_)),
+      __p3_(_STD::move(__u.__p3_))
+{
+    if (size() > 0)
+    {
+        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
+            static_cast<__node_pointer>(addressof(__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, _STD::move(__u.hash_function())),
+      __p3_(_STD::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_[__p1_.first().__next_->__hash_ % bucket_count()] =
+                static_cast<__node_pointer>(addressof(__p1_.first()));
+            size() = __u.size();
+            __u.size() = 0;
+        }
+    }
+}
+
+#endif
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
+{
+    __deallocate(__p1_.first().__next_);
+}
+
+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)
+{
+    __node_allocator& __na = __node_alloc();
+    while (__np != nullptr)
+    {
+        __node_pointer __next = __np->__next_;
+        __node_traits::destroy(__na, 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()
+{
+    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;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
+        __hash_table& __u, true_type)
+{
+    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() = _STD::move(__u.hash_function());
+    max_load_factor() = __u.max_load_factor();
+    key_eq() = _STD::move(__u.key_eq());
+    __p1_.first().__next_ = __u.__p1_.first().__next_;
+    if (size() > 0)
+    {
+        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
+            static_cast<__node_pointer>(addressof(__p1_.first()));
+        __u.__p1_.first().__next_ = nullptr;
+        __u.size() = 0;
+    }
+}
+
+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() = _STD::move(__u.hash_function());
+        key_eq() = _STD::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
+                const_iterator __i = __u.begin();
+                while (__cache != nullptr && __u.size() != 0)
+                {
+                    __cache->__value_ = _STD::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
+            __deallocate(__cache);
+        }
+        const_iterator __i = __u.begin();
+        while (__u.size() != 0)
+        {
+            __node_holder __h =
+                    __construct_node(_STD::move(__u.remove(__i++)->__value_));
+            __node_insert_multi(__h.get());
+            __h.release();
+        }
+    }
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+__hash_table<_Tp, _Hash, _Equal, _Alloc>&
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
+{
+    __move_assign(__u, integral_constant<bool,
+                  __node_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+#endif
+
+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
+            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
+        __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
+            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
+        __deallocate(__cache);
+    }
+    for (; __first != __last; ++__first)
+        __insert_multi(*__first);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin()
+{
+    return iterator(__p1_.first().__next_);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::end()
+{
+    return iterator(nullptr);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const
+{
+    return const_iterator(__p1_.first().__next_);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+inline
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const
+{
+    return const_iterator(nullptr);
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear()
+{
+    if (size() > 0)
+    {
+        __deallocate(__p1_.first().__next_);
+        __p1_.first().__next_ = nullptr;
+        size_type __bc = bucket_count();
+        for (size_type __i; __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 = __nd->__hash_ % __bc;
+        __ndptr = __bucket_list_[__chash];
+        if (__ndptr != nullptr)
+        {
+            for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
+                                             __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(_STD::max<size_type>(2 * __bc + 1,
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+            __chash = __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>(addressof(__p1_.first()));
+            __nd->__next_ = __pn->__next_;
+            __pn->__next_ = __nd;
+            // fix up __bucket_list_
+            __bucket_list_[__chash] = __pn;
+            if (__nd->__next_ != nullptr)
+                __bucket_list_[__nd->__next_->__hash_ % __bc] = __nd;
+        }
+        else
+        {
+            __nd->__next_ = __pn->__next_;
+            __pn->__next_ = __nd;
+        }
+        __ndptr = __nd;
+        // increment size
+        ++size();
+        __inserted = true;
+    }
+__done:
+    return pair<iterator, bool>(iterator(__ndptr), __inserted);
+}
+
+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(_STD::max<size_type>(2 * __bc + 1,
+                       size_type(ceil(float(size() + 1) / max_load_factor()))));
+        __bc = bucket_count();
+    }
+    size_t __chash = __cp->__hash_ % __bc;
+    __node_pointer __pn = __bucket_list_[__chash];
+    if (__pn == nullptr)
+    {
+        __pn = static_cast<__node_pointer>(addressof(__p1_.first()));
+        __cp->__next_ = __pn->__next_;
+        __pn->__next_ = __cp;
+        // fix up __bucket_list_
+        __bucket_list_[__chash] = __pn;
+        if (__cp->__next_ != nullptr)
+            __bucket_list_[__cp->__next_->__hash_ % __bc] = __cp;
+    }
+    else
+    {
+        for (bool __found = false; __pn->__next_ != nullptr &&
+                                   __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 = __cp->__next_->__hash_ % __bc;
+            if (__nhash != __chash)
+                __bucket_list_[__nhash] = __cp;
+        }
+    }
+    ++size();
+    return iterator(__cp);
+}
+
+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 (__p != end() && key_eq()(*__p, __cp->__value_))
+    {
+        __node_pointer __np = const_cast<__node_pointer>(__p.__node_);
+        __cp->__hash_ = __np->__hash_;
+        size_type __bc = bucket_count();
+        if (size()+1 > __bc * max_load_factor() || __bc == 0)
+        {
+            rehash(_STD::max<size_type>(2 * __bc + 1,
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+        }
+        size_t __chash = __cp->__hash_ % __bc;
+        __node_pointer __pp = __bucket_list_[__chash];
+        while (__pp->__next_ != __np)
+            __pp = __pp->__next_;
+        __cp->__next_ = __np;
+        __pp->__next_ = __cp;
+        ++size();
+        return iterator(__cp);
+    }
+    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 = __hash % __bc;
+        __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                       __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(_STD::max<size_type>(2 * __bc + 1,
+                           size_type(ceil(float(size() + 1) / max_load_factor()))));
+            __bc = bucket_count();
+            __chash = __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>(addressof(__p1_.first()));
+            __h->__next_ = __pn->__next_;
+            __pn->__next_ = __h.get();
+            // fix up __bucket_list_
+            __bucket_list_[__chash] = __pn;
+            if (__h->__next_ != nullptr)
+                __bucket_list_[__h->__next_->__hash_ % __bc] = __h.get();
+        }
+        else
+        {
+            __h->__next_ = __pn->__next_;
+            __pn->__next_ = __h.get();
+        }
+        __nd = __h.release();
+        // increment size
+        ++size();
+        __inserted = true;
+    }
+__done:
+    return pair<iterator, bool>(iterator(__nd), __inserted);
+}
+
+#ifdef _LIBCPP_MOVE
+
+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(_STD::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(_STD::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)
+{
+    __node_holder __h = __construct_node(_STD::forward<_Args>(__args)...);
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _P>
+pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(_P&& __x)
+{
+    __node_holder __h = __construct_node(_STD::forward<_P>(__x));
+    pair<iterator, bool> __r = __node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+#endif
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _P>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(_P&& __x)
+{
+    __node_holder __h = __construct_node(_STD::forward<_P>(__x));
+    iterator __r = __node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _P>
+typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
+                                                         _P&& __x)
+{
+    __node_holder __h = __construct_node(_STD::forward<_P>(__x));
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+#else
+
+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)
+{
+    __node_holder __h = __construct_node(__x);
+    iterator __r = __node_insert_multi(__p, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+void
+__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
+{
+    __n = __next_prime(_STD::max<size_type>(__n, size() > 0));
+    size_type __bc = bucket_count();
+    if (__n > __bc)
+        __rehash(__n);
+    else
+    {
+        __n = _STD::max<size_type>
+              (
+                  __n,
+                  __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)
+{
+    __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>(addressof(__p1_.first())));
+        __node_pointer __cp = __pp->__next_;
+        if (__cp != nullptr)
+        {
+            size_type __chash = __cp->__hash_ % __nbc;
+            __bucket_list_[__chash] = __pp;
+            size_type __phash = __chash;
+            for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
+                                                           __cp = __pp->__next_)
+            {
+                __chash = __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 = __hash % __bc;
+        __node_pointer __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                       __nd->__hash_ % __bc == __chash;
+                                                           __nd = __nd->__next_)
+            {
+                if (key_eq()(__nd->__value_, __k))
+                    return iterator(__nd);
+            }
+        }
+    }
+    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 = __hash % __bc;
+        __node_const_pointer __nd = __bucket_list_[__chash];
+        if (__nd != nullptr)
+        {
+            for (__nd = __nd->__next_; __nd != nullptr &&
+                                           __nd->__hash_ % __bc == __chash;
+                                                           __nd = __nd->__next_)
+            {
+                if (key_eq()(__nd->__value_, __k))
+                    return const_iterator(__nd);
+            }
+        }
+        
+    }
+    return end();
+}
+
+#ifdef _LIBCPP_MOVE
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), _STD::forward<_Args>(__args)...);
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = hash_function()(__h->__value_);
+    __h->__next_ = nullptr;
+    return __h;
+}
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), _STD::move(__v));
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = __hash;
+    __h->__next_ = nullptr;
+    return _STD::move(__h);
+}
+
+#else
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), __v);
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = hash_function()(__h->__value_);
+    __h->__next_ = nullptr;
+    return _STD::move(__h);
+}
+
+#endif
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), __v);
+    __h.get_deleter().__value_constructed = true;
+    __h->__hash_ = __hash;
+    __h->__next_ = nullptr;
+    return _STD::move(__h);
+}
+
+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 = const_cast<__node_pointer>(__p.__node_);
+    iterator __r(__np);
+    ++__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)
+{
+    for (const_iterator __p = __first; __first != __last; __p = __first)
+    {
+        ++__first;
+        erase(__p);
+    }
+    __node_pointer __np = const_cast<__node_pointer>(__last.__node_);
+    return iterator (__np);
+}
+
+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)
+{
+    // current node
+    __node_pointer __cn = const_cast<__node_pointer>(__p.__node_);
+    size_type __bc = bucket_count();
+    size_t __chash = __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 == addressof(__p1_.first()) || __pn->__hash_ % __bc != __chash)
+    {
+        if (__cn->__next_ == nullptr || __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 = __cn->__next_->__hash_ % __bc;
+        if (__nhash != __chash)
+            __bucket_list_[__nhash] = __pn;
+    }
+    // remove __cn
+    __pn->__next_ = __cn->__next_;
+    __cn->__next_ = nullptr;
+    --size();
+    return __node_holder(__cn, _D(__node_alloc()));
+}
+
+template <class _Tp, class _Hash, class _Equal, class _Alloc>
+template <class _Key>
+inline
+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)
+{
+    {
+    __node_pointer_pointer __npp = __bucket_list_.release();
+    __bucket_list_.reset(__u.__bucket_list_.release());
+    __u.__bucket_list_.reset(__npp);
+    }
+    _STD::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());
+    _STD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
+    __p2_.swap(__u.__p2_);
+    __p3_.swap(__u.__p3_);
+    if (size() > 0)
+        __bucket_list_[__p1_.first().__next_->__hash_ % bucket_count()] =
+            static_cast<__node_pointer>(addressof(__p1_.first()));
+    if (__u.size() > 0)
+        __u.__bucket_list_[__u.__p1_.first().__next_->__hash_ % __u.bucket_count()] =
+            static_cast<__node_pointer>(addressof(__u.__p1_.first()));
+}
+
+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
+{
+    __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 &&
+                                   __np->__hash_ % __bc == __n;
+                                                    __np = __np->__next_, ++__r)
+            ;
+    }
+    return __r;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP__HASH_TABLE
diff --git a/include/__locale b/include/__locale
new file mode 100644
index 0000000..b767bb0
--- /dev/null
+++ b/include/__locale
@@ -0,0 +1,1433 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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 <xlocale.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class locale;
+
+template <class _Facet> bool has_facet(const locale&) throw();
+template <class _Facet> const _Facet& use_facet(const locale&);
+
+class locale
+{
+public:
+    // types:
+    class facet;
+    class 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() throw();
+    locale(const locale&) throw();
+    explicit locale(const char*);
+    explicit locale(const string&);
+    locale(const locale&, const char*, category);
+    locale(const locale&, const string&, category);
+    template <class _Facet> locale(const locale&, _Facet*);
+    locale(const locale&, const locale&, category);
+
+    ~locale() throw();
+
+    const locale& operator=(const locale&) throw();
+
+    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&) throw();
+    template <class _Facet> friend const _Facet& use_facet(const locale&);
+};
+
+class locale::facet
+    : public __shared_count
+{
+protected:
+    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();
+};
+
+class locale::id
+{
+    once_flag      __flag_;
+    int32_t        __id_;
+   
+    static int32_t __next_id;
+public:
+    id() {}
+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
+{
+    if (!_STD::has_facet<_Facet>(__other))
+        throw runtime_error("locale::combine: locale missing facet");
+    return locale(*this, &const_cast<_Facet&>(_STD::use_facet<_Facet>(__other)));
+}
+
+template <class _Facet>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+has_facet(const locale& __l) throw()
+{
+    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 collate
+    : public locale::facet
+{
+public:
+    typedef _CharT char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit collate(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    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);
+    }
+
+    string_type transform(const char_type* __lo, const char_type* __hi) const
+    {
+        return do_transform(__lo, __hi);
+    }
+
+    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) + *p;
+        size_t g = h & mask;
+        h ^= g | (g >> sr);
+    }
+    return static_cast<long>(h);
+}
+
+extern template class collate<char>;
+extern template class collate<wchar_t>;
+
+// template <class CharT> class collate_byname;
+
+template <class _CharT> class collate_byname;
+
+template <>
+class 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 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 _STD::use_facet<_STD::collate<_CharT> >(*this).compare(
+                                       __x.data(), __x.data() + __x.size(),
+                                       __y.data(), __y.data() + __y.size()) < 0;
+}
+
+// template <class charT> class ctype
+
+class ctype_base {
+public:
+    typedef __uint32_t mask;
+
+    static const mask space  = _CTYPE_S;
+    static const mask print  = _CTYPE_R;
+    static const mask cntrl  = _CTYPE_C;
+    static const mask upper  = _CTYPE_U;
+    static const mask lower  = _CTYPE_L;
+    static const mask alpha  = _CTYPE_A;
+    static const mask digit  = _CTYPE_D;
+    static const mask punct  = _CTYPE_P;
+    static const mask xdigit = _CTYPE_X;
+    static const mask blank  = _CTYPE_B;
+    static const mask alnum  = alpha | digit;
+    static const mask graph  = alnum | punct;
+
+    _LIBCPP_ALWAYS_INLINE ctype_base() {}
+};
+
+template <class _CharT> class ctype;
+
+template <>
+class 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 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_[__c] & __m : 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_[*__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_[*__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_[*__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;
+
+    static const size_t table_size = _CACHED_RUNES;
+    const mask* table() const throw() {return __tab_;}
+    static const mask* classic_table() throw();
+
+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 ctype_byname;
+
+template <>
+class 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 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 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 codecvt;
+
+// template <> class codecvt<char, char, mbstate_t>
+
+template <>
+class 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 throw()
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const throw()
+    {
+        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 throw()
+    {
+        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 throw();
+    virtual bool do_always_noconv() const throw();
+    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 throw();
+};
+
+// template <> class codecvt<wchar_t, char, mbstate_t>
+
+template <>
+class 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 throw()
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const throw()
+    {
+        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 throw()
+    {
+        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 throw();
+    virtual bool do_always_noconv() const throw();
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const throw();
+};
+
+// template <> class codecvt<char16_t, char, mbstate_t>
+
+template <>
+class 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 throw()
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const throw()
+    {
+        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 throw()
+    {
+        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 throw();
+    virtual bool do_always_noconv() const throw();
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const throw();
+};
+
+// template <> class codecvt<char32_t, char, mbstate_t>
+
+template <>
+class 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 throw()
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const throw()
+    {
+        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 throw()
+    {
+        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 throw();
+    virtual bool do_always_noconv() const throw();
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const throw();
+};
+
+// template <> class codecvt<char32_t, char, mbstate_t>
+
+template <>
+class codecvt<char32_t, char16_t, mbstate_t>
+    : public locale::facet,
+      public codecvt_base
+{
+public:
+    typedef char32_t  intern_type;
+    typedef char16_t  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 throw()
+    {
+        return do_encoding();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    bool always_noconv() const throw()
+    {
+        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 throw()
+    {
+        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 throw();
+    virtual bool do_always_noconv() const throw();
+    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
+    virtual int do_max_length() const throw();
+};
+
+// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
+
+template <class _InternT, class _ExternT, class _StateT>
+class codecvt_byname
+    : public codecvt<_InternT, _ExternT, _StateT>
+{
+public:
+    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
+        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
+    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()
+{
+}
+
+extern template class codecvt_byname<char, char, mbstate_t>;
+extern template class codecvt_byname<wchar_t, char, mbstate_t>;
+extern template class codecvt_byname<char16_t, char, mbstate_t>;
+extern template class codecvt_byname<char32_t, char, mbstate_t>;
+
+void __throw_runtime_error(const char*);
+
+template <size_t _N>
+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 _N>
+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 numpunct;
+
+template <>
+class 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 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 numpunct_byname;
+
+template <>
+class 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 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/include/__mutex_base b/include/__mutex_base
new file mode 100644
index 0000000..40d066d
--- /dev/null
+++ b/include/__mutex_base
@@ -0,0 +1,385 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MUTEX_BASE
+#define _LIBCPP___MUTEX_BASE
+
+#include <__config>
+#include <chrono>
+#include <system_error>
+#include <pthread.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class mutex
+{
+    pthread_mutex_t __m_;
+
+public:
+     mutex() {__m_ = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;}
+     ~mutex();
+
+private:
+    mutex(const mutex&);// = delete;
+    mutex& operator=(const mutex&);// = delete;
+
+public:
+    void lock();
+    bool try_lock();
+    void unlock();
+
+    typedef pthread_mutex_t* native_handle_type;
+    native_handle_type native_handle() {return &__m_;}
+};
+
+struct defer_lock_t {};
+struct try_to_lock_t {};
+struct adopt_lock_t {};
+
+//constexpr
+extern const
+defer_lock_t  defer_lock;
+
+//constexpr
+extern const
+try_to_lock_t try_to_lock;
+
+//constexpr
+extern const
+adopt_lock_t  adopt_lock;
+
+template <class _Mutex>
+class lock_guard
+{
+public:
+    typedef _Mutex mutex_type;
+
+private:
+    mutex_type& __m_;
+public:
+
+    explicit lock_guard(mutex_type& __m)
+        : __m_(__m) {__m_.lock();}
+    lock_guard(mutex_type& __m, adopt_lock_t)
+        : __m_(__m) {}
+    ~lock_guard() {__m_.unlock();}
+
+private:
+    lock_guard(lock_guard const&);// = delete;
+    lock_guard& operator=(lock_guard const&);// = delete;
+};
+
+template <class _Mutex>
+class unique_lock
+{
+public:
+    typedef _Mutex mutex_type;
+
+private:
+    mutex_type* __m_;
+    bool __owns_;
+
+public:
+    unique_lock() : __m_(nullptr), __owns_(false) {}
+    explicit unique_lock(mutex_type& __m)
+        : __m_(&__m), __owns_(true) {__m_->lock();}
+    unique_lock(mutex_type& __m, defer_lock_t)
+        : __m_(&__m), __owns_(false) {}
+    unique_lock(mutex_type& __m, try_to_lock_t)
+        : __m_(&__m), __owns_(__m.try_lock()) {}
+    unique_lock(mutex_type& __m, adopt_lock_t)
+        : __m_(&__m), __owns_(true) {}
+    template <class _Clock, class _Duration>
+        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>
+        unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
+            : __m_(&__m), __owns_(__m.try_lock_for(__d)) {}
+    ~unique_lock()
+    {
+        if (__owns_)
+            __m_->unlock();
+    }
+
+private:
+    unique_lock(unique_lock const&); // = delete;
+    unique_lock& operator=(unique_lock const&); // = delete;
+
+public:
+#ifdef _LIBCPP_MOVE
+    unique_lock(unique_lock&& __u)
+        : __m_(__u.__m_), __owns_(__u.__owns_)
+        {__u.__m_ = nullptr; __u.__owns_ = false;}
+    unique_lock& operator=(unique_lock&& __u)
+        {
+            if (__owns_)
+                __m_->unlock();
+            __m_ = __u.__m_;
+            __owns_ = __u.__owns_;
+            __u.__m_ = nullptr;
+            __u.__owns_ = false;
+            return *this;
+        }
+#endif
+
+    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();
+
+    void swap(unique_lock& __u)
+    {
+        _STD::swap(__m_, __u.__m_);
+        _STD::swap(__owns_, __u.__owns_);
+    }
+    mutex_type* release()
+    {
+        mutex_type* __m = __m_;
+        __m_ = nullptr;
+        __owns_ = false;
+        return __m;
+    }
+
+    bool owns_lock() const {return __owns_;}
+//    explicit
+        operator bool () const {return __owns_;}
+    mutex_type* mutex() const {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
+void
+swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) {__x.swap(__y);}
+
+struct cv_status
+{
+    enum _ {
+        no_timeout,
+        timeout
+    };
+
+    _ __v_;
+
+    cv_status(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+
+};
+
+class condition_variable
+{
+    pthread_cond_t __cv_;
+public:
+    condition_variable() {__cv_ = (pthread_cond_t)PTHREAD_COND_INITIALIZER;}
+    ~condition_variable();
+
+private:
+    condition_variable(const condition_variable&); // = delete;
+    condition_variable& operator=(const condition_variable&); // = delete;
+
+public:
+    void notify_one();
+    void notify_all();
+
+    void wait(unique_lock<mutex>& __lk);
+    template <class _Predicate>
+        void wait(unique_lock<mutex>& __lk, _Predicate __pred);
+
+    template <class _Duration>
+        cv_status
+        wait_until(unique_lock<mutex>& __lk,
+                   const chrono::time_point<chrono::system_clock, _Duration>& __t);
+
+    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;
+    native_handle_type native_handle() {return &__cv_;}
+
+private:
+    void __do_timed_wait(unique_lock<mutex>& __lk,
+                 chrono::time_point<chrono::system_clock, chrono::nanoseconds>);
+};
+
+template <class _To, class _Rep, class _Period>
+inline
+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;
+}
+
+template <class _Predicate>
+void
+condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred)
+{
+    while (!__pred())
+        wait(__lk);
+}
+
+template <class _Duration>
+cv_status
+condition_variable::wait_until(unique_lock<mutex>& __lk,
+                 const chrono::time_point<chrono::system_clock, _Duration>& __t)
+{
+    using namespace chrono;
+    typedef time_point<system_clock, nanoseconds> __nano_sys_tmpt;
+    __do_timed_wait(__lk,
+                  __nano_sys_tmpt(__ceil<nanoseconds>(__t.time_since_epoch())));
+    return system_clock::now() < __t ? cv_status::no_timeout :
+                                       cv_status::timeout;
+}
+
+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;
+    system_clock::time_point     __s_now = system_clock::now();
+    typename _Clock::time_point  __c_now = _Clock::now();
+    __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__t - __c_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;
+    system_clock::time_point     __s_now = system_clock::now();
+    monotonic_clock::time_point  __c_now = monotonic_clock::now();
+    __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));
+    return monotonic_clock::now() - __c_now < __d ? cv_status::no_timeout :
+                                                    cv_status::timeout;
+}
+
+template <class _Rep, class _Period, class _Predicate>
+inline
+bool
+condition_variable::wait_for(unique_lock<mutex>& __lk,
+                             const chrono::duration<_Rep, _Period>& __d,
+                             _Predicate __pred)
+{
+    return wait_until(__lk, chrono::monotonic_clock::now() + __d,
+                      _STD::move(__pred));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___MUTEX_BASE
diff --git a/include/__split_buffer b/include/__split_buffer
new file mode 100644
index 0000000..5eb04b6
--- /dev/null
+++ b/include/__split_buffer
@@ -0,0 +1,646 @@
+// -*- C++ -*-
+#ifndef _LIBCPP_SPLIT_BUFFER
+#define _LIBCPP_SPLIT_BUFFER
+
+#include <__config>
+#include <type_traits>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_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>
+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()         {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY const __alloc_rr&     __alloc() const   {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY pointer&              __end_cap()       {return __end_cap_.first();}
+    _LIBCPP_INLINE_VISIBILITY const pointer&        __end_cap() const {return __end_cap_.first();}
+
+    __split_buffer();
+    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();
+
+#ifdef _LIBCPP_MOVE
+    __split_buffer(__split_buffer&& __c);
+    __split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
+    __split_buffer& operator=(__split_buffer&& __c);
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY       iterator begin()       {return __begin_;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __begin_;}
+    _LIBCPP_INLINE_VISIBILITY       iterator end()         {return __end_;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end() const   {return __end_;}
+
+    _LIBCPP_INLINE_VISIBILITY void clear() {__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();
+    void push_front(const_reference __x);
+    void push_back(const_reference __x);
+#ifdef _LIBCPP_MOVE
+    void push_front(value_type&& __x);
+    void push_back(value_type&& __x);
+    template <class... _Args>
+        void emplace_back(_Args&&... __args);
+#endif
+
+    _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, false_type);
+        void __construct_at_end(size_type __n, true_type);
+    void __construct_at_end(size_type __n, const_reference __x);
+        void __construct_at_end(size_type __n, const_reference __x, false_type);
+        void __construct_at_end(size_type __n, const_reference __x, true_type);
+    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, has_trivial_destructor<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)
+        {__destruct_at_end(__new_last, has_trivial_destructor<value_type>());}
+        void __destruct_at_end(pointer __new_last, false_type);
+        void __destruct_at_end(pointer __new_last, true_type);
+
+    void swap(__split_buffer& __x);
+
+    bool __invariants() const;
+
+private:
+    void __move_assign_alloc(const __split_buffer& __c, true_type)
+        {
+            __alloc() = _STD::move(__c.__alloc());
+        }
+
+    void __move_assign_alloc(const __split_buffer& __c, false_type)
+        {}
+
+    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_swap::value>());}
+
+    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, false_type)
+        {}
+};
+
+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>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
+{
+    __construct_at_end(__n, __is_zero_default_constructible<value_type>());
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, false_type)
+{
+    __alloc_rr& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), value_type());
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, true_type)
+{
+    _STD::memset(this->__end_, 0, __n*sizeof(value_type));
+    this->__end_ += __n;
+}
+
+//  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>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
+{
+    __construct_at_end(__n, __x, integral_constant<bool, has_trivial_copy_constructor<value_type>::value &&
+                                                         has_trivial_copy_assign<value_type>::value>());
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, false_type)
+{
+    __alloc_rr& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), __x);
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, true_type)
+{
+    _STD::fill_n(this->__end_, __n, __x);
+    this->__end_ += __n;
+}
+
+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 = _STD::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(),
+                        _STD::__to_raw_pointer(__buf.__end_), _STD::move(*__p));
+            swap(__buf);
+        }
+        __alloc_traits::construct(__a, _STD::__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, _STD::__to_raw_pointer(this->__end_), *__first);
+        ++this->__end_;
+    }
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
+{
+    while (__begin_ < __new_begin)
+        __alloc_traits::destroy(__alloc(), __begin_++);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
+{
+    __begin_ = __new_begin;
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type)
+{
+    while (__new_last < __end_)
+        __alloc_traits::destroy(__alloc(), --__end_);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type)
+{
+    __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_(0, __a)
+{
+    __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
+    __begin_ = __end_ = __first_ + __start;
+    __end_cap() = __first_ + __cap;
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+__split_buffer<_Tp, _Allocator>::__split_buffer()
+    : __first_(0), __begin_(0), __end_(0), __end_cap_(0)
+{
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
+    : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a)
+{
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
+    : __first_(0), __begin_(0), __end_(0), __end_cap_(0, __a)
+{
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::~__split_buffer()
+{
+    clear();
+    if (__first_)
+        __alloc_traits::deallocate(__alloc(), __first_, capacity());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
+    : __first_(_STD::move(__c.__first_)),
+      __begin_(_STD::move(__c.__begin_)),
+      __end_(_STD::move(__c.__end_)),
+      __end_cap_(_STD::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> _I;
+        __construct_at_end(_I(__c.begin()), _I(__c.end()));
+    }
+}
+
+template <class _Tp, class _Allocator>
+__split_buffer<_Tp, _Allocator>&
+__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
+{
+    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
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
+{
+    _STD::swap(__first_, __x.__first_);
+    _STD::swap(__begin_, __x.__begin_);
+    _STD::swap(__end_, __x.__end_);
+    _STD::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_));
+        _STD::swap(__first_, __t.__first_);
+        _STD::swap(__begin_, __t.__begin_);
+        _STD::swap(__end_, __t.__end_);
+        _STD::swap(__end_cap(), __t.__end_cap());
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+__split_buffer<_Tp, _Allocator>::shrink_to_fit()
+{
+    if (capacity() > size())
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            __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_);
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+        }
+#endif
+    }
+}
+
+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_ = _STD::move_backward(__begin_, __end_, __end_ + __d);
+            __end_ += __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 2) / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _STD::__to_raw_pointer(__begin_-1), __x);
+    --__begin_;
+}
+
+#ifdef _LIBCPP_MOVE
+
+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_ = _STD::move_backward(__begin_, __end_, __end_ + __d);
+            __end_ += __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * (__end_cap() - __first_), 1);
+            __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 2) / 4, __alloc());
+            __t.__construct_at_end(move_iterator<pointer>(__begin_),
+                                   move_iterator<pointer>(__end_));
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _STD::__to_raw_pointer(__begin_-1),
+            _STD::move(__x));
+    --__begin_;
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+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_ = _STD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * (__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_));
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _STD::__to_raw_pointer(__end_), __x);
+    ++__end_;
+}
+
+#ifdef _LIBCPP_MOVE
+
+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_ = _STD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * (__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_));
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _STD::__to_raw_pointer(__end_),
+            _STD::move(__x));
+    ++__end_;
+}
+
+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_ = _STD::move(__begin_, __end_, __begin_ - __d);
+            __begin_ -= __d;
+        }
+        else
+        {
+            size_type __c = max<size_type>(2 * (__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_));
+            _STD::swap(__first_, __t.__first_);
+            _STD::swap(__begin_, __t.__begin_);
+            _STD::swap(__end_, __t.__end_);
+            _STD::swap(__end_cap(), __t.__end_cap());
+        }
+    }
+    __alloc_traits::construct(__alloc(), _STD::__to_raw_pointer(__end_),
+                              _STD::forward<_Args>(__args)...);
+    ++__end_;
+}
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_SPLIT_BUFFER
+
+// hh 080222 Created
diff --git a/include/__sso_allocator b/include/__sso_allocator
new file mode 100644
index 0000000..6f5a75f
--- /dev/null
+++ b/include/__sso_allocator
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___SSO_ALLOCATOR
+#define _LIBCPP___SSO_ALLOCATOR
+
+#include <__config>
+#include <type_traits>
+#include <new>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, size_t _N> class _LIBCPP_HIDDEN __sso_allocator;
+
+template <size_t _N>
+class _LIBCPP_HIDDEN __sso_allocator<void, _N>
+{
+public:
+    typedef const void*       const_pointer;
+    typedef void              value_type;
+};
+
+template <class _Tp, size_t _N>
+class _LIBCPP_HIDDEN __sso_allocator
+{
+    typename aligned_storage<sizeof(_Tp) * _N>::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, _N>&) throw()
+         : __allocated_(false) {}
+private:
+    __sso_allocator& operator=(const __sso_allocator&);
+public:
+    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _N>::const_pointer = 0)
+    {
+        if (!__allocated_ && __n <= _N)
+        {
+            __allocated_ = true;
+            return (pointer)&buf_;
+        }
+        return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));
+    }
+    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
+    {
+        if (__p == (pointer)&buf_)
+            __allocated_ = false;
+        else
+            ::operator delete(__p);
+    }
+    _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
+
+    bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}
+    bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___SSO_ALLOCATOR
diff --git a/include/__std_stream b/include/__std_stream
new file mode 100644
index 0000000..6a1fc06
--- /dev/null
+++ b/include/__std_stream
@@ -0,0 +1,313 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___STD_STREAM
+#define _LIBCPP___STD_STREAM
+
+#include <__config>
+#include <ostream>
+#include <istream>
+#include <__locale>
+#include <cstdio>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+static const unsigned __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;
+
+    explicit __stdinbuf(FILE* __fp);
+
+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_;
+    bool __always_noconv_;
+
+    __stdinbuf(const __stdinbuf&);
+    __stdinbuf& operator=(const __stdinbuf&);
+
+    int_type __getchar(bool __consume);
+};
+
+template <class _CharT>
+__stdinbuf<_CharT>::__stdinbuf(FILE* __fp)
+    : __file_(__fp),
+      __st_()
+{
+    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)
+{
+    char __extbuf[__limit];
+    int __nread = max(1, __encoding_);
+    for (int __i = 0; __i < __nread; ++__i)
+    {
+        char __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 _STD::codecvt_base::ok:
+                break;
+            case codecvt_base::partial:
+                __st_ = __sv_st;
+                if (__nread == sizeof(__extbuf))
+                    return traits_type::eof();
+                {
+                    char __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 _STD::codecvt_base::noconv:
+                __1buf = static_cast<char_type>(__extbuf[0]);
+                break;
+            }
+        } while (__r == _STD::codecvt_base::partial);
+    }
+    if (!__consume)
+    {
+        for (int __i = __nread; __i > 0;)
+        {
+            if (ungetc(__extbuf[--__i], __file_) == EOF)
+                return traits_type::eof();
+        }
+    }
+    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()))
+        return __c;
+    char __extbuf[__limit];
+    char* __enxt;
+    const char_type __ci = traits_type::to_char_type(__c);
+    const char_type* __inxt;
+    switch (__cv_->out(__st_, &__ci, &__ci + 1, __inxt,
+                              __extbuf, __extbuf + sizeof(__extbuf), __enxt))
+    {
+    case _STD::codecvt_base::ok:
+        break;
+    case _STD::codecvt_base::noconv:
+        __extbuf[0] = static_cast<char>(__c);
+        __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();
+	return traits_type::not_eof(__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;
+
+    explicit __stdoutbuf(FILE* __fp);
+
+protected:
+    virtual int_type overflow (int_type __c = traits_type::eof());
+    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)
+    : __file_(__fp),
+      __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
+      __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()))
+    {
+        this->setp(&__1buf, &__1buf+1);
+        *this->pptr() = traits_type::to_char_type(__c);
+        this->pbump(1);
+        if (__always_noconv_)
+        {
+            if (fwrite(this->pbase(), sizeof(char_type), 1, __file_) != 1)
+                return traits_type::eof();
+        }
+        else
+        {
+            char* __extbe = __extbuf;
+            codecvt_base::result __r;
+            do
+            {
+                const char_type* __e;
+                __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
+                                        __extbuf,
+                                        __extbuf + sizeof(__extbuf),
+                                        __extbe);
+                if (__e == this->pbase())
+                    return traits_type::eof();
+                if (__r == codecvt_base::noconv)
+                {
+                    if (fwrite(this->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)
+                    {
+                        this->setp((char_type*)__e, this->pptr());
+                        this->pbump(this->epptr() - this->pbase());
+                    }
+                }
+                else
+                    return traits_type::eof();
+            } while (__r == codecvt_base::partial);
+        }
+        this->setp(0, 0);
+    }
+    return traits_type::not_eof(__c);
+}
+
+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/include/__tree b/include/__tree
new file mode 100644
index 0000000..8f8efc2
--- /dev/null
+++ b/include/__tree
@@ -0,0 +1,2170 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TREE
+#define _LIBCPP___TREE
+
+#include <__config>
+#include <iterator>
+#include <memory>
+#include <stdexcept>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class, class, class> class __tree;
+template <class, class, class> class __tree_iterator;
+template <class, class, class> class __tree_const_iterator;
+template <class, class, class, class> class map;
+template <class, class, class, class> class multimap;
+template <class, class, class> class set;
+template <class, class, class> class 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
+bool
+__tree_is_left_child(_NodePtr __x)
+{
+    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
+_NodePtr
+__tree_min(_NodePtr __x)
+{
+    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
+_NodePtr
+__tree_max(_NodePtr __x)
+{
+    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)
+{
+    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)
+{
+    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)
+{
+    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)
+{
+    _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)
+{
+    _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)
+{
+    __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)
+{
+    // __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> 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;
+
+    explicit __tree_node_destructor(allocator_type& __na)
+        : __na_(__na),
+          __value_constructed(false)
+        {}
+
+    void operator()(pointer __p)
+    {
+        if (__value_constructed)
+            __alloc_traits::destroy(__na_, 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_;
+
+    __tree_end_node() : __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_;
+
+    __tree_node_base() : __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_;
+
+#ifdef _LIBCPP_MOVE
+    template <class ..._Args>
+        explicit __tree_node(_Args&& ...__args)
+            : __value_(_STD::forward<_Args>(__args)...) {}
+#else
+    explicit __tree_node(const value_type& __v)
+            : __value_(__v) {}
+#endif
+};
+
+template <class> class __map_iterator;
+template <class> class __map_const_iterator;
+
+template <class _Tp, class _NodePtr, class _DiffType>
+class __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;
+
+    __tree_iterator() {}
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &__ptr_->__value_;}
+
+    __tree_iterator& operator++()
+        {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    __tree_iterator operator++(int)
+        {__tree_iterator __t(*this); ++(*this); return __t;}
+
+    __tree_iterator& operator--()
+        {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    __tree_iterator operator--(int)
+        {__tree_iterator __t(*this); --(*this); return __t;}
+
+    friend bool operator==(const __tree_iterator& __x, const __tree_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+    explicit __tree_iterator(__node_pointer __p) : __ptr_(__p) {}
+    template <class, class, class> friend class __tree;
+    template <class, class, class> friend class __tree_const_iterator;
+    template <class> friend class __map_iterator;
+    template <class, class, class, class> friend class map;
+    template <class, class, class, class> friend class multimap;
+    template <class, class, class> friend class set;
+    template <class, class, class> friend class multiset;
+};
+
+template <class _Tp, class _ConstNodePtr, class _DiffType>
+class __tree_const_iterator
+{
+    typedef _ConstNodePtr                                         __node_pointer;
+    typedef typename pointer_traits<__node_pointer>::element_type __node;
+    typedef const 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;
+
+    __tree_const_iterator() {}
+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:
+    __tree_const_iterator(__non_const_iterator __p) : __ptr_(__p.__ptr_) {}
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &__ptr_->__value_;}
+
+    __tree_const_iterator& operator++()
+        {__ptr_ = static_cast<__node_pointer>(__tree_next(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    __tree_const_iterator operator++(int)
+        {__tree_const_iterator __t(*this); ++(*this); return __t;}
+
+    __tree_const_iterator& operator--()
+        {__ptr_ = static_cast<__node_pointer>(__tree_prev(static_cast<__node_base_pointer>(__ptr_)));
+         return *this;}
+    __tree_const_iterator operator--(int)
+        {__tree_const_iterator __t(*this); --(*this); return __t;}
+
+    friend bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y)
+        {return !(__x == __y);}
+
+private:
+    explicit __tree_const_iterator(__node_pointer __p) : __ptr_(__p) {}
+    template <class, class, class> friend class __tree;
+    template <class, class, class, class> friend class map;
+    template <class, class, class, class> friend class multimap;
+    template <class, class, class> friend class set;
+    template <class, class, class> friend class multiset;
+    template <class> friend class __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 __tree_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::const_pointer    __node_const_pointer;
+    typedef typename __node::base::pointer           __node_base_pointer;
+    typedef typename __node::base::const_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<const __end_node_t>
+#else
+            rebind<const __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:
+    __node_pointer __end_node()
+    {
+        return static_cast<__node_pointer>
+               (
+                   pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first())
+               );
+    }
+    __node_const_pointer __end_node() const
+    {
+        return static_cast<__node_const_pointer>
+               (
+                   pointer_traits<__end_node_const_ptr>::pointer_to(__pair1_.first())
+               );
+    }
+          __node_allocator& __node_alloc()       {return __pair1_.second();}
+private:
+    const __node_allocator& __node_alloc() const {return __pair1_.second();}
+          __node_pointer& __begin_node()         {return __begin_node_;}
+    const __node_pointer& __begin_node()   const {return __begin_node_;}
+public:
+    allocator_type __alloc() const {return allocator_type(__node_alloc());}
+private:
+          size_type& size()                      {return __pair3_.first();}
+public:
+    const size_type& size()                const {return __pair3_.first();}
+          value_compare& value_comp()            {return __pair3_.second();}
+    const value_compare& value_comp()      const {return __pair3_.second();}
+public:
+    __node_pointer       __root()
+        {return static_cast<__node_pointer>      (__end_node()->__left_);}
+    __node_const_pointer __root() const
+        {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_const_pointer, difference_type> const_iterator;
+
+    explicit __tree(const value_compare& __comp);
+    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);
+#ifdef _LIBCPP_MOVE
+    __tree(__tree&& __t);
+    __tree(__tree&& __t, const allocator_type& __a);
+    __tree& operator=(__tree&& __t);
+#endif
+
+    ~__tree();
+
+          iterator begin()       {return       iterator(__begin_node());}
+    const_iterator begin() const {return const_iterator(__begin_node());}
+          iterator end()         {return       iterator(__end_node());}
+    const_iterator end()   const {return const_iterator(__end_node());}
+
+    size_type max_size() const {return __node_traits::max_size(__node_alloc());}
+
+    void clear();
+
+    void swap(__tree& __t);
+
+#ifdef _LIBCPP_MOVE
+    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);
+
+    template <class _V>
+        pair<iterator, bool> __insert_unique(_V&& __v);
+    template <class _V>
+        iterator __insert_unique(const_iterator __p, _V&& __v);
+    template <class _V>
+        iterator __insert_multi(_V&& __v);
+    template <class _V>
+        iterator __insert_multi(const_iterator __p, _V&& __v);
+#else
+
+    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);
+#endif
+
+    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>
+        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>
+        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>
+        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>
+        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> _D;
+    typedef unique_ptr<__node, _D> __node_holder;
+
+    __node_holder remove(const_iterator __p);
+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);
+
+#ifdef _LIBCPP_MOVE
+    template <class ..._Args>
+        __node_holder __construct_node(_Args&& ...__args);
+#else
+        __node_holder __construct_node(const value_type& __v);
+#endif
+
+    void destroy(__node_pointer __nd);
+
+    void __copy_assign_alloc(const __tree& __t)
+        {__copy_assign_alloc(__t, integral_constant<bool,
+             __node_traits::propagate_on_container_copy_assignment::value>());}
+
+    void __copy_assign_alloc(const __tree& __t, true_type)
+        {__node_alloc() = __t.__node_alloc();}
+    void __copy_assign_alloc(const __tree& __t, false_type) {}
+
+    void __move_assign(__tree& __t, false_type);
+    void __move_assign(__tree& __t, true_type);
+
+    void __move_assign_alloc(__tree& __t)
+        {__move_assign_alloc(__t, integral_constant<bool,
+             __node_traits::propagate_on_container_move_assignment::value>());}
+
+    void __move_assign_alloc(__tree& __t, true_type)
+        {__node_alloc() = _STD::move(__t.__node_alloc());}
+    void __move_assign_alloc(__tree& __t, false_type) {}
+
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __node_traits::propagate_on_container_swap::value>());}
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
+        {}
+
+    __node_pointer __detach();
+    static __node_pointer __detach(__node_pointer);
+};
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp)
+    : __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(__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();
+        try
+        {
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __detach(__cache);
+                __node_insert_unique(__cache);
+                __cache = __next;
+            }
+        }
+        catch (...)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+            throw;
+        }
+        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();
+        try
+        {
+            for (; __cache != nullptr && __first != __last; ++__first)
+            {
+                __cache->__value_ = *__first;
+                __node_pointer __next = __detach(__cache);
+                __node_insert_multi(__cache);
+                __cache = __next;
+            }
+        }
+        catch (...)
+        {
+            while (__cache->__parent_ != nullptr)
+                __cache = static_cast<__node_pointer>(__cache->__parent_);
+            destroy(__cache);
+            throw;
+        }
+        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();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t)
+    : __begin_node_(_STD::move(__t.__begin_node_)),
+      __pair1_(_STD::move(__t.__pair1_)),
+      __pair3_(_STD::move(__t.__pair3_))
+{
+    if (size() == 0)
+        __begin_node() = __end_node();
+    else
+    {
+        __end_node()->__left_->__parent_ = __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, _STD::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_ = __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)
+{
+    destroy(static_cast<__node_pointer>(__end_node()->__left_));
+    __begin_node_ = __t.__begin_node_;
+    __pair1_.first() = __t.__pair1_.first();
+    __move_assign_alloc(__t);
+    __pair3_ = _STD::move(__t.__pair3_);
+    if (size() == 0)
+        __begin_node() = __end_node();
+    else
+    {
+        __end_node()->__left_->__parent_ = __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() = _STD::move(__t.value_comp());
+        const_iterator __e = end();
+        if (size() != 0)
+        {
+            __node_pointer __cache = __detach();
+            try
+            {
+                while (__cache != nullptr && __t.size() != 0)
+                {
+                    __cache->__value_ = _STD::move(__t.remove(__t.begin())->__value_);
+                    __node_pointer __next = __detach(__cache);
+                    __node_insert_multi(__cache);
+                    __cache = __next;
+                }
+            }
+            catch (...)
+            {
+                while (__cache->__parent_ != nullptr)
+                    __cache = static_cast<__node_pointer>(__cache->__parent_);
+                destroy(__cache);
+                throw;
+            }
+            if (__cache != nullptr)
+            {
+                while (__cache->__parent_ != nullptr)
+                    __cache = static_cast<__node_pointer>(__cache->__parent_);
+                destroy(__cache);
+            }
+        }
+        while (__t.size() != 0)
+            __insert_multi(__e, _STD::move(__t.remove(__t.begin())->__value_));
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+__tree<_Tp, _Compare, _Allocator>&
+__tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
+{
+    __move_assign(__t, integral_constant<bool,
+                  __node_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+#endif
+
+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)
+{
+    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, addressof(__nd->__value_));
+        __node_traits::deallocate(__na, __nd, 1);
+    }
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
+{
+    using _STD::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_ = __end_node();
+    if (__t.size() == 0)
+        __t.__begin_node() = __t.__end_node();
+    else
+        __t.__end_node()->__left_->__parent_ = __t.__end_node();
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+void
+__tree<_Tp, _Compare, _Allocator>::clear()
+{
+    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 = __nd;
+                    return __parent->__right_;
+                }
+            }
+            else
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = __nd;
+                    return __parent->__left_;
+                }
+            }
+        }
+    }
+    __parent = __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 = __nd;
+                    return __parent->__left_;
+                }
+            }
+            else
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = __nd;
+                    return __parent->__right_;
+                }
+            }
+        }
+    }
+    __parent = __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 = const_cast<__node_pointer&>(__hint.__ptr_);
+                return __parent->__left_;
+            }
+            else
+            {
+                __parent = const_cast<__node_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 = __nd;
+                    return __parent->__left_;
+                }
+            }
+            else if (value_comp()(__nd->__value_, __v))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = __nd;
+                    return __parent->__right_;
+                }
+            }
+            else
+            {
+                __parent = __nd;
+                return __parent;
+            }
+        }
+    }
+    __parent = __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 = const_cast<__node_pointer&>(__hint.__ptr_);
+                return __parent->__left_;
+            }
+            else
+            {
+                __parent = const_cast<__node_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 = _STD::next(__hint);
+        if (__next == end() || value_comp()(__v, *__next))
+        {
+            // *__hint < __v < *next(__hint)
+            if (__hint.__ptr_->__right_ == nullptr)
+            {
+                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                return __parent->__right_;
+            }
+            else
+            {
+                __parent = const_cast<__node_pointer&>(__next.__ptr_);
+                return __parent->__left_;
+            }
+        }
+        // *next(__hint) <= __v
+        return __find_equal(__parent, __v);
+    }
+    // else __v == *__hint
+    __parent = const_cast<__node_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();
+}
+
+#ifdef _LIBCPP_MOVE
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), _STD::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(_STD::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, __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(_STD::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, __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(_STD::forward<_Args>(__args)...);
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
+    __insert_node_at(__parent, __child, __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(_STD::forward<_Args>(__args)...);
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
+    __insert_node_at(__parent, __child, __h.get());
+    return iterator(static_cast<__node_pointer>(__h.release()));
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _V>
+pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(_V&& __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(_STD::forward<_V>(__v));
+        __insert_node_at(__parent, __child, __h.get());
+        __r = __h.release();
+        __inserted = true;
+    }
+    return pair<iterator, bool>(iterator(__r), __inserted);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _V>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, _V&& __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(_STD::forward<_V>(__v));
+        __insert_node_at(__parent, __child, __h.get());
+        __r = __h.release();
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _V>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(_V&& __v)
+{
+    __node_holder __h = __construct_node(_STD::forward<_V>(__v));
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
+    __insert_node_at(__parent, __child, __h.get());
+    return iterator(__h.release());
+}
+
+template <class _Tp, class _Compare, class _Allocator>
+template <class _V>
+typename __tree<_Tp, _Compare, _Allocator>::iterator
+__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, _V&& __v)
+{
+    __node_holder __h = __construct_node(_STD::forward<_V>(__v));
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
+    __insert_node_at(__parent, __child, __h.get());
+    return iterator(__h.release());
+}
+
+#else
+
+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), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), __v);
+    __h.get_deleter().__value_constructed = true;
+    return _STD::move(__h);
+}
+
+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, __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, __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, __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, __h.get());
+    return iterator(__h.release());
+}
+
+#endif
+
+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, __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, __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, __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, __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 = const_cast<__node_pointer>(__p.__ptr_);
+    iterator __r(__np);
+    ++__r;
+    if (__begin_node() == __np)
+        __begin_node() = __r.__ptr_;
+    --size();
+    __node_allocator& __na = __node_alloc();
+    __node_traits::destroy(__na, const_cast<value_type*>(addressof(*__p)));
+    __tree_remove(__end_node()->__left_,
+                  static_cast<__node_base_pointer>(__np));
+    __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(const_cast<__node_pointer>(__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> _P;
+    __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 _STD::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> _P;
+    __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 _P(iterator(__rt),
+                      iterator(
+                          __rt->__right_ != nullptr ?
+                              static_cast<__node_pointer>(__tree_min(__rt->__right_))
+                            : __result));
+    }
+    return _P(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> _P;
+    __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 _P(const_iterator(__rt),
+                      const_iterator(
+                          __rt->__right_ != nullptr ?
+                              static_cast<__node_const_pointer>(__tree_min(__rt->__right_))
+                            : __result));
+    }
+    return _P(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> _P;
+    __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 _P(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), __rt),
+                      __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
+    }
+    return _P(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> _P;
+    __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 _P(__lower_bound(__k, static_cast<__node_const_pointer>(__rt->__left_), __rt),
+                      __upper_bound(__k, static_cast<__node_const_pointer>(__rt->__right_), __result));
+    }
+    return _P(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)
+{
+    __node_pointer __np = const_cast<__node_pointer>(__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, _D(__node_alloc()));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP___TREE
diff --git a/include/__tuple b/include/__tuple
new file mode 100644
index 0000000..3fba6ce
--- /dev/null
+++ b/include/__tuple
@@ -0,0 +1,229 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TUPLE
+#define _LIBCPP___TUPLE
+
+#include <__config>
+#include <cstddef>
+#include <type_traits>
+
+#pragma GCC system_header
+
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
+#include <__tuple_03>
+
+#else
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp> class tuple_size;
+template <size_t _Ip, class _Tp> class tuple_element;
+
+template <class ..._Tp> class tuple;
+template <class _T1, class _T2> class pair;
+template <class _Tp, size_t _Size> struct array;
+
+template <class _Tp> struct __tuple_like : false_type {};
+
+template <class... _Tp> struct __tuple_like<tuple<_Tp...>> : true_type {};
+template <class... _Tp> struct __tuple_like<const tuple<_Tp...>> : true_type {};
+template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
+template <class _T1, class _T2> struct __tuple_like<const pair<_T1, _T2> > : true_type {};
+template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
+template <class _Tp, size_t _Size> struct __tuple_like<const array<_Tp, _Size> > : true_type {};
+
+
+template <size_t _Ip, class ..._Tp>
+typename tuple_element<_Ip, tuple<_Tp...>>::type&
+get(tuple<_Tp...>&);
+
+template <size_t _Ip, class ..._Tp>
+const typename tuple_element<_Ip, tuple<_Tp...>>::type&
+get(const tuple<_Tp...>&);
+
+template <size_t _Ip, class _T1, class _T2>
+typename tuple_element<_Ip, pair<_T1, _T2> >::type&
+get(pair<_T1, _T2>&);
+
+template <size_t _Ip, class _T1, class _T2>
+const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
+get(const pair<_T1, _T2>&);
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_Tp&
+get(array<_Tp, _Size>&);
+
+template <size_t _Ip, class _Tp, size_t _Size>
+const _Tp&
+get(const array<_Tp, _Size>&);
+
+// __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 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 tuple_element<0, __tuple_types<_Hp, _Tp...>>
+{
+public:
+    typedef _Hp type;
+};
+
+template <size_t _Ip, class _Hp, class ..._Tp>
+class tuple_element<_Ip, __tuple_types<_Hp, _Tp...>>
+{
+public:
+    typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...>>::type type;
+};
+
+template <class ..._Tp>
+class 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
+
+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_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;
+};
+
+// __make_assignable_types
+
+template <class _Tuple, class _Tp, size_t _Sp, size_t _Ep>
+struct __make_assignable_types_imp;
+
+template <class ..._Types, class _Tp, size_t _Sp, size_t _Ep>
+struct __make_assignable_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep>
+{
+    typedef typename __make_assignable_types_imp<__tuple_types<_Types...,
+                                      typename remove_reference<typename tuple_element<_Sp, _Tp>::type>::type>,
+                                      _Tp, _Sp+1, _Ep>::type type;
+};
+
+template <class ..._Types, class _Tp, size_t _Ep>
+struct __make_assignable_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_assignable_types
+{
+    static_assert(_Sp <= _Ep, "__make_assignable_types input error");
+    typedef typename __make_assignable_types_imp<__tuple_types<>, typename remove_reference<_Tp>::type, _Sp, _Ep>::type type;
+};
+
+// __tuple_convertible
+
+template <bool, class _Tp, class _Up>
+struct __tuple_convertible_imp : public false_type {};
+
+template <class _Tp0, class ..._Tp, class _Up0, class ..._Up>
+struct __tuple_convertible_imp<true, __tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...>>
+    : public integral_constant<bool,
+                               is_convertible<_Tp0, _Up0>::value &&
+                               __tuple_convertible_imp<true, __tuple_types<_Tp...>, __tuple_types<_Up...>>::value> {};
+
+template <>
+struct __tuple_convertible_imp<true, __tuple_types<>, __tuple_types<>>
+    : public true_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_imp<tuple_size<typename remove_reference<_Tp>::type>::value ==
+                                     tuple_size<_Up>::value,
+             typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type>
+{};
+
+// __tuple_assignable
+
+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_convertible_imp<tuple_size<typename remove_reference<_Tp>::type>::value ==
+                                     tuple_size<_Up>::value,
+             typename __make_tuple_types<_Tp>::type, typename __make_assignable_types<_Up>::type>
+{};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+#endif  // _LIBCPP___TUPLE
diff --git a/include/__tuple_03 b/include/__tuple_03
new file mode 100644
index 0000000..88a91c6
--- /dev/null
+++ b/include/__tuple_03
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___TUPLE_03
+#define _LIBCPP___TUPLE_03
+
+#include <__config>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp> class tuple_size;
+template <size_t _Ip, class _Tp> class tuple_element;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif
diff --git a/include/algorithm b/include/algorithm
new file mode 100644
index 0000000..0765dfa
--- /dev/null
+++ b/include/algorithm
@@ -0,0 +1,5034 @@
+// -*- C++ -*-
+//===-------------------------- algorithm ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_ALGORITHM
+#define _LIBCPP_ALGORITHM
+
+/*
+    algorithm synopsis
+
+#include <initializer_list>
+
+namespace std
+{
+
+template <class InputIterator, class Predicate>
+    bool
+    all_of(InputIterator first, InputIterator last, Predicate pred);
+
+template <class InputIterator, class Predicate>
+    bool
+    any_of(InputIterator first, InputIterator last, Predicate pred);
+
+template <class InputIterator, class Predicate>
+    bool
+    none_of(InputIterator first, InputIterator last, Predicate pred);
+
+template <class InputIterator, class Function>
+    Function
+    for_each(InputIterator first, InputIterator last, Function f);
+
+template <class InputIterator, class T>
+    InputIterator
+    find(InputIterator first, InputIterator last, const T& value);
+
+template <class InputIterator, class Predicate>
+    InputIterator
+    find_if(InputIterator first, InputIterator last, Predicate pred);
+
+template<class InputIterator, class Predicate>
+    InputIterator
+    find_if_not(InputIterator first, InputIterator last, Predicate pred);
+
+template <class ForwardIterator1, class ForwardIterator2>
+    ForwardIterator1
+    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
+             ForwardIterator2 first2, ForwardIterator2 last2);
+
+template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+    ForwardIterator1
+    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
+             ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
+
+template <class ForwardIterator1, class ForwardIterator2>
+    ForwardIterator1
+    find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
+                  ForwardIterator2 first2, ForwardIterator2 last2);
+
+template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+    ForwardIterator1
+    find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
+                  ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
+
+template <class ForwardIterator>
+    ForwardIterator
+    adjacent_find(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class BinaryPredicate>
+    ForwardIterator
+    adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
+
+template <class InputIterator, class T>
+    typename iterator_traits<InputIterator>::difference_type
+    count(InputIterator first, InputIterator last, const T& value);
+
+template <class InputIterator, class Predicate>
+    typename iterator_traits<InputIterator>::difference_type
+    count_if(InputIterator first, InputIterator last, Predicate pred);
+
+template <class InputIterator1, class InputIterator2>
+    pair<InputIterator1, InputIterator2>
+    mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
+
+template <class InputIterator1, class InputIterator2, class BinaryPredicate>
+    pair<InputIterator1, InputIterator2>
+    mismatch(InputIterator1 first1, InputIterator1 last1,
+             InputIterator2 first2, BinaryPredicate pred);
+
+template <class InputIterator1, class InputIterator2>
+    bool
+    equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
+
+template <class InputIterator1, class InputIterator2, class BinaryPredicate>
+    bool
+    equal(InputIterator1 first1, InputIterator1 last1,
+          InputIterator2 first2, BinaryPredicate pred);
+
+template<class ForwardIterator1, class ForwardIterator2>
+    bool
+    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+                   ForwardIterator2 first2);
+
+template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+    bool
+    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
+                   ForwardIterator2 first2, BinaryPredicate pred);
+
+template <class ForwardIterator1, class ForwardIterator2>
+    ForwardIterator1
+    search(ForwardIterator1 first1, ForwardIterator1 last1,
+           ForwardIterator2 first2, ForwardIterator2 last2);
+
+template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
+    ForwardIterator1
+    search(ForwardIterator1 first1, ForwardIterator1 last1,
+           ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
+
+template <class ForwardIterator, class Size, class T>
+    ForwardIterator
+    search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
+
+template <class ForwardIterator, class Size, class T, class BinaryPredicate>
+    ForwardIterator
+    search_n(ForwardIterator first, ForwardIterator last,
+             Size count, const T& value, BinaryPredicate pred);
+
+template <class InputIterator, class OutputIterator>
+    OutputIterator
+    copy(InputIterator first, InputIterator last, OutputIterator result);
+
+template<class InputIterator, class OutputIterator, class Predicate>
+    OutputIterator
+    copy_if(InputIterator first, InputIterator last,
+            OutputIterator result, Predicate pred);
+
+template<class InputIterator, class Size, class OutputIterator>
+    OutputIterator
+    copy_n(InputIterator first, Size n, OutputIterator result);
+
+template <class BidirectionalIterator1, class BidirectionalIterator2>
+    BidirectionalIterator2
+    copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
+                  BidirectionalIterator2 result);
+
+template <class ForwardIterator1, class ForwardIterator2>
+    ForwardIterator2
+    swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
+
+template <class ForwardIterator1, class ForwardIterator2>
+    void
+    iter_swap(ForwardIterator1 a, ForwardIterator2 b);
+
+template <class InputIterator, class OutputIterator, class UnaryOperation>
+    OutputIterator
+    transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
+    OutputIterator
+    transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
+              OutputIterator result, BinaryOperation binary_op);
+
+template <class ForwardIterator, class T>
+    void
+    replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
+
+template <class ForwardIterator, class Predicate, class T>
+    void
+    replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
+
+template <class InputIterator, class OutputIterator, class T>
+    OutputIterator
+    replace_copy(InputIterator first, InputIterator last, OutputIterator result,
+                 const T& old_value, const T& new_value);
+
+template <class InputIterator, class OutputIterator, class Predicate, class T>
+    OutputIterator
+    replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
+
+template <class ForwardIterator, class T>
+    void
+    fill(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class OutputIterator, class Size, class T>
+    OutputIterator
+    fill_n(OutputIterator first, Size n, const T& value);
+
+template <class ForwardIterator, class Generator>
+    void
+    generate(ForwardIterator first, ForwardIterator last, Generator gen);
+
+template <class OutputIterator, class Size, class Generator>
+    OutputIterator
+    generate_n(OutputIterator first, Size n, Generator gen);
+
+template <class ForwardIterator, class T>
+    ForwardIterator
+    remove(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class ForwardIterator, class Predicate>
+    ForwardIterator
+    remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
+
+template <class InputIterator, class OutputIterator, class T>
+    OutputIterator
+    remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
+
+template <class InputIterator, class OutputIterator, class Predicate>
+    OutputIterator
+    remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
+
+template <class ForwardIterator>
+    ForwardIterator
+    unique(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class BinaryPredicate>
+    ForwardIterator
+    unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
+
+template <class InputIterator, class OutputIterator>
+    OutputIterator
+    unique_copy(InputIterator first, InputIterator last, OutputIterator result);
+
+template <class InputIterator, class OutputIterator, class BinaryPredicate>
+    OutputIterator
+    unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
+
+template <class BidirectionalIterator>
+    void
+    reverse(BidirectionalIterator first, BidirectionalIterator last);
+
+template <class BidirectionalIterator, class OutputIterator>
+    OutputIterator
+    reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
+
+template <class ForwardIterator>
+    ForwardIterator
+    rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
+
+template <class ForwardIterator, class OutputIterator>
+    OutputIterator
+    rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
+
+template <class RandomAccessIterator>
+    void
+    random_shuffle(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class RandomNumberGenerator>
+    void
+    random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand);
+
+template <class InputIterator, class Predicate>
+    bool
+    is_partitioned(InputIterator first, InputIterator last, Predicate pred);
+
+template <class ForwardIterator, class Predicate>
+    ForwardIterator
+    partition(ForwardIterator first, ForwardIterator last, Predicate pred);
+
+template <class InputIterator, class OutputIterator1,
+          class OutputIterator2, class Predicate>
+    pair<OutputIterator1, OutputIterator2>
+    partition_copy(InputIterator first, InputIterator last,
+                   OutputIterator1 out_true, OutputIterator2 out_false,
+                   Predicate pred);
+
+template <class ForwardIterator, class Predicate>
+    ForwardIterator
+    stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
+
+template<class ForwardIterator, class Predicate>
+    ForwardIterator
+    partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
+
+template <class ForwardIterator>
+    bool
+    is_sorted(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class Compare>
+    bool
+    is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
+
+template<class ForwardIterator>
+    ForwardIterator
+    is_sorted_until(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class Compare>
+    ForwardIterator
+    is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    sort(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    stable_sort(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
+
+template <class InputIterator, class RandomAccessIterator>
+    RandomAccessIterator
+    partial_sort_copy(InputIterator first, InputIterator last,
+                      RandomAccessIterator result_first, RandomAccessIterator result_last);
+
+template <class InputIterator, class RandomAccessIterator, class Compare>
+    RandomAccessIterator
+    partial_sort_copy(InputIterator first, InputIterator last,
+                      RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
+
+template <class ForwardIterator, class T>
+    ForwardIterator
+    lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class ForwardIterator, class T, class Compare>
+    ForwardIterator
+    lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
+
+template <class ForwardIterator, class T>
+    ForwardIterator
+    upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class ForwardIterator, class T, class Compare>
+    ForwardIterator
+    upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
+
+template <class ForwardIterator, class T>
+    pair<ForwardIterator, ForwardIterator>
+    equal_range(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class ForwardIterator, class T, class Compare>
+    pair<ForwardIterator, ForwardIterator>
+    equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
+
+template <class ForwardIterator, class T>
+    bool
+    binary_search(ForwardIterator first, ForwardIterator last, const T& value);
+
+template <class ForwardIterator, class T, class Compare>
+    bool
+    binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator>
+    OutputIterator
+    merge(InputIterator1 first1, InputIterator1 last1,
+          InputIterator2 first2, InputIterator2 last2, OutputIterator result);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
+    OutputIterator
+    merge(InputIterator1 first1, InputIterator1 last1,
+          InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
+
+template <class BidirectionalIterator>
+    void
+    inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
+
+template <class BidirectionalIterator, class Compare>
+    void
+    inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
+
+template <class InputIterator1, class InputIterator2>
+    bool
+    includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
+
+template <class InputIterator1, class InputIterator2, class Compare>
+    bool
+    includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator>
+    OutputIterator
+    set_union(InputIterator1 first1, InputIterator1 last1,
+              InputIterator2 first2, InputIterator2 last2, OutputIterator result);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
+    OutputIterator
+    set_union(InputIterator1 first1, InputIterator1 last1,
+              InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator>
+    OutputIterator
+    set_intersection(InputIterator1 first1, InputIterator1 last1,
+                     InputIterator2 first2, InputIterator2 last2, OutputIterator result);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
+    OutputIterator
+    set_intersection(InputIterator1 first1, InputIterator1 last1,
+                     InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator>
+    OutputIterator
+    set_difference(InputIterator1 first1, InputIterator1 last1,
+                   InputIterator2 first2, InputIterator2 last2, OutputIterator result);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
+    OutputIterator
+    set_difference(InputIterator1 first1, InputIterator1 last1,
+                   InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator>
+    OutputIterator
+    set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
+                             InputIterator2 first2, InputIterator2 last2, OutputIterator result);
+
+template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
+    OutputIterator
+    set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
+                             InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    push_heap(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    pop_heap(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    make_heap(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator>
+    void
+    sort_heap(RandomAccessIterator first, RandomAccessIterator last);
+
+template <class RandomAccessIterator, class Compare>
+    void
+    sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
+
+template <class RandomAccessIterator> 
+    bool
+    is_heap(RandomAccessIterator first, RandomAccessiterator last); 
+
+template <class RandomAccessIterator, class Compare> 
+    bool
+    is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); 
+
+template <class RandomAccessIterator> 
+    RandomAccessIterator
+    is_heap_until(RandomAccessIterator first, RandomAccessiterator last); 
+
+template <class RandomAccessIterator, class Compare> 
+    RandomAccessIterator
+    is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); 
+
+template <class T>
+    const T&
+    min(const T& a, const T& b);
+
+template <class T, class Compare>
+    const T&
+    min(const T& a, const T& b, Compare comp);
+
+template <class T>
+    const T&
+    max(const T& a, const T& b);
+
+template <class T, class Compare>
+    const T&
+    max(const T& a, const T& b, Compare comp);
+
+template <class ForwardIterator>
+    ForwardIterator
+    min_element(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class Compare>
+    ForwardIterator
+    min_element(ForwardIterator first, ForwardIterator last, Compare comp);
+
+template <class ForwardIterator>
+    ForwardIterator
+    max_element(ForwardIterator first, ForwardIterator last);
+
+template <class ForwardIterator, class Compare>
+    ForwardIterator
+    max_element(ForwardIterator first, ForwardIterator last, Compare comp);
+
+template <class InputIterator1, class InputIterator2>
+    bool
+    lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
+
+template <class InputIterator1, class InputIterator2, class Compare>
+    bool
+    lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
+                            InputIterator2 first2, InputIterator2 last2, Compare comp);
+
+template <class BidirectionalIterator>
+    bool 
+    next_permutation(BidirectionalIterator first, BidirectionalIterator last);
+
+template <class BidirectionalIterator, class Compare>
+    bool
+    next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
+
+template <class BidirectionalIterator>
+    bool
+    prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
+
+template <class BidirectionalIterator, class Compare>
+    bool
+    prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <initializer_list>
+#include <type_traits>
+#include <cstring>
+#include <utility>
+#include <memory>
+#include <iterator>
+#ifdef _LIBCPP_DEBUG
+#include <cassert>
+#endif
+//#include <cstdlib>
+#define RAND_MAX 0x7fffffff     // #include <cstdlib>
+extern "C" int rand(void);      // #include <cstdlib>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::rand;                   // #include <cstdlib>
+
+template <class _T1, class _T2 = _T1>
+struct __equal_to
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;}
+};
+
+template <class _T1>
+struct __equal_to<_T1, _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+};
+
+template <class _T1>
+struct __equal_to<const _T1, _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+};
+
+template <class _T1>
+struct __equal_to<_T1, const _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
+};
+
+template <class _T1, class _T2 = _T1>
+struct __less
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
+};
+
+template <class _T1>
+struct __less<_T1, _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+};
+
+template <class _T1>
+struct __less<const _T1, _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+};
+
+template <class _T1>
+struct __less<_T1, const _T1>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
+};
+
+template <class _Predicate>
+class __negate
+{
+private:
+    _Predicate __p_;
+public:
+    _LIBCPP_INLINE_VISIBILITY __negate() {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    explicit __negate(_Predicate __p) : __p_(__p) {}
+
+    template <class _T1>
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _T1& __x) {return !__p_(__x);}
+
+    template <class _T1, class _T2>
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);}
+};
+
+#ifdef _LIBCPP_DEBUG
+
+template <class _Compare>
+struct __debug_less
+{
+    _Compare __comp_;
+    __debug_less(_Compare& __c) : __comp_(__c) {}
+    template <class _Tp, class _Up>
+    bool operator()(const _Tp& __x, const _Up& __y)
+    {
+        bool __r = __comp_(__x, __y);
+        if (__r)
+            assert(!__comp_(__y, __x));
+        return __r;
+    }
+};
+
+#endif  // _LIBCPP_DEBUG
+
+// all_of
+
+template <class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (!__pred(*__first))
+            return false;
+    return true;
+}
+
+// any_of
+
+template <class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            return true;
+    return false;
+}
+
+// none_of
+
+template <class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            return false;
+    return true;
+}
+
+// for_each
+
+template <class _InputIterator, class _Function>
+inline _LIBCPP_INLINE_VISIBILITY
+_Function
+for_each(_InputIterator __first, _InputIterator __last, _Function __f)
+{
+    for (; __first != __last; ++__first)
+        __f(*__first);
+    return _STD::move(__f);
+}
+
+// find
+
+template <class _InputIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_InputIterator
+find(_InputIterator __first, _InputIterator __last, const _Tp& __value)
+{
+    for (; __first != __last; ++__first)
+        if (*__first == __value)
+            break;
+    return __first;
+}
+
+// find_if
+
+template <class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_InputIterator
+find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            break;
+    return __first;
+}
+
+// find_if_not
+
+template<class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_InputIterator
+find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (!__pred(*__first))
+            break;
+    return __first;
+}
+
+// find_end
+
+template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
+_ForwardIterator1
+__find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+           _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
+           forward_iterator_tag, forward_iterator_tag)
+{
+    // modeled after search algorithm
+    _ForwardIterator1 __r = __last1;  // __last1 is the "default" answer
+    if (__first2 == __last2)
+        return __r;
+    while (true)
+    {
+        while (true)
+        {
+            if (__first1 == __last1)         // if source exhausted return last correct answer
+                return __r;                  //    (or __last1 if never found)
+            if (__pred(*__first1, *__first2))
+                break;
+            ++__first1;
+        }
+        // *__first1 matches *__first2, now match elements after here
+        _ForwardIterator1 __m1 = __first1;
+        _ForwardIterator2 __m2 = __first2;
+        while (true)
+        {
+            if (++__m2 == __last2)
+            {                         // Pattern exhaused, record answer and search for another one
+                __r = __first1;
+                ++__first1;
+                break;
+            }
+            if (++__m1 == __last1)     // Source exhausted, return last answer
+                return __r;
+            if (!__pred(*__m1, *__m2))  // mismatch, restart with a new __first
+            {
+                ++__first1;
+                break;
+            }  // else there is a match, check next elements
+        }
+    }
+}
+
+template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2>
+_BidirectionalIterator1
+__find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1,
+           _BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BinaryPredicate __pred,
+           bidirectional_iterator_tag, bidirectional_iterator_tag)
+{
+    // modeled after search algorithm (in reverse)
+    if (__first2 == __last2)
+        return __last1;  // Everything matches an empty sequence
+    _BidirectionalIterator1 __l1 = __last1;
+    _BidirectionalIterator2 __l2 = __last2;
+    --__l2;
+    while (true)
+    {
+        // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks
+        while (true)
+        {
+            if (__first1 == __l1)  // return __last1 if no element matches *__first2
+                return __last1;
+            if (__pred(*--__l1, *__l2))
+                break;
+        }
+        // *__l1 matches *__l2, now match elements before here
+        _BidirectionalIterator1 __m1 = __l1;
+        _BidirectionalIterator2 __m2 = __l2;
+        while (true)
+        {
+            if (__m2 == __first2)  // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
+                return __m1;
+            if (__m1 == __first1)  // Otherwise if source exhaused, pattern not found
+                return __last1;
+            if (!__pred(*--__m1, *--__m2))  // if there is a mismatch, restart with a new __l1
+            {
+                break;
+            }  // else there is a match, check next elements
+        }
+    }
+}
+
+template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
+_RandomAccessIterator1
+__find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
+           _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
+           random_access_iterator_tag, random_access_iterator_tag)
+{
+    // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
+    typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2;
+    if (__len2 == 0)
+        return __last1;
+    typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1;
+    if (__len1 < __len2)
+        return __last1;
+    const _RandomAccessIterator1 __s = __first1 + (__len2 - 1);  // End of pattern match can't go before here
+    _RandomAccessIterator1 __l1 = __last1;
+    _RandomAccessIterator2 __l2 = __last2;
+    --__l2;
+    while (true)
+    {
+        while (true)
+        {
+            if (__s == __l1)
+                return __last1;
+            if (__pred(*--__l1, *__l2))
+                break;
+        }
+        _RandomAccessIterator1 __m1 = __l1;
+        _RandomAccessIterator2 __m2 = __l2;
+        while (true)
+        {
+            if (__m2 == __first2)
+                return __m1;
+                                 // no need to check range on __m1 because __s guarantees we have enough source
+            if (!__pred(*--__m1, *--__m2))
+            {
+                break;
+            }
+        }
+    }
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
+{
+    return _STD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type>
+                         (__first1, __last1, __first2, __last2, __pred,
+                          typename iterator_traits<_ForwardIterator1>::iterator_category(),
+                          typename iterator_traits<_ForwardIterator2>::iterator_category());
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+         _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+{
+    typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
+    return _STD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+}
+
+// find_first_of
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+_ForwardIterator1
+find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+              _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
+{
+    for (; __first1 != __last1; ++__first1)
+        for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
+            if (__pred(*__first1, *__j))
+                return __first1;
+    return __last1;
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+              _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+{
+    typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
+    return _STD::find_first_of(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+}
+
+// adjacent_find
+
+template <class _ForwardIterator, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (__pred(*__first, *__i))
+                return __first;
+            __first = __i;
+        }
+    }
+    return __last;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
+{
+    typedef typename iterator_traits<_ForwardIterator>::value_type __v;
+    return _STD::adjacent_find(__first, __last, __equal_to<__v>());
+}
+
+// count
+
+template <class _InputIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename iterator_traits<_InputIterator>::difference_type
+count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
+{
+    typename iterator_traits<_InputIterator>::difference_type __r(0);
+    for (; __first != __last; ++__first)
+        if (*__first == __value)
+            ++__r;
+    return __r;
+}
+
+// count_if
+
+template <class _InputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+typename iterator_traits<_InputIterator>::difference_type
+count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    typename iterator_traits<_InputIterator>::difference_type __r(0);
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            ++__r;
+    return __r;
+}
+
+// mismatch
+
+template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+         _InputIterator2 __first2, _BinaryPredicate __pred)
+{
+    for (; __first1 != __last1; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            break;
+    return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_InputIterator1, _InputIterator2>
+mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type __v1;
+    typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+    return _STD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
+}
+
+// equal
+
+template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
+{
+    for (; __first1 != __last1; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            return false;
+    return true;
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type __v1;
+    typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+    return _STD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
+}
+
+// is_permutation
+
+template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+bool
+is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+               _ForwardIterator2 __first2, _BinaryPredicate __pred)
+{
+    // shorten sequences as much as possible by lopping of any equal parts
+    for (; __first1 != __last1; ++__first1, ++__first2)
+        if (!__pred(*__first1, *__first2))
+            goto __not_done;
+    return true;
+__not_done:
+    // __first1 != __last1 && *__first1 != *__first2
+    typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
+    _D1 __l1 = _STD::distance(__first1, __last1);
+    if (__l1 == _D1(1))
+        return false;
+    _ForwardIterator2 __last2 = _STD::next(__first2, __l1);
+    // For each element in [f1, l1) see if there are the same number of
+    //    equal elements in [f2, l2)
+    for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
+    {
+        // Have we already counted the number of *__i in [f1, l1)?
+        for (_ForwardIterator1 __j = __first1; __j != __i; ++__j)
+            if (__pred(*__j, *__i))
+                goto __next_iter;
+        {
+            // Count number of *__i in [f2, l2)
+            _D1 __c2 = 0;
+            for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
+                if (__pred(*__i, *__j))
+                    ++__c2;
+            if (__c2 == 0)
+                return false;
+            // Count number of *__i in [__i, l1) (we can start with 1)
+            _D1 __c1 = 1;
+            for (_ForwardIterator1 __j = _STD::next(__i); __j != __last1; ++__j)
+                if (__pred(*__i, *__j))
+                    ++__c1;
+            if (__c1 != __c2)
+                return false;
+        }
+__next_iter:;
+    }
+    return true;
+}
+
+template<class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+               _ForwardIterator2 __first2)
+{
+    typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
+    return _STD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
+}
+
+// search
+
+template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
+_ForwardIterator1
+__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
+         forward_iterator_tag, forward_iterator_tag)
+{
+    if (__first2 == __last2)
+        return __first1;  // Everything matches an empty sequence
+    while (true)
+    {
+        // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
+        while (true)
+        {
+            if (__first1 == __last1)  // return __last1 if no element matches *__first2
+                return __last1;
+            if (__pred(*__first1, *__first2))
+                break;
+            ++__first1;
+        }
+        // *__first1 matches *__first2, now match elements after here
+        _ForwardIterator1 __m1 = __first1;
+        _ForwardIterator2 __m2 = __first2;
+        while (true)
+        {
+            if (++__m2 == __last2)  // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
+                return __first1;
+            if (++__m1 == __last1)  // Otherwise if source exhaused, pattern not found
+                return __last1;
+            if (!__pred(*__m1, *__m2))  // if there is a mismatch, restart with a new __first1
+            {
+                ++__first1;
+                break;
+            }  // else there is a match, check next elements
+        }
+    }
+}
+
+template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
+_RandomAccessIterator1
+__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
+           _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
+           random_access_iterator_tag, random_access_iterator_tag)
+{
+    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _D1;
+    typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _D2;
+    // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
+    _D2 __len2 = __last2 - __first2;
+    if (__len2 == 0)
+        return __first1;
+    _D1 __len1 = __last1 - __first1;
+    if (__len1 < __len2)
+        return __last1;
+    const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
+    while (true)
+    {
+#if !_LIBCPP_UNROLL_LOOPS
+        while (true)
+        {
+            if (__first1 == __s)
+                return __last1;
+            if (__pred(*__first1, *__first2))
+                break;
+            ++__first1;
+        }
+#else  // _LIBCPP_UNROLL_LOOPS
+        for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll)
+        {
+            if (__pred(*__first1, *__first2))
+                goto __phase2;
+            if (__pred(*++__first1, *__first2))
+                goto __phase2;
+            if (__pred(*++__first1, *__first2))
+                goto __phase2;
+            if (__pred(*++__first1, *__first2))
+                goto __phase2;
+            ++__first1;
+        }
+        switch (__s - __first1)
+        {
+        case 3:
+            if (__pred(*__first1, *__first2))
+                break;
+            ++__first1;
+        case 2:
+            if (__pred(*__first1, *__first2))
+                break;
+            ++__first1;
+        case 1:
+            if (__pred(*__first1, *__first2))
+                break;
+        case 0:
+            return __last1;
+        }
+    __phase2:
+#endif  // _LIBCPP_UNROLL_LOOPS
+        _RandomAccessIterator1 __m1 = __first1;
+        _RandomAccessIterator2 __m2 = __first2;
+#if !_LIBCPP_UNROLL_LOOPS
+         while (true)
+         {
+             if (++__m2 == __last2)
+                 return __first1;
+             ++__m1;          // no need to check range on __m1 because __s guarantees we have enough source
+             if (!__pred(*__m1, *__m2))
+             {
+                 ++__first1;
+                 break;
+             }
+         }
+#else  // _LIBCPP_UNROLL_LOOPS
+        ++__m2;
+        ++__m1;
+        for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll)
+        {
+            if (!__pred(*__m1, *__m2))
+                goto __continue;
+            if (!__pred(*++__m1, *++__m2))
+                goto __continue;
+            if (!__pred(*++__m1, *++__m2))
+                goto __continue;
+            if (!__pred(*++__m1, *++__m2))
+                goto __continue;
+            ++__m1;
+            ++__m2;
+        }
+        switch (__last2 - __m2)
+        {
+        case 3:
+            if (!__pred(*__m1, *__m2))
+                break;
+            ++__m1;
+            ++__m2;
+        case 2:
+            if (!__pred(*__m1, *__m2))
+                break;
+            ++__m1;
+            ++__m2;
+        case 1:
+            if (!__pred(*__m1, *__m2))
+                break;
+        case 0:
+            return __first1;
+        }
+    __continue:
+        ++__first1;
+#endif  // _LIBCPP_UNROLL_LOOPS
+    }
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+       _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
+{
+    return _STD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>
+                         (__first1, __last1, __first2, __last2, __pred,
+                          typename std::iterator_traits<_ForwardIterator1>::iterator_category(),
+                          typename std::iterator_traits<_ForwardIterator2>::iterator_category());
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+       _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+{
+    typedef typename std::iterator_traits<_ForwardIterator1>::value_type __v1;
+    typedef typename std::iterator_traits<_ForwardIterator2>::value_type __v2;
+    return _STD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+}
+
+// search_n
+
+template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
+_ForwardIterator
+__search_n(_ForwardIterator __first, _ForwardIterator __last,
+           _Size __count, const _Tp& __value, _BinaryPredicate __pred, forward_iterator_tag)
+{
+    if (__count <= 0)
+        return __first;
+    while (true)
+    {
+        // Find first element in sequence that matchs __value, with a mininum of loop checks
+        while (true)
+        {
+            if (__first == __last)  // return __last if no element matches __value
+                return __last;
+            if (__pred(*__first, __value))
+                break;
+            ++__first;
+        }
+        // *__first matches __value, now match elements after here
+        _ForwardIterator __m = __first;
+        _Size __c(0);
+        while (true)
+        {
+            if (++__c == __count)  // If pattern exhausted, __first is the answer (works for 1 element pattern)
+                return __first;
+            if (++__m == __last)  // Otherwise if source exhaused, pattern not found
+                return __last;
+            if (!__pred(*__m, __value))  // if there is a mismatch, restart with a new __first
+            {
+                __first = __m;
+                ++__first;
+                break;
+            }  // else there is a match, check next elements
+        }
+    }
+}
+
+template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp>
+_RandomAccessIterator
+__search_n(_RandomAccessIterator __first, _RandomAccessIterator __last,
+           _Size __count, const _Tp& __value, _BinaryPredicate __pred, random_access_iterator_tag)
+{
+    if (__count <= 0)
+        return __first;
+    _Size __len = static_cast<_Size>(__last - __first);
+    if (__len < __count)
+        return __last;
+    const _RandomAccessIterator __s = __last - (__count - 1);  // Start of pattern match can't go beyond here
+    while (true)
+    {
+        // Find first element in sequence that matchs __value, with a mininum of loop checks
+        while (true)
+        {
+            if (__first == __s)  // return __last if no element matches __value
+                return __last;
+            if (__pred(*__first, __value))
+                break;
+            ++__first;
+        }
+        // *__first matches __value, now match elements after here
+        _RandomAccessIterator __m = __first;
+        _Size __c(0);
+        while (true)
+        {
+            if (++__c == __count)  // If pattern exhausted, __first is the answer (works for 1 element pattern)
+                return __first;
+             ++__m;          // no need to check range on __m because __s guarantees we have enough source
+            if (!__pred(*__m, __value))  // if there is a mismatch, restart with a new __first
+            {
+                __first = __m;
+                ++__first;
+                break;
+            }  // else there is a match, check next elements
+        }
+    }
+}
+
+template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+search_n(_ForwardIterator __first, _ForwardIterator __last,
+         _Size __count, const _Tp& __value, _BinaryPredicate __pred)
+{
+    return _STD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>
+           (__first, __last, __count, __value, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+}
+
+template <class _ForwardIterator, class _Size, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value)
+{
+    typedef typename iterator_traits<_ForwardIterator>::value_type __v;
+    return _STD::search_n(__first, __last, __count, __value, __equal_to<__v, _Tp>());
+}
+
+// copy
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
+template <class _Iter>
+struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
+{
+    static const bool value = is_pointer<_Iter>::value;
+};
+
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+_Iter
+__unwrap_iter(_Iter __i)
+{
+    return __i;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    has_trivial_copy_assign<_Tp>::value,
+    _Tp*
+>::type
+__unwrap_iter(move_iterator<_Tp*> __i)
+{
+    return __i.base();
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    has_trivial_copy_assign<_Tp>::value,
+    _Tp*
+>::type
+__unwrap_iter(__wrap_iter<_Tp*> __i)
+{
+    return __i.base();
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    for (; __first != __last; ++__first, ++__result)
+        *__result = *__first;
+    return __result;
+}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_same<typename remove_const<_Tp>::type, _Up>::value &&
+    has_trivial_copy_assign<_Up>::value,
+    _Up*
+>::type
+__copy(_Tp* __first, _Tp* __last, _Up* __result)
+{
+    const size_t __n = static_cast<size_t>(__last - __first);
+    _STD::memmove(__result, __first, __n * sizeof(_Up));
+    return __result + __n;
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    return _STD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
+}
+
+// copy_backward
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    while (__first != __last)
+        *--__result = *--__last;
+    return __result;
+}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_same<typename remove_const<_Tp>::type, _Up>::value &&
+    has_trivial_copy_assign<_Up>::value,
+    _Up*
+>::type
+__copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
+{
+    const size_t __n = static_cast<size_t>(__last - __first);
+    __result -= __n;
+    _STD::memmove(__result, __first, __n * sizeof(_Up));
+    return __result;
+}
+
+template <class _BidirectionalIterator1, class _BidirectionalIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_BidirectionalIterator2
+copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
+              _BidirectionalIterator2 __result)
+{
+    return _STD::__copy_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
+}
+
+// copy_if
+
+template<class _InputIterator, class _OutputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+copy_if(_InputIterator __first, _InputIterator __last,
+        _OutputIterator __result, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+    {
+        if (__pred(*__first))
+        {
+            *__result = *__first;
+            ++__result;
+        }
+    }
+    return __result;
+}
+
+// copy_n
+
+template<class _InputIterator, class _Size, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    __is_input_iterator<_InputIterator>::value &&
+   !__is_random_access_iterator<_InputIterator>::value,
+    _OutputIterator
+>::type
+copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
+{
+    for (; __n > 0; --__n, ++__first, ++__result)
+        *__result = *__first;
+    return __result;
+}
+
+template<class _InputIterator, class _Size, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    __is_random_access_iterator<_InputIterator>::value,
+    _OutputIterator
+>::type
+copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
+{
+    return copy(__first, __first + __n, __result);
+}
+
+// move
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    for (; __first != __last; ++__first, ++__result)
+        *__result = _STD::move(*__first);
+    return __result;
+}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_same<typename remove_const<_Tp>::type, _Up>::value &&
+    has_trivial_copy_assign<_Up>::value,
+    _Up*
+>::type
+__move(_Tp* __first, _Tp* __last, _Up* __result)
+{
+    const size_t __n = static_cast<size_t>(__last - __first);
+    _STD::memmove(__result, __first, __n * sizeof(_Up));
+    return __result + __n;
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    return _STD::__move(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
+}
+
+// move_backward
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    while (__first != __last)
+        *--__result = _STD::move(*--__last);
+    return __result;
+}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_same<typename remove_const<_Tp>::type, _Up>::value &&
+    has_trivial_copy_assign<_Up>::value,
+    _Up*
+>::type
+__move_backward(_Tp* __first, _Tp* __last, _Up* __result)
+{
+    const size_t __n = static_cast<size_t>(__last - __first);
+    __result -= __n;
+    _STD::memmove(__result, __first, __n * sizeof(_Up));
+    return __result;
+}
+
+template <class _BidirectionalIterator1, class _BidirectionalIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_BidirectionalIterator2
+move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
+              _BidirectionalIterator2 __result)
+{
+    return _STD::__move_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
+}
+
+// iter_swap
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
+{
+    swap(*__a, *__b);
+}
+
+// transform
+
+template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
+{
+    for (; __first != __last; ++__first, ++__result)
+        *__result = __op(*__first);
+    return __result;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
+          _OutputIterator __result, _BinaryOperation __binary_op)
+{
+    for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
+        *__result = __binary_op(*__first1, *__first2);
+    return __result;
+}
+
+// replace
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value)
+{
+    for (; __first != __last; ++__first)
+        if (*__first == __old_value)
+            *__first = __new_value;
+}
+
+// replace_if
+
+template <class _ForwardIterator, class _Predicate, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value)
+{
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            *__first = __new_value;
+}
+
+// replace_copy
+
+template <class _InputIterator, class _OutputIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+             const _Tp& __old_value, const _Tp& __new_value)
+{
+    for (; __first != __last; ++__first, ++__result)
+        if (*__first == __old_value)
+            *__result = __new_value;
+        else
+            *__result = *__first;
+    return __result;
+}
+
+// replace_copy_if
+
+template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+                _Predicate __pred, const _Tp& __new_value)
+{
+    for (; __first != __last; ++__first, ++__result)
+        if (__pred(*__first))
+            *__result = __new_value;
+        else
+            *__result = *__first;
+    return __result;
+}
+
+// fill_n
+
+template <class _OutputIterator, class _Size, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value, false_type)
+{
+    for (; __n > 0; ++__first, --__n)
+        *__first = __value;
+    return __first;
+}
+
+template <class _OutputIterator, class _Size, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value, true_type)
+{
+    if (__n > 0)
+        _STD::memset(__first, (unsigned char)__value, (size_t)(__n));
+    return __first + __n;
+}
+
+template <class _OutputIterator, class _Size, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
+{
+   return _STD::__fill_n(__first, __n, __value, integral_constant<bool,
+                                              is_pointer<_OutputIterator>::value &&
+                                              has_trivial_copy_assign<_Tp>::value     &&
+                                              sizeof(_Tp) == 1>());
+}
+
+// fill
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
+{
+    for (; __first != __last; ++__first)
+        *__first = __value;
+}
+
+template <class _RandomAccessIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
+{
+    _STD::fill_n(__first, __last - __first, __value);
+}
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    _STD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
+}
+
+// generate
+
+template <class _ForwardIterator, class _Generator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
+{
+    for (; __first != __last; ++__first)
+        *__first = __gen();
+}
+
+// generate_n
+
+template <class _OutputIterator, class _Size, class _Generator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
+{
+    for (; __n > 0; ++__first, --__n)
+        *__first = __gen();
+    return __first;
+}
+
+// remove
+
+template <class _ForwardIterator, class _Tp>
+_ForwardIterator
+remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    __first = _STD::find(__first, __last, __value);
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (!(*__i == __value))
+            {
+                *__first = _STD::move(*__i);
+                ++__first;
+            }
+        }
+    }
+    return __first;
+}
+
+// remove_if
+
+template <class _ForwardIterator, class _Predicate>
+_ForwardIterator
+remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
+{
+    __first = _STD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
+                           (__first, __last, __pred);
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (!__pred(*__i))
+            {
+                *__first = _STD::move(*__i);
+                ++__first;
+            }
+        }
+    }
+    return __first;
+}
+
+// remove_copy
+
+template <class _InputIterator, class _OutputIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value)
+{
+    for (; __first != __last; ++__first)
+    {
+        if (!(*__first == __value))
+        {
+            *__result = *__first;
+            ++__result;
+        }
+    }
+    return __result;
+}
+
+// remove_copy_if
+
+template <class _InputIterator, class _OutputIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+    {
+        if (!__pred(*__first))
+        {
+            *__result = *__first;
+            ++__result;
+        }
+    }
+    return __result;
+}
+
+// unique
+
+template <class _ForwardIterator, class _BinaryPredicate>
+_ForwardIterator
+unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
+{
+    __first = _STD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
+                                 (__first, __last, __pred);
+    if (__first != __last)
+    {
+        // ...  a  a  ?  ...
+        //      f     i
+        _ForwardIterator __i = __first;
+        for (++__i; ++__i != __last;)
+            if (!__pred(*__first, *__i))
+                *++__first = _STD::move(*__i);
+        ++__first;
+    }
+    return __first;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+unique(_ForwardIterator __first, _ForwardIterator __last)
+{
+    typedef typename iterator_traits<_ForwardIterator>::value_type __v;
+    return _STD::unique(__first, __last, __equal_to<__v>());
+}
+
+// unique_copy
+
+template <class _BinaryPredicate, class _InputIterator, class _OutputIterator>
+_OutputIterator
+__unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
+              input_iterator_tag, output_iterator_tag)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t(*__first);
+        *__result = __t;
+        ++__result;
+        while (++__first != __last)
+        {
+            if (!__pred(__t, *__first))
+            {
+                __t = *__first;
+                *__result = __t;
+                ++__result;
+            }
+        }
+    }
+    return __result;
+}
+
+template <class _BinaryPredicate, class _ForwardIterator, class _OutputIterator>
+_OutputIterator
+__unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
+              forward_iterator_tag, output_iterator_tag)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        *__result = *__i;
+        ++__result;
+        while (++__first != __last)
+        {
+            if (!__pred(*__i, *__first))
+            {
+                *__result = *__first;
+                ++__result;
+                __i = __first;
+            }
+        }
+    }
+    return __result;
+}
+
+template <class _BinaryPredicate, class _InputIterator, class _ForwardIterator>
+_ForwardIterator
+__unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred,
+              input_iterator_tag, forward_iterator_tag)
+{
+    if (__first != __last)
+    {
+        *__result = *__first;
+        while (++__first != __last)
+            if (!__pred(*__result, *__first))
+                *++__result = *__first;
+        ++__result;
+    }
+    return __result;
+}
+
+
+template <class _InputIterator, class _OutputIterator, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
+{
+    return _STD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type>
+                              (__first, __last, __result, __pred,
+                               typename iterator_traits<_InputIterator>::iterator_category(),
+                               typename iterator_traits<_OutputIterator>::iterator_category());
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    typedef typename iterator_traits<_InputIterator>::value_type __v;
+    return _STD::unique_copy(__first, __last, __result, __equal_to<__v>());
+}
+
+// reverse
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
+{
+    while (__first != __last)
+    {
+        if (__first == --__last)
+            break;
+        swap(*__first, *__last);
+        ++__first;
+    }
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
+{
+    if (__first != __last)
+        for (; __first < --__last; ++__first)
+            swap(*__first, *__last);
+}
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
+{
+    _STD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category());
+}
+
+// reverse_copy
+
+template <class _BidirectionalIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
+{
+    for (; __first != __last; ++__result)
+        *__result = *--__last;
+    return __result;
+}
+
+// rotate
+
+template <class _ForwardIterator>
+_ForwardIterator
+__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, false_type)
+{
+    if (__first == __middle)
+        return __last;
+    if (__middle == __last)
+        return __first;
+    _ForwardIterator __i = __middle;
+    while (true)
+    {
+        swap(*__first, *__i);
+        ++__first;
+        if (++__i == __last)
+            break;
+        if (__first == __middle)
+            __middle = __i;
+    }
+    _ForwardIterator __r = __first;
+    if (__first != __middle)
+    {
+        __i = __middle;
+        while (true)
+        {
+            swap(*__first, *__i);
+            ++__first;
+            if (++__i == __last)
+            {
+                if (__first == __middle)
+                    break;
+                __i = __middle;
+            }
+            else if (__first == __middle)
+                __middle = __i;
+        }
+    }
+    return __r;
+}
+
+template<typename _Integral>
+inline _LIBCPP_INLINE_VISIBILITY
+_Integral
+__gcd(_Integral __x, _Integral __y)
+{
+    do
+    {
+        _Integral __t = __x % __y;
+        __x = __y;
+        __y = __t;
+    } while (__y);
+    return __x;
+}
+
+template<typename _RandomAccessIterator>
+_RandomAccessIterator
+__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, true_type)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    
+    if (__first == __middle)
+        return __last;
+    if (__middle == __last)
+        return __first;
+    const difference_type __m1 = __middle - __first;
+    const difference_type __m2 = __last - __middle;
+    if (__m1 == __m2)
+    {
+        _STD::swap_ranges(__first, __middle, __middle);
+        return __middle;
+    }
+    const difference_type __g = __gcd(__m1, __m2);
+    for (_RandomAccessIterator __p = __first + __g; __p != __first;)
+    {
+        value_type __t(*--__p);
+        _RandomAccessIterator __p1 = __p;
+        _RandomAccessIterator __p2 = __p1 + __m1;
+        do
+        {
+            *__p1 = *__p2;
+            __p1 = __p2;
+            const difference_type __d = __last - __p2;
+            if (__m1 < __d)
+                __p2 += __m1;
+            else
+                __p2 = __first + (__m1 - __d);
+        } while (__p2 != __p);
+        *__p1 = __t;
+    }
+    return __first + __m2;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
+{
+    return _STD::__rotate(__first, __middle, __last,
+                          integral_constant
+                          <
+                               bool,
+                               is_convertible
+                               <
+                                   typename iterator_traits<_ForwardIterator>::iterator_category,
+                                   random_access_iterator_tag
+                               >::value &&
+                               has_trivial_copy_assign
+                               <
+                                   typename iterator_traits<_ForwardIterator>::value_type
+                               >::value
+                           >());
+}
+
+// rotate_copy
+
+template <class _ForwardIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result)
+{
+    return _STD::copy(__first, __middle, _STD::copy(__middle, __last, __result));
+}
+
+// min
+
+template <class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+const _Tp&
+min(const _Tp& __a, const _Tp& __b, _Compare __comp)
+{
+    return __comp(__b, __a) ? __b : __a;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+const _Tp&
+min(const _Tp& __a, const _Tp& __b)
+{
+    return _STD::min(__a, __b, __less<_Tp>());
+}
+
+// max
+
+template <class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+const _Tp&
+max(const _Tp& __a, const _Tp& __b, _Compare __comp)
+{
+    return __comp(__a, __b) ? __b : __a;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+const _Tp&
+max(const _Tp& __a, const _Tp& __b)
+{
+    return _STD::max(__a, __b, __less<_Tp>());
+}
+
+// min_element
+
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+            if (__comp(*__i, *__first))
+                __first = __i;
+    }
+    return __first;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+min_element(_ForwardIterator __first, _ForwardIterator __last)
+{
+    return _STD::min_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// max_element
+
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+            if (__comp(*__first, *__i))
+                __first = __i;
+    }
+    return __first;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+max_element(_ForwardIterator __first, _ForwardIterator __last)
+{
+    return _STD::max_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// minmax_element
+
+template <class _ForwardIterator, class _Compare>
+std::pair<_ForwardIterator, _ForwardIterator>
+minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+  std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
+  if (__first != __last)
+  {
+      if (++__first != __last)
+      {
+          if (__comp(*__first, *__result.first))
+          {
+              __result.second = __result.first;
+              __result.first = __first;
+          }
+          else
+              __result.second = __first;
+          while (++__first != __last)
+          {
+              _ForwardIterator __i = __first;
+              if (++__first == __last)
+              {
+                  if (__comp(*__i, *__result.first))
+                      __result.first = __i;
+                  else if (!__comp(*__i, *__result.second))
+                      __result.second = __i;
+                  break;
+              }
+              else
+              {
+                  if (__comp(*__first, *__i))
+                  {
+                      if (__comp(*__first, *__result.first))
+                          __result.first = __first;
+                      if (!__comp(*__i, *__result.second))
+                          __result.second = __i;
+                  }
+                  else
+                  {
+                      if (__comp(*__i, *__result.first))
+                          __result.first = __i;
+                      if (!__comp(*__first, *__result.second))
+                          __result.second = __first;
+                  }
+              }
+          }
+      }
+  }
+  return __result;
+}
+
+template <class _ForwardIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+std::pair<_ForwardIterator, _ForwardIterator>
+minmax_element(_ForwardIterator __first, _ForwardIterator __last)
+{
+    return _STD::minmax_element(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// random_shuffle
+
+template <unsigned int _Bits>
+struct __num_bits
+{
+    static const int __value = 1 + __num_bits<(_Bits >> 1)>::__value;
+};
+
+template <>
+struct __num_bits<0>
+{
+    static const int __value = 0;
+};
+
+const int __rbits = __num_bits<RAND_MAX>::__value;
+const int __lbits = static_cast<int>(sizeof(unsigned long) * __CHAR_BIT__);
+
+template <int _NBits, bool = _NBits <= __rbits>
+struct __random_bits
+{
+    _LIBCPP_INLINE_VISIBILITY operator unsigned long () const
+        {return static_cast<unsigned long>(_STD::rand()) >> (__rbits - _NBits);}
+};
+
+template <int _NBits>
+struct __random_bits<_NBits, false>
+{
+    _LIBCPP_INLINE_VISIBILITY operator unsigned long () const
+        {return static_cast<unsigned long>(_STD::rand()) << (_NBits - __rbits) | __random_bits<_NBits - __rbits>();}
+};
+
+template <int _NBits>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__slab_size(unsigned long __n)
+{
+    return (1UL << _NBits) / __n;
+}
+
+template <>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__slab_size<__lbits>(unsigned long __n)
+{
+    if (__n & 1)
+        return (unsigned long)(~0) / __n;
+    return (1UL << (__lbits-1)) / (__n >> 1);
+}
+
+template <int _NBits>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__scaled_random_number(unsigned long __n)
+{
+    const unsigned long __slab = __slab_size<_NBits>(__n);
+    const unsigned long __usable = __slab * __n;
+    unsigned long __raw;
+    do
+        __raw = __random_bits<_NBits>();
+    while (__raw >= __usable);
+    return __raw / __slab;
+}
+
+template <bool __b, unsigned long = __lbits/__rbits> struct __rs_default;
+
+template <bool __b>
+struct __rs_default<__b, 1>
+{
+    unsigned long operator()(unsigned long __n = 0) const;
+};
+
+template <bool __b>
+unsigned long
+__rs_default<__b, 1>::operator()(unsigned long __n) const
+{
+    switch (__n)
+    {
+    case 0:
+        return __random_bits<__lbits>();
+    case 1:
+        return 0;
+    }
+    if (__n <= (1UL << __rbits))
+        return __scaled_random_number<__rbits>(__n);
+    return __scaled_random_number<__lbits>(__n);
+}
+
+template <bool __b>
+struct __rs_default<__b, 2>
+{
+    unsigned long operator()(unsigned long __n = 0) const;
+};
+
+template <bool __b>
+unsigned long
+__rs_default<__b, 2>::operator()(unsigned long __n) const
+{
+    switch (__n)
+    {
+    case 0:
+        return __random_bits<__lbits>();
+    case 1:
+        return 0;
+    }
+    int __nb = __rbits;
+    while (__nb < __lbits && __n > (1UL << __nb))
+        __nb += _STD::min(__rbits, __lbits - __nb);
+    switch (__nb)
+    {
+    case __rbits:
+        return __scaled_random_number<__rbits>(__n);
+    case 2*__rbits:
+        return __scaled_random_number<2*__rbits>(__n);
+    }
+    return __scaled_random_number<__lbits>(__n);
+}
+
+template <class _RandomAccessIterator>
+void
+random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    difference_type __d = __last - __first;
+    if (__d > 1)
+    {
+        for (--__last; __first < __last; ++__first, --__d)
+            swap(*__first, *(__first
+                + static_cast<difference_type>(__rs_default<true>()(static_cast<unsigned long>(__d)))));
+    }
+}
+
+template <class _RandomAccessIterator, class _RandomNumberGenerator>
+void
+random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
+#ifdef _LIBCPP_MOVE
+               _RandomNumberGenerator&& __rand)
+#else
+               _RandomNumberGenerator& __rand)
+#endif
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    difference_type __d = __last - __first;
+    if (__d > 1)
+    {
+        for (--__last; __first < __last; ++__first, --__d)
+            swap(*__first, *(__first + __rand(__d)));
+    }
+}
+
+template <class _InputIterator, class _Predicate>
+bool
+is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+        if (!__pred(*__first))
+            break;
+    for (; __first != __last; ++__first)
+        if (__pred(*__first))
+            return false;
+    return true;
+}
+
+// partition
+
+template <class _Predicate, class _ForwardIterator>
+_ForwardIterator
+__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
+{
+    while (true)
+    {
+        if (__first == __last)
+            return __first;
+        if (!__pred(*__first))
+            break;
+        ++__first;
+    }
+    for (_ForwardIterator __p = __first; ++__p != __last;)
+    {
+        if (__pred(*__p))
+        {
+            swap(*__first, *__p);
+            ++__first;
+        }
+    }
+    return __first;
+}
+
+template <class _Predicate, class _BidirectionalIterator>
+_BidirectionalIterator
+__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
+            bidirectional_iterator_tag)
+{
+    while (true)
+    {
+        while (true)
+        {
+            if (__first == __last)
+                return __first;
+            if (!__pred(*__first))
+                break;
+            ++__first;
+        }
+        do
+        {
+            if (__first == --__last)
+                return __first;
+        } while (!__pred(*__last));
+        swap(*__first, *__last);
+        ++__first;
+    }
+}
+
+template <class _ForwardIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
+{
+    return _STD::__partition<typename add_lvalue_reference<_Predicate>::type>
+                            (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+}
+
+// partition_copy
+
+template <class _InputIterator, class _OutputIterator1,
+          class _OutputIterator2, class _Predicate>
+pair<_OutputIterator1, _OutputIterator2>
+partition_copy(_InputIterator __first, _InputIterator __last,
+               _OutputIterator1 __out_true, _OutputIterator2 __out_false,
+               _Predicate __pred)
+{
+    for (; __first != __last; ++__first)
+    {
+        if (__pred(*__first))
+        {
+            *__out_true = *__first;
+            ++__out_true;
+        }
+        else
+        {
+            *__out_false = *__first;
+            ++__out_false;
+        }
+    }
+    return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
+}
+
+// partition_point
+
+template<class _ForwardIterator, class _Predicate>
+_ForwardIterator
+partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
+{
+    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+    difference_type __len = _STD::distance(__first, __last);
+    while (__len != 0)
+    {
+        difference_type __l2 = __len / 2;
+        _ForwardIterator __m = __first;
+        _STD::advance(__m, __l2);
+        if (__pred(*__m))
+        {
+            __first = ++__m;
+            __len -= __l2 + 1;
+        }
+        else
+            __len = __l2;
+    }
+    return __first;
+}
+
+// stable_partition
+
+template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
+_ForwardIterator
+__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
+                   _Distance __len, _Pair __p, forward_iterator_tag __fit)
+{
+    // *__first is known to be false
+    // __len >= 1
+    if (__len == 1)
+        return __first;
+    if (__len == 2)
+    {
+        _ForwardIterator __m = __first;
+        if (__pred(*++__m))
+        {
+            swap(*__first, *__m);
+            return __m;
+        }
+        return __first;
+    }
+    if (__len <= __p.second)
+    {   // The buffer is big enough to use
+        typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+        __destruct_n __d(0);
+        unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
+        // Move the falses into the temporary buffer, and the trues to the front of the line
+        // Update __first to always point to the end of the trues
+        value_type* __t = __p.first;
+        ::new(__t) value_type(_STD::move(*__first));
+        __d.__incr((value_type*)0);
+        ++__t;
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (__pred(*__i))
+            {
+                *__first = _STD::move(*__i);
+                ++__first;
+            }
+            else
+            {
+                ::new(__t) value_type(_STD::move(*__i));
+                __d.__incr((value_type*)0);
+                ++__t;
+            }
+        }
+        // All trues now at start of range, all falses in buffer
+        // Move falses back into range, but don't mess up __first which points to first false
+        __i = __first;
+        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i)
+            *__i = _STD::move(*__t2);
+        // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
+        return __first;
+    }
+    // Else not enough buffer, do in place
+    // __len >= 3
+    _ForwardIterator __m = __first;
+    _Distance __len2 = __len / 2;  // __len2 >= 2
+    _STD::advance(__m, __len2);
+    // recurse on [__first, __m), *__first know to be false
+    // F?????????????????
+    // f       m         l
+    typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
+    _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit);
+    // TTTFFFFF??????????
+    // f  ff   m         l
+    // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
+    _ForwardIterator __m1 = __m;
+    _ForwardIterator __second_false = __last;
+    _Distance __len_half = __len - __len2;
+    while (__pred(*__m1))
+    {
+        if (++__m1 == __last)
+            goto __second_half_done;
+        --__len_half;
+    }
+    // TTTFFFFFTTTF??????
+    // f  ff   m  m1     l
+    __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit);
+__second_half_done:
+    // TTTFFFFFTTTTTFFFFF
+    // f  ff   m    sf   l
+    return _STD::rotate(__first_false, __m, __second_false);
+    // TTTTTTTTFFFFFFFFFF
+    //         |
+}
+
+struct __return_temporary_buffer
+{
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_STD::return_temporary_buffer(__p);}
+};
+
+template <class _Predicate, class _ForwardIterator>
+_ForwardIterator
+__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
+                   forward_iterator_tag)
+{
+    const unsigned __alloc_limit = 3;  // might want to make this a function of trivial assignment
+    // Either prove all true and return __first or point to first false
+    while (true)
+    {
+        if (__first == __last)
+            return __first;
+        if (!__pred(*__first))
+            break;
+        ++__first;
+    }
+    // We now have a reduced range [__first, __last)
+    // *__first is known to be false
+    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    difference_type __len = _STD::distance(__first, __last);
+    pair<value_type*, ptrdiff_t> __p(0, 0);
+    unique_ptr<value_type, __return_temporary_buffer> __h;
+    if (__len >= __alloc_limit)
+    {
+        __p = _STD::get_temporary_buffer<value_type>(__len);
+        __h.reset(__p.first);
+    }
+    return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
+                             (__first, __last, __pred, __len, __p, forward_iterator_tag());
+}
+
+template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
+_BidirectionalIterator
+__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
+                   _Distance __len, _Pair __p, bidirectional_iterator_tag __bit)
+{
+    // *__first is known to be false
+    // *__last is known to be true
+    // __len >= 2
+    if (__len == 2)
+    {
+        swap(*__first, *__last);
+        return __last;
+    }
+    if (__len == 3)
+    {
+        _BidirectionalIterator __m = __first;
+        if (__pred(*++__m))
+        {
+            swap(*__first, *__m);
+            swap(*__m, *__last);
+            return __last;
+        }
+        swap(*__m, *__last);
+        swap(*__first, *__m);
+        return __m;
+    }
+    if (__len <= __p.second)
+    {   // The buffer is big enough to use
+        typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+        __destruct_n __d(0);
+        unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
+        // Move the falses into the temporary buffer, and the trues to the front of the line
+        // Update __first to always point to the end of the trues
+        value_type* __t = __p.first;
+        ::new(__t) value_type(_STD::move(*__first));
+        __d.__incr((value_type*)0);
+        ++__t;
+        _BidirectionalIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (__pred(*__i))
+            {
+                *__first = _STD::move(*__i);
+                ++__first;
+            }
+            else
+            {
+                ::new(__t) value_type(_STD::move(*__i));
+                __d.__incr((value_type*)0);
+                ++__t;
+            }
+        }
+        // move *__last, known to be true
+        *__first = _STD::move(*__i);
+        __i = ++__first;
+        // All trues now at start of range, all falses in buffer
+        // Move falses back into range, but don't mess up __first which points to first false
+        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i)
+            *__i = _STD::move(*__t2);
+        // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
+        return __first;
+    }
+    // Else not enough buffer, do in place
+    // __len >= 4
+    _BidirectionalIterator __m = __first;
+    _Distance __len2 = __len / 2;  // __len2 >= 2
+    _STD::advance(__m, __len2);
+    // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
+    // F????????????????T
+    // f       m        l
+    _BidirectionalIterator __m1 = __m;
+    _BidirectionalIterator __first_false = __first;
+    _Distance __len_half = __len2;
+    while (!__pred(*--__m1))
+    {
+        if (__m1 == __first)
+            goto __first_half_done;
+        --__len_half;
+    }
+    // F???TFFF?????????T
+    // f   m1  m        l
+    typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
+    __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit);
+__first_half_done:
+    // TTTFFFFF?????????T
+    // f  ff   m        l
+    // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
+    __m1 = __m;
+    _BidirectionalIterator __second_false = __last;
+    ++__second_false;
+    __len_half = __len - __len2;
+    while (__pred(*__m1))
+    {
+        if (++__m1 == __last)
+            goto __second_half_done;
+        --__len_half;
+    }
+    // TTTFFFFFTTTF?????T
+    // f  ff   m  m1    l
+    __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit);
+__second_half_done:
+    // TTTFFFFFTTTTTFFFFF
+    // f  ff   m    sf  l
+    return _STD::rotate(__first_false, __m, __second_false);
+    // TTTTTTTTFFFFFFFFFF
+    //         |
+}
+
+template <class _Predicate, class _BidirectionalIterator>
+_BidirectionalIterator
+__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
+                   bidirectional_iterator_tag)
+{
+    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+    const difference_type __alloc_limit = 4;  // might want to make this a function of trivial assignment
+    // Either prove all true and return __first or point to first false
+    while (true)
+    {
+        if (__first == __last)
+            return __first;
+        if (!__pred(*__first))
+            break;
+        ++__first;
+    }
+    // __first points to first false, everything prior to __first is already set.
+    // Either prove [__first, __last) is all false and return __first, or point __last to last true
+    do
+    {
+        if (__first == --__last)
+            return __first;
+    } while (!__pred(*__last));
+    // We now have a reduced range [__first, __last]
+    // *__first is known to be false
+    // *__last is known to be true
+    // __len >= 2
+    difference_type __len = _STD::distance(__first, __last) + 1;
+    pair<value_type*, ptrdiff_t> __p(0, 0);
+    unique_ptr<value_type, __return_temporary_buffer> __h;
+    if (__len >= __alloc_limit)
+    {
+        __p = _STD::get_temporary_buffer<value_type>(__len);
+        __h.reset(__p.first);
+    }
+    return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
+                             (__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
+}
+
+template <class _ForwardIterator, class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
+{
+    return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
+                             (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+}
+
+// is_sorted_until
+
+template <class _ForwardIterator, class _Compare>
+_ForwardIterator
+is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    if (__first != __last)
+    {
+        _ForwardIterator __i = __first;
+        while (++__i != __last)
+        {
+            if (__comp(*__i, *__first))
+                return __i;
+            __first = __i;
+        }
+    }
+    return __last;
+}
+
+template<class _ForwardIterator> 
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
+{
+    return _STD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// is_sorted
+
+template <class _ForwardIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
+{
+    return _STD::is_sorted_until(__first, __last, __comp) == __last;
+}
+
+template<class _ForwardIterator> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_sorted(_ForwardIterator __first, _ForwardIterator __last)
+{
+    return _STD::is_sorted(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// sort
+
+// stable, 2-3 compares, 0-2 swaps
+
+template <class _Compare, class _ForwardIterator>
+unsigned
+__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c)
+{
+    unsigned __r = 0;
+    if (!__c(*__y, *__x))          // if x <= y
+    {
+        if (!__c(*__z, *__y))      // if y <= z
+            return __r;            // x <= y && y <= z
+                                   // x <= y && y > z
+        swap(*__y, *__z);          // x <= z && y < z
+        __r = 1;
+        if (__c(*__y, *__x))       // if x > y
+        {
+            swap(*__x, *__y);      // x < y && y <= z
+            __r = 2;
+        }
+        return __r;                // x <= y && y < z
+    }
+    if (__c(*__z, *__y))           // x > y, if y > z
+    {
+        swap(*__x, *__z);          // x < y && y < z
+        __r = 1;
+        return __r;
+    }
+    swap(*__x, *__y);              // x > y && y <= z
+    __r = 1;                       // x < y && x <= z
+    if (__c(*__z, *__y))           // if y > z
+    {
+        swap(*__y, *__z);          // x <= y && y < z
+        __r = 2;
+    }
+    return __r;
+}                                  // x <= y && y <= z
+
+// stable, 3-6 compares, 0-5 swaps
+
+template <class _Compare, class _ForwardIterator>
+unsigned
+__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
+            _ForwardIterator __x4, _Compare __c)
+{
+    unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c);
+    if (__c(*__x4, *__x3))
+    {
+        swap(*__x3, *__x4);
+        ++__r;
+        if (__c(*__x3, *__x2))
+        {
+            swap(*__x2, *__x3);
+            ++__r;
+            if (__c(*__x2, *__x1))
+            {
+                swap(*__x1, *__x2);
+                ++__r;
+            }
+        }
+    }
+    return __r;
+}
+
+// stable, 4-10 compares, 0-9 swaps
+
+template <class _Compare, class _ForwardIterator>
+unsigned
+__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
+            _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c)
+{
+    unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c);
+    if (__c(*__x5, *__x4))
+    {
+        swap(*__x4, *__x5);
+        ++__r;
+        if (__c(*__x4, *__x3))
+        {
+            swap(*__x3, *__x4);
+            ++__r;
+            if (__c(*__x3, *__x2))
+            {
+                swap(*__x2, *__x3);
+                ++__r;
+                if (__c(*__x2, *__x1))
+                {
+                    swap(*__x1, *__x2);
+                    ++__r;
+                }
+            }
+        }
+    }
+    return __r;
+}
+
+// Assumes size > 0
+template <class _Compare, class _BirdirectionalIterator>
+void
+__selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp)
+{
+    _BirdirectionalIterator __lm1 = __last;
+    for (--__lm1; __first != __lm1; ++__first)
+    {
+        _BirdirectionalIterator __i = _STD::min_element<_BirdirectionalIterator,
+                                                        typename add_lvalue_reference<_Compare>::type>
+                                                       (__first, __last, __comp);
+        if (__i != __first)
+            swap(*__first, *__i);
+    }
+}
+
+template <class _Compare, class _BirdirectionalIterator>
+void
+__insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp)
+{
+    typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type;
+    if (__first != __last)
+    {
+        _BirdirectionalIterator __i = __first;
+        for (++__i; __i != __last; ++__i)
+        {
+            _BirdirectionalIterator __j = __i;
+            value_type __t(_STD::move(*__j));
+            for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t,  *--__k); --__j)
+                *__j = _STD::move(*__k);
+            *__j = _STD::move(__t);
+        }
+    }
+}
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    _RandomAccessIterator __j = __first+2;
+    __sort3<_Compare>(__first, __first+1, __j, __comp);
+    for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
+    {
+        if (__comp(*__i, *__j))
+        {
+            value_type __t(_STD::move(*__i));
+            _RandomAccessIterator __k = __j;
+            __j = __i;
+            do
+            {
+                *__j = _STD::move(*__k);
+                __j = __k;
+            } while (__j != __first && __comp(__t, *--__k));
+            *__j = _STD::move(__t);
+        }
+        __j = __i;
+    }
+}
+
+template <class _Compare, class _RandomAccessIterator>
+bool
+__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    switch (__last - __first)
+    {
+    case 0:
+    case 1:
+        return true;
+    case 2:
+        if (__comp(*--__last, *__first))
+            swap(*__first, *__last);
+        return true;
+    case 3:
+        _STD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
+        return true;
+    case 4:
+        _STD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
+        return true;
+    case 5:
+        _STD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
+        return true;
+    }
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    _RandomAccessIterator __j = __first+2;
+    __sort3<_Compare>(__first, __first+1, __j, __comp);
+    const unsigned __limit = 8;
+    unsigned __count = 0;
+    for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
+    {
+        if (__comp(*__i, *__j))
+        {
+            value_type __t(_STD::move(*__i));
+            _RandomAccessIterator __k = __j;
+            __j = __i;
+            do
+            {
+                *__j = _STD::move(*__k);
+                __j = __k;
+            } while (__j != __first && __comp(__t, *--__k));
+            *__j = _STD::move(__t);
+            if (++__count == __limit)
+                return ++__i == __last;
+        }
+        __j = __i;
+    }
+    return true;
+}
+
+template <class _Compare, class _BirdirectionalIterator>
+void
+__insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1,
+                      typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp)
+{
+    typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type;
+    if (__first1 != __last1)
+    {
+        __destruct_n __d(0);
+        unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
+        value_type* __last2 = __first2;
+        ::new(__last2) value_type(_STD::move(*__first1));
+        __d.__incr((value_type*)0);
+        for (++__last2; ++__first1 != __last1; ++__last2)
+        {
+            value_type* __j2 = __last2;
+            value_type* __i2 = __j2;
+            if (__comp(*__first1, *--__i2))
+            {
+                ::new(__j2) value_type(_STD::move(*__i2));
+                __d.__incr((value_type*)0);
+                for (--__j2; __i2 != __first2 && __comp(*__first1,  *--__i2); --__j2)
+                    *__j2 = _STD::move(*__i2);
+                *__j2 = _STD::move(*__first1);
+            }
+            else
+            {
+                ::new(__j2) value_type(_STD::move(*__first1));
+                __d.__incr((value_type*)0);
+            }
+        }
+        __h.release();
+    }
+}
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    // _Compare is known to be a reference type
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    const difference_type __limit = has_trivial_copy_constructor<value_type>::value &&
+                                    has_trivial_copy_assign<value_type>::value ? 30 : 6;
+    while (true)
+    {
+    __restart:
+        difference_type __len = __last - __first;
+        switch (__len)
+        {
+        case 0:
+        case 1:
+            return;
+        case 2:
+            if (__comp(*--__last, *__first))
+                swap(*__first, *__last);
+            return;
+        case 3:
+            _STD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
+            return;
+        case 4:
+            _STD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
+            return;
+        case 5:
+            _STD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
+            return;
+        }
+        if (__len <= __limit)
+        {
+            _STD::__insertion_sort_3<_Compare>(__first, __last, __comp);
+            return;
+        }
+        // __len > 5
+        _RandomAccessIterator __m = __first;
+        _RandomAccessIterator __lm1 = __last;
+        --__lm1;
+        unsigned __n_swaps;
+        {
+        difference_type __delta;
+        if (__len >= 1000)
+        {
+            __delta = __len/2;
+            __m += __delta;
+            __delta /= 2;
+            __n_swaps = _STD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp);
+        }
+        else
+        {
+            __delta = __len/2;
+            __m += __delta;
+            __n_swaps = _STD::__sort3<_Compare>(__first, __m, __lm1, __comp);
+        }
+        }
+        // *__m is median
+        // partition [__first, __m) < *__m and *__m <= [__m, __last)
+        // (this inhibits tossing elements equivalent to __m around unnecessarily)
+        _RandomAccessIterator __i = __first;
+        _RandomAccessIterator __j = __lm1;
+        // j points beyond range to be tested, *__m is known to be <= *__lm1
+        // The search going up is known to be guarded but the search coming down isn't.
+        // Prime the downward search with a guard.
+        if (!__comp(*__i, *__m))  // if *__first == *__m
+        {
+            // *__first == *__m, *__first doesn't go in first part
+            // manually guard downward moving __j against __i
+            while (true)
+            {
+                if (__i == --__j)
+                {
+                    // *__first == *__m, *__m <= all other elements
+                    // Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
+                    ++__i;  // __first + 1
+                    __j = __last;
+                    if (!__comp(*__first, *--__j))  // we need a guard if *__first == *(__last-1)
+                    {
+                        while (true)
+                        {
+                            if (__i == __j)
+                                return;  // [__first, __last) all equivalent elements
+                            if (__comp(*__first, *__i))
+                            {
+                                swap(*__i, *__j);
+                                ++__n_swaps;
+                                ++__i;
+                                break;
+                            }
+                            ++__i;
+                        }
+                    }
+                    // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
+                    if (__i == __j)
+                        return;
+                    while (true)
+                    {
+                        while (!__comp(*__first, *__i))
+                            ++__i;
+                        while (__comp(*__first, *--__j))
+                            ;
+                        if (__i >= __j)
+                            break;
+                        swap(*__i, *__j);
+                        ++__n_swaps;
+                        ++__i;
+                    }
+                    // [__first, __i) == *__first and *__first < [__i, __last)
+                    // The first part is sorted, sort the secod part
+                    // _STD::__sort<_Compare>(__i, __last, __comp);
+                    __first = __i;
+                    goto __restart;
+                }
+                if (__comp(*__j, *__m))
+                {
+                    swap(*__i, *__j);
+                    ++__n_swaps;
+                    break;  // found guard for downward moving __j, now use unguarded partition
+                }
+            }
+        }
+        // It is known that *__i < *__m
+        ++__i;
+        // j points beyond range to be tested, *__m is known to be <= *__lm1
+        // if not yet partitioned...
+        if (__i < __j)
+        {
+            // known that *(__i - 1) < *__m
+            // known that __i <= __m
+            while (true)
+            {
+                // __m still guards upward moving __i
+                while (__comp(*__i, *__m))
+                    ++__i;
+                // It is now known that a guard exists for downward moving __j
+                while (!__comp(*--__j, *__m))
+                    ;
+                if (__i > __j)
+                    break;
+                swap(*__i, *__j);
+                ++__n_swaps;
+                // It is known that __m != __j
+                // If __m just moved, follow it
+                if (__m == __i)
+                    __m = __j;
+                ++__i;
+            }
+        }
+        // [__first, __i) < *__m and *__m <= [__i, __last)
+        if (__i != __m && __comp(*__m, *__i))
+        {
+            swap(*__i, *__m);
+            ++__n_swaps;
+        }
+        // [__first, __i) < *__i and *__i <= [__i+1, __last)
+        // If we were given a perfect partition, see if insertion sort is quick...
+        if (__n_swaps == 0)
+        {
+            bool __fs = _STD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp);
+            if (_STD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp))
+            {
+                if (__fs)
+                    return;
+                __last = __i;
+                continue;
+            }
+            else
+            {
+                if (__fs)
+                {
+                    __first = ++__i;
+                    continue;
+                }
+            }
+        }
+        // sort smaller range with recursive call and larger with tail recursion elimination
+        if (__i - __first < __last - __i)
+        {
+            _STD::__sort<_Compare>(__first, __i, __comp);
+            // _STD::__sort<_Compare>(__i+1, __last, __comp);
+            __first = ++__i;
+        }
+        else
+        {
+            _STD::__sort<_Compare>(__i+1, __last, __comp);
+            // _STD::__sort<_Compare>(__first, __i, __comp);
+            __last = __i;
+        }
+    }
+}
+
+// This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __sort<_Comp_ref>(__first, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __sort<_Comp_ref>(__first, __last, __comp);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort(_Tp** __first, _Tp** __last)
+{
+    _STD::sort((size_t*)__first, (size_t*)__last, __less<size_t>());
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last)
+{
+    _STD::sort(__first.base(), __last.base());
+}
+
+extern template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
+extern template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
+extern template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
+extern template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
+extern template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
+extern template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
+extern template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
+extern template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
+extern template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
+extern template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
+extern template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
+extern template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
+extern template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
+extern template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
+extern template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+
+extern template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
+extern template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
+extern template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
+extern template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
+extern template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
+extern template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
+extern template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
+extern template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
+extern template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
+extern template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
+extern template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
+extern template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
+extern template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
+extern template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
+extern template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
+
+extern template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
+
+// lower_bound
+
+template <class _Compare, class _ForwardIterator, class _Tp>
+_ForwardIterator
+__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+    difference_type __len = _STD::distance(__first, __last);
+    while (__len != 0)
+    {
+        difference_type __l2 = __len / 2;
+        _ForwardIterator __m = __first;
+        _STD::advance(__m, __l2);
+        if (__comp(*__m, __value))
+        {
+            __first = ++__m;
+            __len -= __l2 + 1;
+        }
+        else
+            __len = __l2;
+    }
+    return __first;
+}
+
+template <class _ForwardIterator, class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __lower_bound<_Comp_ref>(__first, __last, __value, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __lower_bound<_Comp_ref>(__first, __last, __value, __comp);
+#endif
+}
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    return _STD::lower_bound(__first, __last, __value,
+                             __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
+}
+
+// upper_bound
+
+template <class _Compare, class _ForwardIterator, class _Tp>
+_ForwardIterator
+__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+    difference_type __len = _STD::distance(__first, __last);
+    while (__len != 0)
+    {
+        difference_type __l2 = __len / 2;
+        _ForwardIterator __m = __first;
+        _STD::advance(__m, __l2);
+        if (__comp(__value, *__m))
+            __len = __l2;
+        else
+        {
+            __first = ++__m;
+            __len -= __l2 + 1;
+        }
+    }
+    return __first;
+}
+
+template <class _ForwardIterator, class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __upper_bound<_Comp_ref>(__first, __last, __value, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __upper_bound<_Comp_ref>(__first, __last, __value, __comp);
+#endif
+}
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator
+upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    return _STD::upper_bound(__first, __last, __value,
+                             __less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>());
+}
+
+// equal_range
+
+template <class _Compare, class _ForwardIterator, class _Tp>
+pair<_ForwardIterator, _ForwardIterator>
+__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
+    difference_type __len = _STD::distance(__first, __last);
+    while (__len != 0)
+    {
+        difference_type __l2 = __len / 2;
+        _ForwardIterator __m = __first;
+        _STD::advance(__m, __l2);
+        if (__comp(*__m, __value))
+        {
+            __first = ++__m;
+            __len -= __l2 + 1;
+        }
+        else if (__comp(__value, *__m))
+        {
+            __last = __m;
+            __len = __l2;
+        }
+        else
+        {
+            _ForwardIterator __mp1 = __m;
+            return pair<_ForwardIterator, _ForwardIterator>
+                   (
+                      __lower_bound<_Compare>(__first, __m, __value, __comp),
+                      __upper_bound<_Compare>(++__mp1, __last, __value, __comp)
+                   );
+        }
+    }
+    return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
+}
+
+template <class _ForwardIterator, class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_ForwardIterator, _ForwardIterator>
+equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __equal_range<_Comp_ref>(__first, __last, __value, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __equal_range<_Comp_ref>(__first, __last, __value, __comp);
+#endif
+}
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_ForwardIterator, _ForwardIterator>
+equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    return _STD::equal_range(__first, __last, __value,
+                             __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
+}
+
+// binary_search
+
+template <class _Compare, class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+    __first = __lower_bound<_Compare>(__first, __last, __value, __comp);
+    return __first != __last && !__comp(__value, *__first);
+}
+
+template <class _ForwardIterator, class _Tp, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __binary_search<_Comp_ref>(__first, __last, __value, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __binary_search<_Comp_ref>(__first, __last, __value, __comp);
+#endif
+}
+
+template <class _ForwardIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+{
+    return _STD::binary_search(__first, __last, __value,
+                             __less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
+}
+
+// merge
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+_OutputIterator
+__merge(_InputIterator1 __first1, _InputIterator1 __last1,
+        _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+    for (; __first1 != __last1; ++__result)
+    {
+        if (__first2 == __last2)
+            return _STD::copy(__first1, __last1, __result);
+        if (__comp(*__first2, *__first1))
+        {
+            *__result = *__first2;
+            ++__first2;
+        }
+        else
+        {
+            *__result = *__first1;
+            ++__first1;
+        }
+    }
+    return _STD::copy(__first2, __last2, __result);
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+merge(_InputIterator1 __first1, _InputIterator1 __last1,
+      _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return _STD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return _STD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+merge(_InputIterator1 __first1, _InputIterator1 __last1,
+      _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type __v1;
+    typedef typename iterator_traits<_InputIterator2>::value_type __v2;
+    return merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>());
+}
+
+// inplace_merge
+
+template <class _Compare, class _BidirectionalIterator>
+void
+__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
+                _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
+                                 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
+                typename iterator_traits<_BidirectionalIterator>::value_type* __buff)
+{
+    typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_BidirectionalIterator>::pointer pointer;
+    __destruct_n __d(0);
+    unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
+    if (__len1 <= __len2)
+    {
+        value_type* __p = __buff;
+        for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), ++__i, ++__p)
+            ::new(__p) value_type(_STD::move(*__i));
+        __merge<_Compare>(move_iterator<value_type*>(__buff),
+                          move_iterator<value_type*>(__p),
+                          move_iterator<_BidirectionalIterator>(__middle),
+                          move_iterator<_BidirectionalIterator>(__last),
+                          __first, __comp);
+    }
+    else
+    {
+        value_type* __p = __buff;
+        for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), ++__i, ++__p)
+            ::new(__p) value_type(_STD::move(*__i));
+        typedef reverse_iterator<_BidirectionalIterator> _RBi;
+        typedef reverse_iterator<value_type*> _Rv;
+        __merge(move_iterator<_RBi>(_RBi(__middle)), move_iterator<_RBi>(_RBi(__first)),
+                move_iterator<_Rv>(_Rv(__p)), move_iterator<_Rv>(_Rv(__buff)),
+                _RBi(__last), __negate<_Compare>(__comp));
+    }
+}
+
+template <class _Compare, class _BidirectionalIterator>
+void
+__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
+                _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
+                                 typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
+                typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size)
+{
+    typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+    while (true)
+    {
+        // if __middle == __last, we're done
+        if (__len2 == 0)
+            return;
+        // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
+        for (; true; ++__first, --__len1)
+        {
+            if (__len1 == 0)
+                return;
+            if (__comp(*__middle, *__first))
+                break;
+        }
+        if (__len1 <= __buff_size || __len2 <= __buff_size)
+        {
+            __buffered_inplace_merge<_Compare>(__first, __middle, __last, __comp, __len1, __len2, __buff);
+            return;
+        }
+        // __first < __middle < __last
+        // *__first > *__middle
+        // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
+        //     all elements in:
+        //         [__first, __m1)  <= [__middle, __m2)
+        //         [__middle, __m2) <  [__m1, __middle)
+        //         [__m1, __middle) <= [__m2, __last)
+        //     and __m1 or __m2 is in the middle of its range
+        _BidirectionalIterator __m1;  // "median" of [__first, __middle)
+        _BidirectionalIterator __m2;  // "median" of [__middle, __last)
+        difference_type __len11;      // distance(__first, __m1)
+        difference_type __len21;      // distance(__middle, __m2)
+        // binary search smaller range
+        if (__len1 < __len2)
+        {   // __len >= 1, __len2 >= 2
+            __len21 = __len2 / 2;
+            __m2 = __middle;
+            _STD::advance(__m2, __len21);
+            __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp);
+            __len11 = _STD::distance(__first, __m1);
+        }
+        else
+        {
+            if (__len1 == 1)
+            {   // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
+                // It is known *__first > *__middle
+                swap(*__first, *__middle);
+                return;
+            }
+            // __len1 >= 2, __len2 >= 1
+            __len11 = __len1 / 2;
+            __m1 = __first;
+            _STD::advance(__m1, __len11);
+            __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp);
+            __len21 = _STD::distance(__middle, __m2);
+        }
+        difference_type __len12 = __len1 - __len11;  // distance(__m1, __middle)
+        difference_type __len22 = __len2 - __len21;  // distance(__m2, __last)
+        // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
+        // swap middle two partitions
+        __middle = _STD::rotate(__m1, __middle, __m2);
+        // __len12 and __len21 now have swapped meanings
+        // merge smaller range with recurisve call and larger with tail recursion elimination
+        if (__len11 + __len21 < __len12 + __len22)
+        {
+            __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
+//          __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
+            __first = __middle;
+            __middle = __m2;
+            __len1 = __len12;
+            __len2 = __len22;
+        }
+        else
+        {
+            __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
+//          __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
+            __last = __middle;
+            __middle = __m1;
+            __len1 = __len11;
+            __len2 = __len21;
+        }
+    }
+}
+
+template <class _Tp>
+struct __inplace_merge_switch
+{
+    static const unsigned value = has_trivial_copy_assign<_Tp>::value;
+};
+
+template <class _BidirectionalIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
+              _Compare __comp)
+{
+    typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
+    typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
+    difference_type __len1 = _STD::distance(__first, __middle);
+    difference_type __len2 = _STD::distance(__middle, __last);
+    difference_type __buf_size = _STD::min(__len1, __len2);
+    pair<value_type*, ptrdiff_t> __buf(0, 0);
+    unique_ptr<value_type, __return_temporary_buffer> __h;
+    if (__inplace_merge_switch<value_type>::value && __buf_size > 8)
+    {
+        __buf = _STD::get_temporary_buffer<value_type>(__buf_size);
+        __h.reset(__buf.first);
+    }
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return _STD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __c, __len1, __len2,
+                                            __buf.first, __buf.second);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return _STD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2,
+                                            __buf.first, __buf.second);
+#endif
+}
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
+{
+    _STD::inplace_merge(__first, __middle, __last,
+                        __less<typename iterator_traits<_BidirectionalIterator>::value_type>());
+}
+
+// stable_sort
+
+template <class _Compare, class _InputIterator1, class _InputIterator2>
+void
+__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
+        _InputIterator2 __first2, _InputIterator2 __last2,
+        typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp)
+{
+    typedef typename iterator_traits<_InputIterator1>::value_type value_type;
+    __destruct_n __d(0);
+    unique_ptr<value_type, __destruct_n&> __h(__result, __d);
+    for (; true; ++__result)
+    {
+        if (__first1 == __last1)
+        {
+            for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0))
+                ::new (__result) value_type(_STD::move(*__first2));
+            __h.release();
+            return;
+        }
+        if (__first2 == __last2)
+        {
+            for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0))
+                ::new (__result) value_type(_STD::move(*__first1));
+            __h.release();
+            return;
+        }
+        if (__comp(*__first2, *__first1))
+        {
+            ::new (__result) value_type(_STD::move(*__first2));
+            __d.__incr((value_type*)0);
+            ++__first2;
+        }
+        else
+        {
+            ::new (__result) value_type(_STD::move(*__first1));
+            __d.__incr((value_type*)0);
+            ++__first1;
+        }
+    }
+}
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+void
+__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1,
+        _InputIterator2 __first2, _InputIterator2 __last2,
+        _OutputIterator __result, _Compare __comp)
+{
+    for (; __first1 != __last1; ++__result)
+    {
+        if (__first2 == __last2)
+        {
+            for (; __first1 != __last1; ++__first1, ++__result)
+                *__result = _STD::move(*__first1);
+            return;
+        }
+        if (__comp(*__first2, *__first1))
+        {
+            *__result = _STD::move(*__first2);
+            ++__first2;
+        }
+        else
+        {
+            *__result = _STD::move(*__first1);
+            ++__first1;
+        }
+    }
+    for (; __first2 != __last2; ++__first2, ++__result)
+        *__result = _STD::move(*__first2);
+}
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+              typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+              typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size);
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp,
+                   typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+                   typename iterator_traits<_RandomAccessIterator>::value_type* __first2)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    switch (__len)
+    {
+    case 0:
+        return;
+    case 1:
+        ::new(__first2) value_type(_STD::move(*__first1));
+        return;
+    case 2:
+       __destruct_n __d(0);
+        unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
+         if (__comp(*--__last1, *__first1))
+        {
+            ::new(__first2) value_type(_STD::move(*__last1));
+            __d.__incr((value_type*)0);
+            ++__first2;
+            ::new(__first2) value_type(_STD::move(*__first1));
+        }
+        else
+        {
+            ::new(__first2) value_type(_STD::move(*__first1));
+            __d.__incr((value_type*)0);
+            ++__first2;
+            ::new(__first2) value_type(_STD::move(*__last1));
+        }
+        __h2.release();
+        return;
+    }
+    if (__len <= 8)
+    {
+        __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp);
+        return;
+    }
+    typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
+    _RandomAccessIterator __m = __first1 + __l2;
+    __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2);
+    __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
+    __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp);
+}
+
+template <class _Tp>
+struct __stable_sort_switch
+{
+    static const unsigned value = 128*has_trivial_copy_assign<_Tp>::value;
+};
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+              typename iterator_traits<_RandomAccessIterator>::difference_type __len,
+              typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    switch (__len)
+    {
+    case 0:
+    case 1:
+        return;
+    case 2:
+        if (__comp(*--__last, *__first))
+            swap(*__first, *__last);
+        return;
+    }
+    if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value))
+    {
+        __insertion_sort<_Compare>(__first, __last, __comp);
+        return;
+    }
+    typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
+    _RandomAccessIterator __m = __first + __l2;
+    if (__len <= __buff_size)
+    {
+        __destruct_n __d(0);
+        unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
+        __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff);
+        __d.__set(__l2, (value_type*)0);
+        __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
+        __d.__set(__len, (value_type*)0);
+        __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
+//         __merge<_Compare>(move_iterator<value_type*>(__buff),
+//                           move_iterator<value_type*>(__buff + __l2),
+//                           move_iterator<_RandomAccessIterator>(__buff + __l2),
+//                           move_iterator<_RandomAccessIterator>(__buff + __len),
+//                           __first, __comp);
+        return;
+    }
+    __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
+    __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
+    __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    difference_type __len = __last - __first;
+    pair<value_type*, ptrdiff_t> __buf(0, 0);
+    unique_ptr<value_type, __return_temporary_buffer> __h;
+    if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value))
+    {
+        __buf = _STD::get_temporary_buffer<value_type>(__len);
+        __h.reset(__buf.first);
+    }
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __stable_sort<_Comp_ref>(__first, __last, __c, __len, __buf.first, __buf.second);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::stable_sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// is_heap_until
+
+template <class _RandomAccessIterator, class _Compare>
+_RandomAccessIterator
+is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename _STD::iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    difference_type __len = __last - __first;
+    difference_type __p = 0;
+    difference_type __c = 1;
+    _RandomAccessIterator __pp = __first;
+    while (__c < __len)
+    {
+        _RandomAccessIterator __cp = __first + __c;
+        if (__comp(*__pp, *__cp))
+            return __cp;
+        ++__c;
+        ++__cp;
+        if (__c == __len)
+            return __last;
+        if (__comp(*__pp, *__cp))
+            return __cp;
+        ++__p;
+        ++__pp;
+        __c = 2 * __p + 1;
+    }
+    return __last;
+}
+
+template<class _RandomAccessIterator> 
+inline _LIBCPP_INLINE_VISIBILITY
+_RandomAccessIterator
+is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    return _STD::is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// is_heap
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    return _STD::is_heap_until(__first, __last, __comp) == __last;
+}
+
+template<class _RandomAccessIterator> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    return _STD::is_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// push_heap
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__push_heap_front(_RandomAccessIterator __first, _RandomAccessIterator, _Compare __comp,
+                  typename iterator_traits<_RandomAccessIterator>::difference_type __len)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    if (__len > 1)
+    {
+        difference_type __p = 0;
+        _RandomAccessIterator __pp = __first;
+        difference_type __c = 2;
+        _RandomAccessIterator __cp = __first + __c;
+        if (__c == __len || __comp(*__cp, *(__cp - 1)))
+        {
+            --__c;
+            --__cp;
+        }
+        if (__comp(*__pp, *__cp))
+        {
+            value_type __t(_STD::move(*__pp));
+            do
+            {
+                *__pp = _STD::move(*__cp);
+                __pp = __cp;
+                __p = __c;
+                __c = (__p + 1) * 2;
+                if (__c > __len)
+                    break;
+                __cp = __first + __c;
+                if (__c == __len || __comp(*__cp, *(__cp - 1)))
+                {
+                    --__c;
+                    --__cp;
+                }
+            } while (__comp(__t, *__cp));
+            *__pp = _STD::move(__t);
+        }
+    }
+}
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__push_heap_back(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+                 typename iterator_traits<_RandomAccessIterator>::difference_type __len)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
+    if (__len > 1)
+    {
+        __len = (__len - 2) / 2;
+        _RandomAccessIterator __ptr = __first + __len;
+        if (__comp(*__ptr, *--__last))
+        {
+            value_type __t(_STD::move(*__last));
+            do
+            {
+                *__last = _STD::move(*__ptr);
+                __last = __ptr;
+                if (__len == 0)
+                    break;
+                __len = (__len - 1) / 2;
+                __ptr = __first + __len;
+            } while (__comp(*__ptr, __t));
+            *__last = _STD::move(__t);
+        }
+    }
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __push_heap_back<_Comp_ref>(__first, __last, __c, __last - __first);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __push_heap_back<_Comp_ref>(__first, __last, __comp, __last - __first);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::push_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// pop_heap
+
+template <class _Compare, class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+           typename iterator_traits<_RandomAccessIterator>::difference_type __len)
+{
+    if (__len > 1)
+    {
+        swap(*__first, *--__last);
+        __push_heap_front<_Compare>(__first, __last, __comp, __len-1);
+    }
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __pop_heap<_Comp_ref>(__first, __last, __c, __last - __first);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// make_heap
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    difference_type __n = __last - __first;
+    if (__n > 1)
+    {
+        __last = __first;
+        ++__last;
+        for (difference_type __i = 1; __i < __n;)
+            __push_heap_back<_Compare>(__first, ++__last, __comp, ++__i);
+    }
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __make_heap<_Comp_ref>(__first, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __make_heap<_Comp_ref>(__first, __last, __comp);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::make_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// sort_heap
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    for (difference_type __n = __last - __first; __n > 1; --__last, --__n)
+        __pop_heap<_Compare>(__first, __last, __comp, __n);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __sort_heap<_Comp_ref>(__first, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __sort_heap<_Comp_ref>(__first, __last, __comp);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    _STD::sort_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// partial_sort
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
+             _Compare __comp)
+{
+    __make_heap<_Compare>(__first, __middle, __comp);
+    typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
+    for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
+    {
+        if (__comp(*__i, *__first))
+        {
+            swap(*__i, *__first);
+            __push_heap_front<_Compare>(__first, __middle, __comp, __len);
+        }
+    }
+    __sort_heap<_Compare>(__first, __middle, __comp);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
+             _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __partial_sort<_Comp_ref>(__first, __middle, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
+{
+    _STD::partial_sort(__first, __middle, __last,
+                       __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// partial_sort_copy
+
+template <class _Compare, class _InputIterator, class _RandomAccessIterator>
+_RandomAccessIterator
+__partial_sort_copy(_InputIterator __first, _InputIterator __last,
+                    _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
+{
+    _RandomAccessIterator __r = __result_first;
+    if (__r != __result_last)
+    {
+        typename iterator_traits<_RandomAccessIterator>::difference_type __len = 0;
+        for (; __first != __last && __r != __result_last; ++__first, ++__r, ++__len)
+            *__r = *__first;
+        __make_heap<_Compare>(__result_first, __r, __comp);
+        for (; __first != __last; ++__first)
+            if (__comp(*__first, *__result_first))
+            {
+                *__result_first = *__first;
+                __push_heap_front<_Compare>(__result_first, __r, __comp, __len);
+            }
+        __sort_heap<_Compare>(__result_first, __r, __comp);
+    }
+    return __r;
+}
+
+template <class _InputIterator, class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_RandomAccessIterator
+partial_sort_copy(_InputIterator __first, _InputIterator __last,
+                  _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp);
+#endif
+}
+
+template <class _InputIterator, class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_RandomAccessIterator
+partial_sort_copy(_InputIterator __first, _InputIterator __last,
+                  _RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
+{
+    return _STD::partial_sort_copy(__first, __last, __result_first, __result_last,
+                                   __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// nth_element
+
+template <class _Compare, class _RandomAccessIterator>
+void
+__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
+{
+    // _Compare is known to be a reference type
+    typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
+    const difference_type __limit = 7;
+    while (true)
+    {
+    __restart:
+        difference_type __len = __last - __first;
+        switch (__len)
+        {
+        case 0:
+        case 1:
+            return;
+        case 2:
+            if (__comp(*--__last, *__first))
+                swap(*__first, *__last);
+            return;
+        case 3:
+            {
+            _RandomAccessIterator __m = __first;
+            _STD::__sort3<_Compare>(__first, ++__m, --__last, __comp);
+            return;
+            }
+        }
+        if (__len <= __limit)
+        {
+            __selection_sort<_Compare>(__first, __last, __comp);
+            return;
+        }
+        // __len > __limit >= 3
+        _RandomAccessIterator __m = __first + __len/2;
+        _RandomAccessIterator __lm1 = __last;
+        unsigned __n_swaps = _STD::__sort3<_Compare>(__first, __m, --__lm1, __comp);
+        // *__m is median
+        // partition [__first, __m) < *__m and *__m <= [__m, __last)
+        // (this inhibits tossing elements equivalent to __m around unnecessarily)
+        _RandomAccessIterator __i = __first;
+        _RandomAccessIterator __j = __lm1;
+        // j points beyond range to be tested, *__lm1 is known to be <= *__m
+        // The search going up is known to be guarded but the search coming down isn't.
+        // Prime the downward search with a guard.
+        if (!__comp(*__i, *__m))  // if *__first == *__m
+        {
+            // *__first == *__m, *__first doesn't go in first part
+            // manually guard downward moving __j against __i
+            while (true)
+            {
+                if (__i == --__j)
+                {
+                    // *__first == *__m, *__m <= all other elements
+                    // Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
+                    ++__i;  // __first + 1
+                    __j = __last;
+                    if (!__comp(*__first, *--__j))  // we need a guard if *__first == *(__last-1)
+                    {
+                        while (true)
+                        {
+                            if (__i == __j)
+                                return;  // [__first, __last) all equivalent elements
+                            if (__comp(*__first, *__i))
+                            {
+                                swap(*__i, *__j);
+                                ++__n_swaps;
+                                ++__i;
+                                break;
+                            }
+                            ++__i;
+                        }
+                    }
+                    // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
+                    if (__i == __j)
+                        return;
+                    while (true)
+                    {
+                        while (!__comp(*__first, *__i))
+                            ++__i;
+                        while (__comp(*__first, *--__j))
+                            ;
+                        if (__i >= __j)
+                            break;
+                        swap(*__i, *__j);
+                        ++__n_swaps;
+                        ++__i;
+                    }
+                    // [__first, __i) == *__first and *__first < [__i, __last)
+                    // The first part is sorted,
+                    if (__nth < __i)
+                        return;
+                    // __nth_element the secod part
+                    // __nth_element<_Compare>(__i, __nth, __last, __comp);
+                    __first = __i;
+                    goto __restart;
+                }
+                if (__comp(*__j, *__m))
+                {
+                    swap(*__i, *__j);
+                    ++__n_swaps;
+                    break;  // found guard for downward moving __j, now use unguarded partition
+                }
+            }
+        }
+        ++__i;
+        // j points beyond range to be tested, *__lm1 is known to be <= *__m
+        // if not yet partitioned...
+        if (__i < __j)
+        {
+            // known that *(__i - 1) < *__m
+            while (true)
+            {
+                // __m still guards upward moving __i
+                while (__comp(*__i, *__m))
+                    ++__i;
+                // It is now known that a guard exists for downward moving __j
+                while (!__comp(*--__j, *__m))
+                    ;
+                if (__i >= __j)
+                    break;
+                swap(*__i, *__j);
+                ++__n_swaps;
+                // It is known that __m != __j
+                // If __m just moved, follow it
+                if (__m == __i)
+                    __m = __j;
+                ++__i;
+            }
+        }
+        // [__first, __i) < *__m and *__m <= [__i, __last)
+        if (__i != __m && __comp(*__m, *__i))
+        {
+            swap(*__i, *__m);
+            ++__n_swaps;
+        }
+        // [__first, __i) < *__i and *__i <= [__i+1, __last)
+        if (__nth == __i)
+            return;
+        if (__n_swaps == 0)
+        {
+            // We were given a perfectly partitioned sequence.  Coincidence?
+            if (__nth < __i)
+            {
+                // Check for [__first, __i) already sorted
+                __j = __m = __first;
+                while (++__j != __i)
+                {
+                    if (__comp(*__j, *__m))
+                        // not yet sorted, so sort
+                        goto not_sorted;
+                    __m = __j;
+                }
+                // [__first, __i) sorted
+                return;
+            }
+            else
+            {
+                // Check for [__i, __last) already sorted
+                __j = __m = __i;
+                while (++__j != __last)
+                {
+                    if (__comp(*__j, *__m))
+                        // not yet sorted, so sort
+                        goto not_sorted;
+                    __m = __j;
+                }
+                // [__i, __last) sorted
+                return;
+            }
+        }
+not_sorted:
+        // __nth_element on range containing __nth
+        if (__nth < __i)
+        {
+            // __nth_element<_Compare>(__first, __nth, __i, __comp);
+            __last = __i;
+        }
+        else
+        {
+            // __nth_element<_Compare>(__i+1, __nth, __last, __comp);
+            __first = ++__i;
+        }
+    }
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    __nth_element<_Comp_ref>(__first, __nth, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    __nth_element<_Comp_ref>(__first, __nth, __last, __comp);
+#endif
+}
+
+template <class _RandomAccessIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
+{
+    _STD::nth_element(__first, __nth, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+}
+
+// includes
+
+template <class _Compare, class _InputIterator1, class _InputIterator2>
+bool
+__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
+           _Compare __comp)
+{
+    for (; __first2 != __last2; ++__first1)
+    {
+        if (__first1 == __last1 || __comp(*__first2, *__first1))
+            return false;
+        if (!__comp(*__first1, *__first2))
+            ++__first2;
+    }
+    return true;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
+         _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
+{
+    return _STD::includes(__first1, __last1, __first2, __last2,
+                          __less<typename iterator_traits<_InputIterator1>::value_type,
+                                 typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// set_union
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+_OutputIterator
+__set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+            _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+    for (; __first1 != __last1; ++__result)
+    {
+        if (__first2 == __last2)
+            return _STD::copy(__first1, __last1, __result);
+        if (__comp(*__first2, *__first1))
+        {
+            *__result = *__first2;
+            ++__first2;
+        }
+        else
+        {
+            *__result = *__first1;
+            if (!__comp(*__first1, *__first2))
+                ++__first2;
+            ++__first1;
+        }
+    }
+    return _STD::copy(__first2, __last2, __result);
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+          _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+          _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
+{
+    return _STD::set_union(__first1, __last1, __first2, __last2, __result,
+                          __less<typename iterator_traits<_InputIterator1>::value_type,
+                                 typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// set_intersection
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+_OutputIterator
+__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+                   _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+    while (__first1 != __last1 && __first2 != __last2)
+    {
+        if (__comp(*__first1, *__first2))
+            ++__first1;
+        else
+        {
+            if (!__comp(*__first2, *__first1))
+            {
+                *__result = *__first1;
+                ++__result;
+                ++__first1;
+            }
+            ++__first2;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+                 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+                 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
+{
+    return _STD::set_intersection(__first1, __last1, __first2, __last2, __result,
+                                  __less<typename iterator_traits<_InputIterator1>::value_type,
+                                         typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// set_difference
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+_OutputIterator
+__set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+                 _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+    while (__first1 != __last1)
+    {
+        if (__first2 == __last2)
+            return _STD::copy(__first1, __last1, __result);
+        if (__comp(*__first1, *__first2))
+        {
+            *__result = *__first1;
+            ++__result;
+            ++__first1;
+        }
+        else
+        {
+            if (!__comp(*__first2, *__first1))
+                ++__first1;
+            ++__first2;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+               _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+               _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
+{
+    return _STD::set_difference(__first1, __last1, __first2, __last2, __result,
+                                __less<typename iterator_traits<_InputIterator1>::value_type,
+                                       typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// set_symmetric_difference
+
+template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
+_OutputIterator
+__set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+                           _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+    while (__first1 != __last1)
+    {
+        if (__first2 == __last2)
+            return _STD::copy(__first1, __last1, __result);
+        if (__comp(*__first1, *__first2))
+        {
+            *__result = *__first1;
+            ++__result;
+            ++__first1;
+        }
+        else
+        {
+            if (__comp(*__first2, *__first1))
+            {
+                *__result = *__first2;
+                ++__result;
+            }
+            else
+                ++__first1;
+            ++__first2;
+        }
+    }
+    return _STD::copy(__first2, __last2, __result);
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+                         _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+                         _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
+{
+    return _STD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result,
+                                          __less<typename iterator_traits<_InputIterator1>::value_type,
+                                                 typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// lexicographical_compare
+
+template <class _Compare, class _InputIterator1, class _InputIterator2>
+bool
+__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
+                          _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
+{
+    for (; __first2 != __last2; ++__first1, ++__first2)
+    {
+        if (__first1 == __last1 || __comp(*__first1, *__first2))
+            return true;
+        if (__comp(*__first2, *__first1))
+            return false;
+    }
+    return false;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
+                        _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
+#endif
+}
+
+template <class _InputIterator1, class _InputIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
+                        _InputIterator2 __first2, _InputIterator2 __last2)
+{
+    return _STD::lexicographical_compare(__first1, __last1, __first2, __last2,
+                                         __less<typename iterator_traits<_InputIterator1>::value_type,
+                                                typename iterator_traits<_InputIterator2>::value_type>());
+}
+
+// next_permutation
+
+template <class _Compare, class _BidirectionalIterator>
+bool
+__next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
+{
+    _BidirectionalIterator __i = __last;
+    if (__first == __last || __first == --__i)
+        return false;
+    while (true)
+    {
+        _BidirectionalIterator __ip1 = __i;
+        if (__comp(*--__i, *__ip1))
+        {
+            _BidirectionalIterator __j = __last;
+            while (!__comp(*__i, *--__j))
+                ;
+            swap(*__i, *__j);
+            _STD::reverse(__ip1, __last);
+            return true;
+        }
+        if (__i == __first)
+        {
+            _STD::reverse(__first, __last);
+            return false;
+        }
+    }
+}
+
+template <class _BidirectionalIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __next_permutation<_Comp_ref>(__first, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __next_permutation<_Comp_ref>(__first, __last, __comp);
+#endif
+}
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+bool 
+next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
+{
+    return _STD::next_permutation(__first, __last,
+                                  __less<typename iterator_traits<_BidirectionalIterator>::value_type>());
+}
+
+// prev_permutation
+
+template <class _Compare, class _BidirectionalIterator>
+bool
+__prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
+{
+    _BidirectionalIterator __i = __last;
+    if (__first == __last || __first == --__i)
+        return false;
+    while (true)
+    {
+        _BidirectionalIterator __ip1 = __i;
+        if (__comp(*__ip1, *--__i))
+        {
+            _BidirectionalIterator __j = __last;
+            while (!__comp(*--__j, *__i))
+                ;
+            swap(*__i, *__j);
+            _STD::reverse(__ip1, __last);
+            return true;
+        }
+        if (__i == __first)
+        {
+            _STD::reverse(__first, __last);
+            return false;
+        }
+    }
+}
+
+template <class _BidirectionalIterator, class _Compare>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
+{
+#ifdef _LIBCPP_DEBUG
+    typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
+    __debug_less<_Compare> __c(__comp);
+    return __prev_permutation<_Comp_ref>(__first, __last, __c);
+#else
+    typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
+    return __prev_permutation<_Comp_ref>(__first, __last, __comp);
+#endif
+}
+
+template <class _BidirectionalIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
+{
+    return _STD::prev_permutation(__first, __last,
+                                  __less<typename iterator_traits<_BidirectionalIterator>::value_type>());
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    _Tp
+>::type
+__rotate_left(_Tp __t, _Tp __n = 1)
+{
+    const unsigned __bits = static_cast<unsigned>(sizeof(_Tp) * __CHAR_BIT__ - 1);
+    __n &= __bits;
+    return static_cast<_Tp>((__t << __n) | (static_cast<typename make_unsigned<_Tp>::type>(__t) >> (__bits - __n)));
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    _Tp
+>::type
+__rotate_right(_Tp __t, _Tp __n = 1)
+{
+    const unsigned __bits = static_cast<unsigned>(sizeof(_Tp) * __CHAR_BIT__ - 1);
+    __n &= __bits;
+    return static_cast<_Tp>((__t << (__bits - __n)) | (static_cast<typename make_unsigned<_Tp>::type>(__t) >> __n));
+}
+
+// Precondition:  __x != 0
+inline _LIBCPP_INLINE_VISIBILITY unsigned           __ctz(unsigned           __x) {return __builtin_ctz  (__x);}
+inline _LIBCPP_INLINE_VISIBILITY unsigned      long __ctz(unsigned      long __x) {return __builtin_ctzl (__x);}
+inline _LIBCPP_INLINE_VISIBILITY unsigned long long __ctz(unsigned long long __x) {return __builtin_ctzll(__x);}
+
+// Precondition:  __x != 0
+inline _LIBCPP_INLINE_VISIBILITY unsigned           __clz(unsigned           __x) {return __builtin_clz  (__x);}
+inline _LIBCPP_INLINE_VISIBILITY unsigned      long __clz(unsigned      long __x) {return __builtin_clzl (__x);}
+inline _LIBCPP_INLINE_VISIBILITY unsigned long long __clz(unsigned long long __x) {return __builtin_clzll(__x);}
+
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned           __x) {return __builtin_popcount  (__x);}
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned      long __x) {return __builtin_popcountl (__x);}
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {return __builtin_popcountll(__x);}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_ALGORITHM
diff --git a/include/array b/include/array
new file mode 100644
index 0000000..0aed5d1
--- /dev/null
+++ b/include/array
@@ -0,0 +1,296 @@
+// -*- C++ -*-
+//===---------------------------- array -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_ARRAY
+#define _LIBCPP_ARRAY
+
+/*
+    array synopsis
+
+namespace std
+{
+template <class T, size_t N > 
+struct array
+{ 
+    // types: 
+    typedef T & reference; 
+    typedef const T & const_reference; 
+    typedef implementation defined iterator; 
+    typedef implementation defined const_iterator; 
+    typedef size_t size_type; 
+    typedef ptrdiff_t difference_type; 
+    typedef T value_type; 
+    typedef T* pointer;
+    typedef const T* const_pointer;
+    typedef std::reverse_iterator<iterator> reverse_iterator; 
+    typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
+
+    // No explicit construct/copy/destroy for aggregate type 
+    void fill(const T& u); 
+    void swap(array& a);
+
+    // iterators: 
+    iterator begin(); 
+    const_iterator begin() const; 
+    iterator end(); 
+    const_iterator end() const; 
+
+    reverse_iterator rbegin(); 
+    const_reverse_iterator rbegin() const; 
+    reverse_iterator rend(); 
+    const_reverse_iterator rend() const; 
+
+    const_iterator cbegin() const; 
+    const_iterator cend() const; 
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend() const; 
+
+    // capacity: 
+    constexpr size_type size() const; 
+    constexpr size_type max_size() const; 
+    bool empty() const; 
+
+    // element access: 
+    reference operator[](size_type n); 
+    const_reference operator[](size_type n) const; 
+    const_reference at(size_type n) const; 
+    reference at(size_type n); 
+
+    reference front(); 
+    const_reference front() const; 
+    reference back(); 
+    const_reference back() const; 
+
+    T* data(); 
+    const T* data() const; 
+};
+
+template <class T, size_t N> 
+  bool operator==(const array<T,N>& x, const array<T,N>& y); 
+template <class T, size_t N> 
+  bool operator!=(const array<T,N>& x, const array<T,N>& y); 
+template <class T, size_t N> 
+  bool operator<(const array<T,N>& x, const array<T,N>& y); 
+template <class T, size_t N> 
+  bool operator>(const array<T,N>& x, const array<T,N>& y); 
+template <class T, size_t N> 
+  bool operator<=(const array<T,N>& x, const array<T,N>& y); 
+template <class T, size_t N> 
+  bool operator>=(const array<T,N>& x, const array<T,N>& y); 
+
+template <class T, size_t N > 
+  void swap(array<T,N>& x, array<T,N>& y); 
+
+template <class T> class tuple_size; 
+template <int I, class T> class tuple_element; 
+template <class T, size_t N> struct tuple_size<array<T, N>>;
+template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>; 
+template <int I, class T, size_t N> T& get(array<T, N>&); 
+template <int I, class T, size_t N> const T& get(const array<T, N>&); 
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__tuple>
+#include <type_traits>
+#include <utility>
+#include <iterator>
+#include <algorithm>
+#include <stdexcept>
+#if defined(_LIBCPP_NO_EXCEPTIONS)
+    #include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, size_t _Size> 
+struct array
+{
+    // types:
+    typedef array __self;
+    typedef _Tp                                   value_type; 
+    typedef value_type&                           reference; 
+    typedef const value_type&                     const_reference; 
+    typedef value_type*                           iterator;
+    typedef const value_type*                     const_iterator;
+    typedef value_type*                           pointer;
+    typedef const value_type*                     const_pointer;
+    typedef size_t                                size_type; 
+    typedef ptrdiff_t                             difference_type; 
+    typedef std::reverse_iterator<iterator>       reverse_iterator; 
+    typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
+
+    value_type __elems_[_Size > 0 ? _Size : 1];
+
+    // No explicit construct/copy/destroy for aggregate type 
+    _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {_STD::fill_n(__elems_, _Size, __u);}
+    _LIBCPP_INLINE_VISIBILITY void swap(array& __a) {_STD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);}
+
+    // iterators: 
+    _LIBCPP_INLINE_VISIBILITY iterator begin()             {return iterator(__elems_);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(__elems_);}
+    _LIBCPP_INLINE_VISIBILITY iterator end()               {return iterator(__elems_ + _Size);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end() const   {return const_iterator(__elems_ + _Size);}
+
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin()             {return reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator rend()               {return reverse_iterator(begin());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const   {return const_reverse_iterator(begin());}
+
+    _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const          {return begin();}
+    _LIBCPP_INLINE_VISIBILITY const_iterator cend() const            {return end();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const {return rbegin();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const   {return rend();}
+
+    // capacity: 
+    _LIBCPP_INLINE_VISIBILITY /*constexpr*/ size_type size() const      {return _Size;}
+    _LIBCPP_INLINE_VISIBILITY /*constexpr*/ size_type max_size() const  {return _Size;}
+    _LIBCPP_INLINE_VISIBILITY bool empty() const                    {return _Size == 0;}
+
+    // element access: 
+    _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n)             {return __elems_[__n];}
+    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __elems_[__n];}
+    reference at(size_type __n); 
+    const_reference at(size_type __n) const; 
+
+    _LIBCPP_INLINE_VISIBILITY reference front()             {return __elems_[0];}
+    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __elems_[0];}
+    _LIBCPP_INLINE_VISIBILITY reference back()              {return __elems_[_Size > 0 ? _Size-1 : 0];}
+    _LIBCPP_INLINE_VISIBILITY const_reference back() const  {return __elems_[_Size > 0 ? _Size-1 : 0];}
+
+    _LIBCPP_INLINE_VISIBILITY value_type* data()             {return __elems_;}
+    _LIBCPP_INLINE_VISIBILITY const value_type* data() const {return __elems_;} 
+};
+
+template <class _Tp, size_t _Size> 
+typename array<_Tp, _Size>::reference
+array<_Tp, _Size>::at(size_type __n)
+{
+    if (__n >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("array::at");
+#else
+        assert(!"array::at out_of_range");
+#endif
+    return __elems_[__n];
+}
+
+template <class _Tp, size_t _Size> 
+typename array<_Tp, _Size>::const_reference
+array<_Tp, _Size>::at(size_type __n) const
+{
+    if (__n >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("array::at");
+#else
+        assert(!"array::at out_of_range");
+#endif
+    return __elems_[__n];
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return _STD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return _STD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, size_t _Size> 
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Tp, size_t _Size>
+  class tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
+
+template <class _Tp, size_t _Size>
+  class tuple_size<const array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
+
+template <size_t _Ip, class _Tp, size_t _Size>
+class tuple_element<_Ip, array<_Tp, _Size> >
+{
+public:
+    typedef _Tp type;
+};
+
+template <size_t _Ip, class _Tp, size_t _Size>
+class tuple_element<_Ip, const array<_Tp, _Size> >
+{
+public:
+    typedef const _Tp type;
+};
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY inline
+_Tp&
+get(array<_Tp, _Size>& __a)
+{
+    return __a[_Ip];
+}
+
+template <size_t _Ip, class _Tp, size_t _Size>
+_LIBCPP_INLINE_VISIBILITY inline
+const _Tp&
+get(const array<_Tp, _Size>& __a)
+{
+    return __a[_Ip];
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_ARRAY
diff --git a/include/bitset b/include/bitset
new file mode 100644
index 0000000..cbeacaa
--- /dev/null
+++ b/include/bitset
@@ -0,0 +1,1022 @@
+// -*- C++ -*-
+//===---------------------------- bitset ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_BITSET
+#define _LIBCPP_BITSET
+
+/*
+    bitset synopsis
+
+namespace std
+{
+
+namespace std {
+
+template <size_t N>
+class bitset
+{
+public:
+    // bit reference:
+    class reference
+    {
+        friend class bitset;
+        reference();
+    public:
+        ~reference();
+        reference& operator=(bool x);           // for b[i] = x;
+        reference& operator=(const reference&); // for b[i] = b[j];
+        bool operator~() const;                 // flips the bit
+        operator bool() const;                  // for x = b[i];
+        reference& flip();                      // for b[i].flip();
+    };
+
+    // 23.3.5.1 constructors:
+    constexpr bitset();
+    constexpr bitset(unsigned long long val);
+    explicit bitset( const char* str );
+    template<class charT, class traits, class Allocator>
+        explicit bitset(const basic_string<charT,traits,Allocator>& str,
+                        typename basic_string<charT,traits,Allocator>::size_type pos = 0,
+                        typename basic_string<charT,traits,Allocator>::size_type n =
+                                 basic_string<charT,traits,Allocator>::npos,
+                        charT zero = charT('0'), charT one = charT('1'));
+
+    // 23.3.5.2 bitset operations:
+    bitset& operator&=(const bitset& rhs);
+    bitset& operator|=(const bitset& rhs);
+    bitset& operator^=(const bitset& rhs);
+    bitset& operator<<=(size_t pos);
+    bitset& operator>>=(size_t pos);
+    bitset& set();
+    bitset& set(size_t pos, bool val = true);
+    bitset& reset();
+    bitset& reset(size_t pos);
+    bitset operator~() const;
+    bitset& flip();
+    bitset& flip(size_t pos);
+
+    // element access:
+    constexpr bool operator[](size_t pos) const; // for b[i];
+    reference operator[](size_t pos);            // for b[i];
+    unsigned long to_ulong() const;
+    unsigned long long to_ullong() const;
+    template <class charT, class traits, class Allocator>
+        basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
+    template <class charT, class traits>
+        basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
+    template <class charT>
+        basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
+    basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
+    size_t count() const;
+    constexpr size_t size() const;
+    bool operator==(const bitset& rhs) const;
+    bool operator!=(const bitset& rhs) const;
+    bool test(size_t pos) const;
+    bool all() const;
+    bool any() const;
+    bool none() const;
+    bitset operator<<(size_t pos) const;
+    bitset operator>>(size_t pos) const;
+};
+
+// 23.3.5.3 bitset operators:
+template <size_t N>
+bitset<N> operator&(const bitset<N>&, const bitset<N>&);
+
+template <size_t N>
+bitset<N> operator|(const bitset<N>&, const bitset<N>&);
+
+template <size_t N>
+bitset<N> operator^(const bitset<N>&, const bitset<N>&);
+
+template <class charT, class traits, size_t N>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
+
+template <class charT, class traits, size_t N>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
+
+template <size_t N> struct hash<std::bitset<N>>;
+
+}  // std
+
+*/
+
+#pragma GCC system_header
+
+#include <__config>
+#include <__bit_reference>
+#include <cstddef>
+#include <climits>
+#include <string>
+#include <stdexcept>
+#include <iosfwd>
+#include <__functional_base>
+#if defined(_LIBCPP_NO_EXCEPTIONS)
+    #include <cassert>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <size_t _N_words, size_t _Size>
+class __bitset
+{
+public:
+    typedef ptrdiff_t              difference_type;
+    typedef size_t                 size_type;
+protected:
+    typedef __bitset __self;
+    typedef size_type              __storage_type;
+    typedef       __storage_type*  __storage_pointer;
+    typedef const __storage_type*  __const_storage_pointer;
+    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
+
+    friend class __bit_reference<__bitset>;
+    friend class __bit_const_reference<__bitset>;
+    friend class __bit_iterator<__bitset, false>;
+    friend class __bit_iterator<__bitset, true>;
+    friend class __bit_array<__bitset>;
+
+    __storage_type __first_[_N_words];
+
+    typedef __bit_reference<__bitset>                  reference;
+    typedef __bit_const_reference<__bitset>            const_reference;
+    typedef __bit_iterator<__bitset, false>            iterator;
+    typedef __bit_iterator<__bitset, true>             const_iterator;
+
+    __bitset();
+    explicit __bitset(unsigned long long __v);
+
+    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos)
+        {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const
+        {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos)
+        {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const
+        {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
+
+    void operator&=(const __bitset& __v);
+    void operator|=(const __bitset& __v);
+    void operator^=(const __bitset& __v);
+
+    void flip();
+    _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
+        {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
+    _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
+        {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
+
+    bool all() const;
+    bool any() const;
+    size_t __hash_code() const;
+private:
+    void __init(unsigned long long __v, false_type);
+    void __init(unsigned long long __v, true_type);
+    unsigned long to_ulong(false_type) const;
+    unsigned long to_ulong(true_type) const;
+    unsigned long long to_ullong(false_type) const;
+    unsigned long long to_ullong(true_type) const;
+    unsigned long long to_ullong(true_type, false_type) const;
+    unsigned long long to_ullong(true_type, true_type) const;
+};
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<_N_words, _Size>::__bitset()
+{
+    _STD::fill_n(__first_, _N_words, __storage_type(0));
+}
+
+template <size_t _N_words, size_t _Size>
+void
+__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type)
+{
+    __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
+    for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word)
+        __t[__i] = static_cast<__storage_type>(__v);
+    _STD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
+    _STD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
+               __storage_type(0));
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type)
+{
+    __first_[0] = __v;
+    _STD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<_N_words, _Size>::__bitset(unsigned long long __v)
+{
+    __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<_N_words, _Size>::operator&=(const __bitset& __v)
+{
+    for (size_type __i = 0; __i < _N_words; ++__i)
+        __first_[__i] &= __v.__first_[__i];
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<_N_words, _Size>::operator|=(const __bitset& __v)
+{
+    for (size_type __i = 0; __i < _N_words; ++__i)
+        __first_[__i] |= __v.__first_[__i];
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<_N_words, _Size>::operator^=(const __bitset& __v)
+{
+    for (size_type __i = 0; __i < _N_words; ++__i)
+        __first_[__i] ^= __v.__first_[__i];
+}
+
+template <size_t _N_words, size_t _Size>
+void
+__bitset<_N_words, _Size>::flip()
+{
+    // do middle whole words
+    size_type __n = _Size;
+    __storage_pointer __p = __first_;
+    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
+        *__p = ~*__p;
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __storage_type __b = *__p & __m;
+        *__p &= ~__m;
+        *__p |= ~__b & __m;
+    }
+}
+
+template <size_t _N_words, size_t _Size>
+unsigned long
+__bitset<_N_words, _Size>::to_ulong(false_type) const
+{
+    const_iterator __e = __make_iter(_Size);
+    const_iterator __i = _STD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
+    if (__i != __e)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw overflow_error("bitset to_ulong overflow error");
+#else
+        assert(!"bitset to_ulong overflow error");
+#endif
+    return __first_[0];
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__bitset<_N_words, _Size>::to_ulong(true_type) const
+{
+    return __first_[0];
+}
+
+template <size_t _N_words, size_t _Size>
+unsigned long long
+__bitset<_N_words, _Size>::to_ullong(false_type) const
+{
+    const_iterator __e = __make_iter(_Size);
+    const_iterator __i = _STD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
+    if (__i != __e)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw overflow_error("bitset to_ullong overflow error");
+#else
+        assert(!"bitset to_ullong overflow error");
+#endif
+    return to_ullong(true_type());
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+__bitset<_N_words, _Size>::to_ullong(true_type) const
+{
+    return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
+{
+    return __first_[0];
+}
+
+template <size_t _N_words, size_t _Size>
+unsigned long long
+__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
+{
+    unsigned long long __r = __first_[0];
+    for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
+        __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
+    return __r;
+}
+
+template <size_t _N_words, size_t _Size>
+bool
+__bitset<_N_words, _Size>::all() const
+{
+    // do middle whole words
+    size_type __n = _Size;
+    __const_storage_pointer __p = __first_;
+    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
+        if (~*__p)
+            return false;
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        if (~*__p & __m)
+            return false;
+    }
+    return true;
+}
+
+template <size_t _N_words, size_t _Size>
+bool
+__bitset<_N_words, _Size>::any() const
+{
+    // do middle whole words
+    size_type __n = _Size;
+    __const_storage_pointer __p = __first_;
+    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
+        if (*__p)
+            return true;
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        if (*__p & __m)
+            return true;
+    }
+    return false;
+}
+
+template <size_t _N_words, size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__bitset<_N_words, _Size>::__hash_code() const
+{
+    size_t __h = 0;
+    for (size_type __i = 0; __i < _N_words; ++__i)
+        __h ^= __first_[__i];
+    return __h;
+}
+
+template <size_t _Size>
+class __bitset<1, _Size>
+{
+public:
+    typedef ptrdiff_t              difference_type;
+    typedef size_t                 size_type;
+protected:
+    typedef __bitset __self;
+    typedef size_type              __storage_type;
+    typedef       __storage_type*  __storage_pointer;
+    typedef const __storage_type*  __const_storage_pointer;
+    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
+
+    friend class __bit_reference<__bitset>;
+    friend class __bit_const_reference<__bitset>;
+    friend class __bit_iterator<__bitset, false>;
+    friend class __bit_iterator<__bitset, true>;
+    friend class __bit_array<__bitset>;
+
+    __storage_type __first_;
+
+    typedef __bit_reference<__bitset>                  reference;
+    typedef __bit_const_reference<__bitset>            const_reference;
+    typedef __bit_iterator<__bitset, false>            iterator;
+    typedef __bit_iterator<__bitset, true>             const_iterator;
+
+    __bitset();
+    explicit __bitset(unsigned long long __v);
+
+    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos)
+        {return reference(&__first_, __storage_type(1) << __pos);}
+    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t __pos) const
+        {return const_reference(&__first_, __storage_type(1) << __pos);}
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos)
+        {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const
+        {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
+
+    void operator&=(const __bitset& __v);
+    void operator|=(const __bitset& __v);
+    void operator^=(const __bitset& __v);
+
+    void flip();
+
+    unsigned long to_ulong() const;
+    unsigned long long to_ullong() const;
+
+    bool all() const;
+    bool any() const;
+
+    size_t __hash_code() const;
+};
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<1, _Size>::__bitset()
+    : __first_(0)
+{
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<1, _Size>::__bitset(unsigned long long __v)
+    : __first_(static_cast<__storage_type>(__v))
+{
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<1, _Size>::operator&=(const __bitset& __v)
+{
+    __first_ &= __v.__first_;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<1, _Size>::operator|=(const __bitset& __v)
+{
+    __first_ |= __v.__first_;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<1, _Size>::operator^=(const __bitset& __v)
+{
+    __first_ ^= __v.__first_;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+__bitset<1, _Size>::flip()
+{
+    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
+    __first_ = ~__first_;
+    __first_ &= __m;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+__bitset<1, _Size>::to_ulong() const
+{
+    return __first_;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+__bitset<1, _Size>::to_ullong() const
+{
+    return __first_;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__bitset<1, _Size>::all() const
+{
+    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
+    return !(~__first_ & __m);
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+__bitset<1, _Size>::any() const
+{
+    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
+    return __first_ & __m;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+__bitset<1, _Size>::__hash_code() const
+{
+    return __first_;
+}
+
+template <>
+class __bitset<0, 0>
+{
+public:
+    typedef ptrdiff_t              difference_type;
+    typedef size_t                 size_type;
+protected:
+    typedef __bitset __self;
+    typedef size_type              __storage_type;
+    typedef       __storage_type*  __storage_pointer;
+    typedef const __storage_type*  __const_storage_pointer;
+    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
+
+    friend class __bit_reference<__bitset>;
+    friend class __bit_const_reference<__bitset>;
+    friend class __bit_iterator<__bitset, false>;
+    friend class __bit_iterator<__bitset, true>;
+    friend class __bit_array<__bitset>;
+
+    typedef __bit_reference<__bitset>                  reference;
+    typedef __bit_const_reference<__bitset>            const_reference;
+    typedef __bit_iterator<__bitset, false>            iterator;
+    typedef __bit_iterator<__bitset, true>             const_iterator;
+
+    __bitset();
+    explicit __bitset(unsigned long long);
+
+    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t)
+        {return reference(0, 1);}
+    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_t) const
+        {return const_reference(0, 1);}
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos)
+        {return iterator(0, 0);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const
+        {return const_iterator(0, 0);}
+
+    _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) {}
+    _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) {}
+    _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) {}
+
+    _LIBCPP_INLINE_VISIBILITY void flip() {}
+
+    _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
+    _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
+
+    _LIBCPP_INLINE_VISIBILITY bool all() const {return true;}
+    _LIBCPP_INLINE_VISIBILITY bool any() const {return false;}
+
+    _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const {return 0;}
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<0, 0>::__bitset()
+{
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+__bitset<0, 0>::__bitset(unsigned long long)
+{
+}
+
+template <size_t _Size> class bitset;
+template <size_t _Size> struct hash<bitset<_Size> >;
+
+template <size_t _Size>
+class bitset
+    : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
+{
+    static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
+    typedef __bitset<__n_words, _Size> base;
+
+public: 
+    typedef typename base::reference       reference;
+    typedef typename base::const_reference const_reference;
+
+    // 23.3.5.1 constructors: 
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset() {}
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset(unsigned long long __v) : base(__v) {}
+    explicit bitset(const char* __str);
+    template<class _CharT, class _Traits, class _Allocator> 
+        explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 
+                        typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 
+                        typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 
+                                (basic_string<_CharT,_Traits,_Allocator>::npos),
+                        _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 
+
+    // 23.3.5.2 bitset operations: 
+    bitset& operator&=(const bitset& __rhs);
+    bitset& operator|=(const bitset& __rhs); 
+    bitset& operator^=(const bitset& __rhs); 
+    bitset& operator<<=(size_t __pos); 
+    bitset& operator>>=(size_t __pos); 
+    bitset& set(); 
+    bitset& set(size_t __pos, bool __val = true); 
+    bitset& reset(); 
+    bitset& reset(size_t __pos); 
+    bitset  operator~() const; 
+    bitset& flip(); 
+    bitset& flip(size_t __pos); 
+
+    // element access: 
+    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
+    _LIBCPP_INLINE_VISIBILITY       reference operator[](size_t __p)       {return base::__make_ref(__p);}
+    unsigned long to_ulong() const; 
+    unsigned long long to_ullong() const; 
+    template <class _CharT, class _Traits, class _Allocator> 
+        basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
+                                                            _CharT __one = _CharT('1')) const; 
+    template <class _CharT, class _Traits> 
+        basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
+                                                                    _CharT __one = _CharT('1')) const; 
+    template <class _CharT> 
+        basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
+                                                                                _CharT __one = _CharT('1')) const; 
+    basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
+                                                                      char __one = '1') const; 
+    size_t count() const;
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY size_t size() const {return _Size;}
+    bool operator==(const bitset& __rhs) const; 
+    bool operator!=(const bitset& __rhs) const; 
+    bool test(size_t __pos) const; 
+    bool all() const; 
+    bool any() const; 
+    _LIBCPP_INLINE_VISIBILITY bool none() const {return !any();}
+    bitset operator<<(size_t __pos) const; 
+    bitset operator>>(size_t __pos) const; 
+
+private:
+
+    size_t __hash_code() const {return base::__hash_code();}
+
+    friend struct hash<bitset>;
+};
+
+template <size_t _Size>
+bitset<_Size>::bitset(const char* __str)
+{
+    size_t __rlen = strlen(__str);
+    for (size_t __i = 0; __i < __rlen; ++__i)
+        if (__str[__i] != '0' && __str[__i] != '1')
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            throw invalid_argument("bitset string ctor has invalid argument");
+#else
+            assert(!"bitset string ctor has invalid argument");
+#endif
+    size_t _M = _STD::min(__rlen, _Size);
+    size_t __i = 0;
+    for (; __i < _M; ++__i)
+    {
+        switch (__str[_M - 1 - __i])
+        {
+        case '0':
+            (*this)[__i] = false;
+            break;
+        case '1':
+            (*this)[__i] = true;
+            break;
+        }
+    }
+    _STD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
+}
+
+template <size_t _Size>
+template<class _CharT, class _Traits, class _Allocator> 
+bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 
+       typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 
+       typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
+       _CharT __zero, _CharT __one)
+{
+    if (__pos > __str.size())
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("bitset string pos out of range");
+#else
+        assert(!"bitset string pos out of range");
+#endif
+    size_t __rlen = _STD::min(__n, __str.size() - __pos);
+    for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
+        if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            throw invalid_argument("bitset string ctor has invalid argument");
+#else
+            assert(!"bitset string ctor has invalid argument");
+#endif
+    size_t _M = _STD::min(__rlen, _Size);
+    size_t __i = 0;
+    for (; __i < _M; ++__i)
+    {
+        _CharT __c = __str[__pos + _M - 1 - __i];
+        if (_Traits::eq(__c, __zero))
+            (*this)[__i] = false;
+        else
+            (*this)[__i] = true;
+    }
+    _STD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::operator&=(const bitset& __rhs)
+{
+    base::operator&=(__rhs);
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::operator|=(const bitset& __rhs)
+{
+    base::operator|=(__rhs);
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::operator^=(const bitset& __rhs)
+{
+    base::operator^=(__rhs);
+    return *this;
+}
+
+template <size_t _Size>
+bitset<_Size>&
+bitset<_Size>::operator<<=(size_t __pos)
+{
+    __pos = _STD::min(__pos, _Size);
+    _STD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
+    _STD::fill_n(base::__make_iter(0), __pos, false);
+    return *this;
+}
+
+template <size_t _Size>
+bitset<_Size>&
+bitset<_Size>::operator>>=(size_t __pos)
+{
+    __pos = _STD::min(__pos, _Size);
+    _STD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
+    _STD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::set()
+{
+    _STD::fill_n(base::__make_iter(0), _Size, true);
+    return *this;
+}
+
+template <size_t _Size>
+bitset<_Size>&
+bitset<_Size>::set(size_t __pos, bool __val)
+{
+    if (__pos >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("bitset set argument out of range");
+#else
+        assert(!"bitset set argument out of range");
+#endif
+    (*this)[__pos] = __val;
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::reset()
+{
+    _STD::fill_n(base::__make_iter(0), _Size, false);
+    return *this;
+}
+
+template <size_t _Size>
+bitset<_Size>&
+bitset<_Size>::reset(size_t __pos)
+{
+    if (__pos >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("bitset reset argument out of range");
+#else
+        assert(!"bitset reset argument out of range");
+#endif
+    (*this)[__pos] = false;
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+bitset<_Size>::operator~() const
+{
+    bitset __x(*this);
+    __x.flip();
+    return __x;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>&
+bitset<_Size>::flip()
+{
+    base::flip();
+    return *this;
+}
+
+template <size_t _Size>
+bitset<_Size>&
+bitset<_Size>::flip(size_t __pos)
+{
+    if (__pos >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("bitset flip argument out of range");
+#else
+        assert(!"bitset flip argument out of range");
+#endif
+    reference r = base::__make_ref(__pos);
+    r = ~r;
+    return *this;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long
+bitset<_Size>::to_ulong() const
+{
+    return base::to_ulong();
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long
+bitset<_Size>::to_ullong() const
+{
+    return base::to_ullong();
+}
+
+template <size_t _Size>
+template <class _CharT, class _Traits, class _Allocator> 
+basic_string<_CharT, _Traits, _Allocator>
+bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
+    for (size_t __i = 0; __i < _Size; ++__i)
+    {
+        if ((*this)[__i])
+            __r[_Size - 1 - __i] = __one;
+    }
+    return __r;
+}
+
+template <size_t _Size>
+template <class _CharT, class _Traits> 
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, _Traits, allocator<_CharT> >
+bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
+{
+    return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
+}
+
+template <size_t _Size>
+template <class _CharT> 
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
+bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
+{
+    return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<char, char_traits<char>, allocator<char> >
+bitset<_Size>::to_string(char __zero, char __one) const
+{
+    return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+bitset<_Size>::count() const
+{
+    return static_cast<size_t>(_STD::count(base::__make_iter(0), base::__make_iter(_Size), true));
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+bitset<_Size>::operator==(const bitset& __rhs) const
+{
+    return _STD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+bitset<_Size>::operator!=(const bitset& __rhs) const
+{
+    return !(*this == __rhs);
+}
+
+template <size_t _Size>
+bool
+bitset<_Size>::test(size_t __pos) const
+{
+    if (__pos >= _Size)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw out_of_range("bitset test argument out of range");
+#else
+        assert(!"bitset test argument out of range");
+#endif
+    return (*this)[__pos];
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+bitset<_Size>::all() const
+{
+    return base::all();
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+bitset<_Size>::any() const
+{
+    return base::any();
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+bitset<_Size>::operator<<(size_t __pos) const
+{
+    bitset __r = *this;
+    __r <<= __pos;
+    return __r;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+bitset<_Size>::operator>>(size_t __pos) const
+{
+    bitset __r = *this;
+    __r >>= __pos;
+    return __r;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+operator&(const bitset<_Size>& __x, const bitset<_Size>& __y)
+{
+    bitset<_Size> __r = __x;
+    __r &= __y;
+    return __r;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+operator|(const bitset<_Size>& __x, const bitset<_Size>& __y)
+{
+    bitset<_Size> __r = __x;
+    __r |= __y;
+    return __r;
+}
+
+template <size_t _Size>
+inline _LIBCPP_INLINE_VISIBILITY
+bitset<_Size>
+operator^(const bitset<_Size>& __x, const bitset<_Size>& __y)
+{
+    bitset<_Size> __r = __x;
+    __r ^= __y;
+    return __r;
+}
+
+template <size_t _Size>
+struct hash<bitset<_Size> >
+    : public unary_function<bitset<_Size>, size_t>
+{
+    size_t operator()(const bitset<_Size>& __bs) const
+        {return __bs.__hash_code();}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_BITSET
diff --git a/include/cassert b/include/cassert
new file mode 100644
index 0000000..0a4136b
--- /dev/null
+++ b/include/cassert
@@ -0,0 +1,23 @@
+// -*- C++ -*-
+//===-------------------------- cassert -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+/*
+    cassert synopsis
+
+Macros:
+
+    assert
+
+*/
+
+#include <__config>
+#include <assert.h>
+
+#pragma GCC system_header
diff --git a/include/ccomplex b/include/ccomplex
new file mode 100644
index 0000000..342cd89
--- /dev/null
+++ b/include/ccomplex
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--------------------------- ccomplex ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CCOMPLEX
+#define _LIBCPP_CCOMPLEX
+
+/*
+    ccomplex synopsis
+
+#include <complex>
+
+*/
+
+#include <complex>
+
+#pragma GCC system_header
+
+// hh 080623 Created
+
+#endif  // _LIBCPP_CCOMPLEX
diff --git a/include/cctype b/include/cctype
new file mode 100644
index 0000000..4d03763
--- /dev/null
+++ b/include/cctype
@@ -0,0 +1,159 @@
+// -*- C++ -*-
+//===---------------------------- cctype ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CCTYPE
+#define _LIBCPP_CCTYPE
+
+/*
+    cctype synopsis
+
+namespace std
+{
+
+int isalnum(int c);
+int isalpha(int c);
+int isblank(int c);  // C99
+int iscntrl(int c);
+int isdigit(int c);
+int isgraph(int c);
+int islower(int c);
+int isprint(int c);
+int ispunct(int c);
+int isspace(int c);
+int isupper(int c);
+int isxdigit(int c);
+int tolower(int c);
+int toupper(int c);
+
+}  // std
+*/
+
+#include <__config>
+#include <ctype.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef isalnum
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalnum(int __c) {return isalnum(__c);}
+#undef isalnum
+inline _LIBCPP_INLINE_VISIBILITY int isalnum(int __c) {return __libcpp_isalnum(__c);}
+#else  // isalnum
+using ::isalnum;
+#endif  // isalnum
+
+#ifdef isalpha
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalpha(int __c) {return isalpha(__c);}
+#undef isalpha
+inline _LIBCPP_INLINE_VISIBILITY int isalpha(int __c) {return __libcpp_isalpha(__c);}
+#else  // isalpha
+using ::isalpha;
+#endif  // isalpha
+
+#ifdef isblank
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isblank(int __c) {return isblank(__c);}
+#undef isblank
+inline _LIBCPP_INLINE_VISIBILITY int isblank(int __c) {return __libcpp_isblank(__c);}
+#else  // isblank
+using ::isblank;
+#endif  // isblank
+
+#ifdef iscntrl
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iscntrl(int __c) {return iscntrl(__c);}
+#undef iscntrl
+inline _LIBCPP_INLINE_VISIBILITY int iscntrl(int __c) {return __libcpp_iscntrl(__c);}
+#else  // iscntrl
+using ::iscntrl;
+#endif  // iscntrl
+
+#ifdef isdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isdigit(int __c) {return isdigit(__c);}
+#undef isdigit
+inline _LIBCPP_INLINE_VISIBILITY int isdigit(int __c) {return __libcpp_isdigit(__c);}
+#else  // isdigit
+using ::isdigit;
+#endif  // isdigit
+
+#ifdef isgraph
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isgraph(int __c) {return isgraph(__c);}
+#undef isgraph
+inline _LIBCPP_INLINE_VISIBILITY int isgraph(int __c) {return __libcpp_isgraph(__c);}
+#else  // isgraph
+using ::isgraph;
+#endif  // isgraph
+
+#ifdef islower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_islower(int __c) {return islower(__c);}
+#undef islower
+inline _LIBCPP_INLINE_VISIBILITY int islower(int __c) {return __libcpp_islower(__c);}
+#else  // islower
+using ::islower;
+#endif  // islower
+
+#ifdef isprint
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isprint(int __c) {return isprint(__c);}
+#undef isprint
+inline _LIBCPP_INLINE_VISIBILITY int isprint(int __c) {return __libcpp_isprint(__c);}
+#else  // isprint
+using ::isprint;
+#endif  // isprint
+
+#ifdef ispunct
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ispunct(int __c) {return ispunct(__c);}
+#undef ispunct
+inline _LIBCPP_INLINE_VISIBILITY int ispunct(int __c) {return __libcpp_ispunct(__c);}
+#else  // ispunct
+using ::ispunct;
+#endif  // ispunct
+
+#ifdef isspace
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isspace(int __c) {return isspace(__c);}
+#undef isspace
+inline _LIBCPP_INLINE_VISIBILITY int isspace(int __c) {return __libcpp_isspace(__c);}
+#else  // isspace
+using ::isspace;
+#endif  // isspace
+
+#ifdef isupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isupper(int __c) {return isupper(__c);}
+#undef isupper
+inline _LIBCPP_INLINE_VISIBILITY int isupper(int __c) {return __libcpp_isupper(__c);}
+#else  // isupper
+using ::isupper;
+#endif  // isupper
+
+#ifdef isxdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isxdigit(int __c) {return isxdigit(__c);}
+#undef isxdigit
+inline _LIBCPP_INLINE_VISIBILITY int isxdigit(int __c) {return __libcpp_isxdigit(__c);}
+#else  // isxdigit
+using ::isxdigit;
+#endif  // isxdigit
+
+#ifdef tolower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_tolower(int __c) {return tolower(__c);}
+#undef tolower
+inline _LIBCPP_INLINE_VISIBILITY int tolower(int __c) {return __libcpp_tolower(__c);}
+#else  // tolower
+using ::tolower;
+#endif  // tolower
+
+#ifdef toupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_toupper(int __c) {return toupper(__c);}
+#undef toupper
+inline _LIBCPP_INLINE_VISIBILITY int toupper(int __c) {return __libcpp_toupper(__c);}
+#else  // toupper
+using ::toupper;
+#endif  // toupper
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CCTYPE
diff --git a/include/cerrno b/include/cerrno
new file mode 100644
index 0000000..8d89d94
--- /dev/null
+++ b/include/cerrno
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+//===-------------------------- cerrno ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CERRNO
+#define _LIBCPP_CERRNO
+
+/*
+    cerrno synopsis
+
+Macros:
+
+    EDOM
+    EILSEQ  // C99
+    ERANGE
+    errno
+
+*/
+
+#include <__config>
+#include <errno.h>
+
+#pragma GCC system_header
+
+#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
+
+const int __elast1 = ELAST+1;
+const int __elast2 = ELAST+2;
+#undef ELAST
+
+#ifdef ENOTRECOVERABLE
+
+#define EOWNERDEAD __elast1
+#define ELAST EOWNERDEAD
+
+#elif defined(EOWNERDEAD)
+
+#define ENOTRECOVERABLE __elast1
+#define ELAST ENOTRECOVERABLE
+
+#else
+
+#define EOWNERDEAD __elast1
+#define ENOTRECOVERABLE __elast2
+#define ELAST ENOTRECOVERABLE
+
+#endif
+
+#endif
+
+#endif  // _LIBCPP_CERRNO
diff --git a/include/cfenv b/include/cfenv
new file mode 100644
index 0000000..937eb26
--- /dev/null
+++ b/include/cfenv
@@ -0,0 +1,80 @@
+// -*- C++ -*-
+//===---------------------------- cctype ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CFENV
+#define _LIBCPP_CFENV
+
+/*
+    cfenv synopsis
+
+This entire header is C99 / C++0X
+
+Macros:
+
+    FE_DIVBYZERO
+    FE_INEXACT
+    FE_INVALID
+    FE_OVERFLOW
+    FE_UNDERFLOW
+    FE_ALL_EXCEPT
+    FE_DOWNWARD
+    FE_TONEAREST
+    FE_TOWARDZERO
+    FE_UPWARD
+    FE_DFL_ENV
+
+namespace std
+{
+
+Types:
+
+    fenv_t
+    fexcept_t
+
+int feclearexcept(int excepts);
+int fegetexceptflag(fexcept_t* flagp, int excepts);
+int feraiseexcept(int excepts);
+int fesetexceptflag(const fexcept_t* flagp, int excepts);
+int fetestexcept(int excepts);
+int fegetround();
+int fesetround(int round);
+int fegetenv(fenv_t* envp);
+int feholdexcept(fenv_t* envp);
+int fesetenv(const fenv_t* envp);
+int feupdateenv(const fenv_t* envp);
+
+}  // std
+*/
+
+#include <__config>
+#include <fenv.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::fenv_t;
+using ::fexcept_t;
+
+using ::feclearexcept;
+using ::fegetexceptflag;
+using ::feraiseexcept;
+using ::fesetexceptflag;
+using ::fetestexcept;
+using ::fegetround;
+using ::fesetround;
+using ::fegetenv;
+using ::feholdexcept;
+using ::fesetenv;
+using ::feupdateenv;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CFENV
diff --git a/include/cfloat b/include/cfloat
new file mode 100644
index 0000000..f1a0a78
--- /dev/null
+++ b/include/cfloat
@@ -0,0 +1,76 @@
+// -*- C++ -*-
+//===--------------------------- cfloat -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CFLOAT
+#define _LIBCPP_CFLOAT
+
+/*
+    cfloat synopsis
+
+Macros:
+
+    FLT_ROUNDS
+    FLT_EVAL_METHOD     // C99
+    FLT_RADIX
+
+    FLT_MANT_DIG
+    DBL_MANT_DIG
+    LDBL_MANT_DIG
+
+    DECIMAL_DIG         // C99
+
+    FLT_DIG
+    DBL_DIG
+    LDBL_DIG
+
+    FLT_MIN_EXP
+    DBL_MIN_EXP
+    LDBL_MIN_EXP
+
+    FLT_MIN_10_EXP
+    DBL_MIN_10_EXP
+    LDBL_MIN_10_EXP
+
+    FLT_MAX_EXP
+    DBL_MAX_EXP
+    LDBL_MAX_EXP
+
+    FLT_MAX_10_EXP
+    DBL_MAX_10_EXP
+    LDBL_MAX_10_EXP
+
+    FLT_MAX
+    DBL_MAX
+    LDBL_MAX
+
+    FLT_EPSILON
+    DBL_EPSILON
+    LDBL_EPSILON
+
+    FLT_MIN
+    DBL_MIN
+    LDBL_MIN
+
+*/
+
+#include <__config>
+#include <float.h>
+
+#pragma GCC system_header
+
+#ifndef FLT_EVAL_METHOD
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif
+
+#ifndef DECIMAL_DIG
+#define DECIMAL_DIG __DECIMAL_DIG__
+#endif
+
+#endif  // _LIBCPP_CFLOAT
diff --git a/include/chrono b/include/chrono
new file mode 100644
index 0000000..d066ba4
--- /dev/null
+++ b/include/chrono
@@ -0,0 +1,868 @@
+// -*- C++ -*-
+//===---------------------------- chrono ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CHRONO
+#define _LIBCPP_CHRONO
+
+/*
+    chrono synopsis
+
+namespace std
+{
+namespace chrono
+{
+
+template <class ToDuration, class Rep, class Period>
+ToDuration
+duration_cast(const duration<Rep, Period>& fd);
+
+template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
+
+template <class Rep>
+struct duration_values
+{
+public:
+    static Rep zero();
+    static Rep max();
+    static Rep min();
+};
+
+// duration
+
+template <class Rep, class Period = ratio<1>>
+class duration
+{
+    static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
+    static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
+    static_assert(Period::num > 0, "duration period must be positive");
+public:
+    typedef Rep rep;
+    typedef Period period;
+
+    duration() = default;
+    template <class Rep2>
+        explicit duration(const Rep2& r,
+            typename enable_if
+            <
+               is_convertible<Rep2, rep>::value &&
+               (treat_as_floating_point<rep>::value ||
+               !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
+            >::type* = 0);
+
+    // conversions
+    template <class Rep2, class Period2>
+        duration(const duration<Rep2, Period2>& d,
+            typename enable_if
+            <
+                treat_as_floating_point<rep>::value ||
+                ratio_divide<Period2, period>::type::den == 1
+            >::type* = 0);
+
+    // observer
+
+    rep count() const;
+
+    // arithmetic
+
+    duration  operator+() const;
+    duration  operator-() const;
+    duration& operator++();
+    duration  operator++(int);
+    duration& operator--();
+    duration  operator--(int);
+
+    duration& operator+=(const duration& d);
+    duration& operator-=(const duration& d);
+
+    duration& operator*=(const rep& rhs);
+    duration& operator/=(const rep& rhs);
+
+    // special values
+
+    static duration zero();
+    static duration min();
+    static duration max();
+};
+
+typedef duration<long long,         nano> nanoseconds;
+typedef duration<long long,        micro> microseconds;
+typedef duration<long long,        milli> milliseconds;
+typedef duration<long long              > seconds;
+typedef duration<     long, ratio<  60> > minutes;
+typedef duration<     long, ratio<3600> > hours;
+
+template <class Clock, class Duration = typename Clock::duration>
+class time_point
+{
+public:
+    typedef Clock                     clock;
+    typedef Duration                  duration;
+    typedef typename duration::rep    rep;
+    typedef typename duration::period period;
+private:
+    duration d_;  // exposition only
+
+public:
+    time_point();  // has value "epoch"
+    explicit time_point(const duration& d);  // same as time_point() + d
+
+    // conversions
+    template <class Duration2>
+       time_point(const time_point<clock, Duration2>& t);
+
+    // observer
+
+    duration time_since_epoch() const;
+
+    // arithmetic
+
+    time_point& operator+=(const duration& d);
+    time_point& operator-=(const duration& d);
+
+    // special values
+
+    static constexpr time_point min();
+    static constexpr time_point max();
+};
+
+} // chrono
+
+// common_type traits
+template <class Rep1, class Period1, class Rep2, class Period2>
+  struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
+
+template <class Clock, class Duration1, class Duration2>
+  struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
+
+namespace chrono {
+
+// duration arithmetic
+template <class Rep1, class Period1, class Rep2, class Period2>
+  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
+  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
+  operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period, class Rep2>
+  duration<typename common_type<Rep1, Rep2>::type, Period>
+  operator*(const duration<Rep1, Period>& d, const Rep2& s);
+template <class Rep1, class Period, class Rep2>
+  duration<typename common_type<Rep1, Rep2>::type, Period>
+  operator*(const Rep1& s, const duration<Rep2, Period>& d);
+template <class Rep1, class Period, class Rep2>
+  duration<typename common_type<Rep1, Rep2>::type, Period>
+  operator/(const duration<Rep1, Period>& d, const Rep2& s);
+template <class Rep1, class Period1, class Rep2, class Period2>
+  typename common_type<Rep1, Rep2>::type
+  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+// duration comparisons
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Rep2, class Period2>
+   bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+// duration_cast
+template <class ToDuration, class Rep, class Period>
+  ToDuration duration_cast(const duration<Rep, Period>& d);
+
+// time_point arithmetic
+template <class Clock, class Duration1, class Rep2, class Period2>
+  time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
+  operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Rep1, class Period1, class Clock, class Duration2>
+  time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
+  operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Rep2, class Period2>
+  time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
+  operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+  typename common_type<Duration1, Duration2>::type
+  operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+
+// time_point comparisons
+template <class Clock, class Duration1, class Duration2>
+   bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+   bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+   bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+   bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+   bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+template <class Clock, class Duration1, class Duration2>
+   bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+
+// time_point_cast
+
+template <class ToDuration, class Clock, class Duration>
+  time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
+
+// Clocks
+
+class system_clock
+{
+public:
+    typedef microseconds                     duration;
+    typedef duration::rep                    rep;
+    typedef duration::period                 period;
+    typedef chrono::time_point<system_clock> time_point;
+    static const bool is_monotonic =          false;
+
+    static time_point now();
+    static time_t     to_time_t  (const time_point& __t);
+    static time_point from_time_t(time_t __t);
+};
+
+class monotonic_clock
+{
+public:
+    typedef nanoseconds                                   duration;
+    typedef duration::rep                                 rep;
+    typedef duration::period                              period;
+    typedef chrono::time_point<monotonic_clock, duration> time_point;
+    static const bool is_monotonic =                       true;
+
+    static time_point now();
+};
+
+typedef monotonic_clock high_resolution_clock;
+
+}  // chrono
+
+}  // std
+*/
+
+#include <__config>
+#include <ctime>
+#include <type_traits>
+#include <ratio>
+#include <limits>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace chrono
+{
+
+template <class _Rep, class _Period = ratio<1> > class duration;
+
+template <class T>
+struct __is_duration : false_type {};
+
+template <class _Rep, class _Period>
+struct __is_duration<duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<const duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<volatile duration<_Rep, _Period> > : true_type  {};
+
+template <class _Rep, class _Period>
+struct __is_duration<const volatile duration<_Rep, _Period> > : true_type  {};
+
+} // chrono
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+struct common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> >
+{
+    typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
+                             typename __ratio_gcd<_Period1, _Period2>::type> type;
+};
+
+namespace chrono {
+
+// duration_cast
+
+template <class _FromDuration, class _ToDuration,
+          class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
+          bool = _Period::num == 1,
+          bool = _Period::den == 1>
+struct __duration_cast;
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
+    }
+};
+
+template <class _FromDuration, class _ToDuration, class _Period>
+struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    _ToDuration operator()(const _FromDuration& __fd) const
+    {
+        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
+        return _ToDuration(static_cast<typename _ToDuration::rep>(
+                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
+                                                          / static_cast<_Ct>(_Period::den)));
+    }
+};
+
+template <class _ToDuration, class _Rep, class _Period>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    __is_duration<_ToDuration>::value,
+    _ToDuration
+>::type
+duration_cast(const duration<_Rep, _Period>& __fd)
+{
+    return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
+}
+
+template <class _Rep> struct treat_as_floating_point : is_floating_point<_Rep> {};
+
+template <class _Rep>
+struct duration_values
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY static _Rep zero() {return _Rep(0);}
+    _LIBCPP_INLINE_VISIBILITY static _Rep max()  {return numeric_limits<_Rep>::max();}
+    _LIBCPP_INLINE_VISIBILITY static _Rep min()  {return numeric_limits<_Rep>::lowest();}
+};
+
+// duration
+
+template <class _Rep, class _Period>
+class duration
+{
+    static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
+    static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
+    static_assert(_Period::num > 0, "duration period must be positive");
+public:
+    typedef _Rep rep;
+    typedef _Period period;
+private:
+    rep __rep_;
+public:
+
+    _LIBCPP_INLINE_VISIBILITY duration() {} // = default;
+    template <class _Rep2>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit duration(const _Rep2& __r,
+            typename enable_if
+            <
+               is_convertible<_Rep2, rep>::value &&
+               (treat_as_floating_point<rep>::value ||
+               !treat_as_floating_point<_Rep2>::value)
+            >::type* = 0)
+                : __rep_(__r) {}
+
+    // conversions
+    template <class _Rep2, class _Period2>
+        _LIBCPP_INLINE_VISIBILITY
+        duration(const duration<_Rep2, _Period2>& __d,
+            typename enable_if
+            <
+                treat_as_floating_point<rep>::value ||
+                (ratio_divide<_Period2, period>::type::den == 1 &&
+                 !treat_as_floating_point<_Rep2>::value)
+            >::type* = 0)
+                : __rep_(_STD::chrono::duration_cast<duration>(__d).count()) {}
+
+    // observer
+
+    _LIBCPP_INLINE_VISIBILITY rep count() const {return __rep_;}
+
+    // arithmetic
+
+    _LIBCPP_INLINE_VISIBILITY duration  operator+() const {return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration  operator-() const {return duration(-__rep_);}
+    _LIBCPP_INLINE_VISIBILITY duration& operator++()      {++__rep_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration  operator++(int)   {return duration(__rep_++);}
+    _LIBCPP_INLINE_VISIBILITY duration& operator--()      {--__rep_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration  operator--(int)   {return duration(__rep_--);}
+
+    _LIBCPP_INLINE_VISIBILITY duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
+    _LIBCPP_INLINE_VISIBILITY duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
+
+    // special values
+
+    _LIBCPP_INLINE_VISIBILITY static duration zero() {return duration(duration_values<rep>::zero());}
+    _LIBCPP_INLINE_VISIBILITY static duration min()  {return duration(duration_values<rep>::min());}
+    _LIBCPP_INLINE_VISIBILITY static duration max()  {return duration(duration_values<rep>::max());}
+};
+
+typedef duration<long long,         nano> nanoseconds;
+typedef duration<long long,        micro> microseconds;
+typedef duration<long long,        milli> milliseconds;
+typedef duration<long long              > seconds;
+typedef duration<     long, ratio<  60> > minutes;
+typedef duration<     long, ratio<3600> > hours;
+
+// Duration ==
+
+template <class _LhsDuration, class _RhsDuration>
+struct __duration_eq
+{
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
+        {
+            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
+            return _Ct(__lhs).count() == _Ct(__rhs).count();
+        }
+};
+
+template <class _LhsDuration>
+struct __duration_eq<_LhsDuration, _LhsDuration>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
+        {return __lhs.count() == __rhs.count();}
+};
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
+}
+
+// Duration !=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+// Duration <
+
+template <class _LhsDuration, class _RhsDuration>
+struct __duration_lt
+{
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs)
+        {
+            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
+            return _Ct(__lhs).count() < _Ct(__rhs).count();
+        }
+};
+
+template <class _LhsDuration>
+struct __duration_lt<_LhsDuration, _LhsDuration>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs)
+        {return __lhs.count() < __rhs.count();}
+};
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
+}
+
+// Duration >
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+// Duration <=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+// Duration >=
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+// Duration +
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
+    __r += __rhs;
+    return __r;
+}
+
+// Duration -
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
+    __r -= __rhs;
+    return __r;
+}
+
+// Duration *
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    duration<_Cr, _Period> __r = __d;
+    __r *= static_cast<_Cr>(__s);
+    return __r;
+}
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
+    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
+>::type
+operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
+{
+    return __d * __s;
+}
+
+// Duration /
+
+template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
+struct __duration_divide_result
+{
+};
+
+template <class _Duration, class _Rep2,
+    bool = is_convertible<_Rep2,
+                          typename common_type<typename _Duration::rep, _Rep2>::type>::value>
+struct __duration_divide_imp
+{
+};
+
+template <class _Rep1, class _Period, class _Rep2>
+struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
+{
+    typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
+};
+
+template <class _Rep1, class _Period, class _Rep2>
+struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
+    : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
+{
+};
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
+operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    duration<_Cr, _Period> __r = __d;
+    __r /= static_cast<_Cr>(__s);
+    return __r;
+}
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename common_type<_Rep1, _Rep2>::type
+operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
+    return _Ct(__lhs).count() / _Ct(__rhs).count();
+}
+
+// Duration %
+
+template <class _Rep1, class _Period, class _Rep2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
+operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
+{
+    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
+    duration<_Cr, _Period> __r = __d;
+    __r %= static_cast<_Cr>(__s);
+    return __r;
+}
+
+template <class _Rep1, class _Period1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
+operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type __r = __lhs;
+    __r %= __rhs;
+    return __r;
+}
+
+//////////////////////////////////////////////////////////
+///////////////////// time_point /////////////////////////
+//////////////////////////////////////////////////////////
+
+template <class _Clock, class _Duration = typename _Clock::duration>
+class time_point
+{
+    static_assert(__is_duration<_Duration>::value,
+                  "Second template parameter of time_point must be a std::chrono::duration");
+public:
+    typedef _Clock                    clock;
+    typedef _Duration                 duration;
+    typedef typename duration::rep    rep;
+    typedef typename duration::period period;
+private:
+    duration __d_;
+
+public:
+    _LIBCPP_INLINE_VISIBILITY time_point() : __d_(duration::zero()) {}
+    _LIBCPP_INLINE_VISIBILITY explicit time_point(const duration& __d) : __d_(__d) {}
+
+    // conversions
+    template <class _Duration2>
+    _LIBCPP_INLINE_VISIBILITY
+    time_point(const time_point<clock, _Duration2>& t,
+        typename enable_if
+        <
+            is_convertible<_Duration2, duration>::value
+        >::type* = 0)
+            : __d_(t.time_since_epoch()) {}
+
+    // observer
+
+    _LIBCPP_INLINE_VISIBILITY duration time_since_epoch() const {return __d_;}
+
+    // arithmetic
+
+    _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d;}
+    _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d;}
+
+    // special values
+
+    _LIBCPP_INLINE_VISIBILITY static time_point min() {return time_point(duration::min());}
+    _LIBCPP_INLINE_VISIBILITY static time_point max() {return time_point(duration::max());}
+};
+
+} // chrono
+
+template <class _Clock, class _Duration1, class _Duration2>
+struct common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> >
+{
+    typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
+};
+
+namespace chrono {
+
+template <class _ToDuration, class _Clock, class _Duration>
+inline _LIBCPP_INLINE_VISIBILITY
+time_point<_Clock, _ToDuration>
+time_point_cast(const time_point<_Clock, _Duration>& __t)
+{
+    return time_point<_Clock, _ToDuration>(_STD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
+}
+
+// time_point ==
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() == __rhs.time_since_epoch();
+}
+
+// time_point !=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+// time_point <
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() < __rhs.time_since_epoch();
+}
+
+// time_point >
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+// time_point <=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+// time_point >=
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+// time_point operator+(time_point x, duration y);
+
+template <class _Clock, class _Duration1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
+operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
+    _Tr __r(__lhs.time_since_epoch());
+    __r += __rhs;
+    return __r;
+}
+
+// time_point operator+(duration x, time_point y);
+
+template <class _Rep1, class _Period1, class _Clock, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
+operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __rhs + __lhs;
+}
+
+// time_point operator-(time_point x, duration y);
+
+template <class _Clock, class _Duration1, class _Rep2, class _Period2>
+inline _LIBCPP_INLINE_VISIBILITY
+time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
+operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
+{
+    return __lhs + (-__rhs);
+}
+
+// duration operator-(time_point x, time_point y);
+
+template <class _Clock, class _Duration1, class _Duration2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename common_type<_Duration1, _Duration2>::type
+operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
+{
+    return __lhs.time_since_epoch() - __rhs.time_since_epoch();
+}
+
+//////////////////////////////////////////////////////////
+/////////////////////// clocks ///////////////////////////
+//////////////////////////////////////////////////////////
+
+class system_clock
+{
+public:
+    typedef microseconds                     duration;
+    typedef duration::rep                    rep;
+    typedef duration::period                 period;
+    typedef chrono::time_point<system_clock> time_point;
+    static const bool is_monotonic =          false;
+
+    static time_point now();
+    static time_t     to_time_t  (const time_point& __t);
+    static time_point from_time_t(time_t __t);
+};
+
+class monotonic_clock
+{
+public:
+    typedef nanoseconds                                   duration;
+    typedef duration::rep                                 rep;
+    typedef duration::period                              period;
+    typedef chrono::time_point<monotonic_clock, duration> time_point;
+    static const bool is_monotonic =                       true;
+
+    static time_point now();
+};
+
+typedef monotonic_clock high_resolution_clock;
+
+} // chrono
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CHRONO
diff --git a/include/cinttypes b/include/cinttypes
new file mode 100644
index 0000000..e0a7622
--- /dev/null
+++ b/include/cinttypes
@@ -0,0 +1,257 @@
+// -*- C++ -*-
+//===--------------------------- cinttypes --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CINTTYPES
+#define _LIBCPP_CINTTYPES
+
+/*
+    cinttypes synopsis
+
+This entire header is C99 / C++0X
+
+#include <cstdint>  // <cinttypes> includes <cstdint>
+
+Macros:
+
+    PRId8
+    PRId16
+    PRId32
+    PRId64
+
+    PRIdLEAST8
+    PRIdLEAST16
+    PRIdLEAST32
+    PRIdLEAST64
+
+    PRIdFAST8
+    PRIdFAST16
+    PRIdFAST32
+    PRIdFAST64
+
+    PRIdMAX
+    PRIdPTR
+
+    PRIi8
+    PRIi16
+    PRIi32
+    PRIi64
+
+    PRIiLEAST8
+    PRIiLEAST16
+    PRIiLEAST32
+    PRIiLEAST64
+
+    PRIiFAST8
+    PRIiFAST16
+    PRIiFAST32
+    PRIiFAST64
+
+    PRIiMAX
+    PRIiPTR
+
+    PRIo8
+    PRIo16
+    PRIo32
+    PRIo64
+
+    PRIoLEAST8
+    PRIoLEAST16
+    PRIoLEAST32
+    PRIoLEAST64
+
+    PRIoFAST8
+    PRIoFAST16
+    PRIoFAST32
+    PRIoFAST64
+
+    PRIoMAX
+    PRIoPTR
+
+    PRIu8
+    PRIu16
+    PRIu32
+    PRIu64
+
+    PRIuLEAST8
+    PRIuLEAST16
+    PRIuLEAST32
+    PRIuLEAST64
+
+    PRIuFAST8
+    PRIuFAST16
+    PRIuFAST32
+    PRIuFAST64
+
+    PRIuMAX
+    PRIuPTR
+
+    PRIx8
+    PRIx16
+    PRIx32
+    PRIx64
+
+    PRIxLEAST8
+    PRIxLEAST16
+    PRIxLEAST32
+    PRIxLEAST64
+
+    PRIxFAST8
+    PRIxFAST16
+    PRIxFAST32
+    PRIxFAST64
+
+    PRIxMAX
+    PRIxPTR
+
+    PRIX8
+    PRIX16
+    PRIX32
+    PRIX64
+
+    PRIXLEAST8
+    PRIXLEAST16
+    PRIXLEAST32
+    PRIXLEAST64
+
+    PRIXFAST8
+    PRIXFAST16
+    PRIXFAST32
+    PRIXFAST64
+
+    PRIXMAX
+    PRIXPTR
+
+    SCNd8
+    SCNd16
+    SCNd32
+    SCNd64
+
+    SCNdLEAST8
+    SCNdLEAST16
+    SCNdLEAST32
+    SCNdLEAST64
+
+    SCNdFAST8
+    SCNdFAST16
+    SCNdFAST32
+    SCNdFAST64
+
+    SCNdMAX
+    SCNdPTR
+
+    SCNi8
+    SCNi16
+    SCNi32
+    SCNi64
+
+    SCNiLEAST8
+    SCNiLEAST16
+    SCNiLEAST32
+    SCNiLEAST64
+
+    SCNiFAST8
+    SCNiFAST16
+    SCNiFAST32
+    SCNiFAST64
+
+    SCNiMAX
+    SCNiPTR
+
+    SCNo8
+    SCNo16
+    SCNo32
+    SCNo64
+
+    SCNoLEAST8
+    SCNoLEAST16
+    SCNoLEAST32
+    SCNoLEAST64
+
+    SCNoFAST8
+    SCNoFAST16
+    SCNoFAST32
+    SCNoFAST64
+
+    SCNoMAX
+    SCNoPTR
+
+    SCNu8
+    SCNu16
+    SCNu32
+    SCNu64
+
+    SCNuLEAST8
+    SCNuLEAST16
+    SCNuLEAST32
+    SCNuLEAST64
+
+    SCNuFAST8
+    SCNuFAST16
+    SCNuFAST32
+    SCNuFAST64
+
+    SCNuMAX
+    SCNuPTR
+
+    SCNx8
+    SCNx16
+    SCNx32
+    SCNx64
+
+    SCNxLEAST8
+    SCNxLEAST16
+    SCNxLEAST32
+    SCNxLEAST64
+
+    SCNxFAST8
+    SCNxFAST16
+    SCNxFAST32
+    SCNxFAST64
+
+    SCNxMAX
+    SCNxPTR
+
+namespace std
+{
+
+Types:
+
+    imaxdiv_t
+
+intmax_t  imaxabs(intmax_t j);
+imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
+intmax_t  strtoimax(const char* restrict nptr, char** restrict endptr, int base);
+uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base);
+intmax_t  wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
+uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
+
+}  // std
+*/
+
+#include <__config>
+#include <cstdint>
+#include <inttypes.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using::imaxdiv_t;
+
+using::imaxabs;
+using::imaxdiv;
+using::strtoimax;
+using::strtoumax;
+using::wcstoimax;
+using::wcstoumax;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CINTTYPES
diff --git a/include/ciso646 b/include/ciso646
new file mode 100644
index 0000000..5058ed7
--- /dev/null
+++ b/include/ciso646
@@ -0,0 +1,23 @@
+// -*- C++ -*-
+//===--------------------------- ciso646 ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CISO646
+#define _LIBCPP_CISO646
+
+/*
+    ciso646 synopsis
+
+*/
+
+#include <__config>
+
+#pragma GCC system_header
+
+#endif  // _LIBCPP_CISO646
diff --git a/include/climits b/include/climits
new file mode 100644
index 0000000..305c7c7
--- /dev/null
+++ b/include/climits
@@ -0,0 +1,46 @@
+// -*- C++ -*-
+//===--------------------------- climits ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CLIMITS
+#define _LIBCPP_CLIMITS
+
+/*
+    climits synopsis
+
+Macros:
+
+    CHAR_BIT
+    SCHAR_MIN
+    SCHAR_MAX
+    UCHAR_MAX
+    CHAR_MIN
+    CHAR_MAX
+    MB_LEN_MAX
+    SHRT_MIN
+    SHRT_MAX
+    USHRT_MAX
+    INT_MIN
+    INT_MAX
+    UINT_MAX
+    LONG_MIN
+    LONG_MAX
+    ULONG_MAX
+    LLONG_MIN   // C99
+    LLONG_MAX   // C99
+    ULLONG_MAX  // C99
+
+*/
+
+#include <__config>
+#include <limits.h>
+
+#pragma GCC system_header
+
+#endif  // _LIBCPP_CLIMITS
diff --git a/include/clocale b/include/clocale
new file mode 100644
index 0000000..bb4865b
--- /dev/null
+++ b/include/clocale
@@ -0,0 +1,51 @@
+// -*- C++ -*-
+//===--------------------------- clocale ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CLOCALE
+#define _LIBCPP_CLOCALE
+
+/*
+    clocale synopsis
+
+Macros:
+
+    LC_ALL
+    LC_COLLATE
+    LC_CTYPE
+    LC_MONETARY
+    LC_NUMERIC
+    LC_TIME
+    NULL
+
+namespace std
+{
+
+struct lconv;
+char* setlocale(int category, const char* locale);
+lconv* localeconv();
+
+}  // std
+
+*/
+
+#include <__config>
+#include <locale.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::lconv;
+using ::setlocale;
+using ::localeconv;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CLOCALE
diff --git a/include/cmath b/include/cmath
new file mode 100644
index 0000000..01a9139
--- /dev/null
+++ b/include/cmath
@@ -0,0 +1,1644 @@
+// -*- C++ -*-
+//===---------------------------- cmath -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CMATH
+#define _LIBCPP_CMATH
+
+/*
+    cmath synopsis
+
+Macros:
+
+    HUGE_VAL
+    HUGE_VALF               // C99
+    HUGE_VALL               // C99
+    INFINITY                // C99
+    NAN                     // C99
+    FP_INFINITE             // C99
+    FP_NAN                  // C99
+    FP_NORMAL               // C99
+    FP_SUBNORMAL            // C99
+    FP_ZERO                 // C99
+    FP_FAST_FMA             // C99
+    FP_FAST_FMAF            // C99
+    FP_FAST_FMAL            // C99
+    FP_ILOGB0               // C99
+    FP_ILOGBNAN             // C99
+    MATH_ERRNO              // C99
+    MATH_ERREXCEPT          // C99
+    math_errhandling        // C99
+
+namespace std
+{
+
+Types:
+
+    float_t                 // C99
+    double_t                // C99
+
+// C90
+
+floating_point abs(floating_point x);
+
+floating_point acos (arithmetic x);
+float          acosf(float x);
+long double    acosl(long double x);
+
+floating_point asin (arithmetic x);
+float          asinf(float x);
+long double    asinl(long double x);
+
+floating_point atan (arithmetic x);
+float          atanf(float x);
+long double    atanl(long double x);
+
+floating_point atan2 (arithmetic y, arithmetic x);
+float          atan2f(float y, float x);
+long double    atan2l(long double y, long double x);
+
+floating_point ceil (arithmetic x);
+float          ceilf(float x);
+long double    ceill(long double x);
+
+floating_point cos (arithmetic x);
+float          cosf(float x);
+long double    cosl(long double x);
+
+floating_point cosh (arithmetic x);
+float          coshf(float x);
+long double    coshl(long double x);
+
+floating_point exp (arithmetic x);
+float          expf(float x);
+long double    expl(long double x);
+
+floating_point fabs (arithmetic x);
+float          fabsf(float x);
+long double    fabsl(long double x);
+
+floating_point floor (arithmetic x);
+float          floorf(float x);
+long double    floorl(long double x);
+
+floating_point fmod (arithmetic x, arithmetic y);
+float          fmodf(float x, float y);
+long double    fmodl(long double x, long double y);
+
+floating_point frexp (arithmetic value, int* exp);
+float          frexpf(float value, int* exp);
+long double    frexpl(long double value, int* exp);
+
+floating_point ldexp (arithmetic value, int exp);
+float          ldexpf(float value, int exp);
+long double    ldexpl(long double value, int exp);
+
+floating_point log (arithmetic x);
+float          logf(float x);
+long double    logl(long double x);
+
+floating_point log10 (arithmetic x);
+float          log10f(float x);
+long double    log10l(long double x);
+
+floating_point modf (floating_point value, floating_point* iptr);
+float          modff(float value, float* iptr);
+long double    modfl(long double value, long double* iptr);
+
+floating_point pow (arithmetic x, arithmetic y);
+float          powf(float x, float y);
+long double    powl(long double x, long double y);
+
+floating_point sin (arithmetic x);
+float          sinf(float x);
+long double    sinl(long double x);
+
+floating_point sinh (arithmetic x);
+float          sinhf(float x);
+long double    sinhl(long double x);
+
+floating_point sqrt (arithmetic x);
+float          sqrtf(float x);
+long double    sqrtl(long double x);
+
+floating_point tan (arithmetic x);
+float          tanf(float x);
+long double    tanl(long double x);
+
+floating_point tanh (arithmetic x);
+float          tanhf(float x);
+long double    tanhl(long double x);
+
+//  C99
+
+bool signbit(floating_point x);
+
+int fpclassify(floating_point x);
+
+bool isfinite(floating_point x); 
+bool isinf(floating_point x); 
+bool isnan(floating_point x); 
+bool isnormal(floating_point x); 
+
+bool isgreater(floating_point x, floating_point y); 
+bool isgreaterequal(floating_point x, floating_point y); 
+bool isless(floating_point x, floating_point y); 
+bool islessequal(floating_point x, floating_point y); 
+bool islessgreater(floating_point x, floating_point y); 
+bool isunordered(floating_point x, floating_point y); 
+
+floating_point acosh (arithmetic x);
+float          acoshf(float x);
+long double    acoshl(long double x);
+
+floating_point asinh (arithmetic x);
+float          asinhf(float x);
+long double    asinhl(long double x);
+
+floating_point atanh (arithmetic x);
+float          atanhf(float x);
+long double    atanhl(long double x);
+
+floating_point cbrt (arithmetic x);
+float          cbrtf(float x);
+long double    cbrtl(long double x);
+
+floating_point copysign (arithmetic x, arithmetic y);
+float          copysignf(float x, float y);
+long double    copysignl(long double x, long double y);
+
+floating_point erf (arithmetic x);
+float          erff(float x);
+long double    erfl(long double x);
+
+floating_point erfc (arithmetic x);
+float          erfcf(float x);
+long double    erfcl(long double x);
+
+floating_point exp2 (arithmetic x);
+float          exp2f(float x);
+long double    exp2l(long double x);
+
+floating_point expm1 (arithmetic x);
+float          expm1f(float x);
+long double    expm1l(long double x);
+
+floating_point fdim (arithmetic x, arithmetic y);
+float          fdimf(float x, float y);
+long double    fdiml(long double x, long double y);
+
+floating_point fma (arithmetic x, arithmetic y, arithmetic z);
+float          fmaf(float x, float y, float z);
+long double    fmal(long double x, long double y, long double z);
+
+floating_point fmax (arithmetic x, arithmetic y);
+float          fmaxf(float x, float y);
+long double    fmaxl(long double x, long double y);
+
+floating_point fmin (arithmetic x, arithmetic y);
+float          fminf(float x, float y);
+long double    fminl(long double x, long double y);
+
+floating_point hypot (arithmetic x, arithmetic y);
+float          hypotf(float x, float y);
+long double    hypotl(long double x, long double y);
+
+int ilogb (arithmetic x);
+int ilogbf(float x);
+int ilogbl(long double x);
+
+floating_point lgamma (arithmetic x);
+float          lgammaf(float x);
+long double    lgammal(long double x);
+
+long long llrint (arithmetic x);
+long long llrintf(float x);
+long long llrintl(long double x);
+
+long long llround (arithmetic x);
+long long llroundf(float x);
+long long llroundl(long double x);
+
+floating_point log1p (arithmetic x);
+float          log1pf(float x);
+long double    log1pl(long double x);
+
+floating_point log2 (arithmetic x);
+float          log2f(float x);
+long double    log2l(long double x);
+
+floating_point logb (arithmetic x);
+float          logbf(float x);
+long double    logbl(long double x);
+
+long lrint (arithmetic x);
+long lrintf(float x);
+long lrintl(long double x);
+
+long lround (arithmetic x);
+long lroundf(float x);
+long lroundl(long double x);
+
+double      nan (const char* str);
+float       nanf(const char* str);
+long double nanl(const char* str);
+
+floating_point nearbyint (arithmetic x);
+float          nearbyintf(float x);
+long double    nearbyintl(long double x);
+
+floating_point nextafter (arithmetic x, arithmetic y);
+float          nextafterf(float x, float y);
+long double    nextafterl(long double x, long double y);
+
+floating_point nexttoward (arithmetic x, long double y);
+float          nexttowardf(float x, long double y);
+long double    nexttowardl(long double x, long double y);
+
+floating_point remainder (arithmetic x, arithmetic y);
+float          remainderf(float x, float y);
+long double    remainderl(long double x, long double y);
+
+floating_point remquo (arithmetic x, arithmetic y, int* pquo);
+float          remquof(float x, float y, int* pquo);
+long double    remquol(long double x, long double y, int* pquo);
+
+floating_point rint (arithmetic x);
+float          rintf(float x);
+long double    rintl(long double x);
+
+floating_point round (arithmetic x);
+float          roundf(float x);
+long double    roundl(long double x);
+
+floating_point scalbln (arithmetic x, long ex);
+float          scalblnf(float x, long ex);
+long double    scalblnl(long double x, long ex);
+
+floating_point scalbn (arithmetic x, int ex);
+float          scalbnf(float x, int ex);
+long double    scalbnl(long double x, int ex);
+
+floating_point tgamma (arithmetic x);
+float          tgammaf(float x);
+long double    tgammal(long double x);
+
+floating_point trunc (arithmetic x);
+float          truncf(float x);
+long double    truncl(long double x);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <math.h>
+#include <type_traits>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::float_t;
+using ::double_t;
+
+// abs
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_floating_point<_A1>::value, _A1>::type
+abs(_A1 __x) {return fabs(__x);}
+
+// acos
+
+using ::acos;
+using ::acosf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       acos(float __x)       {return acosf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) {return acosl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+acos(_A1 __x) {return acos((double)__x);}
+
+// asin
+
+using ::asin;
+using ::asinf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       asin(float __x)       {return asinf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) {return asinl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+asin(_A1 __x) {return asin((double)__x);}
+
+// atan
+
+using ::atan;
+using ::atanf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       atan(float __x)       {return atanf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) {return atanl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+atan(_A1 __x) {return atan((double)__x);}
+
+// atan2
+
+using ::atan2;
+using ::atan2f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __y, float __x)             {return atan2f(__y, __x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) {return atan2l(__y, __x);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+atan2(_A1 __y, _A2 __x)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return atan2((__result_type)__y, (__result_type)__x);
+}
+
+// ceil
+
+using ::ceil;
+using ::ceilf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __x)       {return ceilf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) {return ceill(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+ceil(_A1 __x) {return ceil((double)__x);}
+
+// cos
+
+using ::cos;
+using ::cosf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       cos(float __x)       {return cosf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) {return cosl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cos(_A1 __x) {return cos((double)__x);}
+
+// cosh
+
+using ::cosh;
+using ::coshf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       cosh(float __x)       {return coshf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) {return coshl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cosh(_A1 __x) {return cosh((double)__x);}
+
+// exp
+
+using ::exp;
+using ::expf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       exp(float __x)       {return expf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) {return expl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+exp(_A1 __x) {return exp((double)__x);}
+
+// fabs
+
+using ::fabs;
+using ::fabsf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fabs(float __x)       {return fabsf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) {return fabsl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+fabs(_A1 __x) {return fabs((double)__x);}
+
+// floor
+
+using ::floor;
+using ::floorf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       floor(float __x)       {return floorf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) {return floorl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+floor(_A1 __x) {return floor((double)__x);}
+
+// fmod
+
+using ::fmod;
+using ::fmodf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fmod(float __x, float __y)             {return fmodf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) {return fmodl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+fmod(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmod((__result_type)__x, (__result_type)__y);
+}
+
+// frexp
+
+using ::frexp;
+using ::frexpf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       frexp(float __x, int* __e)       {return frexpf(__x, __e);}
+inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) {return frexpl(__x, __e);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+frexp(_A1 __x, int* __e) {return frexp((double)__x, __e);}
+
+// ldexp
+
+using ::ldexp;
+using ::ldexpf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       ldexp(float __x, int __e)       {return ldexpf(__x, __e);}
+inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) {return ldexpl(__x, __e);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+ldexp(_A1 __x, int __e) {return ldexp((double)__x, __e);}
+
+// log
+
+using ::log;
+using ::logf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log(float __x)       {return logf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) {return logl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log(_A1 __x) {return log((double)__x);}
+
+// log10
+
+using ::log10;
+using ::log10f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log10(float __x)       {return log10f(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) {return log10l(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log10(_A1 __x) {return log10((double)__x);}
+
+// modf
+
+using ::modf;
+using ::modff;
+
+inline _LIBCPP_INLINE_VISIBILITY float       modf(float __x, float* __y)             {return modff(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) {return modfl(__x, __y);}
+
+// pow
+
+using ::pow;
+using ::powf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       pow(float __x, float __y)             {return powf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) {return powl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+pow(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return pow((__result_type)__x, (__result_type)__y);
+}
+
+// sin
+
+using ::sin;
+using ::sinf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       sin(float __x)       {return sinf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) {return sinl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sin(_A1 __x) {return sin((double)__x);}
+
+// sinh
+
+using ::sinh;
+using ::sinhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       sinh(float __x)       {return sinhf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) {return sinhl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sinh(_A1 __x) {return sinh((double)__x);}
+
+// sqrt
+
+using ::sqrt;
+using ::sqrtf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       sqrt(float __x)       {return sqrtf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) {return sqrtl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+sqrt(_A1 __x) {return sqrt((double)__x);}
+
+// tan
+
+using ::tan;
+using ::tanf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       tan(float __x)       {return tanf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) {return tanl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tan(_A1 __x) {return tan((double)__x);}
+
+// tanh
+
+using ::tanh;
+using ::tanhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       tanh(float __x)       {return tanhf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) {return tanhl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tanh(_A1 __x) {return tanh((double)__x);}
+
+// signbit
+
+#ifndef signbit
+#error Implementation error: signbit not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_signbit(_A1 __x)
+{
+    return signbit(__x);
+}
+
+#undef signbit
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, bool>::type
+signbit(_A1 __x)
+{
+    return __libcpp_signbit(__x);
+}
+
+#endif  // signbit
+
+// fpclassify
+
+#ifndef fpclassify
+#error Implementation error: fpclassify not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+int
+__libcpp_fpclassify(_A1 __x)
+{
+    return fpclassify(__x);
+}
+
+#undef fpclassify
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, int>::type
+fpclassify(_A1 __x)
+{
+    return __libcpp_fpclassify(__x);
+}
+
+#endif  // fpclassify
+
+// isfinite
+
+#ifndef isfinite
+#error Implementation error: isfinite not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isfinite(_A1 __x)
+{
+    return isfinite(__x);
+}
+
+#undef isfinite
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, bool>::type
+isfinite(_A1 __x)
+{
+    return __libcpp_isfinite(__x);
+}
+
+#endif  // isfinite
+
+// isinf
+
+#ifndef isinf
+#error Implementation error: isinf not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isinf(_A1 __x)
+{
+    return isinf(__x);
+}
+
+#undef isinf
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, bool>::type
+isinf(_A1 __x)
+{
+    return __libcpp_isinf(__x);
+}
+
+#endif  // isinf
+
+// isnan
+
+#ifndef isnan
+#error Implementation error: isnan not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isnan(_A1 __x)
+{
+    return isnan(__x);
+}
+
+#undef isnan
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, bool>::type
+isnan(_A1 __x)
+{
+    return __libcpp_isnan(__x);
+}
+
+#endif  // isnan
+
+// isnormal
+
+#ifndef isnormal
+#error Implementation error: isnormal not defined
+#else
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isnormal(_A1 __x)
+{
+    return isnormal(__x);
+}
+
+#undef isnormal
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if<is_floating_point<_A1>::value, bool>::type
+isnormal(_A1 __x)
+{
+    return __libcpp_isnormal(__x);
+}
+
+#endif  // isnormal
+
+// isgreater
+
+#ifndef isgreater
+#error Implementation error: isgreater not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isgreater(_A1 __x, _A2 __y)
+{
+    return isgreater(__x, __y);
+}
+
+#undef isgreater
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+isgreater(_A1 __x, _A2 __y)
+{
+    return __libcpp_isgreater(__x, __y);
+}
+
+#endif  // isgreater
+
+// isgreaterequal
+
+#ifndef isgreaterequal
+#error Implementation error: isgreaterequal not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isgreaterequal(_A1 __x, _A2 __y)
+{
+    return isgreaterequal(__x, __y);
+}
+
+#undef isgreaterequal
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+isgreaterequal(_A1 __x, _A2 __y)
+{
+    return __libcpp_isgreaterequal(__x, __y);
+}
+
+#endif  // isgreaterequal
+
+// isless
+
+#ifndef isless
+#error Implementation error: isless not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isless(_A1 __x, _A2 __y)
+{
+    return isless(__x, __y);
+}
+
+#undef isless
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+isless(_A1 __x, _A2 __y)
+{
+    return __libcpp_isless(__x, __y);
+}
+
+#endif  // isless
+
+// islessequal
+
+#ifndef islessequal
+#error Implementation error: islessequal not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_islessequal(_A1 __x, _A2 __y)
+{
+    return islessequal(__x, __y);
+}
+
+#undef islessequal
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+islessequal(_A1 __x, _A2 __y)
+{
+    return __libcpp_islessequal(__x, __y);
+}
+
+#endif  // islessequal
+
+// islessgreater
+
+#ifndef islessgreater
+#error Implementation error: islessgreater not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_islessgreater(_A1 __x, _A2 __y)
+{
+    return islessgreater(__x, __y);
+}
+
+#undef islessgreater
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+islessgreater(_A1 __x, _A2 __y)
+{
+    return __libcpp_islessgreater(__x, __y);
+}
+
+#endif  // islessgreater
+
+// isunordered
+
+#ifndef isunordered
+#error Implementation error: isunordered not defined
+#else
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+bool
+__libcpp_isunordered(_A1 __x, _A2 __y)
+{
+    return isunordered(__x, __y);
+}
+
+#undef isunordered
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    is_floating_point<_A1>::value &&
+    is_floating_point<_A2>::value,
+    bool
+>::type
+isunordered(_A1 __x, _A2 __y)
+{
+    return __libcpp_isunordered(__x, __y);
+}
+
+#endif  // isunordered
+
+// acosh
+
+using ::acosh;
+using ::acoshf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __x)       {return acoshf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __x) {return acoshl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+acosh(_A1 __x) {return acosh((double)__x);}
+
+// asinh
+
+using ::asinh;
+using ::asinhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __x)       {return asinhf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __x) {return asinhl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+asinh(_A1 __x) {return asinh((double)__x);}
+
+// atanh
+
+using ::atanh;
+using ::atanhf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __x)       {return atanhf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __x) {return atanhl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+atanh(_A1 __x) {return atanh((double)__x);}
+
+// cbrt
+
+using ::cbrt;
+using ::cbrtf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __x)       {return cbrtf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __x) {return cbrtl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+cbrt(_A1 __x) {return cbrt((double)__x);}
+
+// copysign
+
+using ::copysign;
+using ::copysignf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       copysign(float __x, float __y)             {return copysignf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __x, long double __y) {return copysignl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+copysign(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return copysign((__result_type)__x, (__result_type)__y);
+}
+
+// erf
+
+using ::erf;
+using ::erff;
+
+inline _LIBCPP_INLINE_VISIBILITY float       erf(float __x)       {return erff(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __x) {return erfl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+erf(_A1 __x) {return erf((double)__x);}
+
+// erfc
+
+using ::erfc;
+using ::erfcf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       erfc(float __x)       {return erfcf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __x) {return erfcl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+erfc(_A1 __x) {return erfc((double)__x);}
+
+// exp2
+
+using ::exp2;
+using ::exp2f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       exp2(float __x)       {return exp2f(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __x) {return exp2l(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+exp2(_A1 __x) {return exp2((double)__x);}
+
+// expm1
+
+using ::expm1;
+using ::expm1f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       expm1(float __x)       {return expm1f(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __x) {return expm1l(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+expm1(_A1 __x) {return expm1((double)__x);}
+
+// fdim
+
+using ::fdim;
+using ::fdimf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fdim(float __x, float __y)             {return fdimf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __x, long double __y) {return fdiml(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+fdim(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fdim((__result_type)__x, (__result_type)__y);
+}
+
+// fma
+
+inline _LIBCPP_INLINE_VISIBILITY float fmaf(float __x, float __y, float __z) {return (float)((double)__x*__y + __z);}
+#define FP_FAST_FMAF
+
+//#if (defined(__ppc__) || defined(__ppc64__))
+//inline _LIBCPP_INLINE_VISIBILITY double fma(register double __x, register double __y, register double __z) {asm {fmadd __x, __x, __y, __z} return __x;}
+//#define FP_FAST_FMA
+//#else
+using ::fma;
+//#endif
+
+inline _LIBCPP_INLINE_VISIBILITY float       fma(float __x, float __y, float __z)                   {return fmaf(__x, __y, __z);}
+inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __x, long double __y, long double __z) {return fmal(__x, __y, __z);}
+
+template <class _A1, class _A2, class _A3>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value &&
+    is_arithmetic<_A3>::value,
+    typename __promote<_A1, _A2, _A3>::type
+>::type
+fma(_A1 __x, _A2 __y, _A3 __z)
+{
+    typedef typename __promote<_A1, _A2, _A3>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value &&
+                      is_same<_A3, __result_type>::value)), "");
+    return fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
+}
+
+// fmax
+
+using ::fmax;
+using ::fmaxf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fmax(float __x, float __y)             {return fmaxf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __x, long double __y) {return fmaxl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+fmax(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmax((__result_type)__x, (__result_type)__y);
+}
+
+// fmin
+
+using ::fmin;
+using ::fminf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       fmin(float __x, float __y)             {return fminf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __x, long double __y) {return fminl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+fmin(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return fmin((__result_type)__x, (__result_type)__y);
+}
+
+// hypot
+
+using ::hypot;
+using ::hypotf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       hypot(float __x, float __y)             {return hypotf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __x, long double __y) {return hypotl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+hypot(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return hypot((__result_type)__x, (__result_type)__y);
+}
+
+// ilogb
+
+using ::ilogb;
+using ::ilogbf;
+
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __x)       {return ilogbf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __x) {return ilogbl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, int>::type
+ilogb(_A1 __x) {return ilogb((double)__x);}
+
+// lgamma
+
+using ::lgamma;
+using ::lgammaf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       lgamma(float __x)       {return lgammaf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __x) {return lgammal(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+lgamma(_A1 __x) {return lgamma((double)__x);}
+
+// llrint
+
+using ::llrint;
+using ::llrintf;
+
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __x)       {return llrintf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __x) {return llrintl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long long>::type
+llrint(_A1 __x) {return llrint((double)__x);}
+
+// llround
+
+using ::llround;
+using ::llroundf;
+
+inline _LIBCPP_INLINE_VISIBILITY long long llround(float __x)       {return llroundf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __x) {return llroundl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long long>::type
+llround(_A1 __x) {return llround((double)__x);}
+
+// log1p
+
+using ::log1p;
+using ::log1pf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log1p(float __x)       {return log1pf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __x) {return log1pl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log1p(_A1 __x) {return log1p((double)__x);}
+
+// log2
+
+using ::log2;
+using ::log2f;
+
+inline _LIBCPP_INLINE_VISIBILITY float       log2(float __x)       {return log2f(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __x) {return log2l(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+log2(_A1 __x) {return log2((double)__x);}
+
+// logb
+
+using ::logb;
+using ::logbf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       logb(float __x)       {return logbf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __x) {return logbl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+logb(_A1 __x) {return logb((double)__x);}
+
+// lrint
+
+using ::lrint;
+using ::lrintf;
+
+inline _LIBCPP_INLINE_VISIBILITY long lrint(float __x)       {return lrintf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __x) {return lrintl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long>::type
+lrint(_A1 __x) {return lrint((double)__x);}
+
+// lround
+
+using ::lround;
+using ::lroundf;
+
+inline _LIBCPP_INLINE_VISIBILITY long lround(float __x)       {return lroundf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long lround(long double __x) {return lroundl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, long>::type
+lround(_A1 __x) {return lround((double)__x);}
+
+// nan
+
+using ::nan;
+using ::nanf;
+
+// nearbyint
+
+using ::nearbyint;
+using ::nearbyintf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nearbyint(float __x)       {return nearbyintf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __x) {return nearbyintl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+nearbyint(_A1 __x) {return nearbyint((double)__x);}
+
+// nextafter
+
+using ::nextafter;
+using ::nextafterf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nextafter(float __x, float __y)             {return nextafterf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __x, long double __y) {return nextafterl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+nextafter(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return nextafter((__result_type)__x, (__result_type)__y);
+}
+
+// nexttoward
+
+using ::nexttoward;
+using ::nexttowardf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       nexttoward(float __x, long double __y)       {return nexttowardf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+nexttoward(_A1 __x, long double __y) {return nexttoward((double)__x, __y);}
+
+// remainder
+
+using ::remainder;
+using ::remainderf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __x, float __y)             {return remainderf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) {return remainderl(__x, __y);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+remainder(_A1 __x, _A2 __y)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return remainder((__result_type)__x, (__result_type)__y);
+}
+
+// remquo
+
+using ::remquo;
+using ::remquof;
+
+inline _LIBCPP_INLINE_VISIBILITY float       remquo(float __x, float __y, int* __z)             {return remquof(__x, __y, __z);}
+inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __x, long double __y, int* __z) {return remquol(__x, __y, __z);}
+
+template <class _A1, class _A2>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_A1>::value &&
+    is_arithmetic<_A2>::value,
+    typename __promote<_A1, _A2>::type
+>::type
+remquo(_A1 __x, _A2 __y, int* __z)
+{
+    typedef typename __promote<_A1, _A2>::type __result_type;
+    static_assert((!(is_same<_A1, __result_type>::value &&
+                      is_same<_A2, __result_type>::value)), "");
+    return remquo((__result_type)__x, (__result_type)__y, __z);
+}
+
+// rint
+
+using ::rint;
+using ::rintf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       rint(float __x)       {return rintf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __x) {return rintl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+rint(_A1 __x) {return rint((double)__x);}
+
+// round
+
+using ::round;
+using ::roundf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       round(float __x)       {return roundf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) {return roundl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+round(_A1 __x) {return round((double)__x);}
+
+// scalbln
+
+using ::scalbln;
+using ::scalblnf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       scalbln(float __x, long __y)       {return scalblnf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __x, long __y) {return scalblnl(__x, __y);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+scalbln(_A1 __x, long __y) {return scalbln((double)__x, __y);}
+
+// scalbn
+
+using ::scalbn;
+using ::scalbnf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       scalbn(float __x, int __y)       {return scalbnf(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __x, int __y) {return scalbnl(__x, __y);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+scalbn(_A1 __x, int __y) {return scalbn((double)__x, __y);}
+
+// tgamma
+
+using ::tgamma;
+using ::tgammaf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       tgamma(float __x)       {return tgammaf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __x) {return tgammal(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+tgamma(_A1 __x) {return tgamma((double)__x);}
+
+// trunc
+
+using ::trunc;
+using ::truncf;
+
+inline _LIBCPP_INLINE_VISIBILITY float       trunc(float __x)       {return truncf(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __x) {return truncl(__x);}
+
+template <class _A1>
+_LIBCPP_ALWAYS_INLINE
+_LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_integral<_A1>::value, double>::type
+trunc(_A1 __x) {return trunc((double)__x);}
+
+using ::acosl;
+using ::asinl;
+using ::atanl;
+using ::atan2l;
+using ::ceill;
+using ::cosl;
+using ::coshl;
+using ::expl;
+using ::fabsl;
+using ::floorl;
+using ::fmodl;
+using ::frexpl;
+using ::ldexpl;
+using ::logl;
+using ::log10l;
+using ::modfl;
+using ::powl;
+using ::sinl;
+using ::sinhl;
+using ::sqrtl;
+using ::tanl;
+using ::tanhl;
+using ::acoshl;
+using ::asinhl;
+using ::atanhl;
+using ::cbrtl;
+using ::copysignl;
+using ::erfl;
+using ::erfcl;
+using ::exp2l;
+using ::expm1l;
+using ::fdiml;
+using ::fmal;
+using ::fmaxl;
+using ::fminl;
+using ::hypotl;
+using ::ilogbl;
+using ::lgammal;
+using ::llrintl;
+using ::llroundl;
+using ::log1pl;
+using ::log2l;
+using ::logbl;
+using ::lrintl;
+using ::lroundl;
+using ::nanl;
+using ::nearbyintl;
+using ::nextafterl;
+using ::nexttowardl;
+using ::remainderl;
+using ::remquol;
+using ::rintl;
+using ::roundl;
+using ::scalblnl;
+using ::scalbnl;
+using ::tgammal;
+using ::truncl;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CMATH
diff --git a/include/complex b/include/complex
new file mode 100644
index 0000000..dd6f8aa
--- /dev/null
+++ b/include/complex
@@ -0,0 +1,1528 @@
+// -*- C++ -*-
+//===--------------------------- complex ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_COMPLEX
+#define _LIBCPP_COMPLEX
+
+/*
+    complex synopsis
+
+namespace std
+{
+
+template<class T>
+class complex
+{
+public:
+    typedef T value_type;
+
+    complex(const T& re = T(), const T& im = T());
+    complex(const complex&);
+    template<class X> complex(const complex<X>&);
+
+    T real() const;
+    T imag() const;
+
+    void real(T);
+    void imag(T);
+
+    complex<T>& operator= (const T&);
+    complex<T>& operator+=(const T&);
+    complex<T>& operator-=(const T&);
+    complex<T>& operator*=(const T&);
+    complex<T>& operator/=(const T&);
+
+    complex& operator=(const complex&);
+    template<class X> complex<T>& operator= (const complex<X>&);
+    template<class X> complex<T>& operator+=(const complex<X>&);
+    template<class X> complex<T>& operator-=(const complex<X>&);
+    template<class X> complex<T>& operator*=(const complex<X>&);
+    template<class X> complex<T>& operator/=(const complex<X>&);
+};
+
+template<>
+class complex<float>
+{ 
+public: 
+    typedef float value_type; 
+
+    constexpr complex(float re = 0.0f, float im = 0.0f); 
+    explicit constexpr complex(const complex<double>&); 
+    explicit constexpr complex(const complex<long double>&); 
+
+    constexpr float real() const; 
+    void real(float);
+    constexpr float imag() const; 
+    void imag(float);
+
+    complex<float>& operator= (float); 
+    complex<float>& operator+=(float); 
+    complex<float>& operator-=(float); 
+    complex<float>& operator*=(float); 
+    complex<float>& operator/=(float); 
+
+    complex<float>& operator=(const complex<float>&); 
+    template<class X> complex<float>& operator= (const complex<X>&); 
+    template<class X> complex<float>& operator+=(const complex<X>&); 
+    template<class X> complex<float>& operator-=(const complex<X>&); 
+    template<class X> complex<float>& operator*=(const complex<X>&); 
+    template<class X> complex<float>& operator/=(const complex<X>&); 
+};
+
+template<>
+class complex<double>
+{ 
+public: 
+    typedef double value_type; 
+
+    constexpr complex(double re = 0.0, double im = 0.0); 
+    constexpr complex(const complex<float>&); 
+    explicit constexpr complex(const complex<long double>&); 
+
+    constexpr double real() const; 
+    void real(double);
+    constexpr double imag() const; 
+    void imag(double);
+
+    complex<double>& operator= (double); 
+    complex<double>& operator+=(double); 
+    complex<double>& operator-=(double); 
+    complex<double>& operator*=(double); 
+    complex<double>& operator/=(double); 
+    complex<double>& operator=(const complex<double>&); 
+
+    template<class X> complex<double>& operator= (const complex<X>&); 
+    template<class X> complex<double>& operator+=(const complex<X>&); 
+    template<class X> complex<double>& operator-=(const complex<X>&); 
+    template<class X> complex<double>& operator*=(const complex<X>&); 
+    template<class X> complex<double>& operator/=(const complex<X>&); 
+}; 
+
+template<>
+class complex<long double>
+{ 
+public: 
+    typedef long double value_type; 
+
+    constexpr complex(long double re = 0.0L, long double im = 0.0L); 
+    constexpr complex(const complex<float>&); 
+    constexpr complex(const complex<double>&); 
+
+    constexpr long double real() const; 
+    void real(long double);
+    constexpr long double imag() const; 
+    void imag(long double);
+
+    complex<long double>& operator=(const complex<long double>&); 
+    complex<long double>& operator= (long double); 
+    complex<long double>& operator+=(long double); 
+    complex<long double>& operator-=(long double); 
+    complex<long double>& operator*=(long double); 
+    complex<long double>& operator/=(long double); 
+
+    template<class X> complex<long double>& operator= (const complex<X>&); 
+    template<class X> complex<long double>& operator+=(const complex<X>&); 
+    template<class X> complex<long double>& operator-=(const complex<X>&); 
+    template<class X> complex<long double>& operator*=(const complex<X>&); 
+    template<class X> complex<long double>& operator/=(const complex<X>&); 
+};
+
+// 26.3.6 operators:
+template<class T> complex<T> operator+(const complex<T>&, const complex<T>&);
+template<class T> complex<T> operator+(const complex<T>&, const T&);
+template<class T> complex<T> operator+(const T&, const complex<T>&);
+template<class T> complex<T> operator-(const complex<T>&, const complex<T>&);
+template<class T> complex<T> operator-(const complex<T>&, const T&);
+template<class T> complex<T> operator-(const T&, const complex<T>&);
+template<class T> complex<T> operator*(const complex<T>&, const complex<T>&);
+template<class T> complex<T> operator*(const complex<T>&, const T&);
+template<class T> complex<T> operator*(const T&, const complex<T>&);
+template<class T> complex<T> operator/(const complex<T>&, const complex<T>&);
+template<class T> complex<T> operator/(const complex<T>&, const T&);
+template<class T> complex<T> operator/(const T&, const complex<T>&);
+template<class T> complex<T> operator+(const complex<T>&);
+template<class T> complex<T> operator-(const complex<T>&);
+template<class T> bool operator==(const complex<T>&, const complex<T>&);
+template<class T> bool operator==(const complex<T>&, const T&);
+template<class T> bool operator==(const T&, const complex<T>&);
+template<class T> bool operator!=(const complex<T>&, const complex<T>&);
+template<class T> bool operator!=(const complex<T>&, const T&);
+template<class T> bool operator!=(const T&, const complex<T>&);
+
+template<class T, class charT, class traits>
+  basic_istream<charT, traits>&
+  operator>>(basic_istream<charT, traits>&, complex<T>&);
+template<class T, class charT, class traits>
+  basic_ostream<charT, traits>&
+  operator<<(basic_ostream<charT, traits>&, const complex<T>&);
+
+// 26.3.7 values:
+
+template<class T>              T real(const complex<T>&);
+                     long double real(long double);
+                          double real(double);
+template<Integral T>      double real(T);
+                          float  real(float);
+
+template<class T>              T imag(const complex<T>&);
+                     long double imag(long double);
+                          double imag(double);
+template<Integral T>      double imag(T);
+                          float  imag(float);
+
+template<class T> T abs(const complex<T>&);
+
+template<class T>              T arg(const complex<T>&);
+                     long double arg(long double);
+                          double arg(double);
+template<Integral T>      double arg(T);
+                          float  arg(float);
+
+template<class T>              T norm(const complex<T>&);
+                     long double norm(long double);
+                          double norm(double);
+template<Integral T>      double norm(T);
+                          float  norm(float);
+
+template<class T>      complex<T>  conj(const complex<T>&);
+                       long double conj(long double);
+                       double      conj(double);
+template<Integral T>   double      conj(T);
+                       float       conj(float);
+
+template<class T>    complex<T>  proj(const complex<T>&);
+                     long double proj(long double);
+                     double      proj(double);
+template<Integral T> double      proj(T);
+                     float       proj(float);
+
+template<class T> complex<T> polar(const T&, const T& = 0);
+
+// 26.3.8 transcendentals:
+template<class T> complex<T> acos(const complex<T>&);
+template<class T> complex<T> asin(const complex<T>&);
+template<class T> complex<T> atan(const complex<T>&);
+template<class T> complex<T> acosh(const complex<T>&);
+template<class T> complex<T> asinh(const complex<T>&);
+template<class T> complex<T> atanh(const complex<T>&);
+template<class T> complex<T> cos (const complex<T>&);
+template<class T> complex<T> cosh (const complex<T>&);
+template<class T> complex<T> exp (const complex<T>&);
+template<class T> complex<T> log (const complex<T>&);
+template<class T> complex<T> log10(const complex<T>&);
+
+template<class T> complex<T> pow(const complex<T>&, const T&);
+template<class T> complex<T> pow(const complex<T>&, const complex<T>&);
+template<class T> complex<T> pow(const T&, const complex<T>&);
+
+template<class T> complex<T> sin (const complex<T>&);
+template<class T> complex<T> sinh (const complex<T>&);
+template<class T> complex<T> sqrt (const complex<T>&);
+template<class T> complex<T> tan (const complex<T>&);
+template<class T> complex<T> tanh (const complex<T>&);
+
+template<class T, class charT, class traits>
+  basic_istream<charT, traits>&
+  operator>>(basic_istream<charT, traits>& is, complex<T>& x);
+
+template<class T, class charT, class traits>
+  basic_ostream<charT, traits>&
+  operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <type_traits>
+#include <stdexcept>
+#include <cmath>
+#include <sstream>
+#if defined(_LIBCPP_NO_EXCEPTIONS)
+    #include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template<class _Tp> class complex;
+
+template<class _Tp> complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w);
+template<class _Tp> complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
+
+template<class _Tp>
+class complex
+{
+public:
+    typedef _Tp value_type;
+private:
+    value_type __re_;
+    value_type __im_;
+public:
+    _LIBCPP_INLINE_VISIBILITY
+    complex(const value_type& __re = value_type(), const value_type& __im = value_type())
+        : __re_(__re), __im_(__im) {}
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY
+    complex(const complex<_Xp>& __c)
+        : __re_(__c.real()), __im_(__c.imag()) {}
+
+    _LIBCPP_INLINE_VISIBILITY value_type real() const {return __re_;}
+    _LIBCPP_INLINE_VISIBILITY value_type imag() const {return __im_;}
+
+    _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
+    _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
+
+    _LIBCPP_INLINE_VISIBILITY complex& operator= (const value_type& __re) {__re_ = __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator+=(const value_type& __re) {__re_ += __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;}
+
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
+        {
+            __re_ = __c.real();
+            __im_ = __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
+        {
+            __re_ += __c.real();
+            __im_ += __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
+        {
+            __re_ -= __c.real();
+            __im_ -= __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
+        {
+            *this = *this * __c;
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
+        {
+            *this = *this / __c;
+            return *this;
+        }
+};
+
+template<> class complex<double>;
+template<> class complex<long double>;
+
+template<>
+class complex<float>
+{ 
+    float __re_;
+    float __im_;
+public: 
+    typedef float value_type; 
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(float __re = 0.0f, float __im = 0.0f)
+        : __re_(__re), __im_(__im) {}
+    explicit /*constexpr*/ complex(const complex<double>& __c);
+    explicit /*constexpr*/ complex(const complex<long double>& __c);
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float real() const {return __re_;}
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float imag() const {return __im_;}
+
+    _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
+    _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
+
+    _LIBCPP_INLINE_VISIBILITY complex& operator= (float __re) {__re_ = __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator+=(float __re) {__re_ += __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator-=(float __re) {__re_ -= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;}
+
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
+        {
+            __re_ = __c.real();
+            __im_ = __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
+        {
+            __re_ += __c.real();
+            __im_ += __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
+        {
+            __re_ -= __c.real();
+            __im_ -= __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
+        {
+            *this = *this * __c;
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
+        {
+            *this = *this / __c;
+            return *this;
+        }
+};
+
+template<>
+class complex<double>
+{ 
+    double __re_;
+    double __im_;
+public: 
+    typedef double value_type; 
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(double __re = 0.0, double __im = 0.0)
+        : __re_(__re), __im_(__im) {}
+    /*constexpr*/ complex(const complex<float>& __c);
+    explicit /*constexpr*/ complex(const complex<long double>& __c);
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double real() const {return __re_;}
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double imag() const {return __im_;}
+
+    _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
+    _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
+
+    _LIBCPP_INLINE_VISIBILITY complex& operator= (double __re) {__re_ = __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;}
+
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
+        {
+            __re_ = __c.real();
+            __im_ = __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
+        {
+            __re_ += __c.real();
+            __im_ += __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
+        {
+            __re_ -= __c.real();
+            __im_ -= __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
+        {
+            *this = *this * __c;
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
+        {
+            *this = *this / __c;
+            return *this;
+        }
+}; 
+
+template<>
+class complex<long double>
+{ 
+    long double __re_;
+    long double __im_;
+public: 
+    typedef long double value_type; 
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(long double __re = 0.0L, long double __im = 0.0L)
+        : __re_(__re), __im_(__im) {}
+    /*constexpr*/ complex(const complex<float>& __c);
+    /*constexpr*/ complex(const complex<double>& __c);
+
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double real() const {return __re_;}
+    /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double imag() const {return __im_;}
+
+    _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
+    _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
+
+    _LIBCPP_INLINE_VISIBILITY complex& operator= (long double __re) {__re_ = __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator+=(long double __re) {__re_ += __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator-=(long double __re) {__re_ -= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;}
+    _LIBCPP_INLINE_VISIBILITY complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;}
+
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
+        {
+            __re_ = __c.real();
+            __im_ = __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
+        {
+            __re_ += __c.real();
+            __im_ += __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
+        {
+            __re_ -= __c.real();
+            __im_ -= __c.imag();
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
+        {
+            *this = *this * __c;
+            return *this;
+        }
+    template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
+        {
+            *this = *this / __c;
+            return *this;
+        }
+};
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<float>::complex(const complex<double>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<float>::complex(const complex<long double>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<double>::complex(const complex<float>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<double>::complex(const complex<long double>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<long double>::complex(const complex<float>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+//constexpr
+inline _LIBCPP_INLINE_VISIBILITY
+complex<long double>::complex(const complex<double>& __c)
+    : __re_(__c.real()), __im_(__c.imag()) {}
+
+// 26.3.6 operators:
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(__x);
+    __t += __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator+(const complex<_Tp>& __x, const _Tp& __y)
+{
+    complex<_Tp> __t(__x);
+    __t += __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator+(const _Tp& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(__y);
+    __t += __x;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(__x);
+    __t -= __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator-(const complex<_Tp>& __x, const _Tp& __y)
+{
+    complex<_Tp> __t(__x);
+    __t -= __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator-(const _Tp& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(-__y);
+    __t += __x;
+    return __t;
+}
+
+template<class _Tp>
+complex<_Tp>
+operator*(const complex<_Tp>& __z, const complex<_Tp>& __w)
+{
+    _Tp __a = __z.real();
+    _Tp __b = __z.imag();
+    _Tp __c = __w.real();
+    _Tp __d = __w.imag();
+    _Tp __ac = __a * __c;
+    _Tp __bd = __b * __d;
+    _Tp __ad = __a * __d;
+    _Tp __bc = __b * __c;
+    _Tp __x = __ac - __bd;
+    _Tp __y = __ad + __bc;
+    if (isnan(__x) && isnan(__y))
+    {
+        bool __recalc = false;
+        if (isinf(__a) || isinf(__b))
+        {
+            __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a);
+            __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b);
+            if (isnan(__c))
+                __c = copysign(_Tp(0), __c);
+            if (isnan(__d))
+                __d = copysign(_Tp(0), __d);
+            __recalc = true;
+        }
+        if (isinf(__c) || isinf(__d))
+        {
+            __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c);
+            __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d);
+            if (isnan(__a))
+                __a = copysign(_Tp(0), __a);
+            if (isnan(__b))
+                __b = copysign(_Tp(0), __b);
+            __recalc = true;
+        }
+        if (!__recalc && (isinf(__ac) || isinf(__bd) ||
+                          isinf(__ad) || isinf(__bc)))
+        {
+            if (isnan(__a))
+                __a = copysign(_Tp(0), __a);
+            if (isnan(__b))
+                __b = copysign(_Tp(0), __b);
+            if (isnan(__c))
+                __c = copysign(_Tp(0), __c);
+            if (isnan(__d))
+                __d = copysign(_Tp(0), __d);
+            __recalc = true;
+        }
+        if (__recalc)
+        {
+            __x = _Tp(INFINITY) * (__a * __c - __b * __d);
+            __y = _Tp(INFINITY) * (__a * __d + __b * __c);
+        }
+    }
+    return complex<_Tp>(__x, __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator*(const complex<_Tp>& __x, const _Tp& __y)
+{
+    complex<_Tp> __t(__x);
+    __t *= __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator*(const _Tp& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(__y);
+    __t *= __x;
+    return __t;
+}
+
+template<class _Tp>
+complex<_Tp>
+operator/(const complex<_Tp>& __z, const complex<_Tp>& __w)
+{
+    int __ilogbw = 0;
+    _Tp __a = __z.real();
+    _Tp __b = __z.imag();
+    _Tp __c = __w.real();
+    _Tp __d = __w.imag();
+    _Tp __logbw = logb(fmax(fabs(__c), fabs(__d)));
+    if (isfinite(__logbw))
+    {
+        __ilogbw = static_cast<int>(__logbw);
+        __c = scalbn(__c, -__ilogbw);
+        __d = scalbn(__d, -__ilogbw);
+    }
+    _Tp __denom = __c * __c + __d * __d;
+    _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
+    _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
+    if (isnan(__x) && isnan(__y))
+    {
+        if ((__denom == _Tp(0)) && (!isnan(__a) || !isnan(__b)))
+        {
+            __x = copysign(_Tp(INFINITY), __c) * __a;
+            __y = copysign(_Tp(INFINITY), __c) * __b;
+        }
+        else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d))
+        {
+            __a = copysign(isinf(__a) ? _Tp(1) : _Tp(0), __a);
+            __b = copysign(isinf(__b) ? _Tp(1) : _Tp(0), __b);
+            __x = _Tp(INFINITY) * (__a * __c + __b * __d);
+            __y = _Tp(INFINITY) * (__b * __c - __a * __d);
+        }
+        else if (isinf(__logbw) && __logbw > _Tp(0) && isfinite(__a) && isfinite(__b))
+        {
+            __c = copysign(isinf(__c) ? _Tp(1) : _Tp(0), __c);
+            __d = copysign(isinf(__d) ? _Tp(1) : _Tp(0), __d);
+            __x = _Tp(0) * (__a * __c + __b * __d);
+            __y = _Tp(0) * (__b * __c - __a * __d);
+        }
+    }
+    return complex<_Tp>(__x, __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator/(const complex<_Tp>& __x, const _Tp& __y)
+{
+    return complex<_Tp>(__x.real() / __y, __x.imag() / __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator/(const _Tp& __x, const complex<_Tp>& __y)
+{
+    complex<_Tp> __t(__x);
+    __t /= __y;
+    return __t;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator+(const complex<_Tp>& __x)
+{
+    return __x;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+operator-(const complex<_Tp>& __x)
+{
+    return complex<_Tp>(-__x.real(), -__x.imag());
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
+{
+    return __x.real() == __y.real() && __x.imag() == __y.imag();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const complex<_Tp>& __x, const _Tp& __y)
+{
+    return __x.real() == __y && __x.imag() == 0;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const _Tp& __x, const complex<_Tp>& __y)
+{
+    return __x == __y.real() && 0 == __y.imag();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
+{
+    return !(__x == __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const complex<_Tp>& __x, const _Tp& __y)
+{
+    return !(__x == __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const _Tp& __x, const complex<_Tp>& __y)
+{
+    return !(__x == __y);
+}
+
+/*
+    Move to <istream>
+
+template<class T, class charT, class traits>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>&, complex<T>&);
+
+    Move to <ostream>
+
+template<class T, class charT, class traits>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>&, const complex<T>&);
+*/
+
+// 26.3.7 values:
+
+// real
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+real(const complex<_Tp>& __c)
+{
+    return __c.real();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+real(long double __re)
+{
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+real(double __re)
+{
+    return __re;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+real(_Tp  __re)
+{
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+real(float  __re)
+{
+    return __re;
+}
+
+// imag
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+imag(const complex<_Tp>& __c)
+{
+    return __c.imag();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+imag(long double __re)
+{
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+imag(double __re)
+{
+    return 0;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+imag(_Tp  __re)
+{
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+imag(float  __re)
+{
+    return 0;
+}
+
+// abs
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+abs(const complex<_Tp>& __c)
+{
+    return hypot(__c.real(), __c.imag());
+}
+
+// arg
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+arg(const complex<_Tp>& __c)
+{
+    return atan2(__c.imag(), __c.real());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+arg(long double __re)
+{
+    return atan2l(0.L, __re);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+arg(double __re)
+{
+    return atan2(0., __re);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+arg(_Tp __re)
+{
+    return atan2(0., __re);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+arg(float __re)
+{
+    return atan2f(0.F, __re);
+}
+
+// norm
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+norm(const complex<_Tp>& __c)
+{
+    if (isinf(__c.real()))
+        return abs(__c.real());
+    if (isinf(__c.imag()))
+        return abs(__c.imag());
+    return __c.real() * __c.real() + __c.imag() * __c.imag();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+norm(long double __re)
+{
+    return __re * __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+norm(double __re)
+{
+    return __re * __re;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+norm(_Tp __re)
+{
+    return (double)__re * __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+norm(float __re)
+{
+    return __re * __re;
+}
+
+// conj
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+conj(const complex<_Tp>& __c)
+{
+    return complex<_Tp>(__c.real(), -__c.imag());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+conj(long double __re)
+{
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+conj(double __re)
+{
+    return __re;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+conj(_Tp __re)
+{
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+conj(float __re)
+{
+    return __re;
+}
+
+// proj
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+proj(const complex<_Tp>& __c)
+{
+    std::complex<_Tp> __r = __c;
+    if (isinf(__c.real()) || isinf(__c.imag()))
+        __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag()));
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+long double
+proj(long double __re)
+{
+    if (isinf(__re))
+        __re = abs(__re);
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+double
+proj(double __re)
+{
+    if (isinf(__re))
+        __re = abs(__re);
+    return __re;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_integral<_Tp>::value,
+    double
+>::type
+proj(_Tp __re)
+{
+    return __re;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+float
+proj(float __re)
+{
+    if (isinf(__re))
+        __re = abs(__re);
+    return __re;
+}
+
+// polar
+
+template<class _Tp>
+complex<_Tp>
+polar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
+{
+    if (isnan(__rho) || signbit(__rho))
+        return complex<_Tp>(_Tp(NAN), _Tp(NAN));
+    if (isnan(__theta))
+    {
+        if (isinf(__rho))
+            return complex<_Tp>(__rho, __theta);
+        return complex<_Tp>(__theta, __theta);
+    }
+    if (isinf(__theta))
+    {
+        if (isinf(__rho))
+            return complex<_Tp>(__rho, _Tp(NAN));
+        return complex<_Tp>(_Tp(NAN), _Tp(NAN));
+    }
+    _Tp __x = __rho * cos(__theta);
+    if (isnan(__x))
+        __x = 0;
+    _Tp __y = __rho * sin(__theta);
+    if (isnan(__y))
+        __y = 0;
+    return complex<_Tp>(__x, __y);
+}
+
+// log
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+log(const complex<_Tp>& __x)
+{
+    return complex<_Tp>(log(abs(__x)), arg(__x));
+}
+
+// log10
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+log10(const complex<_Tp>& __x)
+{
+    return log(__x) / log(_Tp(10));
+}
+
+// sqrt
+
+template<class _Tp>
+complex<_Tp>
+sqrt(const complex<_Tp>& __x)
+{
+    if (isinf(__x.imag()))
+        return complex<_Tp>(_Tp(INFINITY), __x.imag());
+    if (isinf(__x.real()))
+    {
+        if (__x.real() > _Tp(0))
+            return complex<_Tp>(__x.real(), isnan(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag()));
+        return complex<_Tp>(isnan(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag()));
+    }
+    return polar(sqrt(abs(__x)), arg(__x) / _Tp(2));
+}
+
+// exp
+
+template<class _Tp>
+complex<_Tp>
+exp(const complex<_Tp>& __x)
+{
+    _Tp __i = __x.imag();
+    if (isinf(__x.real()))
+    {
+        if (__x.real() < _Tp(0))
+        {
+            if (!isfinite(__i))
+                __i = _Tp(1);
+        }
+        else if (__i == 0 || !isfinite(__i))
+        {
+            if (isinf(__i))
+                __i = _Tp(NAN);
+            return complex<_Tp>(__x.real(), __i);
+        }
+    }
+    else if (isnan(__x.real()) && __x.imag() == 0)
+        return __x;
+    _Tp __e = exp(__x.real());
+    return complex<_Tp>(__e * cos(__i), __e * sin(__i));
+}
+
+// pow
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
+{
+    return exp(__y * log(__x));
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<typename __promote<_Tp, _Up>::type>
+pow(const complex<_Tp>& __x, const complex<_Up>& __y)
+{
+    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
+    return _STD::pow(result_type(__x), result_type(__y));
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_Up>::value,
+    complex<typename __promote<_Tp, _Up>::type>
+>::type
+pow(const complex<_Tp>& __x, const _Up& __y)
+{
+    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
+    return _STD::pow(result_type(__x), result_type(__y));
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    is_arithmetic<_Tp>::value,
+    complex<typename __promote<_Tp, _Up>::type>
+>::type
+pow(const _Tp& __x, const complex<_Up>& __y)
+{
+    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
+    return _STD::pow(result_type(__x), result_type(__y));
+}
+
+// asinh
+
+template<class _Tp>
+complex<_Tp>
+asinh(const complex<_Tp>& __x)
+{
+    const _Tp __pi(atan2(+0., -0.));
+    if (isinf(__x.real()))
+    {
+        if (isnan(__x.imag()))
+            return __x;
+        if (isinf(__x.imag()))
+            return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag()));
+        return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
+    }
+    if (isnan(__x.real()))
+    {
+        if (isinf(__x.imag()))
+            return complex<_Tp>(__x.imag(), __x.real());
+        if (__x.imag() == 0)
+            return __x;
+        return complex<_Tp>(__x.real(), __x.real());
+    }
+    if (isinf(__x.imag()))
+        return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
+    complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) + _Tp(1)));
+    return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag()));
+}
+
+// acosh
+
+template<class _Tp>
+complex<_Tp>
+acosh(const complex<_Tp>& __x)
+{
+    const _Tp __pi(atan2(+0., -0.));
+    if (isinf(__x.real()))
+    {
+        if (isnan(__x.imag()))
+            return complex<_Tp>(abs(__x.real()), __x.imag());
+        if (isinf(__x.imag()))
+            if (__x.real() > 0)
+                return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag()));
+            else
+                return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag()));
+        if (__x.real() < 0)
+            return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag()));
+        return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
+    }
+    if (isnan(__x.real()))
+    {
+        if (isinf(__x.imag()))
+            return complex<_Tp>(abs(__x.imag()), __x.real());
+        return complex<_Tp>(__x.real(), __x.real());
+    }
+    if (isinf(__x.imag()))
+        return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag()));
+    complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1)));
+    return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag()));
+}
+
+// atanh
+
+template<class _Tp>
+complex<_Tp>
+atanh(const complex<_Tp>& __x)
+{
+    const _Tp __pi(atan2(+0., -0.));
+    if (isinf(__x.imag()))
+    {
+        return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
+    }
+    if (isnan(__x.imag()))
+    {
+        if (isinf(__x.real()) || __x.real() == 0)
+            return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag());
+        return complex<_Tp>(__x.imag(), __x.imag());
+    }
+    if (isnan(__x.real()))
+    {
+        return complex<_Tp>(__x.real(), __x.real());
+    }
+    if (isinf(__x.real()))
+    {
+        return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
+    }
+    if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0))
+    {
+        return complex<_Tp>(copysign(_Tp(INFINITY), __x.real()), copysign(_Tp(0), __x.imag()));
+    }
+    complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2);
+    return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag()));
+}
+
+// sinh
+
+template<class _Tp>
+complex<_Tp>
+sinh(const complex<_Tp>& __x)
+{
+    if (isinf(__x.real()) && !isfinite(__x.imag()))
+        return complex<_Tp>(__x.real(), _Tp(NAN));
+    if (__x.real() == 0 && !isfinite(__x.imag()))
+        return complex<_Tp>(__x.real(), _Tp(NAN));
+    if (__x.imag() == 0 && !isfinite(__x.real()))
+        return __x;
+    return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag()));
+}
+
+// cosh
+
+template<class _Tp>
+complex<_Tp>
+cosh(const complex<_Tp>& __x)
+{
+    if (isinf(__x.real()) && !isfinite(__x.imag()))
+        return complex<_Tp>(abs(__x.real()), _Tp(NAN));
+    if (__x.real() == 0 && !isfinite(__x.imag()))
+        return complex<_Tp>(_Tp(NAN), __x.real());
+    if (__x.real() == 0 && __x.imag() == 0)
+        return complex<_Tp>(_Tp(1), __x.imag());
+    if (__x.imag() == 0 && !isfinite(__x.real()))
+        return complex<_Tp>(abs(__x.real()), __x.imag());
+    return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag()));
+}
+
+// tanh
+
+template<class _Tp>
+complex<_Tp>
+tanh(const complex<_Tp>& __x)
+{
+    if (isinf(__x.real()))
+    {
+        if (!isfinite(__x.imag()))
+            return complex<_Tp>(_Tp(1), _Tp(0));
+        return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
+    }
+    if (isnan(__x.real()) && __x.imag() == 0)
+        return __x;
+    _Tp __2r(_Tp(2) * __x.real());
+    _Tp __2i(_Tp(2) * __x.imag());
+    _Tp __d(cosh(__2r) + cos(__2i));
+    return  complex<_Tp>(sinh(__2r)/__d, sin(__2i)/__d);
+}
+
+// asin
+
+template<class _Tp>
+complex<_Tp>
+asin(const complex<_Tp>& __x)
+{
+    complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real()));
+    return complex<_Tp>(__z.imag(), -__z.real());
+}
+
+// acos
+
+template<class _Tp>
+complex<_Tp>
+acos(const complex<_Tp>& __x)
+{
+    const _Tp __pi(atan2(+0., -0.));
+    if (isinf(__x.real()))
+    {
+        if (isnan(__x.imag()))
+            return complex<_Tp>(__x.imag(), __x.real());
+        if (isinf(__x.imag()))
+        {
+            if (__x.real() < _Tp(0))
+                return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag());
+            return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag());
+        }
+        if (__x.real() < _Tp(0))
+            return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real());
+        return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real());
+    }
+    if (isnan(__x.real()))
+    {
+        if (isinf(__x.imag()))
+            return complex<_Tp>(__x.real(), -__x.imag());
+        return complex<_Tp>(__x.real(), __x.real());
+    }
+    if (isinf(__x.imag()))
+        return complex<_Tp>(__pi/_Tp(2), -__x.imag());
+    if (__x.real() == 0)
+        return complex<_Tp>(__pi/_Tp(2), -__x.imag());
+    complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1)));
+    if (signbit(__x.imag()))
+        return complex<_Tp>(abs(__z.imag()), abs(__z.real()));
+    return complex<_Tp>(abs(__z.imag()), -abs(__z.real()));
+}
+
+// atan
+
+template<class _Tp>
+complex<_Tp>
+atan(const complex<_Tp>& __x)
+{
+    complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real()));
+    return complex<_Tp>(__z.imag(), -__z.real());
+}
+
+// sin
+
+template<class _Tp>
+complex<_Tp>
+sin(const complex<_Tp>& __x)
+{
+    complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real()));
+    return complex<_Tp>(__z.imag(), -__z.real());
+}
+
+// cos
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+complex<_Tp>
+cos(const complex<_Tp>& __x)
+{
+    return cosh(complex<_Tp>(-__x.imag(), __x.real()));
+}
+
+// tan
+
+template<class _Tp>
+complex<_Tp>
+tan(const complex<_Tp>& __x)
+{
+    complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real()));
+    return complex<_Tp>(__z.imag(), -__z.real());
+}
+
+template<class _Tp, class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
+{
+    if (__is.good())
+    {
+        ws(__is);
+        if (__is.peek() == _CharT('('))
+        {
+            __is.get();
+            _Tp __r;
+            __is >> __r;
+            if (!__is.fail())
+            {
+                ws(__is);
+                _CharT __c = __is.peek();
+                if (__c == _CharT(','))
+                {
+                    __is.get();
+                    _Tp __i;
+                    __is >> __i;
+                    if (!__is.fail())
+                    {
+                        ws(__is);
+                        __c = __is.peek();
+                        if (__c == _CharT(')'))
+                        {
+                            __is.get();
+                            __x = complex<_Tp>(__r, __i);
+                        }
+                        else
+                            __is.setstate(ios_base::failbit);
+                    }
+                    else
+                        __is.setstate(ios_base::failbit);
+                }
+                else if (__c == _CharT(')'))
+                {
+                    __is.get();
+                    __x = complex<_Tp>(__r, _Tp(0));
+                }
+                else
+                    __is.setstate(ios_base::failbit);
+            }
+            else
+                __is.setstate(ios_base::failbit);
+        }
+        else
+        {
+            _Tp __r;
+            __is >> __r;
+            if (!__is.fail())
+                __x = complex<_Tp>(__r, _Tp(0));
+            else
+                __is.setstate(ios_base::failbit);
+        }
+    }
+    else
+        __is.setstate(ios_base::failbit);
+    return __is;
+}
+
+template<class _Tp, class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
+{
+    basic_ostringstream<_CharT, _Traits> __s;
+    __s.flags(__os.flags());
+    __s.imbue(__os.getloc());
+    __s.precision(__os.precision());
+    __s << '(' << __x.real() << ',' << __x.imag() << ')';
+    return __os << __s.str();
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_COMPLEX
diff --git a/include/complex.h b/include/complex.h
new file mode 100644
index 0000000..cca9af7
--- /dev/null
+++ b/include/complex.h
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+//===--------------------------- complex.h --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_COMPLEX_H
+#define _LIBCPP_COMPLEX_H
+
+/*
+    complex.h synopsis
+
+#include <ccomplex>
+
+*/
+
+#include <ccomplex>
+
+#pragma GCC system_header
+
+#endif  // _LIBCPP_COMPLEX_H
diff --git a/include/condition_variable b/include/condition_variable
new file mode 100644
index 0000000..5154952
--- /dev/null
+++ b/include/condition_variable
@@ -0,0 +1,249 @@
+// -*- C++ -*-
+//===---------------------- condition_variable ----------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CONDITION_VARIABLE
+#define _LIBCPP_CONDITION_VARIABLE
+
+/*
+    condition_variable synopsis
+
+namespace std
+{
+
+enum class cv_status { no_timeout, timeout };
+
+class condition_variable
+{
+public:
+    condition_variable();
+    ~condition_variable();
+
+    condition_variable(const condition_variable&) = delete;
+    condition_variable& operator=(const condition_variable&) = delete;
+
+    void notify_one();
+    void notify_all();
+
+    void wait(unique_lock<mutex>& lock);
+    template <class Predicate>
+        void wait(unique_lock<mutex>& lock, Predicate pred);
+
+    template <class Clock, class Duration>
+        cv_status
+        wait_until(unique_lock<mutex>& lock,
+                   const chrono::time_point<Clock, Duration>& abs_time);
+
+    template <class Clock, class Duration, class Predicate>
+        bool
+        wait_until(unique_lock<mutex>& lock,
+                   const chrono::time_point<Clock, Duration>& abs_time,
+                   Predicate pred);
+
+    template <class Rep, class Period>
+        cv_status
+        wait_for(unique_lock<mutex>& lock,
+                 const chrono::duration<Rep, Period>& rel_time);
+
+    template <class Rep, class Period, class Predicate>
+        bool
+        wait_for(unique_lock<mutex>& lock,
+                 const chrono::duration<Rep, Period>& rel_time,
+                 Predicate pred);
+
+    typedef pthread_cond_t* native_handle_type;
+    native_handle_type native_handle();
+};
+
+class condition_variable_any
+{
+public:
+    condition_variable_any();
+    ~condition_variable_any();
+
+    condition_variable_any(const condition_variable_any&) = delete;
+    condition_variable_any& operator=(const condition_variable_any&) = delete;
+
+    void notify_one();
+    void notify_all();
+
+    template <class Lock>
+        void wait(Lock& lock);
+    template <class Lock, class Predicate>
+        void wait(Lock& lock, Predicate pred);
+
+    template <class Lock, class Clock, class Duration>
+        cv_status
+        wait_until(Lock& lock,
+                   const chrono::time_point<Clock, Duration>& abs_time);
+
+    template <class Lock, class Clock, class Duration, class Predicate>
+        bool
+        wait_until(Lock& lock,
+                   const chrono::time_point<Clock, Duration>& abs_time,
+                   Predicate pred);
+
+    template <class Lock, class Rep, class Period>
+        cv_status
+        wait_for(Lock& lock,
+                 const chrono::duration<Rep, Period>& rel_time);
+
+    template <class Lock, class Rep, class Period, class Predicate>
+        bool
+        wait_for(Lock& lock,
+                 const chrono::duration<Rep, Period>& rel_time,
+                 Predicate pred);
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__mutex_base>
+#include <memory>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class condition_variable_any
+{
+    condition_variable __cv_;
+    shared_ptr<mutex>  __mut_;
+public:
+    condition_variable_any();
+
+    void notify_one();
+    void notify_all();
+
+    template <class _Lock>
+        void wait(_Lock& __lock);
+    template <class _Lock, class _Predicate>
+        void wait(_Lock& __lock, _Predicate __pred);
+
+    template <class _Lock, class _Clock, class _Duration>
+        cv_status
+        wait_until(_Lock& __lock,
+                   const chrono::time_point<_Clock, _Duration>& __t);
+
+    template <class _Lock, class _Clock, class _Duration, class _Predicate>
+        bool
+        wait_until(_Lock& __lock,
+                   const chrono::time_point<_Clock, _Duration>& __t,
+                   _Predicate __pred);
+
+    template <class _Lock, class _Rep, class _Period>
+        cv_status
+        wait_for(_Lock& __lock,
+                 const chrono::duration<_Rep, _Period>& __d);
+
+    template <class _Lock, class _Rep, class _Period, class _Predicate>
+        bool
+        wait_for(_Lock& __lock,
+                 const chrono::duration<_Rep, _Period>& __d,
+                 _Predicate __pred);
+};
+
+inline
+condition_variable_any::condition_variable_any()
+    : __mut_(make_shared<mutex>()) {}
+
+inline
+void
+condition_variable_any::notify_one()
+{
+    {lock_guard<mutex> _(*__mut_);}
+    __cv_.notify_one();
+}
+
+inline
+void
+condition_variable_any::notify_all()
+{
+    {lock_guard<mutex> _(*__mut_);}
+    __cv_.notify_all();
+}
+
+struct __lock_external
+{
+    template <class _Lock>
+    void operator()(_Lock* __m) {__m->lock();}
+};
+
+template <class _Lock>
+void
+condition_variable_any::wait(_Lock& __lock)
+{
+    shared_ptr<mutex> __mut = __mut_;
+    unique_lock<mutex> __lk(*__mut);
+    __lock.unlock();
+    unique_ptr<_Lock, __lock_external> __(&__lock);
+    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
+    __cv_.wait(__lk);
+}  // __mut_.unlock(), __lock.lock()
+
+template <class _Lock, class _Predicate>
+inline
+void
+condition_variable_any::wait(_Lock& __lock, _Predicate __pred)
+{
+    while (!__pred())
+        wait(__lock);
+}
+
+template <class _Lock, class _Clock, class _Duration>
+cv_status
+condition_variable_any::wait_until(_Lock& __lock,
+                                   const chrono::time_point<_Clock, _Duration>& __t)
+{
+    shared_ptr<mutex> __mut = __mut_;
+    unique_lock<mutex> __lk(*__mut);
+    __lock.unlock();
+    unique_ptr<_Lock, __lock_external> __(&__lock);
+    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
+    return __cv_.wait_until(__lk, __t);
+}  // __mut_.unlock(), __lock.lock()
+
+template <class _Lock, class _Clock, class _Duration, class _Predicate>
+inline
+bool
+condition_variable_any::wait_until(_Lock& __lock,
+                                   const chrono::time_point<_Clock, _Duration>& __t,
+                                   _Predicate __pred)
+{
+    while (!__pred())
+        if (wait_until(__lock, __t) == cv_status::timeout)
+            return __pred();
+    return true;
+}
+
+template <class _Lock, class _Rep, class _Period>
+inline
+cv_status
+condition_variable_any::wait_for(_Lock& __lock,
+                                 const chrono::duration<_Rep, _Period>& __d)
+{
+    return wait_until(__lock, chrono::monotonic_clock::now() + __d);
+}
+
+template <class _Lock, class _Rep, class _Period, class _Predicate>
+inline
+bool
+condition_variable_any::wait_for(_Lock& __lock,
+                                 const chrono::duration<_Rep, _Period>& __d,
+                                 _Predicate __pred)
+{
+    return wait_until(__lock, chrono::monotonic_clock::now() + __d,
+                      _STD::move(__pred));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CONDITION_VARIABLE
diff --git a/include/csetjmp b/include/csetjmp
new file mode 100644
index 0000000..7ab2bd2
--- /dev/null
+++ b/include/csetjmp
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+//===--------------------------- csetjmp ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSETJMP
+#define _LIBCPP_CSETJMP
+
+/*
+    csetjmp synopsis
+
+Macros:
+
+    setjmp
+
+namespace std
+{
+
+Types:
+
+    jmp_buf
+
+void longjmp(jmp_buf env, int val);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <setjmp.h>
+
+#pragma GCC system_header
+
+#ifndef setjmp
+#define setjmp(env) setjmp(env)
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::jmp_buf;
+using ::longjmp;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSETJMP
diff --git a/include/csignal b/include/csignal
new file mode 100644
index 0000000..f73f167
--- /dev/null
+++ b/include/csignal
@@ -0,0 +1,56 @@
+// -*- C++ -*-
+//===--------------------------- csignal ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSIGNAL
+#define _LIBCPP_CSIGNAL
+
+/*
+    csignal synopsis
+
+Macros:
+
+    SIG_DFL
+    SIG_ERR
+    SIG_IGN
+    SIGABRT
+    SIGFPE
+    SIGILL
+    SIGINT
+    SIGSEGV
+    SIGTERM
+ 
+namespace std
+{
+
+Types:
+
+    sig_atomic_t
+
+void (*signal(int sig, void (*func)(int)))(int);
+int raise(int sig);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <signal.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::sig_atomic_t;
+using ::signal;
+using ::raise;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSIGNAL
diff --git a/include/cstdarg b/include/cstdarg
new file mode 100644
index 0000000..26f1d29
--- /dev/null
+++ b/include/cstdarg
@@ -0,0 +1,46 @@
+// -*- C++ -*-
+//===--------------------------- cstdarg ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDARG
+#define _LIBCPP_CSTDARG
+
+/*
+    cstdarg synopsis
+
+Macros:
+
+    type va_arg(va_list ap, type);
+    void va_copy(va_list dest, va_list src);  // C99
+    void va_end(va_list ap);
+    void va_start(va_list ap, parmN);
+ 
+namespace std
+{
+
+Types:
+
+    va_list
+
+}  // std
+
+*/
+
+#include <__config>
+#include <stdarg.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::va_list;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTDARG
diff --git a/include/cstdbool b/include/cstdbool
new file mode 100644
index 0000000..9652b79
--- /dev/null
+++ b/include/cstdbool
@@ -0,0 +1,30 @@
+// -*- C++ -*-
+//===--------------------------- cstdbool ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDBOOL
+#define _LIBCPP_CSTDBOOL
+
+/*
+    cstdbool synopsis
+
+Macros:
+
+    __bool_true_false_are_defined
+
+*/
+
+#include <__config>
+
+#pragma GCC system_header
+
+#undef __bool_true_false_are_defined
+#define __bool_true_false_are_defined 1
+
+#endif  // _LIBCPP_CSTDBOOL
diff --git a/include/cstddef b/include/cstddef
new file mode 100644
index 0000000..6b0a1c7
--- /dev/null
+++ b/include/cstddef
@@ -0,0 +1,88 @@
+// -*- C++ -*-
+//===--------------------------- cstddef ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDDEF
+#define _LIBCPP_CSTDDEF
+
+/*
+    cstddef synopsis
+
+Macros:
+
+    offsetof(type,member-designator)
+    NULL
+ 
+namespace std
+{
+
+Types:
+
+    ptrdiff_t
+    size_t
+    max_align_t
+    nullptr_t
+
+}  // std
+
+*/
+
+#include <__config>
+#include <stddef.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::ptrdiff_t;
+using ::size_t;
+
+typedef long double max_align_t;
+
+#ifdef _LIBCPP_HAS_NO_NULLPTR
+
+struct nullptr_t
+{
+    void* _;
+
+    struct __nat {int __for_bool_;};
+
+    _LIBCPP_ALWAYS_INLINE nullptr_t(int __nat::*) {}
+
+    _LIBCPP_ALWAYS_INLINE operator int __nat::*() const {return 0;}
+
+    template <class T>
+        _LIBCPP_ALWAYS_INLINE 
+        operator T* () const {return 0;}
+
+    template <class T, class U>
+        _LIBCPP_ALWAYS_INLINE 
+        operator T U::* () const {return 0;}
+
+    friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE bool operator<(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE bool operator<=(nullptr_t, nullptr_t) {return true;}
+    friend _LIBCPP_ALWAYS_INLINE bool operator>(nullptr_t, nullptr_t) {return false;}
+    friend _LIBCPP_ALWAYS_INLINE bool operator>=(nullptr_t, nullptr_t) {return true;}
+};
+
+inline _LIBCPP_ALWAYS_INLINE nullptr_t __get_nullptr_t() {return nullptr_t(0);}
+
+#define nullptr _STD::__get_nullptr_t()
+
+#else
+
+typedef decltype(nullptr) nullptr_t;
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTDDEF
diff --git a/include/cstdint b/include/cstdint
new file mode 100644
index 0000000..d8f8a19
--- /dev/null
+++ b/include/cstdint
@@ -0,0 +1,189 @@
+// -*- C++ -*-
+//===--------------------------- cstdint ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDINT
+#define _LIBCPP_CSTDINT
+
+/*
+    cstdint synopsis
+
+Macros:
+
+    INT8_MIN
+    INT16_MIN
+    INT32_MIN
+    INT64_MIN
+
+    INT8_MAX
+    INT16_MAX
+    INT32_MAX
+    INT64_MAX
+
+    UINT8_MAX
+    UINT16_MAX
+    UINT32_MAX
+    UINT64_MAX
+
+    INT_LEAST8_MIN
+    INT_LEAST16_MIN
+    INT_LEAST32_MIN
+    INT_LEAST64_MIN
+
+    INT_LEAST8_MAX
+    INT_LEAST16_MAX
+    INT_LEAST32_MAX
+    INT_LEAST64_MAX
+
+    UINT_LEAST8_MAX
+    UINT_LEAST16_MAX
+    UINT_LEAST32_MAX
+    UINT_LEAST64_MAX
+
+    INT_FAST8_MIN
+    INT_FAST16_MIN
+    INT_FAST32_MIN
+    INT_FAST64_MIN
+
+    INT_FAST8_MAX
+    INT_FAST16_MAX
+    INT_FAST32_MAX
+    INT_FAST64_MAX
+
+    UINT_FAST8_MAX
+    UINT_FAST16_MAX
+    UINT_FAST32_MAX
+    UINT_FAST64_MAX
+
+    INTPTR_MIN
+    INTPTR_MAX
+    UINTPTR_MAX
+
+    INTMAX_MIN
+    INTMAX_MAX
+
+    UINTMAX_MAX
+
+    PTRDIFF_MIN
+    PTRDIFF_MAX
+
+    SIG_ATOMIC_MIN
+    SIG_ATOMIC_MAX
+
+    SIZE_MAX
+
+    WCHAR_MIN
+    WCHAR_MAX
+
+    WINT_MIN
+    WINT_MAX
+
+    INT8_C(value)
+    INT16_C(value)
+    INT32_C(value)
+    INT64_C(value)
+
+    UINT8_C(value)
+    UINT16_C(value)
+    UINT32_C(value)
+    UINT64_C(value)
+
+    INTMAX_C(value)
+    UINTMAX_C(value)
+
+namespace std
+{
+
+Types:
+
+    int8_t
+    int16_t
+    int32_t
+    int64_t
+
+    uint8_t
+    uint16_t
+    uint32_t
+    uint64_t
+
+    int_least8_t
+    int_least16_t
+    int_least32_t
+    int_least64_t
+
+    uint_least8_t
+    uint_least16_t
+    uint_least32_t
+    uint_least64_t
+
+    int_fast8_t
+    int_fast16_t
+    int_fast32_t
+    int_fast64_t
+
+    uint_fast8_t
+    uint_fast16_t
+    uint_fast32_t
+    uint_fast64_t
+
+    intptr_t
+    uintptr_t
+
+    intmax_t
+    uintmax_t
+
+}  // std
+*/
+
+#include <__config>
+#include <stdint.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using::int8_t;
+using::int16_t;
+using::int32_t;
+using::int64_t;
+
+using::uint8_t;
+using::uint16_t;
+using::uint32_t;
+using::uint64_t;
+
+using::int_least8_t;
+using::int_least16_t;
+using::int_least32_t;
+using::int_least64_t;
+
+using::uint_least8_t;
+using::uint_least16_t;
+using::uint_least32_t;
+using::uint_least64_t;
+
+using::int_fast8_t;
+using::int_fast16_t;
+using::int_fast32_t;
+using::int_fast64_t;
+
+using::uint_fast8_t;
+using::uint_fast16_t;
+using::uint_fast32_t;
+using::uint_fast64_t;
+
+using::intptr_t;
+using::uintptr_t;
+
+using::intmax_t;
+using::uintmax_t;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTDINT
diff --git a/include/cstdio b/include/cstdio
new file mode 100644
index 0000000..17b97cb
--- /dev/null
+++ b/include/cstdio
@@ -0,0 +1,159 @@
+// -*- C++ -*-
+//===---------------------------- cstdio ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDIO
+#define _LIBCPP_CSTDIO
+
+/*
+    cstdio synopsis
+
+Macros:
+
+    BUFSIZ
+    EOF
+    FILENAME_MAX
+    FOPEN_MAX
+    L_tmpnam
+    NULL
+    SEEK_CUR
+    SEEK_END
+    SEEK_SET
+    TMP_MAX
+    _IOFBF
+    _IOLBF
+    _IONBF
+    stderr
+    stdin
+    stdout
+
+namespace std
+{
+
+Types:
+
+FILE
+fpos_t
+size_t
+
+int remove(const char* filename);
+int rename(const char* old, const char* new);
+FILE* tmpfile(void);
+char* tmpnam(char* s);
+int fclose(FILE* stream);
+int fflush(FILE* stream);
+FILE* fopen(const char* restrict filename, const char* restrict mode);
+FILE* freopen(const char* restrict filename, const char * restrict mode,
+              FILE * restrict stream);
+void setbuf(FILE* restrict stream, char* restrict buf);
+int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size);
+int fprintf(FILE* restrict stream, const char* restrict format, ...);
+int fscanf(FILE* restrict stream, const char * restrict format, ...);
+int printf(const char* restrict format, ...);
+int scanf(const char* restrict format, ...);
+int snprintf(char* restrict s, size_t n, const char* restrict format, ...);    // C99
+int sprintf(char* restrict s, const char* restrict format, ...);
+int sscanf(const char* restrict s, const char* restrict format, ...);
+int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg);
+int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg);  // C99
+int vprintf(const char* restrict format, va_list arg);
+int vscanf(const char* restrict format, va_list arg);                          // C99
+int vsnprintf(char* restrict s, size_t n, const char* restrict format,         // C99
+              va_list arg);
+int vsprintf(char* restrict s, const char* restrict format, va_list arg);
+int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99
+int fgetc(FILE* stream);
+char* fgets(char* restrict s, int n, FILE* restrict stream);
+int fputc(int c, FILE* stream);
+int fputs(const char* restrict s, FILE* restrict stream);
+int getc(FILE* stream);
+int getchar(void);
+char* gets(char* s);
+int putc(int c, FILE* stream);
+int putchar(int c);
+int puts(const char* s);
+int ungetc(int c, FILE* stream);
+size_t fread(void* restrict ptr, size_t size, size_t nmemb,
+             FILE* restrict stream);
+size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb,
+              FILE* restrict stream);
+int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
+int fseek(FILE* stream, long offset, int whence);
+int fsetpos(FILE*stream, const fpos_t* pos);
+long ftell(FILE* stream);
+void rewind(FILE* stream);
+void clearerr(FILE* stream);
+int feof(FILE* stream);
+int ferror(FILE* stream);
+void perror(const char* s);
+
+}  // std
+*/
+
+#include <__config>
+#include <stdio.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::FILE;
+using ::fpos_t;
+using ::size_t;
+
+using ::remove;
+using ::rename;
+using ::tmpfile;
+using ::tmpnam;
+using ::fclose;
+using ::fflush;
+using ::fopen;
+using ::freopen;
+using ::setbuf;
+using ::setvbuf;
+using ::fprintf;
+using ::fscanf;
+using ::printf;
+using ::scanf;
+using ::snprintf;
+using ::sprintf;
+using ::sscanf;
+using ::vfprintf;
+using ::vfscanf;
+using ::vprintf;
+using ::vscanf;
+using ::vsnprintf;
+using ::vsprintf;
+using ::vsscanf;
+using ::fgetc;
+using ::fgets;
+using ::fputc;
+using ::fputs;
+using ::getc;
+using ::getchar;
+using ::gets;
+using ::putc;
+using ::putchar;
+using ::puts;
+using ::ungetc;
+using ::fread;
+using ::fwrite;
+using ::fgetpos;
+using ::fseek;
+using ::fsetpos;
+using ::ftell;
+using ::rewind;
+using ::clearerr;
+using ::feof;
+using ::ferror;
+using ::perror;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTDIO
diff --git a/include/cstdlib b/include/cstdlib
new file mode 100644
index 0000000..15d4dc9
--- /dev/null
+++ b/include/cstdlib
@@ -0,0 +1,138 @@
+// -*- C++ -*-
+//===--------------------------- cstdlib ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDLIB
+#define _LIBCPP_CSTDLIB
+
+/*
+    cstdlib synopsis
+
+Macros:
+
+    EXIT_FAILURE
+    EXIT_SUCCESS
+    MB_CUR_MAX
+    NULL
+    RAND_MAX
+ 
+namespace std
+{
+
+Types:
+
+    size_t
+    div_t
+    ldiv_t
+    lldiv_t                                                               // C99
+
+double    atof (const char* nptr);
+int       atoi (const char* nptr);
+long      atol (const char* nptr);
+long long atoll(const char* nptr);                                        // C99
+double             strtod  (const char* restrict nptr, char** restrict endptr);
+float              strtof  (const char* restrict nptr, char** restrict endptr); // C99
+long double        strtold (const char* restrict nptr, char** restrict endptr); // C99
+long               strtol  (const char* restrict nptr, char** restrict endptr, int base);
+long long          strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
+unsigned long      strtoul (const char* restrict nptr, char** restrict endptr, int base);
+unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
+int rand(void);
+void srand(unsigned int seed);
+void* calloc(size_t nmemb, size_t size);
+void free(void* ptr);
+void* malloc(size_t size);
+void* realloc(void* ptr, size_t size);
+void abort(void);
+int atexit(void (*func)(void));
+void exit(int status);
+void _Exit(int status);
+char* getenv(const char* name);
+int system(const char* string);
+void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
+              int (*compar)(const void *, const void *));
+void qsort(void* base, size_t nmemb, size_t size,
+           int (*compar)(const void *, const void *));
+int         abs(      int j);
+long        abs(     long j);
+long long   abs(long long j);                                             // C++0X
+long       labs(     long j);
+long long llabs(long long j);                                             // C99
+div_t     div(      int numer,       int denom);
+ldiv_t    div(     long numer,      long denom);
+lldiv_t   div(long long numer, long long denom);                          // C++0X              
+ldiv_t   ldiv(     long numer,      long denom);
+lldiv_t lldiv(long long numer, long long denom);                          // C99
+int mblen(const char* s, size_t n);
+int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
+int wctomb(char* s, wchar_t wchar);
+size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
+size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <stdlib.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::size_t;
+using ::div_t;
+using ::ldiv_t;
+using ::lldiv_t;
+using ::atof;
+using ::atoi;
+using ::atol;
+using ::atoll;
+using ::strtod;
+using ::strtof;
+using ::strtold;
+using ::strtol;
+using ::strtoll;
+using ::strtoul;
+using ::strtoull;
+using ::rand;
+using ::srand;
+using ::calloc;
+using ::free;
+using ::malloc;
+using ::realloc;
+using ::abort;
+using ::atexit;
+using ::exit;
+using ::_Exit;
+using ::getenv;
+using ::system;
+using ::bsearch;
+using ::qsort;
+using ::abs;
+using ::labs;
+using ::llabs;
+using ::div;
+using ::ldiv;
+using ::lldiv;
+using ::mblen;
+using ::mbtowc;
+using ::wctomb;
+using ::mbstowcs;
+using ::wcstombs;
+
+inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) {return  labs(__x);}
+inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) {return llabs(__x);}
+
+inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) {return  ldiv(__x, __y);}
+inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) {return lldiv(__x, __y);}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTDLIB
diff --git a/include/cstring b/include/cstring
new file mode 100644
index 0000000..66c0f57
--- /dev/null
+++ b/include/cstring
@@ -0,0 +1,106 @@
+// -*- C++ -*-
+//===--------------------------- cstring ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTRING
+#define _LIBCPP_CSTRING
+
+/*
+    cstring synopsis
+
+Macros:
+
+    NULL
+ 
+namespace std
+{
+
+Types:
+
+    size_t
+
+void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
+void* memmove(void* s1, const void* s2, size_t n);
+char* strcpy (char* restrict s1, const char* restrict s2);
+char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
+char* strcat (char* restrict s1, const char* restrict s2);
+char* strncat(char* restrict s1, const char* restrict s2, size_t n);
+int memcmp(const void* s1, const void* s2, size_t n);
+int strcmp (const char* s1, const char* s2);
+int strncmp(const char* s1, const char* s2, size_t n);
+int strcoll(const char* s1, const char* s2);
+size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
+const void* memchr(const void* s, int c, size_t n);
+      void* memchr(      void* s, int c, size_t n);
+const char* strchr(const char* s, int c);
+      char* strchr(      char* s, int c);
+size_t strcspn(const char* s1, const char* s2);
+const char* strpbrk(const char* s1, const char* s2);
+      char* strpbrk(      char* s1, const char* s2);
+const char* strrchr(const char* s, int c);
+      char* strrchr(      char* s, int c);
+size_t strspn(const char* s1, const char* s2);
+const char* strstr(const char* s1, const char* s2);
+      char* strstr(      char* s1, const char* s2);
+char* strtok(char* restrict s1, const char* restrict s2);
+void* memset(void* s, int c, size_t n);
+char* strerror(int errnum);
+size_t strlen(const char* s);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <string.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::size_t;
+using ::memcpy;
+using ::memmove;
+using ::strcpy;
+using ::strncpy;
+using ::strcat;
+using ::strncat;
+using ::memcmp;
+using ::strcmp;
+using ::strncmp;
+using ::strcoll;
+using ::strxfrm;
+
+inline _LIBCPP_INLINE_VISIBILITY const void* memchr(const void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY       void* memchr(      void* __s, int __c, size_t __n) {return ::memchr(__s, __c, __n);}
+
+inline _LIBCPP_INLINE_VISIBILITY const char* strchr(const char* __s, int __c) {return ::strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strchr(      char* __s, int __c) {return ::strchr(__s, __c);}
+
+using ::strcspn;
+
+inline _LIBCPP_INLINE_VISIBILITY const char* strpbrk(const char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strpbrk(      char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY const char* strrchr(const char* __s, int __c) {return ::strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strrchr(      char* __s, int __c) {return ::strrchr(__s, __c);}
+
+using ::strspn;
+
+inline _LIBCPP_INLINE_VISIBILITY const char* strstr(const char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       char* strstr(      char* __s1, const char* __s2) {return ::strstr(__s1, __s2);}
+
+using ::strtok;
+using ::memset;
+using ::strerror;
+using ::strlen;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CSTRING
diff --git a/include/ctgmath b/include/ctgmath
new file mode 100644
index 0000000..a1e1de9
--- /dev/null
+++ b/include/ctgmath
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===-------------------------- ctgmath -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CTGMATH
+#define _LIBCPP_CTGMATH
+
+/*
+    ctgmath synopsis
+
+#include <ccomplex>
+#include <cmath>
+
+*/
+
+#include <ccomplex>
+#include <cmath>
+
+#pragma GCC system_header
+
+#endif  // _LIBCPP_CTGMATH
diff --git a/include/ctime b/include/ctime
new file mode 100644
index 0000000..ac73a02
--- /dev/null
+++ b/include/ctime
@@ -0,0 +1,70 @@
+// -*- C++ -*-
+//===---------------------------- ctime -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CTIME
+#define _LIBCPP_CTIME
+
+/*
+    ctime synopsis
+
+Macros:
+
+    NULL
+    CLOCKS_PER_SEC
+ 
+namespace std
+{
+
+Types:
+
+    clock_t
+    size_t
+    time_t
+    tm
+
+clock_t clock();
+double difftime(time_t time1, time_t time0);
+time_t mktime(tm* timeptr);
+time_t time(time_t* timer);
+char* asctime(const tm* timeptr);
+char* ctime(const time_t* timer);
+tm*    gmtime(const time_t* timer);
+tm* localtime(const time_t* timer);
+size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
+                const tm* restrict timeptr);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <time.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::clock_t;
+using ::size_t;
+using ::time_t;
+using ::tm;
+using ::clock;
+using ::difftime;
+using ::mktime;
+using ::time;
+using ::asctime;
+using ::ctime;
+using ::gmtime;
+using ::localtime;
+using ::strftime;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CTIME
diff --git a/include/cwchar b/include/cwchar
new file mode 100644
index 0000000..42e51a5
--- /dev/null
+++ b/include/cwchar
@@ -0,0 +1,195 @@
+// -*- C++ -*-
+//===--------------------------- cwchar -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CWCHAR
+#define _LIBCPP_CWCHAR
+
+/*
+    cwchar synopsis
+
+Macros:
+
+    NULL
+    WCHAR_MAX
+    WCHAR_MIN
+    WEOF
+ 
+namespace std
+{
+
+Types:
+
+    mbstate_t
+    size_t
+    tm
+    wint_t
+
+int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
+int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
+int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...);
+int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
+int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);
+int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);  // C99
+int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg);
+int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg);  // C99
+int vwprintf(const wchar_t* restrict format, va_list arg);
+int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
+int wprintf(const wchar_t* restrict format, ...);
+int wscanf(const wchar_t* restrict format, ...);
+wint_t fgetwc(FILE* stream);
+wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
+wint_t fputwc(wchar_t c, FILE* stream);
+int fputws(const wchar_t* restrict s, FILE* restrict stream);
+int fwide(FILE* stream, int mode);
+wint_t getwc(FILE* stream);
+wint_t getwchar(); 
+wint_t putwc(wchar_t c, FILE* stream);
+wint_t putwchar(wchar_t c);
+wint_t ungetwc(wint_t c, FILE* stream);
+double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
+float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr);         // C99
+long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr);  // C99
+long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
+long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
+unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
+unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);  // C99
+wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
+wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
+wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2);
+wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
+int wcscmp(const wchar_t* s1, const wchar_t* s2);
+int wcscoll(const wchar_t* s1, const wchar_t* s2);
+int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n);
+size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
+const wchar_t* wcschr(const wchar_t* s, wchar_t c);
+      wchar_t* wcschr(      wchar_t* s, wchar_t c);
+size_t wcscspn(const wchar_t* s1, const wchar_t* s2);
+size_t wcslen(const wchar_t* s);
+const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2);
+      wchar_t* wcspbrk(      wchar_t* s1, const wchar_t* s2);
+const wchar_t* wcsrchr(const wchar_t* s, wchar_t c);
+      wchar_t* wcsrchr(      wchar_t* s, wchar_t c);
+size_t wcsspn(const wchar_t* s1, const wchar_t* s2);
+const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2);
+      wchar_t* wcsstr(      wchar_t* s1, const wchar_t* s2);
+wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr);
+const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n);
+      wchar_t* wmemchr(      wchar_t* s, wchar_t c, size_t n);
+int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
+wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
+wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
+wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
+size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format,
+                const tm* restrict timeptr);
+wint_t btowc(int c);
+int wctob(wint_t c);
+int mbsinit(const mbstate_t* ps);
+size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps);
+size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps); 
+size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps);
+size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len,
+                 mbstate_t* restrict ps); 
+size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
+                 mbstate_t* restrict ps);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cwctype>
+#include <wchar.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::mbstate_t;
+using ::size_t;
+using ::tm;
+using ::wint_t;
+using ::FILE;
+using ::fwprintf;
+using ::fwscanf;
+using ::swprintf;
+using ::swscanf;
+using ::vfwprintf;
+using ::vfwscanf;
+using ::vswprintf;
+using ::vswscanf;
+using ::vwprintf;
+using ::vwscanf;
+using ::wprintf;
+using ::wscanf;
+using ::fgetwc;
+using ::fgetws;
+using ::fputwc;
+using ::fputws;
+using ::fwide;
+using ::getwc;
+using ::getwchar;
+using ::putwc;
+using ::putwchar;
+using ::ungetwc;
+using ::wcstod;
+using ::wcstof;
+using ::wcstold;
+using ::wcstol;
+using ::wcstoll;
+using ::wcstoul;
+using ::wcstoull;
+using ::wcscpy;
+using ::wcsncpy;
+using ::wcscat;
+using ::wcsncat;
+using ::wcscmp;
+using ::wcscoll;
+using ::wcsncmp;
+using ::wcsxfrm;
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcschr(      wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);}
+
+using ::wcscspn;
+using ::wcslen;
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcspbrk(      wchar_t* __s1, const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsrchr(      wchar_t* __s, wchar_t __c) {return ::wcsrchr(__s, __c);}
+
+using ::wcsspn;
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wcsstr(      wchar_t* __s1, const wchar_t* __s2) {return ::wcsstr(__s1, __s2);}
+
+using ::wcstok;
+
+inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY       wchar_t* wmemchr(      wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
+
+using ::wmemcmp;
+using ::wmemcpy;
+using ::wmemmove;
+using ::wmemset;
+using ::wcsftime;
+using ::btowc;
+using ::wctob;
+using ::mbsinit;
+using ::mbrlen;
+using ::mbrtowc;
+using ::wcrtomb;
+using ::mbsrtowcs;
+using ::wcsrtombs;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CWCHAR
diff --git a/include/cwctype b/include/cwctype
new file mode 100644
index 0000000..7d173fc
--- /dev/null
+++ b/include/cwctype
@@ -0,0 +1,211 @@
+// -*- C++ -*-
+//===--------------------------- cwctype ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CWCTYPE
+#define _LIBCPP_CWCTYPE
+
+/*
+    cwctype synopsis
+
+Macros:
+
+    WEOF
+ 
+namespace std
+{
+
+Types:
+
+    wint_t
+    wctrans_t
+    wctype_t
+
+int iswalnum(wint_t wc);
+int iswalpha(wint_t wc);
+int iswblank(wint_t wc);  // C99
+int iswcntrl(wint_t wc);
+int iswdigit(wint_t wc);
+int iswgraph(wint_t wc);
+int iswlower(wint_t wc);
+int iswprint(wint_t wc);
+int iswpunct(wint_t wc);
+int iswspace(wint_t wc);
+int iswupper(wint_t wc);
+int iswxdigit(wint_t wc);
+int iswctype(wint_t wc, wctype_t desc);
+wctype_t wctype(const char* property);
+wint_t towlower(wint_t wc);
+wint_t towupper(wint_t wc);
+wint_t towctrans(wint_t wc, wctrans_t desc);
+wctrans_t wctrans(const char* property);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cctype>
+#include <wctype.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+using ::wint_t;
+using ::wctrans_t;
+using ::wctype_t;
+
+#ifdef iswalnum
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalnum(wint_t __wc) {return iswalnum(__wc);}
+#undef iswalnum
+inline _LIBCPP_INLINE_VISIBILITY int iswalnum(wint_t __wc) {return __libcpp_iswalnum(__wc);}
+#else
+using ::iswalnum;
+#endif
+
+#ifdef iswalpha
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalpha(wint_t __wc) {return iswalpha(__wc);}
+#undef iswalpha
+inline _LIBCPP_INLINE_VISIBILITY int iswalpha(wint_t __wc) {return __libcpp_iswalpha(__wc);}
+#else
+using ::iswalpha;
+#endif
+
+#ifdef iswblank
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswblank(wint_t __wc) {return iswblank(__wc);}
+#undef iswblank
+inline _LIBCPP_INLINE_VISIBILITY int iswblank(wint_t __wc) {return __libcpp_iswblank(__wc);}
+#else
+using ::iswblank;
+#endif
+
+#ifdef iswcntrl
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswcntrl(wint_t __wc) {return iswcntrl(__wc);}
+#undef iswcntrl
+inline _LIBCPP_INLINE_VISIBILITY int iswcntrl(wint_t __wc) {return __libcpp_iswcntrl(__wc);}
+#else
+using ::iswcntrl;
+#endif
+
+#ifdef iswdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswdigit(wint_t __wc) {return iswdigit(__wc);}
+#undef iswdigit
+inline _LIBCPP_INLINE_VISIBILITY int iswdigit(wint_t __wc) {return __libcpp_iswdigit(__wc);}
+#else
+using ::iswdigit;
+#endif
+
+#ifdef iswgraph
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswgraph(wint_t __wc) {return iswgraph(__wc);}
+#undef iswgraph
+inline _LIBCPP_INLINE_VISIBILITY int iswgraph(wint_t __wc) {return __libcpp_iswgraph(__wc);}
+#else
+using ::iswgraph;
+#endif
+
+#ifdef iswlower
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswlower(wint_t __wc) {return iswlower(__wc);}
+#undef iswlower
+inline _LIBCPP_INLINE_VISIBILITY int iswlower(wint_t __wc) {return __libcpp_iswlower(__wc);}
+#else
+using ::iswlower;
+#endif
+
+#ifdef iswprint
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswprint(wint_t __wc) {return iswprint(__wc);}
+#undef iswprint
+inline _LIBCPP_INLINE_VISIBILITY int iswprint(wint_t __wc) {return __libcpp_iswprint(__wc);}
+#else
+using ::iswprint;
+#endif
+
+#ifdef iswpunct
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswpunct(wint_t __wc) {return iswpunct(__wc);}
+#undef iswpunct
+inline _LIBCPP_INLINE_VISIBILITY int iswpunct(wint_t __wc) {return __libcpp_iswpunct(__wc);}
+#else
+using ::iswpunct;
+#endif
+
+#ifdef iswspace
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswspace(wint_t __wc) {return iswspace(__wc);}
+#undef iswspace
+inline _LIBCPP_INLINE_VISIBILITY int iswspace(wint_t __wc) {return __libcpp_iswspace(__wc);}
+#else
+using ::iswspace;
+#endif
+
+#ifdef iswupper
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswupper(wint_t __wc) {return iswupper(__wc);}
+#undef iswupper
+inline _LIBCPP_INLINE_VISIBILITY int iswupper(wint_t __wc) {return __libcpp_iswupper(__wc);}
+#else
+using ::iswupper;
+#endif
+
+#ifdef iswxdigit
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswxdigit(wint_t __wc) {return iswxdigit(__wc);}
+#undef iswxdigit
+inline _LIBCPP_INLINE_VISIBILITY int iswxdigit(wint_t __wc) {return __libcpp_iswxdigit(__wc);}
+#else
+using ::iswxdigit;
+#endif
+
+#ifdef iswctype
+inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswctype(wint_t __w, wctype_t __d) {return iswctype(__w, __d);}
+#undef iswctype
+inline _LIBCPP_INLINE_VISIBILITY int iswctype(wint_t __w, wctype_t __d) {return __libcpp_iswctype(__w, __d);}
+#else
+using ::iswctype;
+#endif
+
+#ifdef wctype
+inline _LIBCPP_INLINE_VISIBILITY wctype_t __libcpp_wctype(const char* __p) {return wctype(__p);}
+#undef wctype
+inline _LIBCPP_INLINE_VISIBILITY wctype_t wctype(const char* __p) {return __libcpp_wctype(__p);}
+#else
+using ::wctype;
+#endif
+
+#ifdef towlower
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towlower(wint_t __wc) {return towlower(__wc);}
+#undef towlower
+inline _LIBCPP_INLINE_VISIBILITY wint_t towlower(wint_t __wc) {return __libcpp_towlower(__wc);}
+#else
+using ::towlower;
+#endif
+
+#ifdef towupper
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towupper(wint_t __wc) {return towupper(__wc);}
+#undef towupper
+inline _LIBCPP_INLINE_VISIBILITY wint_t towupper(wint_t __wc) {return __libcpp_towupper(__wc);}
+#else
+using ::towupper;
+#endif
+
+#ifdef towctrans
+inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towctrans(wint_t __wc, wctype_t __d) {return towctrans(__wc, __d);}
+#undef towctrans
+inline _LIBCPP_INLINE_VISIBILITY wint_t towctrans(wint_t __wc, wctype_t __d) {return __libcpp_towctrans(__wc, __d);}
+#else
+using ::towctrans;
+#endif
+
+#ifdef wctrans
+inline _LIBCPP_INLINE_VISIBILITY wctrans_t __libcpp_wctrans(const char* __p) {return wctrans(__p);}
+#undef wctrans
+inline _LIBCPP_INLINE_VISIBILITY wctrans_t wctrans(const char* __p) {return __libcpp_wctrans(__p);}
+#else
+using ::wctrans;
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_CWCTYPE
diff --git a/include/deque b/include/deque
new file mode 100644
index 0000000..ae6b8df
--- /dev/null
+++ b/include/deque
@@ -0,0 +1,2732 @@
+// -*- C++ -*-
+//===---------------------------- deque -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_DEQUE
+#define _LIBCPP_DEQUE
+
+/*
+    deque synopsis
+
+namespace std
+{
+
+template <class T, class Allocator = allocator<T> >
+class deque
+{
+public:
+    // types:
+    typedef T value_type;
+    typedef Allocator allocator_type;
+
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    // construct/copy/destroy:
+    deque();
+    explicit deque(const allocator_type& a);
+    explicit deque(size_type n);
+    deque(size_type n, const value_type& v);
+    deque(size_type n, const value_type& v, const allocator_type& a);
+    template <class InputIterator>
+        deque(InputIterator f, InputIterator l);
+    template <class InputIterator>
+        deque(InputIterator f, InputIterator l, const allocator_type& a);
+    deque(const deque& c);
+    deque(deque&& c);
+    deque(initializer_list<value_type> il, const Allocator& a = allocator_type());
+    deque(const deque& c, const allocator_type& a);
+    deque(deque&& c, const allocator_type& a);
+    ~deque();
+
+    deque& operator=(const deque& c);
+    deque& operator=(deque&& c);
+    deque& operator=(initializer_list<value_type> il);
+
+    template <class InputIterator>
+        void assign(InputIterator f, InputIterator l);
+    void assign(size_type n, const value_type& v);
+    void assign(initializer_list<value_type> il);
+
+    allocator_type get_allocator() const;
+
+    // iterators:
+
+    iterator       begin();
+    const_iterator begin() const;
+    iterator       end();
+    const_iterator end() const;
+
+    reverse_iterator       rbegin();
+    const_reverse_iterator rbegin() const;
+    reverse_iterator       rend();
+    const_reverse_iterator rend() const;
+
+    const_iterator         cbegin() const;
+    const_iterator         cend() const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend() const;
+
+    // capacity:
+    size_type size() const;
+    size_type max_size() const;
+    void resize(size_type n);
+    void resize(size_type n, const value_type& v);
+    void shrink_to_fit();
+    bool empty() const;
+
+    // element access:
+    reference operator[](size_type i);
+    const_reference operator[](size_type i) const;
+    reference at(size_type i);
+    const_reference at(size_type i) const;
+    reference front();
+    const_reference front() const;
+    reference back();
+    const_reference back() const;
+
+    // modifiers:
+    void push_front(const value_type& v);
+    void push_front(value_type&& v);
+    void push_back(const value_type& v);
+    void push_back(value_type&& v);
+    template <class... Args> void emplace_front(Args&&... args);
+    template <class... Args> void emplace_back(Args&&... args);
+    template <class... Args> iterator emplace(const_iterator p, Args&&... args);
+    iterator insert(const_iterator p, const value_type& v);
+    iterator insert(const_iterator p, value_type&& v);
+    iterator insert(const_iterator p, size_type n, const value_type& v);
+    template <class InputIterator>
+        iterator insert (const_iterator p, InputIterator f, InputIterator l);
+    iterator insert(const_iterator p, initializer_list<value_type> il);
+    void pop_front();
+    void pop_back();
+    iterator erase(const_iterator p);
+    iterator erase(const_iterator f, const_iterator l);
+    void swap(deque& c);
+    void clear();
+};
+
+template <class T, class Allocator>
+    bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+template <class T, class Allocator>
+    bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+template <class T, class Allocator>
+    bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+template <class T, class Allocator>
+    bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+template <class T, class Allocator>
+    bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+template <class T, class Allocator>
+    bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+
+// specialized algorithms:
+template <class T, class Allocator>
+    void swap(deque<T,Allocator>& x, deque<T,Allocator>& y);
+
+}  // std
+
+*/
+
+#pragma GCC system_header
+
+#include <__config>
+#include <__split_buffer>
+#include <type_traits>
+#include <initializer_list>
+#include <iterator>
+#include <algorithm>
+#include <stdexcept>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Allocator> class __deque_base;
+
+template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
+          class _DiffType, _DiffType _BlockSize>
+class __deque_iterator;
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy(_RAIter __f,
+     _RAIter __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+     typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     _OutputIterator __r);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy_backward(_RAIter __f,
+              _RAIter __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+              typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              _OutputIterator __r);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move(_RAIter __f,
+     _RAIter __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+     typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     _OutputIterator __r);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move_backward(_RAIter __f,
+              _RAIter __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+              typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              _OutputIterator __r);
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
+          class _DiffType, _DiffType _BlockSize>
+class __deque_iterator
+{
+    typedef _MapPointer __map_iterator;
+public:
+    typedef _Pointer  pointer;
+    typedef _DiffType difference_type;
+private:
+    __map_iterator __m_iter_;
+    pointer        __ptr_;
+
+    static const difference_type __block_size = _BlockSize;
+public:
+    typedef _ValueType                  value_type;
+    typedef random_access_iterator_tag  iterator_category;
+    typedef _Reference                  reference;
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator() {}
+
+    template <class _P, class _R, class _MP>
+    _LIBCPP_INLINE_VISIBILITY
+    __deque_iterator(const __deque_iterator<value_type, _P, _R, _MP, difference_type, __block_size>& __it,
+                typename enable_if<is_convertible<_P, pointer>::value>::type* = 0)
+        : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
+
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
+    {
+        if (++__ptr_ - *__m_iter_ == __block_size)
+        {
+            ++__m_iter_;
+            __ptr_ = *__m_iter_;
+        }
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
+    {
+        __deque_iterator __tmp = *this;
+        ++(*this);
+        return __tmp;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
+    {
+        if (__ptr_ == *__m_iter_)
+        {
+            --__m_iter_;
+            __ptr_ = *__m_iter_ + __block_size;
+        }
+        --__ptr_;
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
+    {
+        __deque_iterator __tmp = *this;
+        --(*this);
+        return __tmp;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
+    {
+        if (__n != 0)
+        {
+            __n += __ptr_ - *__m_iter_;
+            if (__n > 0)
+            {
+                __m_iter_ += __n / __block_size;
+                __ptr_ = *__m_iter_ + __n % __block_size;
+            }
+            else // (__n < 0)
+            {
+                difference_type __z = __block_size - 1 - __n;
+                __m_iter_ -= __z / __block_size;
+                __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
+            }
+        }
+        return *this;
+    }
+    
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
+    {
+        return *this += -__n;
+    }
+    
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
+    {
+        __deque_iterator __t(*this);
+        __t += __n;
+        return __t;
+    }
+    
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
+    {
+        __deque_iterator __t(*this);
+        __t -= __n;
+        return __t;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY
+    friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
+        {return __it + __n;}
+
+    _LIBCPP_INLINE_VISIBILITY
+    friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
+    {
+        if (__x != __y)
+            return (__x.__m_iter_ - __y.__m_iter_) * __block_size
+                 + (__x.__ptr_ - *__x.__m_iter_)
+                 - (__y.__ptr_ - *__y.__m_iter_);
+        return 0;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
+        {return *(*this + __n);}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return !(__x == __y);}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator<(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return __x.__m_iter_ < __y.__m_iter_ ||
+               (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return __y < __x;}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return !(__y < __x);}
+
+    _LIBCPP_INLINE_VISIBILITY friend
+        bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
+        {return !(__x < __y);}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p)
+        : __m_iter_(__m), __ptr_(__p) {}
+
+
+    template <class _Tp, class _A> friend class __deque_base;
+    template <class _Tp, class _A> friend class deque;
+    template <class _V, class _P, class _R, class _MP, class _D, _D>
+        friend class __deque_iterator;
+
+    template <class _RAIter,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    copy(_RAIter __f,
+         _RAIter __l,
+         __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+         typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _OutputIterator>
+    friend
+    _OutputIterator
+    copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+         __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+         _OutputIterator __r);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+         __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+         __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+    template <class _RAIter,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    copy_backward(_RAIter __f,
+                  _RAIter __l,
+                  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+                  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _OutputIterator>
+    friend
+    _OutputIterator
+    copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+                  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+                  _OutputIterator __r);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+                  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+                  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+    template <class _RAIter,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    move(_RAIter __f,
+         _RAIter __l,
+         __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+         typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _OutputIterator>
+    friend
+    _OutputIterator
+    move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+         __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+         _OutputIterator __r);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+         __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+         __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+
+    template <class _RAIter,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    move_backward(_RAIter __f,
+                  _RAIter __l,
+                  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+                  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _OutputIterator>
+    friend
+    _OutputIterator
+    move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+                  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+                  _OutputIterator __r);
+
+    template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+              class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+    friend
+    __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+    move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+                  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+                  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
+};
+
+// copy
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy(_RAIter __f,
+     _RAIter __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+     typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
+{
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
+    while (__f != __l)
+    {
+        pointer __rb = __r.__ptr_;
+        pointer __re = *__r.__m_iter_ + _B2;
+        difference_type __bs = __re - __rb;
+        difference_type __n = __l - __f;
+        _RAIter __m = __l;
+        if (__n > __bs)
+        {
+            __n = __bs;
+            __m = __f + __n;
+        }
+        _STD::copy(__f, __m, __rb);
+        __f = __m;
+        __r += __n;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     _OutputIterator __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + _B1;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        __r = _STD::copy(__fb, __fe, __r);
+        __n -= __bs;
+        __f += __bs;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + _B1;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        __r = _STD::copy(__fb, __fe, __r);
+        __n -= __bs;
+        __f += __bs;
+    }
+    return __r;
+}
+
+// copy_backward
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy_backward(_RAIter __f,
+              _RAIter __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+              typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
+{
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
+    while (__f != __l)
+    {
+        __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = prev(__r);
+        pointer __rb = *__rp.__m_iter_;
+        pointer __re = __rp.__ptr_ + 1;
+        difference_type __bs = __re - __rb;
+        difference_type __n = __l - __f;
+        _RAIter __m = __f;
+        if (__n > __bs)
+        {
+            __n = __bs;
+            __m = __l - __n;
+        }
+        _STD::copy_backward(__m, __l, __re);
+        __l = __m;
+        __r -= __n;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              _OutputIterator __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        __r = _STD::copy_backward(__lb, __le, __r);
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        __r = _STD::copy_backward(__lb, __le, __r);
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+    return __r;
+}
+
+// move
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move(_RAIter __f,
+     _RAIter __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+     typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
+{
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
+    while (__f != __l)
+    {
+        pointer __rb = __r.__ptr_;
+        pointer __re = *__r.__m_iter_ + _B2;
+        difference_type __bs = __re - __rb;
+        difference_type __n = __l - __f;
+        _RAIter __m = __l;
+        if (__n > __bs)
+        {
+            __n = __bs;
+            __m = __f + __n;
+        }
+        _STD::move(__f, __m, __rb);
+        __f = __m;
+        __r += __n;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     _OutputIterator __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + _B1;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        __r = _STD::move(__fb, __fe, __r);
+        __n -= __bs;
+        __f += __bs;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+     __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+     __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + _B1;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        __r = _STD::move(__fb, __fe, __r);
+        __n -= __bs;
+        __f += __bs;
+    }
+    return __r;
+}
+
+// move_backward
+
+template <class _RAIter,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move_backward(_RAIter __f,
+              _RAIter __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
+              typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
+{
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
+    typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
+    while (__f != __l)
+    {
+        __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = prev(__r);
+        pointer __rb = *__rp.__m_iter_;
+        pointer __re = __rp.__ptr_ + 1;
+        difference_type __bs = __re - __rb;
+        difference_type __n = __l - __f;
+        _RAIter __m = __f;
+        if (__n > __bs)
+        {
+            __n = __bs;
+            __m = __l - __n;
+        }
+        _STD::move_backward(__m, __l, __re);
+        __l = __m;
+        __r -= __n;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _OutputIterator>
+_OutputIterator
+move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              _OutputIterator __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        __r = _STD::move_backward(__lb, __le, __r);
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+    return __r;
+}
+
+template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
+          class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
+__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
+move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
+              __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
+              __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
+{
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
+    typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        __r = _STD::move_backward(__lb, __le, __r);
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+    return __r;
+}
+
+template <bool>
+class __deque_base_common
+{
+protected:
+    void __throw_length_error() const;
+    void __throw_out_of_range() const;
+};
+
+template <bool __b>
+void
+__deque_base_common<__b>::__throw_length_error() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw length_error("deque");
+#endif
+}
+
+template <bool __b>
+void
+__deque_base_common<__b>::__throw_out_of_range() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw out_of_range("deque");
+#endif
+}
+
+template <class _Tp, class _Allocator>
+class __deque_base
+    : protected __deque_base_common<true>
+{
+    __deque_base(const __deque_base& __c);
+    __deque_base& operator=(const __deque_base& __c);
+protected:
+    typedef _Tp                                      value_type;
+    typedef _Allocator                               allocator_type;
+    typedef allocator_traits<allocator_type>         __alloc_traits;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+
+    static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
+
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<pointer>
+#else
+                rebind_alloc<pointer>::other
+#endif
+                                                         __pointer_allocator;
+    typedef allocator_traits<__pointer_allocator>        __map_traits;
+    typedef typename __map_traits::pointer               __map_pointer;
+    typedef typename __map_traits::const_pointer         __map_const_pointer;
+    typedef __split_buffer<pointer, __pointer_allocator> __map;
+
+    typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
+                             difference_type, __block_size>    iterator;
+    typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
+                             difference_type, __block_size>    const_iterator;
+
+    __map __map_;
+    size_type __start_;
+    __compressed_pair<size_type, allocator_type> __size_;
+
+    iterator       begin();
+    const_iterator begin() const;
+    iterator       end();
+    const_iterator end() const;
+
+    _LIBCPP_INLINE_VISIBILITY size_type&            size()          {return __size_.first();}
+    _LIBCPP_INLINE_VISIBILITY const size_type&      size() const    {return __size_.first();}
+    _LIBCPP_INLINE_VISIBILITY allocator_type&       __alloc()       {return __size_.second();}
+    _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const {return __size_.second();}
+
+    __deque_base();
+    explicit __deque_base(const allocator_type& __a);
+    ~__deque_base();
+
+#ifdef _LIBCPP_MOVE
+
+    __deque_base(__deque_base&& __c);
+    __deque_base(__deque_base&& __c, const allocator_type& __a);
+
+#endif
+    void swap(__deque_base& __c);
+    void clear();
+
+    bool __invariants() const;
+
+    void __move_assign(__deque_base& __c)
+    {
+        __map_ = _STD::move(__c.__map_);
+        __start_ = __c.__start_;
+        size() = __c.size();
+        __move_assign_alloc(__c);
+        __c.__start_ = __c.size() = 0;
+    }
+
+    void __move_assign_alloc(__deque_base& __c)
+        {__move_assign_alloc(__c, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_move_assignment::value>());}
+
+private:
+    void __move_assign_alloc(const __deque_base& __c, true_type)
+        {
+            __alloc() = _STD::move(__c.__alloc());
+        }
+
+    void __move_assign_alloc(const __deque_base& __c, false_type)
+        {}
+
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_swap::value>());}
+
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
+        {}
+};
+
+template <class _Tp, class _Allocator>
+bool
+__deque_base<_Tp, _Allocator>::__invariants() const
+{
+    if (!__map_.__invariants())
+        return false;
+    if (__map_.size() >= size_type(-1) / __block_size)
+        return false;
+    for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
+         __i != __e; ++__i)
+        if (*__i == nullptr)
+            return false;
+    if (__map_.size() != 0)
+    {
+        if (size() >= __map_.size() * __block_size)
+            return false;
+        if (__start_ >= __map_.size() * __block_size - size())
+            return false;
+    }
+    else
+    {
+        if (size() != 0)
+            return false;
+        if (__start_ != 0)
+            return false;
+    }
+    return true;
+}
+
+template <class _Tp, class _Allocator>
+typename __deque_base<_Tp, _Allocator>::iterator
+__deque_base<_Tp, _Allocator>::begin()
+{
+    __map_pointer __mp = __map_.begin() + __start_ / __block_size;
+    return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
+}
+
+template <class _Tp, class _Allocator>
+typename __deque_base<_Tp, _Allocator>::const_iterator
+__deque_base<_Tp, _Allocator>::begin() const
+{
+    __map_const_pointer __mp = __map_.begin() + __start_ / __block_size;
+    return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
+}
+
+template <class _Tp, class _Allocator>
+typename __deque_base<_Tp, _Allocator>::iterator
+__deque_base<_Tp, _Allocator>::end()
+{
+    size_type __p = size() + __start_;
+    __map_pointer __mp = __map_.begin() + __p / __block_size;
+    return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
+}
+
+template <class _Tp, class _Allocator>
+typename __deque_base<_Tp, _Allocator>::const_iterator
+__deque_base<_Tp, _Allocator>::end() const
+{
+    size_type __p = size() + __start_;
+    __map_const_pointer __mp = __map_.begin() + __p / __block_size;
+    return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+__deque_base<_Tp, _Allocator>::__deque_base()
+    : __start_(0), __size_(0) {}
+
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
+    : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
+
+template <class _Tp, class _Allocator>
+__deque_base<_Tp, _Allocator>::~__deque_base()
+{
+    clear();
+    typename __map::iterator __i = __map_.begin();
+    typename __map::iterator __e = __map_.end();
+    for (; __i != __e; ++__i)
+        __alloc_traits::deallocate(__alloc(), *__i, __block_size);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
+    : __map_(_STD::move(__c.__map_)),
+      __start_(_STD::move(__c.__start_)),
+      __size_(_STD::move(__c.__size_))
+{
+    __c.__start_ = 0;
+    __c.size() = 0;
+}
+
+template <class _Tp, class _Allocator>
+__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
+    : __map_(_STD::move(__c.__map_), __pointer_allocator(__a)),
+      __start_(_STD::move(__c.__start_)),
+      __size_(_STD::move(__c.size()), __a)
+{
+    if (__a == __c.__alloc())
+    {
+        __c.__start_ = 0;
+        __c.size() = 0;
+    }
+    else
+    {
+        __map_.clear();
+        __start_ = 0;
+        size() = 0;
+    }
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+void
+__deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
+{
+    __map_.swap(__c.__map_);
+    _STD::swap(__start_, __c.__start_);
+    _STD::swap(size(), __c.size());
+    __swap_alloc(__alloc(), __c.__alloc());
+}
+
+template <class _Tp, class _Allocator>
+void
+__deque_base<_Tp, _Allocator>::clear()
+{
+    allocator_type& __a = __alloc();
+    for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
+        __alloc_traits::destroy(__a, addressof(*__i));
+    size() = 0;
+    while (__map_.size() > 2)
+    {
+        __alloc_traits::deallocate(__a, __map_.front(), __block_size);
+        __map_.pop_front();
+    }
+    switch (__map_.size())
+    {
+    case 1:
+        __start_ = __block_size / 2;
+        break;
+    case 2:
+        __start_ = __block_size;
+        break;
+    }
+}
+
+template <class _Tp, class _Allocator = allocator<_Tp> >
+class deque
+    : private __deque_base<_Tp, _Allocator>
+{
+public:
+    // types:
+    
+    typedef _Tp value_type;
+    typedef _Allocator allocator_type;
+
+    typedef __deque_base<value_type, allocator_type> __base;
+
+    typedef typename __base::__alloc_traits        __alloc_traits;
+    typedef typename __base::reference             reference;
+    typedef typename __base::const_reference       const_reference;
+    typedef typename __base::iterator              iterator;
+    typedef typename __base::const_iterator        const_iterator;
+    typedef typename __base::size_type             size_type;
+    typedef typename __base::difference_type       difference_type;
+
+    typedef typename __base::pointer               pointer;
+    typedef typename __base::const_pointer         const_pointer;
+    typedef _STD::reverse_iterator<iterator>       reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
+
+    // construct/copy/destroy:
+    _LIBCPP_INLINE_VISIBILITY deque() {}
+    _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {}
+    explicit deque(size_type __n);
+    deque(size_type __n, const value_type& __v);
+    deque(size_type __n, const value_type& __v, const allocator_type& __a);
+    template <class _InputIter>
+        deque(_InputIter __f, _InputIter __l,
+              typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
+    template <class _InputIter>
+        deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
+              typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
+    deque(const deque& __c);
+    deque(const deque& __c, const allocator_type& __a);
+    deque(initializer_list<value_type> __il);
+    deque(initializer_list<value_type> __il, const allocator_type& __a);
+
+    deque& operator=(const deque& __c);
+    deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
+
+#ifdef _LIBCPP_MOVE
+    deque(deque&& __c);
+    deque(deque&& __c, const allocator_type& __a);
+    deque& operator=(deque&& __c);
+#endif
+
+    template <class _InputIter>
+        void assign(_InputIter __f, _InputIter __l,
+                    typename enable_if<__is_input_iterator<_InputIter>::value &&
+                                      !__is_random_access_iterator<_InputIter>::value>::type* = 0);
+    template <class _RAIter>
+        void assign(_RAIter __f, _RAIter __l,
+                    typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
+    void assign(size_type __n, const value_type& __v);
+    void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
+
+    allocator_type get_allocator() const;
+
+    // iterators:
+
+    iterator       begin()       {return __base::begin();}
+    const_iterator begin() const {return __base::begin();}
+    iterator       end()         {return __base::end();}
+    const_iterator end()   const {return __base::end();}
+
+    reverse_iterator       rbegin()       {return       reverse_iterator(__base::end());}
+    const_reverse_iterator rbegin() const {return const_reverse_iterator(__base::end());}
+    reverse_iterator       rend()         {return       reverse_iterator(__base::begin());}
+    const_reverse_iterator rend()   const {return const_reverse_iterator(__base::begin());}
+
+    const_iterator         cbegin()  const {return __base::begin();}
+    const_iterator         cend()    const {return __base::end();}
+    const_reverse_iterator crbegin() const {return const_reverse_iterator(__base::end());}
+    const_reverse_iterator crend()   const {return const_reverse_iterator(__base::begin());}
+
+    // capacity:
+    _LIBCPP_INLINE_VISIBILITY size_type size() const {return __base::size();}
+    size_type max_size() const {return __alloc_traits::max_size(__base::__alloc());}
+    void resize(size_type __n);
+    void resize(size_type __n, const value_type& __v);
+    void shrink_to_fit();
+    bool empty() const {return __base::size() == 0;}
+
+    // element access:
+    reference operator[](size_type __i);
+    const_reference operator[](size_type __i) const;
+    reference at(size_type __i);
+    const_reference at(size_type __i) const;
+    reference front();
+    const_reference front() const;
+    reference back();
+    const_reference back() const;
+
+    // 23.2.2.3 modifiers:
+    void push_front(const value_type& __v);
+    void push_back(const value_type& __v);
+#ifdef _LIBCPP_MOVE
+    template <class... _Args> void emplace_front(_Args&&... __args);
+    template <class... _Args> void emplace_back(_Args&&... __args);
+    template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
+    void push_front(value_type&& __v);
+    void push_back(value_type&& __v);
+    iterator insert(const_iterator __p, value_type&& __v);
+#endif
+    iterator insert(const_iterator __p, const value_type& __v);
+    iterator insert(const_iterator __p, size_type __n, const value_type& __v);
+    template <class _InputIter>
+        iterator insert (const_iterator __p, _InputIter __f, _InputIter __l,
+                         typename enable_if<__is_input_iterator<_InputIter>::value
+                                         &&!__is_bidirectional_iterator<_InputIter>::value>::type* = 0);
+    template <class _BiIter>
+        iterator insert (const_iterator __p, _BiIter __f, _BiIter __l,
+                         typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
+    iterator insert(const_iterator __p, initializer_list<value_type> __il)
+        {return insert(__p, __il.begin(), __il.end());}
+    void pop_front();
+    void pop_back();
+    iterator erase(const_iterator __p);
+    iterator erase(const_iterator __f, const_iterator __l);
+
+    void swap(deque& __c);
+    void clear();
+
+    bool __invariants() const {return __base::__invariants();}
+private:
+    static size_type __recommend_blocks(size_type __n)
+    {
+        return __n / __base::__block_size + (__n % __base::__block_size != 0);
+    }
+    size_type __capacity() const
+    {
+        return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
+    }
+    size_type __front_spare() const
+    {
+        return __base::__start_;
+    }
+    size_type __back_spare() const
+    {
+        return __capacity() - (__base::__start_ + __base::size());
+    }
+
+    template <class _InpIter>
+        void __append(_InpIter __f, _InpIter __l,
+                 typename enable_if<__is_input_iterator<_InpIter>::value &&
+                                   !__is_forward_iterator<_InpIter>::value>::type* = 0);
+    template <class _ForIter>
+        void __append(_ForIter __f, _ForIter __l,
+                      typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
+    void __append(size_type __n);
+    void __append(size_type __n, const value_type& __v);
+    void __erase_to_end(const_iterator __f);
+    void __add_front_capacity();
+    void __add_front_capacity(size_type __n);
+    void __add_back_capacity();
+    void __add_back_capacity(size_type __n);
+    iterator __move_and_check(iterator __f, iterator __l, iterator __r,
+                              const_pointer& __vt);
+    iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
+                                       const_pointer& __vt);
+    void __move_construct_and_check(iterator __f, iterator __l,
+                                    iterator __r, const_pointer& __vt);
+    void __move_construct_backward_and_check(iterator __f, iterator __l,
+                                             iterator __r, const_pointer& __vt);
+
+    void __copy_assign_alloc(const deque& __c)
+        {__copy_assign_alloc(__c, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+    void __copy_assign_alloc(const deque& __c, true_type)
+        {
+            if (__base::__alloc() != __c.__alloc())
+            {
+                clear();
+                shrink_to_fit();
+            }
+            __base::__alloc() = __c.__alloc();
+            __base::__map_.__alloc() = __c.__map_.__alloc();
+        }
+
+    void __copy_assign_alloc(const deque& __c, false_type)
+        {}
+
+    void __move_assign(deque& __c, true_type);
+    void __move_assign(deque& __c, false_type);
+};
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(size_type __n)
+{
+    if (__n > 0)
+        __append(__n);
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
+{
+    if (__n > 0)
+        __append(__n, __v);
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
+    : __base(__a)
+{
+    if (__n > 0)
+        __append(__n, __v);
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIter>
+deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
+              typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
+{
+    __append(__f, __l);
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIter>
+deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
+              typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
+    : __base(__a)
+{
+    __append(__f, __l);
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(const deque& __c)
+    : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
+{
+    __append(__c.begin(), __c.end());
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
+    : __base(__a)
+{
+    __append(__c.begin(), __c.end());
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
+{
+    __append(__il.begin(), __il.end());
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
+    : __base(__a)
+{
+    __append(__il.begin(), __il.end());
+}
+
+template <class _Tp, class _Allocator>
+deque<_Tp, _Allocator>&
+deque<_Tp, _Allocator>::operator=(const deque& __c)
+{
+    if (this != &__c)
+    {
+        __copy_assign_alloc(__c);
+        assign(__c.begin(), __c.end());
+    }
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+inline
+deque<_Tp, _Allocator>::deque(deque&& __c)
+    : __base(_STD::move(__c))
+{
+}
+
+template <class _Tp, class _Allocator>
+inline
+deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
+    : __base(_STD::move(__c), __a)
+{
+    if (__a != __c.__alloc())
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__c.begin()), _I(__c.end()));
+    }
+}
+
+template <class _Tp, class _Allocator>
+inline
+deque<_Tp, _Allocator>&
+deque<_Tp, _Allocator>::operator=(deque&& __c)
+{
+    __move_assign(__c, integral_constant<bool,
+          __alloc_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
+{
+    if (__base::__alloc() != __c.__alloc())
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__c.begin()), _I(__c.end()));
+    }
+    else
+        __move_assign(__c, true_type());
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
+{
+    clear();
+    shrink_to_fit();
+    __base::__move_assign(__c);
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+template <class _InputIter>
+void
+deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
+                               typename enable_if<__is_input_iterator<_InputIter>::value &&
+                                                 !__is_random_access_iterator<_InputIter>::value>::type*)
+{
+    iterator __i = __base::begin();
+    iterator __e = __base::end();
+    for (; __f != __l && __i != __e; ++__f, ++__i)
+        *__i = *__f;
+    if (__f != __l)
+        __append(__f, __l);
+    else
+        __erase_to_end(__i);
+}
+
+template <class _Tp, class _Allocator>
+template <class _RAIter>
+void
+deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
+                               typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
+{
+    if (static_cast<size_type>(__l - __f) > __base::size())
+    {
+        _RAIter __m = __f + __base::size();
+        _STD::copy(__f, __m, __base::begin());
+        __append(__m, __l);
+    }
+    else
+        __erase_to_end(_STD::copy(__f, __l, __base::begin()));
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
+{
+    if (__n > __base::size())
+    {
+        _STD::fill_n(__base::begin(), __base::size(), __v);
+        __n -= __base::size();
+        __append(__n, __v);
+    }
+    else
+        __erase_to_end(_STD::fill_n(__base::begin(), __n, __v));
+}
+
+template <class _Tp, class _Allocator>
+inline
+_Allocator
+deque<_Tp, _Allocator>::get_allocator() const
+{
+    return __base::__alloc();
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::resize(size_type __n)
+{
+    if (__n > __base::size())
+        __append(__n - __base::size());
+    else if (__n < __base::size())
+        __erase_to_end(__base::begin() + __n);
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
+{
+    if (__n > __base::size())
+        __append(__n - __base::size(), __v);
+    else if (__n < __base::size())
+        __erase_to_end(__base::begin() + __n);
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::shrink_to_fit()
+{
+    allocator_type& __a = __base::__alloc();
+    if (empty())
+    {
+        while (__base::__map_.size() > 0)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+            __base::__map_.pop_back();
+        }
+        __base::__start_ = 0;
+    }
+    else
+    {
+        if (__front_spare() >= __base::__block_size)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
+            __base::__map_.pop_front();
+            __base::__start_ -= __base::__block_size;
+        }
+        if (__back_spare() >= __base::__block_size)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+            __base::__map_.pop_back();
+        }
+    }
+    __base::__map_.shrink_to_fit();
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::reference
+deque<_Tp, _Allocator>::operator[](size_type __i)
+{
+    size_type __p = __base::__start_ + __i;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::const_reference
+deque<_Tp, _Allocator>::operator[](size_type __i) const
+{
+    size_type __p = __base::__start_ + __i;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::reference
+deque<_Tp, _Allocator>::at(size_type __i)
+{
+    if (__i >= __base::size())
+        __base::__throw_out_of_range();
+    size_type __p = __base::__start_ + __i;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::const_reference
+deque<_Tp, _Allocator>::at(size_type __i) const
+{
+    if (__i >= __base::size())
+        __base::__throw_out_of_range();
+    size_type __p = __base::__start_ + __i;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::reference
+deque<_Tp, _Allocator>::front()
+{
+    return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+                                      + __base::__start_ % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::const_reference
+deque<_Tp, _Allocator>::front() const
+{
+    return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+                                      + __base::__start_ % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::reference
+deque<_Tp, _Allocator>::back()
+{
+    size_type __p = __base::size() + __base::__start_ - 1;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+inline
+typename deque<_Tp, _Allocator>::const_reference
+deque<_Tp, _Allocator>::back() const
+{
+    size_type __p = __base::size() + __base::__start_ - 1;
+    return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::push_back(const value_type& __v)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__back_spare() == 0)
+        __add_back_capacity();
+    // __back_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*__base::end()), __v);
+    ++__base::size();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::push_back(value_type&& __v)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__back_spare() == 0)
+        __add_back_capacity();
+    // __back_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*__base::end()), _STD::move(__v));
+    ++__base::size();
+}
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+void
+deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__back_spare() == 0)
+        __add_back_capacity();
+    // __back_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*__base::end()), _STD::forward<_Args>(__args)...);
+    ++__base::size();
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::push_front(const value_type& __v)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__front_spare() == 0)
+        __add_front_capacity();
+    // __front_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*--__base::begin()), __v);
+    --__base::__start_;
+    ++__base::size();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::push_front(value_type&& __v)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__front_spare() == 0)
+        __add_front_capacity();
+    // __front_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*--__base::begin()), _STD::move(__v));
+    --__base::__start_;
+    ++__base::size();
+}
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+void
+deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
+{
+    allocator_type& __a = __base::__alloc();
+    if (__front_spare() == 0)
+        __add_front_capacity();
+    // __front_spare() >= 1
+    __alloc_traits::construct(__a, addressof(*--__base::begin()), _STD::forward<_Args>(__args)...);
+    --__base::__start_;
+    ++__base::size();
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
+{
+    size_type __pos = __p - __base::begin();
+    size_type __to_end = __base::size() - __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < __to_end)
+    {   // insert by shifting things backward
+        if (__front_spare() == 0)
+            __add_front_capacity();
+        // __front_spare() >= 1
+        if (__pos == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*--__base::begin()), __v);
+            --__base::__start_;
+            ++__base::size();
+        }
+        else
+        {
+            const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
+            iterator __b = __base::begin();
+            iterator __bm1 = prev(__b);
+            if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
+                __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
+            __alloc_traits::construct(__a, addressof(*__bm1), _STD::move(*__b));
+            --__base::__start_;
+            ++__base::size();
+            if (__pos > 1)
+                __b = __move_and_check(next(__b), __b + __pos, __b, __vt);
+            *__b = *__vt;
+        }
+    }
+    else
+    {   // insert by shifting things forward
+        if (__back_spare() == 0)
+            __add_back_capacity();
+        // __back_capacity >= 1
+        size_type __de = __base::size() - __pos;
+        if (__de == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*__base::end()), __v);
+            ++__base::size();
+        }
+        else
+        {
+            const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
+            iterator __e = __base::end();
+            iterator __em1 = prev(__e);
+            if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
+                __vt = pointer_traits<const_pointer>::pointer_to(*__e);
+            __alloc_traits::construct(__a, addressof(*__e), _STD::move(*__em1));
+            ++__base::size();
+            if (__de > 1)
+                __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
+            *--__e = *__vt;
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
+{
+    size_type __pos = __p - __base::begin();
+    size_type __to_end = __base::size() - __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < __to_end)
+    {   // insert by shifting things backward
+        if (__front_spare() == 0)
+            __add_front_capacity();
+        // __front_spare() >= 1
+        if (__pos == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*--__base::begin()), _STD::move(__v));
+            --__base::__start_;
+            ++__base::size();
+        }
+        else
+        {
+            iterator __b = __base::begin();
+            iterator __bm1 = prev(__b);
+            __alloc_traits::construct(__a, addressof(*__bm1), _STD::move(*__b));
+            --__base::__start_;
+            ++__base::size();
+            if (__pos > 1)
+                __b = _STD::move(next(__b), __b + __pos, __b);
+            *__b = _STD::move(__v);
+        }
+    }
+    else
+    {   // insert by shifting things forward
+        if (__back_spare() == 0)
+            __add_back_capacity();
+        // __back_capacity >= 1
+        size_type __de = __base::size() - __pos;
+        if (__de == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*__base::end()), _STD::move(__v));
+            ++__base::size();
+        }
+        else
+        {
+            iterator __e = __base::end();
+            iterator __em1 = prev(__e);
+            __alloc_traits::construct(__a, addressof(*__e), _STD::move(*__em1));
+            ++__base::size();
+            if (__de > 1)
+                __e = _STD::move_backward(__e - __de, __em1, __e);
+            *--__e = _STD::move(__v);
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
+{
+    size_type __pos = __p - __base::begin();
+    size_type __to_end = __base::size() - __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < __to_end)
+    {   // insert by shifting things backward
+        if (__front_spare() == 0)
+            __add_front_capacity();
+        // __front_spare() >= 1
+        if (__pos == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*--__base::begin()), _STD::forward<_Args>(__args)...);
+            --__base::__start_;
+            ++__base::size();
+        }
+        else
+        {
+            iterator __b = __base::begin();
+            iterator __bm1 = prev(__b);
+            __alloc_traits::construct(__a, addressof(*__bm1), _STD::move(*__b));
+            --__base::__start_;
+            ++__base::size();
+            if (__pos > 1)
+                __b = _STD::move(next(__b), __b + __pos, __b);
+            *__b = value_type(_STD::forward<_Args>(__args)...);
+        }
+    }
+    else
+    {   // insert by shifting things forward
+        if (__back_spare() == 0)
+            __add_back_capacity();
+        // __back_capacity >= 1
+        size_type __de = __base::size() - __pos;
+        if (__de == 0)
+        {
+            __alloc_traits::construct(__a, addressof(*__base::end()), _STD::forward<_Args>(__args)...);
+            ++__base::size();
+        }
+        else
+        {
+            iterator __e = __base::end();
+            iterator __em1 = prev(__e);
+            __alloc_traits::construct(__a, addressof(*__e), _STD::move(*__em1));
+            ++__base::size();
+            if (__de > 1)
+                __e = _STD::move_backward(__e - __de, __em1, __e);
+            *--__e = value_type(_STD::forward<_Args>(__args)...);
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
+{
+    size_type __pos = __p - __base::begin();
+    size_type __to_end = __base::size() - __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < __to_end)
+    {   // insert by shifting things backward
+        if (__n > __front_spare())
+            __add_front_capacity(__n - __front_spare());
+        // __n <= __front_spare()
+        size_type __old_n = __n;
+        iterator __old_begin = __base::begin();
+        iterator __i = __old_begin;
+        if (__n > __pos)
+        {
+            for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
+                __alloc_traits::construct(__a, addressof(*--__i), __v);
+            __n = __pos;
+        }
+        if (__n > 0)
+        {
+            const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
+            iterator __obn = __old_begin + __n;
+            __move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
+            if (__n < __pos)
+                __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
+            _STD::fill_n(__old_begin, __n, *__vt);
+        }
+    }
+    else
+    {   // insert by shifting things forward
+        size_type __back_capacity = __back_spare();
+        if (__n > __back_capacity)
+            __add_back_capacity(__n - __back_capacity);
+        // __n <= __back_capacity
+        size_type __old_n = __n;
+        iterator __old_end = __base::end();
+        iterator __i = __old_end;
+        size_type __de = __base::size() - __pos;
+        if (__n > __de)
+        {
+            for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
+                __alloc_traits::construct(__a, addressof(*__i), __v);
+            __n = __de;
+        }
+        if (__n > 0)
+        {
+            const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
+            iterator __oen = __old_end - __n;
+            __move_construct_and_check(__oen, __old_end, __i, __vt);
+            if (__n < __de)
+                __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt);
+            _STD::fill_n(__old_end - __n, __n, *__vt);
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIter>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
+                               typename enable_if<__is_input_iterator<_InputIter>::value
+                                               &&!__is_bidirectional_iterator<_InputIter>::value>::type*)
+{
+    __split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
+    __buf.__construct_at_end(__f, __l);
+    typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi;
+    return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
+}
+
+template <class _Tp, class _Allocator>
+template <class _BiIter>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
+                               typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
+{
+    size_type __n = _STD::distance(__f, __l);
+    size_type __pos = __p - __base::begin();
+    size_type __to_end = __base::size() - __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < __to_end)
+    {   // insert by shifting things backward
+        if (__n > __front_spare())
+            __add_front_capacity(__n - __front_spare());
+        // __n <= __front_spare()
+        size_type __old_n = __n;
+        iterator __old_begin = __base::begin();
+        iterator __i = __old_begin;
+        _BiIter __m = __f;
+        if (__n > __pos)
+        {
+            __m = __pos < __n / 2 ? _STD::prev(__l, __pos) : _STD::next(__f, __n - __pos);
+            for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
+                __alloc_traits::construct(__a, addressof(*--__i), *--__j);
+            __n = __pos;
+        }
+        if (__n > 0)
+        {
+            iterator __obn = __old_begin + __n;
+            for (iterator __j = __obn; __j != __old_begin;)
+            {
+                __alloc_traits::construct(__a, addressof(*--__i), _STD::move(*--__j));
+                --__base::__start_;
+                ++__base::size();
+            }
+            if (__n < __pos)
+                __old_begin = _STD::move(__obn, __old_begin + __pos, __old_begin);
+            _STD::copy(__m, __l, __old_begin);
+        }
+    }
+    else
+    {   // insert by shifting things forward
+        size_type __back_capacity = __back_spare();
+        if (__n > __back_capacity)
+            __add_back_capacity(__n - __back_capacity);
+        // __n <= __back_capacity
+        size_type __old_n = __n;
+        iterator __old_end = __base::end();
+        iterator __i = __old_end;
+        _BiIter __m = __l;
+        size_type __de = __base::size() - __pos;
+        if (__n > __de)
+        {
+            __m = __de < __n / 2 ? _STD::next(__f, __de) : _STD::prev(__l, __n - __de);
+            for (_BiIter __j = __m; __j != __l; ++__i, ++__j, ++__base::size())
+                __alloc_traits::construct(__a, addressof(*__i), *__j);
+            __n = __de;
+        }
+        if (__n > 0)
+        {
+            iterator __oen = __old_end - __n;
+            for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
+                __alloc_traits::construct(__a, addressof(*__i), _STD::move(*__j));
+            if (__n < __de)
+                __old_end = _STD::move_backward(__old_end - __de, __oen, __old_end);
+            _STD::copy_backward(__f, __m, __old_end);
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+template <class _Tp, class _Allocator>
+template <class _InpIter>
+void
+deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
+                                 typename enable_if<__is_input_iterator<_InpIter>::value &&
+                                                   !__is_forward_iterator<_InpIter>::value>::type*)
+{
+    for (; __f != __l; ++__f)
+        push_back(*__f);
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForIter>
+void
+deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
+                                 typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
+{
+    size_type __n = _STD::distance(__f, __l);
+    allocator_type& __a = __base::__alloc();
+    size_type __back_capacity = __back_spare();
+    if (__n > __back_capacity)
+        __add_back_capacity(__n - __back_capacity);
+    // __n <= __back_capacity
+    for (iterator __i = __base::end(); __f != __l; ++__i, ++__f, ++__base::size())
+        __alloc_traits::construct(__a, addressof(*__i), *__f);
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__append(size_type __n)
+{
+    allocator_type& __a = __base::__alloc();
+    size_type __back_capacity = __back_spare();
+    if (__n > __back_capacity)
+        __add_back_capacity(__n - __back_capacity);
+    // __n <= __back_capacity
+    for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
+        __alloc_traits::construct(__a, addressof(*__i));
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
+{
+    allocator_type& __a = __base::__alloc();
+    size_type __back_capacity = __back_spare();
+    if (__n > __back_capacity)
+        __add_back_capacity(__n - __back_capacity);
+    // __n <= __back_capacity
+    for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
+        __alloc_traits::construct(__a, addressof(*__i), __v);
+}
+
+// Create front capacity for one block of elements.
+// Strong guarantee.  Either do it or don't touch anything.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__add_front_capacity()
+{
+    allocator_type& __a = __base::__alloc();
+    if (__back_spare() >= __base::__block_size)
+    {
+        __base::__start_ += __base::__block_size;
+        pointer __pt = __base::__map_.back();
+        __base::__map_.pop_back();
+        __base::__map_.push_front(__pt);
+    }
+    // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
+    else if (__base::__map_.size() < __base::__map_.capacity())
+    {   // we can put the new buffer into the map, but don't shift things around
+        // until all buffers are allocated.  If we throw, we don't need to fix
+        // anything up (any added buffers are undetectible)
+        if (__base::__map_.__front_spare() > 0)
+            __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
+        else
+        {
+            __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+            // Done allocating, reorder capacity
+            pointer __pt = __base::__map_.back();
+            __base::__map_.pop_back();
+            __base::__map_.push_front(__pt);
+        }
+        __base::__start_ = __base::__map_.size() == 1 ?
+                               __base::__block_size / 2 :
+                               __base::__start_ + __base::__block_size;
+    }
+    // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
+    else
+    {
+        __split_buffer<pointer, typename __base::__pointer_allocator&>
+            __buf(max<size_type>(2 * __base::__map_.capacity(), 1),
+                  0, __base::__map_.__alloc());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __alloc_traits::deallocate(__a, __buf.front(), __base::__block_size);
+            throw;
+        }
+#endif
+        for (typename __base::__map_pointer __i = __base::__map_.begin();
+                __i != __base::__map_.end(); ++__i)
+            __buf.push_back(*__i);
+        _STD::swap(__base::__map_.__first_, __buf.__first_);
+        _STD::swap(__base::__map_.__begin_, __buf.__begin_);
+        _STD::swap(__base::__map_.__end_, __buf.__end_);
+        _STD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
+        __base::__start_ = __base::__map_.size() == 1 ?
+                               __base::__block_size / 2 :
+                               __base::__start_ + __base::__block_size;
+    }
+}
+
+// Create front capacity for __n elements.
+// Strong guarantee.  Either do it or don't touch anything.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
+{
+    allocator_type& __a = __base::__alloc();
+    size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
+    // Number of unused blocks at back:
+    size_type __back_capacity = __back_spare() / __base::__block_size;
+    __back_capacity = min(__back_capacity, __nb);  // don't take more than you need
+    __nb -= __back_capacity;  // number of blocks need to allocate
+    // If __nb == 0, then we have sufficient capacity.
+    if (__nb == 0)
+    {
+        __base::__start_ += __base::__block_size * __back_capacity;
+        for (; __back_capacity > 0; --__back_capacity)
+        {
+            pointer __pt = __base::__map_.back();
+            __base::__map_.pop_back();
+            __base::__map_.push_front(__pt);
+        }
+    }
+    // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
+    else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
+    {   // we can put the new buffers into the map, but don't shift things around
+        // until all buffers are allocated.  If we throw, we don't need to fix
+        // anything up (any added buffers are undetectible)
+        for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
+        {
+            if (__base::__map_.__front_spare() == 0)
+                break;
+            __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
+        }
+        for (; __nb > 0; --__nb, ++__back_capacity)
+            __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+        // Done allocating, reorder capacity
+        __base::__start_ += __back_capacity * __base::__block_size;
+        for (; __back_capacity > 0; --__back_capacity)
+        {
+            pointer __pt = __base::__map_.back();
+            __base::__map_.pop_back();
+            __base::__map_.push_front(__pt);
+        }
+    }
+    // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
+    else
+    {
+        size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
+        __split_buffer<pointer, typename __base::__pointer_allocator&>
+            __buf(max<size_type>(2* __base::__map_.capacity(),
+                                 __nb + __base::__map_.size()),
+                  0, __base::__map_.__alloc());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (; __nb > 0; --__nb)
+                __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            for (typename __base::__map_pointer __i = __buf.begin();
+                    __i != __buf.end(); ++__i)
+                __alloc_traits::deallocate(__a, *__i, __base::__block_size);
+            throw;
+        }
+#endif
+        for (; __back_capacity > 0; --__back_capacity)
+        {
+            __buf.push_back(__base::__map_.back());
+            __base::__map_.pop_back();
+        }
+        for (typename __base::__map_pointer __i = __base::__map_.begin();
+                __i != __base::__map_.end(); ++__i)
+            __buf.push_back(*__i);
+        _STD::swap(__base::__map_.__first_, __buf.__first_);
+        _STD::swap(__base::__map_.__begin_, __buf.__begin_);
+        _STD::swap(__base::__map_.__end_, __buf.__end_);
+        _STD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
+        __base::__start_ += __ds;
+    }
+}
+
+// Create back capacity for one block of elements.
+// Strong guarantee.  Either do it or don't touch anything.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__add_back_capacity()
+{
+    allocator_type& __a = __base::__alloc();
+    if (__front_spare() >= __base::__block_size)
+    {
+        __base::__start_ -= __base::__block_size;
+        pointer __pt = __base::__map_.front();
+        __base::__map_.pop_front();
+        __base::__map_.push_back(__pt);
+    }
+    // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
+    else if (__base::__map_.size() < __base::__map_.capacity())
+    {   // we can put the new buffer into the map, but don't shift things around
+        // until it is allocated.  If we throw, we don't need to fix
+        // anything up (any added buffers are undetectible)
+        if (__base::__map_.__back_spare() != 0)
+            __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+        else
+        {
+            __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
+            // Done allocating, reorder capacity
+            pointer __pt = __base::__map_.front();
+            __base::__map_.pop_front();
+            __base::__map_.push_back(__pt);
+        }
+    }
+    // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
+    else
+    {
+        __split_buffer<pointer, typename __base::__pointer_allocator&>
+            __buf(max<size_type>(2* __base::__map_.capacity(), 1),
+                  __base::__map_.size(),
+                  __base::__map_.__alloc());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            __alloc_traits::deallocate(__a, __buf.back(), __base::__block_size);
+            throw;
+        }
+#endif
+        for (typename __base::__map_pointer __i = __base::__map_.end();
+                __i != __base::__map_.begin();)
+            __buf.push_front(*--__i);
+        _STD::swap(__base::__map_.__first_, __buf.__first_);
+        _STD::swap(__base::__map_.__begin_, __buf.__begin_);
+        _STD::swap(__base::__map_.__end_, __buf.__end_);
+        _STD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
+    }
+}
+
+// Create back capacity for __n elements.
+// Strong guarantee.  Either do it or don't touch anything.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
+{
+    allocator_type& __a = __base::__alloc();
+    size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
+    // Number of unused blocks at front:
+    size_type __front_capacity = __front_spare() / __base::__block_size;
+    __front_capacity = min(__front_capacity, __nb);  // don't take more than you need
+    __nb -= __front_capacity;  // number of blocks need to allocate
+    // If __nb == 0, then we have sufficient capacity.
+    if (__nb == 0)
+    {
+        __base::__start_ -= __base::__block_size * __front_capacity;
+        for (; __front_capacity > 0; --__front_capacity)
+        {
+            pointer __pt = __base::__map_.front();
+            __base::__map_.pop_front();
+            __base::__map_.push_back(__pt);
+        }
+    }
+    // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
+    else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
+    {   // we can put the new buffers into the map, but don't shift things around
+        // until all buffers are allocated.  If we throw, we don't need to fix
+        // anything up (any added buffers are undetectible)
+        for (; __nb > 0; --__nb)
+        {
+            if (__base::__map_.__back_spare() == 0)
+                break;
+            __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+        }
+        for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
+                                 __base::__block_size - (__base::__map_.size() == 1))
+            __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
+        // Done allocating, reorder capacity
+        __base::__start_ -= __base::__block_size * __front_capacity;
+        for (; __front_capacity > 0; --__front_capacity)
+        {
+            pointer __pt = __base::__map_.front();
+            __base::__map_.pop_front();
+            __base::__map_.push_back(__pt);
+        }
+    }
+    // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
+    else
+    {
+        size_type __ds = __front_capacity * __base::__block_size;
+        __split_buffer<pointer, typename __base::__pointer_allocator&>
+            __buf(max<size_type>(2* __base::__map_.capacity(),
+                                 __nb + __base::__map_.size()),
+                  __base::__map_.size() - __front_capacity,
+                  __base::__map_.__alloc());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (; __nb > 0; --__nb)
+                __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            for (typename __base::__map_pointer __i = __buf.begin();
+                    __i != __buf.end(); ++__i)
+                __alloc_traits::deallocate(__a, *__i, __base::__block_size);
+            throw;
+        }
+#endif
+        for (; __front_capacity > 0; --__front_capacity)
+        {
+            __buf.push_back(__base::__map_.front());
+            __base::__map_.pop_front();
+        }
+        for (typename __base::__map_pointer __i = __base::__map_.end();
+                __i != __base::__map_.begin();)
+            __buf.push_front(*--__i);
+        _STD::swap(__base::__map_.__first_, __buf.__first_);
+        _STD::swap(__base::__map_.__begin_, __buf.__begin_);
+        _STD::swap(__base::__map_.__end_, __buf.__end_);
+        _STD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
+        __base::__start_ -= __ds;
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::pop_front()
+{
+    allocator_type& __a = __base::__alloc();
+    __alloc_traits::destroy(__a, *(__base::__map_.begin() +
+                                   __base::__start_ / __base::__block_size) +
+                                   __base::__start_ % __base::__block_size);
+    --__base::size();
+    if (++__base::__start_ >= 2 * __base::__block_size)
+    {
+        __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
+        __base::__map_.pop_front();
+        __base::__start_ -= __base::__block_size;
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::pop_back()
+{
+    allocator_type& __a = __base::__alloc();
+    size_type __p = __base::size() + __base::__start_ - 1;
+    __alloc_traits::destroy(__a, *(__base::__map_.begin() +
+                                   __p / __base::__block_size) +
+                                   __p % __base::__block_size);
+    --__base::size();
+    if (__back_spare() >= 2 * __base::__block_size)
+    {
+        __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+        __base::__map_.pop_back();
+    }
+}
+
+// move assign [__f, __l) to [__r, __r + (__l-__f)).
+// If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
+                                         const_pointer& __vt)
+{
+    // as if
+    //   for (; __f != __l; ++__f, ++__r)
+    //       *__r = _STD::move(*__f);
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + __base::__block_size;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        if (__fb <= __vt && __vt < __fe)
+            __vt = (const_iterator(__f.__m_iter_, __vt) -= __f - __r).__ptr_;
+        __r = _STD::move(__fb, __fe, __r);
+        __n -= __bs;
+        __f += __bs;
+    }
+    return __r;
+}
+
+// move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
+// If __vt points into [__f, __l), then add (__r - __l) to __vt.
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
+                                                  const_pointer& __vt)
+{
+    // as if
+    //   while (__f != __l)
+    //       *--__r = _STD::move(*--__l);
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        if (__lb <= __vt && __vt < __le)
+            __vt = (const_iterator(__l.__m_iter_, __vt) += __r - __l - 1).__ptr_;
+        __r = _STD::move_backward(__lb, __le, __r);
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+    return __r;
+}
+
+// move construct [__f, __l) to [__r, __r + (__l-__f)).
+// If __vt points into [__f, __l), then add (__r - __f) to __vt.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
+                                                   iterator __r, const_pointer& __vt)
+{
+    allocator_type& __a = __base::__alloc();
+    // as if
+    //   for (; __f != __l; ++__r, ++__f, ++__base::size())
+    //       __alloc_traits::construct(__a, addressof(*__r), _STD::move(*__f));
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        pointer __fb = __f.__ptr_;
+        pointer __fe = *__f.__m_iter_ + __base::__block_size;
+        difference_type __bs = __fe - __fb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __fe = __fb + __bs;
+        }
+        if (__fb <= __vt && __vt < __fe)
+            __vt = (const_iterator(__f.__m_iter_, __vt) += __r - __f).__ptr_;
+        for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
+            __alloc_traits::construct(__a, addressof(*__r), _STD::move(*__fb));
+        __n -= __bs;
+        __f += __bs;
+    }
+}
+
+// move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
+// If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
+                                                            iterator __r, const_pointer& __vt)
+{
+    allocator_type& __a = __base::__alloc();
+    // as if
+    //   for (iterator __j = __l; __j != __f;)
+    //   {
+    //       __alloc_traitsconstruct(__a, addressof(*--__r), _STD::move(*--__j));
+    //       --__base::__start_;
+    //       ++__base::size();
+    //   }
+    difference_type __n = __l - __f;
+    while (__n > 0)
+    {
+        --__l;
+        pointer __lb = *__l.__m_iter_;
+        pointer __le = __l.__ptr_ + 1;
+        difference_type __bs = __le - __lb;
+        if (__bs > __n)
+        {
+            __bs = __n;
+            __lb = __le - __bs;
+        }
+        if (__lb <= __vt && __vt < __le)
+            __vt = (const_iterator(__l.__m_iter_, __vt) -= __l - __r + 1).__ptr_;
+        while (__le != __lb)
+        {
+            __alloc_traits::construct(__a, addressof(*--__r), _STD::move(*--__le));
+            --__base::__start_;
+            ++__base::size();
+        }
+        __n -= __bs;
+        __l -= __bs - 1;
+    }
+}
+
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::erase(const_iterator __f)
+{
+    difference_type __n = 1;
+    iterator __b = __base::begin();
+    difference_type __pos = __f - __b;
+    iterator __p = __b + __pos;
+    allocator_type& __a = __base::__alloc();
+    if (__pos < (__base::size() - 1) / 2)
+    {   // erase from front
+        _STD::move_backward(__b, __p, next(__p));
+        __alloc_traits::destroy(__a, addressof(*__b));
+        --__base::size();
+        ++__base::__start_;
+        if (__front_spare() >= 2 * __base::__block_size)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
+            __base::__map_.pop_front();
+            __base::__start_ -= __base::__block_size;
+        }
+    }
+    else
+    {   // erase from back
+        iterator __i = _STD::move(next(__p), __base::end(), __p);
+        __alloc_traits::destroy(__a, addressof(*__i));
+        --__base::size();
+        if (__back_spare() >= 2 * __base::__block_size)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+            __base::__map_.pop_back();
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+template <class _Tp, class _Allocator>
+typename deque<_Tp, _Allocator>::iterator
+deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
+{
+    difference_type __n = __l - __f;
+    iterator __b = __base::begin();
+    difference_type __pos = __f - __b;
+    iterator __p = __b + __pos;
+    if (__n > 0)
+    {
+        allocator_type& __a = __base::__alloc();
+        if (__pos < (__base::size() - __n) / 2)
+        {   // erase from front
+            iterator __i = _STD::move_backward(__b, __p, __p + __n);
+            for (; __b != __i; ++__b)
+                __alloc_traits::destroy(__a, addressof(*__b));
+            __base::size() -= __n;
+            __base::__start_ += __n;
+            while (__front_spare() >= 2 * __base::__block_size)
+            {
+                __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
+                __base::__map_.pop_front();
+                __base::__start_ -= __base::__block_size;
+            }
+        }
+        else
+        {   // erase from back
+            iterator __i = _STD::move(__p + __n, __base::end(), __p);
+            for (iterator __e = __base::end(); __i != __e; ++__i)
+                __alloc_traits::destroy(__a, addressof(*__i));
+            __base::size() -= __n;
+            while (__back_spare() >= 2 * __base::__block_size)
+            {
+                __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+                __base::__map_.pop_back();
+            }
+        }
+    }
+    return __base::begin() + __pos;
+}
+
+template <class _Tp, class _Allocator>
+void
+deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
+{
+    iterator __e = __base::end();
+    difference_type __n = __e - __f;
+    if (__n > 0)
+    {
+        allocator_type& __a = __base::__alloc();
+        iterator __b = __base::begin();
+        difference_type __pos = __f - __b;
+        for (iterator __p = __b + __pos; __p != __e; ++__p)
+            __alloc_traits::destroy(__a, addressof(*__p));
+        __base::size() -= __n;
+        while (__back_spare() >= 2 * __base::__block_size)
+        {
+            __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
+            __base::__map_.pop_back();
+        }
+    }
+}
+
+template <class _Tp, class _Allocator>
+inline
+void
+deque<_Tp, _Allocator>::swap(deque& __c)
+{
+    __base::swap(__c);
+}
+
+template <class _Tp, class _Allocator>
+inline
+void
+deque<_Tp, _Allocator>::clear()
+{
+    __base::clear();
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
+    return __sz == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_DEQUE
diff --git a/include/exception b/include/exception
new file mode 100644
index 0000000..9fdbcae
--- /dev/null
+++ b/include/exception
@@ -0,0 +1,155 @@
+// -*- C++ -*-
+//===-------------------------- exception ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXCEPTION
+#define _LIBCPP_EXCEPTION
+
+/*
+    exception synopsis
+
+namespace std
+{
+
+class exception
+{
+public:
+    exception() throw();
+    exception(const exception&) throw();
+    exception& operator=(const exception&) throw();
+    virtual ~exception() throw();
+    virtual const char* what() const throw();
+};
+
+class bad_exception
+    : public exception
+{
+public:
+    bad_exception() throw();
+    bad_exception(const bad_exception&) throw();
+    bad_exception& operator=(const bad_exception&) throw();
+    virtual ~bad_exception() throw();
+    virtual const char* what() const throw();
+};
+
+typedef void (*unexpected_handler)();
+unexpected_handler set_unexpected(unexpected_handler  f ) throw();
+void unexpected [[noreturn]] ();
+
+typedef void (*terminate_handler)();
+terminate_handler set_terminate(terminate_handler  f ) throw();
+void terminate [[noreturn]] ();
+
+bool uncaught_exception() throw();
+
+typedef unspecified exception_ptr;
+
+exception_ptr current_exception();
+void rethrow_exception [[noreturn]] (exception_ptr p);
+template<class E> exception_ptr make_exception_ptr(E e);
+
+class nested_exception
+{
+public:
+    nested_exception() throw();
+    nested_exception(const nested_exception&) throw() = default;
+    nested_exception& operator=(const nested_exception&) throw() = default;
+    virtual ~nested_exception() = default;
+
+    // access functions
+    void rethrow_nested [[noreturn]] () const;
+    exception_ptr nested_ptr() const;
+};
+
+template <class T> void throw_with_nested [[noreturn]] (T&& t);
+template <class E> void rethrow_if_nested(const E& e);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cstddef>
+
+#pragma GCC system_header
+
+namespace std  // purposefully not using versioning namespace
+{
+
+class _LIBCPP_EXCEPTION_ABI exception
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY exception() throw() {}
+    virtual ~exception() throw();
+    virtual const char* what() const throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI bad_exception
+    : public exception
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY bad_exception() throw() {}
+    virtual ~bad_exception() throw();
+    virtual const char* what() const throw();
+};
+
+typedef void (*unexpected_handler)();
+_LIBCPP_VISIBLE unexpected_handler set_unexpected(unexpected_handler) throw();
+_LIBCPP_VISIBLE void unexpected();
+
+typedef void (*terminate_handler)();
+_LIBCPP_VISIBLE terminate_handler set_terminate(terminate_handler) throw();
+_LIBCPP_VISIBLE void terminate() __attribute__((__noreturn__));
+
+_LIBCPP_VISIBLE bool uncaught_exception() throw();
+
+class exception_ptr;
+
+exception_ptr current_exception();
+void rethrow_exception(exception_ptr);  // noreturn
+
+class exception_ptr
+{
+    void* __ptr_;
+public:
+    exception_ptr()  : __ptr_() {}
+    exception_ptr(nullptr_t) : __ptr_() {}
+    exception_ptr(const exception_ptr&);
+    exception_ptr& operator=(const exception_ptr&);
+    ~exception_ptr();
+
+    // explicit
+        operator bool() const {return __ptr_ != nullptr;}
+
+    friend bool operator==(const exception_ptr& __x, const exception_ptr& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const exception_ptr& __x, const exception_ptr& __y)
+        {return !(__x == __y);}
+
+    friend exception_ptr current_exception();
+    friend void rethrow_exception(exception_ptr);  // noreturn
+};
+
+template<class _E>
+exception_ptr
+make_exception_ptr(_E __e)
+{
+    try
+    {
+        throw __e;
+    }
+    catch (...)
+    {
+        return current_exception();
+    }
+}
+
+}  // std
+
+#endif  // _LIBCPP_EXCEPTION
diff --git a/include/ext/hash_map b/include/ext/hash_map
new file mode 100644
index 0000000..16b7ca1
--- /dev/null
+++ b/include/ext/hash_map
@@ -0,0 +1,908 @@
+// -*- C++ -*-
+//===-------------------------- hash_map ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_HASH_MAP
+#define _LIBCPP_HASH_MAP
+
+/*
+
+    hash_map synopsis
+
+namespace __gnu_cxx
+{
+
+template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+          class Alloc = allocator<pair<const Key, T>>>
+class hash_map
+{
+public:
+    // types
+    typedef Key                                                        key_type;
+    typedef T                                                          mapped_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef pair<const key_type, mapped_type>                          value_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+
+    explicit hash_map(size_type n = 193, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        hash_map(InputIterator f, InputIterator l,
+                      size_type n = 193, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    hash_map(const hash_map&);
+    ~hash_map();
+    hash_map& operator=(const hash_map&);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+
+    pair<iterator, bool> insert(const value_type& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+
+    void erase(const_iterator position);
+    size_type erase(const key_type& k);
+    void erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(hash_map&);
+
+    hasher hash_funct() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    mapped_type& operator[](const key_type& k);
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type elems_in_bucket(size_type n) const;
+
+    void resize(size_type n);
+};
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    void swap(hash_map<Key, T, Hash, Pred, Alloc>& x,
+              hash_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x,
+               const hash_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x,
+               const hash_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+          class Alloc = allocator<pair<const Key, T>>>
+class hash_multimap
+{
+public:
+    // types
+    typedef Key                                                        key_type;
+    typedef T                                                          mapped_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef pair<const key_type, mapped_type>                          value_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+
+    explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        hash_multimap(InputIterator f, InputIterator l,
+                      size_type n = 193, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    explicit hash_multimap(const allocator_type&);
+    hash_multimap(const hash_multimap&);
+    ~hash_multimap();
+    hash_multimap& operator=(const hash_multimap&);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+
+    iterator insert(const value_type& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+
+    void erase(const_iterator position);
+    size_type erase(const key_type& k);
+    void erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(hash_multimap&);
+
+    hasher hash_funct() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type elems_in_bucket(size_type n) const;
+
+    void resize(size_type n);
+};
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x,
+              hash_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,
+               const hash_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,
+               const hash_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+}  // __gnu_cxx
+
+*/
+
+#include <__config>
+#include <__hash_table>
+#include <functional>
+#include <stdexcept>
+
+#warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>
+
+#pragma GCC system_header
+
+namespace __gnu_cxx {
+
+using namespace std;
+
+template <class _Tp, class _Hash, bool = is_empty<_Hash>::value>
+class __hash_map_hasher
+    : private _Hash
+{
+public:
+    __hash_map_hasher() : _Hash() {}
+    __hash_map_hasher(const _Hash& __h) : _Hash(__h) {}
+    const _Hash& hash_function() const {return *this;}
+    size_t operator()(const _Tp& __x) const
+        {return static_cast<const _Hash&>(*this)(__x.first);}
+    size_t operator()(const typename _Tp::first_type& __x) const
+        {return static_cast<const _Hash&>(*this)(__x);}
+};
+
+template <class _Tp, class _Hash>
+class __hash_map_hasher<_Tp, _Hash, false>
+{
+    _Hash __hash_;
+public:
+    __hash_map_hasher() : __hash_() {}
+    __hash_map_hasher(const _Hash& __h) : __hash_(__h) {}
+    const _Hash& hash_function() const {return __hash_;}
+    size_t operator()(const _Tp& __x) const
+        {return __hash_(__x.first);}
+    size_t operator()(const typename _Tp::first_type& __x) const
+        {return __hash_(__x);}
+};
+
+template <class _Tp, class _Pred, bool = is_empty<_Pred>::value>
+class __hash_map_equal
+    : private _Pred
+{
+public:
+    __hash_map_equal() : _Pred() {}
+    __hash_map_equal(const _Pred& __p) : _Pred(__p) {}
+    const _Pred& key_eq() const {return *this;}
+    bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
+    bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+        {return static_cast<const _Pred&>(*this)(__x, __y.first);}
+    bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+        {return static_cast<const _Pred&>(*this)(__x.first, __y);}
+    bool operator()(const typename _Tp::first_type& __x, 
+                    const typename _Tp::first_type& __y) const
+        {return static_cast<const _Pred&>(*this)(__x, __y);}
+};
+
+template <class _Tp, class _Pred>
+class __hash_map_equal<_Tp, _Pred, false>
+{
+    _Pred __pred_;
+public:
+    __hash_map_equal() : __pred_() {}
+    __hash_map_equal(const _Pred& __p) : __pred_(__p) {}
+    const _Pred& key_eq() const {return __pred_;}
+    bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __pred_(__x.first, __y.first);}
+    bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+        {return __pred_(__x, __y.first);}
+    bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+        {return __pred_(__x.first, __y);}
+    bool operator()(const typename _Tp::first_type& __x,
+                    const typename _Tp::first_type& __y) const
+        {return __pred_(__x, __y);}
+};
+
+template <class _Alloc>
+class __hash_map_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:
+    typedef typename value_type::first_type     first_type;
+    typedef typename value_type::second_type    second_type;
+
+    allocator_type& __na_;
+
+    __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
+
+public:
+    bool __first_constructed;
+    bool __second_constructed;
+
+    explicit __hash_map_node_destructor(allocator_type& __na)
+        : __na_(__na),
+          __first_constructed(false),
+          __second_constructed(false)
+        {}
+
+#ifdef _LIBCPP_MOVE
+    __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
+        : __na_(__x.__na_),
+          __first_constructed(__x.__value_constructed),
+          __second_constructed(__x.__value_constructed)
+        {
+            __x.__value_constructed = false;
+        }
+#else
+    __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
+        : __na_(__x.__na_),
+          __first_constructed(__x.__value_constructed),
+          __second_constructed(__x.__value_constructed)
+        {
+            const_cast<bool&>(__x.__value_constructed) = false;
+        }
+#endif
+
+    void operator()(pointer __p)
+    {
+        if (__second_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.second));
+        if (__first_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.first));
+        if (__p)
+            __alloc_traits::deallocate(__na_, __p, 1);
+    }
+};
+
+template <class _HashIterator>
+class __hash_map_iterator
+{
+    _HashIterator __i_;
+
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::second_type      mapped_type;
+public:
+    typedef forward_iterator_tag                                 iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::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;
+
+    __hash_map_iterator() {}
+
+    __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __hash_map_iterator& operator++() {++__i_; return *this;}
+    __hash_map_iterator operator++(int)
+    {
+        __hash_map_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class, class> friend class hash_map;
+    template <class, class, class, class, class> friend class hash_multimap;
+    template <class> friend class __hash_const_iterator;
+    template <class> friend class __hash_const_local_iterator;
+    template <class> friend class __hash_map_const_iterator;
+};
+
+template <class _HashIterator>
+class __hash_map_const_iterator
+{
+    _HashIterator __i_;
+
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::second_type      mapped_type;
+public:
+    typedef forward_iterator_tag                                 iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::difference_type              difference_type;
+    typedef const value_type&                                    reference;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
+
+    __hash_map_const_iterator() {}
+
+    __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
+    __hash_map_const_iterator(
+            __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
+                : __i_(__i.__i_) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __hash_map_const_iterator& operator++() {++__i_; return *this;}
+    __hash_map_const_iterator operator++(int)
+    {
+        __hash_map_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class, class> friend class hash_map;
+    template <class, class, class, class, class> friend class hash_multimap;
+    template <class> friend class __hash_const_iterator;
+    template <class> friend class __hash_const_local_iterator;
+};
+
+template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
+          class _Alloc = allocator<pair<const _Key, _Tp> > >
+class hash_map
+{
+public:
+    // types
+    typedef _Key                                           key_type;
+    typedef _Tp                                            mapped_type;
+    typedef _Hash                                          hasher;
+    typedef _Pred                                          key_equal;
+    typedef _Alloc                                         allocator_type;
+    typedef pair<const key_type, mapped_type>              value_type;
+    typedef value_type&                                    reference;
+    typedef const value_type&                              const_reference;
+
+private:
+    typedef pair<key_type, mapped_type>                    __value_type;
+    typedef __hash_map_hasher<__value_type, hasher>   __hasher;
+    typedef __hash_map_equal<__value_type, key_equal> __key_equal;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                           __allocator_type;
+
+    typedef __hash_table<__value_type, __hasher,
+                         __key_equal,  __allocator_type>   __table;
+
+    __table __table_;
+
+    typedef typename __table::__node_pointer               __node_pointer;
+    typedef typename __table::__node_const_pointer         __node_const_pointer;
+    typedef typename __table::__node_traits                __node_traits;
+    typedef typename __table::__node_allocator             __node_allocator;
+    typedef typename __table::__node                       __node;
+    typedef __hash_map_node_destructor<__node_allocator>   _D;
+    typedef unique_ptr<__node, _D>                         __node_holder;
+    typedef allocator_traits<allocator_type>               __alloc_traits;
+public:
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+
+    typedef __hash_map_iterator<typename __table::iterator>       iterator;
+    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
+
+    hash_map() {__table_.rehash(193);}
+    explicit hash_map(size_type __n, const hasher& __hf = hasher(),
+                           const key_equal& __eql = key_equal());
+    hash_map(size_type __n, const hasher& __hf,
+                  const key_equal& __eql,
+                  const allocator_type& __a);
+    template <class _InputIterator>
+        hash_map(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        hash_map(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        hash_map(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf,
+                      const key_equal& __eql,
+                      const allocator_type& __a);
+    hash_map(const hash_map& __u);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+
+    pair<iterator, bool> insert(const value_type& __x)
+        {return __table_.__insert_unique(__x);}
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+
+    void erase(const_iterator __p) {__table_.erase(__p.__i_);}
+    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
+    void erase(const_iterator __first, const_iterator __last)
+        {__table_.erase(__first.__i_, __last.__i_);}
+    void clear() {__table_.clear();}
+
+    void swap(hash_map& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_funct() const
+        {return __table_.hash_function().hash_function();}
+    key_equal key_eq() const
+        {return __table_.key_eq().key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_unique(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_unique(__k);}
+
+    mapped_type& operator[](const key_type& __k);
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type elems_in_bucket(size_type __n) const
+        {return __table_.bucket_size(__n);}
+
+    void resize(size_type __n) {__table_.rehash(__n);}
+
+private:
+    __node_holder __construct_node(const key_type& __k);
+};
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        _InputIterator __first, _InputIterator __last)
+{
+    __table_.rehash(193);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
+        const hash_map& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first), __k);
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second));
+    __h.get_deleter().__second_constructed = true;
+    return _STD::move(__h);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                       _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_unique(*__first);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+_Tp&
+hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
+{
+    iterator __i = find(__k);
+    if (__i != end())
+        return __i->second;
+    __node_holder __h = __construct_node(__k);
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    __h.release();
+    return __r.first->second;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+     hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
+            __i != __ex; ++__i)
+    {
+        const_iterator __j = __y.find(__i->first);
+        if (__j == __ey || !(*__i == *__j))
+            return false;
+    }
+    return true;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
+          class _Alloc = allocator<pair<const _Key, _Tp> > >
+class hash_multimap
+{
+public:
+    // types
+    typedef _Key                                           key_type;
+    typedef _Tp                                            mapped_type;
+    typedef _Hash                                          hasher;
+    typedef _Pred                                          key_equal;
+    typedef _Alloc                                         allocator_type;
+    typedef pair<const key_type, mapped_type>              value_type;
+    typedef value_type&                                    reference;
+    typedef const value_type&                              const_reference;
+
+private:
+    typedef pair<key_type, mapped_type>                    __value_type;
+    typedef __hash_map_hasher<__value_type, hasher>   __hasher;
+    typedef __hash_map_equal<__value_type, key_equal> __key_equal;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                           __allocator_type;
+
+    typedef __hash_table<__value_type, __hasher,
+                         __key_equal,  __allocator_type>   __table;
+
+    __table __table_;
+
+    typedef typename __table::__node_traits                __node_traits;
+    typedef typename __table::__node_allocator             __node_allocator;
+    typedef typename __table::__node                       __node;
+    typedef __hash_map_node_destructor<__node_allocator>   _D;
+    typedef unique_ptr<__node, _D>                         __node_holder;
+    typedef allocator_traits<allocator_type>               __alloc_traits;
+public:
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+
+    typedef __hash_map_iterator<typename __table::iterator>       iterator;
+    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
+
+    hash_multimap() {__table_.rehash(193);}
+    explicit hash_multimap(size_type __n, const hasher& __hf = hasher(),
+                                const key_equal& __eql = key_equal());
+    hash_multimap(size_type __n, const hasher& __hf,
+                                const key_equal& __eql,
+                                const allocator_type& __a);
+    template <class _InputIterator>
+        hash_multimap(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        hash_multimap(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        hash_multimap(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf,
+                      const key_equal& __eql,
+                      const allocator_type& __a);
+    hash_multimap(const hash_multimap& __u);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+
+    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+
+    void erase(const_iterator __p) {__table_.erase(__p.__i_);}
+    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
+    void erase(const_iterator __first, const_iterator __last)
+        {__table_.erase(__first.__i_, __last.__i_);}
+    void clear() {__table_.clear();}
+
+    void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_funct() const
+        {return __table_.hash_function().hash_function();}
+    key_equal key_eq() const
+        {return __table_.key_eq().key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_multi(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_multi(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type elems_in_bucket(size_type __n) const
+        {return __table_.bucket_size(__n);}
+
+    void resize(size_type __n) {__table_.rehash(__n);}
+};
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        _InputIterator __first, _InputIterator __last)
+{
+    __table_.rehash(193);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
+        const hash_multimap& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                            _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_multi(*__first);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+     hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    typedef pair<const_iterator, const_iterator> _EqRng;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
+    {
+        _EqRng __xeq = __x.equal_range(__i->first);
+        _EqRng __yeq = __y.equal_range(__i->first);
+        if (_STD::distance(__xeq.first, __xeq.second) !=
+            _STD::distance(__yeq.first, __yeq.second) ||
+                  !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
+            return false;
+        __i = __xeq.second;
+    }
+    return true;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+} // __gnu_cxx
+
+#endif  // _LIBCPP_HASH_MAP
diff --git a/include/ext/hash_set b/include/ext/hash_set
new file mode 100644
index 0000000..58c037d
--- /dev/null
+++ b/include/ext/hash_set
@@ -0,0 +1,598 @@
+// -*- C++ -*-
+//===------------------------- hash_set ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_HASH_SET
+#define _LIBCPP_HASH_SET
+
+/*
+
+    hash_set synopsis
+
+namespace __gnu_cxx
+{
+
+template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
+          class Alloc = allocator<Value>>
+class hash_set
+{
+public:
+    // types
+    typedef Value                                                      key_type;
+    typedef key_type                                                   value_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+
+    explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        hash_set(InputIterator f, InputIterator l,
+                      size_type n = 193, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    hash_set(const hash_set&);
+    ~hash_set();
+    hash_set& operator=(const hash_set&);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+
+    pair<iterator, bool> insert(const value_type& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+
+    void erase(const_iterator position);
+    size_type erase(const key_type& k);
+    void erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(hash_set&);
+
+    hasher hash_funct() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type elems_in_bucket(size_type n) const;
+
+    void resize(size_type n);
+};
+
+template <class Value, class Hash, class Pred, class Alloc>
+    void swap(hash_set<Value, Hash, Pred, Alloc>& x,
+              hash_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
+               const hash_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
+               const hash_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
+          class Alloc = allocator<Value>>
+class hash_multiset
+{
+public:
+    // types
+    typedef Value                                                      key_type;
+    typedef key_type                                                   value_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+
+    explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        hash_multiset(InputIterator f, InputIterator l,
+                      size_type n = 193, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    hash_multiset(const hash_multiset&);
+    ~hash_multiset();
+    hash_multiset& operator=(const hash_multiset&);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+
+    iterator insert(const value_type& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+
+    void erase(const_iterator position);
+    size_type erase(const key_type& k);
+    void erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(hash_multiset&);
+
+    hasher hash_funct() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type elems_in_bucket(size_type n) const;
+
+    void resize(size_type n);
+};
+
+template <class Value, class Hash, class Pred, class Alloc>
+    void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
+              hash_multiset<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
+               const hash_multiset<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
+               const hash_multiset<Value, Hash, Pred, Alloc>& y);
+}  // __gnu_cxx
+
+*/
+
+#include <__config>
+#include <__hash_table>
+#include <functional>
+
+#warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
+
+namespace __gnu_cxx {
+
+using namespace std;
+
+template <class _Value, class _Hash = std::hash<_Value>, class _Pred = equal_to<_Value>,
+          class _Alloc = allocator<_Value> >
+class hash_set
+{
+public:
+    // types
+    typedef _Value                                                     key_type;
+    typedef key_type                                                   value_type;
+    typedef _Hash                                                      hasher;
+    typedef _Pred                                                      key_equal;
+    typedef _Alloc                                                     allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+
+private:
+    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
+
+    __table __table_;
+
+public:
+    typedef typename __table::pointer         pointer;
+    typedef typename __table::const_pointer   const_pointer;
+    typedef typename __table::size_type       size_type;
+    typedef typename __table::difference_type difference_type;
+
+    typedef typename __table::const_iterator       iterator;
+    typedef typename __table::const_iterator       const_iterator;
+
+    hash_set() {__table_.rehash(193);}
+    explicit hash_set(size_type __n, const hasher& __hf = hasher(),
+                           const key_equal& __eql = key_equal());
+    hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
+                  const allocator_type& __a);
+    template <class _InputIterator>
+        hash_set(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        hash_set(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        hash_set(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf, const key_equal& __eql,
+                      const allocator_type& __a);
+    hash_set(const hash_set& __u);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+
+    pair<iterator, bool> insert(const value_type& __x)
+        {return __table_.__insert_unique(__x);}
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+
+    void erase(const_iterator __p) {__table_.erase(__p);}
+    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
+    void erase(const_iterator __first, const_iterator __last)
+        {__table_.erase(__first, __last);}
+    void clear() {__table_.clear();}
+
+    void swap(hash_set& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_funct() const {return __table_.hash_function();}
+    key_equal key_eq() const {return __table_.key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_unique(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_unique(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
+
+    void resize(size_type __n) {__table_.rehash(__n);}
+};
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
+        _InputIterator __first, _InputIterator __last)
+{
+    __table_.rehash(193);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
+        const hash_set& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                    _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_unique(*__first);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
+     hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
+           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
+            __i != __ex; ++__i)
+    {
+        const_iterator __j = __y.find(*__i);
+        if (__j == __ey || !(*__i == *__j))
+            return false;
+    }
+    return true;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
+           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
+          class _Alloc = allocator<_Value> >
+class hash_multiset
+{
+public:
+    // types
+    typedef _Value                                                     key_type;
+    typedef key_type                                                   value_type;
+    typedef _Hash                                                      hasher;
+    typedef _Pred                                                      key_equal;
+    typedef _Alloc                                                     allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+
+private:
+    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
+
+    __table __table_;
+
+public:
+    typedef typename __table::pointer         pointer;
+    typedef typename __table::const_pointer   const_pointer;
+    typedef typename __table::size_type       size_type;
+    typedef typename __table::difference_type difference_type;
+
+    typedef typename __table::const_iterator       iterator;
+    typedef typename __table::const_iterator       const_iterator;
+
+    hash_multiset() {__table_.rehash(193);}
+    explicit hash_multiset(size_type __n, const hasher& __hf = hasher(),
+                                const key_equal& __eql = key_equal());
+    hash_multiset(size_type __n, const hasher& __hf,
+                       const key_equal& __eql, const allocator_type& __a);
+    template <class _InputIterator>
+        hash_multiset(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        hash_multiset(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        hash_multiset(_InputIterator __first, _InputIterator __last,
+                      size_type __n , const hasher& __hf,
+                      const key_equal& __eql, const allocator_type& __a);
+    hash_multiset(const hash_multiset& __u);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+
+    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+
+    void erase(const_iterator __p) {__table_.erase(__p);}
+    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
+    void erase(const_iterator __first, const_iterator __last)
+        {__table_.erase(__first, __last);}
+    void clear() {__table_.clear();}
+
+    void swap(hash_multiset& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_funct() const {return __table_.hash_function();}
+    key_equal key_eq() const {return __table_.key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_multi(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_multi(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
+
+    void resize(size_type __n) {__table_.rehash(__n);}
+};
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        _InputIterator __first, _InputIterator __last)
+{
+    __table_.rehash(193);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
+        const hash_multiset& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                         _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_multi(*__first);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+     hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    typedef pair<const_iterator, const_iterator> _EqRng;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
+    {
+        _EqRng __xeq = __x.equal_range(*__i);
+        _EqRng __yeq = __y.equal_range(*__i);
+        if (_STD::distance(__xeq.first, __xeq.second) !=
+            _STD::distance(__yeq.first, __yeq.second) ||
+                  !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
+            return false;
+        __i = __xeq.second;
+    }
+    return true;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+} // __gnu_cxx
+
+#endif  // _LIBCPP_HASH_SET
diff --git a/include/forward_list b/include/forward_list
new file mode 100644
index 0000000..002ecd8
--- /dev/null
+++ b/include/forward_list
@@ -0,0 +1,1458 @@
+// -*- C++ -*-
+//===----------------------- forward_list ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FORWARD_LIST
+#define _LIBCPP_FORWARD_LIST
+
+/*
+    forward_list synopsis
+
+namespace std
+{
+
+template <class T, class Allocator = allocator<T>>
+class forward_list
+{
+public:
+    typedef T         value_type;
+    typedef Allocator allocator_type;
+
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef <details> iterator;
+    typedef <details> const_iterator;
+
+    forward_list();
+    explicit forward_list(const allocator_type& a);
+    explicit forward_list(size_type n);
+    forward_list(size_type n, const value_type& v);
+    forward_list(size_type n, const value_type& v, const allocator_type& a);
+    template <class InputIterator>
+        forward_list(InputIterator first, InputIterator last);
+    template <class InputIterator>
+        forward_list(InputIterator first, InputIterator last, const allocator_type& a);
+    forward_list(const forward_list& x);
+    forward_list(const forward_list& x, const allocator_type& a);
+    forward_list(forward_list&& x);
+    forward_list(forward_list&& x, const allocator_type& a);
+    forward_list(initializer_list<value_type> il);
+    forward_list(initializer_list<value_type> il, const allocator_type& a);
+
+    ~forward_list();
+
+    forward_list& operator=(const forward_list& x);
+    forward_list& operator=(forward_list&& x);
+    forward_list& operator=(initializer_list<value_type> il);
+
+    template <class InputIterator>
+        void assign(InputIterator first, InputIterator last);
+    void assign(size_type n, const value_type& v);
+    void assign(initializer_list<value_type> il);
+
+    allocator_type get_allocator() const;
+
+    iterator       begin();
+    const_iterator begin() const;
+    iterator       end();
+    const_iterator end() const;
+
+    const_iterator cbegin() const;
+    const_iterator cend() const;
+
+    iterator       before_begin();
+    const_iterator before_begin() const;
+    const_iterator cbefore_begin() const;
+
+    bool empty() const;
+    size_type max_size() const;
+
+    reference       front();
+    const_reference front() const;
+
+    template <class... Args> void emplace_front(Args&&... args);
+    void push_front(const value_type& v);
+    void push_front(value_type&& v);
+
+    void pop_front();
+
+    template <class... Args>
+        iterator emplace_after(const_iterator p, Args&&... args);
+    iterator insert_after(const_iterator p, const value_type& v);
+    iterator insert_after(const_iterator p, value_type&& v);
+    iterator insert_after(const_iterator p, size_type n, const value_type& v);
+    template <class InputIterator>
+        iterator insert_after(const_iterator p,
+                              InputIterator first, InputIterator last);
+    iterator insert_after(const_iterator p, initializer_list<value_type> il);
+
+    void erase_after(const_iterator p);
+    void erase_after(const_iterator first, const_iterator last);
+
+    void swap(forward_list& x);
+
+    void resize(size_type n);
+    void resize(size_type n, const value_type& v);
+    void clear();
+
+    void splice_after(const_iterator p, forward_list&& x);
+    void splice_after(const_iterator p, forward_list&& x, const_iterator i);
+    void splice_after(const_iterator p, forward_list&& x,
+                      const_iterator first, const_iterator last);
+    void remove(const value_type& v);
+    template <class Predicate> void remove_if(Predicate pred);
+    void unique();
+    template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
+    void merge(forward_list&& x);
+    template <class Compare> void merge(forward_list&& x, Compare comp);
+    void sort();
+    template <class Compare> void sort(Compare comp);
+    void reverse();
+};
+
+template <class T, class Allocator>
+    bool operator==(const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    bool operator< (const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    bool operator!=(const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    bool operator> (const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    bool operator>=(const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    bool operator<=(const forward_list<T, Allocator>& x,
+                    const forward_list<T, Allocator>& y);
+
+template <class T, class Allocator>
+    void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+
+#include <initializer_list>
+#include <memory>
+#include <limits>
+#include <iterator>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class, class> struct __forward_list_node;
+
+template <class _NodePtr>
+struct __forward_begin_node
+{
+    typedef __forward_begin_node __self;
+    typedef _NodePtr pointer;
+
+    pointer __next_;
+
+    __forward_begin_node() : __next_(nullptr) {}
+};
+
+template <class _Tp, class _VoidPtr>
+struct __forward_list_node
+    : public __forward_begin_node
+             <
+                 typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                     rebind<__forward_list_node<_Tp, _VoidPtr> >
+#else
+                     rebind<__forward_list_node<_Tp, _VoidPtr> >::other
+#endif
+             >
+{
+    typedef _Tp value_type;
+
+    value_type __value_;
+};
+
+template<class, class> class forward_list;
+template<class> class __forward_list_const_iterator;
+
+template <class _NodePtr>
+class __forward_list_iterator
+{
+    typedef _NodePtr __node_pointer;
+
+    __node_pointer __ptr_;
+
+    explicit __forward_list_iterator(__node_pointer __p) : __ptr_(__p) {}
+
+    template<class, class> friend class forward_list;
+    template<class> friend class __forward_list_const_iterator;
+
+public:
+    typedef forward_iterator_tag                              iterator_category;
+    typedef typename pointer_traits<__node_pointer>::element_type::value_type
+                                                              value_type;
+    typedef value_type& reference;
+    typedef typename pointer_traits<__node_pointer>::difference_type 
+                                                              difference_type;
+    typedef typename pointer_traits<__node_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                              pointer;
+
+    __forward_list_iterator() : __ptr_(nullptr) {}
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &__ptr_->__value_;}
+
+    __forward_list_iterator& operator++()
+    {
+        __ptr_ = __ptr_->__next_;
+        return *this;
+    }
+    __forward_list_iterator operator++(int)
+    {
+        __forward_list_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __forward_list_iterator& __x,
+                           const __forward_list_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __forward_list_iterator& __x,
+                           const __forward_list_iterator& __y)
+        {return !(__x == __y);}
+};
+
+template <class _NodeConstPtr>
+class __forward_list_const_iterator
+{
+    typedef _NodeConstPtr __node_const_pointer;
+
+    __node_const_pointer __ptr_;
+
+    explicit __forward_list_const_iterator(__node_const_pointer __p)
+        : __ptr_(__p) {}
+
+    typedef typename remove_const
+        <
+            typename pointer_traits<__node_const_pointer>::element_type
+        >::type                                               __node;
+    typedef typename pointer_traits<__node_const_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<__node>
+#else
+            rebind<__node>::other
+#endif
+                                                              __node_pointer;
+
+    template<class, class> friend class forward_list;
+
+public:
+    typedef forward_iterator_tag                              iterator_category;
+    typedef typename __node::value_type                       value_type;
+    typedef const value_type& reference;
+    typedef typename pointer_traits<__node_const_pointer>::difference_type 
+                                                              difference_type;
+    typedef typename pointer_traits<__node_const_pointer>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                                              pointer;
+
+    __forward_list_const_iterator() : __ptr_(nullptr) {}
+    __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p)
+        : __ptr_(__p.__ptr_) {}
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &__ptr_->__value_;}
+
+    __forward_list_const_iterator& operator++()
+    {
+        __ptr_ = __ptr_->__next_;
+        return *this;
+    }
+    __forward_list_const_iterator operator++(int)
+    {
+        __forward_list_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __forward_list_const_iterator& __x,
+                           const __forward_list_const_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __forward_list_const_iterator& __x,
+                           const __forward_list_const_iterator& __y)
+        {return !(__x == __y);}
+};
+
+template <class _Tp, class _Alloc>
+class __forward_list_base
+{
+protected:
+    typedef _Tp    value_type;
+    typedef _Alloc allocator_type;
+
+    typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
+    typedef __forward_list_node<value_type, void_pointer>           __node;
+    typedef typename __node::__self                                 __begin_node;
+    typedef typename allocator_traits<allocator_type>::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::const_pointer     __node_const_pointer;
+
+    __compressed_pair<__begin_node, __node_allocator> __before_begin_;
+
+    __node_pointer        __before_begin()
+        {return pointer_traits<__node_pointer>::pointer_to(
+                                static_cast<__node&>(__before_begin_.first()));}
+    __node_const_pointer  __before_begin() const
+        {return pointer_traits<__node_const_pointer>::pointer_to(
+                          static_cast<const __node&>(__before_begin_.first()));}
+
+          __node_allocator& __alloc()       {return __before_begin_.second();}
+    const __node_allocator& __alloc() const {return __before_begin_.second();}
+
+    typedef __forward_list_iterator<__node_pointer>             iterator;
+    typedef __forward_list_const_iterator<__node_const_pointer> const_iterator;
+
+    __forward_list_base()
+        : __before_begin_(__begin_node()) {}
+    __forward_list_base(const allocator_type& __a)
+        : __before_begin_(__begin_node(), __node_allocator(__a)) {}
+
+#ifdef _LIBCPP_MOVE
+    __forward_list_base(__forward_list_base&& __x);
+    __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
+#endif
+
+private:
+    __forward_list_base(const __forward_list_base&);
+    __forward_list_base& operator=(const __forward_list_base&);
+protected:
+
+    ~__forward_list_base();
+
+    void __copy_assign_alloc(const __forward_list_base& __x)
+        {__copy_assign_alloc(__x, integral_constant<bool,
+              __node_traits::propagate_on_container_copy_assignment::value>());}
+
+    void __move_assign_alloc(__forward_list_base& __x)
+        {__move_assign_alloc(__x, integral_constant<bool,
+              __node_traits::propagate_on_container_move_assignment::value>());}
+
+    void swap(__forward_list_base& __x);
+    void clear();
+
+private:
+    void __copy_assign_alloc(const __forward_list_base&, false_type) {}
+    void __copy_assign_alloc(const __forward_list_base& __x, true_type)
+    {
+        if (__alloc() != __x.__alloc())
+            clear();
+        __alloc() = __x.__alloc();
+    }
+
+    void __move_assign_alloc(__forward_list_base& __x, false_type) {}
+    void __move_assign_alloc(__forward_list_base& __x, true_type)
+        {__alloc() = _STD::move(__x.__alloc());}
+
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                         __node_traits::propagate_on_container_swap::value>());}
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
+                                                                     false_type)
+        {}
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
+                                                                      true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+};
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+inline
+__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
+    : __before_begin_(_STD::move(__x.__before_begin_))
+{
+    __x.__before_begin()->__next_ = nullptr;
+}
+
+template <class _Tp, class _Alloc>
+inline
+__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
+                                                      const allocator_type& __a)
+    : __before_begin_(__begin_node(), __node_allocator(__a))
+{
+    if (__alloc() == __x.__alloc())
+    {
+        __before_begin()->__next_ = __x.__before_begin()->__next_;
+        __x.__before_begin()->__next_ = nullptr;
+    }
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
+{
+    clear();
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
+{
+    __swap_alloc(__alloc(), __x.__alloc());
+    using _STD::swap;
+    swap(__before_begin()->__next_, __x.__before_begin()->__next_);
+}
+
+template <class _Tp, class _Alloc>
+void
+__forward_list_base<_Tp, _Alloc>::clear()
+{
+    __node_allocator& __a = __alloc();
+    for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
+    {
+        __node_pointer __next = __p->__next_;
+        __node_traits::destroy(__a, addressof(__p->__value_));
+        __node_traits::deallocate(__a, __p, 1);
+        __p = __next;
+    }
+    __before_begin()->__next_ = nullptr;
+}
+
+template <class _Tp, class _Alloc = allocator<_Tp> >
+class forward_list
+    : private __forward_list_base<_Tp, _Alloc>
+{
+    typedef __forward_list_base<_Tp, _Alloc> base;
+public:
+    typedef _Tp    value_type;
+    typedef _Alloc allocator_type;
+
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef typename base::iterator       iterator;
+    typedef typename base::const_iterator const_iterator;
+
+    forward_list() {} // = default;
+    explicit forward_list(const allocator_type& __a);
+    explicit forward_list(size_type __n);
+    forward_list(size_type __n, const value_type& __v);
+    forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
+    template <class _InputIterator>
+        forward_list(_InputIterator __f, _InputIterator __l,
+                     typename enable_if<
+                       __is_input_iterator<_InputIterator>::value
+                     >::type* = nullptr);
+    template <class _InputIterator>
+        forward_list(_InputIterator __f, _InputIterator __l,
+                     const allocator_type& __a,
+                     typename enable_if<
+                       __is_input_iterator<_InputIterator>::value
+                     >::type* = nullptr);
+    forward_list(const forward_list& __x);
+    forward_list(const forward_list& __x, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    forward_list(forward_list&& __x) : base(_STD::move(__x)) {}
+    forward_list(forward_list&& __x, const allocator_type& __a);
+#endif
+    forward_list(initializer_list<value_type> __il);
+    forward_list(initializer_list<value_type> __il, const allocator_type& __a);
+
+    // ~forward_list() = default;
+
+    forward_list& operator=(const forward_list& __x);
+#ifdef _LIBCPP_MOVE
+    forward_list& operator=(forward_list&& __x);
+#endif
+    forward_list& operator=(initializer_list<value_type> __il);
+
+    template <class _InputIterator>
+        typename enable_if
+        <
+            __is_input_iterator<_InputIterator>::value,
+            void
+        >::type
+        assign(_InputIterator __f, _InputIterator __l);
+    void assign(size_type __n, const value_type& __v);
+    void assign(initializer_list<value_type> __il);
+
+    allocator_type get_allocator() const {return allocator_type(base::__alloc());}
+
+    iterator       begin()       {return       iterator(base::__before_begin()->__next_);}
+    const_iterator begin() const {return const_iterator(base::__before_begin()->__next_);}
+    iterator       end()         {return       iterator(nullptr);}
+    const_iterator end() const   {return const_iterator(nullptr);}
+
+    const_iterator cbegin() const {return const_iterator(base::__before_begin()->__next_);}
+    const_iterator cend() const   {return const_iterator(nullptr);}
+
+    iterator       before_begin()        {return       iterator(base::__before_begin());}
+    const_iterator before_begin() const  {return const_iterator(base::__before_begin());}
+    const_iterator cbefore_begin() const {return const_iterator(base::__before_begin());}
+
+    bool empty() const {return base::__before_begin()->__next_ == nullptr;}
+    size_type max_size() const {return numeric_limits<size_type>::max();}
+
+    reference       front()       {return base::__before_begin()->__next_->__value_;}
+    const_reference front() const {return base::__before_begin()->__next_->__value_;}
+
+#ifdef _LIBCPP_MOVE
+    template <class... _Args> void emplace_front(_Args&&... __args);
+    void push_front(value_type&& __v);
+#endif
+    void push_front(const value_type& __v);
+
+    void pop_front();
+
+#ifdef _LIBCPP_MOVE
+    template <class... _Args>
+        iterator emplace_after(const_iterator __p, _Args&&... __args);
+    iterator insert_after(const_iterator __p, value_type&& __v);
+#endif
+    iterator insert_after(const_iterator __p, const value_type& __v);
+    iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
+    template <class _InputIterator>
+        typename enable_if
+        <
+            __is_input_iterator<_InputIterator>::value,
+            iterator
+        >::type
+        insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
+    iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
+        {return insert_after(__p, __il.begin(), __il.end());}
+
+    void erase_after(const_iterator __p);
+    void erase_after(const_iterator __f, const_iterator __l);
+
+    void swap(forward_list& __x) {base::swap(__x);}
+
+    void resize(size_type __n);
+    void resize(size_type __n, const value_type& __v);
+    void clear() {base::clear();}
+
+#ifdef _LIBCPP_MOVE
+    void splice_after(const_iterator __p, forward_list&& __x);
+    void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
+    void splice_after(const_iterator __p, forward_list&& __x,
+                      const_iterator __f, const_iterator __l);
+#else
+    void splice_after(const_iterator __p, forward_list& __x);
+    void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
+    void splice_after(const_iterator __p, forward_list& __x,
+                      const_iterator __f, const_iterator __l);
+#endif
+    void remove(const value_type& __v);
+    template <class _Predicate> void remove_if(_Predicate __pred);
+    void unique() {unique(__equal_to<value_type>());}
+    template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
+#ifdef _LIBCPP_MOVE
+    void merge(forward_list&& __x) {merge(_STD::move(__x), __less<value_type>());}
+    template <class _Compare> void merge(forward_list&& __x, _Compare __comp);
+#else
+    void merge(forward_list& __x) {merge(__x, __less<value_type>());}
+    template <class _Compare> void merge(forward_list& __x, _Compare __comp);
+#endif
+    void sort() {sort(__less<value_type>());}
+    template <class _Compare> void sort(_Compare __comp);
+    void reverse();
+
+private:
+    typedef typename base::__node_allocator  __node_allocator;
+    typedef typename base::__node            __node;
+    typedef typename base::__node_traits     __node_traits;
+    typedef typename base::__node_pointer    __node_pointer;
+
+#ifdef _LIBCPP_MOVE
+    void __move_assign(forward_list& __x, true_type);
+    void __move_assign(forward_list& __x, false_type);
+#endif
+
+    template <class _Compare>
+        static
+        __node_pointer
+        __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
+
+    template <class _Compare>
+        static
+        __node_pointer
+        __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
+};
+
+template <class _Tp, class _Alloc>
+inline
+forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
+    : base(__a)
+{
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(size_type __n)
+{
+    if (__n > 0)
+    {
+        __node_allocator& __a = base::__alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
+        for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
+                                                             __p = __p->__next_)
+        {
+            __h.reset(__node_traits::allocate(__a, 1));
+            __node_traits::construct(__a, addressof(__h->__value_));
+            __h->__next_ = nullptr;
+            __p->__next_ = __h.release();
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
+{
+    insert_after(cbefore_begin(), __n, __v);
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
+                                        const allocator_type& __a)
+    : base(__a)
+{
+    insert_after(cbefore_begin(), __n, __v);
+}
+
+template <class _Tp, class _Alloc>
+template <class _InputIterator>
+forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
+                                        typename enable_if<
+                                          __is_input_iterator<_InputIterator>::value
+                                        >::type*)
+{
+    insert_after(cbefore_begin(), __f, __l);
+}
+
+template <class _Tp, class _Alloc>
+template <class _InputIterator>
+forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
+                                        const allocator_type& __a,
+                                        typename enable_if<
+                                          __is_input_iterator<_InputIterator>::value
+                                        >::type*)
+    : base(__a)
+{
+    insert_after(cbefore_begin(), __f, __l);
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
+    : base(allocator_type(
+             __node_traits::select_on_container_copy_construction(__x.__alloc())
+                         )
+          )
+{
+    insert_after(cbefore_begin(), __x.begin(), __x.end());
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
+                                        const allocator_type& __a)
+    : base(__a)
+{
+    insert_after(cbefore_begin(), __x.begin(), __x.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
+                                        const allocator_type& __a)
+    : base(_STD::move(__x), __a)
+{
+    if (base::__alloc() != __x.__alloc())
+    {
+        typedef move_iterator<iterator> _I;
+        insert_after(cbefore_begin(), _I(__x.begin()), _I(__x.end()));
+    }
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
+{
+    insert_after(cbefore_begin(), __il.begin(), __il.end());
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
+                                        const allocator_type& __a)
+    : base(__a)
+{
+    insert_after(cbefore_begin(), __il.begin(), __il.end());
+}
+
+template <class _Tp, class _Alloc>
+forward_list<_Tp, _Alloc>&
+forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
+{
+    if (this != &__x)
+    {
+        base::__copy_assign_alloc(__x);
+        assign(__x.begin(), __x.end());
+    }
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
+{
+    clear();
+    base::__move_assign_alloc(__x);
+    base::__before_begin()->__next_ = __x.__before_begin()->__next_;
+    __x.__before_begin()->__next_ = nullptr;
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
+{
+    if (base::__alloc() == __x.__alloc())
+        __move_assign(__x, true_type());
+    else
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__x.begin()), _I(__x.end()));
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+forward_list<_Tp, _Alloc>&
+forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
+{
+    __move_assign(__x, integral_constant<bool,
+          __node_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+inline
+forward_list<_Tp, _Alloc>&
+forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
+{
+    assign(__il.begin(), __il.end());
+    return *this;
+}
+
+template <class _Tp, class _Alloc>
+template <class _InputIterator>
+typename enable_if
+<
+    __is_input_iterator<_InputIterator>::value,
+    void
+>::type
+forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
+{
+    iterator __i = before_begin();
+    iterator __j = next(__i);
+    iterator __e = end();
+    for (; __j != __e && __f != __l; ++__i, ++__j, ++__f)
+        *__j = *__f;
+    if (__j == __e)
+        insert_after(__i, __f, __l);
+    else
+        erase_after(__i, __e);
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
+{
+    iterator __i = before_begin();
+    iterator __j = next(__i);
+    iterator __e = end();
+    for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
+        *__j = __v;
+    if (__j == __e)
+        insert_after(__i, __n, __v);
+    else
+        erase_after(__i, __e);
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
+{
+    assign(__il.begin(), __il.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+template <class... _Args>
+void
+forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
+{
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_),
+                                  _STD::forward<_Args>(__args)...);
+    __h->__next_ = base::__before_begin()->__next_;
+    base::__before_begin()->__next_ = __h.release();
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
+{
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_), _STD::move(__v));
+    __h->__next_ = base::__before_begin()->__next_;
+    base::__before_begin()->__next_ = __h.release();
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
+{
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_), __v);
+    __h->__next_ = base::__before_begin()->__next_;
+    base::__before_begin()->__next_ = __h.release();
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::pop_front()
+{
+    __node_allocator& __a = base::__alloc();
+    __node_pointer __p = base::__before_begin()->__next_;
+    base::__before_begin()->__next_ = __p->__next_;
+    __node_traits::destroy(__a, addressof(__p->__value_));
+    __node_traits::deallocate(__a, __p, 1);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+template <class... _Args>
+typename forward_list<_Tp, _Alloc>::iterator
+forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
+{
+    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_),
+                                  _STD::forward<_Args>(__args)...);
+    __h->__next_ = __r->__next_;
+    __r->__next_ = __h.release();
+    return iterator(__r->__next_);
+}
+
+template <class _Tp, class _Alloc>
+typename forward_list<_Tp, _Alloc>::iterator
+forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
+{
+    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_), _STD::move(__v));
+    __h->__next_ = __r->__next_;
+    __r->__next_ = __h.release();
+    return iterator(__r->__next_);
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+typename forward_list<_Tp, _Alloc>::iterator
+forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
+{
+    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    __node_allocator& __a = base::__alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+    __node_traits::construct(__a, addressof(__h->__value_), __v);
+    __h->__next_ = __r->__next_;
+    __r->__next_ = __h.release();
+    return iterator(__r->__next_);
+}
+
+template <class _Tp, class _Alloc>
+typename forward_list<_Tp, _Alloc>::iterator
+forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
+                                        const value_type& __v)
+{
+    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    if (__n > 0)
+    {
+        __node_allocator& __a = base::__alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+        __node_traits::construct(__a, addressof(__h->__value_), __v);
+        __node_pointer __first = __h.release();
+        __node_pointer __last = __first;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (--__n; __n != 0; --__n, __last = __last->__next_)
+            {
+                __h.reset(__node_traits::allocate(__a, 1));
+                __node_traits::construct(__a, addressof(__h->__value_), __v);
+                __last->__next_ = __h.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (__first != nullptr)
+            {
+                __node_pointer __next = __first->__next_;
+                __node_traits::destroy(__a, addressof(__first->__value_));
+                __node_traits::deallocate(__a, __first, 1);
+                __first = __next;
+            }
+            throw;
+        }
+#endif
+        __last->__next_ = __r->__next_;
+        __r->__next_ = __first;
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Alloc>
+template <class _InputIterator>
+typename enable_if
+<
+    __is_input_iterator<_InputIterator>::value,
+    typename forward_list<_Tp, _Alloc>::iterator
+>::type
+forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
+                                        _InputIterator __f, _InputIterator __l)
+{
+    __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
+    if (__f != __l)
+    {
+        __node_allocator& __a = base::__alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
+        __node_traits::construct(__a, addressof(__h->__value_), *__f);
+        __node_pointer __first = __h.release();
+        __node_pointer __last = __first;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (++__f; __f != __l; ++__f, __last = __last->__next_)
+            {
+                __h.reset(__node_traits::allocate(__a, 1));
+                __node_traits::construct(__a, addressof(__h->__value_), *__f);
+                __last->__next_ = __h.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (__first != nullptr)
+            {
+                __node_pointer __next = __first->__next_;
+                __node_traits::destroy(__a, addressof(__first->__value_));
+                __node_traits::deallocate(__a, __first, 1);
+                __first = __next;
+            }
+            throw;
+        }
+#endif
+        __last->__next_ = __r->__next_;
+        __r->__next_ = __first;
+    }
+    return iterator(__r);
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
+{
+    __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
+    __node_pointer __n = __p->__next_;
+    __p->__next_ = __n->__next_;
+    __node_allocator& __a = base::__alloc();
+    __node_traits::destroy(__a, addressof(__n->__value_));
+    __node_traits::deallocate(__a, __n, 1);
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
+{
+    if (__f != __l)
+    {
+        __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
+        __node_pointer __n = __p->__next_;
+        __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
+        if (__n != __e)
+        {
+            __p->__next_ = __e;
+            __node_allocator& __a = base::__alloc();
+            do
+            {
+                __p = __n->__next_;
+                __node_traits::destroy(__a, addressof(__n->__value_));
+                __node_traits::deallocate(__a, __n, 1);
+                __n = __p;
+            } while (__n != __e);
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::resize(size_type __n)
+{
+    size_type __sz = 0;
+    iterator __p = before_begin();
+    iterator __i = begin();
+    iterator __e = end();
+    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
+        ;
+    if (__i != __e)
+        erase_after(__p, __e);
+    else
+    {
+        __n -= __sz;
+        if (__n > 0)
+        {
+            __node_allocator& __a = base::__alloc();
+            typedef __allocator_destructor<__node_allocator> _D;
+            unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
+            for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
+                                                         __ptr = __ptr->__next_)
+            {
+                __h.reset(__node_traits::allocate(__a, 1));
+                __node_traits::construct(__a, addressof(__h->__value_));
+                __h->__next_ = nullptr;
+                __ptr->__next_ = __h.release();
+            }
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
+{
+    size_type __sz = 0;
+    iterator __p = before_begin();
+    iterator __i = begin();
+    iterator __e = end();
+    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
+        ;
+    if (__i != __e)
+        erase_after(__p, __e);
+    else
+    {
+        __n -= __sz;
+        if (__n > 0)
+        {
+            __node_allocator& __a = base::__alloc();
+            typedef __allocator_destructor<__node_allocator> _D;
+            unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
+            for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
+                                                         __ptr = __ptr->__next_)
+            {
+                __h.reset(__node_traits::allocate(__a, 1));
+                __node_traits::construct(__a, addressof(__h->__value_), __v);
+                __h->__next_ = nullptr;
+                __ptr->__next_ = __h.release();
+            }
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
+#ifdef _LIBCPP_MOVE
+                                        forward_list&& __x)
+#else
+                                        forward_list& __x)
+#endif
+{
+    if (!__x.empty())
+    {
+        if (__p.__ptr_->__next_ != nullptr)
+        {
+            const_iterator __lm1 = __x.before_begin();
+            while (__lm1.__ptr_->__next_ != nullptr)
+                ++__lm1;
+            const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
+                const_cast<__node_pointer>(__p.__ptr_)->__next_;
+        }
+        const_cast<__node_pointer>(__p.__ptr_)->__next_ =
+            const_cast<__node_pointer>(__x.__before_begin())->__next_;
+        const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr;
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
+#ifdef _LIBCPP_MOVE
+                                        forward_list&& __x,
+#else
+                                        forward_list& __x,
+#endif
+                                        const_iterator __i)
+{
+    const_iterator __lm1 = next(__i);
+    if (__p != __i && __p != __lm1)
+    {
+        const_cast<__node_pointer>(__i.__ptr_)->__next_ =
+            const_cast<__node_pointer>(__lm1.__ptr_)->__next_;
+        const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
+            const_cast<__node_pointer>(__p.__ptr_)->__next_;
+        const_cast<__node_pointer>(__p.__ptr_)->__next_ =
+            const_cast<__node_pointer>(__lm1.__ptr_);
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
+#ifdef _LIBCPP_MOVE
+                                        forward_list&& __x,
+#else
+                                        forward_list& __x,
+#endif
+                                        const_iterator __f, const_iterator __l)
+{
+    if (__f != __l && __p != __f)
+    {
+        const_iterator __lm1 = __f;
+        while (__lm1.__ptr_->__next_ != __l.__ptr_)
+            ++__lm1;
+        if (__f != __lm1)
+        {
+            const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
+                const_cast<__node_pointer>(__p.__ptr_)->__next_;
+            const_cast<__node_pointer>(__p.__ptr_)->__next_ =
+                const_cast<__node_pointer>(__f.__ptr_)->__next_;
+            const_cast<__node_pointer>(__f.__ptr_)->__next_ =
+                const_cast<__node_pointer>(__l.__ptr_);
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::remove(const value_type& __v)
+{
+    iterator __e = end();
+    for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
+    {
+        if (__i.__ptr_->__next_->__value_ == __v)
+        {
+            iterator __j = next(__i, 2);
+            for (; __j != __e && *__j == __v; ++__j)
+                ;
+            erase_after(__i, __j);
+            if (__j == __e)
+                break;
+            __i = __j;
+        }
+        else
+            ++__i;
+    }
+}
+
+template <class _Tp, class _Alloc>
+template <class _Predicate>
+void
+forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
+{
+    iterator __e = end();
+    for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
+    {
+        if (__pred(__i.__ptr_->__next_->__value_))
+        {
+            iterator __j = next(__i, 2);
+            for (; __j != __e && __pred(*__j); ++__j)
+                ;
+            erase_after(__i, __j);
+            if (__j == __e)
+                break;
+            __i = __j;
+        }
+        else
+            ++__i;
+    }
+}
+
+template <class _Tp, class _Alloc>
+template <class _BinaryPredicate>
+void
+forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
+{
+    for (iterator __i = begin(), __e = end(); __i != __e;)
+    {
+        iterator __j = next(__i);
+        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
+            ;
+        if (__i.__ptr_->__next_ != __j.__ptr_)
+            erase_after(__i, __j);
+        __i = __j;
+    }
+}
+
+template <class _Tp, class _Alloc>
+template <class _Compare>
+void
+#ifdef _LIBCPP_MOVE
+forward_list<_Tp, _Alloc>::merge(forward_list&& __x, _Compare __comp)
+#else
+forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
+#endif
+{
+    if (this != &__x)
+    {
+        base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
+                                                    __x.__before_begin()->__next_,
+                                                    __comp);
+        __x.__before_begin()->__next_ = nullptr;
+    }
+}
+
+template <class _Tp, class _Alloc>
+template <class _Compare>
+typename forward_list<_Tp, _Alloc>::__node_pointer
+forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
+                                   _Compare& __comp)
+{
+    if (__f1 == nullptr)
+        return __f2;
+    if (__f2 == nullptr)
+        return __f1;
+    __node_pointer __r;
+    if (__comp(__f2->__value_, __f1->__value_))
+    {
+        __node_pointer __t = __f2;
+        while (__t->__next_ != nullptr &&
+                             __comp(__t->__next_->__value_, __f1->__value_))
+            __t = __t->__next_;
+        __r = __f2;
+        __f2 = __t->__next_;
+        __t->__next_ = __f1;
+    }
+    else
+        __r = __f1;
+    __node_pointer __p = __f1;
+    __f1 = __f1->__next_;
+    while (__f1 != nullptr && __f2 != nullptr)
+    {
+        if (__comp(__f2->__value_, __f1->__value_))
+        {
+            __node_pointer __t = __f2;
+            while (__t->__next_ != nullptr &&
+                                 __comp(__t->__next_->__value_, __f1->__value_))
+                __t = __t->__next_;
+            __p->__next_ = __f2;
+            __f2 = __t->__next_;
+            __t->__next_ = __f1;
+        }
+        __p = __f1;
+        __f1 = __f1->__next_;
+    }
+    if (__f2 != nullptr)
+        __p->__next_ = __f2;
+    return __r;
+}
+
+template <class _Tp, class _Alloc>
+template <class _Compare>
+inline
+void
+forward_list<_Tp, _Alloc>::sort(_Compare __comp)
+{
+    base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
+                                       _STD::distance(begin(), end()), __comp);
+}
+
+template <class _Tp, class _Alloc>
+template <class _Compare>
+typename forward_list<_Tp, _Alloc>::__node_pointer
+forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
+                                  _Compare& __comp)
+{
+    switch (__sz)
+    {
+    case 0:
+    case 1:
+        return __f1;
+    case 2:
+        if (__comp(__f1->__next_->__value_, __f1->__value_))
+        {
+            __node_pointer __t = __f1->__next_;
+            __t->__next_ = __f1;
+            __f1->__next_ = nullptr;
+            __f1 = __t;
+        }
+        return __f1;
+    }
+    difference_type __sz1 = __sz / 2;
+    difference_type __sz2 = __sz - __sz1;
+    __node_pointer __t = next(iterator(__f1), __sz1 - 1).__ptr_;
+    __node_pointer __f2 = __t->__next_;
+    __t->__next_ = nullptr;
+    return __merge(__sort(__f1, __sz1, __comp),
+                   __sort(__f2, __sz2, __comp), __comp);
+}
+
+template <class _Tp, class _Alloc>
+void
+forward_list<_Tp, _Alloc>::reverse()
+{
+    __node_pointer __p = base::__before_begin()->__next_;
+    if (__p != nullptr)
+    {
+        __node_pointer __f = __p->__next_;
+        __p->__next_ = nullptr;
+        while (__f != nullptr)
+        {
+            __node_pointer __t = __f->__next_;
+            __f->__next_ = __p;
+            __p = __f;
+            __f = __t;
+        }
+        base::__before_begin()->__next_ = __p;
+    }
+}
+
+template <class _Tp, class _Alloc>
+bool operator==(const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    typedef forward_list<_Tp, _Alloc> _C;
+    typedef typename _C::const_iterator _I;
+    _I __ix = __x.begin();
+    _I __ex = __x.end();
+    _I __iy = __y.begin();
+    _I __ey = __y.end();
+    for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
+        if (!(*__ix == *__iy))
+            return false;
+    return (__ix == __ex) == (__iy == __ey);
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool operator!=(const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool operator< (const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(),
+                                         __y.begin(), __y.end());
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool operator> (const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool operator>=(const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool operator<=(const forward_list<_Tp, _Alloc>& __x,
+                const forward_list<_Tp, _Alloc>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FORWARD_LIST
diff --git a/include/fstream b/include/fstream
new file mode 100644
index 0000000..88e7dc5
--- /dev/null
+++ b/include/fstream
@@ -0,0 +1,1394 @@
+// -*- C++ -*-
+//===------------------------- fstream ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FSTREAM
+#define _LIBCPP_FSTREAM
+
+/*
+    fstream synopsis
+
+template <class charT, class traits = char_traits<charT> >
+class basic_filebuf
+    : public basic_streambuf<charT, traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // 27.9.1.2 Constructors/destructor:
+    basic_filebuf();
+    basic_filebuf(basic_filebuf&& rhs);
+    virtual ~basic_filebuf();
+
+    // 27.9.1.3 Assign/swap:
+    basic_filebuf& operator=(basic_filebuf&& rhs);
+    void swap(basic_filebuf& rhs);
+
+    // 27.9.1.4 Members:
+    bool is_open() const;
+    basic_filebuf* open(const char* s, ios_base::openmode mode);
+    basic_filebuf* open(const string& s, ios_base::openmode mode);
+    basic_filebuf* close();
+
+protected:
+    // 27.9.1.5 Overridden virtual functions:
+    virtual streamsize showmanyc();
+    virtual int_type underflow();
+    virtual int_type uflow();
+    virtual int_type pbackfail(int_type c = traits_type::eof());
+    virtual int_type overflow (int_type c = traits_type::eof());
+    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n);
+    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type sp,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual int sync();
+    virtual void imbue(const locale& loc);
+};
+
+template <class charT, class traits>
+  void
+  swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
+
+typedef basic_filebuf<char>    filebuf;
+typedef basic_filebuf<wchar_t> wfilebuf;
+
+template <class charT, class traits = char_traits<charT> >
+class basic_ifstream
+    : public basic_istream<charT,traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_ifstream();
+    explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in);
+    explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in);
+    basic_ifstream(basic_ifstream&& rhs);
+
+    basic_ifstream& operator=(basic_ifstream&& rhs);
+    void swap(basic_ifstream& rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* s, ios_base::openmode mode = ios_base::in);
+    void open(const string& s, ios_base::openmode mode = ios_base::in);
+    void close();
+};
+
+template <class charT, class traits>
+  void
+  swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y);
+
+typedef basic_ifstream<char>    ifstream;
+typedef basic_ifstream<wchar_t> wifstream;
+
+template <class charT, class traits = char_traits<charT> >
+class basic_ofstream
+    : public basic_ostream<charT,traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_ofstream();
+    explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out);
+    explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out);
+    basic_ofstream(basic_ofstream&& rhs);
+
+    basic_ofstream& operator=(basic_ofstream&& rhs);
+    void swap(basic_ofstream& rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* s, ios_base::openmode mode = ios_base::out);
+    void open(const string& s, ios_base::openmode mode = ios_base::out);
+    void close();
+};
+
+template <class charT, class traits> 
+  void
+  swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
+
+typedef basic_ofstream<char>    ofstream;
+typedef basic_ofstream<wchar_t> wofstream;
+
+template <class charT, class traits=char_traits<charT> >
+class basic_fstream
+    : public basic_iostream<charT,traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_fstream();
+    explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
+    explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
+    basic_fstream(basic_fstream&& rhs);
+
+    basic_fstream& operator=(basic_fstream&& rhs);
+    void swap(basic_fstream& rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
+    void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
+    void close();
+};
+
+template <class charT, class traits>
+  void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y);
+
+typedef basic_fstream<char>    fstream;
+typedef basic_fstream<wchar_t> wfstream;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ostream>
+#include <istream>
+#include <__locale>
+#include <cstdio>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _CharT, class _Traits>
+class basic_filebuf
+    : public basic_streambuf<_CharT, _Traits>
+{
+public:
+    typedef _CharT                           char_type;
+    typedef _Traits                          traits_type;
+    typedef typename traits_type::int_type   int_type;
+    typedef typename traits_type::pos_type   pos_type;
+    typedef typename traits_type::off_type   off_type;
+    typedef typename traits_type::state_type state_type;
+
+    // 27.9.1.2 Constructors/destructor:
+    basic_filebuf();
+#ifdef _LIBCPP_MOVE
+    basic_filebuf(basic_filebuf&& __rhs);
+#endif
+    virtual ~basic_filebuf();
+
+    // 27.9.1.3 Assign/swap:
+#ifdef _LIBCPP_MOVE
+    basic_filebuf& operator=(basic_filebuf&& __rhs);
+#endif
+    void swap(basic_filebuf& __rhs);
+
+    // 27.9.1.4 Members:
+    bool is_open() const;
+    basic_filebuf* open(const char* __s, ios_base::openmode __mode);
+    basic_filebuf* open(const string& __s, ios_base::openmode __mode);
+    basic_filebuf* close();
+
+protected:
+    // 27.9.1.5 Overridden virtual functions:
+    virtual int_type underflow();
+    virtual int_type pbackfail(int_type __c = traits_type::eof());
+    virtual int_type overflow (int_type __c = traits_type::eof());
+    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n);
+    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
+                             ios_base::openmode __wch = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type __sp,
+                             ios_base::openmode __wch = ios_base::in | ios_base::out);
+    virtual int sync();
+    virtual void imbue(const locale& __loc);
+
+private:
+    char*       __extbuf_;
+    const char* __extbufnext_;
+    const char* __extbufend_;
+    char __extbuf_min_[8];
+    size_t __ebs_;
+    char_type* __intbuf_;
+    size_t __ibs_;
+    FILE* __file_;
+    const codecvt<char_type, char, state_type>* __cv_;
+    state_type __st_;
+    ios_base::openmode __om_;
+    ios_base::openmode __cm_;
+    bool __owns_eb_;
+    bool __owns_ib_;
+    bool __always_noconv_;
+
+    bool __read_mode();
+    void __write_mode();
+};
+
+template <class _CharT, class _Traits>
+basic_filebuf<_CharT, _Traits>::basic_filebuf()
+    : __extbuf_(0),
+      __extbufnext_(0),
+      __extbufend_(0),
+      __ebs_(0),
+      __intbuf_(0),
+      __ibs_(0),
+      __file_(0),
+      __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
+      __st_(),
+      __om_(0),
+      __cm_(0),
+      __owns_eb_(false),
+      __owns_ib_(false),
+      __always_noconv_(__cv_->always_noconv())
+{
+    setbuf(0, 4096);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs)
+    : basic_streambuf<_CharT, _Traits>(__rhs)
+{
+    if (__rhs.__extbuf_ == __rhs.__extbuf_min_)
+    {
+        __extbuf_ = __extbuf_min_;
+        __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_);
+        __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_);
+    }
+    else
+    {
+        __extbuf_ = __rhs.__extbuf_;
+        __extbufnext_ = __rhs.__extbufnext_;
+        __extbufend_ = __rhs.__extbufend_;
+    }
+    __ebs_ = __rhs.__ebs_;
+    __intbuf_ = __rhs.__intbuf_;
+    __ibs_ = __rhs.__ibs_;
+    __file_ = __rhs.__file_;
+    __cv_ = __rhs.__cv_;
+    __st_ = __rhs.__st_;
+    __om_ = __rhs.__om_;
+    __cm_ = __rhs.__cm_;
+    __owns_eb_ = __rhs.__owns_eb_;
+    __owns_ib_ = __rhs.__owns_ib_;
+    __always_noconv_ = __rhs.__always_noconv_;
+    if (__rhs.pbase())
+    {
+        if (__rhs.pbase() == __rhs.__intbuf_)
+            this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase()));
+        else
+            this->setp((char_type*)__extbuf_,
+                       (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase()));
+        this->pbump(__rhs. pptr() - __rhs.pbase());
+    }
+    else if (__rhs.eback())
+    {
+        if (__rhs.eback() == __rhs.__intbuf_)
+            this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()),
+                                  __intbuf_ + (__rhs.egptr() - __rhs.eback()));
+        else
+            this->setg((char_type*)__extbuf_,
+                       (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()),
+                       (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback()));
+    }
+    __rhs.__extbuf_ = 0;
+    __rhs.__extbufnext_ = 0;
+    __rhs.__extbufend_ = 0;
+    __rhs.__ebs_ = 0;
+    __rhs.__intbuf_ = 0;
+    __rhs.__ibs_ = 0;
+    __rhs.__file_ = 0;
+    __rhs.__st_ = state_type();
+    __rhs.__om_ = 0;
+    __rhs.__cm_ = 0;
+    __rhs.__owns_eb_ = false;
+    __rhs.__owns_ib_ = false;
+    __rhs.setg(0, 0, 0);
+    __rhs.setp(0, 0);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_filebuf<_CharT, _Traits>&
+basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs)
+{
+    close();
+    swap(__rhs);
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+basic_filebuf<_CharT, _Traits>::~basic_filebuf()
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        close();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+    }
+#endif
+    if (__owns_eb_)
+        delete [] __extbuf_;
+    if (__owns_ib_)
+        delete [] __intbuf_;
+}
+
+template <class _CharT, class _Traits>
+void
+basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs)
+{
+    basic_streambuf<char_type, traits_type>::swap(__rhs);
+    if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
+    {
+        _STD::swap(__extbuf_, __rhs.__extbuf_);
+        _STD::swap(__extbufnext_, __rhs.__extbufnext_);
+        _STD::swap(__extbufend_, __rhs.__extbufend_);
+    }
+    else
+    {
+        ptrdiff_t __ln = __extbufnext_ - __extbuf_;
+        ptrdiff_t __le = __extbufend_ - __extbuf_;
+        ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_;
+        ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_;
+        if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
+        {
+            __extbuf_ = __rhs.__extbuf_;
+            __rhs.__extbuf_ = __rhs.__extbuf_min_;
+        }
+        else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_)
+        {
+            __rhs.__extbuf_ = __extbuf_;
+            __extbuf_ = __extbuf_min_;
+        }
+        __extbufnext_ = __extbuf_ + __rn;
+        __extbufend_ = __extbuf_ + __re;
+        __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln;
+        __rhs.__extbufend_ = __rhs.__extbuf_ + __le;
+    }
+    _STD::swap(__ebs_, __rhs.__ebs_);
+    _STD::swap(__intbuf_, __rhs.__intbuf_);
+    _STD::swap(__ibs_, __rhs.__ibs_);
+    _STD::swap(__file_, __rhs.__file_);
+    _STD::swap(__cv_, __rhs.__cv_);
+    _STD::swap(__st_, __rhs.__st_);
+    _STD::swap(__om_, __rhs.__om_);
+    _STD::swap(__cm_, __rhs.__cm_);
+    _STD::swap(__owns_eb_, __rhs.__owns_eb_);
+    _STD::swap(__owns_ib_, __rhs.__owns_ib_);
+    _STD::swap(__always_noconv_, __rhs.__always_noconv_);
+    if (this->eback() == (char_type*)__rhs.__extbuf_min_)
+    {
+        ptrdiff_t __n = this->gptr() - this->eback();
+        ptrdiff_t __e = this->egptr() - this->eback();
+        this->setg((char_type*)__extbuf_min_,
+                   (char_type*)__extbuf_min_ + __n,
+                   (char_type*)__extbuf_min_ + __e);
+    }
+    else if (this->pbase() == (char_type*)__rhs.__extbuf_min_)
+    {
+        ptrdiff_t __n = this->pptr() - this->pbase();
+        ptrdiff_t __e = this->epptr() - this->pbase();
+        this->setp((char_type*)__extbuf_min_,
+                   (char_type*)__extbuf_min_ + __e);
+        this->pbump(__n);
+    }
+    if (__rhs.eback() == (char_type*)__extbuf_min_)
+    {
+        ptrdiff_t __n = __rhs.gptr() - __rhs.eback();
+        ptrdiff_t __e = __rhs.egptr() - __rhs.eback();
+        __rhs.setg((char_type*)__rhs.__extbuf_min_,
+                   (char_type*)__rhs.__extbuf_min_ + __n,
+                   (char_type*)__rhs.__extbuf_min_ + __e);
+    }
+    else if (__rhs.pbase() == (char_type*)__extbuf_min_)
+    {
+        ptrdiff_t __n = __rhs.pptr() - __rhs.pbase();
+        ptrdiff_t __e = __rhs.epptr() - __rhs.pbase();
+        __rhs.setp((char_type*)__rhs.__extbuf_min_,
+                   (char_type*)__rhs.__extbuf_min_ + __e);
+        __rhs.pbump(__n);
+    }
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+basic_filebuf<_CharT, _Traits>::is_open() const
+{
+    return __file_ != 0;
+}
+
+template <class _CharT, class _Traits>
+basic_filebuf<_CharT, _Traits>*
+basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
+{
+    basic_filebuf<_CharT, _Traits>* __rt = 0;
+    if (__file_ == 0)
+    {
+        __rt = this;
+        const char* __mdstr;
+        switch (__mode & ~ios_base::ate)
+        {
+        case ios_base::out:
+        case ios_base::out | ios_base::trunc:
+            __mdstr = "w";
+            break;
+        case ios_base::out | ios_base::app:
+        case ios_base::app:
+            __mdstr = "a";
+            break;
+        case ios_base::in:
+            __mdstr = "r";
+            break;
+        case ios_base::in | ios_base::out:
+            __mdstr = "r+";
+            break;
+        case ios_base::in | ios_base::out | ios_base::trunc:
+            __mdstr = "w+";
+            break;
+        case ios_base::in | ios_base::out | ios_base::app:
+        case ios_base::in | ios_base::app:
+            __mdstr = "a+";
+            break;
+        case ios_base::out | ios_base::binary:
+        case ios_base::out | ios_base::trunc | ios_base::binary:
+            __mdstr = "wb";
+            break;
+        case ios_base::out | ios_base::app | ios_base::binary:
+        case ios_base::app | ios_base::binary:
+            __mdstr = "ab";
+            break;
+        case ios_base::in | ios_base::binary:
+            __mdstr = "rb";
+            break;
+        case ios_base::in | ios_base::out | ios_base::binary:
+            __mdstr = "r+b";
+            break;
+        case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
+            __mdstr = "w+b";
+            break;
+        case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
+        case ios_base::in | ios_base::app | ios_base::binary:
+            __mdstr = "a+b";
+            break;
+        default:
+            __rt = 0;
+            break;
+        }
+        if (__rt)
+        {
+            __file_ = fopen(__s, __mdstr);
+            if (__file_)
+            {
+                __om_ = __mode;
+                if (__mode & ios_base::ate)
+                {
+                    if (fseek(__file_, 0, SEEK_END))
+                    {
+                        fclose(__file_);
+                        __file_ = 0;
+                        __rt = 0;
+                    }
+                }
+            }
+            else
+                __rt = 0;
+        }
+    }
+    return __rt;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_filebuf<_CharT, _Traits>*
+basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
+{
+    return open(__s.c_str(), __mode);
+}
+
+template <class _CharT, class _Traits>
+basic_filebuf<_CharT, _Traits>*
+basic_filebuf<_CharT, _Traits>::close()
+{
+    basic_filebuf<_CharT, _Traits>* __rt = 0;
+    if (__file_)
+    {
+        __rt = this;
+        unique_ptr<FILE, int(*)(FILE*)> __h(__file_, fclose);
+        if ((__cm_ & ios_base::out) && sync())
+            __rt = 0;
+        if (fclose(__h.release()) == 0)
+            __file_ = 0;
+        else
+            __rt = 0;
+    }
+    return __rt;
+}
+
+template <class _CharT, class _Traits>
+typename basic_filebuf<_CharT, _Traits>::int_type
+basic_filebuf<_CharT, _Traits>::underflow()
+{
+    if (__file_ == 0)
+        return traits_type::eof();
+    bool __initial = __read_mode();
+    char_type __1buf;
+    if (this->gptr() == 0)
+        this->setg(&__1buf, &__1buf+1, &__1buf+1);
+    const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4);
+    int_type __c = traits_type::eof();
+    if (this->gptr() == this->egptr())
+    {
+        memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
+        if (__always_noconv_)
+        {
+            size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz);
+            __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_);
+            if (__nmemb != 0)
+            {
+                this->setg(this->eback(),
+                           this->eback() + __unget_sz,
+                           this->eback() + __unget_sz + __nmemb);
+                __c = *this->gptr();
+            }
+        }
+        else
+        {
+            memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
+            __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
+            __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
+            size_t __nmemb = min(static_cast<size_t>(this->egptr() - this->eback() - __unget_sz),
+                                 static_cast<size_t>(__extbufend_ - __extbufnext_));
+            codecvt_base::result __r;
+            state_type __svs = __st_;
+            size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_);
+            if (__nr != 0)
+            {
+                __extbufend_ = __extbufnext_ + __nr;
+                char_type*  __inext;
+                __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
+                                       this->eback() + __unget_sz,
+                                       this->egptr(), __inext);
+                if (__r == codecvt_base::noconv)
+                {
+                    this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_);
+                    __c = *this->gptr();
+                }
+                else if (__inext != this->eback() + __unget_sz)
+                {
+                    this->setg(this->eback(), this->eback() + __unget_sz, __inext);
+                    __c = *this->gptr();
+                }
+            }
+        }
+    }
+    else
+        __c = *this->gptr();
+    if (this->eback() == &__1buf)
+        this->setg(0, 0, 0);
+    return __c;
+}
+
+template <class _CharT, class _Traits>
+typename basic_filebuf<_CharT, _Traits>::int_type
+basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c)
+{
+    if (__file_ && this->eback() < this->gptr())
+    {
+        if (traits_type::eq_int_type(__c, traits_type::eof()))
+        {
+            this->gbump(-1);
+            return traits_type::not_eof(__c);
+        }
+        if ((__om_ & ios_base::out) ||
+            traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
+        {
+            this->gbump(-1);
+            *this->gptr() = traits_type::to_char_type(__c);
+            return __c;
+        }
+    }
+    return traits_type::eof();
+}
+
+template <class _CharT, class _Traits>
+typename basic_filebuf<_CharT, _Traits>::int_type
+basic_filebuf<_CharT, _Traits>::overflow(int_type __c)
+{
+    if (__file_ == 0)
+        return traits_type::eof();
+    __write_mode();
+    char_type __1buf;
+    char_type* __pb_save = this->pbase();
+    char_type* __epb_save = this->epptr();
+    if (!traits_type::eq_int_type(__c, traits_type::eof()))
+    {
+        if (this->pptr() == 0)
+            this->setp(&__1buf, &__1buf+1);
+        *this->pptr() = traits_type::to_char_type(__c);
+        this->pbump(1);
+    }
+    if (this->pptr() != this->pbase())
+    {
+        if (__always_noconv_)
+        {
+            size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
+            if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb)
+                return traits_type::eof();
+        }
+        else
+        {
+            char* __extbe = __extbuf_;
+            codecvt_base::result __r;
+            do
+            {
+                const char_type* __e;
+                __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
+                                        __extbuf_, __extbuf_ + __ebs_, __extbe);
+                if (__e == this->pbase())
+                    return traits_type::eof();
+                if (__r == codecvt_base::noconv)
+                {
+                    size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
+                    if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb)
+                        return traits_type::eof();
+                }
+                else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
+                {
+                    size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
+                    if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
+                        return traits_type::eof();
+                    if (__r == codecvt_base::partial)
+                    {
+                        this->setp((char_type*)__e, this->pptr());
+                        this->pbump(this->epptr() - this->pbase());
+                    }
+                }
+                else
+                    return traits_type::eof();
+            } while (__r == codecvt_base::partial);
+        }
+        this->setp(__pb_save, __epb_save);
+    }
+    return traits_type::not_eof(__c);
+}
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>*
+basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n)
+{
+    this->setg(0, 0, 0);
+    this->setp(0, 0);
+    if (__owns_eb_)
+        delete [] __extbuf_;
+    if (__owns_ib_)
+        delete [] __intbuf_;
+    __ebs_ = __n;
+    if (__ebs_ > sizeof(__extbuf_min_))
+    {
+        if (__always_noconv_ && __s)
+        {
+            __extbuf_ = (char*)__s;
+            __owns_eb_ = false;
+        }
+        else
+        {
+            __extbuf_ = new char[__ebs_];
+            __owns_eb_ = true;
+        }
+    }
+    else
+    {
+        __extbuf_ = __extbuf_min_;
+        __ebs_ = sizeof(__extbuf_min_);
+        __owns_eb_ = false;
+    }
+    if (!__always_noconv_)
+    {
+        __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
+        if (__s && __ibs_ >= sizeof(__extbuf_min_))
+        {
+            __intbuf_ = __s;
+            __owns_ib_ = false;
+        }
+        else
+        {
+            __intbuf_ = new char_type[__ibs_];
+            __owns_ib_ = true;
+        }
+    }
+    else
+    {
+        __ibs_ = 0;
+        __intbuf_ = 0;
+        __owns_ib_ = false;
+    }
+    return this;
+}
+
+template <class _CharT, class _Traits>
+typename basic_filebuf<_CharT, _Traits>::pos_type
+basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
+                                        ios_base::openmode)
+{
+    int __width = __cv_->encoding();
+    if (__file_ == 0 || (__width <= 0 && __off != 0) || sync())
+        return pos_type(off_type(-1));
+    // __width > 0 || __off == 0
+    int __whence;
+    switch (__way)
+    {
+    case ios_base::beg:
+        __whence = SEEK_SET;
+        break;
+    case ios_base::cur:
+        __whence = SEEK_CUR;
+        break;
+    case ios_base::end:
+        __whence = SEEK_END;
+        break;
+    default:
+        return pos_type(off_type(-1));
+    }
+    if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence))
+        return pos_type(off_type(-1));
+    pos_type __r = ftello(__file_);
+    __r.state(__st_);
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+typename basic_filebuf<_CharT, _Traits>::pos_type
+basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode __wch)
+{
+    if (__file_ == 0 || sync())
+        return pos_type(off_type(-1));
+    if (fseeko(__file_, __sp, SEEK_SET))
+        return pos_type(off_type(-1));
+    return __sp;
+}
+
+template <class _CharT, class _Traits>
+int
+basic_filebuf<_CharT, _Traits>::sync()
+{
+    if (__file_ == 0)
+        return 0;
+    if (__cm_ & ios_base::out)
+    {
+        if (this->pptr() != this->pbase())
+            if (overflow() == traits_type::eof())
+                return -1;
+        codecvt_base::result __r;
+        do
+        {
+            char* __extbe;
+            __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
+            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;
+    }
+    else if (__cm_ & ios_base::in)
+    {
+        off_type __c;
+        if (__always_noconv_)
+            __c = this->egptr() - this->gptr();
+        else
+        {
+            int __width = __cv_->encoding();
+            __c = __extbufend_ - __extbufnext_;
+            if (__width > 0)
+                __c += __width * (this->egptr() - this->gptr());
+            else
+            {
+                if (this->gptr() != this->egptr())
+                {
+                    reverse(this->gptr(), this->egptr());
+                    codecvt_base::result __r;
+                    const char_type* __e = this->gptr();
+                    char* __extbe;
+                    do
+                    {
+                        __r = __cv_->out(__st_, __e, this->egptr(), __e,
+                                         __extbuf_, __extbuf_ + __ebs_, __extbe);
+                        switch (__r)
+                        {
+                        case codecvt_base::noconv:
+                            __c += this->egptr() - this->gptr();
+                            break;
+                        case codecvt_base::ok:
+                        case codecvt_base::partial:
+                            __c += __extbe - __extbuf_;
+                            break;
+                        default:
+                            return -1;
+                        }
+                    } while (__r == codecvt_base::partial);
+                }
+            }
+        }
+        if (fseeko(__file_, -__c, SEEK_CUR))
+            return -1;
+        this->setg(0, 0, 0);
+        __cm_ = 0;
+    }
+    return 0;
+}
+
+template <class _CharT, class _Traits>
+void
+basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc)
+{
+    sync();
+    __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
+    bool __old_anc = __always_noconv_;
+    __always_noconv_ = __cv_->always_noconv();
+    if (__old_anc != __always_noconv_)
+    {
+        this->setg(0, 0, 0);
+        this->setp(0, 0);
+        // invariant, char_type is char, else we couldn't get here
+        if (__always_noconv_)  // need to dump __intbuf_
+        {
+            if (__owns_eb_)
+                delete [] __extbuf_;
+            __owns_eb_ = __owns_ib_;
+            __ebs_ = __ibs_;
+            __extbuf_ = (char*)__intbuf_;
+            __ibs_ = 0;
+            __intbuf_ = 0;
+            __owns_ib_ = false;
+        }
+        else  // need to obtain an __intbuf_.
+        {     // If __extbuf_ is user-supplied, use it, else new __intbuf_
+            if (!__owns_eb_ && __extbuf_ != __extbuf_min_)
+            {
+                __ibs_ = __ebs_;
+                __intbuf_ = (char_type*)__extbuf_;
+                __owns_ib_ = false;
+                __extbuf_ = new char[__ebs_];
+                __owns_eb_ = true;
+            }
+            else
+            {
+                __ibs_ = __ebs_;
+                __intbuf_ = new char_type[__ibs_];
+                __owns_ib_ = true;
+            }
+        }
+    }
+}
+
+template <class _CharT, class _Traits>
+bool
+basic_filebuf<_CharT, _Traits>::__read_mode()
+{
+    if (!(__cm_ & ios_base::in))
+    {
+        this->setp(0, 0);
+        if (__always_noconv_)
+            this->setg((char_type*)__extbuf_,
+                       (char_type*)__extbuf_ + __ebs_,
+                       (char_type*)__extbuf_ + __ebs_);
+        else
+            this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
+        __cm_ = ios_base::in;
+        return true;
+    }
+    return false;
+}
+
+template <class _CharT, class _Traits>
+void
+basic_filebuf<_CharT, _Traits>::__write_mode()
+{
+    if (!(__cm_ & ios_base::out))
+    {
+        this->setg(0, 0, 0);
+        if (__ebs_ > sizeof(__extbuf_min_))
+        {
+            if (__always_noconv_)
+                this->setp((char_type*)__extbuf_,
+                           (char_type*)__extbuf_ + (__ebs_ - 1));
+            else
+                this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
+        }
+        else
+            this->setp(0, 0);
+        __cm_ = ios_base::out;
+    }
+}
+
+// basic_ifstream
+
+template <class _CharT, class _Traits>
+class basic_ifstream
+    : public basic_istream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_ifstream();
+    explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
+    explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in);
+#ifdef _LIBCPP_MOVE
+    basic_ifstream(basic_ifstream&& __rhs);
+#endif
+
+#ifdef _LIBCPP_MOVE
+    basic_ifstream& operator=(basic_ifstream&& __rhs);
+#endif
+    void swap(basic_ifstream& __rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* __s, ios_base::openmode __mode = ios_base::in);
+    void open(const string& __s, ios_base::openmode __mode = ios_base::in);
+    void close();
+
+private:
+    basic_filebuf<char_type, traits_type> __sb_;
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ifstream<_CharT, _Traits>::basic_ifstream()
+    : basic_istream<char_type, traits_type>(&__sb_)
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
+    : basic_istream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode | ios_base::in) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
+    : basic_istream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode | ios_base::in) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
+    : basic_istream<char_type, traits_type>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    this->set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ifstream<_CharT, _Traits>&
+basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs)
+{
+    basic_istream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs)
+{
+    basic_istream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_filebuf<_CharT, _Traits>*
+basic_ifstream<_CharT, _Traits>::rdbuf() const
+{
+    return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+basic_ifstream<_CharT, _Traits>::is_open() const
+{
+    return __sb_.is_open();
+}
+
+template <class _CharT, class _Traits>
+void
+basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode | ios_base::in))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+void
+basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode | ios_base::in))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ifstream<_CharT, _Traits>::close()
+{
+    if (__sb_.close() == 0)
+        this->setstate(ios_base::failbit);
+}
+
+// basic_ofstream
+
+template <class _CharT, class _Traits>
+class basic_ofstream
+    : public basic_ostream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_ofstream();
+    explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out);
+    explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out);
+#ifdef _LIBCPP_MOVE
+    basic_ofstream(basic_ofstream&& __rhs);
+#endif
+
+#ifdef _LIBCPP_MOVE
+    basic_ofstream& operator=(basic_ofstream&& __rhs);
+#endif
+    void swap(basic_ofstream& __rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* __s, ios_base::openmode __mode = ios_base::out);
+    void open(const string& __s, ios_base::openmode __mode = ios_base::out);
+    void close();
+
+private:
+    basic_filebuf<char_type, traits_type> __sb_;
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ofstream<_CharT, _Traits>::basic_ofstream()
+    : basic_ostream<char_type, traits_type>(&__sb_)
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
+    : basic_ostream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode | ios_base::out) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
+    : basic_ostream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode | ios_base::out) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
+    : basic_ostream<char_type, traits_type>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    this->set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ofstream<_CharT, _Traits>&
+basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs)
+{
+    basic_ostream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs)
+{
+    basic_ostream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_filebuf<_CharT, _Traits>*
+basic_ofstream<_CharT, _Traits>::rdbuf() const
+{
+    return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+basic_ofstream<_CharT, _Traits>::is_open() const
+{
+    return __sb_.is_open();
+}
+
+template <class _CharT, class _Traits>
+void
+basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode | ios_base::out))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+void
+basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode | ios_base::out))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ofstream<_CharT, _Traits>::close()
+{
+    if (__sb_.close() == 0)
+        this->setstate(ios_base::failbit);
+}
+
+// basic_fstream
+
+template <class _CharT, class _Traits>
+class basic_fstream
+    : public basic_iostream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    basic_fstream();
+    explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
+    explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
+#ifdef _LIBCPP_MOVE
+    basic_fstream(basic_fstream&& __rhs);
+#endif
+
+#ifdef _LIBCPP_MOVE
+    basic_fstream& operator=(basic_fstream&& __rhs);
+#endif
+    void swap(basic_fstream& __rhs);
+
+    basic_filebuf<char_type, traits_type>* rdbuf() const;
+    bool is_open() const;
+    void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
+    void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
+    void close();
+
+private:
+    basic_filebuf<char_type, traits_type> __sb_;
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_fstream<_CharT, _Traits>::basic_fstream()
+    : basic_iostream<char_type, traits_type>(&__sb_)
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
+    : basic_iostream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
+    : basic_iostream<char_type, traits_type>(&__sb_)
+{
+    if (__sb_.open(__s, __mode) == 0)
+        this->setstate(ios_base::failbit);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
+    : basic_iostream<char_type, traits_type>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    this->set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_fstream<_CharT, _Traits>&
+basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs)
+{
+    basic_iostream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs)
+{
+    basic_iostream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_filebuf<_CharT, _Traits>*
+basic_fstream<_CharT, _Traits>::rdbuf() const
+{
+    return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+basic_fstream<_CharT, _Traits>::is_open() const
+{
+    return __sb_.is_open();
+}
+
+template <class _CharT, class _Traits>
+void
+basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+void
+basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
+{
+    if (__sb_.open(__s, __mode))
+        this->clear();
+    else
+        this->setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_fstream<_CharT, _Traits>::close()
+{
+    if (__sb_.close() == 0)
+        this->setstate(ios_base::failbit);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FSTREAM
diff --git a/include/functional b/include/functional
new file mode 100644
index 0000000..1551fb5
--- /dev/null
+++ b/include/functional
@@ -0,0 +1,1850 @@
+// -*- C++ -*-
+//===------------------------ functional ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FUNCTIONAL
+#define _LIBCPP_FUNCTIONAL
+
+/*
+    functional synopsis
+
+namespace std
+{
+
+template <class Arg, class Result>
+struct unary_function
+{
+    typedef Arg    argument_type;
+    typedef Result result_type;
+};
+
+template <class Arg1, class Arg2, class Result>
+struct binary_function
+{
+    typedef Arg1   first_argument_type;
+    typedef Arg2   second_argument_type;
+    typedef Result result_type;
+};
+
+template <ObjectType T>
+class reference_wrapper
+    : public unary_function<T1, R> // if wrapping a unary functor
+    : public binary_function<T1, T2, R> // if wraping a binary functor
+{
+public:
+    // types
+    typedef T type;
+    typedef see below result_type; // Not always defined
+
+    // construct/copy/destroy
+    reference_wrapper(T&);
+    reference_wrapper(T&&) = delete; // do not bind to temps
+    reference_wrapper(const reference_wrapper<T>& x);
+
+    // assignment
+    reference_wrapper& operator=(const reference_wrapper<T>& x);
+
+    // access
+    operator T& () const;
+    T& get() const;
+
+    // invoke
+    template <class... ArgTypes>
+      requires Callable<T, ArgTypes&&...>
+        Callable<T, ArgTypes&&...>::result_type
+          operator() (ArgTypes&&...) const;
+};
+
+template <ObjectType T> reference_wrapper<T> ref(T& t);
+template <ObjectType T> void ref(const T&& t) = delete; // LWG 688
+template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t);
+
+template <ObjectType T> reference_wrapper<const T> cref(const T& t);
+template <ObjectType T> void cref(const T&& t) = delete; // LWG 688
+template <ObjectType T> reference_wrapper<const T> cref(reference_wrapper<T> t);
+
+template <class T>
+struct plus : binary_function<T, T, T>
+{
+    T operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct minus : binary_function<T, T, T>
+{
+    T operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct multiplies : binary_function<T, T, T>
+{
+    T operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct divides : binary_function<T, T, T>
+{
+    T operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct modulus : binary_function<T, T, T>
+{
+    T operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct negate : unary_function<T, T>
+{
+    T operator()(const T& x) const;
+};
+
+template <class T>
+struct equal_to : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct not_equal_to : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct greater : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct less : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct greater_equal : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct less_equal : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct logical_and : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct logical_or : binary_function<T, T, bool>
+{
+    bool operator()(const T& x, const T& y) const;
+};
+
+template <class T>
+struct logical_not : unary_function<T, bool>
+{
+    bool operator()(const T& x) const;
+};
+
+template <class Predicate>
+class unary_negate
+    : public unary_function<typename Predicate::argument_type, bool>
+{
+public:
+    explicit unary_negate(const Predicate& pred);
+    bool operator()(const typename Predicate::argument_type& x) const;
+};
+
+template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
+
+template <class Predicate>
+class binary_negate
+    : public binary_function<typename Predicate::first_argument_type,
+                             typename Predicate::second_argument_type,
+                             bool>
+{
+public:
+    explicit binary_negate(const Predicate& pred);
+    bool operator()(const typename Predicate::first_argument_type& x,
+                    const typename Predicate::second_argument_type& y) const;
+};
+
+template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
+
+template<class T> struct is_bind_expression;
+template<class T> struct is_placeholder;
+
+template<CopyConstructible Fn, CopyConstructible... Types> 
+  unspecified bind(Fn, Types...);
+template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> 
+  unspecified bind(Fn, Types...);
+
+namespace placeholders { 
+  // M is the implementation-defined number of placeholders 
+  extern unspecified _1;
+  extern unspecified _2;
+  . 
+  . 
+  . 
+  extern unspecified _M;
+}
+
+template <class Operation>
+class binder1st
+    : public unary_function<typename Operation::second_argument_type,
+                            typename Operation::result_type>
+{
+protected:
+    Operation                               op;
+    typename Operation::first_argument_type value;
+public:
+    binder1st(const Operation& x, const typename Operation::first_argument_type y);
+    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
+    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
+};
+
+template <class Operation, class T>
+binder1st<Operation> bind1st(const Operation& op, const T& x);
+
+template <class Operation>
+class binder2nd
+    : public unary_function<typename Operation::first_argument_type,
+                            typename Operation::result_type>
+{
+protected:
+    Operation                                op;
+    typename Operation::second_argument_type value;
+public:
+    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
+    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
+    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
+};
+
+template <class Operation, class T>
+binder2nd<Operation> bind2nd(const Operation& op, const T& x);
+
+template <class Arg, class Result>
+class pointer_to_unary_function : public unary_function<Arg, Result>
+{
+public:
+    explicit pointer_to_unary_function(Result (*f)(Arg));
+    Result operator()(Arg x) const;
+};
+
+template <class Arg, class Result>
+pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
+
+template <class Arg1, class Arg2, class Result>
+class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
+{
+public:
+    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
+    Result operator()(Arg1 x, Arg2 y) const;
+};
+
+template <class Arg1, class Arg2, class Result>
+pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
+
+template<class S, class T>
+class mem_fun_t : public unary_function<T*, S>
+{
+public:
+    explicit mem_fun_t(S (T::*p)());
+    S operator()(T* p) const;
+};
+
+template<class S, class T, class A>
+class mem_fun1_t : public binary_function<T*, A, S>
+{
+public:
+    explicit mem_fun1_t(S (T::*p)(A));
+    S operator()(T* p, A x) const;
+};
+
+template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());
+template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
+
+template<class S, class T>
+class mem_fun_ref_t : public unary_function<T, S>
+{
+public:
+    explicit mem_fun_ref_t(S (T::*p)());
+    S operator()(T& p) const;
+};
+
+template<class S, class T, class A>
+class mem_fun1_ref_t : public binary_function<T, A, S>
+{
+public:
+    explicit mem_fun1_ref_t(S (T::*p)(A));
+    S operator()(T& p, A x) const;
+};
+
+template<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());
+template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
+
+template <class S, class T>
+class const_mem_fun_t : public unary_function<const T*, S>
+{
+public:
+    explicit const_mem_fun_t(S (T::*p)() const);
+    S operator()(const T* p) const;
+};
+
+template <class S, class T, class A>
+class const_mem_fun1_t : public binary_function<const T*, A, S>
+{
+public:
+    explicit const_mem_fun1_t(S (T::*p)(A) const);
+    S operator()(const T* p, A x) const;
+};
+
+template <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);
+template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
+
+template <class S, class T>
+class const_mem_fun_ref_t : public unary_function<T, S>
+{
+public:
+    explicit const_mem_fun_ref_t(S (T::*p)() const);
+    S operator()(const T& p) const;
+};
+
+template <class S, class T, class A>
+class const_mem_fun1_ref_t : public binary_function<T, A, S>
+{
+public:
+    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
+    S operator()(const T& p, A x) const;
+};
+
+template <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);
+template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
+
+class bad_function_call
+    : public exception
+{
+};
+
+template<Returnable R, class T> unspecified mem_fn(R T::* pm);
+template<Returnable R, class T, CopyConstructible... Args> 
+  unspecified mem_fn(R (T::* pm)(Args...));
+template<Returnable R, class T, CopyConstructible... Args> 
+  unspecified mem_fn(R (T::* pm)(Args...) const);
+template<Returnable R, class T, CopyConstructible... Args> 
+  unspecified mem_fn(R (T::* pm)(Args...) volatile);
+template<Returnable R, class T, CopyConstructible... Args> 
+  unspecified mem_fn(R (T::* pm)(Args...) const volatile);
+
+template<FunctionType> class function; // undefined
+
+template<Returnable R, CopyConstructible... ArgTypes>
+class function<R(ArgTypes...)>
+  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
+                                      // ArgTypes contains T1
+  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
+                                      // ArgTypes contains T1 and T2
+{
+public:
+    typedef R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function();
+    function(nullptr_t);
+    function(const function&);
+    function(function&&);
+    template<class F>
+      requires CopyConstructible<F> && Callable<F, ArgTypes...>
+            && Convertible<Callable<F, ArgTypes...>::result_type, R>
+      function(F);
+//     template<class F>
+//       requires CopyConstructible<F> && Callable<F, ArgTypes...>
+//             && Convertible<Callable<F, ArgTypes...>::result_type, R>
+//       function(F&&);
+    template<Allocator Alloc>
+      function(allocator_arg_t, const Alloc&);
+    template<Allocator Alloc>
+      function(allocator_arg_t, const Alloc&, nullptr_t);
+    template<Allocator Alloc>
+      function(allocator_arg_t, const Alloc&, const function&);
+    template<Allocator Alloc>
+      function(allocator_arg_t, const Alloc&, function&&);
+    template<class F, Allocator Alloc>
+      function(allocator_arg_t, const Alloc&, F);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F&&);
+
+    function& operator=(const function&);
+    function& operator=(function&&);
+    function& operator=(nullptr_t);
+    template<class F>
+      requires CopyConstructible<F> && Callable<F, ArgTypes..>
+            && Convertible<Callable<F, ArgTypes...>::result_type
+      function& operator=(F);
+//     template<class F>
+//       requires CopyConstructible<F> && Callable<F, ArgTypes...>
+//             && Convertible<Callable<F, ArgTypes...>::result_type, R>
+//       function& operator=(F&&);
+    template<class F>
+      requires Callable<F, ArgTypes...>
+            && Convertible<Callable<F, ArgTypes...>::result_type, R>
+      function& operator=(reference_wrapper<F>);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+    template<class F, Allocator Alloc>
+      requires Callable<F, ArgTypes...>
+            && Convertible<Callable<F, ArgTypes...>::result_type, R>
+      void assign(F, const Alloc&);
+
+    // 20.7.16.2.3, function capacity:
+    explicit operator bool() const;
+
+    // deleted overloads close possible hole in the type system
+    template<class R2, class... ArgTypes2>
+      bool operator==(const function<R2(ArgTypes2...)>&) = delete;
+    template<class R2, class... ArgTypes2>
+      bool operator!=(const function<R2(ArgTypes2...)>&) = delete;
+
+    // 20.7.16.2.4, function invocation:
+    R operator()(ArgTypes...) const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename T>
+      requires Callable<T, ArgTypes...>
+            && Convertible<Callable<T, ArgTypes...>::result_type, R>
+      T* target();
+    template <typename T>
+      requires Callable<T, ArgTypes...>
+            && Convertible<Callable<T, ArgTypes...>::result_type, R>
+      const T* target() const;
+};
+
+// 20.7.16.2.6, Null pointer comparisons: 
+template <MoveConstructible R, MoveConstructible ... ArgTypes> 
+  bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
+
+template <MoveConstructible R, MoveConstructible ... ArgTypes> 
+  bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
+
+template <MoveConstructible R, MoveConstructible ... ArgTypes> 
+  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
+
+template <MoveConstructible  R, MoveConstructible ... ArgTypes> 
+  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
+
+// 20.7.16.2.7, specialized algorithms: 
+template <MoveConstructible  R, MoveConstructible ... ArgTypes> 
+  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
+
+template <class T> struct hash;
+
+template <> struct hash<bool>;
+template <> struct hash<char>;
+template <> struct hash<signed char>;
+template <> struct hash<unsigned char>;
+template <> struct hash<char16_t>;
+template <> struct hash<char32_t>;
+template <> struct hash<wchar_t>;
+template <> struct hash<short>;
+template <> struct hash<unsigned short>;
+template <> struct hash<int>;
+template <> struct hash<unsigned int>;
+template <> struct hash<long>;
+template <> struct hash<long long>;
+template <> struct hash<unsigned long>;
+template <> struct hash<unsigned long long>;
+
+template <> struct hash<float>;
+template <> struct hash<double>;
+template <> struct hash<long double>;
+
+template<class T> struct hash<T*>;
+
+}  // std
+
+POLICY:  For non-variadic implementations, the number of arguments is limited
+         to 3.  It is hoped that the need for non-variadic implementations
+         will be minimal.
+
+*/
+
+#include <__config>
+#include <type_traits>
+#include <typeinfo>
+#include <exception>
+#include <memory>
+#include <tuple>
+
+#include <__functional_base>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+struct plus : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x + __y;}
+};
+
+template <class _Tp>
+struct minus : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x - __y;}
+};
+
+template <class _Tp>
+struct multiplies : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x * __y;}
+};
+
+template <class _Tp>
+struct divides : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x / __y;}
+};
+
+template <class _Tp>
+struct modulus : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x % __y;}
+};
+
+template <class _Tp>
+struct negate : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
+        {return -__x;}
+};
+
+template <class _Tp>
+struct equal_to : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x == __y;}
+};
+
+template <class _Tp>
+struct not_equal_to : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x != __y;}
+};
+
+template <class _Tp>
+struct greater : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x > __y;}
+};
+
+template <class _Tp>
+struct less : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x < __y;}
+};
+
+template <class _Tp>
+struct greater_equal : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x >= __y;}
+};
+
+template <class _Tp>
+struct less_equal : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x <= __y;}
+};
+
+template <class _Tp>
+struct logical_and : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x && __y;}
+};
+
+template <class _Tp>
+struct logical_or : binary_function<_Tp, _Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x || __y;}
+};
+
+template <class _Tp>
+struct logical_not : unary_function<_Tp, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
+        {return !__x;}
+};
+
+template <class _Tp>
+struct bit_and : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x & __y;}
+};
+
+template <class _Tp>
+struct bit_or : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x | __y;}
+};
+
+template <class _Tp>
+struct bit_xor : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x ^ __y;}
+};
+
+template <class _Predicate>
+class unary_negate
+    : public unary_function<typename _Predicate::argument_type, bool>
+{
+    _Predicate __pred_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
+        : __pred_(__pred) {}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
+        {return !__pred_(__x);}
+};
+
+template <class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+unary_negate<_Predicate>
+not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
+
+template <class _Predicate>
+class binary_negate
+    : public binary_function<typename _Predicate::first_argument_type,
+                             typename _Predicate::second_argument_type,
+                             bool>
+{
+    _Predicate __pred_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
+        : __pred_(__pred) {}
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
+                    const typename _Predicate::second_argument_type& __y) const
+        {return !__pred_(__x, __y);}
+};
+
+template <class _Predicate>
+inline _LIBCPP_INLINE_VISIBILITY
+binary_negate<_Predicate>
+not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
+
+template <class __Operation>
+class binder1st
+    : public unary_function<typename __Operation::second_argument_type,
+                            typename __Operation::result_type>
+{
+protected:
+    __Operation                               op;
+    typename __Operation::first_argument_type value;
+public:
+    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
+                               const typename __Operation::first_argument_type __y)
+        : op(__x), value(__y) {}
+    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
+        (typename __Operation::second_argument_type& __x) const
+            {return op(value, __x);}
+    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
+        (const typename __Operation::second_argument_type& __x) const
+            {return op(value, __x);}
+};
+
+template <class __Operation, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+binder1st<__Operation>
+bind1st(const __Operation& __op, const _Tp& __x)
+    {return binder1st<__Operation>(__op, __x);}
+
+template <class __Operation>
+class binder2nd
+    : public unary_function<typename __Operation::first_argument_type,
+                            typename __Operation::result_type>
+{
+protected:
+    __Operation                                op;
+    typename __Operation::second_argument_type value;
+public:
+    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
+        : op(__x), value(__y) {}
+    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
+        (      typename __Operation::first_argument_type& __x) const
+            {return op(__x, value);}
+    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
+        (const typename __Operation::first_argument_type& __x) const
+            {return op(__x, value);}
+};
+
+template <class __Operation, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+binder2nd<__Operation>
+bind2nd(const __Operation& __op, const _Tp& __x)
+    {return binder2nd<__Operation>(__op, __x);}
+
+template <class _Arg, class _Result>
+class pointer_to_unary_function : public unary_function<_Arg, _Result>
+{
+    _Result (*__f_)(_Arg);
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
+        : __f_(__f) {}
+    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
+        {return __f_(__x);}
+};
+
+template <class _Arg, class _Result>
+inline _LIBCPP_INLINE_VISIBILITY
+pointer_to_unary_function<_Arg,_Result>
+ptr_fun(_Result (*__f)(_Arg))
+    {return pointer_to_unary_function<_Arg,_Result>(__f);}
+
+template <class _Arg1, class _Arg2, class _Result>
+class pointer_to_binary_function : public binary_function<_Arg1, _Arg2, _Result>
+{
+    _Result (*__f_)(_Arg1, _Arg2);
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
+        : __f_(__f) {}
+    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
+        {return __f_(__x, __y);}
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+inline _LIBCPP_INLINE_VISIBILITY
+pointer_to_binary_function<_Arg1,_Arg2,_Result>
+ptr_fun(_Result (*__f)(_Arg1,_Arg2))
+    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
+
+template<class _Sp, class _Tp>
+class mem_fun_t : public unary_function<_Tp*, _Sp>
+{
+    _Sp (_Tp::*__p_)();
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
+        {return (__p->*__p_)();}
+};
+
+template<class _Sp, class _Tp, class _Ap>
+class mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
+{
+    _Sp (_Tp::*__p_)(_Ap);
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
+        {return (__p->*__p_)(__x);}
+};
+
+template<class _Sp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+mem_fun_t<_Sp,_Tp>
+mem_fun(_Sp (_Tp::*__f)())
+    {return mem_fun_t<_Sp,_Tp>(__f);}
+
+template<class _Sp, class _Tp, class _Ap>
+inline _LIBCPP_INLINE_VISIBILITY
+mem_fun1_t<_Sp,_Tp,_Ap>
+mem_fun(_Sp (_Tp::*__f)(_Ap))
+    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
+
+template<class _Sp, class _Tp>
+class mem_fun_ref_t : public unary_function<_Tp, _Sp>
+{
+    _Sp (_Tp::*__p_)();
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
+        {return (__p.*__p_)();}
+};
+
+template<class _Sp, class _Tp, class _Ap>
+class mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
+{
+    _Sp (_Tp::*__p_)(_Ap);
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
+        {return (__p.*__p_)(__x);}
+};
+
+template<class _Sp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+mem_fun_ref_t<_Sp,_Tp>
+mem_fun_ref(_Sp (_Tp::*__f)())
+    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
+
+template<class _Sp, class _Tp, class _Ap>
+inline _LIBCPP_INLINE_VISIBILITY
+mem_fun1_ref_t<_Sp,_Tp,_Ap>
+mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
+    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
+
+template <class _Sp, class _Tp>
+class const_mem_fun_t : public unary_function<const _Tp*, _Sp>
+{
+    _Sp (_Tp::*__p_)() const;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
+        {return (__p->*__p_)();}
+};
+
+template <class _Sp, class _Tp, class _Ap>
+class const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
+{
+    _Sp (_Tp::*__p_)(_Ap) const;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
+        {return (__p->*__p_)(__x);}
+};
+
+template <class _Sp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+const_mem_fun_t<_Sp,_Tp>
+mem_fun(_Sp (_Tp::*__f)() const)
+    {return const_mem_fun_t<_Sp,_Tp>(__f);}
+
+template <class _Sp, class _Tp, class _Ap>
+inline _LIBCPP_INLINE_VISIBILITY
+const_mem_fun1_t<_Sp,_Tp,_Ap>
+mem_fun(_Sp (_Tp::*__f)(_Ap) const)
+    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
+
+template <class _Sp, class _Tp>
+class const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
+{
+    _Sp (_Tp::*__p_)() const;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
+        {return (__p.*__p_)();}
+};
+
+template <class _Sp, class _Tp, class _Ap>
+class const_mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
+{
+    _Sp (_Tp::*__p_)(_Ap) const;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
+        : __p_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
+        {return (__p.*__p_)(__x);}
+};
+
+template <class _Sp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+const_mem_fun_ref_t<_Sp,_Tp>
+mem_fun_ref(_Sp (_Tp::*__f)() const)
+    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
+
+template <class _Sp, class _Tp, class _Ap>
+inline _LIBCPP_INLINE_VISIBILITY
+const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
+mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
+    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
+
+
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
+#include <__functional_03>
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+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
+    template <class... _ArgTypes>
+       typename __invoke_return<type, _ArgTypes...>::type
+          operator() (_ArgTypes&&... __args)
+          {
+              return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...);
+          }
+};
+
+template<class _R, class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R _T::*>
+mem_fn(_R _T::* __pm)
+{
+    return __mem_fn<_R _T::*>(__pm);
+}
+
+template<class _R, class _T, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_Args...)>
+mem_fn(_R (_T::* __pm)(_Args...))
+{
+    return __mem_fn<_R (_T::*)(_Args...)>(__pm);
+}
+
+template<class _R, class _T, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_Args...) const>
+mem_fn(_R (_T::* __pm)(_Args...) const)
+{
+    return __mem_fn<_R (_T::*)(_Args...) const>(__pm);
+}
+
+template<class _R, class _T, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_Args...) volatile>
+mem_fn(_R (_T::* __pm)(_Args...) volatile)
+{
+    return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm);
+}
+
+template<class _R, class _T, class ..._Args>
+inline _LIBCPP_INLINE_VISIBILITY
+__mem_fn<_R (_T::*)(_Args...) const volatile>
+mem_fn(_R (_T::* __pm)(_Args...) const volatile)
+{
+    return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm);
+}
+
+// bad_function_call
+
+class bad_function_call
+    : public exception
+{
+};
+
+template<class _Fp> class function; // undefined
+
+namespace __function
+{
+
+template<class _R, class ..._ArgTypes>
+struct __maybe_derive_from_unary_function
+{
+};
+
+template<class _R, class _A1>
+struct __maybe_derive_from_unary_function<_R(_A1)>
+    : public unary_function<_A1, _R>
+{
+};
+
+template<class _R, class ..._ArgTypes>
+struct __maybe_derive_from_binary_function
+{
+};
+
+template<class _R, class _A1, class _A2>
+struct __maybe_derive_from_binary_function<_R(_A1, _A2)>
+    : public binary_function<_A1, _A2, _R>
+{
+};
+
+template<class _Fp> class __base;
+
+template<class _R, class ..._ArgTypes>
+class __base<_R(_ArgTypes...)>
+{
+    __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 _R operator()(_ArgTypes&& ...) = 0;
+    virtual const void* target(const type_info&) const = 0;
+    virtual const std::type_info& target_type() const = 0;
+};
+
+template<class _FD, class _Alloc, class _FB> class __func;
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+class __func<_F, _Alloc, _R(_ArgTypes...)>
+    : public  __base<_R(_ArgTypes...)>
+{
+    __compressed_pair<_F, _Alloc> __f_;
+public:
+    explicit __func(_F __f) : __f_(_STD::move(__f)) {}
+    explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
+    virtual __base<_R(_ArgTypes...)>* __clone() const;
+    virtual void __clone(__base<_R(_ArgTypes...)>*) const;
+    virtual void destroy();
+    virtual void destroy_deallocate();
+    virtual _R operator()(_ArgTypes&& ... __arg);
+    virtual const void* target(const type_info&) const;
+    virtual const std::type_info& target_type() const;
+};
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+__base<_R(_ArgTypes...)>*
+__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    typedef __allocator_destructor<_A> _D;
+    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
+    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
+    return __hold.release();
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+void
+__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const
+{
+    ::new (__p) __func(__f_.first(), __f_.second());
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+void
+__func<_F, _Alloc, _R(_ArgTypes...)>::destroy()
+{
+    __f_.~__compressed_pair<_F, _Alloc>();
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+void
+__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate()
+{
+    typedef typename _Alloc::template rebind<__func>::other _A;
+    _A __a(__f_.second());
+    __f_.~__compressed_pair<_F, _Alloc>();
+    __a.deallocate(this, 1);
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+_R
+__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
+{
+    return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...);
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+const void*
+__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const
+{
+    if (__ti == typeid(_F))
+        return &__f_.first();
+    return (const void*)0;
+}
+
+template<class _F, class _Alloc, class _R, class ..._ArgTypes>
+const std::type_info&
+__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const
+{
+    return typeid(_F);
+}
+
+}  // __function
+
+template<class _R, class ..._ArgTypes>
+class function<_R(_ArgTypes...)>
+    : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>,
+      public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)>
+{
+    typedef __function::__base<_R(_ArgTypes...)> __base;
+    aligned_storage<3*sizeof(void*)>::type __buf_;
+    __base* __f_;
+
+    template <class _F>
+        static bool __not_null(const _F&) {return true;}
+    template <class _R2, class ..._A>
+        static bool __not_null(_R2 (*__p)(_A...)) {return __p;}
+    template <class _R2, class _C, class ..._A>
+        static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;}
+    template <class _R2, class _C, class ..._A>
+        static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;}
+    template <class _R2, class _C, class ..._A>
+        static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;}
+    template <class _R2, class _C, class ..._A>
+        static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;}
+    template <class _R2, class ..._A>
+        static bool __not_null(const function<_R(_A...)>& __p) {return __p;}
+public:
+    typedef _R result_type;
+
+    // 20.7.16.2.1, construct/copy/destroy:
+    explicit function() : __f_(0) {}
+    function(nullptr_t) : __f_(0) {}
+    function(const function&);
+#ifdef _LIBCPP_MOVE
+    function(function&&);
+#endif
+    template<class _F>
+      function(_F,
+               typename enable_if<!is_integral<_F>::value>::type* = 0);
+
+//     template<class _Alloc>
+//       function(allocator_arg_t, const _Alloc&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, nullptr_t);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, const function&);
+//     template<Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, function&&);
+//     template<class F, Allocator Alloc>
+//       function(allocator_arg_t, const Alloc&, F);
+
+    function& operator=(const function&);
+    function& operator=(function&&);
+    function& operator=(nullptr_t);
+    template<class _F>
+      typename enable_if
+      <
+        !is_integral<typename decay<_F>::type>::value,
+        function&
+      >::type
+      operator=(_F&&);
+
+    ~function();
+
+    // 20.7.16.2.2, function modifiers:
+    void swap(function&);
+//     template<class _F, class _Alloc>
+//       void assign(_F, const _Alloc&);
+
+    // 20.7.16.2.3, function capacity:
+    /*explicit*/ operator bool() const {return __f_;}
+
+private:
+    // deleted overloads close possible hole in the type system
+    template<class _R2, class... _ArgTypes2>
+      bool operator==(const function<_R2(_ArgTypes2...)>&);// = delete;
+    template<class _R2, class... _ArgTypes2>
+      bool operator!=(const function<_R2(_ArgTypes2...)>&);// = delete;
+public:
+    // 20.7.16.2.4, function invocation:
+    _R operator()(_ArgTypes...) const;
+
+    // 20.7.16.2.5, function target access:
+    const std::type_info& target_type() const;
+    template <typename _T> _T* target();
+    template <typename _T> const _T* target() const;
+};
+
+template<class _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>::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 _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>::function(function&& __f)
+{
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+    {
+        __f_ = __f.__f_;
+        __f.__f_ = 0;
+    }
+}
+
+template<class _R, class ..._ArgTypes>
+template <class _F>
+function<_R(_ArgTypes...)>::function(_F __f,
+                                     typename enable_if<!is_integral<_F>::value>::type*)
+    : __f_(0)
+{
+    if (__not_null(__f))
+    {
+        typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
+        if (sizeof(_FF) <= sizeof(__buf_))
+        {
+            __f_ = (__base*)&__buf_;
+            ::new (__f_) _FF(_STD::move(__f));
+        }
+        else
+        {
+            typedef allocator<_FF> _A;
+            _A __a;
+            typedef __allocator_destructor<_A> _D;
+            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
+            ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a));
+            __f_ = __hold.release();
+        }
+    }
+}
+
+template<class _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>&
+function<_R(_ArgTypes...)>::operator=(const function& __f)
+{
+    function(__f).swap(*this);
+    return *this;
+}
+
+template<class _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>&
+function<_R(_ArgTypes...)>::operator=(function&& __f)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+    if (__f.__f_ == 0)
+        __f_ = 0;
+    else if (__f.__f_ == (__base*)&__f.__buf_)
+    {
+        __f_ = (__base*)&__buf_;
+        __f.__f_->__clone(__f_);
+    }
+    else
+    {
+        __f_ = __f.__f_;
+        __f.__f_ = 0;
+    }
+}
+
+template<class _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>&
+function<_R(_ArgTypes...)>::operator=(nullptr_t)
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+    __f_ = 0;
+}
+
+template<class _R, class ..._ArgTypes>
+template <class _F>
+typename enable_if
+<
+    !is_integral<typename decay<_F>::type>::value,
+    function<_R(_ArgTypes...)>&
+>::type
+function<_R(_ArgTypes...)>::operator=(_F&& __f)
+{
+    function(_STD::forward<_F>(__f)).swap(*this);
+    return *this;
+}
+
+template<class _R, class ..._ArgTypes>
+function<_R(_ArgTypes...)>::~function()
+{
+    if (__f_ == (__base*)&__buf_)
+        __f_->destroy();
+    else if (__f_)
+        __f_->destroy_deallocate();
+}
+
+template<class _R, class ..._ArgTypes>
+void
+function<_R(_ArgTypes...)>::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
+        _STD::swap(__f_, __f.__f_);
+}
+
+template<class _R, class ..._ArgTypes>
+_R
+function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
+{
+    if (__f_ == 0)
+        throw bad_function_call();
+    return (*__f_)(_STD::forward<_ArgTypes>(__arg)...);
+}
+
+template<class _R, class ..._ArgTypes>
+const std::type_info&
+function<_R(_ArgTypes...)>::target_type() const
+{
+    if (__f_ == 0)
+        return typeid(void);
+    return __f_->target_type();
+}
+
+template<class _R, class ..._ArgTypes>
+template <typename _T>
+_T*
+function<_R(_ArgTypes...)>::target()
+{
+    if (__f_ == 0)
+        return (_T*)0;
+    return (_T*)__f_->target(typeid(_T));
+}
+
+template<class _R, class ..._ArgTypes>
+template <typename _T>
+const _T*
+function<_R(_ArgTypes...)>::target() const
+{
+    if (__f_ == 0)
+        return (const _T*)0;
+    return (const _T*)__f_->target(typeid(_T));
+}
+
+template <class _R, class... _ArgTypes> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;}
+
+template <class _R, class... _ArgTypes> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;}
+
+template <class _R, class... _ArgTypes> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;}
+
+template <class _R, class... _ArgTypes> 
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;}
+
+template <class _R, class... _ArgTypes> 
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y)
+{return __x.swap(__y);}
+
+template<class _Tp> struct __is_bind_expression : public false_type {};
+template<class _Tp> struct 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 is_placeholder
+    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
+
+namespace placeholders
+{
+
+template <int _N> 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 _N>
+struct __is_placeholder<placeholders::__ph<_N> >
+    : public integral_constant<int, _N> {};
+
+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...>)
+{
+    return __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(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 = get<_Indx>(__uj);
+    return __t;
+//    return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(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 _F, class _BoundArgs, class _TupleUj>
+struct __bind_return;
+
+template <class _F, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __invoke_return
+    <
+        _F&,
+        typename __mu_return
+        <
+            _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _F, class ..._BoundArgs, class _TupleUj>
+struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
+{
+    typedef typename __invoke_return
+    <
+        _F&,
+        typename __mu_return
+        <
+            const _BoundArgs,
+            _TupleUj
+        >::type...
+    >::type type;
+};
+
+template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __bind_return<_F, _BoundArgs, _Args>::type
+__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
+                _Args&& __args)
+{
+    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
+}
+
+template<class _F, class ..._BoundArgs> 
+class __bind
+    : public __weak_result_type<_F>
+{
+    _F __f_;
+    tuple<_BoundArgs...> __bound_args_;
+
+    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
+public:
+    __bind(__bind&& __b)
+        : __f_(_STD::move(__b.__f_)),
+          __bound_args_(_STD::move(__b.__bound_args_)) {}
+
+    template <class _G, class ..._BA>
+      explicit __bind(_G&& __f, _BA&& ...__bound_args)
+        : __f_(_STD::forward<_G>(__f)),
+          __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        typename __bind_return<_F, 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<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
+        operator()(_Args&& ...__args) const
+        {
+            return __apply_functor(__f_, __bound_args_, __indices(), 
+                                   tuple<_Args&&...>(__args...));
+        }
+};
+
+template<class _F, class ..._BoundArgs> 
+struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
+
+template<class _R, class _F, class ..._BoundArgs> 
+class __bind_r
+    : public __bind<_F, _BoundArgs...>
+{
+    typedef __bind<_F, _BoundArgs...> base;
+public:
+    typedef _R result_type;
+
+    template <class _G, class ..._BA>
+      explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
+        : base(_STD::forward<_G>(__f),
+               _STD::forward<_BA>(__bound_args)...) {}
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args)
+        {
+            return base::operator()(_STD::forward<_Args>(__args)...);
+        }
+
+    template <class ..._Args>
+        result_type
+        operator()(_Args&& ...__args) const
+        {
+            return base::operator()(_STD::forward<_Args>(__args)...);
+        }
+};
+
+template<class _R, class _F, class ..._BoundArgs> 
+struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
+
+template<class _F, class ..._BoundArgs> 
+inline _LIBCPP_INLINE_VISIBILITY
+__bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...>
+bind(_F&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
+}
+
+template<class _R, class _F, class ..._BoundArgs> 
+inline _LIBCPP_INLINE_VISIBILITY
+__bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...>
+bind(_F&& __f, _BoundArgs&&... __bound_args)
+{
+    typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
+    return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+template <>
+struct hash<bool>
+    : public unary_function<bool, size_t>
+{
+    size_t operator()(bool __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<char>
+    : public unary_function<char, size_t>
+{
+    size_t operator()(char __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<signed char>
+    : public unary_function<signed char, size_t>
+{
+    size_t operator()(signed char __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<unsigned char>
+    : public unary_function<unsigned char, size_t>
+{
+    size_t operator()(unsigned char __v) const {return static_cast<size_t>(__v);}
+};
+
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+
+template <>
+struct hash<char16_t>
+    : public unary_function<char16_t, size_t>
+{
+    size_t operator()(char16_t __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<char32_t>
+    : public unary_function<char32_t, size_t>
+{
+    size_t operator()(char32_t __v) const {return static_cast<size_t>(__v);}
+};
+
+#endif
+
+template <>
+struct hash<wchar_t>
+    : public unary_function<wchar_t, size_t>
+{
+    size_t operator()(wchar_t __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<short>
+    : public unary_function<short, size_t>
+{
+    size_t operator()(short __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<unsigned short>
+    : public unary_function<unsigned short, size_t>
+{
+    size_t operator()(unsigned short __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<int>
+    : public unary_function<int, size_t>
+{
+    size_t operator()(int __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<unsigned int>
+    : public unary_function<unsigned int, size_t>
+{
+    size_t operator()(unsigned int __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<long>
+    : public unary_function<long, size_t>
+{
+    size_t operator()(long __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<unsigned long>
+    : public unary_function<unsigned long, size_t>
+{
+    size_t operator()(unsigned long __v) const {return static_cast<size_t>(__v);}
+};
+
+template <>
+struct hash<long long>
+    : public unary_function<long long, size_t>
+{
+    size_t operator()(long long __v) const
+    {
+        size_t __r = 0;
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
+            __r ^= __p[__i];
+        return __r;
+    }
+};
+
+template <>
+struct hash<unsigned long long>
+    : public unary_function<unsigned long long, size_t>
+{
+    size_t operator()(unsigned long long __v) const
+    {
+        size_t __r = 0;
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
+            __r ^= __p[__i];
+        return __r;
+    }
+};
+
+template <>
+struct hash<float>
+    : public unary_function<float, size_t>
+{
+    size_t operator()(float __v) const
+    {
+        if (__v == 0)
+            return 0;
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        return *__p;
+    }
+};
+
+template <>
+struct hash<double>
+    : public unary_function<double, size_t>
+{
+    size_t operator()(double __v) const
+    {
+        if (__v == 0)
+            return 0;
+        size_t __r = 0;
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
+            __r ^= __p[__i];
+        return __r;
+    }
+};
+
+template <>
+struct hash<long double>
+    : public unary_function<long double, size_t>
+{
+    size_t operator()(long double __v) const
+    {
+        if (__v == 0)
+            return 0;
+        size_t __r = 0;
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
+            __r ^= __p[__i];
+        return __r;
+    }
+};
+
+template<class _Tp>
+struct hash<_Tp*>
+    : public unary_function<_Tp*, size_t>
+{
+    size_t operator()(_Tp* __v) const
+    {
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        return *__p;
+    }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FUNCTIONAL
diff --git a/include/future b/include/future
new file mode 100644
index 0000000..96230e7
--- /dev/null
+++ b/include/future
@@ -0,0 +1,500 @@
+// -*- C++ -*-
+//===--------------------------- future -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_FUTURE
+#define _LIBCPP_FUTURE
+
+/*
+    future synopsis
+
+namespace std
+{
+
+enum class future_errc
+{
+    broken_promise,
+    future_already_retrieved,
+    promise_already_satisfied,
+    no_state
+};
+
+enum class launch
+{
+    any,
+    async,
+    sync
+};
+
+enum class future_status
+{
+    ready,
+    timeout,
+    deferred
+};
+
+template <> struct is_error_code_enum<future_errc> : public true_type { };
+error_code make_error_code(future_errc e);
+error_condition make_error_condition(future_errc e);
+
+const error_category& future_category();
+
+class future_error
+    : public logic_error
+{
+public:
+    future_error(error_code ec);  // exposition only
+
+    const error_code& code() const throw();
+    const char*       what() const throw();
+};
+
+template <class R>
+class promise
+{
+public:
+    promise();
+    template <class Allocator>
+        promise(allocator_arg_t, const Allocator& a);
+    promise(promise&& rhs);
+    promise(const promise& rhs) = delete;
+    ~promise();
+
+    // assignment
+    promise& operator=(promise&& rhs);
+    promise& operator=(const promise& rhs) = delete;
+    void swap(promise& other);
+
+    // retrieving the result
+    future<R> get_future();
+
+    // setting the result
+    void set_value(const R& r);
+    void set_value(R&& r);
+    void set_exception(exception_ptr p);
+
+    // setting the result with deferred notification
+    void set_value_at_thread_exit(const R& r);
+    void set_value_at_thread_exit(R&& r);
+    void set_exception_at_thread_exit(exception_ptr p);
+};
+
+template <class R>
+class promise<R&>
+{
+public:
+    promise();
+    template <class Allocator>
+        promise(allocator_arg_t, const Allocator& a);
+    promise(promise&& rhs);
+    promise(const promise& rhs) = delete;
+    ~promise();
+
+    // assignment
+    promise& operator=(promise&& rhs);
+    promise& operator=(const promise& rhs) = delete;
+    void swap(promise& other);
+
+    // retrieving the result
+    future<R> get_future();
+
+    // setting the result
+    void set_value(R& r);
+    void set_exception(exception_ptr p);
+
+    // setting the result with deferred notification
+    void set_value_at_thread_exit(R&);
+    void set_exception_at_thread_exit(exception_ptr p);
+};
+
+template <>
+class promise<void>
+{
+public:
+    promise();
+    template <class Allocator>
+        promise(allocator_arg_t, const Allocator& a);
+    promise(promise&& rhs);
+    promise(const promise& rhs) = delete;
+    ~promise();
+
+    // assignment
+    promise& operator=(promise&& rhs);
+    promise& operator=(const promise& rhs) = delete;
+    void swap(promise& other);
+
+    // retrieving the result
+    future<R> get_future();
+
+    // setting the result
+    void set_value();
+    void set_exception(exception_ptr p);
+
+    // setting the result with deferred notification
+    void set_value_at_thread_exit();
+    void set_exception_at_thread_exit(exception_ptr p);
+};
+
+template <class R> void swap(promise<R>& x, promise<R>& y);
+
+template <class R, class Alloc>
+    struct uses_allocator<promise<R>, Alloc> : public true_type {};
+
+template <class R>
+class future
+{
+public:
+    future();
+    future(future&&);
+    future(const future& rhs) = delete;
+    ~future();
+    future& operator=(const future& rhs) = delete;
+    future& operator=(future&&);
+
+    // retrieving the value
+    R get();
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class R>
+class future<R&>
+{
+public:
+    future();
+    future(future&&);
+    future(const future& rhs) = delete;
+    ~future();
+    future& operator=(const future& rhs) = delete;
+    future& operator=(future&&);
+
+    // retrieving the value
+    R& get();
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <>
+class future<void>
+{
+public:
+    future();
+    future(future&&);
+    future(const future& rhs) = delete;
+    ~future();
+    future& operator=(const future& rhs) = delete;
+    future& operator=(future&&);
+
+    // retrieving the value
+    void get();
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class R>
+class shared_future
+{
+public:
+    shared_future();
+    shared_future(const shared_future& rhs);
+    shared_future(future<R>&&);
+    shared_future(shared_future&& rhs);
+    ~shared_future();
+    shared_future& operator=(const shared_future& rhs);
+    shared_future& operator=(shared_future&& rhs);
+
+    // retrieving the value
+    const R& get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class R>
+class shared_future<R&>
+{
+public:
+    shared_future();
+    shared_future(const shared_future& rhs);
+    shared_future(future<R>&&);
+    shared_future(shared_future&& rhs);
+    ~shared_future();
+    shared_future& operator=(const shared_future& rhs);
+    shared_future& operator=(shared_future&& rhs);
+
+    // retrieving the value
+    R& get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <>
+class shared_future<void>
+{
+public:
+    shared_future();
+    shared_future(const shared_future& rhs);
+    shared_future(future<R>&&);
+    shared_future(shared_future&& rhs);
+    ~shared_future();
+    shared_future& operator=(const shared_future& rhs);
+    shared_future& operator=(shared_future&& rhs);
+
+    // retrieving the value
+    void get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class R>
+class atomic_future
+{
+public:
+    atomic_future();
+    atomic_future(const atomic_future& rhs);
+    atomic_future(future<R>&&);
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& rhs);
+
+    // retrieving the value
+    const R& get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class R>
+class atomic_future<R&>
+{
+public:
+    atomic_future();
+    atomic_future(const atomic_future& rhs);
+    atomic_future(future<R>&&);
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& rhs);
+
+    // retrieving the value
+    R& get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <>
+class atomic_future<void>
+{
+public:
+    atomic_future();
+    atomic_future(const atomic_future& rhs);
+    atomic_future(future<R>&&);
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& rhs);
+
+    // retrieving the value
+    void get() const;
+
+    // functions to check state
+    bool valid() const;
+
+    void wait() const;
+    template <class Rep, class Period>
+        future_status
+        wait_for(const chrono::duration<Rep, Period>& rel_time) const;
+    template <class Clock, class Duration>
+        future_status
+        wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
+};
+
+template <class F, class... Args>
+  future<typename result_of<F(Args...)>::type>
+  async(F&& f, Args&&... args);
+
+template <class F, class... Args>
+  future<typename result_of<F(Args...)>::type>
+  async(launch policy, F&& f, Args&&... args);
+
+template <class> class packaged_task;	// undefined
+
+template <class R, class... ArgTypes>
+class packaged_task<R(ArgTypes...)>
+{
+public:
+    typedef R result_type;
+
+    // construction and destruction
+    packaged_task();
+    template <class F>
+        explicit packaged_task(F f);
+    template <class F, class Allocator>
+        explicit packaged_task(allocator_arg_t, const Allocator& a, F f);
+    explicit packaged_task(R(*f)(ArgTypes...));
+    template <class F>
+        explicit packaged_task(F&& f);
+    template <class F, class Allocator>
+        explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
+    ~packaged_task();
+
+    // no copy
+    packaged_task(packaged_task&) = delete;
+    packaged_task& operator=(packaged_task&) = delete;
+
+    // move support
+    packaged_task(packaged_task&& other);
+    packaged_task& operator=(packaged_task&& other);
+    void swap(packaged_task& other);
+
+    explicit operator bool() const;
+
+    // result retrieval
+    future<R> get_future();
+
+    // execution
+    void operator()(ArgTypes... );
+    void make_ready_at_thread_exit(ArgTypes...);
+
+    void reset();
+};
+
+template <class R>
+  void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&);
+
+template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <system_error>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+//enum class future_errc
+struct future_errc
+{
+enum _ {
+    broken_promise,
+    future_already_retrieved,
+    promise_already_satisfied,
+    no_state
+};
+
+    _ __v_;
+
+    future_errc(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+
+};
+
+//enum class launch
+struct launch
+{
+enum _ {
+    any,
+    async,
+    sync
+};
+
+    _ __v_;
+
+    launch(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+
+};
+
+//enum class future_status
+struct future_status
+{
+enum _ {
+    ready,
+    timeout,
+    deferred
+};
+
+    _ __v_;
+
+    future_status(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_FUTURE
diff --git a/include/initializer_list b/include/initializer_list
new file mode 100644
index 0000000..d780be9
--- /dev/null
+++ b/include/initializer_list
@@ -0,0 +1,80 @@
+// -*- C++ -*-
+//===----------------------- initializer_list -----------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_INITIALIZER_LIST
+#define _LIBCPP_INITIALIZER_LIST
+
+/*
+    initializer_list synopsis
+
+namespace std
+{
+
+template<class E>
+class initializer_list
+{
+public:
+    typedef E        value_type;
+    typedef const E& reference;
+    typedef const E& const_reference;
+    typedef size_t   size_type;
+
+    typedef const E* iterator;
+    typedef const E* const_iterator;
+
+    initializer_list();
+
+    size_t   size()  const;
+    const E* begin() const;
+    const E* end()   const;
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cstddef>
+
+#pragma GCC system_header
+
+namespace std  // purposefully not versioned
+{
+
+template<class _E>
+class initializer_list
+{
+    const _E* __begin_;
+    size_t    __size_;
+
+    _LIBCPP_ALWAYS_INLINE
+    initializer_list(const _E* __b, size_t __s)
+        : __begin_(__b),
+          __size_(__s)
+        {}
+public:
+    typedef _E        value_type;
+    typedef const _E& reference;
+    typedef const _E& const_reference;
+    typedef size_t    size_type;
+
+    typedef const _E* iterator;
+    typedef const _E* const_iterator;
+
+    _LIBCPP_ALWAYS_INLINE initializer_list() : __begin_(nullptr), __size_(0) {}
+
+    _LIBCPP_ALWAYS_INLINE size_t    size()  const {return __size_;}
+    _LIBCPP_ALWAYS_INLINE const _E* begin() const {return __begin_;}
+    _LIBCPP_ALWAYS_INLINE const _E* end()   const {return __begin_ + __size_;}
+};
+
+}  // std
+
+#endif  // _LIBCPP_INITIALIZER_LIST
diff --git a/include/iomanip b/include/iomanip
new file mode 100644
index 0000000..d5d2785
--- /dev/null
+++ b/include/iomanip
@@ -0,0 +1,481 @@
+// -*- C++ -*-
+//===--------------------------- iomanip ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_IOMANIP
+#define _LIBCPP_IOMANIP
+
+/*
+    iomanip synopsis
+
+// types T1, T2, ... are unspecified implementation types
+T1 resetiosflags(ios_base::fmtflags mask);
+T2 setiosflags (ios_base::fmtflags mask);
+T3 setbase(int base);
+template<charT> T4 setfill(charT c);
+T5 setprecision(int n);
+T6 setw(int n);
+template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
+template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
+template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
+template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <istream>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// resetiosflags
+
+class __iom_t1
+{
+    ios_base::fmtflags __mask_;
+public:
+    explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x)
+    {
+        __is.unsetf(__x.__mask_);
+        return __is;
+    }
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x)
+    {
+        __os.unsetf(__x.__mask_);
+        return __os;
+    }
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t1
+resetiosflags(ios_base::fmtflags __mask)
+{
+    return __iom_t1(__mask);
+}
+
+// setiosflags
+
+class __iom_t2
+{
+    ios_base::fmtflags __mask_;
+public:
+    explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x)
+    {
+        __is.setf(__x.__mask_);
+        return __is;
+    }
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x)
+    {
+        __os.setf(__x.__mask_);
+        return __os;
+    }
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t2
+setiosflags(ios_base::fmtflags __mask)
+{
+    return __iom_t2(__mask);
+}
+
+// setbase
+
+class __iom_t3
+{
+    int __base_;
+public:
+    explicit __iom_t3(int __b) : __base_(__b) {}
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x)
+    {
+        __is.setf(__x.__base_ == 8  ? ios_base::oct :
+                  __x.__base_ == 10 ? ios_base::dec :
+                  __x.__base_ == 16 ? ios_base::hex :
+                  ios_base::fmtflags(0), ios_base::basefield);
+        return __is;
+    }
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x)
+    {
+        __os.setf(__x.__base_ == 8  ? ios_base::oct :
+                  __x.__base_ == 10 ? ios_base::dec :
+                  __x.__base_ == 16 ? ios_base::hex :
+                  ios_base::fmtflags(0), ios_base::basefield);
+        return __os;
+    }
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t3
+setbase(int __base)
+{
+    return __iom_t3(__base);
+}
+
+// setfill
+
+template<class _CharT>
+class __iom_t4
+{
+    _CharT __fill_;
+public:
+    explicit __iom_t4(_CharT __c) : __fill_(__c) {}
+
+    template <class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x)
+    {
+        __os.fill(__x.__fill_);
+        return __os;
+    }
+};
+
+template<class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t4<_CharT>
+setfill(_CharT __c)
+{
+    return __iom_t4<_CharT>(__c);
+}
+
+// setprecision
+
+class __iom_t5
+{
+    int __n_;
+public:
+    explicit __iom_t5(int __n) : __n_(__n) {}
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x)
+    {
+        __is.precision(__x.__n_);
+        return __is;
+    }
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x)
+    {
+        __os.precision(__x.__n_);
+        return __os;
+    }
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t5
+setprecision(int __n)
+{
+    return __iom_t5(__n);
+}
+
+// setw
+
+class __iom_t6
+{
+    int __n_;
+public:
+    explicit __iom_t6(int __n) : __n_(__n) {}
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x)
+    {
+        __is.width(__x.__n_);
+        return __is;
+    }
+
+    template <class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x)
+    {
+        __os.width(__x.__n_);
+        return __os;
+    }
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t6
+setw(int __n)
+{
+    return __iom_t6(__n);
+}
+
+// get_money
+
+template <class _MoneyT> class __iom_t7;
+
+template <class _CharT, class _Traits, class _MoneyT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
+
+template <class _MoneyT>
+class __iom_t7
+{
+    _MoneyT& __mon_;
+    bool __intl_;
+public:
+    __iom_t7(_MoneyT& __mon, bool __intl)
+        : __mon_(__mon), __intl_(__intl) {}
+
+    template <class _CharT, class _Traits, class _M>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_M>& __x);
+};
+
+template <class _CharT, class _Traits, class _MoneyT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __s(__is);
+        if (__s)
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            typedef money_get<_CharT, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            const _F& __mf = use_facet<_F>(__is.getloc());
+            __mf.get(_I(__is), _I(), __x.__intl_, __is, __err, __x.__mon_);
+            __is.setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template <class _MoneyT>
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t7<_MoneyT>
+get_money(_MoneyT& __mon, bool __intl = false)
+{
+    return __iom_t7<_MoneyT>(__mon, __intl);
+}
+
+// put_money
+
+template <class _MoneyT> class __iom_t8;
+
+template <class _CharT, class _Traits, class _MoneyT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
+
+template <class _MoneyT>
+class __iom_t8
+{
+    const _MoneyT& __mon_;
+    bool __intl_;
+public:
+    __iom_t8(const _MoneyT& __mon, bool __intl)
+        : __mon_(__mon), __intl_(__intl) {}
+
+    template <class _CharT, class _Traits, class _M>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_M>& __x);
+};
+
+template <class _CharT, class _Traits, class _MoneyT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _O;
+            typedef money_put<_CharT, _O> _F;
+            const _F& __mf = use_facet<_F>(__os.getloc());
+            if (__mf.put(_O(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
+                __os.setstate(ios_base::badbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template <class _MoneyT>
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t8<_MoneyT>
+put_money(const _MoneyT& __mon, bool __intl = false)
+{
+    return __iom_t8<_MoneyT>(__mon, __intl);
+}
+
+// get_time
+
+template <class _CharT> class __iom_t9;
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
+
+template <class _CharT>
+class __iom_t9
+{
+    tm* __tm_;
+    const _CharT* __fmt_;
+public:
+    __iom_t9(tm* __tm, const _CharT* __fmt)
+        : __tm_(__tm), __fmt_(__fmt) {}
+
+    template <class _C, class _Traits>
+    friend
+    basic_istream<_C, _Traits>&
+    operator>>(basic_istream<_C, _Traits>& __is, const __iom_t9<_C>& __x);
+};
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __s(__is);
+        if (__s)
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            typedef time_get<_CharT, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            const _F& __tf = use_facet<_F>(__is.getloc());
+            __tf.get(_I(__is), _I(), __is, __err, __x.__tm_,
+                     __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
+            __is.setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t9<_CharT>
+get_time(tm* __tm, const _CharT* __fmt)
+{
+    return __iom_t9<_CharT>(__tm, __fmt);
+}
+
+// put_time
+
+template <class _CharT> class __iom_t10;
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
+
+template <class _CharT>
+class __iom_t10
+{
+    const tm* __tm_;
+    const _CharT* __fmt_;
+public:
+    __iom_t10(const tm* __tm, const _CharT* __fmt)
+        : __tm_(__tm), __fmt_(__fmt) {}
+
+    template <class _C, class _Traits>
+    friend
+    basic_ostream<_C, _Traits>&
+    operator<<(basic_ostream<_C, _Traits>& __os, const __iom_t10<_C>& __x);
+};
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _O;
+            typedef time_put<_CharT, _O> _F;
+            const _F& __tf = use_facet<_F>(__os.getloc());
+            if (__tf.put(_O(__os), __os, __os.fill(), __x.__tm_,
+                         __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed())
+                __os.setstate(ios_base::badbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+__iom_t10<_CharT>
+put_time(const tm* __tm, const _CharT* __fmt)
+{
+    return __iom_t10<_CharT>(__tm, __fmt);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_IOMANIP
diff --git a/include/ios b/include/ios
new file mode 100644
index 0000000..8e58e58
--- /dev/null
+++ b/include/ios
@@ -0,0 +1,965 @@
+// -*- C++ -*-
+//===---------------------------- ios -------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_IOS
+#define _LIBCPP_IOS
+
+/*
+    ios synopsis
+
+#include <iosfwd>
+
+namespace std
+{
+
+typedef OFF_T streamoff;
+typedef SZ_T streamsize;
+template <class stateT> class fpos;
+
+class ios_base
+{
+public:
+    class failure;
+
+    typedef T1 fmtflags;
+    static const fmtflags boolalpha;
+    static const fmtflags dec;
+    static const fmtflags fixed;
+    static const fmtflags hex;
+    static const fmtflags internal;
+    static const fmtflags left;
+    static const fmtflags oct;
+    static const fmtflags right;
+    static const fmtflags scientific;
+    static const fmtflags showbase;
+    static const fmtflags showpoint;
+    static const fmtflags showpos;
+    static const fmtflags skipws;
+    static const fmtflags unitbuf;
+    static const fmtflags uppercase;
+    static const fmtflags adjustfield;
+    static const fmtflags basefield;
+    static const fmtflags floatfield;
+
+    typedef T2 iostate;
+    static const iostate badbit;
+    static const iostate eofbit;
+    static const iostate failbit;
+    static const iostate goodbit;
+
+    typedef T3 openmode;
+    static const openmode app;
+    static const openmode ate;
+    static const openmode binary;
+    static const openmode in;
+    static const openmode out;
+    static const openmode trunc;
+
+    typedef T4 seekdir;
+    static const seekdir beg;
+    static const seekdir cur;
+    static const seekdir end;
+
+    class Init;
+
+    // 27.5.2.2 fmtflags state:
+    fmtflags flags() const;
+    fmtflags flags(fmtflags fmtfl);
+    fmtflags setf(fmtflags fmtfl);
+    fmtflags setf(fmtflags fmtfl, fmtflags mask);
+    void unsetf(fmtflags mask);
+
+    streamsize precision() const;
+    streamsize precision(streamsize prec);
+    streamsize width() const;
+    streamsize width(streamsize wide);
+
+    // 27.5.2.3 locales:
+    locale imbue(const locale& loc);
+    locale getloc() const;
+
+    // 27.5.2.5 storage:
+    static int xalloc();
+    long& iword(int index);
+    void*& pword(int index);
+
+    // destructor
+    virtual ~ios_base();
+
+    // 27.5.2.6 callbacks;
+    enum event { erase_event, imbue_event, copyfmt_event };
+    typedef void (*event_callback)(event, ios_base&, int index);
+    void register_callback(event_callback fn, int index);
+
+    ios_base(const ios_base&) = delete;
+    ios_base& operator=(const ios_base&) = delete;
+
+    static bool sync_with_stdio(bool sync = true);
+
+protected:
+    ios_base();
+};
+
+template <class charT, class traits = char_traits<charT> >
+class basic_ios
+    : public ios_base
+{
+public:
+    // types:
+    typedef charT char_type;
+    typedef typename traits::int_type int_type;
+    typedef typename traits::pos_type pos_type;
+    typedef typename traits::off_type off_type;
+    typedef traits traits_type;
+
+    operator unspecified-bool-type() const;
+    bool operator!() const;
+    iostate rdstate() const;
+    void clear(iostate state = goodbit);
+    void setstate(iostate state);
+    bool good() const;
+    bool eof() const;
+    bool fail() const;
+    bool bad() const;
+
+    iostate exceptions() const;
+    void exceptions(iostate except);
+
+    // 27.5.4.1 Constructor/destructor:
+    explicit basic_ios(basic_streambuf<charT,traits>* sb);
+    virtual ~basic_ios();
+
+    // 27.5.4.2 Members:
+    basic_ostream<charT,traits>* tie() const;
+    basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
+
+    basic_streambuf<charT,traits>* rdbuf() const;
+    basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
+
+    basic_ios& copyfmt(const basic_ios& rhs);
+
+    char_type fill() const;
+    char_type fill(char_type ch);
+
+    locale imbue(const locale& loc);
+
+    char narrow(char_type c, char dfault) const;
+    char_type widen(char c) const;
+
+    basic_ios(const basic_ios& ) = delete;
+    basic_ios& operator=(const basic_ios&) = delete;
+
+protected:
+    basic_ios();
+    void init(basic_streambuf<charT,traits>* sb);
+    void move(basic_ios& rhs);
+    void swap(basic_ios& rhs);
+    void set_rdbuf(basic_streambuf<charT, traits>* sb);
+};
+
+// 27.5.5, manipulators:
+ios_base& boolalpha (ios_base& str);
+ios_base& noboolalpha(ios_base& str);
+ios_base& showbase (ios_base& str);
+ios_base& noshowbase (ios_base& str);
+ios_base& showpoint (ios_base& str);
+ios_base& noshowpoint(ios_base& str);
+ios_base& showpos (ios_base& str);
+ios_base& noshowpos (ios_base& str);
+ios_base& skipws (ios_base& str);
+ios_base& noskipws (ios_base& str);
+ios_base& uppercase (ios_base& str);
+ios_base& nouppercase(ios_base& str);
+ios_base& unitbuf (ios_base& str);
+ios_base& nounitbuf (ios_base& str);
+
+// 27.5.5.2 adjustfield:
+ios_base& internal (ios_base& str);
+ios_base& left (ios_base& str);
+ios_base& right (ios_base& str);
+
+// 27.5.5.3 basefield:
+ios_base& dec (ios_base& str);
+ios_base& hex (ios_base& str);
+ios_base& oct (ios_base& str);
+
+// 27.5.5.4 floatfield:
+ios_base& fixed (ios_base& str);
+ios_base& scientific (ios_base& str);
+ios_base& hexfloat (ios_base& str);
+ios_base& defaultfloat(ios_base& str);
+
+// 27.5.5.5 error reporting:
+enum class io_errc
+{
+    stream = 1
+};
+
+concept_map ErrorCodeEnum<io_errc> { };
+error_code make_error_code(io_errc e);
+error_condition make_error_condition(io_errc e);
+storage-class-specifier const error_category& iostream_category;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <iosfwd>
+#include <__locale>
+#include <system_error>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+typedef ptrdiff_t streamsize;
+
+class ios_base
+{
+public:
+    class failure;
+
+    typedef unsigned int fmtflags;
+    static const fmtflags boolalpha   = 0x0001;
+    static const fmtflags dec         = 0x0002;
+    static const fmtflags fixed       = 0x0004;
+    static const fmtflags hex         = 0x0008;
+    static const fmtflags internal    = 0x0010;
+    static const fmtflags left        = 0x0020;
+    static const fmtflags oct         = 0x0040;
+    static const fmtflags right       = 0x0080;
+    static const fmtflags scientific  = 0x0100;
+    static const fmtflags showbase    = 0x0200;
+    static const fmtflags showpoint   = 0x0400;
+    static const fmtflags showpos     = 0x0800;
+    static const fmtflags skipws      = 0x1000;
+    static const fmtflags unitbuf     = 0x2000;
+    static const fmtflags uppercase   = 0x4000;
+    static const fmtflags adjustfield = left | right | internal;
+    static const fmtflags basefield   = dec | oct | hex;
+    static const fmtflags floatfield  = scientific | fixed;
+
+    typedef unsigned int iostate;
+    typedef iostate      io_state;
+    static const iostate badbit  = 0x1;
+    static const iostate eofbit  = 0x2;
+    static const iostate failbit = 0x4;
+    static const iostate goodbit = 0x0;
+
+    typedef unsigned int openmode;
+    typedef openmode     open_mode;
+    static const openmode app    = 0x01;
+    static const openmode ate    = 0x02;
+    static const openmode binary = 0x04;
+    static const openmode in     = 0x08;
+    static const openmode out    = 0x10;
+    static const openmode trunc  = 0x20;
+
+    enum seekdir {beg, cur, end};
+    typedef seekdir seek_dir;
+
+    typedef _STD::streamoff streamoff;
+    typedef _STD::streampos streampos;
+
+    class Init;
+
+    // 27.5.2.2 fmtflags state:
+    fmtflags flags() const;
+    fmtflags flags(fmtflags __fmtfl);
+    fmtflags setf(fmtflags __fmtfl);
+    fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
+    void unsetf(fmtflags __mask);
+
+    streamsize precision() const;
+    streamsize precision(streamsize __prec);
+    streamsize width() const;
+    streamsize width(streamsize __wide);
+
+    // 27.5.2.3 locales:
+    locale imbue(const locale& __loc);
+    locale getloc() const;
+
+    // 27.5.2.5 storage:
+    static int xalloc();
+    long& iword(int __index);
+    void*& pword(int __index);
+
+    // destructor
+    virtual ~ios_base();
+
+    // 27.5.2.6 callbacks;
+    enum event { erase_event, imbue_event, copyfmt_event };
+    typedef void (*event_callback)(event, ios_base&, int __index);
+    void register_callback(event_callback __fn, int __index);
+
+private:
+    ios_base(const ios_base&); // = delete;
+    ios_base& operator=(const ios_base&); // = delete;
+
+public:
+    static bool sync_with_stdio(bool __sync = true);
+
+    iostate rdstate() const;
+    void clear(iostate __state = goodbit);
+    void setstate(iostate __state);
+    
+    bool good() const; 
+    bool eof() const; 
+    bool fail() const; 
+    bool bad() const; 
+
+    iostate exceptions() const; 
+    void exceptions(iostate __except);
+
+    void __set_badbit_and_consider_rethrow();
+    void __set_failbit_and_consider_rethrow();
+
+protected:
+    ios_base() {// purposefully does no initialization
+               }
+
+    void init(void* __sb);
+    _LIBCPP_ALWAYS_INLINE void* rdbuf() const {return __rdbuf_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    void rdbuf(void* __sb)
+    {
+        __rdbuf_ = __sb;
+        clear();
+    }
+
+    void __call_callbacks(event);
+    void copyfmt(const ios_base&);
+    void move(ios_base&);
+    void swap(ios_base&);
+
+    _LIBCPP_ALWAYS_INLINE
+    void set_rdbuf(void* __sb)
+    {
+        __rdbuf_ = __sb;
+    }
+
+private:
+    // All data members must be scalars
+    fmtflags        __fmtflags_;
+    streamsize      __precision_;
+    streamsize      __width_;
+    iostate         __rdstate_;
+    iostate         __exceptions_;
+    void*           __rdbuf_;
+    void*           __loc_;
+    event_callback* __fn_;
+    int*            __index_;
+    size_t          __event_size_;
+    size_t          __event_cap_;
+    static int      __xindex_;
+    long*           __iarray_;
+    size_t          __iarray_size_;
+    size_t          __iarray_cap_;
+    void**          __parray_;
+    size_t          __parray_size_;
+    size_t          __parray_cap_;
+};
+
+//enum class io_errc
+struct io_errc
+{
+enum _ {
+    stream = 1
+};
+    _ __v_;
+
+    _LIBCPP_ALWAYS_INLINE io_errc(_ __v) : __v_(__v) {}
+    _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;}
+};
+
+template <> struct is_error_code_enum<io_errc> : public true_type { };
+template <> struct is_error_code_enum<io_errc::_> : public true_type { };
+
+const error_category& iostream_category();
+
+inline _LIBCPP_INLINE_VISIBILITY
+error_code
+make_error_code(io_errc __e)
+{
+    return error_code(static_cast<int>(__e), iostream_category());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+error_condition
+make_error_condition(io_errc __e)
+{
+    return error_condition(static_cast<int>(__e), iostream_category());
+}
+
+class ios_base::failure
+    : public system_error
+{ 
+public: 
+    explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
+    explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); 
+    virtual ~failure() throw();
+};
+
+class ios_base::Init
+{
+public:
+    Init();
+    ~Init();
+};
+
+// fmtflags
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::fmtflags
+ios_base::flags() const
+{
+    return __fmtflags_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::fmtflags
+ios_base::flags(fmtflags __fmtfl)
+{
+    fmtflags __r = __fmtflags_;
+    __fmtflags_ = __fmtfl;
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::fmtflags
+ios_base::setf(fmtflags __fmtfl)
+{
+    fmtflags __r = __fmtflags_;
+    __fmtflags_ |= __fmtfl;
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+void
+ios_base::unsetf(fmtflags __mask)
+{
+    __fmtflags_ &= ~__mask;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::fmtflags
+ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
+{
+    fmtflags __r = __fmtflags_;
+    unsetf(__mask);
+    __fmtflags_ |= __fmtfl & __mask;
+    return __r;
+}
+
+// precision
+
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+ios_base::precision() const
+{
+    return __precision_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+ios_base::precision(streamsize __prec)
+{
+    streamsize __r = __precision_;
+    __precision_ = __prec;
+    return __r;
+}
+
+// width
+
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+ios_base::width() const
+{
+    return __width_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+ios_base::width(streamsize __wide)
+{
+    streamsize __r = __width_;
+    __width_ = __wide;
+    return __r;
+}
+
+// iostate
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::iostate
+ios_base::rdstate() const
+{
+    return __rdstate_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+void
+ios_base::setstate(iostate __state)
+{
+    clear(__rdstate_ | __state);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+ios_base::good() const
+{
+    return __rdstate_ == 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+ios_base::eof() const
+{
+    return __rdstate_ & eofbit;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+ios_base::fail() const
+{
+    return __rdstate_ & (failbit | badbit);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+ios_base::bad() const
+{
+    return __rdstate_ & badbit;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base::iostate
+ios_base::exceptions() const
+{
+    return __exceptions_;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+void
+ios_base::exceptions(iostate __except)
+{
+    __exceptions_ = __except;
+    clear(__rdstate_);
+}
+
+template <class _CharT, class _Traits>
+class basic_ios
+    : public ios_base
+{
+public:
+    // types:
+    typedef _CharT char_type;
+    typedef _Traits traits_type;
+
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    _LIBCPP_ALWAYS_INLINE // explicit
+        operator bool() const {return !fail();}
+    _LIBCPP_ALWAYS_INLINE bool operator!() const    {return  fail();}
+    _LIBCPP_ALWAYS_INLINE iostate rdstate() const   {return ios_base::rdstate();}
+    _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);}
+    _LIBCPP_ALWAYS_INLINE void setstate(iostate __state) {ios_base::setstate(__state);}
+    _LIBCPP_ALWAYS_INLINE bool good() const {return ios_base::good();}
+    _LIBCPP_ALWAYS_INLINE bool eof() const  {return ios_base::eof();}
+    _LIBCPP_ALWAYS_INLINE bool fail() const {return ios_base::fail();}
+    _LIBCPP_ALWAYS_INLINE bool bad() const  {return ios_base::bad();}
+
+    _LIBCPP_ALWAYS_INLINE iostate exceptions() const {return ios_base::exceptions();}
+    _LIBCPP_ALWAYS_INLINE void exceptions(iostate __except) {ios_base::exceptions(__except);}
+
+    // 27.5.4.1 Constructor/destructor:
+    explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
+    virtual ~basic_ios();
+
+    // 27.5.4.2 Members:
+    basic_ostream<char_type, traits_type>* tie() const;
+    basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
+
+    basic_streambuf<char_type, traits_type>* rdbuf() const;
+    basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
+
+    basic_ios& copyfmt(const basic_ios& __rhs);
+
+    char_type fill() const;
+    char_type fill(char_type __ch);
+
+    locale imbue(const locale& __loc);
+
+    char narrow(char_type __c, char __dfault) const;
+    char_type widen(char __c) const;
+
+protected:
+    basic_ios() {// purposefully does no initialization
+                }
+    void init(basic_streambuf<char_type, traits_type>* __sb);
+
+    void move(basic_ios& __rhs);
+#ifdef _LIBCPP_MOVE
+    void move(basic_ios&& __rhs) {move(__rhs);}
+#endif
+    void swap(basic_ios& __rhs);
+    void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
+private:
+    basic_ostream<char_type, traits_type>* __tie_;
+    char_type __fill_;
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
+{
+    init(__sb);
+}
+
+template <class _CharT, class _Traits>
+basic_ios<_CharT, _Traits>::~basic_ios()
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
+{
+    ios_base::init(__sb);
+    __tie_ = 0;
+    __fill_ = widen(' ');
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>*
+basic_ios<_CharT, _Traits>::tie() const
+{
+    return __tie_;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>*
+basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
+{
+    basic_ostream<char_type, traits_type>* __r = __tie_;
+    __tie_ = __tiestr;
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_streambuf<_CharT, _Traits>*
+basic_ios<_CharT, _Traits>::rdbuf() const
+{
+    return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_streambuf<_CharT, _Traits>*
+basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
+{
+    basic_streambuf<char_type, traits_type>* __r = rdbuf();
+    ios_base::rdbuf(__sb);
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+locale
+basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
+{
+    locale __r = getloc();
+    ios_base::imbue(__loc);
+    if (rdbuf())
+        rdbuf()->pubimbue(__loc);
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+char
+basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
+{
+    return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT
+basic_ios<_CharT, _Traits>::widen(char __c) const
+{
+    return use_facet<ctype<char_type> >(getloc()).widen(__c);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT
+basic_ios<_CharT, _Traits>::fill() const
+{
+    return __fill_;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT
+basic_ios<_CharT, _Traits>::fill(char_type __ch)
+{
+    char_type __r = __fill_;
+    __fill_ = __ch;
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+basic_ios<_CharT, _Traits>&
+basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
+{
+    if (this != &__rhs)
+    {
+        __call_callbacks(erase_event);
+        ios_base::copyfmt(__rhs);
+        __tie_ = __rhs.__tie_;
+        __fill_ = __rhs.__fill_;
+        __call_callbacks(copyfmt_event);
+        exceptions(__rhs.exceptions());
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
+{
+    ios_base::move(__rhs);
+    __tie_ = __rhs.__tie_;
+    __rhs.__tie_ = 0;
+    __fill_ = __rhs.__fill_;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs)
+{
+    ios_base::swap(__rhs);
+    _STD::swap(__tie_, __rhs.__tie_);
+    _STD::swap(__fill_, __rhs.__fill_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
+{
+    ios_base::set_rdbuf(__sb);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+boolalpha(ios_base& __str)
+{
+    __str.setf(ios_base::boolalpha);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+noboolalpha(ios_base& __str)
+{
+    __str.unsetf(ios_base::boolalpha);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+showbase(ios_base& __str)
+{
+    __str.setf(ios_base::showbase);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+noshowbase(ios_base& __str)
+{
+    __str.unsetf(ios_base::showbase);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+showpoint(ios_base& __str)
+{
+    __str.setf(ios_base::showpoint);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+noshowpoint(ios_base& __str)
+{
+    __str.unsetf(ios_base::showpoint);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+showpos(ios_base& __str)
+{
+    __str.setf(ios_base::showpos);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+noshowpos(ios_base& __str)
+{
+    __str.unsetf(ios_base::showpos);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+skipws(ios_base& __str)
+{
+    __str.setf(ios_base::skipws);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+noskipws(ios_base& __str)
+{
+    __str.unsetf(ios_base::skipws);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+uppercase(ios_base& __str)
+{
+    __str.setf(ios_base::uppercase);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+nouppercase(ios_base& __str)
+{
+    __str.unsetf(ios_base::uppercase);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+unitbuf(ios_base& __str)
+{
+    __str.setf(ios_base::unitbuf);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+nounitbuf(ios_base& __str)
+{
+    __str.unsetf(ios_base::unitbuf);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+internal(ios_base& __str)
+{
+    __str.setf(ios_base::internal, ios_base::adjustfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+left(ios_base& __str)
+{
+    __str.setf(ios_base::left, ios_base::adjustfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+right(ios_base& __str)
+{
+    __str.setf(ios_base::right, ios_base::adjustfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+dec(ios_base& __str)
+{
+    __str.setf(ios_base::dec, ios_base::basefield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+hex(ios_base& __str)
+{
+    __str.setf(ios_base::hex, ios_base::basefield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+oct(ios_base& __str)
+{
+    __str.setf(ios_base::oct, ios_base::basefield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+fixed(ios_base& __str)
+{
+    __str.setf(ios_base::fixed, ios_base::floatfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+scientific(ios_base& __str)
+{
+    __str.setf(ios_base::scientific, ios_base::floatfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+hexfloat(ios_base& __str)
+{
+    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
+    return __str;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+ios_base&
+defaultfloat(ios_base& __str)
+{
+    __str.unsetf(ios_base::floatfield);
+    return __str;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_IOS
diff --git a/include/iosfwd b/include/iosfwd
new file mode 100644
index 0000000..2094a37
--- /dev/null
+++ b/include/iosfwd
@@ -0,0 +1,173 @@
+// -*- C++ -*-
+//===--------------------------- iosfwd -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_IOSFWD
+#define _LIBCPP_IOSFWD
+
+/*
+    iosfwd synopsis
+
+namespace std
+{
+
+template<class charT> struct char_traits;
+template<class T>     class allocator;
+
+template <class charT, class traits = char_traits<charT> > class basic_ios;
+
+template <class charT, class traits = char_traits<charT> > class basic_streambuf;
+template <class charT, class traits = char_traits<charT> > class basic_istream;
+template <class charT, class traits = char_traits<charT> > class basic_ostream;
+template <class charT, class traits = char_traits<charT> > class basic_iostream;
+
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+    class basic_stringbuf;
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+    class basic_istringstream;
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+    class basic_ostringstream;
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+    class basic_stringstream;
+
+template <class charT, class traits = char_traits<charT> > class basic_filebuf;
+template <class charT, class traits = char_traits<charT> > class basic_ifstream;
+template <class charT, class traits = char_traits<charT> > class basic_ofstream;
+template <class charT, class traits = char_traits<charT> > class basic_fstream;
+
+template <class charT, class traits = char_traits<charT> > class istreambuf_iterator;
+template <class charT, class traits = char_traits<charT> > class ostreambuf_iterator;
+
+typedef basic_ios<char>              ios;
+typedef basic_ios<wchar_t>           wios;
+
+typedef basic_streambuf<char>        streambuf;
+typedef basic_istream<char>          istream;
+typedef basic_ostream<char>          ostream;
+typedef basic_iostream<char>         iostream;
+
+typedef basic_stringbuf<char>        stringbuf;
+typedef basic_istringstream<char>    istringstream;
+typedef basic_ostringstream<char>    ostringstream;
+typedef basic_stringstream<char>     stringstream;
+
+typedef basic_filebuf<char>          filebuf;
+typedef basic_ifstream<char>         ifstream;
+typedef basic_ofstream<char>         ofstream;
+typedef basic_fstream<char>          fstream;
+
+typedef basic_streambuf<wchar_t>     wstreambuf;
+typedef basic_istream<wchar_t>       wistream;
+typedef basic_ostream<wchar_t>       wostream;
+typedef basic_iostream<wchar_t>      wiostream;
+
+typedef basic_stringbuf<wchar_t>     wstringbuf;
+typedef basic_istringstream<wchar_t> wistringstream;
+typedef basic_ostringstream<wchar_t> wostringstream;
+typedef basic_stringstream<wchar_t>  wstringstream;
+
+typedef basic_filebuf<wchar_t>       wfilebuf;
+typedef basic_ifstream<wchar_t>      wifstream;
+typedef basic_ofstream<wchar_t>      wofstream;
+typedef basic_fstream<wchar_t>       wfstream;
+
+template <class state> class fpos;
+typedef fpos<char_traits<char>::state_type>    streampos;
+typedef fpos<char_traits<wchar_t>::state_type> wstreampos;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <_types.h>  // for __darwin_mbstate_t
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template<class _CharT>  struct char_traits;
+template<class _Tp>     class allocator;
+
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_ios;
+
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_streambuf;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_istream;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_ostream;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_iostream;
+
+template <class _CharT, class _Traits = char_traits<_CharT>,  class _Allocator = allocator<_CharT> >
+    class basic_stringbuf;
+template <class _CharT, class _Traits = char_traits<_CharT>,  class _Allocator = allocator<_CharT> >
+    class basic_istringstream;
+template <class _CharT, class _Traits = char_traits<_CharT>,  class _Allocator = allocator<_CharT> >
+    class basic_ostringstream;
+template <class _CharT, class _Traits = char_traits<_CharT>,  class _Allocator = allocator<_CharT> >
+    class basic_stringstream;
+
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_filebuf;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_ifstream;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_ofstream;
+template <class _CharT, class _Traits = char_traits<_CharT> > class basic_fstream;
+
+template <class _CharT, class _Traits = char_traits<_CharT> > class istreambuf_iterator;
+template <class _CharT, class _Traits = char_traits<_CharT> > class ostreambuf_iterator;
+
+typedef basic_ios<char>              ios;
+typedef basic_ios<wchar_t>           wios;
+
+typedef basic_streambuf<char>        streambuf;
+typedef basic_istream<char>          istream;
+typedef basic_ostream<char>          ostream;
+typedef basic_iostream<char>         iostream;
+
+typedef basic_stringbuf<char>        stringbuf;
+typedef basic_istringstream<char>    istringstream;
+typedef basic_ostringstream<char>    ostringstream;
+typedef basic_stringstream<char>     stringstream;
+
+typedef basic_filebuf<char>          filebuf;
+typedef basic_ifstream<char>         ifstream;
+typedef basic_ofstream<char>         ofstream;
+typedef basic_fstream<char>          fstream;
+
+typedef basic_streambuf<wchar_t>     wstreambuf;
+typedef basic_istream<wchar_t>       wistream;
+typedef basic_ostream<wchar_t>       wostream;
+typedef basic_iostream<wchar_t>      wiostream;
+
+typedef basic_stringbuf<wchar_t>     wstringbuf;
+typedef basic_istringstream<wchar_t> wistringstream;
+typedef basic_ostringstream<wchar_t> wostringstream;
+typedef basic_stringstream<wchar_t>  wstringstream;
+
+typedef basic_filebuf<wchar_t>       wfilebuf;
+typedef basic_ifstream<wchar_t>      wifstream;
+typedef basic_ofstream<wchar_t>      wofstream;
+typedef basic_fstream<wchar_t>       wfstream;
+
+template <class _State>             class fpos;
+typedef fpos<__darwin_mbstate_t>    streampos;
+typedef fpos<__darwin_mbstate_t>    wstreampos;
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+typedef fpos<__darwin_mbstate_t>    u16streampos;
+typedef fpos<__darwin_mbstate_t>    u32streampos;
+#endif
+
+typedef long long streamoff;        // for char_traits in <string>
+
+template <class _CharT,             // for <stdexcept>
+          class _Traits = char_traits<_CharT>,
+          class _Allocator = allocator<_CharT> > class basic_string;
+typedef basic_string<char, char_traits<char>, allocator<char> > string;
+typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_IOSFWD
diff --git a/include/iostream b/include/iostream
new file mode 100644
index 0000000..8e9dcd7
--- /dev/null
+++ b/include/iostream
@@ -0,0 +1,58 @@
+// -*- C++ -*-
+//===--------------------------- iostream ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_IOSTREAM
+#define _LIBCPP_IOSTREAM
+
+/*
+    iostream synopsis
+
+#include <ios>
+#include <streambuf>
+#include <istream>
+#include <ostream>
+
+namespace std {
+
+extern istream cin;
+extern ostream cout;
+extern ostream cerr;
+extern ostream clog;
+extern wistream wcin;
+extern wostream wcout;
+extern wostream wcerr;
+extern wostream wclog;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ios>
+#include <streambuf>
+#include <istream>
+#include <ostream>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+extern _LIBCPP_VISIBLE istream cin;
+extern _LIBCPP_VISIBLE ostream cout;
+extern _LIBCPP_VISIBLE ostream cerr;
+extern _LIBCPP_VISIBLE ostream clog;
+extern _LIBCPP_VISIBLE wistream wcin;
+extern _LIBCPP_VISIBLE wostream wcout;
+extern _LIBCPP_VISIBLE wostream wcerr;
+extern _LIBCPP_VISIBLE wostream wclog;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_IOSTREAM
diff --git a/include/istream b/include/istream
new file mode 100644
index 0000000..02c54ff
--- /dev/null
+++ b/include/istream
@@ -0,0 +1,1733 @@
+// -*- C++ -*-
+//===--------------------------- istream ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_ISTREAM
+#define _LIBCPP_ISTREAM
+
+/*
+    istream synopsis
+
+template <class charT, class traits = char_traits<charT> >
+class basic_istream
+    : virtual public basic_ios<charT,traits>
+{
+public:
+    // types (inherited from basic_ios (27.5.4)):
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // 27.7.1.1.1 Constructor/destructor:
+    explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
+    basic_istream(basic_istream&& rhs);
+    virtual ~basic_istream();
+
+    // 27.7.1.1.2 Assign/swap:
+    basic_istream& operator=(basic_istream&& rhs);
+    void swap(basic_istream& rhs);
+
+    // 27.7.1.1.3 Prefix/suffix:
+    class sentry;
+
+    // 27.7.1.2 Formatted input:
+    basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
+    basic_istream& operator>>(basic_ios<char_type, traits_type>&
+                              (*pf)(basic_ios<char_type, traits_type>&));
+    basic_istream& operator>>(ios_base& (*pf)(ios_base&));
+    basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
+    basic_istream& operator>>(bool& n);
+    basic_istream& operator>>(short& n);
+    basic_istream& operator>>(unsigned short& n);
+    basic_istream& operator>>(int& n);
+    basic_istream& operator>>(unsigned int& n);
+    basic_istream& operator>>(long& n);
+    basic_istream& operator>>(unsigned long& n);
+    basic_istream& operator>>(long long& n);
+    basic_istream& operator>>(unsigned long long& n);
+    basic_istream& operator>>(float& f);
+    basic_istream& operator>>(double& f);
+    basic_istream& operator>>(long double& f);
+    basic_istream& operator>>(void*& p);
+
+    // 27.7.1.3 Unformatted input:
+    streamsize gcount() const;
+    int_type get();
+    basic_istream& get(char_type& c);
+    basic_istream& get(char_type* s, streamsize n);
+    basic_istream& get(char_type* s, streamsize n, char_type delim);
+    basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
+    basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
+
+    basic_istream& getline(char_type* s, streamsize n);
+    basic_istream& getline(char_type* s, streamsize n, char_type delim);
+
+    basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
+    int_type peek();
+    basic_istream& read (char_type* s, streamsize n);
+    streamsize readsome(char_type* s, streamsize n);
+
+    basic_istream& putback(char_type c);
+    basic_istream& unget();
+    int sync();
+
+    pos_type tellg();
+    basic_istream& seekg(pos_type);
+    basic_istream& seekg(off_type, ios_base::seekdir);
+};
+
+// 27.7.1.2.3 character extraction templates:
+template<class charT, class traits>
+  basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
+
+template<class traits>
+  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
+
+template<class traits>
+  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
+
+template<class charT, class traits>
+  basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
+
+template<class traits>
+  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
+
+template<class traits>
+  basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
+
+template <class charT, class traits>
+  void
+  swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
+
+typedef basic_istream<char> istream;
+typedef basic_istream<wchar_t> wistream;
+
+template <class charT, class traits = char_traits<charT> >
+class basic_iostream :
+    public basic_istream<charT,traits>,
+    public basic_ostream<charT,traits>
+{
+public:
+    // types:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // constructor/destructor
+    explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
+    basic_iostream(basic_iostream&& rhs);
+    virtual ~basic_iostream();
+
+    // assign/swap
+    basic_iostream& operator=(basic_iostream&& rhs);
+    void swap(basic_iostream& rhs);
+};
+
+template <class charT, class traits>
+  void
+  swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
+
+typedef basic_iostream<char> iostream;
+typedef basic_iostream<wchar_t> wiostream;
+
+template <class charT, class traits>
+  basic_istream<charT,traits>&
+  ws(basic_istream<charT,traits>& is);
+
+template <class charT, class traits, class T>
+  basic_istream<charT, traits>&
+  operator>>(basic_istream<charT, traits>&& is, T& x);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ostream>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _CharT, class _Traits>
+class basic_istream
+    : virtual public basic_ios<_CharT, _Traits>
+{
+    streamsize __gc_;
+public:
+    // types (inherited from basic_ios (27.5.4)):
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // 27.7.1.1.1 Constructor/destructor:
+    explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb);
+    virtual ~basic_istream();
+protected:
+#ifdef _LIBCPP_MOVE
+    basic_istream(basic_istream&& __rhs);
+#endif
+
+    // 27.7.1.1.2 Assign/swap:
+#ifdef _LIBCPP_MOVE
+    basic_istream& operator=(basic_istream&& __rhs);
+#endif
+    void swap(basic_istream& __rhs);
+public:
+
+    // 27.7.1.1.3 Prefix/suffix:
+    class sentry;
+
+    // 27.7.1.2 Formatted input:
+    basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&));
+    basic_istream& operator>>(basic_ios<char_type, traits_type>&
+                              (*__pf)(basic_ios<char_type, traits_type>&));
+    basic_istream& operator>>(ios_base& (*__pf)(ios_base&));
+    basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
+    basic_istream& operator>>(bool& __n);
+    basic_istream& operator>>(short& __n);
+    basic_istream& operator>>(unsigned short& __n);
+    basic_istream& operator>>(int& __n);
+    basic_istream& operator>>(unsigned int& __n);
+    basic_istream& operator>>(long& __n);
+    basic_istream& operator>>(unsigned long& __n);
+    basic_istream& operator>>(long long& __n);
+    basic_istream& operator>>(unsigned long long& __n);
+    basic_istream& operator>>(float& __f);
+    basic_istream& operator>>(double& __f);
+    basic_istream& operator>>(long double& __f);
+    basic_istream& operator>>(void*& __p);
+
+    // 27.7.1.3 Unformatted input:
+    streamsize gcount() const {return __gc_;}
+    int_type get();
+    basic_istream& get(char_type& __c);
+    basic_istream& get(char_type* __s, streamsize __n);
+    basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
+    basic_istream& get(basic_streambuf<char_type, traits_type>& __sb);
+    basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
+
+    basic_istream& getline(char_type* __s, streamsize __n);
+    basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
+
+    basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
+    int_type peek();
+    basic_istream& read (char_type* __s, streamsize __n);
+    streamsize readsome(char_type* __s, streamsize __n);
+
+    basic_istream& putback(char_type __c);
+    basic_istream& unget();
+    int sync();
+
+    pos_type tellg();
+    basic_istream& seekg(pos_type __pos);
+    basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
+};
+
+template <class _CharT, class _Traits>
+class basic_istream<_CharT, _Traits>::sentry
+{
+    bool __ok_;
+
+    sentry(const sentry&); // = delete;
+    sentry& operator=(const sentry&); // = delete;
+
+public:
+    explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
+//    ~sentry() = default;
+
+    // explicit
+        operator bool() const {return __ok_;}
+};
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
+                                               bool __noskipws)
+    : __ok_(false)
+{
+    if (__is.good())
+    {
+        if (__is.tie())
+            __is.tie()->flush();
+        if (!__noskipws && (__is.flags() & ios_base::skipws))
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
+            _I __i(__is);
+            _I __eof;
+            for (; __i != __eof; ++__i)
+                if (!__ct.is(__ct.space, *__i))
+                    break;
+            if (__i == __eof)
+                __is.setstate(ios_base::failbit | ios_base::eofbit);
+        }
+        __ok_ = __is.good();
+    }
+    else
+        __is.setstate(ios_base::failbit);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>::basic_istream(basic_streambuf<char_type, traits_type>* __sb)
+    : __gc_(0)
+{
+    this->init(__sb);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
+    : __gc_(__rhs.__gc_)
+{
+    __rhs.__gc_ = 0;
+    this->move(__rhs);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
+{
+    swap(__rhs);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>::~basic_istream()
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_istream<_CharT, _Traits>::swap(basic_istream& __rhs)
+{
+    _STD::swap(__gc_, __rhs.__gc_);
+    basic_ios<char_type, traits_type>::swap(__rhs);
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(long& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(long long& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(float& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(double& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(long double& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(bool& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(void*& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __n);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(short& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            long __temp;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
+            if (__temp < numeric_limits<short>::min())
+            {
+                __err |= ios_base::failbit;
+                __n = numeric_limits<short>::min();
+            }
+            else if (__temp > numeric_limits<short>::max())
+            {
+                __err |= ios_base::failbit;
+                __n = numeric_limits<short>::max();
+            }
+            else
+                __n = static_cast<short>(__temp);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(int& __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            typedef num_get<char_type, _I> _F;
+            ios_base::iostate __err = ios_base::goodbit;
+            long __temp;
+            use_facet<_F>(this->getloc()).get(_I(*this), _I(), *this, __err, __temp);
+            if (__temp < numeric_limits<int>::min())
+            {
+                __err |= ios_base::failbit;
+                __n = numeric_limits<int>::min();
+            }
+            else if (__temp > numeric_limits<int>::max())
+            {
+                __err |= ios_base::failbit;
+                __n = numeric_limits<int>::max();
+            }
+            else
+                __n = static_cast<int>(__temp);
+            this->setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(basic_istream& (*__pf)(basic_istream&))
+{
+    return __pf(*this);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(basic_ios<char_type, traits_type>&
+                                           (*__pf)(basic_ios<char_type, traits_type>&))
+{
+    __pf(*this);
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(ios_base& (*__pf)(ios_base&))
+{
+    __pf(*this);
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+        if (__sen)
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            streamsize __n = __is.width();
+            if (__n == 0)
+                __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
+            streamsize __c = 0;
+            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
+            _I __i(__is);
+            _I __eof;
+            for (; __i != __eof && __c < __n-1; ++__i, ++__s, ++__c)
+            {
+                _CharT __ch = *__i;
+                if (__ct.is(__ct.space, __ch))
+                    break;
+                *__s = __ch;
+            }
+            *__s = _CharT();
+            __is.width(0);
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i == __eof)
+               __err |= ios_base::eofbit;
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            __is.setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template<class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<char, _Traits>&
+operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
+{
+    return __is >> (char*)__s;
+}
+
+template<class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<char, _Traits>&
+operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
+{
+    return __is >> (char*)__s;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+        if (__sen)
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            _I __i(__is);
+            _I __eof;
+            if (__i != __eof)
+            {
+                __c = *__i;
+                if (++__i == __eof)
+                    __is.setstate(ios_base::eofbit);
+            }
+            else
+                __is.setstate(ios_base::eofbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template<class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<char, _Traits>&
+operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
+{
+    return __is >> (char&)__c;
+}
+
+template<class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<char, _Traits>&
+operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
+{
+    return __is >> (char&)__c;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this, true);
+        if (__s)
+        {
+            streamsize __c = 0;
+            if (__sb)
+            {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                try
+                {
+#endif
+                    typedef istreambuf_iterator<char_type, traits_type> _I;
+                    typedef ostreambuf_iterator<char_type, traits_type> _O;
+                    _I __i(*this);
+                    _I __eof;
+                    _O __o(__sb);
+                    for (; __i != __eof; ++__i, ++__o, ++__c)
+                    {
+                        *__o = *__i;
+                        if (__o.failed())
+                            break;
+                    }
+                    ios_base::iostate __err = ios_base::goodbit;
+                    if (__i == __eof)
+                       __err |= ios_base::eofbit;
+                    if (__c == 0)
+                       __err |= ios_base::failbit;
+                    this->setstate(__err);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                }
+                catch (...)
+                {
+                    if (__c == 0)
+                        this->__set_failbit_and_consider_rethrow();
+                }
+#endif
+            }
+            else
+                this->setstate(ios_base::failbit);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+typename basic_istream<_CharT, _Traits>::int_type
+basic_istream<_CharT, _Traits>::get()
+{
+    __gc_ = 0;
+    int_type __r = traits_type::eof();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this, true);
+        if (__s)
+        {
+            streamsize __c = 0;
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            _I __i(*this);
+            _I __eof;
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i != __eof)
+            {
+                __r = traits_type::to_int_type(*__i);
+                ++__c;
+                if (++__i == __eof)
+                    __err |= ios_base::eofbit;
+            }
+            else
+                __err |= ios_base::failbit | ios_base::eofbit;
+            this->setstate(__err);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __r;
+}
+
+template<class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::get(char_type& __c)
+{
+    int_type __ch = get();
+    if (__ch != traits_type::eof())
+        __c = traits_type::to_char_type(__ch);
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            streamsize __c = 0;
+            if (__n > 0)
+            {
+                typedef istreambuf_iterator<char_type, traits_type> _I;
+                _I __i(*this);
+                _I __eof;
+                for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c)
+                {
+                    char_type __ch = *__i;
+                    if (traits_type::eq(__ch, __dlm))
+                        break;
+                    *__s = __ch;
+                }
+                *__s = char_type();
+                ios_base::iostate __err = ios_base::goodbit;
+                if (__i == __eof)
+                   __err |= ios_base::eofbit;
+                if (__c == 0)
+                   __err |= ios_base::failbit;
+                this->setstate(__err);
+            }
+            else
+                this->setstate(ios_base::failbit);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n)
+{
+    return get(__s, __n, this->widen('\n'));
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
+                                    char_type __dlm)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            streamsize __c = 0;
+            ios_base::iostate __err = ios_base::goodbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            try
+            {
+#endif
+                typedef istreambuf_iterator<char_type, traits_type> _I;
+                typedef ostreambuf_iterator<char_type, traits_type> _O;
+                _I __i(*this);
+                _I __eof;
+                _O __o(&__sb);
+                for (; __i != __eof; ++__i, ++__o, ++__c)
+                {
+                    char_type __ch = *__i;
+                    if (traits_type::eq(__ch, __dlm))
+                        break;
+                    *__o = __ch;
+                    if (__o.failed())
+                        break;
+                }
+                if (__i == __eof)
+                   __err |= ios_base::eofbit;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            }
+            catch (...)
+            {
+            }
+#endif
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            this->setstate(__err);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb)
+{
+    return get(__sb, this->widen('\n'));
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            streamsize __c = 0;
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            _I __i(*this);
+            _I __eof;
+            for (; __i != __eof; ++__s, --__n)
+            {
+                char_type __ch = *__i;
+                ++__i;
+                ++__c;
+                if (traits_type::eq(__ch, __dlm))
+                    break;
+                if (__n < 2)
+                {
+                    this->setstate(ios_base::failbit);
+                    break;
+                }
+                *__s = __ch;
+            }
+            if (__n)
+                *__s = char_type();
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i == __eof)
+               __err |= ios_base::eofbit;
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            this->setstate(__err);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n)
+{
+    return getline(__s, __n, this->widen('\n'));
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            streamsize __c = 0;
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            _I __i(*this);
+            _I __eof;
+            if (__n != numeric_limits<streamsize>::max())
+            {
+                for (; __n > 0 && __i != __eof; --__n)
+                {
+                    char_type __ch = *__i;
+                    ++__i;
+                    ++__c;
+                    if (traits_type::eq(__ch, __dlm))
+                        break;
+                }
+            }
+            else
+            {
+                while (__i != __eof)
+                {
+                    char_type __ch = *__i;
+                    ++__i;
+                    ++__c;
+                    if (traits_type::eq(__ch, __dlm))
+                        break;
+                }
+            }
+            if (__i == __eof)
+                this->setstate(ios_base::eofbit);
+            __gc_ = __c;
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+typename basic_istream<_CharT, _Traits>::int_type
+basic_istream<_CharT, _Traits>::peek()
+{
+    __gc_ = 0;
+    int_type __r = traits_type::eof();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+            __r = this->rdbuf()->sgetc();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __r;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            streamsize __c = 0;
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            _I __i(*this);
+            _I __eof;
+            for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n)
+                *__s = *__i;
+            if (__i == __eof)
+            {
+                ios_base::iostate __err = ios_base::eofbit;
+                if (__n > 0)
+                    __err |= ios_base::failbit;
+                this->setstate(__err);
+            }
+            __gc_ = __c;
+        }
+        else
+            this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+streamsize
+basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
+{
+    __gc_ = 0;
+    streamsize __c = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            typedef istreambuf_iterator<char_type, traits_type> _I;
+            _I __i(*this);
+            _I __eof;
+            __c = this->rdbuf()->in_avail();
+            switch (__c)
+            {
+            case -1:
+                __i = __eof;
+                break;
+            case 0:
+                break;
+            default:
+                __c = min(__c, __n);
+                for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i)
+                    *__s = *__i;
+            }
+            if (__i == __eof)
+                this->setstate(ios_base::eofbit);
+            __gc_ = __c;
+        }
+        else
+            this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __c;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::putback(char_type __c)
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
+                this->setstate(ios_base::badbit);
+        }
+        else
+            this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::unget()
+{
+    __gc_ = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
+                this->setstate(ios_base::badbit);
+        }
+        else
+            this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+int
+basic_istream<_CharT, _Traits>::sync()
+{
+    int __r = 0;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+        {
+            if (this->rdbuf() == 0)
+                return -1;
+            if (this->rdbuf()->pubsync() == -1)
+            {
+                this->setstate(ios_base::badbit);
+                return -1;
+            }
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __r;
+}
+
+template<class _CharT, class _Traits>
+typename basic_istream<_CharT, _Traits>::pos_type
+basic_istream<_CharT, _Traits>::tellg()
+{
+    pos_type __r(-1);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+            __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __r;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+            if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
+                this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this, true);
+        if (__sen)
+            this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+ws(basic_istream<_CharT, _Traits>& __is)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
+        if (__sen)
+        {
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
+            _I __i(__is);
+            _I __eof;
+            for (; __i != __eof; ++__i)
+                if (!__ct.is(__ct.space, *__i))
+                    break;
+            if (__i == __eof)
+                __is.setstate(ios_base::failbit | ios_base::eofbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
+{
+    __is >> __x;
+    return __is;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+class basic_iostream
+    : public basic_istream<_CharT, _Traits>,
+      public basic_ostream<_CharT, _Traits>
+{
+public:
+    // types:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // constructor/destructor
+    explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb);
+    virtual ~basic_iostream();
+protected:
+#ifdef _LIBCPP_MOVE
+    basic_iostream(basic_iostream&& __rhs);
+#endif
+
+    // assign/swap
+#ifdef _LIBCPP_MOVE
+    basic_iostream& operator=(basic_iostream&& __rhs);
+#endif
+    void swap(basic_iostream& __rhs);
+public:
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
+    : basic_istream<_CharT, _Traits>(__sb)
+{
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
+    : basic_istream<_CharT, _Traits>(_STD::move(__rhs))
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_iostream<_CharT, _Traits>&
+basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
+{
+    swap(__rhs);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+basic_iostream<_CharT, _Traits>::~basic_iostream()
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs)
+{
+    basic_istream<char_type, traits_type>::swap(__rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           basic_string<_CharT, _Traits, _Allocator>& __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+        if (__sen)
+        {
+            __str.clear();
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            streamsize __n = __is.width();
+            if (__n == 0)
+                __n = __str.max_size();
+            if (__n < 0)
+                __n = numeric_limits<streamsize>::max();
+            streamsize __c = 0;
+            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
+            _I __i(__is);
+            _I __eof;
+            for (; __i != __eof && __c < __n; ++__i, ++__c)
+            {
+                _CharT __ch = *__i;
+                if (__ct.is(__ct.space, __ch))
+                    break;
+                __str.push_back(__ch);
+            }
+            __is.width(0);
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i == __eof)
+               __err |= ios_base::eofbit;
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            __is.setstate(__err);
+        }
+        else
+            __is.setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_istream<_CharT, _Traits>& 
+getline(basic_istream<_CharT, _Traits>& __is,
+        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
+        if (__sen)
+        {
+            __str.clear();
+            streamsize __c = 0;
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            _I __i(__is);
+            _I __eof;
+            streamsize __n = __str.max_size();
+            if (__n < 0)
+                __n = numeric_limits<streamsize>::max();
+            for (; __i != __eof;)
+            {
+                _CharT __ch = *__i;
+                ++__i;
+                ++__c;
+                if (_Traits::eq(__ch, __dlm))
+                    break;
+                if (__c == __n)
+                {
+                    __is.setstate(ios_base::failbit);
+                    break;
+                }
+                __str.push_back(__ch);
+            }
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i == __eof)
+               __err |= ios_base::eofbit;
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            __is.setstate(__err);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+inline
+basic_istream<_CharT, _Traits>& 
+getline(basic_istream<_CharT, _Traits>& __is,
+        basic_string<_CharT, _Traits, _Allocator>& __str)
+{
+    return getline(__is, __str, __is.widen('\n'));
+}
+
+#ifdef _LIBCPP_MOVE
+
+template<class _CharT, class _Traits, class _Allocator>
+inline
+basic_istream<_CharT, _Traits>& 
+getline(basic_istream<_CharT, _Traits>&& __is,
+        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm)
+{
+    return getline(__is, __str, __dlm);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+inline
+basic_istream<_CharT, _Traits>& 
+getline(basic_istream<_CharT, _Traits>&& __is,
+        basic_string<_CharT, _Traits, _Allocator>& __str)
+{
+    return getline(__is, __str, __is.widen('\n'));
+}
+
+#endif
+
+template <class _CharT, class _Traits, size_t _Size>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
+        if (__sen)
+        {
+            basic_string<_CharT, _Traits> __str;
+            const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
+            typedef istreambuf_iterator<_CharT, _Traits> _I;
+            streamsize __c = 0;
+            _CharT __zero = __ct.widen('0');
+            _CharT __one = __ct.widen('1');
+            _I __i(__is);
+            _I __eof;
+            for (; __i != __eof && __c < _Size; ++__i, ++__c)
+            {
+                _CharT __ch = *__i;
+                if (__ch != __zero && __ch != __one)
+                    break;
+                __str.push_back(__ch);
+            }
+            __is.width(0);
+            __x = bitset<_Size>(__str);
+            ios_base::iostate __err = ios_base::goodbit;
+            if (__i == __eof)
+               __err |= ios_base::eofbit;
+            if (__c == 0)
+               __err |= ios_base::failbit;
+            __is.setstate(__err);
+        }
+        else
+            __is.setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __is.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __is;
+}
+
+extern template class basic_istream<char>;
+extern template class basic_istream<wchar_t>;
+extern template class basic_iostream<char>;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_ISTREAM
diff --git a/include/iterator b/include/iterator
new file mode 100644
index 0000000..52beb42
--- /dev/null
+++ b/include/iterator
@@ -0,0 +1,1706 @@
+// -*- C++ -*-
+//===-------------------------- iterator ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_ITERATOR
+#define _LIBCPP_ITERATOR
+
+/*
+    iterator synopsis
+
+namespace std
+{
+
+template<class Iterator>
+struct iterator_traits
+{
+    typedef typename Iterator::difference_type difference_type;
+    typedef typename Iterator::value_type value_type;
+    typedef typename Iterator::pointer pointer;
+    typedef typename Iterator::reference reference;
+    typedef typename Iterator::iterator_category iterator_category;
+};
+
+template<class T>
+struct iterator_traits<T*>
+{
+    typedef ptrdiff_t difference_type;
+    typedef T value_type;
+    typedef T* pointer;
+    typedef T& reference;
+    typedef random_access_iterator_tag iterator_category;
+};
+
+template<class T>
+struct iterator_traits<const T*>
+{
+    typedef ptrdiff_t difference_type;
+    typedef T value_type;
+    typedef const T* pointer;
+    typedef const T& reference;
+    typedef random_access_iterator_tag iterator_category;
+};
+
+template<class Category, class T, class Distance = ptrdiff_t,
+         class Pointer = T*, class Reference = T&>
+struct iterator
+{
+    typedef T         value_type;
+    typedef Distance  difference_type;
+    typedef Pointer   pointer;
+    typedef Reference reference;
+    typedef Category  iterator_category;
+};
+
+struct input_iterator_tag  {};
+struct output_iterator_tag {};
+struct forward_iterator_tag       : public input_iterator_tag         {};
+struct bidirectional_iterator_tag : public forward_iterator_tag       {};
+struct random_access_iterator_tag : public bidirectional_iterator_tag {};
+
+// extension: second argument not conforming to C++03
+template <class InputIterator>
+void advance(InputIterator& i,
+             typename iterator_traits<InputIterator>::difference_type n);
+
+template <class InputIterator>
+typename iterator_traits<InputIterator>::difference_type
+distance(InputIterator first, InputIterator last);
+
+template <class Iterator>
+class reverse_iterator
+    : public iterator<typename iterator_traits<Iterator>::iterator_category,
+                      typename iterator_traits<Iterator>::value_type,
+                      typename iterator_traits<Iterator>::difference_type,
+                      typename iterator_traits<Iterator>::pointer,
+                      typename iterator_traits<Iterator>::reference>
+{
+protected:
+    Iterator current;
+public:
+    typedef Iterator                                            iterator_type;
+    typedef typename iterator_traits<Iterator>::difference_type difference_type;
+    typedef typename iterator_traits<Iterator>::reference       reference;
+    typedef typename iterator_traits<Iterator>::pointer         pointer;
+    
+    reverse_iterator();
+    explicit reverse_iterator(Iterator x);
+    template <class U> reverse_iterator(const reverse_iterator<U>& u);
+    Iterator base() const;
+    reference operator*() const;
+    pointer   operator->() const;
+    reverse_iterator& operator++();
+    reverse_iterator  operator++(int);
+    reverse_iterator& operator--();
+    reverse_iterator  operator--(int);
+    reverse_iterator  operator+ (difference_type n) const;
+    reverse_iterator& operator+=(difference_type n);
+    reverse_iterator  operator- (difference_type n) const;
+    reverse_iterator& operator-=(difference_type n);
+    reference         operator[](difference_type n) const;
+};
+
+template <class Iterator1, class Iterator2>
+bool
+operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+bool
+operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+bool
+operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+bool
+operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+bool
+operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+bool
+operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator1, class Iterator2>
+typename reverse_iterator<Iterator1>::difference_type
+operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
+
+template <class Iterator>
+reverse_iterator<Iterator>
+operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
+
+template <class Container>
+class back_insert_iterator
+{
+protected:
+    Container* container;
+public:
+    typedef Container                   container_type;
+    typedef void                        value_type;
+    typedef void                        difference_type;
+    typedef back_insert_iterator<Cont>& reference;
+    typedef void                        pointer;
+
+    explicit back_insert_iterator(Container& x);
+    back_insert_iterator& operator=(typename Container::const_reference value);
+    back_insert_iterator& operator*();
+    back_insert_iterator& operator++();
+    back_insert_iterator  operator++(int);
+};
+
+template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
+
+template <class Container>
+class front_insert_iterator
+{
+protected:
+    Container* container;
+public:
+    typedef Container                    container_type;
+    typedef void                         value_type;
+    typedef void                         difference_type;
+    typedef front_insert_iterator<Cont>& reference;
+    typedef void                         pointer;
+
+    explicit front_insert_iterator(Container& x);
+    front_insert_iterator& operator=(typename Container::const_reference value);
+    front_insert_iterator& operator*();
+    front_insert_iterator& operator++();
+    front_insert_iterator  operator++(int);
+};
+
+template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
+
+template <class Container>
+class insert_iterator
+{
+protected:
+    Container* container;
+    typename Container::iterator iter;
+public:
+    typedef Container              container_type;
+    typedef void                   value_type;
+    typedef void                   difference_type;
+    typedef insert_iterator<Cont>& reference;
+    typedef void                   pointer;
+
+    insert_iterator(Container& x, typename Container::iterator i);
+    insert_iterator& operator=(typename Container::const_reference value);
+    insert_iterator& operator*();
+    insert_iterator& operator++();
+    insert_iterator& operator++(int);
+};
+
+template <class Container, class Iterator>
+insert_iterator<Container> inserter(Container& x, Iterator i);
+
+template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
+class istream_iterator
+    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
+{
+public:
+    typedef charT char_type;
+    typedef traits traits_type;
+    typedef basic_istream<charT,traits> istream_type;
+
+    istream_iterator();
+    istream_iterator(istream_type& s);
+    istream_iterator(const istream_iterator& x);
+    ~istream_iterator();
+
+    const T& operator*() const;
+    const T* operator->() const;
+    istream_iterator& operator++();
+    istream_iterator  operator++(int);
+};
+
+template <class T, class charT, class traits, class Distance>
+bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
+                const istream_iterator<T,charT,traits,Distance>& y);
+template <class T, class charT, class traits, class Distance>
+bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
+                const istream_iterator<T,charT,traits,Distance>& y);
+
+template <class T, class charT = char, class traits = char_traits<charT> >
+class ostream_iterator
+    : public iterator<output_iterator_tag, void, void, void ,void>
+{
+public:
+    typedef charT char_type;
+    typedef traits traits_type;
+    typedef basic_ostream<charT,traits> ostream_type;
+
+    ostream_iterator(ostream_type& s);
+    ostream_iterator(ostream_type& s, const charT* delimiter);
+    ostream_iterator(const ostream_iterator& x);
+    ~ostream_iterator();
+    ostream_iterator& operator=(const T& value);
+
+    ostream_iterator& operator*();
+    ostream_iterator& operator++();
+    ostream_iterator& operator++(int);
+};
+
+template<class charT, class traits = char_traits<charT> >
+class istreambuf_iterator
+    : public iterator<input_iterator_tag, charT,
+                      typename traits::off_type, unspecified,
+                      charT>
+{
+public:
+    typedef charT                         char_type;
+    typedef traits                        traits_type;
+    typedef typename traits::int_type     int_type;
+    typedef basic_streambuf<charT,traits> streambuf_type;
+    typedef basic_istream<charT,traits>   istream_type;
+
+    istreambuf_iterator() throw();
+    istreambuf_iterator(istream_type& s) throw();
+    istreambuf_iterator(streambuf_type* s) throw();
+    istreambuf_iterator(a-private-type) throw();
+
+    charT                operator*() const;
+    pointer operator->() const;
+    istreambuf_iterator& operator++();
+    a-private-type       operator++(int);
+
+    bool equal(const istreambuf_iterator& b) const;
+};
+
+template <class charT, class traits>
+bool operator==(const istreambuf_iterator<charT,traits>& a,
+                const istreambuf_iterator<charT,traits>& b);
+template <class charT, class traits>
+bool operator!=(const istreambuf_iterator<charT,traits>& a,
+                const istreambuf_iterator<charT,traits>& b);
+
+template <class charT, class traits = char_traits<charT> >
+class ostreambuf_iterator
+    : public iterator<output_iterator_tag, void, void, void, void>
+{
+public:
+    typedef charT                         char_type;
+    typedef traits                        traits_type;
+    typedef basic_streambuf<charT,traits> streambuf_type;
+    typedef basic_ostream<charT,traits>   ostream_type;
+
+    ostreambuf_iterator(ostream_type& s) throw();
+    ostreambuf_iterator(streambuf_type* s) throw();
+    ostreambuf_iterator& operator=(charT c);
+    ostreambuf_iterator& operator*();
+    ostreambuf_iterator& operator++();
+    ostreambuf_iterator& operator++(int);
+    bool failed() const throw();
+};
+
+template <class C> auto begin(C& c) -> decltype(c.begin());
+template <class C> auto begin(const C& c) -> decltype(c.begin());
+template <class C> auto end(C& c) -> decltype(c.end());
+template <class C> auto end(const C& c) -> decltype(c.end());
+template <class T, size_t N> T* begin(T (&array)[N]);
+template <class T, size_t N> T* end(T (&array)[N]);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <type_traits>
+#include <cstddef>
+#include <iosfwd>
+#ifdef _LIBCPP_DEBUG
+#include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct input_iterator_tag {};
+struct output_iterator_tag {};
+struct forward_iterator_tag       : public input_iterator_tag {};
+struct bidirectional_iterator_tag : public forward_iterator_tag {};
+struct random_access_iterator_tag : public bidirectional_iterator_tag {};
+
+template <class _Tp>
+struct __has_iterator_category
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::iterator_category* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Iter, bool> struct ____iterator_traits {};
+
+template <class _Iter>
+struct ____iterator_traits<_Iter, true>
+{
+    typedef typename _Iter::difference_type   difference_type;
+    typedef typename _Iter::value_type        value_type;
+    typedef typename _Iter::pointer           pointer;
+    typedef typename _Iter::reference         reference;
+    typedef typename _Iter::iterator_category iterator_category;
+};
+
+template <class _Iter, bool> struct __iterator_traits {};
+
+template <class _Iter>
+struct __iterator_traits<_Iter, true>
+    :  ____iterator_traits
+      <
+        _Iter,
+        is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
+        is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
+      >
+{};
+
+// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
+//    exists.  Else iterator_traits<Iterator> will be an empty class.  This is a
+//    conforming extension which allows some programs to compile and behave as
+//    the client expects instead of failing at compile time.
+
+template <class _Iter>
+struct iterator_traits
+    : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
+
+template<class _Tp>
+struct iterator_traits<_Tp*>
+{
+    typedef ptrdiff_t difference_type;
+    typedef typename remove_const<_Tp>::type value_type;
+    typedef _Tp* pointer;
+    typedef _Tp& reference;
+    typedef random_access_iterator_tag iterator_category;
+};
+
+template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
+struct __has_iterator_category_convertible_to
+    : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
+{};
+
+template <class _Tp, class _Up>
+struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
+
+template <class _Tp>
+struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
+
+template <class _Tp>
+struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
+
+template <class _Tp>
+struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
+
+template <class _Tp>
+struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
+
+template<class _Category, class _Tp, class _Distance = ptrdiff_t,
+         class _Pointer = _Tp*, class _Reference = _Tp&>
+struct iterator
+{
+    typedef _Tp        value_type;
+    typedef _Distance  difference_type;
+    typedef _Pointer   pointer;
+    typedef _Reference reference;
+    typedef _Category  iterator_category;
+};
+
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY
+void __advance(_InputIter& __i,
+             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
+{
+    for (; __n > 0; --__n)
+        ++__i;
+}
+
+template <class _BiDirIter>
+inline _LIBCPP_INLINE_VISIBILITY
+void __advance(_BiDirIter& __i,
+             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
+{
+    if (__n >= 0)
+        for (; __n > 0; --__n)
+            ++__i;
+    else
+        for (; __n < 0; ++__n)
+            --__i;
+}
+
+template <class _RandIter>
+inline _LIBCPP_INLINE_VISIBILITY
+void __advance(_RandIter& __i,
+             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
+{
+   __i += __n;
+}
+
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY
+void advance(_InputIter& __i,
+             typename iterator_traits<_InputIter>::difference_type __n)
+{
+    __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
+}
+
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY
+typename iterator_traits<_InputIter>::difference_type
+__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
+{
+    typename iterator_traits<_InputIter>::difference_type __r(0);
+    for (; __first != __last; ++__first)
+        ++__r;
+    return __r;
+}
+
+template <class _RandIter>
+inline _LIBCPP_INLINE_VISIBILITY
+typename iterator_traits<_RandIter>::difference_type
+__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
+{
+    return __last - __first;
+}
+
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY
+typename iterator_traits<_InputIter>::difference_type
+distance(_InputIter __first, _InputIter __last)
+{
+    return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
+}
+
+template <class _ForwardIter>
+inline
+_ForwardIter
+next(_ForwardIter __x,
+     typename iterator_traits<_ForwardIter>::difference_type __n = 1,
+     typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
+{
+    advance(__x, __n);
+    return __x;
+}
+
+template <class _BidiretionalIter>
+inline
+_BidiretionalIter
+prev(_BidiretionalIter __x,
+     typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
+     typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
+{
+    advance(__x, -__n);
+    return __x;
+}
+
+template <class _Iter>
+class reverse_iterator
+    : public iterator<typename iterator_traits<_Iter>::iterator_category,
+                      typename iterator_traits<_Iter>::value_type,
+                      typename iterator_traits<_Iter>::difference_type,
+                      typename iterator_traits<_Iter>::pointer,
+                      typename iterator_traits<_Iter>::reference>
+{
+private:
+    mutable _Iter __t;
+protected:
+    _Iter current;
+public:
+    typedef _Iter                                            iterator_type;
+    typedef typename iterator_traits<_Iter>::difference_type difference_type;
+    typedef typename iterator_traits<_Iter>::reference       reference;
+    typedef typename iterator_traits<_Iter>::pointer         pointer;
+    
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
+    _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
+        : __t(__u.base()), current(__u.base()) {}
+    _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator  operator++(int)
+        {reverse_iterator __tmp(*this); --current; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator  operator--(int)
+        {reverse_iterator __tmp(*this); ++current; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator  operator+ (difference_type __n) const
+        {return reverse_iterator(current - __n);}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
+        {current -= __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator  operator- (difference_type __n) const
+        {return reverse_iterator(current + __n);}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
+        {current += __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reference         operator[](difference_type __n) const
+        {return current[-__n-1];}
+};
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() == __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() > __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() != __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() < __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() <= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __x.base() >= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename reverse_iterator<_Iter1>::difference_type
+operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
+{
+    return __y.base() - __x.base();
+}
+
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Iter>
+operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
+{
+    return reverse_iterator<_Iter>(__x.base() - __n);
+}
+
+template <class _Container>
+class back_insert_iterator
+    : public iterator<output_iterator_tag,
+                      void,
+                      void,
+                      void,
+                      back_insert_iterator<_Container>&>
+{
+protected:
+    _Container* container;
+public:
+    typedef _Container container_type;
+
+    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
+    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::const_reference __value)
+        {container->push_back(__value); return *this;}
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value)
+        {container->push_back(_STD::move(__value)); return *this;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*()     {return *this;}
+    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++()    {return *this;}
+    _LIBCPP_INLINE_VISIBILITY back_insert_iterator  operator++(int) {return *this;}
+};
+
+template <class _Container>
+inline _LIBCPP_INLINE_VISIBILITY
+back_insert_iterator<_Container>
+back_inserter(_Container& __x)
+{
+    return back_insert_iterator<_Container>(__x);
+}
+
+template <class _Container>
+class front_insert_iterator
+    : public iterator<output_iterator_tag,
+                      void,
+                      void,
+                      void,
+                      front_insert_iterator<_Container>&>
+{
+protected:
+    _Container* container;
+public:
+    typedef _Container container_type;
+
+    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
+    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::const_reference __value)
+        {container->push_front(__value); return *this;}
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value)
+        {container->push_front(_STD::move(__value)); return *this;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*()     {return *this;}
+    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++()    {return *this;}
+    _LIBCPP_INLINE_VISIBILITY front_insert_iterator  operator++(int) {return *this;}
+};
+
+template <class _Container>
+inline _LIBCPP_INLINE_VISIBILITY
+front_insert_iterator<_Container>
+front_inserter(_Container& __x)
+{
+    return front_insert_iterator<_Container>(__x);
+}
+
+template <class _Container>
+class insert_iterator
+    : public iterator<output_iterator_tag,
+                      void,
+                      void,
+                      void,
+                      insert_iterator<_Container>&>
+{
+protected:
+    _Container* container;
+    typename _Container::iterator iter;
+public:
+    typedef _Container container_type;
+
+    _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
+        : container(&__x), iter(__i) {}
+    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::const_reference __value)
+        {iter = container->insert(iter, __value); ++iter; return *this;}
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value)
+        {iter = container->insert(iter, _STD::move(__value)); ++iter; return *this;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*()        {return *this;}
+    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++()       {return *this;}
+    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int)    {return *this;}
+};
+
+template <class _Container>
+inline _LIBCPP_INLINE_VISIBILITY
+insert_iterator<_Container>
+inserter(_Container& __x, typename _Container::iterator __i)
+{
+    return insert_iterator<_Container>(__x, __i);
+}
+
+template <class _Tp, class _CharT = char,
+          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
+class istream_iterator
+    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
+{
+public:
+    typedef _CharT char_type;
+    typedef _Traits traits_type;
+    typedef basic_istream<_CharT,_Traits> istream_type;
+private:
+    istream_type* __in_stream_;
+    _Tp __value_;
+public:
+    _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
+    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
+        {
+            if (!(*__in_stream_ >> __value_))
+                __in_stream_ = 0;
+        }
+
+    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
+    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
+        {
+            if (!(*__in_stream_ >> __value_))
+                __in_stream_ = 0;
+            return *this;
+        }
+    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
+        {istream_iterator __t(*this); ++(*this); return __t;}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator==(const istream_iterator& __x, const istream_iterator& __y)
+        {return __x.__in_stream_ == __y.__in_stream_;}
+
+    friend _LIBCPP_INLINE_VISIBILITY
+    bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
+        {return !(__x == __y);}
+};
+
+template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
+class ostream_iterator
+    : public iterator<output_iterator_tag, void, void, void, void>
+{
+public:
+    typedef _CharT char_type;
+    typedef _Traits traits_type;
+    typedef basic_ostream<_CharT,_Traits> ostream_type;
+private:
+    ostream_type* __out_stream_;
+    const char_type* __delim_;
+public:
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
+        : __out_stream_(&__s), __delim_(0) {}
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
+        : __out_stream_(&__s), __delim_(__delimiter) {}
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value)
+        {
+            *__out_stream_ << __value;
+            if (__delim_)
+                *__out_stream_ << __delim_;
+            return *this;
+        }
+
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
+    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
+};
+
+template<class _CharT, class _Traits>
+class istreambuf_iterator
+    : public iterator<input_iterator_tag, _CharT,
+                      typename _Traits::off_type, _CharT*,
+                      _CharT>
+{
+public:
+    typedef _CharT                          char_type;
+    typedef _Traits                         traits_type;
+    typedef typename _Traits::int_type      int_type;
+    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
+    typedef basic_istream<_CharT,_Traits>   istream_type;
+private:
+    streambuf_type* __sbuf_;
+
+    class __proxy
+    {
+        char_type __keep_;
+        streambuf_type* __sbuf_;
+        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
+            : __keep_(__c), __sbuf_(__s) {}
+        friend class istreambuf_iterator;
+    public:
+        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
+    };
+
+    void __test_for_eof()
+    {
+        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
+            __sbuf_ = 0;
+    }
+public:
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator() throw() : __sbuf_(0) {}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) throw()
+        : __sbuf_(__s.rdbuf()) {__test_for_eof();}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) throw()
+        : __sbuf_(__s) {__test_for_eof();}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) throw()
+        : __sbuf_(__p.__sbuf_) {}
+
+    _LIBCPP_INLINE_VISIBILITY _CharT               operator*() const {return __sbuf_->sgetc();}
+    _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
+    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
+        {
+            if (traits_type::eq_int_type(__sbuf_->snextc(), traits_type::eof()))
+                __sbuf_ = 0;
+            return *this;
+        }
+    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
+        {
+            char_type __c = __sbuf_->sgetc();
+            ++(*this);
+            return __proxy(__c, __sbuf_);
+        }
+
+    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
+        {return (__sbuf_ == 0) == (__b.__sbuf_ == 0);}
+};
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
+                const istreambuf_iterator<_CharT,_Traits>& __b)
+                {return __a.equal(__b);}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
+                const istreambuf_iterator<_CharT,_Traits>& __b)
+                {return !__a.equal(__b);}
+
+template <class _CharT, class _Traits>
+class ostreambuf_iterator
+    : public iterator<output_iterator_tag, void, void, void, void>
+{
+public:
+    typedef _CharT                          char_type;
+    typedef _Traits                         traits_type;
+    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
+    typedef basic_ostream<_CharT,_Traits>   ostream_type;
+private:
+    streambuf_type* __sbuf_;
+public:
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) throw()
+        : __sbuf_(__s.rdbuf()) {}
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) throw()
+        : __sbuf_(__s) {}
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
+        {
+            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
+                __sbuf_ = 0;
+            return *this;
+        }
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
+    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
+    _LIBCPP_INLINE_VISIBILITY bool failed() const throw() {return __sbuf_ == 0;}
+};
+
+template <class _Iter>
+class move_iterator
+{
+private:
+    _Iter __i;
+public:
+    typedef _Iter                                            iterator_type;
+    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
+    typedef typename iterator_traits<iterator_type>::value_type value_type;
+    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
+    typedef typename iterator_traits<iterator_type>::pointer pointer;
+#ifdef _LIBCPP_MOVE
+    typedef value_type&& reference;
+#else
+    typedef typename iterator_traits<iterator_type>::reference reference;
+#endif
+    
+    _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
+    _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
+        : __i(__u.base()) {}
+    _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__i;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY move_iterator  operator++(int)
+        {move_iterator __tmp(*this); ++__i; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY move_iterator  operator--(int)
+        {move_iterator __tmp(*this); --__i; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY move_iterator  operator+ (difference_type __n) const
+        {return move_iterator(__i + __n);}
+    _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
+        {__i += __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY move_iterator  operator- (difference_type __n) const
+        {return move_iterator(__i - __n);}
+    _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
+        {__i -= __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reference         operator[](difference_type __n) const
+        {return __i[__n];}
+};
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() == __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() < __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() != __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() > __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() >= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() <= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename move_iterator<_Iter1>::difference_type
+operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
+{
+    return __x.base() - __y.base();
+}
+
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+move_iterator<_Iter>
+operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
+{
+    return move_iterator<_Iter>(__x.base() + __n);
+}
+
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+move_iterator<_Iter>
+make_move_iterator(const _Iter& __i)
+{
+    return move_iterator<_Iter>(__i);
+}
+
+// __wrap_iter
+
+template <class _Iter> class __wrap_iter;
+
+template <class _Iter1, class _Iter2>
+bool
+operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+bool
+operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+bool
+operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+bool
+operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+bool
+operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+bool
+operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter1, class _Iter2>
+typename __wrap_iter<_Iter1>::difference_type
+operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+
+template <class _Iter>
+__wrap_iter<_Iter>
+operator+(typename __wrap_iter<_Iter>::difference_type, const __wrap_iter<_Iter>&);
+
+template <class _I, class _O> _O copy(_I, _I, _O);
+template <class _B1, class _B2> _B2 copy_backward(_B1, _B1, _B2);
+template <class _I, class _O> _O move(_I, _I, _O);
+template <class _B1, class _B2> _B2 move_backward(_B1, _B1, _B2);
+
+template <class _Tp>
+typename enable_if
+<
+    has_trivial_copy_assign<_Tp>::value,
+    _Tp*
+>::type
+__unwrap_iter(__wrap_iter<_Tp*>);
+
+template <class _Iter>
+class __wrap_iter
+{
+public:
+    typedef _Iter                                                      iterator_type;
+    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
+    typedef typename iterator_traits<iterator_type>::value_type        value_type;
+    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
+    typedef typename iterator_traits<iterator_type>::pointer           pointer;
+    typedef typename iterator_traits<iterator_type>::reference         reference;
+private:
+    iterator_type __i;
+public:
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter() {}
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
+        typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0)
+        : __i(__u.base()) {}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__i;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() {++__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator++(int)
+        {__wrap_iter __tmp(*this); ++__i; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() {--__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator--(int)
+        {__wrap_iter __tmp(*this); --__i; return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator+ (difference_type __n) const
+        {return __wrap_iter(__i + __n);}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n)
+        {__i += __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator- (difference_type __n) const
+        {return __wrap_iter(__i - __n);}
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n)
+        {__i -= __n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reference        operator[](difference_type __n) const
+        {return __i[__n];}
+
+    _LIBCPP_INLINE_VISIBILITY iterator_type base() const {return __i;}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) : __i(__x) {}
+
+    template <class _Up> friend class __wrap_iter;
+    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
+    template <class _Tp, class _Alloc> friend class vector;
+
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    bool
+    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1, class _Iter2>
+    friend
+    typename __wrap_iter<_Iter1>::difference_type
+    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&);
+    
+    template <class _Iter1>
+    friend
+    __wrap_iter<_Iter1>
+    operator+(typename __wrap_iter<_Iter1>::difference_type, const __wrap_iter<_Iter1>&);
+
+    template <class _I, class _O> friend _O copy(_I, _I, _O);
+    template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
+    template <class _I, class _O> friend _O move(_I, _I, _O);
+    template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
+
+    template <class _Tp>
+    friend
+    typename enable_if
+    <
+        has_trivial_copy_assign<_Tp>::value,
+        _Tp*
+    >::type
+    __unwrap_iter(__wrap_iter<_Tp*>);
+};
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() == __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() < __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() != __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() > __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() >= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() <= __y.base();
+}
+
+template <class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __wrap_iter<_Iter1>::difference_type
+operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y)
+{
+    return __x.base() - __y.base();
+}
+
+template <class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+__wrap_iter<_Iter>
+operator+(typename __wrap_iter<_Iter>::difference_type __n,
+          const __wrap_iter<_Iter>& __x)
+{
+    return __wrap_iter<_Iter>(__x.base() + __n);
+}
+
+#ifdef _LIBCPP_DEBUG
+
+// __debug_iter
+
+template <class _Container, class _Iter> class __debug_iter;
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator==(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator<(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator!=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator>(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator>=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+bool
+operator<=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter1, class _Iter2>
+typename __debug_iter<_Container, _Iter1>::difference_type
+operator-(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
+
+template <class _Container, class _Iter>
+__debug_iter<_Container, _Iter>
+operator+(typename __debug_iter<_Container, _Iter>::difference_type, const __debug_iter<_Container, _Iter>&);
+
+template <class _Container, class _Iter>
+class __debug_iter
+{
+public:
+    typedef _Iter                                                      iterator_type;
+    typedef _Container                                                 __container_type;
+    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
+    typedef typename iterator_traits<iterator_type>::value_type        value_type;
+    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
+    typedef typename iterator_traits<iterator_type>::pointer           pointer;
+    typedef typename iterator_traits<iterator_type>::reference         reference;
+private:
+    iterator_type __i;
+    __debug_iter* __next;
+    __container_type* __cont;
+    
+public:
+    _LIBCPP_INLINE_VISIBILITY __debug_iter() : __next(0), __cont(0) {}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter& __x)
+        : __i(__x.base()), __next(0), __cont(0) {__set_owner(__x.__cont);}
+    __debug_iter& operator=(const __debug_iter& __x);
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter<_Container, _Up>& __u,
+        typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0)
+        : __i(__u.base()), __next(0), __cont(0) {__set_owner(__u.__cont);}
+    _LIBCPP_INLINE_VISIBILITY ~__debug_iter() {__remove_owner();}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const {assert(__is_deref()); return *__i;}
+    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const {return &(operator*());}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter& operator++() {assert(__can_increment()); ++__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter  operator++(int)
+        {__debug_iter __tmp(*this); operator++(); return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter& operator--() {assert(__can_decrement()); --__i; return *this;}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter  operator--(int)
+        {__debug_iter __tmp(*this); operator--(); return __tmp;}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter  operator+ (difference_type __n) const
+        {__debug_iter __t(*this); __t += __n; return __t;}
+    __debug_iter& operator+=(difference_type __n);
+    _LIBCPP_INLINE_VISIBILITY __debug_iter  operator- (difference_type __n) const
+        {__debug_iter __t(*this); __t -= __n; return __t;}
+    _LIBCPP_INLINE_VISIBILITY __debug_iter& operator-=(difference_type __n)
+        {*this += -__n; return *this;}
+    _LIBCPP_INLINE_VISIBILITY reference        operator[](difference_type __n) const
+        {return *(*this + __n);}
+
+private:
+    _LIBCPP_INLINE_VISIBILITY __debug_iter(const __container_type* __c, iterator_type __x)
+        : __i(__x), __next(0), __cont(0) {__set_owner(__c);}
+    _LIBCPP_INLINE_VISIBILITY iterator_type base() const {return __i;}
+
+    void __set_owner(const __container_type* __c);
+    void __remove_owner();
+    static void __remove_all(__container_type* __c);
+    static void swap(__container_type* __x, __container_type* __y);
+    
+    _LIBCPP_INLINE_VISIBILITY bool __is_deref() const
+        {return __is_deref(__is_random_access_iterator<iterator_type>());}
+    bool __is_deref(false_type) const;
+    bool __is_deref(true_type) const;
+    _LIBCPP_INLINE_VISIBILITY bool __can_decrement() const
+        {return __can_decrement(integral_constant<int, is_pointer<iterator_type>::value ? 2:
+                                                       __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
+    bool __can_decrement(integral_constant<int, 0>) const;
+    bool __can_decrement(integral_constant<int, 1>) const;
+    bool __can_decrement(integral_constant<int, 2>) const;
+    _LIBCPP_INLINE_VISIBILITY bool __can_increment() const
+        {return __can_increment(integral_constant<int, is_pointer<iterator_type>::value ? 2:
+                                                       __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
+    bool __can_increment(integral_constant<int, 0>) const;
+    bool __can_increment(integral_constant<int, 1>) const;
+    bool __can_increment(integral_constant<int, 2>) const;
+
+    _LIBCPP_INLINE_VISIBILITY bool __can_add(difference_type __n) const
+        {return __can_add(__n, is_pointer<iterator_type>());}
+    bool __can_add(difference_type __n, false_type) const;
+    bool __can_add(difference_type __n, true_type) const;
+
+    template <class _Cp, class _Up> friend class __debug_iter;
+    friend class _Container::__self;
+
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator==(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator<(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator!=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator>(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator>=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    bool
+    operator<=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1, class _Iter2>
+    friend
+    typename __debug_iter<_Cp, _Iter1>::difference_type
+    operator-(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
+    
+    template <class _Cp, class _Iter1>
+    friend
+    __debug_iter<_Cp, _Iter1>
+    operator+(typename __debug_iter<_Cp, _Iter1>::difference_type, const __debug_iter<_Cp, _Iter1>&);
+};
+
+template <class _Container, class _Iter>
+__debug_iter<_Container, _Iter>&
+__debug_iter<_Container, _Iter>::operator=(const __debug_iter& __x)
+{
+    if (this != &__x)
+    {
+        __remove_owner();
+        __i = __x.__i;
+        __set_owner(__x.__cont);
+    }
+    return *this;
+}
+    
+template <class _Container, class _Iter>
+void
+__debug_iter<_Container, _Iter>::__set_owner(const __container_type* __c)
+{
+    __cont = const_cast<__container_type*>(__c);
+    __debug_iter*& __head = __cont->__get_iterator_list(this);
+    __next = __head;
+    __head = this;
+}
+
+template <class _Container, class _Iter>
+void
+__debug_iter<_Container, _Iter>::__remove_owner()
+{
+    if (__cont)
+    {
+        __debug_iter*& __head = __cont->__get_iterator_list(this);
+        if (__head == this)
+            __head = __next;
+        else
+        {
+            __debug_iter* __prev = __head;
+            for (__debug_iter* __p = __head->__next; __p != this; __p = __p->__next)
+                __prev = __p;
+            __prev->__next = __next;
+        }
+        __cont = 0;
+    }
+}
+
+template <class _Container, class _Iter>
+void
+__debug_iter<_Container, _Iter>::__remove_all(__container_type* __c)
+{
+    __debug_iter*& __head = __c->__get_iterator_list((__debug_iter*)0);
+    __debug_iter* __p = __head;
+    __head = 0;
+    while (__p)
+    {
+        __p->__cont = 0;
+        __debug_iter* __n = __p->__next;
+        __p->__next = 0;
+        __p = __n;
+    }
+}
+
+template <class _Container, class _Iter>
+void
+__debug_iter<_Container, _Iter>::swap(__container_type* __x, __container_type* __y)
+{
+    __debug_iter*& __head_x = __x->__get_iterator_list((__debug_iter*)0);
+    __debug_iter*& __head_y = __y->__get_iterator_list((__debug_iter*)0);
+    __debug_iter* __p = __head_x;
+    __head_x = __head_y;
+    __head_y = __p;
+    for (__p = __head_x; __p; __p = __p->__next)
+        __p->__cont = __x;
+    for (__p = __head_y; __p; __p = __p->__next)
+        __p->__cont = __y;
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__is_deref(false_type) const
+{
+    if (__cont == 0)
+        return false;
+    return __i != __cont->end().base();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__is_deref(true_type) const
+{
+    if (__cont == 0)
+        return false;
+    return __i < __cont->end().base();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 0>) const
+{
+    if (__cont == 0)
+        return false;
+    return __i != __cont->begin().base();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 1>) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    return __b < __i && __i <= __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 2>) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    return __b < __i && __i <= __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 0>) const
+{
+    if (__cont == 0)
+        return false;
+    return __i != __cont->end().base();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 1>) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    return __b <= __i && __i < __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 2>) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    return __b <= __i && __i < __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_add(difference_type __n, false_type) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    iterator_type __j = __i + __n;
+    return __b <= __j && __j <= __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+bool
+__debug_iter<_Container, _Iter>::__can_add(difference_type __n, true_type) const
+{
+    if (__cont == 0)
+        return false;
+    iterator_type __b = __cont->begin().base();
+    iterator_type __j = __i + __n;
+    return __b <= __j && __j <= __b + __cont->size();
+}
+
+template <class _Container, class _Iter>
+__debug_iter<_Container, _Iter>&
+__debug_iter<_Container, _Iter>::operator+=(difference_type __n)
+{
+    assert(__can_add(__n));
+    __i += __n;
+    return *this;
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    assert(__x.__cont && __x.__cont == __y.__cont);
+    return __x.base() == __y.base();
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    assert(__x.__cont && __x.__cont == __y.__cont);
+    return __x.base() < __y.base();
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Container, class _Iter1, class _Iter2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename __debug_iter<_Container, _Iter1>::difference_type
+operator-(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
+{
+    assert(__x.__cont && __x.__cont == __y.__cont);
+    return __x.base() - __y.base();
+}
+
+template <class _Container, class _Iter>
+inline _LIBCPP_INLINE_VISIBILITY
+__debug_iter<_Container, _Iter>
+operator+(typename __debug_iter<_Container, _Iter>::difference_type __n,
+          const __debug_iter<_Container, _Iter>& __x)
+{
+    return __x + __n;
+}
+
+#endif  // _LIBCPP_DEBUG
+
+#ifdef _LIBCPP_MOVE
+
+template <class _C>
+inline
+auto
+begin(_C& __c) -> decltype(__c.begin())
+{
+    return __c.begin();
+}
+
+template <class _C>
+inline
+auto
+begin(const _C& __c) -> decltype(__c.begin())
+{
+    return __c.begin();
+}
+
+template <class _C>
+inline
+auto
+end(_C& __c) -> decltype(__c.end())
+{
+    return __c.end();
+}
+
+template <class _C>
+inline
+auto
+end(const _C& __c) -> decltype(__c.end())
+{
+    return __c.end();
+}
+
+#else
+
+template <class _C>
+inline
+typename _C::iterator
+begin(_C& __c)
+{
+    return __c.begin();
+}
+
+template <class _C>
+inline
+typename _C::const_iterator
+begin(const _C& __c)
+{
+    return __c.begin();
+}
+
+template <class _C>
+inline
+typename _C::iterator
+end(_C& __c)
+{
+    return __c.end();
+}
+
+template <class _C>
+inline
+typename _C::const_iterator
+end(const _C& __c)
+{
+    return __c.end();
+}
+
+#endif
+
+template <class _T, size_t _N>
+inline
+_T*
+begin(_T (&__array)[_N])
+{
+    return __array;
+}
+
+template <class _T, size_t _N>
+inline
+_T*
+end(_T (&__array)[_N])
+{
+    return __array + _N;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_ITERATOR
diff --git a/include/limits b/include/limits
new file mode 100644
index 0000000..6cebc2d
--- /dev/null
+++ b/include/limits
@@ -0,0 +1,613 @@
+// -*- C++ -*-
+//===---------------------------- limits ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_LIMITS
+#define _LIBCPP_LIMITS
+
+/*
+    limits synopsis
+
+namespace std
+{
+
+template<class T>
+class numeric_limits
+{
+public:
+    static const bool is_specialized = false;
+    static T min() throw();
+    static T max() throw();
+    static T lowest() throw();
+
+    static const int  digits = 0;
+    static const int  digits10 = 0;
+    static const int  max_digits10 = 0;
+    static const bool is_signed = false;
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int  radix = 0;
+    static T epsilon() throw();
+    static T round_error() throw();
+
+    static const int  min_exponent = 0;
+    static const int  min_exponent10 = 0;
+    static const int  max_exponent = 0;
+    static const int  max_exponent10 = 0;
+
+    static const bool has_infinity = false;
+    static const bool has_quiet_NaN = false;
+    static const bool has_signaling_NaN = false;
+    static const float_denorm_style has_denorm = denorm_absent;
+    static const bool has_denorm_loss = false;
+    static T infinity() throw();
+    static T quiet_NaN() throw();
+    static T signaling_NaN() throw();
+    static T denorm_min() throw();
+
+    static const bool is_iec559 = false;
+    static const bool is_bounded = false;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_toward_zero;
+};
+
+enum float_round_style
+{
+    round_indeterminate       = -1,
+    round_toward_zero         =  0,
+    round_to_nearest          =  1,
+    round_toward_infinity     =  2,
+    round_toward_neg_infinity =  3
+};
+
+enum float_denorm_style
+{
+    denorm_indeterminate = -1,
+    denorm_absent = 0,
+    denorm_present = 1
+};
+
+template<> class numeric_limits<cv bool>;
+
+template<> class numeric_limits<cv char>;
+template<> class numeric_limits<cv signed char>;
+template<> class numeric_limits<cv unsigned char>;
+template<> class numeric_limits<cv wchar_t>;
+template<> class numeric_limits<cv char16_t>;
+template<> class numeric_limits<cv char32_t>;
+
+template<> class numeric_limits<cv short>;
+template<> class numeric_limits<cv int>;
+template<> class numeric_limits<cv long>;
+template<> class numeric_limits<cv long long>;
+template<> class numeric_limits<cv unsigned short>;
+template<> class numeric_limits<cv unsigned int>;
+template<> class numeric_limits<cv unsigned long>;
+template<> class numeric_limits<cv unsigned long long>;
+
+template<> class numeric_limits<cv float>;
+template<> class numeric_limits<cv double>;
+template<> class numeric_limits<cv long double>;
+
+}  // std
+
+*/
+
+#pragma GCC system_header
+
+#include <__config>
+#include <type_traits>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+enum float_round_style
+{
+    round_indeterminate       = -1,
+    round_toward_zero         =  0,
+    round_to_nearest          =  1,
+    round_toward_infinity     =  2,
+    round_toward_neg_infinity =  3
+};
+
+enum float_denorm_style
+{
+    denorm_indeterminate = -1,
+    denorm_absent = 0,
+    denorm_present = 1
+};
+
+template <class _Tp, bool = is_arithmetic<_Tp>::value>
+class __libcpp_numeric_limits
+{
+protected:
+    typedef _Tp type;
+
+    static const bool is_specialized = false;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return type();}
+
+    static const int  digits = 0;
+    static const int  digits10 = 0;
+    static const int  max_digits10 = 0;
+    static const bool is_signed = false;
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int  radix = 0;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return type();}
+
+    static const int  min_exponent = 0;
+    static const int  min_exponent10 = 0;
+    static const int  max_exponent = 0;
+    static const int  max_exponent10 = 0;
+
+    static const bool has_infinity = false;
+    static const bool has_quiet_NaN = false;
+    static const bool has_signaling_NaN = false;
+    static const float_denorm_style has_denorm = denorm_absent;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return type();}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return type();}
+
+    static const bool is_iec559 = false;
+    static const bool is_bounded = false;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_toward_zero;
+};
+
+template <class _Tp, int digits, bool is_signed>
+struct __libcpp_compute_min
+{
+    static const _Tp value = _Tp(_Tp(1) << digits);
+};
+
+template <class _Tp, int digits>
+struct __libcpp_compute_min<_Tp, digits, false>
+{
+    static const _Tp value = _Tp(0);
+};
+
+template <class _Tp>
+class __libcpp_numeric_limits<_Tp, true>
+{
+protected:
+    typedef _Tp type;
+
+    static const bool is_specialized = true;
+
+    static const bool is_signed = type(-1) < type(0);
+    static const int  digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
+    static const int  digits10 = digits * 3 / 10;
+    static const int  max_digits10 = 0;
+    static const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
+    static const type __max = is_signed ? type(type(~0) ^ __min) : type(~0);
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __min;}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __max;}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return min();}
+
+    static const bool is_integer = true;
+    static const bool is_exact = true;
+    static const int  radix = 2;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return type(0);}
+
+    static const int  min_exponent = 0;
+    static const int  min_exponent10 = 0;
+    static const int  max_exponent = 0;
+    static const int  max_exponent10 = 0;
+
+    static const bool has_infinity = false;
+    static const bool has_quiet_NaN = false;
+    static const bool has_signaling_NaN = false;
+    static const float_denorm_style has_denorm = denorm_absent;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return type(0);}
+
+    static const bool is_iec559 = false;
+    static const bool is_bounded = true;
+    static const bool is_modulo = true;
+
+#if __i386__ || __x86_64__
+    static const bool traps = true;
+#else
+    static const bool traps = false;
+#endif
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_toward_zero;
+};
+
+template <>
+class __libcpp_numeric_limits<bool, true>
+{
+protected:
+    typedef bool type;
+
+    static const bool is_specialized = true;
+
+    static const bool is_signed = false;
+    static const int  digits = 1;
+    static const int  digits10 = 0;
+    static const int  max_digits10 = 0;
+    static const type __min = false;
+    static const type __max = true;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __min;}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __max;}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return min();}
+
+    static const bool is_integer = true;
+    static const bool is_exact = true;
+    static const int  radix = 2;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return type(0);}
+
+    static const int  min_exponent = 0;
+    static const int  min_exponent10 = 0;
+    static const int  max_exponent = 0;
+    static const int  max_exponent10 = 0;
+
+    static const bool has_infinity = false;
+    static const bool has_quiet_NaN = false;
+    static const bool has_signaling_NaN = false;
+    static const float_denorm_style has_denorm = denorm_absent;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return type(0);}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return type(0);}
+
+    static const bool is_iec559 = false;
+    static const bool is_bounded = true;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_toward_zero;
+};
+
+template <>
+class __libcpp_numeric_limits<float, true>
+{
+protected:
+    typedef float type;
+
+    static const bool is_specialized = true;
+
+    static const bool is_signed = true;
+    static const int  digits = __FLT_MANT_DIG__;
+    static const int  digits10 = __FLT_DIG__;
+    static const int  max_digits10 = 2+(digits * 30103)/100000;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __FLT_MIN__;}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __FLT_MAX__;}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return -max();}
+
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int  radix = __FLT_RADIX__;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __FLT_EPSILON__;}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return 0.5F;}
+
+    static const int  min_exponent = __FLT_MIN_EXP__;
+    static const int  min_exponent10 = __FLT_MIN_10_EXP__;
+    static const int  max_exponent = __FLT_MAX_EXP__;
+    static const int  max_exponent10 = __FLT_MAX_10_EXP__;
+
+    static const bool has_infinity = true;
+    static const bool has_quiet_NaN = true;
+    static const bool has_signaling_NaN = true;
+    static const float_denorm_style has_denorm = denorm_present;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __builtin_huge_valf();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __builtin_nanf("");}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __builtin_nansf("");}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __FLT_DENORM_MIN__;}
+
+    static const bool is_iec559 = true;
+    static const bool is_bounded = true;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_to_nearest;
+};
+
+template <>
+class __libcpp_numeric_limits<double, true>
+{
+protected:
+    typedef double type;
+
+    static const bool is_specialized = true;
+
+    static const bool is_signed = true;
+    static const int  digits = __DBL_MANT_DIG__;
+    static const int  digits10 = __DBL_DIG__;
+    static const int  max_digits10 = 2+(digits * 30103)/100000;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __DBL_MIN__;}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __DBL_MAX__;}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return -max();}
+
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int  radix = __FLT_RADIX__;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __DBL_EPSILON__;}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return 0.5;}
+
+    static const int  min_exponent = __DBL_MIN_EXP__;
+    static const int  min_exponent10 = __DBL_MIN_10_EXP__;
+    static const int  max_exponent = __DBL_MAX_EXP__;
+    static const int  max_exponent10 = __DBL_MAX_10_EXP__;
+
+    static const bool has_infinity = true;
+    static const bool has_quiet_NaN = true;
+    static const bool has_signaling_NaN = true;
+    static const float_denorm_style has_denorm = denorm_present;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __builtin_huge_val();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __builtin_nan("");}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __builtin_nans("");}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __DBL_DENORM_MIN__;}
+
+    static const bool is_iec559 = true;
+    static const bool is_bounded = true;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_to_nearest;
+};
+
+template <>
+class __libcpp_numeric_limits<long double, true>
+{
+protected:
+    typedef long double type;
+
+    static const bool is_specialized = true;
+
+    static const bool is_signed = true;
+    static const int  digits = __LDBL_MANT_DIG__;
+    static const int  digits10 = __LDBL_DIG__;
+    static const int  max_digits10 = 2+(digits * 30103)/100000;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __LDBL_MIN__;}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __LDBL_MAX__;}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return -max();}
+
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int  radix = __FLT_RADIX__;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __LDBL_EPSILON__;}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return 0.5;}
+
+    static const int  min_exponent = __LDBL_MIN_EXP__;
+    static const int  min_exponent10 = __LDBL_MIN_10_EXP__;
+    static const int  max_exponent = __LDBL_MAX_EXP__;
+    static const int  max_exponent10 = __LDBL_MAX_10_EXP__;
+
+    static const bool has_infinity = true;
+    static const bool has_quiet_NaN = true;
+    static const bool has_signaling_NaN = true;
+    static const float_denorm_style has_denorm = denorm_present;
+    static const bool has_denorm_loss = false;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __builtin_huge_vall();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __builtin_nanl("");}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __builtin_nansl("");}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __LDBL_DENORM_MIN__;}
+
+#if (defined(__ppc__) || defined(__ppc64__))
+    static const bool is_iec559 = false;
+#else
+    static const bool is_iec559 = true;
+#endif
+    static const bool is_bounded = true;
+    static const bool is_modulo = false;
+
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const float_round_style round_style = round_to_nearest;
+};
+
+template <class _Tp>
+class numeric_limits
+    : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
+{
+    typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base;
+    typedef typename __base::type type;
+public:
+    static const bool is_specialized = __base::is_specialized;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __base::min();}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __base::max();}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return __base::lowest();}
+
+    static const int  digits = __base::digits;
+    static const int  digits10 = __base::digits10;
+    static const int  max_digits10 = __base::max_digits10;
+    static const bool is_signed = __base::is_signed;
+    static const bool is_integer = __base::is_integer;
+    static const bool is_exact = __base::is_exact;
+    static const int  radix = __base::radix;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __base::epsilon();}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return __base::round_error();}
+
+    static const int  min_exponent = __base::min_exponent;
+    static const int  min_exponent10 = __base::min_exponent10;
+    static const int  max_exponent = __base::max_exponent;
+    static const int  max_exponent10 = __base::max_exponent10;
+
+    static const bool has_infinity = __base::has_infinity;
+    static const bool has_quiet_NaN = __base::has_quiet_NaN;
+    static const bool has_signaling_NaN = __base::has_signaling_NaN;
+    static const float_denorm_style has_denorm = __base::has_denorm;
+    static const bool has_denorm_loss = __base::has_denorm_loss;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __base::infinity();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __base::quiet_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __base::signaling_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __base::denorm_min();}
+
+    static const bool is_iec559 = __base::is_iec559;
+    static const bool is_bounded = __base::is_bounded;
+    static const bool is_modulo = __base::is_modulo;
+
+    static const bool traps = __base::traps;
+    static const bool tinyness_before = __base::tinyness_before;
+    static const float_round_style round_style = __base::round_style;
+};
+
+template <class _Tp>
+class numeric_limits<const _Tp>
+    : private numeric_limits<_Tp>
+{
+    typedef numeric_limits<_Tp> __base;
+    typedef _Tp type;
+public:
+    static const bool is_specialized = __base::is_specialized;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __base::min();}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __base::max();}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return __base::lowest();}
+
+    static const int  digits = __base::digits;
+    static const int  digits10 = __base::digits10;
+    static const int  max_digits10 = __base::max_digits10;
+    static const bool is_signed = __base::is_signed;
+    static const bool is_integer = __base::is_integer;
+    static const bool is_exact = __base::is_exact;
+    static const int  radix = __base::radix;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __base::epsilon();}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return __base::round_error();}
+
+    static const int  min_exponent = __base::min_exponent;
+    static const int  min_exponent10 = __base::min_exponent10;
+    static const int  max_exponent = __base::max_exponent;
+    static const int  max_exponent10 = __base::max_exponent10;
+
+    static const bool has_infinity = __base::has_infinity;
+    static const bool has_quiet_NaN = __base::has_quiet_NaN;
+    static const bool has_signaling_NaN = __base::has_signaling_NaN;
+    static const float_denorm_style has_denorm = __base::has_denorm;
+    static const bool has_denorm_loss = __base::has_denorm_loss;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __base::infinity();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __base::quiet_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __base::signaling_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __base::denorm_min();}
+
+    static const bool is_iec559 = __base::is_iec559;
+    static const bool is_bounded = __base::is_bounded;
+    static const bool is_modulo = __base::is_modulo;
+
+    static const bool traps = __base::traps;
+    static const bool tinyness_before = __base::tinyness_before;
+    static const float_round_style round_style = __base::round_style;
+};
+
+template <class _Tp>
+class numeric_limits<volatile _Tp>
+    : private numeric_limits<_Tp>
+{
+    typedef numeric_limits<_Tp> __base;
+    typedef _Tp type;
+public:
+    static const bool is_specialized = __base::is_specialized;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __base::min();}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __base::max();}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return __base::lowest();}
+
+    static const int  digits = __base::digits;
+    static const int  digits10 = __base::digits10;
+    static const int  max_digits10 = __base::max_digits10;
+    static const bool is_signed = __base::is_signed;
+    static const bool is_integer = __base::is_integer;
+    static const bool is_exact = __base::is_exact;
+    static const int  radix = __base::radix;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __base::epsilon();}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return __base::round_error();}
+
+    static const int  min_exponent = __base::min_exponent;
+    static const int  min_exponent10 = __base::min_exponent10;
+    static const int  max_exponent = __base::max_exponent;
+    static const int  max_exponent10 = __base::max_exponent10;
+
+    static const bool has_infinity = __base::has_infinity;
+    static const bool has_quiet_NaN = __base::has_quiet_NaN;
+    static const bool has_signaling_NaN = __base::has_signaling_NaN;
+    static const float_denorm_style has_denorm = __base::has_denorm;
+    static const bool has_denorm_loss = __base::has_denorm_loss;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __base::infinity();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __base::quiet_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __base::signaling_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __base::denorm_min();}
+
+    static const bool is_iec559 = __base::is_iec559;
+    static const bool is_bounded = __base::is_bounded;
+    static const bool is_modulo = __base::is_modulo;
+
+    static const bool traps = __base::traps;
+    static const bool tinyness_before = __base::tinyness_before;
+    static const float_round_style round_style = __base::round_style;
+};
+
+template <class _Tp>
+class numeric_limits<const volatile _Tp>
+    : private numeric_limits<_Tp>
+{
+    typedef numeric_limits<_Tp> __base;
+    typedef _Tp type;
+public:
+    static const bool is_specialized = __base::is_specialized;
+    _LIBCPP_INLINE_VISIBILITY static type min() throw() {return __base::min();}
+    _LIBCPP_INLINE_VISIBILITY static type max() throw() {return __base::max();}
+    _LIBCPP_INLINE_VISIBILITY static type lowest() throw() {return __base::lowest();}
+
+    static const int  digits = __base::digits;
+    static const int  digits10 = __base::digits10;
+    static const int  max_digits10 = __base::max_digits10;
+    static const bool is_signed = __base::is_signed;
+    static const bool is_integer = __base::is_integer;
+    static const bool is_exact = __base::is_exact;
+    static const int  radix = __base::radix;
+    _LIBCPP_INLINE_VISIBILITY static type epsilon() throw() {return __base::epsilon();}
+    _LIBCPP_INLINE_VISIBILITY static type round_error() throw() {return __base::round_error();}
+
+    static const int  min_exponent = __base::min_exponent;
+    static const int  min_exponent10 = __base::min_exponent10;
+    static const int  max_exponent = __base::max_exponent;
+    static const int  max_exponent10 = __base::max_exponent10;
+
+    static const bool has_infinity = __base::has_infinity;
+    static const bool has_quiet_NaN = __base::has_quiet_NaN;
+    static const bool has_signaling_NaN = __base::has_signaling_NaN;
+    static const float_denorm_style has_denorm = __base::has_denorm;
+    static const bool has_denorm_loss = __base::has_denorm_loss;
+    _LIBCPP_INLINE_VISIBILITY static type infinity() throw() {return __base::infinity();}
+    _LIBCPP_INLINE_VISIBILITY static type quiet_NaN() throw() {return __base::quiet_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type signaling_NaN() throw() {return __base::signaling_NaN();}
+    _LIBCPP_INLINE_VISIBILITY static type denorm_min() throw() {return __base::denorm_min();}
+
+    static const bool is_iec559 = __base::is_iec559;
+    static const bool is_bounded = __base::is_bounded;
+    static const bool is_modulo = __base::is_modulo;
+
+    static const bool traps = __base::traps;
+    static const bool tinyness_before = __base::tinyness_before;
+    static const float_round_style round_style = __base::round_style;
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_LIMITS
diff --git a/include/list b/include/list
new file mode 100644
index 0000000..33229a2
--- /dev/null
+++ b/include/list
@@ -0,0 +1,1531 @@
+// -*- C++ -*-
+//===---------------------------- list ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_LIST
+#define _LIBCPP_LIST
+
+/*
+    list synopsis
+
+namespace std
+{
+
+template <class T, class Alloc = allocator<T> >
+class list
+{
+public:
+
+    // types:
+    typedef T value_type;
+    typedef Alloc allocator_type;
+    typedef typename allocator_type::reference reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::pointer pointer;
+    typedef typename allocator_type::const_pointer const_pointer;
+    typedef implementation-defined iterator;
+    typedef implementation-defined const_iterator;
+    typedef implementation-defined size_type;
+    typedef implementation-defined difference_type;
+    typedef reverse_iterator<iterator> reverse_iterator;
+    typedef reverse_iterator<const_iterator> const_reverse_iterator;
+
+    list();
+    explicit list(const allocator_type& a);
+    explicit list(size_type n);
+    list(size_type n, const value_type& value);
+    list(size_type n, const value_type& value, const allocator_type& a);
+    template <class Iter>
+        list(Iter first, Iter last);
+    template <class Iter>
+        list(Iter first, Iter last, const allocator_type& a);
+    list(const list& x);
+    list(const list&, const allocator_type& a);
+    list(list&& x);
+    list(list&&, const allocator_type& a);
+    list(initializer_list<value_type>);
+    list(initializer_list<value_type>, const allocator_type& a);
+
+    ~list();
+
+    list& operator=(const list& x);
+    list& operator=(list&& x);
+    list& operator=(initializer_list<value_type>);
+    template <class Iter>
+        void assign(Iter first, Iter last);
+    void assign(size_type n, const value_type& t);
+    void assign(initializer_list<value_type>);
+
+    allocator_type get_allocator() const;
+
+    iterator begin();
+    const_iterator begin() const;
+    iterator end();
+    const_iterator end() const;
+    reverse_iterator rbegin();
+    const_reverse_iterator rbegin() const;
+    reverse_iterator rend();
+    const_reverse_iterator rend() const;
+    const_iterator cbegin() const;
+    const_iterator cend() const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend() const;
+
+    reference front();
+    const_reference front() const;
+    reference back();
+    const_reference back() const;
+
+    bool empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    template <class... Args>
+        void emplace_front(Args&&... args);
+    void pop_front();
+    template <class... Args>
+        void emplace_back(Args&&... args);
+    void pop_back();
+    void push_front(const value_type& x);
+    void push_front(value_type&& x);
+    void push_back(const value_type& x);
+    void push_back(value_type&& x);
+    template <class... Args>
+        iterator emplace(const_iterator position, Args&&... args);
+    iterator insert(const_iterator position, const value_type& x);
+    iterator insert(const_iterator position, value_type&& x);
+    iterator insert(const_iterator position, size_type n, const value_type& x);
+    template <class Iter>
+        iterator insert(const_iterator position, Iter first, Iter last);
+    iterator insert(const_iterator position, initializer_list<value_type> il);
+
+    iterator erase(const_iterator position);
+    iterator erase(const_iterator position, const_iterator last);
+
+    void resize(size_type sz);
+    void resize(size_type sz, const value_type& c);
+
+    void swap(list<value_type,allocator_type>&);
+    void clear();
+
+    void splice(const_iterator position, list& x);
+    void splice(const_iterator position, list&& x);
+    void splice(const_iterator position, list& x, const_iterator i);
+    void splice(const_iterator position, list&& x, const_iterator i);
+    void splice(const_iterator position, list& x, const_iterator first,
+                                                  const_iterator last);
+    void splice(const_iterator position, list&& x, const_iterator first,
+                                                  const_iterator last);
+
+    void remove(const value_type& value);
+    template <class Pred> void remove_if(Pred pred);
+    void unique();
+    template <class BinaryPredicate>
+        void unique(BinaryPredicate binary_pred);
+    void merge(list& x);
+    void merge(list&& x);
+    template <class Compare>
+        void merge(list& x, Compare comp);
+    template <class Compare>
+        void merge(list&& x, Compare comp);
+    void sort();
+    template <class Compare>
+        void sort(Compare comp);
+    void reverse();
+};
+
+template <class T, class Alloc>
+    bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
+template <class T, class Alloc>
+    bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
+template <class T, class Alloc>
+    bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
+template <class T, class Alloc>
+    bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
+template <class T, class Alloc>
+    bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
+template <class T, class Alloc>
+    bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
+
+template <class T, class Alloc>
+    void swap(list<T,Alloc>& x, list<T,Alloc>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+
+#include <memory>
+#include <limits>
+#include <initializer_list>
+#include <iterator>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class, class> struct __list_node;
+
+template <class _Tp, class _VoidPtr>
+struct __list_node_base
+{
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node<_Tp, _VoidPtr> > pointer;
+#else
+        rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
+#endif
+
+    pointer __prev_;
+    pointer __next_;
+
+    __list_node_base()
+        : __prev_(static_cast<pointer>(this)),
+          __next_(static_cast<pointer>(this))
+          {}
+};
+
+template <class _Tp, class _VoidPtr>
+struct __list_node
+    : public __list_node_base<_Tp, _VoidPtr>
+{
+    _Tp __value_;
+};
+
+template <class, class> class list;
+template <class, class> class __list_imp;
+template <class, class> class __list_const_iterator;
+
+template <class _Tp, class _VoidPtr>
+class __list_iterator
+{
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
+#else
+        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
+#endif
+
+    __node_pointer __ptr_;
+
+    explicit __list_iterator(__node_pointer __p) : __ptr_(__p) {}
+
+    template<class, class> friend class list;
+    template<class, class> friend class __list_imp;
+    template<class, class> friend class __list_const_iterator;
+public:
+    typedef bidirectional_iterator_tag       iterator_category;
+    typedef _Tp                              value_type;
+    typedef value_type&                      reference;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                             pointer;
+    typedef typename pointer_traits<pointer>::difference_type difference_type;
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &(operator*());}
+
+    __list_iterator& operator++() {__ptr_ = __ptr_->__next_; return *this;}
+    __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
+
+    __list_iterator& operator--() {__ptr_ = __ptr_->__prev_; return *this;}
+    __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
+
+    friend bool operator==(const __list_iterator& __x, const __list_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
+        {return !(__x == __y);}
+};
+
+template <class _Tp, class _VoidPtr>
+class __list_const_iterator
+{
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+        rebind<const __list_node<_Tp, _VoidPtr> > __node_pointer;
+#else
+        rebind<const __list_node<_Tp, _VoidPtr> >::other __node_pointer;
+#endif
+
+    __node_pointer __ptr_;
+
+    explicit __list_const_iterator(__node_pointer __p) : __ptr_(__p) {}
+
+    template<class, class> friend class list;
+    template<class, class> friend class __list_imp;
+public:
+    typedef bidirectional_iterator_tag       iterator_category;
+    typedef _Tp                              value_type;
+    typedef const value_type&                reference;
+    typedef typename pointer_traits<_VoidPtr>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<const value_type>
+#else
+            rebind<const value_type>::other
+#endif
+                                             pointer;
+    typedef typename pointer_traits<pointer>::difference_type difference_type;
+
+    __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) : __ptr_(__p.__ptr_) {}
+
+    reference operator*() const {return __ptr_->__value_;}
+    pointer operator->() const {return &(operator*());}
+
+    __list_const_iterator& operator++() {__ptr_ = __ptr_->__next_; return *this;}
+    __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
+
+    __list_const_iterator& operator--() {__ptr_ = __ptr_->__prev_; return *this;}
+    __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
+
+    friend bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
+        {return __x.__ptr_ == __y.__ptr_;}
+    friend bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
+        {return !(__x == __y);}
+};
+
+template <class _Tp, class _Alloc>
+class __list_imp
+{
+    __list_imp(const __list_imp&);
+    __list_imp& operator=(const __list_imp&);
+protected:
+    typedef _Tp                                                     value_type;
+    typedef _Alloc                                                  allocator_type;
+    typedef allocator_traits<allocator_type>                        __alloc_traits;
+    typedef typename __alloc_traits::size_type                      size_type;
+    typedef typename __alloc_traits::void_pointer                   __void_pointer;
+    typedef __list_iterator<value_type, __void_pointer>             iterator;
+    typedef __list_const_iterator<value_type, __void_pointer>       const_iterator;
+    typedef __list_node_base<value_type, __void_pointer>            __node_base;
+    typedef __list_node<value_type, __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_alloc_traits;
+    typedef typename __node_alloc_traits::pointer                    __node_pointer;
+    typedef typename __node_alloc_traits::const_pointer              __node_const_pointer;
+    typedef typename __alloc_traits::pointer                         pointer;
+    typedef typename __alloc_traits::const_pointer                   const_pointer;
+    typedef typename __alloc_traits::difference_type                 difference_type;
+
+    __node_base __end_;
+    __compressed_pair<size_type, __node_allocator> __size_alloc_;
+
+          size_type& __sz()       {return __size_alloc_.first();}
+    const size_type& __sz() const {return __size_alloc_.first();}
+          __node_allocator& __node_alloc()       {return __size_alloc_.second();}
+    const __node_allocator& __node_alloc() const {return __size_alloc_.second();}
+
+    static void __unlink_nodes(__node_base& __f, __node_base& __l);
+
+    __list_imp();
+    __list_imp(const allocator_type& __a);
+    ~__list_imp();
+    void clear();
+    bool empty() const {return __sz() == 0;}
+
+          iterator begin()       {return       iterator(__end_.__next_);}
+    const_iterator begin() const {return const_iterator(__end_.__next_);}
+          iterator end()       {return       iterator(static_cast<__node_pointer>      (&__end_));}
+    const_iterator end() const {return const_iterator(static_cast<__node_const_pointer>(&__end_));}
+
+    void swap(__list_imp& __c);
+
+    void __copy_assign_alloc(const __list_imp& __c)
+        {__copy_assign_alloc(__c, integral_constant<bool,
+                      __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+    void __move_assign_alloc(__list_imp& __c)
+        {__move_assign_alloc(__c, integral_constant<bool,
+                      __node_alloc_traits::propagate_on_container_move_assignment::value>());}
+
+private:
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __node_alloc_traits::propagate_on_container_swap::value>());}
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
+        {}
+
+    void __copy_assign_alloc(const __list_imp& __c, true_type)
+        {
+            if (__node_alloc() != __c.__node_alloc())
+                clear();
+            __node_alloc() = __c.__node_alloc();
+        }
+
+    void __copy_assign_alloc(const __list_imp& __c, false_type)
+        {}
+
+    void __move_assign_alloc(const __list_imp& __c, true_type)
+        {
+            __node_alloc() = _STD::move(__c.__node_alloc());
+        }
+
+    void __move_assign_alloc(const __list_imp& __c, false_type)
+        {}
+};
+
+// Unlink nodes [__f, __l]
+template <class _Tp, class _Alloc>
+inline
+void
+__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l)
+{
+    __f.__prev_->__next_ = __l.__next_;
+    __l.__next_->__prev_ = __f.__prev_;
+}
+
+template <class _Tp, class _Alloc>
+inline
+__list_imp<_Tp, _Alloc>::__list_imp()
+    : __size_alloc_(0)
+{
+}
+
+template <class _Tp, class _Alloc>
+inline
+__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
+    : __size_alloc_(0, __node_allocator(__a))
+{
+}
+
+template <class _Tp, class _Alloc>
+__list_imp<_Tp, _Alloc>::~__list_imp()
+{
+    clear();
+}
+
+template <class _Tp, class _Alloc>
+void
+__list_imp<_Tp, _Alloc>::clear()
+{
+    if (!empty())
+    {
+        __node_allocator& __na = __node_alloc();
+        iterator __f = begin();
+        iterator __l = end();
+        __unlink_nodes(*__f.__ptr_, *__l.__ptr_->__prev_);
+        __sz() = 0;
+        while (__f != __l)
+        {
+            __node& __n = *__f.__ptr_;
+            ++__f;
+            __node_alloc_traits::destroy(__na, addressof(__n.__value_));
+            __node_alloc_traits::deallocate(__na, addressof(__n), 1);
+        }
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
+{
+    using _STD::swap;
+    __swap_alloc(__node_alloc(), __c.__node_alloc());
+    swap(__sz(), __c.__sz());
+    swap(__end_, __c.__end_);
+    if (__sz() == 0)
+        __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_);
+    else
+        __end_.__prev_->__next_ = __end_.__next_->__prev_
+                                = &static_cast<__node&>(__end_);
+    if (__c.__sz() == 0)
+        __c.__end_.__next_ = __c.__end_.__prev_
+                           = &static_cast<__node&>(__c.__end_);
+    else
+        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_
+                                    = &static_cast<__node&>(__c.__end_);
+}
+
+template <class _Tp, class _Alloc = allocator<_Tp> >
+class list
+    : private __list_imp<_Tp, _Alloc>
+{
+    typedef __list_imp<_Tp, _Alloc> base;
+    typedef typename base::__node              __node;
+    typedef typename base::__node_allocator    __node_allocator;
+    typedef typename base::__node_pointer      __node_pointer;
+    typedef typename base::__node_alloc_traits __node_alloc_traits;
+
+public:
+    typedef _Tp                                      value_type;
+    typedef _Alloc                                   allocator_type;
+    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
+                  "Invalid allocator::value_type");
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+    typedef typename base::pointer                   pointer;
+    typedef typename base::const_pointer             const_pointer;
+    typedef typename base::size_type                 size_type;
+    typedef typename base::difference_type           difference_type;
+    typedef typename base::iterator                  iterator;
+    typedef typename base::const_iterator            const_iterator;
+    typedef _STD::reverse_iterator<iterator>         reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>   const_reverse_iterator;
+
+    list() {}
+    list(const allocator_type& __a) : base(__a) {}
+    list(size_type __n);
+    list(size_type __n, const value_type& __x);
+    list(size_type __n, const value_type& __x, const allocator_type& __a);
+    template <class _InpIter>
+        list(_InpIter __f, _InpIter __l,
+             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
+    template <class _InpIter>
+        list(_InpIter __f, _InpIter __l, const allocator_type& __a,
+             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
+
+    list(const list& __c);
+    list(const list& __c, const allocator_type& __a);
+    list& operator=(const list& __c);
+    list(initializer_list<value_type> __il);
+    list(initializer_list<value_type> __il, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    list(list&& __c);
+    list(list&& __c, const allocator_type& __a);
+    list& operator=(list&& __c);
+#endif
+    list& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+
+    template <class _InpIter>
+        void assign(_InpIter __f, _InpIter __l,
+             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
+    void assign(size_type __n, const value_type& __x);
+    void assign(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end());}
+
+    allocator_type get_allocator() const;
+
+    size_type size() const     {return base::__sz();}
+    bool empty() const         {return base::empty();}
+    size_type max_size() const {return numeric_limits<difference_type>::max();}
+
+          iterator begin()        {return base::begin();}
+    const_iterator begin()  const {return base::begin();}
+          iterator end()          {return base::end();}
+    const_iterator end()    const {return base::end();}
+    const_iterator cbegin() const {return base::begin();}
+    const_iterator cend()   const {return base::end();}
+
+          reverse_iterator rbegin()        {return       reverse_iterator(end());}
+    const_reverse_iterator rbegin()  const {return const_reverse_iterator(end());}
+          reverse_iterator rend()          {return       reverse_iterator(begin());}
+    const_reverse_iterator rend()    const {return const_reverse_iterator(begin());}
+    const_reverse_iterator crbegin() const {return const_reverse_iterator(end());}
+    const_reverse_iterator crend()   const {return const_reverse_iterator(begin());}
+
+          reference front()        {return base::__end_.__next_->__value_;}
+    const_reference front() const  {return base::__end_.__next_->__value_;}
+          reference back()         {return base::__end_.__prev_->__value_;}
+    const_reference back()  const  {return base::__end_.__prev_->__value_;}
+
+#ifdef _LIBCPP_MOVE
+    void push_front(value_type&& __x);
+    void push_back(value_type&& __x);
+    template <class... _Args>
+       void emplace_front(_Args&&... __args);
+    template <class... _Args>
+        void emplace_back(_Args&&... __args);
+    template <class... _Args>
+        iterator emplace(const_iterator __p, _Args&&... __args);
+    iterator insert(const_iterator __p, value_type&& __x);
+#endif
+
+    void push_front(const value_type& __x);
+    void push_back(const value_type& __x);
+
+    iterator insert(const_iterator __p, const value_type& __x);
+    iterator insert(const_iterator __p, size_type __n, const value_type& __x);
+    template <class _InpIter>
+        iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
+             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
+    iterator insert(const_iterator __p, initializer_list<value_type> __il)
+        {return insert(__p, __il.begin(), __il.end());}
+
+    void swap(list& __c) {base::swap(__c);}
+    void clear() {base::clear();}
+
+    void pop_front();
+    void pop_back();
+
+    iterator erase(const_iterator __p);
+    iterator erase(const_iterator __f, const_iterator __l);
+
+    void resize(size_type __n);
+    void resize(size_type __n, const value_type& __x);
+
+    void splice(const_iterator __p, list& __c);
+#ifdef _LIBCPP_MOVE
+    void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
+#endif
+    void splice(const_iterator __p, list& __c, const_iterator __i);
+#ifdef _LIBCPP_MOVE
+    void splice(const_iterator __p, list&& __c, const_iterator __i)
+        {splice(__p, __c, __i);}
+#endif
+    void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
+#ifdef _LIBCPP_MOVE
+    void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
+        {splice(__p, __c, __f, __l);}
+#endif
+
+    void remove(const value_type& __x);
+    template <class _Pred> void remove_if(_Pred __pred);
+    void unique();
+    template <class _BinaryPred>
+        void unique(_BinaryPred __binary_pred);
+    void merge(list& __c);
+#ifdef _LIBCPP_MOVE
+    void merge(list&& __c) {merge(__c);}
+#endif
+    template <class _Comp>
+        void merge(list& __c, _Comp __comp);
+#ifdef _LIBCPP_MOVE
+    template <class _Comp>
+        void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
+#endif
+    void sort();
+    template <class _Comp>
+        void sort(_Comp __comp);
+
+    void reverse();
+
+private:
+    static void __link_nodes(__node& __p, __node& __f, __node& __l);
+    iterator __iterator(size_type __n);
+    template <class _Comp>
+        static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
+
+    void __move_assign(list& __c, true_type);
+    void __move_assign(list& __c, false_type);
+};
+
+// Link in nodes [__f, __l] just prior to __p
+template <class _Tp, class _Alloc>
+inline
+void
+list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l)
+{
+    __p.__prev_->__next_ = &__f;
+    __f.__prev_ = __p.__prev_;
+    __p.__prev_ = &__l;
+    __l.__next_ = &__p;
+}
+
+template <class _Tp, class _Alloc>
+inline
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::__iterator(size_type __n)
+{
+    return __n <= base::__sz() / 2 ? next(begin(), __n)
+                                   : prev(end(), base::__sz() - __n);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(size_type __n)
+{
+    for (; __n > 0; --__n)
+#ifdef _LIBCPP_MOVE
+        emplace_back();
+#else
+        push_back(value_type());
+#endif
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
+{
+    for (; __n > 0; --__n)
+        push_back(__x);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
+    : base(__a)
+{
+    for (; __n > 0; --__n)
+        push_back(__x);
+}
+
+template <class _Tp, class _Alloc>
+template <class _InpIter>
+list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
+                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
+{
+    for (; __f != __l; ++__f)
+        push_back(*__f);
+}
+
+template <class _Tp, class _Alloc>
+template <class _InpIter>
+list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
+                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
+    : base(__a)
+{
+    for (; __f != __l; ++__f)
+        push_back(*__f);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(const list& __c)
+    : base(allocator_type(
+           __node_alloc_traits::select_on_container_copy_construction(
+                __c.__node_alloc())))
+{
+    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
+        push_back(*__i);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
+    : base(__a)
+{
+    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
+        push_back(*__i);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
+    : base(__a)
+{
+    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
+            __e = __il.end(); __i != __e; ++__i)
+        push_back(*__i);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
+{
+    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
+            __e = __il.end(); __i != __e; ++__i)
+        push_back(*__i);
+}
+
+template <class _Tp, class _Alloc>
+inline
+list<_Tp, _Alloc>&
+list<_Tp, _Alloc>::operator=(const list& __c)
+{
+    if (this != &__c)
+    {
+        base::__copy_assign_alloc(__c);
+        assign(__c.begin(), __c.end());
+    }
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+inline
+list<_Tp, _Alloc>::list(list&& __c)
+    : base(allocator_type(_STD::move(__c.__node_alloc())))
+{
+    splice(end(), __c);
+}
+
+template <class _Tp, class _Alloc>
+inline
+list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
+    : base(__a)
+{
+    if (__a == __c.get_allocator())
+        splice(end(), __c);
+    else
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__c.begin()), _I(__c.end()));
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+list<_Tp, _Alloc>&
+list<_Tp, _Alloc>::operator=(list&& __c)
+{
+    __move_assign(__c, integral_constant<bool,
+          __node_alloc_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
+{
+    if (base::__node_alloc() != __c.__node_alloc())
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__c.begin()), _I(__c.end()));
+    }
+    else
+        __move_assign(__c, true_type());
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
+{
+    clear();
+    base::__move_assign_alloc(__c);
+    splice(end(), __c);
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+template <class _InpIter>
+void
+list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
+                          typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
+{
+    iterator __i = begin();
+    iterator __e = end();
+    for (; __f != __l && __i != __e; ++__f, ++__i)
+        *__i = *__f;
+    if (__i == __e)
+        insert(__e, __f, __l);
+    else
+        erase(__i, __e);
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
+{
+    iterator __i = begin();
+    iterator __e = end();
+    for (; __n > 0 && __i != __e; --__n, ++__i)
+        *__i = __x;
+    if (__i == __e)
+        insert(__e, __n, __x);
+    else
+        erase(__i, __e);
+}
+
+template <class _Tp, class _Alloc>
+inline
+_Alloc
+list<_Tp, _Alloc>::get_allocator() const
+{
+    return allocator_type(base::__node_alloc());
+}
+
+template <class _Tp, class _Alloc>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __hold->__prev_ = 0;
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    ++base::__sz();
+    return iterator(__hold.release());
+}
+
+template <class _Tp, class _Alloc>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
+{
+    iterator __r(const_cast<__node_pointer>(__p.__ptr_));
+    if (__n > 0)
+    {
+        size_type __ds = 0;
+        __node_allocator& __na = base::__node_alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+        __hold->__prev_ = 0;
+        __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+        ++__ds;
+        __r = iterator(__hold.get());
+        __hold.release();
+        iterator __e = __r;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            {
+                __hold.reset(__node_alloc_traits::allocate(__na, 1));
+                __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+                __e.__ptr_->__next_ = __hold.get();
+                __hold->__prev_ = __e.__ptr_;
+                __hold.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (true)
+            {
+                __node_alloc_traits::destroy(__na, addressof(*__e));
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
+                if (__prev == 0)
+                    break;
+                __e = iterator(__prev);
+            }
+            throw;
+        }
+#endif
+        __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_);
+        base::__sz() += __ds;
+    }
+    return __r;
+}
+
+template <class _Tp, class _Alloc>
+template <class _InpIter>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
+             typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
+{
+    iterator __r(const_cast<__node_pointer>(__p.__ptr_));
+    if (__f != __l)
+    {
+        size_type __ds = 0;
+        __node_allocator& __na = base::__node_alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+        __hold->__prev_ = 0;
+        __node_alloc_traits::construct(__na, addressof(__hold->__value_), *__f);
+        ++__ds;
+        __r = iterator(__hold.get());
+        __hold.release();
+        iterator __e = __r;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (++__f; __f != __l; ++__f, ++__e, ++__ds)
+            {
+                __hold.reset(__node_alloc_traits::allocate(__na, 1));
+                __node_alloc_traits::construct(__na, addressof(__hold->__value_), *__f);
+                __e.__ptr_->__next_ = __hold.get();
+                __hold->__prev_ = __e.__ptr_;
+                __hold.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (true)
+            {
+                __node_alloc_traits::destroy(__na, addressof(*__e));
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
+                if (__prev == 0)
+                    break;
+                __e = iterator(__prev);
+            }
+            throw;
+        }
+#endif
+        __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_);
+        base::__sz() += __ds;
+    }
+    return __r;
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::push_front(const value_type& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+    __link_nodes(*base::__end_.__next_, *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::push_back(const value_type& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+    __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::push_front(value_type&& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x));
+    __link_nodes(*base::__end_.__next_, *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::push_back(value_type&& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x));
+    __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+template <class _Tp, class _Alloc>
+template <class... _Args>
+void
+list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...);
+    __link_nodes(*base::__end_.__next_, *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+template <class _Tp, class _Alloc>
+template <class... _Args>
+void
+list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...);
+    __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold);
+    ++base::__sz();
+    __hold.release();
+}
+
+template <class _Tp, class _Alloc>
+template <class... _Args>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __hold->__prev_ = 0;
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::forward<_Args>(__args)...);
+    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    ++base::__sz();
+    return iterator(__hold.release());
+}
+
+template <class _Tp, class _Alloc>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
+{
+    __node_allocator& __na = base::__node_alloc();
+    typedef __allocator_destructor<__node_allocator> _D;
+    unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+    __hold->__prev_ = 0;
+    __node_alloc_traits::construct(__na, addressof(__hold->__value_), _STD::move(__x));
+    __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold);
+    ++base::__sz();
+    return iterator(__hold.release());
+}
+
+#endif
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::pop_front()
+{
+    __node_allocator& __na = base::__node_alloc();
+    __node& __n = *base::__end_.__next_;
+    base::__unlink_nodes(__n, __n);
+    --base::__sz();
+    __node_alloc_traits::destroy(__na, addressof(__n.__value_));
+    __node_alloc_traits::deallocate(__na, addressof(__n), 1);
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::pop_back()
+{
+    __node_allocator& __na = base::__node_alloc();
+    __node& __n = *base::__end_.__prev_;
+    base::__unlink_nodes(__n, __n);
+    --base::__sz();
+    __node_alloc_traits::destroy(__na, addressof(__n.__value_));
+    __node_alloc_traits::deallocate(__na, addressof(__n), 1);
+}
+
+template <class _Tp, class _Alloc>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::erase(const_iterator __p)
+{
+    __node_allocator& __na = base::__node_alloc();
+    __node& __n = const_cast<__node&>(*__p.__ptr_);
+    __node_pointer __r = __n.__next_;
+    base::__unlink_nodes(__n, __n);
+    --base::__sz();
+    __node_alloc_traits::destroy(__na, addressof(__n.__value_));
+    __node_alloc_traits::deallocate(__na, addressof(__n), 1);
+    return iterator(__r);
+}
+
+template <class _Tp, class _Alloc>
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
+{
+    if (__f != __l)
+    {
+        __node_allocator& __na = base::__node_alloc();
+        base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_);
+        while (__f != __l)
+        {
+            __node& __n = const_cast<__node&>(*__f.__ptr_);
+            ++__f;
+            --base::__sz();
+            __node_alloc_traits::destroy(__na, addressof(__n.__value_));
+            __node_alloc_traits::deallocate(__na, addressof(__n), 1);
+        }
+    }
+    return iterator(const_cast<__node_pointer>(__l.__ptr_));
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::resize(size_type __n)
+{
+    if (__n < base::__sz())
+        erase(__iterator(__n), end());
+    else if (__n > base::__sz())
+    {
+        __n -= base::__sz();
+        size_type __ds = 0;
+        __node_allocator& __na = base::__node_alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+        __hold->__prev_ = 0;
+        __node_alloc_traits::construct(__na, addressof(__hold->__value_));
+        ++__ds;
+        iterator __r = iterator(__hold.release());
+        iterator __e = __r;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            {
+                __hold.reset(__node_alloc_traits::allocate(__na, 1));
+                __node_alloc_traits::construct(__na, addressof(__hold->__value_));
+                __e.__ptr_->__next_ = __hold.get();
+                __hold->__prev_ = __e.__ptr_;
+                __hold.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (true)
+            {
+                __node_alloc_traits::destroy(__na, addressof(*__e));
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
+                if (__prev == 0)
+                    break;
+                __e = iterator(__prev);
+            }
+            throw;
+        }
+#endif
+        __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_);
+        base::__sz() += __ds;
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
+{
+    if (__n < base::__sz())
+        erase(__iterator(__n), end());
+    else if (__n > base::__sz())
+    {
+        __n -= base::__sz();
+        size_type __ds = 0;
+        __node_allocator& __na = base::__node_alloc();
+        typedef __allocator_destructor<__node_allocator> _D;
+        unique_ptr<__node, _D> __hold(__node_alloc_traits::allocate(__na, 1), _D(__na, 1));
+        __hold->__prev_ = 0;
+        __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+        ++__ds;
+        iterator __r = iterator(__hold.release());
+        iterator __e = __r;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (--__n; __n != 0; --__n, ++__e, ++__ds)
+            {
+                __hold.reset(__node_alloc_traits::allocate(__na, 1));
+                __node_alloc_traits::construct(__na, addressof(__hold->__value_), __x);
+                __e.__ptr_->__next_ = __hold.get();
+                __hold->__prev_ = __e.__ptr_;
+                __hold.release();
+            }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            while (true)
+            {
+                __node_alloc_traits::destroy(__na, addressof(*__e));
+                __node_pointer __prev = __e.__ptr_->__prev_;
+                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
+                if (__prev == 0)
+                    break;
+                __e = iterator(__prev);
+            }
+            throw;
+        }
+#endif
+        __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_);
+        base::__sz() += __ds;
+    }        
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
+{
+    if (!__c.empty())
+    {
+        __node& __f = *__c.__end_.__next_;
+        __node& __l = *__c.__end_.__prev_;
+        base::__unlink_nodes(__f, __l);
+        __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l);
+        base::__sz() += __c.__sz();
+        __c.__sz() = 0;
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
+{
+    if (__p != __i && __p != next(__i))
+    {
+        __node& __f = const_cast<__node&>(*__i.__ptr_);
+        base::__unlink_nodes(__f, __f);
+        __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f);
+        --__c.__sz();
+        ++base::__sz();
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
+{
+    if (__f != __l)
+    {
+        if (this != &__c)
+        {
+            size_type __s = _STD::distance(__f, __l);
+            __c.__sz() -= __s;
+            base::__sz() += __s;
+        }
+        __node& __first = const_cast<__node&>(*__f.__ptr_);
+        --__l;
+        __node& __last = const_cast<__node&>(*__l.__ptr_);
+        base::__unlink_nodes(__first, __last);
+        __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last);
+    }
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::remove(const value_type& __x)
+{
+    for (iterator __i = begin(), __e = end(); __i != __e;)
+    {
+        if (*__i == __x)
+        {
+            iterator __j = next(__i);
+            for (; __j != __e && *__j == __x; ++__j)
+                ;
+            __i = erase(__i, __j);
+        }
+        else
+            ++__i;
+    }
+}
+
+template <class _Tp, class _Alloc>
+template <class _Pred>
+void
+list<_Tp, _Alloc>::remove_if(_Pred __pred)
+{
+    for (iterator __i = begin(), __e = end(); __i != __e;)
+    {
+        if (__pred(*__i))
+        {
+            iterator __j = next(__i);
+            for (; __j != __e && __pred(*__j); ++__j)
+                ;
+            __i = erase(__i, __j);
+        }
+        else
+            ++__i;
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+list<_Tp, _Alloc>::unique()
+{
+    unique(__equal_to<value_type>());
+}
+
+template <class _Tp, class _Alloc>
+template <class _BinaryPred>
+void
+list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
+{
+    for (iterator __i = begin(), __e = end(); __i != __e;)
+    {
+        iterator __j = next(__i);
+        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
+            ;
+        if (++__i != __j)
+            __i = erase(__i, __j);
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+list<_Tp, _Alloc>::merge(list& __c)
+{
+    merge(__c, __less<value_type>());
+}
+
+template <class _Tp, class _Alloc>
+template <class _Comp>
+void
+list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
+{
+    if (this != &__c)
+    {
+        iterator __f1 = begin();
+        iterator __e1 = end();
+        iterator __f2 = __c.begin();
+        iterator __e2 = __c.end();
+        while (__f1 != __e1 && __f2 != __e2)
+        {
+            if (__comp(*__f2, *__f1))
+            {
+                size_type __ds = 1;
+                iterator __m2 = next(__f2);
+                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
+                    ;
+                base::__sz() += __ds;
+                __c.__sz() -= __ds;
+                __node& __f = *__f2.__ptr_;
+                __node& __l = *__m2.__ptr_->__prev_;
+                __f2 = __m2;
+                base::__unlink_nodes(__f, __l);
+                __m2 = next(__f1);
+                __link_nodes(*__f1.__ptr_, __f, __l);
+                __f1 = __m2;
+            }
+            else
+                ++__f1;
+        }
+        splice(__e1, __c);
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+list<_Tp, _Alloc>::sort()
+{
+    sort(__less<value_type>());
+}
+
+template <class _Tp, class _Alloc>
+template <class _Comp>
+inline
+void
+list<_Tp, _Alloc>::sort(_Comp __comp)
+{
+    __sort(begin(), end(), base::__sz(), __comp);
+}
+
+template <class _Tp, class _Alloc>
+template <class _Comp>
+inline
+typename list<_Tp, _Alloc>::iterator
+list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
+{
+    switch (__n)
+    {
+    case 0:
+    case 1:
+        return __f1;
+    case 2:
+        if (__comp(*--__e2, *__f1))
+        {
+            __node& __f = *__e2.__ptr_;
+            base::__unlink_nodes(__f, __f);
+            __link_nodes(*__f1.__ptr_, __f, __f);
+            return __e2;
+        }
+        return __f1;
+    }
+    size_type __n2 = __n / 2;
+    iterator __e1 = next(__f1, __n2);
+    iterator  __r = __f1 = __sort(__f1, __e1, __n2, __comp);
+    iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
+    if (__comp(*__f2, *__f1))
+    {
+        iterator __m2 = next(__f2);
+        for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
+            ;
+        __node& __f = *__f2.__ptr_;
+        __node& __l = *__m2.__ptr_->__prev_;
+        __r = __f2;
+        __e1 = __f2 = __m2;
+        base::__unlink_nodes(__f, __l);
+        __m2 = next(__f1);
+        __link_nodes(*__f1.__ptr_, __f, __l);
+        __f1 = __m2;
+    }
+    else
+        ++__f1;
+    while (__f1 != __e1 && __f2 != __e2)
+    {
+        if (__comp(*__f2, *__f1))
+        {
+            iterator __m2 = next(__f2);
+            for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
+                ;
+            __node& __f = *__f2.__ptr_;
+            __node& __l = *__m2.__ptr_->__prev_;
+            if (__e1 == __f2)
+                __e1 = __m2;
+            __f2 = __m2;
+            base::__unlink_nodes(__f, __l);
+            __m2 = next(__f1);
+            __link_nodes(*__f1.__ptr_, __f, __l);
+            __f1 = __m2;
+        }
+        else
+            ++__f1;
+    }
+    return __r;
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::reverse()
+{
+    if (base::__sz() > 1)
+    {
+        iterator __e = end();
+        for (iterator __i = begin(); __i != __e; --__i)
+            _STD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
+        _STD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
+    }
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Alloc>
+inline
+bool
+operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Alloc>
+inline
+void
+swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_LIST
diff --git a/include/locale b/include/locale
new file mode 100644
index 0000000..9052833
--- /dev/null
+++ b/include/locale
@@ -0,0 +1,3369 @@
+// -*- C++ -*-
+//===-------------------------- locale ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_LOCALE
+#define _LIBCPP_LOCALE
+
+/*
+    locale synopsis
+
+namespace std
+{
+
+class locale
+{
+public:
+    // types:
+    class facet;
+    class id;
+
+    typedef int category;
+    static const category // values assigned here are for exposition only
+        none     = 0x000,
+        collate  = 0x010,
+        ctype    = 0x020,
+        monetary = 0x040,
+        numeric  = 0x080,
+        time     = 0x100,
+        messages = 0x200,
+        all = collate | ctype | monetary | numeric | time | messages;
+
+    // construct/copy/destroy:
+    locale() throw();
+    locale(const locale& other) throw();
+    explicit locale(const char* std_name);
+    explicit locale(const string& std_name);
+    locale(const locale& other, const char* std_name, category);
+    locale(const locale& other, const string& std_name, category);
+    template <class Facet> locale(const locale& other, Facet* f);
+    locale(const locale& other, const locale& one, category);
+
+    ~locale() throw(); // not virtual
+
+    const locale& operator=(const locale& other) throw();
+
+    template <class Facet> locale combine(const locale& other) const;
+
+    // locale operations:
+    basic_string<char> name() const;
+    bool operator==(const locale& other) const;
+    bool operator!=(const locale& other) const;
+    template <class charT, class Traits, class Allocator>
+      bool operator()(const basic_string<charT,Traits,Allocator>& s1,
+                      const basic_string<charT,Traits,Allocator>& s2) const;
+
+    // global locale objects:
+    static locale global(const locale&);
+    static const locale& classic();
+};
+
+template <class Facet> const Facet& use_facet(const locale&);
+template <class Facet> bool has_facet(const locale&) throw();
+
+// 22.3.3, convenience interfaces:
+template <class charT> bool isspace (charT c, const locale& loc);
+template <class charT> bool isprint (charT c, const locale& loc);
+template <class charT> bool iscntrl (charT c, const locale& loc);
+template <class charT> bool isupper (charT c, const locale& loc);
+template <class charT> bool islower (charT c, const locale& loc);
+template <class charT> bool isalpha (charT c, const locale& loc);
+template <class charT> bool isdigit (charT c, const locale& loc);
+template <class charT> bool ispunct (charT c, const locale& loc);
+template <class charT> bool isxdigit(charT c, const locale& loc);
+template <class charT> bool isalnum (charT c, const locale& loc);
+template <class charT> bool isgraph (charT c, const locale& loc);
+template <class charT> charT toupper(charT c, const locale& loc);
+template <class charT> charT tolower(charT c, const locale& loc);
+template <class Codecvt, class Elem = wchar_t> class wstring_convert;
+template <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>>
+  class wbuffer_convert;
+
+// 22.4.1 and 22.4.1.3, ctype:
+class ctype_base;
+template <class charT> class ctype;
+template <> class ctype<char>; // specialization
+template <class charT> class ctype_byname;
+template <> class ctype_byname<char>; // specialization
+
+class codecvt_base;
+template <class internT, class externT, class stateT> class codecvt;
+template <class internT, class externT, class stateT> class codecvt_byname;
+
+// 22.4.2 and 22.4.3, numeric:
+template <class charT, class InputIterator> class num_get;
+template <class charT, class OutputIterator> class num_put;
+template <class charT> class numpunct;
+template <class charT> class numpunct_byname;
+
+// 22.4.4, col lation:
+template <class charT> class collate;
+template <class charT> class collate_byname;
+
+// 22.4.5, date and time:
+class time_base;
+template <class charT, class InputIterator> class time_get;
+template <class charT, class InputIterator> class time_get_byname;
+template <class charT, class OutputIterator> class time_put;
+template <class charT, class OutputIterator> class time_put_byname;
+
+// 22.4.6, money:
+class money_base;
+template <class charT, class InputIterator> class money_get;
+template <class charT, class OutputIterator> class money_put;
+template <class charT, bool Intl> class moneypunct;
+template <class charT, bool Intl> class moneypunct_byname;
+
+// 22.4.7, message retrieval:
+class messages_base;
+template <class charT> class messages;
+template <class charT> class messages_byname;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__locale>
+#include <algorithm>
+#include <memory>
+#include <ios>
+#include <streambuf>
+#include <iterator>
+#include <limits>
+#include <cstdlib>
+#include <ctime>
+#include <nl_types.h>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// __scan_keyword
+// Scans [__b, __e) until a match is found in the basic_strings range
+//  [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
+//  __b will be incremented (visibly), consuming CharT until a match is found
+//  or proved to not exist.  A keyword may be "", in which will match anything.
+//  If one keyword is a prefix of another, and the next CharT in the input
+//  might match another keyword, the algorithm will attempt to find the longest
+//  matching keyword.  If the longer matching keyword ends up not matching, then
+//  no keyword match is found.  If no keyword match is found, __ke is returned
+//  and failbit is set in __err.
+//  Else an iterator pointing to the matching keyword is found.  If more than
+//  one keyword matches, an iterator to the first matching keyword is returned.
+//  If on exit __b == __e, eofbit is set in __err.  If __case_senstive is false,
+//  __ct is used to force to lower case before comparing characters.
+//  Examples:
+//  Keywords:  "a", "abb"
+//  If the input is "a", the first keyword matches and eofbit is set.
+//  If the input is "abc", no match is found and "ab" are consumed.
+template <class _InputIterator, class _ForwardIterator, class _Ctype>
+_LIBCPP_HIDDEN
+_ForwardIterator
+__scan_keyword(_InputIterator& __b, _InputIterator __e,
+               _ForwardIterator __kb, _ForwardIterator __ke,
+               const _Ctype& __ct, ios_base::iostate& __err,
+               bool __case_sensitive = true)
+{
+    typedef typename iterator_traits<_InputIterator>::value_type _CharT;
+    size_t __nkw = _STD::distance(__kb, __ke);
+    const unsigned char __doesnt_match = '\0';
+    const unsigned char __might_match = '\1';
+    const unsigned char __does_match = '\2';
+    unsigned char __statbuf[100];
+    unsigned char* __status = __statbuf;
+    unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free);
+    if (__nkw > sizeof(__statbuf))
+    {
+        __status = (unsigned char*)malloc(__nkw);
+        if (__status == 0)
+            __throw_bad_alloc();
+        __stat_hold.reset(__status);
+    }
+    size_t __n_might_match = __nkw;  // At this point, any keyword might match
+    size_t __n_does_match = 0;       // but none of them definitely do
+    // Initialize all statuses to __might_match, except for "" keywords are __does_match
+    unsigned char* __st = __status;
+    for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+    {
+        if (!__ky->empty())
+            *__st = __might_match;
+        else
+        {
+            *__st = __does_match;
+            --__n_might_match;
+            ++__n_does_match;
+        }
+    }
+    // While there might be a match, test keywords against the next CharT
+    for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx)
+    {
+        // Peek at the next CharT but don't consume it
+        _CharT __c = *__b;
+        if (!__case_sensitive)
+            __c = __ct.toupper(__c);
+        bool __consume = false;
+        // For each keyword which might match, see if the __indx character is __c
+        // If a match if found, consume __c
+        // If a match is found, and that is the last character in the keyword,
+        //    then that keyword matches.
+        // If the keyword doesn't match this character, then change the keyword
+        //    to doesn't match
+        __st = __status;
+        for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+        {
+            if (*__st == __might_match)
+            {
+                _CharT __kc = (*__ky)[__indx];
+                if (!__case_sensitive)
+                    __kc = __ct.toupper(__kc);
+                if (__c == __kc)
+                {
+                    __consume = true;
+                    if (__ky->size() == __indx+1)
+                    {
+                        *__st = __does_match;
+                        --__n_might_match;
+                        ++__n_does_match;
+                    }
+                }
+                else
+                {
+                    *__st = __doesnt_match;
+                    --__n_might_match;
+                }
+            }
+        }
+        // consume if we matched a character
+        if (__consume)
+        {
+            ++__b;
+            // If we consumed a character and there might be a matched keyword that
+            //   was marked matched on a previous iteration, then such keywords
+            //   which are now marked as not matching.
+            if (__n_might_match + __n_does_match > 1)
+            {
+                __st = __status;
+                for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+                {
+                    if (*__st == __does_match && __ky->size() != __indx+1)
+                    {
+                        *__st = __doesnt_match;
+                        --__n_does_match;
+                    }
+                }
+            }
+        }
+    }
+    // We've exited the loop because we hit eof and/or we have no more "might matches".
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    // Return the first matching result
+    for (__st = __status; __kb != __ke; ++__kb, ++__st)
+        if (*__st == __does_match)
+            break;
+    if (__kb == __ke)
+        __err |= ios_base::failbit;
+    return __kb;
+}
+
+struct __num_get_base
+{
+    static const int __num_get_buf_sz = 40;
+
+    static int __get_base(ios_base&);
+    static const char __src[33];
+};
+
+void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
+                      ios_base::iostate& __err);
+
+
+template <class _CharT>
+struct __num_get
+    : protected __num_get_base
+{
+    static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
+    static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
+                                      _CharT& __thousands_sep);
+    static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
+                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
+                  unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
+    static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
+                                   char* __a, char*& __a_end,
+                                   _CharT __decimal_point, _CharT __thousands_sep,
+                                   const string& __grouping, unsigned* __g,
+                                   unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
+};
+
+template <class _CharT>
+string
+__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
+{
+    locale __loc = __iob.getloc();
+    use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms);
+    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
+    __thousands_sep = __np.thousands_sep();
+    return __np.grouping();
+}
+
+template <class _CharT>
+string
+__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
+                    _CharT& __thousands_sep)
+{
+    locale __loc = __iob.getloc();
+    use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms);
+    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
+    __decimal_point = __np.decimal_point();
+    __thousands_sep = __np.thousands_sep();
+    return __np.grouping();
+}
+
+template <class _CharT>
+int
+__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
+                  unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
+                  unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
+{
+    if (__ct == __thousands_sep && __grouping.size() != 0)
+    {
+        if (__g_end-__g < __num_get_buf_sz)
+        {
+            *__g_end++ = __dc;
+            __dc = 0;
+        }
+        return 0;
+    }
+    ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms;
+    if (__f >= 26)
+        return -1;
+    if (__a_end-__a < __num_get_buf_sz - 1)
+        *__a_end++ = __src[__f];
+    switch (__base)
+    {
+    case 8:
+    case 10:
+        if (__f >= __base)
+            return 0;
+        break;
+    default:
+        if (__f >= 22)
+            return 0;
+        break;
+    }
+    ++__dc;
+    return 0;
+}
+
+template <class _CharT>
+int
+__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end,
+                    _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping,
+                    unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms)
+{
+    if (__ct == __decimal_point)
+    {
+        if (!__in_units)
+            return -1;
+        __in_units = false;
+        *__a_end++ = '.';
+        if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
+            *__g_end++ = __dc;
+        return 0;
+    }
+    if (__ct == __thousands_sep && __grouping.size() != 0)
+    {
+        if (!__in_units)
+            return -1;
+        if (__g_end-__g < __num_get_buf_sz)
+        {
+            *__g_end++ = __dc;
+            __dc = 0;
+        }
+        return 0;
+    }
+    ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms;
+    if (__f >= 32)
+        return -1;
+    char __x = __src[__f];
+    if (__a_end-__a < __num_get_buf_sz - 1)
+        *__a_end++ = __x;
+    if (__x == 'x' || __x == 'X')
+        __exp = 'P';
+    else if ((__x & 0xDF) == __exp)
+    {
+        __in_units = false;
+        if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
+            *__g_end++ = __dc;
+    }
+    if (__f >= 22)
+        return 0;
+    ++__dc;
+    return 0;
+}
+
+extern template class __num_get<char>;
+extern template class __num_get<wchar_t>;
+
+template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
+class num_get
+    : public locale::facet,
+      private __num_get<_CharT>
+{
+public:
+    typedef _CharT char_type;
+    typedef _InputIterator iter_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit num_get(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, bool& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, long& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, long long& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, unsigned short& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, unsigned int& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, unsigned long& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, unsigned long long& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, float& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, double& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, long double& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, void*& __v) const
+    {
+        return do_get(__b, __e, __iob, __err, __v);
+    }
+
+    static locale::id id;
+
+protected:
+    ~num_get() {}
+
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, bool& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, long& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, long long& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, unsigned short& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, unsigned int& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, unsigned long& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, unsigned long long& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, float& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, double& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, long double& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, void*& __v) const;
+};
+
+template <class _CharT, class _InputIterator>
+locale::id
+num_get<_CharT, _InputIterator>::id;
+
+template <class _Tp>
+_Tp
+__num_get_signed_integral(const char* __a, const char* __a_end,
+                          ios_base::iostate& __err, int __base)
+{
+    if (__a != __a_end)
+    {
+        char *__p2;
+        long long __ll = strtoll_l(__a, &__p2, __base, 0);
+        if (__p2 != __a_end)
+        {
+            __err = ios_base::failbit;
+            return 0;
+        }
+        else if (__ll > numeric_limits<_Tp>::max())
+        {
+            __err = ios_base::failbit;
+            return numeric_limits<_Tp>::max();
+        }
+        else if (__ll < numeric_limits<_Tp>::min())
+        {
+            __err = ios_base::failbit;
+            return numeric_limits<_Tp>::min();
+        }
+        return static_cast<_Tp>(__ll);
+    }
+    __err = ios_base::failbit;
+    return 0;
+}
+
+template <class _Tp>
+_Tp
+__num_get_unsigned_integral(const char* __a, const char* __a_end,
+                            ios_base::iostate& __err, int __base)
+{
+    if (__a != __a_end)
+    {
+        char *__p2;
+        unsigned long long __ll = strtoull_l(__a, &__p2, __base, 0);
+        if (__p2 != __a_end)
+        {
+            __err = ios_base::failbit;
+            return 0;
+        }
+        else if (__ll > numeric_limits<_Tp>::max())
+        {
+            __err = ios_base::failbit;
+            return numeric_limits<_Tp>::max();
+        }
+        return static_cast<_Tp>(__ll);
+    }
+    __err = ios_base::failbit;
+    return 0;
+}
+
+template <class _Tp>
+_Tp
+__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err)
+{
+    if (__a != __a_end)
+    {
+        char *__p2;
+        long double __ld = strtold_l(__a, &__p2, 0);
+        if (__p2 != __a_end)
+        {
+            __err = ios_base::failbit;
+            return 0;
+        }
+        return static_cast<_Tp>(__ld);
+    }
+    __err = ios_base::failbit;
+    return 0;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        bool& __v) const
+{
+    if ((__iob.flags() & ios_base::boolalpha) == 0)
+    {
+        long __lv = -1;
+        __b = do_get(__b, __e, __iob, __err, __lv);
+        switch (__lv)
+        {
+        case 0:
+            __v = false;
+            break;
+        case 1:
+            __v = true;
+            break;
+        default:
+            __v = true;
+            __err = ios_base::failbit;
+            break;
+        }
+        return __b;
+    }
+    const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc());
+    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc());
+    typedef typename numpunct<_CharT>::string_type string_type;
+    const string_type __names[2] = {__np.truename(), __np.falsename()};
+    const string_type* __i = __scan_keyword(__b, __e, __names, __names+2,
+                                            __ct, __err);
+    __v = __i == __names;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        long& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end,
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_signed_integral<long>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        long long& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end, 
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_signed_integral<long long>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        unsigned short& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end,
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_unsigned_integral<unsigned short>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        unsigned int& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end,
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_unsigned_integral<unsigned int>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        unsigned long& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end,
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_unsigned_integral<unsigned long>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        unsigned long long& __v) const
+{
+    // Stage 1
+    int __base = this->__get_base(__iob);
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, __g, __g_end,
+                                    __atoms))
+            break;
+    if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_unsigned_integral<unsigned long long>(__a, __a_end, __err, __base);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        float& __v) const
+{
+    // Stage 1, nothing to do
+    // Stage 2
+    char_type __atoms[32];
+    char_type __decimal_point;
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_float_prep(__iob, __atoms, 
+                                                  __decimal_point, 
+                                                  __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    bool __in_units = true;
+    char __exp = 'E';
+    for (; __b != __e; ++__b)
+        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 
+                                      __decimal_point, __thousands_sep, 
+                                      __grouping, __g, __g_end,
+                                      __dc, __atoms))
+            break;
+    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_float<float>(__a, __a_end, __err);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        double& __v) const
+{
+    // Stage 1, nothing to do
+    // Stage 2
+    char_type __atoms[32];
+    char_type __decimal_point;
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_float_prep(__iob, __atoms, 
+                                                  __decimal_point, 
+                                                  __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    bool __in_units = true;
+    char __exp = 'E';
+    for (; __b != __e; ++__b)
+        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 
+                                      __decimal_point, __thousands_sep, 
+                                      __grouping, __g, __g_end,
+                                      __dc, __atoms))
+            break;
+    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_float<double>(__a, __a_end, __err);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        long double& __v) const
+{
+    // Stage 1, nothing to do
+    // Stage 2
+    char_type __atoms[32];
+    char_type __decimal_point;
+    char_type __thousands_sep;
+    string __grouping = this->__stage2_float_prep(__iob, __atoms, 
+                                                  __decimal_point,
+                                                  __thousands_sep);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    bool __in_units = true;
+    char __exp = 'E';
+    for (; __b != __e; ++__b)
+        if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 
+                                      __decimal_point, __thousands_sep, 
+                                      __grouping, __g, __g_end,
+                                      __dc, __atoms))
+            break;
+    if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
+        *__g_end++ = __dc;
+    // Stage 3
+    __v = __num_get_float<long double>(__a, __a_end, __err);
+    // Digit grouping checked
+    __check_grouping(__grouping, __g, __g_end, __err);
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                        ios_base& __iob,
+                                        ios_base::iostate& __err,
+                                        void*& __v) const
+{
+    // Stage 1
+    int __base = 16;
+    // Stage 2
+    char_type __atoms[26];
+    char_type __thousands_sep;
+    string __grouping;
+    use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
+                                                    __num_get_base::__src + 26, __atoms);
+    char __a[__num_get_base::__num_get_buf_sz] = {0};
+    char* __a_end = __a;
+    unsigned __g[__num_get_base::__num_get_buf_sz];
+    unsigned* __g_end = __g;
+    unsigned __dc = 0;
+    for (; __b != __e; ++__b)
+        if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 
+                                    __thousands_sep, __grouping, 
+                                    __g, __g_end, __atoms))
+            break;
+    // Stage 3
+    __a[sizeof(__a)-1] = 0;
+    if (sscanf_l(__a, 0, "%p", &__v) != 1)
+        __err = ios_base::failbit;
+    // EOF checked
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+extern template class num_get<char>;
+extern template class num_get<wchar_t>;
+
+struct __num_put_base
+{
+protected:
+    static void __format_int(char* __fmt, const char* __len, bool __signd,
+                             ios_base::fmtflags __flags);
+    static bool __format_float(char* __fmt, const char* __len,
+                               ios_base::fmtflags __flags);
+    static char* __identify_padding(char* __nb, char* __ne,
+                                    const ios_base& __iob);
+};
+
+template <class _CharT>
+struct __num_put
+    : protected __num_put_base
+{
+    static void __widen_and_group_int(char* __nb, char* __np, char* __ne,
+                                      _CharT* __ob, _CharT*& __op, _CharT*& __oe,
+                                      const locale& __loc);
+    static void __widen_and_group_float(char* __nb, char* __np, char* __ne,
+                                        _CharT* __ob, _CharT*& __op, _CharT*& __oe,
+                                        const locale& __loc);
+};
+
+template <class _CharT>
+void
+__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne,
+                                         _CharT* __ob, _CharT*& __op, _CharT*& __oe,
+                                         const locale& __loc)
+{
+    const ctype<_CharT>&    __ct = use_facet<ctype<_CharT> >   (__loc);
+    const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
+    string __grouping = __npt.grouping();
+    if (__grouping.empty())
+    {
+        __ct.widen(__nb, __ne, __ob);
+        __oe = __ob + (__ne - __nb);
+    }
+    else
+    {
+        __oe = __ob;
+        char* __nf = __nb;
+        if (*__nf == '-' || *__nf == '+')
+            *__oe++ = __ct.widen(*__nf++);
+        if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
+                                                   __nf[1] == 'X'))
+        {
+            *__oe++ = __ct.widen(*__nf++);
+            *__oe++ = __ct.widen(*__nf++);
+        }
+        reverse(__nf, __ne);
+        _CharT __thousands_sep = __npt.thousands_sep();
+        unsigned __dc = 0;
+        unsigned __dg = 0;
+        for (char* __p = __nf; __p < __ne; ++__p)
+        {
+            if (static_cast<unsigned>(__grouping[__dg]) > 0 &&
+                __dc == static_cast<unsigned>(__grouping[__dg]))
+            {
+                *__oe++ = __thousands_sep;
+                __dc = 0;
+                if (__dg < __grouping.size()-1)
+                    ++__dg;
+            }
+            *__oe++ = __ct.widen(*__p);
+            ++__dc;
+        }
+        reverse(__ob + (__nf - __nb), __oe);
+    }
+    if (__np == __ne)
+        __op = __oe;
+    else
+        __op = __ob + (__np - __nb);
+}
+
+template <class _CharT>
+void
+__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
+                                           _CharT* __ob, _CharT*& __op, _CharT*& __oe,
+                                           const locale& __loc)
+{
+    const ctype<_CharT>&    __ct = use_facet<ctype<_CharT> >   (__loc);
+    const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
+    string __grouping = __npt.grouping();
+    __oe = __ob;
+    char* __nf = __nb;
+    if (*__nf == '-' || *__nf == '+')
+        *__oe++ = __ct.widen(*__nf++);
+    char* __ns;
+    if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
+                                               __nf[1] == 'X'))
+    {
+        *__oe++ = __ct.widen(*__nf++);
+        *__oe++ = __ct.widen(*__nf++);
+        for (__ns = __nf; __ns < __ne; ++__ns)
+            if (!isxdigit_l(*__ns, 0))
+                break;
+    }
+    else
+    {
+        for (__ns = __nf; __ns < __ne; ++__ns)
+            if (!isdigit_l(*__ns, 0))
+                break;
+    }
+    if (__grouping.empty())
+    {
+        __ct.widen(__nf, __ns, __oe);
+        __oe += __ns - __nf;
+    }
+    else
+    {
+        reverse(__nf, __ns);
+        _CharT __thousands_sep = __npt.thousands_sep();
+        unsigned __dc = 0;
+        unsigned __dg = 0;
+        for (char* __p = __nf; __p < __ns; ++__p)
+        {
+            if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg]))
+            {
+                *__oe++ = __thousands_sep;
+                __dc = 0;
+                if (__dg < __grouping.size()-1)
+                    ++__dg;
+            }
+            *__oe++ = __ct.widen(*__p);
+            ++__dc;
+        }
+        reverse(__ob + (__nf - __nb), __oe);
+    }
+    for (__nf = __ns; __nf < __ne; ++__nf)
+    {
+        if (*__nf == '.')
+        {
+            *__oe++ = __npt.decimal_point();
+            ++__nf;
+            break;
+        }
+        else
+            *__oe++ = __ct.widen(*__nf);
+    }
+    __ct.widen(__nf, __ne, __oe);
+    __oe += __ne - __nf;
+    if (__np == __ne)
+        __op = __oe;
+    else
+        __op = __ob + (__np - __nb);
+}
+
+extern template class __num_put<char>;
+extern template class __num_put<wchar_t>;
+
+template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
+class num_put
+    : public locale::facet,
+      private __num_put<_CharT>
+{
+public:
+    typedef _CharT char_type;
+    typedef _OutputIterator iter_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit num_put(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  bool __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  long __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  long long __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  unsigned long __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  unsigned long long __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  double __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  long double __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  const void* __v) const
+    {
+        return do_put(__s, __iob, __fl, __v);
+    }
+
+    static locale::id id;
+
+protected:
+    ~num_put() {}
+
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             bool __v) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             long __v) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             long long __v) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             unsigned long) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             unsigned long long) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             double __v) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             long double __v) const;
+    virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
+                             const void* __v) const;
+};
+
+template <class _CharT, class _OutputIterator>
+locale::id
+num_put<_CharT, _OutputIterator>::id;
+
+template <class _CharT, class _OutputIterator>
+_LIBCPP_HIDDEN
+_OutputIterator
+__pad_and_output(_OutputIterator __s,
+                 const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
+                 ios_base& __iob, _CharT __fl)
+{
+    streamsize __sz = __oe - __ob;
+    streamsize __ns = __iob.width();
+    if (__ns > __sz)
+        __ns -= __sz;
+    else
+        __ns = 0;
+    for (;__ob < __op; ++__ob, ++__s)
+        *__s = *__ob;
+    for (; __ns; --__ns, ++__s)
+        *__s = __fl;
+    for (; __ob < __oe; ++__ob, ++__s)
+        *__s = *__ob;
+    __iob.width(0);
+    return __s;
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, bool __v) const
+{
+    if ((__iob.flags() & ios_base::boolalpha) == 0)
+        return do_put(__s, __iob, __fl, (unsigned long)__v);
+    const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc());
+    typedef typename numpunct<char_type>::string_type string_type;
+    string_type __nm = __v ? __np.truename() : __np.falsename();
+    for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
+        *__s = *__i;
+    return __s;
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, long __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[6] = {'%', 0};
+    const char* __len = "l";
+    this->__format_int(__fmt+1, __len, true, __iob.flags());
+    const unsigned __nbuf = (numeric_limits<long>::digits / 3)
+                          + ((numeric_limits<long>::digits % 3) != 0)
+                          + 1;
+    char __nar[__nbuf];
+    int __nc = sprintf_l(__nar, 0, __fmt, __v);
+    char* __ne = __nar + __nc;
+    char* __np = this->__identify_padding(__nar, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, long long __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[8] = {'%', 0};
+    const char* __len = "ll";
+    this->__format_int(__fmt+1, __len, true, __iob.flags());
+    const unsigned __nbuf = (numeric_limits<long long>::digits / 3)
+                          + ((numeric_limits<long long>::digits % 3) != 0)
+                          + 1;
+    char __nar[__nbuf];
+    int __nc = sprintf_l(__nar, 0, __fmt, __v);
+    char* __ne = __nar + __nc;
+    char* __np = this->__identify_padding(__nar, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, unsigned long __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[6] = {'%', 0};
+    const char* __len = "l";
+    this->__format_int(__fmt+1, __len, false, __iob.flags());
+    const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3)
+                          + ((numeric_limits<unsigned long>::digits % 3) != 0)
+                          + 1;
+    char __nar[__nbuf];
+    int __nc = sprintf_l(__nar, 0, __fmt, __v);
+    char* __ne = __nar + __nc;
+    char* __np = this->__identify_padding(__nar, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, unsigned long long __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[8] = {'%', 0};
+    const char* __len = "ll";
+    this->__format_int(__fmt+1, __len, false, __iob.flags());
+    const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3)
+                          + ((numeric_limits<unsigned long long>::digits % 3) != 0)
+                          + 1;
+    char __nar[__nbuf];
+    int __nc = sprintf_l(__nar, 0, __fmt, __v);
+    char* __ne = __nar + __nc;
+    char* __np = this->__identify_padding(__nar, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, double __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[8] = {'%', 0};
+    const char* __len = "";
+    bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
+    const unsigned __nbuf = 30;
+    char __nar[__nbuf];
+    char* __nb = __nar;
+    int __nc;
+    if (__specify_precision)
+        __nc = snprintf_l(__nb, __nbuf, 0, __fmt, (int)__iob.precision(), __v);
+    else
+        __nc = snprintf_l(__nb, __nbuf, 0, __fmt, __v);
+    unique_ptr<char, void(*)(void*)> __nbh(0, free);
+    if (__nc > static_cast<int>(__nbuf-1))
+    {
+        if (__specify_precision)
+            __nc = asprintf_l(&__nb, 0, __fmt, (int)__iob.precision(), __v);
+        else
+            __nc = asprintf_l(&__nb, 0, __fmt, __v);
+        if (__nb == 0)
+            __throw_bad_alloc();
+        __nbh.reset(__nb);
+    }
+    char* __ne = __nb + __nc;
+    char* __np = this->__identify_padding(__nb, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __ob = __o;
+    unique_ptr<char_type, void(*)(void*)> __obh(0, free);
+    if (__nb != __nar)
+    {
+        __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+        if (__ob == 0)
+            __throw_bad_alloc();
+        __obh.reset(__ob);
+    }
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
+    return __s;
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, long double __v) const
+{
+    // Stage 1 - Get number in narrow char
+    char __fmt[8] = {'%', 0};
+    const char* __len = "L";
+    bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
+    const unsigned __nbuf = 30;
+    char __nar[__nbuf];
+    char* __nb = __nar;
+    int __nc;
+    if (__specify_precision)
+        __nc = snprintf_l(__nb, __nbuf, 0, __fmt, (int)__iob.precision(), __v);
+    else
+        __nc = snprintf_l(__nb, __nbuf, 0, __fmt, __v);
+    unique_ptr<char, void(*)(void*)> __nbh(0, free);
+    if (__nc > static_cast<int>(__nbuf-1))
+    {
+        if (__specify_precision)
+            __nc = asprintf_l(&__nb, 0, __fmt, (int)__iob.precision(), __v);
+        else
+            __nc = asprintf_l(&__nb, 0, __fmt, __v);
+        if (__nb == 0)
+            __throw_bad_alloc();
+        __nbh.reset(__nb);
+    }
+    char* __ne = __nb + __nc;
+    char* __np = this->__identify_padding(__nb, __ne, __iob);
+    // Stage 2 - Widen __nar while adding thousands separators
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __ob = __o;
+    unique_ptr<char_type, void(*)(void*)> __obh(0, free);
+    if (__nb != __nar)
+    {
+        __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+        if (__ob == 0)
+            __throw_bad_alloc();
+        __obh.reset(__ob);
+    }
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
+    // [__o, __oe) contains thousands_sep'd wide number
+    // Stage 3 & 4
+    __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
+    return __s;
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                         char_type __fl, const void* __v) const
+{
+    // Stage 1 - Get pointer in narrow char
+    char __fmt[6] = "%p";
+    const unsigned __nbuf = 20;
+    char __nar[__nbuf];
+    int __nc = sprintf_l(__nar, 0, __fmt, __v);
+    char* __ne = __nar + __nc;
+    char* __np = this->__identify_padding(__nar, __ne, __iob);
+    // Stage 2 - Widen __nar
+    char_type __o[2*(__nbuf-1) - 1];
+    char_type* __op;  // pad here
+    char_type* __oe;  // end of output
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    __ct.widen(__nar, __ne, __o);
+    __oe = __o + (__ne - __nar);
+    if (__np == __ne)
+        __op = __oe;
+    else
+        __op = __o + (__np - __nar);
+    // [__o, __oe) contains wide number
+    // Stage 3 & 4
+    return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
+}
+
+extern template class num_put<char>;
+extern template class num_put<wchar_t>;
+
+template <class _CharT, class _InputIterator>
+_LIBCPP_HIDDEN
+int
+__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e,
+                     ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n)
+{
+    // Precondition:  __n >= 1
+    if (__b == __e)
+    {
+        __err |= ios_base::eofbit | ios_base::failbit;
+        return 0;
+    }
+    // get first digit
+    _CharT __c = *__b;
+    if (!__ct.is(ctype_base::digit, __c))
+    {
+        __err |= ios_base::failbit;
+        return 0;
+    }
+    int __r = __ct.narrow(__c, 0) - '0';
+    for (++__b, --__n; __b != __e && __n > 0; ++__b, --__n)
+    {
+        // get next digit
+        __c = *__b;
+        if (!__ct.is(ctype_base::digit, __c))
+            return __r;
+        __r = __r * 10 + __ct.narrow(__c, 0) - '0';
+    }
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __r;
+}
+
+class time_base
+{
+public:
+    enum dateorder {no_order, dmy, mdy, ymd, ydm};
+};
+
+template <class _CharT>
+class __time_get_c_storage
+{
+protected:
+    typedef basic_string<_CharT> string_type;
+
+    virtual const string_type* __weeks() const;
+    virtual const string_type* __months() const;
+    virtual const string_type* __am_pm() const;
+    virtual const string_type& __c() const;
+    virtual const string_type& __r() const;
+    virtual const string_type& __x() const;
+    virtual const string_type& __X() const;
+};
+
+template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
+class time_get
+    : public locale::facet,
+      public time_base,
+      private __time_get_c_storage<_CharT>
+{
+public:
+    typedef _CharT                  char_type;
+    typedef _InputIterator          iter_type;
+    typedef time_base::dateorder    dateorder;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit time_get(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    dateorder date_order() const
+    {
+        return this->do_date_order();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob,
+                       ios_base::iostate& __err, tm* __tm) const
+    {
+        return do_get_time(__b, __e, __iob, __err, __tm);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob,
+                       ios_base::iostate& __err, tm* __tm) const
+    {
+        return do_get_date(__b, __e, __iob, __err, __tm);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
+                          ios_base::iostate& __err, tm* __tm) const
+    {
+        return do_get_weekday(__b, __e, __iob, __err, __tm);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
+                            ios_base::iostate& __err, tm* __tm) const
+    {
+        return do_get_monthname(__b, __e, __iob, __err, __tm);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob,
+                       ios_base::iostate& __err, tm* __tm) const
+    {
+        return do_get_year(__b, __e, __iob, __err, __tm);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, tm *__tm,
+                  char __fmt, char __mod = 0) const
+    {
+        return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
+    }
+
+    iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
+                  ios_base::iostate& __err, tm* __tm,
+                  const char_type* __fmtb, const char_type* __fmte) const;
+
+    static locale::id id;
+
+protected:
+    ~time_get() {}
+
+    virtual dateorder do_date_order() const;
+    virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob,
+                                  ios_base::iostate& __err, tm* __tm) const;
+    virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob,
+                                  ios_base::iostate& __err, tm* __tm) const;
+    virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
+                                     ios_base::iostate& __err, tm* __tm) const;
+    virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
+                                       ios_base::iostate& __err, tm* __tm) const;
+    virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob,
+                                  ios_base::iostate& __err, tm* __tm) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
+                             ios_base::iostate& __err, tm* __tm,
+                             char __fmt, char __mod) const;
+private:
+    void __get_white_space(iter_type& __b, iter_type __e,
+                           ios_base::iostate& __err, const ctype<char_type>& __ct) const;
+    void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err,
+                       const ctype<char_type>& __ct) const;
+
+    void __get_weekdayname(int& __m,
+                           iter_type& __b, iter_type __e,
+                           ios_base::iostate& __err,
+                           const ctype<char_type>& __ct) const;
+    void __get_monthname(int& __m,
+                         iter_type& __b, iter_type __e,
+                         ios_base::iostate& __err,
+                         const ctype<char_type>& __ct) const;
+    void __get_day(int& __d,
+                   iter_type& __b, iter_type __e,
+                   ios_base::iostate& __err,
+                   const ctype<char_type>& __ct) const;
+    void __get_month(int& __m,
+                     iter_type& __b, iter_type __e,
+                     ios_base::iostate& __err,
+                     const ctype<char_type>& __ct) const;
+    void __get_year(int& __y,
+                   iter_type& __b, iter_type __e,
+                   ios_base::iostate& __err,
+                   const ctype<char_type>& __ct) const;
+    void __get_year4(int& __y,
+                    iter_type& __b, iter_type __e,
+                    ios_base::iostate& __err,
+                    const ctype<char_type>& __ct) const;
+    void __get_hour(int& __d,
+                    iter_type& __b, iter_type __e,
+                    ios_base::iostate& __err,
+                    const ctype<char_type>& __ct) const;
+    void __get_12_hour(int& __h,
+                       iter_type& __b, iter_type __e,
+                       ios_base::iostate& __err,
+                       const ctype<char_type>& __ct) const;
+    void __get_am_pm(int& __h,
+                     iter_type& __b, iter_type __e,
+                     ios_base::iostate& __err,
+                     const ctype<char_type>& __ct) const;
+    void __get_minute(int& __m,
+                      iter_type& __b, iter_type __e,
+                      ios_base::iostate& __err,
+                      const ctype<char_type>& __ct) const;
+    void __get_second(int& __s,
+                      iter_type& __b, iter_type __e,
+                      ios_base::iostate& __err,
+                      const ctype<char_type>& __ct) const;
+    void __get_weekday(int& __w,
+                       iter_type& __b, iter_type __e,
+                       ios_base::iostate& __err,
+                       const ctype<char_type>& __ct) const;
+    void __get_day_year_num(int& __w,
+                            iter_type& __b, iter_type __e,
+                            ios_base::iostate& __err,
+                            const ctype<char_type>& __ct) const;
+};
+
+template <class _CharT, class _InputIterator>
+locale::id
+time_get<_CharT, _InputIterator>::id;
+
+// time_get primatives
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w,
+                                                    iter_type& __b, iter_type __e,
+                                                    ios_base::iostate& __err,
+                                                    const ctype<char_type>& __ct) const
+{
+    // Note:  ignoring case comes from the POSIX strptime spec
+    const string_type* __wk = this->__weeks();
+    int __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
+    if (__i < 14)
+        __w = __i % 7;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_monthname(int& __m,
+                                                  iter_type& __b, iter_type __e,
+                                                  ios_base::iostate& __err,
+                                                  const ctype<char_type>& __ct) const
+{
+    // Note:  ignoring case comes from the POSIX strptime spec
+    const string_type* __month = this->__months();
+    int __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
+    if (__i < 24)
+        __m = __i % 12;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_day(int& __d,
+                                            iter_type& __b, iter_type __e,
+                                            ios_base::iostate& __err,
+                                            const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
+    if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
+        __d = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_month(int& __m,
+                                              iter_type& __b, iter_type __e,
+                                              ios_base::iostate& __err,
+                                              const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
+    if (!(__err & ios_base::failbit) && __t <= 11)
+        __m = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_year(int& __y,
+                                             iter_type& __b, iter_type __e,
+                                             ios_base::iostate& __err,
+                                             const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
+    if (!(__err & ios_base::failbit))
+    {
+        if (__t < 69)
+            __t += 2000;
+        else if (69 <= __t && __t <= 99)
+            __t += 1900;
+        __y = __t - 1900;
+    }
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_year4(int& __y,
+                                              iter_type& __b, iter_type __e,
+                                              ios_base::iostate& __err,
+                                              const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
+    if (!(__err & ios_base::failbit))
+        __y = __t - 1900;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_hour(int& __h,
+                                             iter_type& __b, iter_type __e,
+                                             ios_base::iostate& __err,
+                                             const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
+    if (!(__err & ios_base::failbit) && __t <= 23)
+        __h = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_12_hour(int& __h,
+                                                iter_type& __b, iter_type __e,
+                                                ios_base::iostate& __err,
+                                                const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
+    if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
+        __h = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_minute(int& __m,
+                                               iter_type& __b, iter_type __e,
+                                               ios_base::iostate& __err,
+                                               const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
+    if (!(__err & ios_base::failbit) && __t <= 59)
+        __m = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_second(int& __s,
+                                               iter_type& __b, iter_type __e,
+                                               ios_base::iostate& __err,
+                                               const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
+    if (!(__err & ios_base::failbit) && __t <= 60)
+        __s = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_weekday(int& __w,
+                                                iter_type& __b, iter_type __e,
+                                                ios_base::iostate& __err,
+                                                const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1);
+    if (!(__err & ios_base::failbit) && __t <= 6)
+        __w = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d,
+                                                     iter_type& __b, iter_type __e,
+                                                     ios_base::iostate& __err,
+                                                     const ctype<char_type>& __ct) const
+{
+    int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3);
+    if (!(__err & ios_base::failbit) && __t <= 365)
+        __d = __t;
+    else
+        __err |= ios_base::failbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e,
+                                                    ios_base::iostate& __err,
+                                                    const ctype<char_type>& __ct) const
+{
+    for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
+        ;
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_am_pm(int& __h,
+                                              iter_type& __b, iter_type __e,
+                                              ios_base::iostate& __err,
+                                              const ctype<char_type>& __ct) const
+{
+    const string_type* __ap = this->__am_pm();
+    if (__ap[0].size() + __ap[1].size() == 0)
+    {
+        __err |= ios_base::failbit;
+        return;
+    }
+    int __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
+    if (__i == 0 && __h == 12)
+        __h = 0;
+    else if (__i == 1 && __h < 12)
+        __h += 12;
+}
+
+template <class _CharT, class _InputIterator>
+void
+time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e,
+                                                ios_base::iostate& __err,
+                                                const ctype<char_type>& __ct) const
+{
+    if (__b == __e)
+    {
+        __err |= ios_base::eofbit | ios_base::failbit;
+        return;
+    }
+    if (__ct.narrow(*__b, 0) != '%')
+        __err |= ios_base::failbit;
+    else if(++__b == __e)
+        __err |= ios_base::eofbit;
+}
+
+// time_get end primatives
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e,
+                                      ios_base& __iob,
+                                      ios_base::iostate& __err, tm* __tm,
+                                      const char_type* __fmtb, const char_type* __fmte) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    __err = ios_base::goodbit;
+    while (__fmtb != __fmte && __err == ios_base::goodbit)
+    {
+        if (__b == __e)
+        {
+            __err = ios_base::failbit;
+            break;
+        }
+        if (__ct.narrow(*__fmtb, 0) == '%')
+        {
+            if (++__fmtb == __fmte)
+            {
+                __err = ios_base::failbit;
+                break;
+            }
+            char __cmd = __ct.narrow(*__fmtb, 0);
+            char __opt = '\0';
+            if (__cmd == 'E' || __cmd == '0')
+            {
+                if (++__fmtb == __fmte)
+                {
+                    __err = ios_base::failbit;
+                    break;
+                }
+                __opt = __cmd;
+                __cmd = __ct.narrow(*__fmtb, 0);
+            }
+            __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
+            ++__fmtb;
+        }
+        else if (__ct.is(ctype_base::space, *__fmtb))
+        {
+            for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
+                ;
+            for (        ;    __b != __e    && __ct.is(ctype_base::space, *__b);    ++__b)
+                ;
+        }
+        else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb))
+        {
+            ++__b;
+            ++__fmtb;
+        }
+        else
+            __err = ios_base::failbit;
+    }
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+typename time_get<_CharT, _InputIterator>::dateorder
+time_get<_CharT, _InputIterator>::do_date_order() const
+{
+    return mdy;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e,
+                                              ios_base& __iob,
+                                              ios_base::iostate& __err,
+                                              tm* __tm) const
+{
+    const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
+    return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e,
+                                              ios_base& __iob,
+                                              ios_base::iostate& __err,
+                                              tm* __tm) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    const string_type& __fmt = this->__x();
+    return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e,
+                                                 ios_base& __iob,
+                                                 ios_base::iostate& __err,
+                                                 tm* __tm) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e,
+                                                   ios_base& __iob,
+                                                   ios_base::iostate& __err,
+                                                   tm* __tm) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e,
+                                              ios_base& __iob,
+                                              ios_base::iostate& __err,
+                                              tm* __tm) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    __get_year(__tm->tm_year, __b, __e, __err, __ct);
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                         ios_base& __iob,
+                                         ios_base::iostate& __err, tm* __tm,
+                                         char __fmt, char) const
+{
+    __err = ios_base::goodbit;
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    switch (__fmt)
+    {
+    case 'a':
+    case 'A':
+        __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
+        break;
+    case 'b':
+    case 'B':
+    case 'h':
+        __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
+        break;
+    case 'c':
+        {
+        const string_type& __fmt = this->__c();
+        __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+        }
+        break;
+    case 'd':
+    case 'e':
+        __get_day(__tm->tm_mday, __b, __e, __err, __ct);
+        break;
+    case 'D':
+        {
+        const char_type __fmt[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
+        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        }
+        break;
+    case 'H':
+        __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
+        break;
+    case 'I':
+        __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
+        break;
+    case 'j':
+        __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
+        break;
+    case 'm':
+        __get_month(__tm->tm_mon, __b, __e, __err, __ct);
+        break;
+    case 'M':
+        __get_minute(__tm->tm_min, __b, __e, __err, __ct);
+        break;
+    case 'n':
+    case 't':
+        __get_white_space(__b, __e, __err, __ct);
+        break;
+    case 'p':
+        __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
+        break;
+    case 'r':
+        {
+        const char_type __fmt[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
+        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        }
+        break;
+    case 'R':
+        {
+        const char_type __fmt[] = {'%', 'H', ':', '%', 'M'};
+        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        }
+        break;
+    case 'S':
+        __get_second(__tm->tm_sec, __b, __e, __err, __ct);
+        break;
+    case 'T':
+        {
+        const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
+        __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+        }
+        break;
+    case 'w':
+        __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
+        break;
+    case 'x':
+        return do_get_date(__b, __e, __iob, __err, __tm);
+    case 'X':
+        {
+        const string_type& __fmt = this->__X();
+        __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+        }
+        break;
+    case 'y':
+        __get_year(__tm->tm_year, __b, __e, __err, __ct);
+        break;
+    case 'Y':
+        __get_year4(__tm->tm_year, __b, __e, __err, __ct);
+        break;
+    case '%':
+        __get_percent(__b, __e, __err, __ct);
+        break;
+    default:
+        __err |= ios_base::failbit;
+    }
+    return __b;
+}
+
+extern template class time_get<char>;
+extern template class time_get<wchar_t>;
+
+class __time_get
+{
+protected:
+    locale_t __loc_;
+
+    __time_get(const char* __nm);
+    __time_get(const string& __nm);
+    ~__time_get();
+};
+
+template <class _CharT>
+class __time_get_storage
+    : public __time_get
+{
+protected:
+    typedef basic_string<_CharT> string_type;
+
+    string_type __weeks_[14];
+    string_type __months_[24];
+    string_type __am_pm_[2];
+    string_type __c_;
+    string_type __r_;
+    string_type __x_;
+    string_type __X_;
+
+    explicit __time_get_storage(const char* __nm);
+    explicit __time_get_storage(const string& __nm);
+
+    _LIBCPP_ALWAYS_INLINE ~__time_get_storage() {}
+
+    time_base::dateorder __do_date_order() const;
+
+private:
+    void init(const ctype<_CharT>&);
+    string_type __analyze(char __fmt, const ctype<_CharT>&);
+};
+
+template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
+class time_get_byname
+    : public time_get<_CharT, _InputIterator>,
+      private __time_get_storage<_CharT>
+{
+public:
+    typedef time_base::dateorder    dateorder;
+    typedef _InputIterator          iter_type;
+    typedef _CharT                  char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit time_get_byname(const char* __nm, size_t __refs = 0)
+        : time_get<_CharT, _InputIterator>(__refs),
+          __time_get_storage<_CharT>(__nm) {}
+    explicit time_get_byname(const string& __nm, size_t __refs = 0)
+        : time_get<_CharT, _InputIterator>(__refs),
+          __time_get_storage<_CharT>(__nm) {}
+
+protected:
+    ~time_get_byname() {}
+
+    virtual dateorder do_date_order() const {return this->__do_date_order();}
+private:
+    virtual const string_type* __weeks() const  {return this->__weeks_;}
+    virtual const string_type* __months() const {return this->__months_;}
+    virtual const string_type* __am_pm() const  {return this->__am_pm_;}
+    virtual const string_type& __c() const      {return this->__c_;}
+    virtual const string_type& __r() const      {return this->__r_;}
+    virtual const string_type& __x() const      {return this->__x_;}
+    virtual const string_type& __X() const      {return this->__X_;}
+};
+
+extern template class time_get_byname<char>;
+extern template class time_get_byname<wchar_t>;
+
+class __time_put
+{
+    locale_t __loc_;
+protected:
+    _LIBCPP_ALWAYS_INLINE __time_put() : __loc_(0) {}
+    __time_put(const char* __nm);
+    __time_put(const string& __nm);
+    ~__time_put();
+    void __do_put(char* __nb, char*& __ne, const tm* __tm,
+                  char __fmt, char __mod) const;
+    void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
+                  char __fmt, char __mod) const;
+};
+
+template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
+class time_put
+    : public locale::facet,
+      private __time_put
+{
+public:
+    typedef _CharT char_type;
+    typedef _OutputIterator iter_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit time_put(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm,
+                  const char_type* __pb, const char_type* __pe) const;
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
+                  const tm* __tm, char __fmt, char __mod = 0) const
+    {
+        return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
+    }
+
+    static locale::id id;
+
+protected:
+    ~time_put() {}
+    virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm,
+                             char __fmt, char __mod) const;
+
+    explicit time_put(const char* __nm, size_t __refs)
+        : locale::facet(__refs),
+          __time_put(__nm) {}
+    explicit time_put(const string& __nm, size_t __refs)
+        : locale::facet(__refs),
+          __time_put(__nm) {}
+};
+
+template <class _CharT, class _OutputIterator>
+locale::id
+time_put<_CharT, _OutputIterator>::id;
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob,
+                                       char_type __fl, const tm* __tm,
+                                       const char_type* __pb,
+                                       const char_type* __pe) const
+{
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
+    for (; __pb != __pe; ++__pb)
+    {
+        if (__ct.narrow(*__pb, 0) == '%')
+        {
+            if (++__pb == __pe)
+            {
+                *__s++ = __pb[-1];
+                break;
+            }
+            char __mod = 0;
+            char __fmt = __ct.narrow(*__pb, 0);
+            if (__fmt == 'E' || __fmt == 'O')
+            {
+                if (++__pb == __pe)
+                {
+                    *__s++ = __pb[-2];
+                    *__s++ = __pb[-1];
+                    break;
+                }
+                __mod = __fmt;
+                __fmt = __ct.narrow(*__pb, 0);
+            }
+            __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
+        }
+        else
+            *__s++ = *__pb;
+    }
+    return __s;
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+                                          char_type, const tm* __tm,
+                                          char __fmt, char __mod) const
+{
+    char_type __nar[100];
+    char_type* __nb = __nar;
+    char_type* __ne = __nb + 100;
+    __do_put(__nb, __ne, __tm, __fmt, __mod);
+    return copy(__nb, __ne, __s);
+}
+
+extern template class time_put<char>;
+extern template class time_put<wchar_t>;
+
+template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
+class time_put_byname
+    : public time_put<_CharT, _OutputIterator>
+{
+public:
+    _LIBCPP_ALWAYS_INLINE
+    explicit time_put_byname(const char* __nm, size_t __refs = 0)
+        : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit time_put_byname(const string& __nm, size_t __refs = 0)
+        : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
+
+protected:
+    ~time_put_byname() {}
+};
+
+extern template class time_put_byname<char>;
+extern template class time_put_byname<wchar_t>;
+
+// money_base
+
+class money_base
+{
+public:
+    enum part {none, space, symbol, sign, value};
+    struct pattern {char field[4];};
+
+    _LIBCPP_ALWAYS_INLINE money_base() {}
+};
+
+// moneypunct
+
+template <class _CharT, bool _International = false>
+class moneypunct
+    : public locale::facet,
+      public money_base
+{
+public:
+    typedef _CharT                  char_type;
+    typedef basic_string<char_type> string_type;
+
+    explicit moneypunct(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE char_type   decimal_point() const {return do_decimal_point();}
+    _LIBCPP_ALWAYS_INLINE char_type   thousands_sep() const {return do_thousands_sep();}
+    _LIBCPP_ALWAYS_INLINE string      grouping()      const {return do_grouping();}
+    _LIBCPP_ALWAYS_INLINE string_type curr_symbol()   const {return do_curr_symbol();}
+    _LIBCPP_ALWAYS_INLINE string_type positive_sign() const {return do_positive_sign();}
+    _LIBCPP_ALWAYS_INLINE string_type negative_sign() const {return do_negative_sign();}
+    _LIBCPP_ALWAYS_INLINE int         frac_digits()   const {return do_frac_digits();}
+    _LIBCPP_ALWAYS_INLINE pattern     pos_format()    const {return do_pos_format();}
+    _LIBCPP_ALWAYS_INLINE pattern     neg_format()    const {return do_neg_format();}
+
+    static locale::id id;
+    static const bool intl = _International;
+
+protected:
+    ~moneypunct() {}
+
+    virtual char_type   do_decimal_point() const {return numeric_limits<char_type>::max();}
+    virtual char_type   do_thousands_sep() const {return numeric_limits<char_type>::max();}
+    virtual string      do_grouping()      const {return string();}
+    virtual string_type do_curr_symbol()   const {return string_type();}
+    virtual string_type do_positive_sign() const {return string_type();}
+    virtual string_type do_negative_sign() const {return string_type(1, '-');}
+    virtual int         do_frac_digits()   const {return 0;}
+    virtual pattern     do_pos_format()    const
+        {pattern __p = {symbol, sign, none, value}; return __p;}
+    virtual pattern     do_neg_format()    const
+        {pattern __p = {symbol, sign, none, value}; return __p;}
+};
+
+template <class _CharT, bool _International>
+locale::id
+moneypunct<_CharT, _International>::id;
+
+extern template class moneypunct<char, false>;
+extern template class moneypunct<char, true>;
+extern template class moneypunct<wchar_t, false>;
+extern template class moneypunct<wchar_t, true>;
+
+// moneypunct_byname
+
+template <class _CharT, bool _International = false>
+class moneypunct_byname : public moneypunct<_CharT, _International>
+{
+public:
+    typedef money_base::pattern  pattern;
+    typedef _CharT                  char_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
+        : moneypunct<_CharT, _International>(__refs) {init(__nm);}
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
+        : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());}
+
+protected:
+    ~moneypunct_byname() {}
+
+    virtual char_type   do_decimal_point() const {return __decimal_point_;}
+    virtual char_type   do_thousands_sep() const {return __thousands_sep_;}
+    virtual string      do_grouping()      const {return __grouping_;}
+    virtual string_type do_curr_symbol()   const {return __curr_symbol_;}
+    virtual string_type do_positive_sign() const {return __positive_sign_;}
+    virtual string_type do_negative_sign() const {return __negative_sign_;}
+    virtual int         do_frac_digits()   const {return __frac_digits_;}
+    virtual pattern     do_pos_format()    const {return __pos_format_;}
+    virtual pattern     do_neg_format()    const {return __neg_format_;}
+
+private:
+    char_type   __decimal_point_;
+    char_type   __thousands_sep_;
+    string      __grouping_;
+    string_type __curr_symbol_;
+    string_type __positive_sign_;
+    string_type __negative_sign_;
+    int         __frac_digits_;
+    pattern     __pos_format_;
+    pattern     __neg_format_;
+
+    void init(const char*);
+};
+
+template<> void moneypunct_byname<char, false>::init(const char*);
+template<> void moneypunct_byname<char, true>::init(const char*);
+template<> void moneypunct_byname<wchar_t, false>::init(const char*);
+template<> void moneypunct_byname<wchar_t, true>::init(const char*);
+
+extern template class moneypunct_byname<char, false>;
+extern template class moneypunct_byname<char, true>;
+extern template class moneypunct_byname<wchar_t, false>;
+extern template class moneypunct_byname<wchar_t, true>;
+
+// money_get
+
+template <class _CharT>
+class __money_get
+{
+protected:
+    typedef _CharT                  char_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE __money_get() {}
+
+    static void __gather_info(bool __intl, const locale& __loc,
+                              money_base::pattern& __pat, char_type& __dp,
+                              char_type& __ts, string& __grp,
+                              string_type& __sym, string_type& __psn,
+                              string_type& __nsn, int& __fd);
+};
+
+template <class _CharT>
+void
+__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
+                                   money_base::pattern& __pat, char_type& __dp,
+                                   char_type& __ts, string& __grp,
+                                   string_type& __sym, string_type& __psn,
+                                   string_type& __nsn, int& __fd)
+{
+    if (__intl)
+    {
+        const moneypunct<char_type, true>& __mp =
+            use_facet<moneypunct<char_type, true> >(__loc);
+        __pat = __mp.neg_format();
+        __nsn = __mp.negative_sign();
+        __psn = __mp.positive_sign();
+        __dp = __mp.decimal_point();
+        __ts = __mp.thousands_sep();
+        __grp = __mp.grouping();
+        __sym = __mp.curr_symbol();
+        __fd = __mp.frac_digits();
+    }
+    else
+    {
+        const moneypunct<char_type, false>& __mp =
+            use_facet<moneypunct<char_type, false> >(__loc);
+        __pat = __mp.neg_format();
+        __nsn = __mp.negative_sign();
+        __psn = __mp.positive_sign();
+        __dp = __mp.decimal_point();
+        __ts = __mp.thousands_sep();
+        __grp = __mp.grouping();
+        __sym = __mp.curr_symbol();
+        __fd = __mp.frac_digits();
+    }
+}
+
+extern template class __money_get<char>;
+extern template class __money_get<wchar_t>;
+
+template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
+class money_get
+    : public locale::facet,
+      private __money_get<_CharT>
+{
+public:
+    typedef _CharT                  char_type;
+    typedef _InputIterator          iter_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit money_get(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
+                  ios_base::iostate& __err, long double& __v) const
+    {
+        return do_get(__b, __e, __intl, __iob, __err, __v);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
+                  ios_base::iostate& __err, string_type& __v) const
+    {
+        return do_get(__b, __e, __intl, __iob, __err, __v);
+    }
+
+    static locale::id id;
+
+protected:
+
+    ~money_get() {}
+    
+    virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
+                             ios_base& __iob, ios_base::iostate& __err,
+                             long double& __v) const;
+    virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
+                             ios_base& __iob, ios_base::iostate& __err,
+                             string_type& __v) const;
+
+private:
+    static bool __do_get(iter_type& __b, iter_type __e,
+                         bool __intl, const locale& __loc,
+                         ios_base::fmtflags __flags, ios_base::iostate& __err,
+                         bool& __neg, const ctype<char_type>& __ct,
+                         unique_ptr<char_type, void(*)(void*)>& __wb,
+                         char_type*& __wn, char_type* __we);
+};
+
+template <class _CharT, class _InputIterator>
+locale::id
+money_get<_CharT, _InputIterator>::id;
+
+void __do_nothing(void*);
+
+template <class _Tp>
+_LIBCPP_HIDDEN
+void
+__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
+{
+    bool __owns = __b.get_deleter() != __do_nothing;
+    size_t __cur_cap = (__e-__b.get()) * sizeof(_Tp);
+    size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
+                       2 * __cur_cap : numeric_limits<size_t>::max();
+    size_t __n_off = __n - __b.get();
+    _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap);
+    if (__t == 0)
+        __throw_bad_alloc();
+    if (__owns)
+        __b.release();
+    __b = unique_ptr<_Tp, void(*)(void*)>(__t, free);
+    __new_cap /= sizeof(_Tp);
+    __n = __b.get() + __n_off;
+    __e = __b.get() + __new_cap;
+}
+
+// true == success
+template <class _CharT, class _InputIterator>
+bool
+money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
+                                            bool __intl, const locale& __loc,
+                                            ios_base::fmtflags __flags,
+                                            ios_base::iostate& __err,
+                                            bool& __neg,
+                                            const ctype<char_type>& __ct,
+                                            unique_ptr<char_type, void(*)(void*)>& __wb,
+                                            char_type*& __wn, char_type* __we)
+{
+    const unsigned __bz = 100;
+    unsigned __gbuf[__bz];
+    unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
+    unsigned* __gn = __gb.get();
+    unsigned* __ge = __gn + __bz;
+    money_base::pattern __pat;
+    char_type __dp;
+    char_type __ts;
+    string __grp;
+    string_type __sym;
+    string_type __psn;
+    string_type __nsn;
+    int __fd;
+    __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp,
+                                       __sym, __psn, __nsn, __fd);
+    const string_type* __trailing_sign = 0;
+    __wn = __wb.get();
+    for (unsigned __p = 0; __p < 4 && __b != __e; ++__p)
+    {
+        switch (__pat.field[__p])
+        {
+        case money_base::space:
+            if (__p != 3)
+            {
+                if (__ct.is(ctype_base::space, *__b))
+                    ++__b;
+                else
+                {
+                    __err |= ios_base::failbit;
+                    return false;
+                }
+            }
+            // drop through            
+        case money_base::none:
+            if (__p != 3)
+            {
+                while (__b != __e && __ct.is(ctype_base::space, *__b))
+                    ++__b;
+            }
+            break;
+        case money_base::sign:
+            if (__psn.size() + __nsn.size() > 0)
+            {
+                if (__psn.size() == 0 || __nsn.size() == 0)
+                {   // sign is optional
+                    if (__psn.size() > 0)
+                    {   // __nsn.size() == 0
+                        if (*__b == __psn[0])
+                        {
+                            ++__b;
+                            if (__psn.size() > 1)
+                                __trailing_sign = &__psn;
+                        }
+                        else
+                            __neg = true;
+                    }
+                    else if (*__b == __nsn[0])  // __nsn.size() > 0 &&  __psn.size() == 0
+                    {
+                        ++__b;
+                        __neg = true;
+                        if (__nsn.size() > 1)
+                            __trailing_sign = &__nsn;
+                    }
+                }
+                else  // sign is required
+                {
+                    if (*__b == __psn[0])
+                    {
+                        ++__b;
+                        if (__psn.size() > 1)
+                            __trailing_sign = &__psn;
+                    }
+                    else if (*__b == __nsn[0])
+                    {
+                        ++__b;
+                        __neg = true;
+                        if (__nsn.size() > 1)
+                            __trailing_sign = &__nsn;
+                    }
+                    else
+                    {
+                        __err |= ios_base::failbit;
+                        return false;
+                    }
+                }
+            }
+            break;
+        case money_base::symbol:
+            {
+            bool __more_needed = __trailing_sign ||
+                                 (__p < 2)       ||
+                                 (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
+            bool __sb = __flags & ios_base::showbase;
+            if (__sb || __more_needed)
+            {
+                ios_base::iostate __et = ios_base::goodbit;
+                string_type* __k = __scan_keyword(__b, __e, &__sym, &__sym+1,
+                                                  __ct, __et);
+                if (__sb && __k != &__sym)
+                {
+                    __err |= ios_base::failbit;
+                    return false;
+                }
+            }
+            }
+            break;
+        case money_base::value:
+            {
+            unsigned __ng = 0;
+            for (; __b != __e; ++__b)
+            {
+                char_type __c = *__b;
+                if (__ct.is(ctype_base::digit, __c))
+                {
+                    if (__wn == __we)
+                        __double_or_nothing(__wb, __wn, __we);
+                    *__wn++ = __c;
+                    ++__ng;
+                }
+                else if (__grp.size() > 0 && __ng > 0 && __c == __ts)
+                {
+                    if (__gn == __ge)
+                        __double_or_nothing(__gb, __gn, __ge);
+                    *__gn++ = __ng;
+                    __ng = 0;
+                }
+                else
+                    break;
+            }
+            if (__gb.get() != __gn && __ng > 0)
+            {
+                if (__gn == __ge)
+                    __double_or_nothing(__gb, __gn, __ge);
+                *__gn++ = __ng;
+            }
+            if (__fd > 0)
+            {
+                if (__b == __e || *__b != __dp)
+                {
+                    __err |= ios_base::failbit;
+                    return false;
+                }
+                for (++__b; __fd > 0; --__fd, ++__b)
+                {
+                    if (__b == __e || !__ct.is(ctype_base::digit, *__b))
+                    {
+                        __err |= ios_base::failbit;
+                        return false;
+                    }
+                    if (__wn == __we)
+                        __double_or_nothing(__wb, __wn, __we);
+                    *__wn++ = *__b;
+                }
+            }
+            if (__wn == __wb.get())
+            {
+                __err |= ios_base::failbit;
+                return false;
+            }
+            }
+            break;
+        }
+    }
+    if (__trailing_sign)
+    {
+        for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b)
+        {
+            if (__b == __e || *__b != (*__trailing_sign)[__i])
+            {
+                __err |= ios_base::failbit;
+                return false;
+            }
+        }
+    }
+    if (__gb.get() != __gn)
+    {
+        ios_base::iostate __et = ios_base::goodbit;
+        __check_grouping(__grp, __gb.get(), __gn, __et);
+        if (__et)
+        {
+            __err |= ios_base::failbit;
+            return false;
+        }
+    }
+    return true;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                          bool __intl, ios_base& __iob,
+                                          ios_base::iostate& __err,
+                                          long double& __v) const
+{
+    const unsigned __bz = 100;
+    char_type __wbuf[__bz];
+    unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
+    char_type* __wn;
+    char_type* __we = __wbuf + __bz;
+    locale __loc = __iob.getloc();
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
+    bool __neg = false;
+    if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
+                 __wb, __wn, __we))
+    {
+        const char __src[] = "0123456789";
+        char_type __atoms[sizeof(__src)-1];
+        __ct.widen(__src, __src + (sizeof(__src)-1), __atoms);
+        char __nbuf[__bz];
+        char* __nc = __nbuf;
+        unique_ptr<char, void(*)(void*)> __h(0, free);
+        if (__wn - __wb.get() > __bz-2)
+        {
+            __h.reset((char*)malloc(__wn - __wb.get() + 2));
+            if (__h.get() == 0)
+                __throw_bad_alloc();
+            __nc = __h.get();
+        }
+        if (__neg)
+            *__nc++ = '-';
+        for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
+            *__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms];
+        *__nc = char();
+        if (sscanf(__nbuf, "%Lf", &__v) != 1)
+            __throw_runtime_error("money_get error");
+    }
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+template <class _CharT, class _InputIterator>
+_InputIterator
+money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
+                                          bool __intl, ios_base& __iob,
+                                          ios_base::iostate& __err,
+                                          string_type& __v) const
+{
+    const unsigned __bz = 100;
+    char_type __wbuf[__bz];
+    unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
+    char_type* __wn;
+    char_type* __we = __wbuf + __bz;
+    locale __loc = __iob.getloc();
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
+    bool __neg = false;
+    if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
+                 __wb, __wn, __we))
+    {
+        __v.clear();
+        if (__neg)
+            __v.push_back(__ct.widen('-'));
+        char_type __z = __ct.widen('0');
+        char_type* __w;
+        for (__w = __wb.get(); __w < __wn-1; ++__w)
+            if (*__w != __z)
+                break;
+        __v.append(__w, __wn);
+    }
+    if (__b == __e)
+        __err |= ios_base::eofbit;
+    return __b;
+}
+
+extern template class money_get<char>;
+extern template class money_get<wchar_t>;
+
+// money_put
+
+template <class _CharT>
+class __money_put
+{
+protected:
+    typedef _CharT                  char_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE __money_put() {}
+
+    static void __gather_info(bool __intl, bool __neg, const locale& __loc,
+                              money_base::pattern& __pat, char_type& __dp,
+                              char_type& __ts, string& __grp,
+                              string_type& __sym, string_type& __sn,
+                              int& __fd);
+    static void __format(char_type* __mb, char_type*& __mi, char_type*& __me,
+                         ios_base::fmtflags __flags,
+                         const char_type* __db, const char_type* __de,
+                         const ctype<char_type>& __ct, bool __neg,
+                         const money_base::pattern& __pat, char_type __dp,
+                         char_type __ts, const string& __grp,
+                         const string_type& __sym, const string_type& __sn,
+                         int __fd);
+};
+
+template <class _CharT>
+void
+__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc,
+                                   money_base::pattern& __pat, char_type& __dp,
+                                   char_type& __ts, string& __grp,
+                                   string_type& __sym, string_type& __sn,
+                                   int& __fd)
+{
+    if (__intl)
+    {
+        const moneypunct<char_type, true>& __mp =
+            use_facet<moneypunct<char_type, true> >(__loc);
+        if (__neg)
+        {
+            __pat = __mp.neg_format();
+            __sn = __mp.negative_sign();
+        }
+        else
+        {
+            __pat = __mp.pos_format();
+            __sn = __mp.positive_sign();
+        }
+        __dp = __mp.decimal_point();
+        __ts = __mp.thousands_sep();
+        __grp = __mp.grouping();
+        __sym = __mp.curr_symbol();
+        __fd = __mp.frac_digits();
+    }
+    else
+    {
+        const moneypunct<char_type, false>& __mp =
+            use_facet<moneypunct<char_type, false> >(__loc);
+        if (__neg)
+        {
+            __pat = __mp.neg_format();
+            __sn = __mp.negative_sign();
+        }
+        else
+        {
+            __pat = __mp.pos_format();
+            __sn = __mp.positive_sign();
+        }
+        __dp = __mp.decimal_point();
+        __ts = __mp.thousands_sep();
+        __grp = __mp.grouping();
+        __sym = __mp.curr_symbol();
+        __fd = __mp.frac_digits();
+    }
+}
+
+template <class _CharT>
+void
+__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me,
+                              ios_base::fmtflags __flags,
+                              const char_type* __db, const char_type* __de,
+                              const ctype<char_type>& __ct, bool __neg,
+                              const money_base::pattern& __pat, char_type __dp,
+                              char_type __ts, const string& __grp,
+                              const string_type& __sym, const string_type& __sn,
+                              int __fd)
+{
+    __me = __mb;
+    for (unsigned __p = 0; __p < 4; ++__p)
+    {
+        switch (__pat.field[__p])
+        {
+        case money_base::none:
+            __mi = __me;
+            break;
+        case money_base::space:
+            __mi = __me;
+            *__me++ = __ct.widen(' ');
+            break;
+        case money_base::sign:
+            if (!__sn.empty())
+                *__me++ = __sn[0];
+            break;
+        case money_base::symbol:
+            if (!__sym.empty() && (__flags & ios_base::showbase))
+                __me = copy(__sym.begin(), __sym.end(), __me);
+            break;
+        case money_base::value:
+            {
+            // remember start of value so we can reverse it
+            char_type* __t = __me;
+            // find beginning of digits
+            if (__neg)
+                ++__db;
+            // find end of digits
+            const char_type* __d;
+            for (__d = __db; __d < __de; ++__d)
+                if (!__ct.is(ctype_base::digit, *__d))
+                    break;
+            // print fractional part
+            if (__fd > 0)
+            {
+                int __f;
+                for (__f = __fd; __d > __db && __f > 0; --__f)
+                    *__me++ = *--__d;
+                char_type __z = __f > 0 ? __ct.widen('0') : char_type();
+                for (; __f > 0; --__f)
+                    *__me++ = __z;
+                *__me++ = __dp;
+            }
+            // print units part
+            if (__d == __db)
+            {
+                *__me++ = __ct.widen('0');
+            }
+            else
+            {
+                unsigned __ng = 0;
+                unsigned __ig = 0;
+                unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max()
+                                              : static_cast<unsigned>(__grp[__ig]);
+                while (__d != __db)
+                {
+                    if (__ng == __gl)
+                    {
+                        *__me++ = __ts;
+                        __ng = 0;
+                        if (++__ig < __grp.size())
+                            __gl = __grp[__ig] == numeric_limits<char>::max() ?
+                                        numeric_limits<unsigned>::max() :
+                                        static_cast<unsigned>(__grp[__ig]);
+                    }
+                    *__me++ = *--__d;
+                    ++__ng;
+                }
+            }
+            // reverse it
+            reverse(__t, __me);
+            }
+            break;
+        }
+    }
+    // print rest of sign, if any
+    if (__sn.size() > 1)
+        __me = copy(__sn.begin()+1, __sn.end(), __me);
+    // set alignment
+    if ((__flags & ios_base::adjustfield) == ios_base::left)
+        __mi = __me;
+    else if ((__flags & ios_base::adjustfield) != ios_base::internal)
+        __mi = __mb;
+}
+
+extern template class __money_put<char>;
+extern template class __money_put<wchar_t>;
+
+template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
+class money_put
+    : public locale::facet,
+      private __money_put<_CharT>
+{
+public:
+    typedef _CharT                  char_type;
+    typedef _OutputIterator         iter_type;
+    typedef basic_string<char_type> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit money_put(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
+                  long double __units) const
+    {
+        return do_put(__s, __intl, __iob, __fl, __units);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
+                  const string_type& __digits) const
+    {
+        return do_put(__s, __intl, __iob, __fl, __digits);
+    }
+
+    static locale::id id;
+
+protected:
+    ~money_put() {}
+
+    virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
+                             char_type __fl, long double __units) const;
+    virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
+                             char_type __fl, const string_type& __digits) const;
+};
+
+template <class _CharT, class _OutputIterator>
+locale::id
+money_put<_CharT, _OutputIterator>::id;
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
+                                           ios_base& __iob, char_type __fl,
+                                           long double __units) const
+{
+    // convert to char
+    const size_t __bs = 100;
+    char __buf[__bs];
+    char* __bb = __buf;
+    char_type __digits[__bs];
+    char_type* __db = __digits;
+    size_t __n = snprintf(__bb, __bs, "%.0Lf", __units);
+    unique_ptr<char, void(*)(void*)> __hn(0, free);
+    unique_ptr<char_type, void(*)(void*)> __hd(0, free);
+    // secure memory for digit storage
+    if (__n > __bs-1)
+    {
+        __n = asprintf_l(&__bb, 0, "%.0Lf", __units);
+        if (__bb == 0)
+            __throw_bad_alloc();
+        __hn.reset(__bb);
+        __hd.reset((char_type*)malloc(__n * sizeof(char_type)));
+        if (__hd == 0)
+            __throw_bad_alloc();
+        __db = __hd.get();
+    }
+    // gather info
+    locale __loc = __iob.getloc();
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
+    __ct.widen(__bb, __bb + __n, __db);
+    bool __neg = __n > 0 && __bb[0] == '-';
+    money_base::pattern __pat;
+    char_type __dp;
+    char_type __ts;
+    string __grp;
+    string_type __sym;
+    string_type __sn;
+    int __fd;
+    this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
+    // secure memory for formatting
+    char_type __mbuf[__bs];
+    char_type* __mb = __mbuf;
+    unique_ptr<char_type, void(*)(void*)> __hw(0, free);
+    size_t __exn = static_cast<int>(__n) > __fd ?
+                   (__n - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
+                 : __sn.size() + __sym.size() + __fd + 2;
+    if (__exn > __bs)
+    {
+        __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
+        __mb = __hw.get();
+        if (__mb == 0)
+            __throw_bad_alloc();
+    }
+    // format
+    char_type* __mi;
+    char_type* __me;
+    this->__format(__mb, __mi, __me, __iob.flags(),
+                   __db, __db + __n, __ct,
+                   __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
+    return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
+}
+
+template <class _CharT, class _OutputIterator>
+_OutputIterator
+money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
+                                           ios_base& __iob, char_type __fl,
+                                           const string_type& __digits) const
+{
+    // gather info
+    locale __loc = __iob.getloc();
+    const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
+    bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
+    money_base::pattern __pat;
+    char_type __dp;
+    char_type __ts;
+    string __grp;
+    string_type __sym;
+    string_type __sn;
+    int __fd;
+    this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
+    // secure memory for formatting
+    char_type __mbuf[100];
+    char_type* __mb = __mbuf;
+    unique_ptr<char_type, void(*)(void*)> __h(0, free);
+    size_t __exn = __digits.size() > __fd ?
+                   (__digits.size() - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
+                 : __sn.size() + __sym.size() + __fd + 2;
+    if (__exn > 100)
+    {
+        __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
+        __mb = __h.get();
+        if (__mb == 0)
+            __throw_bad_alloc();
+    }
+    // format
+    char_type* __mi;
+    char_type* __me;
+    this->__format(__mb, __mi, __me, __iob.flags(),
+                   __digits.data(), __digits.data() + __digits.size(), __ct,
+                   __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
+    return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
+}
+
+extern template class money_put<char>;
+extern template class money_put<wchar_t>;
+
+// messages
+
+class messages_base
+{
+public:
+    typedef nl_catd catalog;
+
+    _LIBCPP_ALWAYS_INLINE messages_base() {}
+};
+
+template <class _CharT>
+class messages
+    : public locale::facet,
+      public messages_base
+{
+public:
+    typedef _CharT               char_type;
+    typedef basic_string<_CharT> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit messages(size_t __refs = 0)
+        : locale::facet(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    catalog open(const basic_string<char>& __nm, const locale& __loc) const
+    {
+        return do_open(__nm, __loc);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    string_type get(catalog __c, int __set, int __msgid,
+                    const string_type& __dflt) const
+    {
+        return do_get(__c, __set, __msgid, __dflt);
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    void close(catalog __c) const
+    {
+        do_close(__c);
+    }
+
+    static locale::id id;
+
+protected:
+    ~messages() {}
+
+    virtual catalog do_open(const basic_string<char>&, const locale&) const;
+    virtual string_type do_get(catalog, int __set, int __msgid,
+                               const string_type& __dflt) const;
+    virtual void do_close(catalog) const;
+};
+
+template <class _CharT>
+locale::id
+messages<_CharT>::id;
+
+template <class _CharT>
+typename messages<_CharT>::catalog
+messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
+{
+    return catopen(__nm.c_str(), NL_CAT_LOCALE);
+}
+
+template <class _CharT>
+typename messages<_CharT>::string_type
+messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
+                         const string_type& __dflt) const
+{
+    string __ndflt;
+    __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
+                                                       __dflt.c_str(),
+                                                       __dflt.c_str() + __dflt.size());
+    char* __n = catgets(__c, __set, __msgid, __ndflt.c_str());
+    string_type __w;
+    __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
+                                                        __n, __n + strlen(__n));
+    return __w;
+}
+
+template <class _CharT>
+void
+messages<_CharT>::do_close(catalog __c) const
+{
+    catclose(__c);
+}
+
+extern template class messages<char>;
+extern template class messages<wchar_t>;
+
+template <class _CharT>
+class messages_byname
+    : public messages<_CharT>
+{
+public:
+    typedef messages_base::catalog catalog;
+    typedef basic_string<_CharT> string_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit messages_byname(const char*, size_t __refs = 0)
+        : messages<_CharT>(__refs) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit messages_byname(const string&, size_t __refs = 0)
+        : messages<_CharT>(__refs) {}
+
+protected:
+    ~messages_byname() {}
+};
+
+extern template class messages_byname<char>;
+extern template class messages_byname<wchar_t>;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_LOCALE
diff --git a/include/map b/include/map
new file mode 100644
index 0000000..5f4e09f
--- /dev/null
+++ b/include/map
@@ -0,0 +1,1663 @@
+// -*- C++ -*-
+//===----------------------------- map ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_MAP
+#define _LIBCPP_MAP
+
+/*
+
+    map synopsis
+
+namespace std
+{
+
+template <class Key, class T, class Compare = less<Key>,
+          class Allocator = allocator<pair<const Key, T>>>
+class map
+{
+public:
+    // types:
+    typedef Key                                      key_type;
+    typedef T                                        mapped_type;
+    typedef pair<const key_type, mapped_type>        value_type;
+    typedef Compare                                  key_compare;
+    typedef Allocator                                allocator_type;
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    class value_compare
+        : public binary_function<value_type, value_type, bool>
+    {
+        friend class map;
+    protected:
+        key_compare comp;
+
+        value_compare(key_compare c);
+    public:
+        bool operator()(const value_type& x, const value_type& y) const;
+    };
+
+    // construct/copy/destroy:
+    map();
+    explicit map(const key_compare& comp);
+    map(const key_compare& comp, const allocator_type& a);
+    template <class InputIterator>
+        map(InputIterator first, InputIterator last,
+            const key_compare& comp = key_compare());
+    template <class InputIterator>
+        map(InputIterator first, InputIterator last,
+            const key_compare& comp, const allocator_type& a);
+    map(const map& m);
+    map(map&& m);
+    explicit map(const allocator_type& a);
+    map(const map& m, const allocator_type& a);
+    map(map&& m, const allocator_type& a);
+    map(initializer_list<value_type> il, const key_compare& comp = key_compare());
+    map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
+    ~map();
+
+    map& operator=(const map& m);
+    map& operator=(map&& m);
+    map& operator=(initializer_list<value_type> il);
+
+    // iterators:
+          iterator begin();
+    const_iterator begin() const;
+          iterator end();
+    const_iterator end()   const;
+
+          reverse_iterator rbegin();
+    const_reverse_iterator rbegin() const;
+          reverse_iterator rend();
+    const_reverse_iterator rend()   const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    // capacity:
+    bool      empty()    const;
+    size_type size()     const;
+    size_type max_size() const;
+
+    // element access:
+    mapped_type& operator[](const key_type& k);
+    mapped_type& operator[](key_type&& k);
+
+          mapped_type& at(const key_type& k);
+    const mapped_type& at(const key_type& k) const;
+
+    // modifiers:
+    template <class... Args>
+        pair<iterator, bool> emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    pair<iterator, bool> insert(const value_type& v);
+    template <class P>
+        pair<iterator, bool> insert(P&& p);
+    iterator insert(const_iterator position, const value_type& v);
+    template <class P>
+        iterator insert(const_iterator position, P&& p);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type> il);
+
+    iterator  erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator  erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(map& m);
+
+    // observers:
+    allocator_type get_allocator() const;
+    key_compare    key_comp()      const;
+    value_compare  value_comp()    const;
+
+    // map operations:
+          iterator find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type      count(const key_type& k) const;
+          iterator lower_bound(const key_type& k);
+    const_iterator lower_bound(const key_type& k) const;
+          iterator upper_bound(const key_type& k);
+    const_iterator upper_bound(const key_type& k) const;
+    pair<iterator,iterator>             equal_range(const key_type& k);
+    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
+};
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator==(const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator< (const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator!=(const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator> (const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator>=(const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator<=(const map<Key, T, Compare, Allocator>& x,
+           const map<Key, T, Compare, Allocator>& y);
+
+// specialized algorithms:
+template <class Key, class T, class Compare, class Allocator>
+void
+swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare = less<Key>,
+          class Allocator = allocator<pair<const Key, T>>>
+class multimap
+{
+public:
+    // types:
+    typedef Key                                      key_type;
+    typedef T                                        mapped_type;
+    typedef pair<const key_type,mapped_type>         value_type;
+    typedef Compare                                  key_compare;
+    typedef Allocator                                allocator_type;
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    class value_compare
+        : public binary_function<value_type,value_type,bool>
+    {
+        friend class multimap;
+    protected:
+        key_compare comp;
+        value_compare(key_compare c);
+    public:
+        bool operator()(const value_type& x, const value_type& y) const;
+    };
+
+    // construct/copy/destroy:
+    explicit multimap(const key_compare& comp = key_compare());
+    multimap(const key_compare& comp, const allocator_type& a);
+    template <class InputIterator>
+        multimap(InputIterator first, InputIterator last, const key_compare& comp);
+    template <class InputIterator>
+        multimap(InputIterator first, InputIterator last, const key_compare& comp,
+                 const allocator_type& a);
+    multimap(const multimap& m);
+    multimap(multimap&& m);
+    explicit multimap(const allocator_type& a);
+    multimap(const multimap& m, const allocator_type& a);
+    multimap(multimap&& m, const allocator_type& a);
+    multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
+    multimap(initializer_list<value_type> il, const key_compare& comp,
+             const allocator_type& a);
+    ~multimap();
+
+    multimap& operator=(const multimap& m);
+    multimap& operator=(multimap&& m);
+    multimap& operator=(initializer_list<value_type> il);
+
+    // iterators:
+          iterator begin();
+    const_iterator begin() const;
+          iterator end();
+    const_iterator end()   const;
+
+          reverse_iterator rbegin();
+    const_reverse_iterator rbegin() const;
+          reverse_iterator rend();
+    const_reverse_iterator rend()   const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    // capacity:
+    bool      empty()    const;
+    size_type size()     const;
+    size_type max_size() const;
+
+    // modifiers:
+    template <class... Args>
+        iterator emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    iterator insert(const value_type& v);
+    template <class P>
+        iterator insert(P&& p);
+    iterator insert(const_iterator position, const value_type& v);
+    template <class P>
+        iterator insert(const_iterator position, P&& p);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type> il);
+
+    iterator  erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator  erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(multimap& m);
+
+    // observers:
+    allocator_type get_allocator() const;
+    key_compare    key_comp()      const;
+    value_compare  value_comp()    const;
+
+    // map operations:
+          iterator find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type      count(const key_type& k) const;
+          iterator lower_bound(const key_type& k);
+    const_iterator lower_bound(const key_type& k) const;
+          iterator upper_bound(const key_type& k);
+    const_iterator upper_bound(const key_type& k) const;
+    pair<iterator,iterator>             equal_range(const key_type& k);
+    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
+};
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator==(const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator< (const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator!=(const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator> (const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator>=(const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+template <class Key, class T, class Compare, class Allocator>
+bool
+operator<=(const multimap<Key, T, Compare, Allocator>& x,
+           const multimap<Key, T, Compare, Allocator>& y);
+
+// specialized algorithms:
+template <class Key, class T, class Compare, class Allocator>
+void
+swap(multimap<Key, T, Compare, Allocator>& x,
+     multimap<Key, T, Compare, Allocator>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__tree>
+#include <iterator>
+#include <memory>
+#include <utility>
+#include <functional>
+#include <initializer_list>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Key, class _Tp, class _Compare, bool = is_empty<_Compare>::value>
+class __map_value_compare
+    : private _Compare
+{
+    typedef pair<_Key, _Tp> _P;
+    typedef pair<const _Key, _Tp> _CP;
+public:
+    __map_value_compare() : _Compare() {}
+    __map_value_compare(_Compare c) : _Compare(c) {}
+    const _Compare& key_comp() const {return *this;}
+    bool operator()(const _CP& __x, const _CP& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+    bool operator()(const _CP& __x, const _P& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+    bool operator()(const _CP& __x, const _Key& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y);}
+    bool operator()(const _P& __x, const _CP& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+    bool operator()(const _P& __x, const _P& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+    bool operator()(const _P& __x, const _Key& __y) const
+        {return static_cast<const _Compare&>(*this)(__x.first, __y);}
+    bool operator()(const _Key& __x, const _CP& __y) const
+        {return static_cast<const _Compare&>(*this)(__x, __y.first);}
+    bool operator()(const _Key& __x, const _P& __y) const
+        {return static_cast<const _Compare&>(*this)(__x, __y.first);}
+    bool operator()(const _Key& __x, const _Key& __y) const
+        {return static_cast<const _Compare&>(*this)(__x, __y);}
+
+
+
+//     bool operator()(const _Tp& __x, const _Tp& __y) const
+//         {return static_cast<const _Compare&>(*this)(__x.first, __y.first);}
+//     bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+//         {return static_cast<const _Compare&>(*this)(__x, __y.first);}
+//     bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+//         {return static_cast<const _Compare&>(*this)(__x.first, __y);}
+//     bool operator()(const typename _Tp::first_type& __x,
+//                     const typename _Tp::first_type& __y) const
+//         {return static_cast<const _Compare&>(*this)(__x, __y);}
+};
+
+template <class _Key, class _Tp, class _Compare>
+class __map_value_compare<_Key, _Tp, _Compare, false>
+{
+    _Compare comp;
+
+    typedef pair<_Key, _Tp> _P;
+    typedef pair<const _Key, _Tp> _CP;
+
+public:
+    __map_value_compare() : comp() {}
+    __map_value_compare(_Compare c) : comp(c) {}
+    const _Compare& key_comp() const {return comp;}
+
+    bool operator()(const _CP& __x, const _CP& __y) const
+        {return comp(__x.first, __y.first);}
+    bool operator()(const _CP& __x, const _P& __y) const
+        {return comp(__x.first, __y.first);}
+    bool operator()(const _CP& __x, const _Key& __y) const
+        {return comp(__x.first, __y);}
+    bool operator()(const _P& __x, const _CP& __y) const
+        {return comp(__x.first, __y.first);}
+    bool operator()(const _P& __x, const _P& __y) const
+        {return comp(__x.first, __y.first);}
+    bool operator()(const _P& __x, const _Key& __y) const
+        {return comp(__x.first, __y);}
+    bool operator()(const _Key& __x, const _CP& __y) const
+        {return comp(__x, __y.first);}
+    bool operator()(const _Key& __x, const _P& __y) const
+        {return comp(__x, __y.first);}
+    bool operator()(const _Key& __x, const _Key& __y) const
+        {return comp(__x, __y);}
+
+
+
+//     bool operator()(const _Tp& __x, const _Tp& __y) const
+//         {return comp(__x.first, __y.first);}
+//     bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+//         {return comp(__x, __y.first);}
+//     bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+//         {return comp(__x.first, __y);}
+//     bool operator()(const typename _Tp::first_type& __x,
+//                     const typename _Tp::first_type& __y) const
+//         {return comp(__x, __y);}
+};
+
+template <class _Allocator>
+class __map_node_destructor
+{
+    typedef _Allocator                          allocator_type;
+    typedef allocator_traits<allocator_type>    __alloc_traits;
+    typedef typename __alloc_traits::value_type::value_type value_type;
+public:
+    typedef typename __alloc_traits::pointer    pointer;
+private:
+    typedef typename value_type::first_type     first_type;
+    typedef typename value_type::second_type    second_type;
+
+    allocator_type& __na_;
+
+    __map_node_destructor& operator=(const __map_node_destructor&);
+
+public:
+    bool __first_constructed;
+    bool __second_constructed;
+
+    explicit __map_node_destructor(allocator_type& __na)
+        : __na_(__na),
+          __first_constructed(false),
+          __second_constructed(false)
+        {}
+
+#ifdef _LIBCPP_MOVE
+    __map_node_destructor(__tree_node_destructor<allocator_type>&& __x)
+        : __na_(__x.__na_),
+          __first_constructed(__x.__value_constructed),
+          __second_constructed(__x.__value_constructed)
+        {
+            __x.__value_constructed = false;
+        }
+#endif
+
+    void operator()(pointer __p)
+    {
+        if (__second_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.second));
+        if (__first_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.first));
+        if (__p)
+            __alloc_traits::deallocate(__na_, __p, 1);
+    }
+};
+
+template <class, class, class, class> class map;
+template <class, class, class, class> class multimap;
+template <class> class __map_const_iterator;
+
+template <class _TreeIterator>
+class __map_iterator
+{
+    _TreeIterator __i_;
+
+    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
+    typedef const typename _TreeIterator::value_type::first_type key_type;
+    typedef typename _TreeIterator::value_type::second_type      mapped_type;
+public:
+    typedef bidirectional_iterator_tag                           iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _TreeIterator::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;
+
+    __map_iterator() {}
+
+    __map_iterator(_TreeIterator __i) : __i_(__i) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __map_iterator& operator++() {++__i_; return *this;}
+    __map_iterator operator++(int)
+    {
+        __map_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    __map_iterator& operator--() {--__i_; return *this;}
+    __map_iterator operator--(int)
+    {
+        __map_iterator __t(*this);
+        --(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __map_iterator& __x, const __map_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class> friend class map;
+    template <class, class, class, class> friend class multimap;
+    template <class> friend class __map_const_iterator;
+};
+
+template <class _TreeIterator>
+class __map_const_iterator
+{
+    _TreeIterator __i_;
+
+    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
+    typedef const typename _TreeIterator::value_type::first_type key_type;
+    typedef typename _TreeIterator::value_type::second_type      mapped_type;
+public:
+    typedef bidirectional_iterator_tag                           iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _TreeIterator::difference_type              difference_type;
+    typedef const value_type&                                    reference;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
+
+    __map_const_iterator() {}
+
+    __map_const_iterator(_TreeIterator __i) : __i_(__i) {}
+    __map_const_iterator(
+            __map_iterator<typename _TreeIterator::__non_const_iterator> __i)
+                : __i_(__i.__i_) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __map_const_iterator& operator++() {++__i_; return *this;}
+    __map_const_iterator operator++(int)
+    {
+        __map_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    __map_const_iterator& operator--() {--__i_; return *this;}
+    __map_const_iterator operator--(int)
+    {
+        __map_const_iterator __t(*this);
+        --(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class> friend class map;
+    template <class, class, class, class> friend class multimap;
+    template <class, class, class> friend class __tree_const_iterator;
+};
+
+template <class _Key, class _Tp, class _Compare = less<_Key>,
+          class _Allocator = allocator<pair<const _Key, _Tp> > >
+class map
+{
+public:
+    // types:
+    typedef _Key                                     key_type;
+    typedef _Tp                                      mapped_type;
+    typedef pair<const key_type, mapped_type>        value_type;
+    typedef _Compare                                 key_compare;
+    typedef _Allocator                               allocator_type;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+
+    class value_compare
+        : public binary_function<value_type, value_type, bool>
+    {
+        friend class map;
+    protected:
+        key_compare comp;
+
+        value_compare(key_compare c) : comp(c) {}
+    public:
+        bool operator()(const value_type& __x, const value_type& __y) const
+            {return comp(__x.first, __y.first);}
+    };
+
+private:
+    typedef pair<key_type, mapped_type>                             __value_type;
+    typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                           __allocator_type;
+    typedef __tree<__value_type, __vc, __allocator_type>   __base;
+    typedef typename __base::__node_traits                 __node_traits;
+    typedef allocator_traits<allocator_type>               __alloc_traits;
+
+    __base __tree_;
+
+public:
+    typedef typename __alloc_traits::pointer               pointer;
+    typedef typename __alloc_traits::const_pointer         const_pointer;
+    typedef typename __alloc_traits::size_type             size_type;
+    typedef typename __alloc_traits::difference_type       difference_type;
+    typedef __map_iterator<typename __base::iterator>      iterator;
+    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
+    typedef _STD::reverse_iterator<iterator>               reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>         const_reverse_iterator;
+
+    explicit map(const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp)) {}
+
+    explicit map(const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a) {}
+
+    template <class _InputIterator>
+        map(_InputIterator __f, _InputIterator __l,
+            const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp))
+        {
+            insert(__f, __l);
+        }
+
+    template <class _InputIterator>
+        map(_InputIterator __f, _InputIterator __l,
+            const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a)
+        {
+            insert(__f, __l);
+        }
+
+    map(const map& __m)
+        : __tree_(__m.__tree_)
+        {
+            insert(__m.begin(), __m.end());
+        }
+
+#ifdef _LIBCPP_MOVE
+
+    map(map&& __m)
+        : __tree_(_STD::move(__m.__tree_))
+        {
+        }
+
+    map(map&& __m, const allocator_type& __a);
+
+    map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp))
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    map& operator=(map&& __m)
+        {
+            __tree_ = _STD::move(__m.__tree_);
+            return *this;
+        }
+
+    map& operator=(initializer_list<value_type> __il)
+        {
+            __tree_.__assign_unique(__il.begin(), __il.end());
+            return *this;
+        }
+
+#endif
+
+    explicit map(const allocator_type& __a)
+        : __tree_(__a)
+        {
+        }
+
+    map(const map& __m, const allocator_type& __a)
+        : __tree_(__m.__tree_.value_comp(), __a)
+        {
+            insert(__m.begin(), __m.end());
+        }
+
+          iterator begin()       {return __tree_.begin();}
+    const_iterator begin() const {return __tree_.begin();}
+          iterator end()         {return __tree_.end();}
+    const_iterator end()   const {return __tree_.end();}
+
+          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+          reverse_iterator rend()         {return       reverse_iterator(begin());}
+    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+
+    const_iterator         cbegin()  const {return begin();}
+    const_iterator         cend()    const {return end();}
+    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crend()   const {return rend();}
+
+    bool      empty()    const {return __tree_.size() == 0;}
+    size_type size()     const {return __tree_.size();}
+    size_type max_size() const {return __tree_.max_size();}
+
+    mapped_type& operator[](const key_type& __k);
+#ifdef _LIBCPP_MOVE
+    mapped_type& operator[](key_type&& __k);
+#endif
+
+          mapped_type& at(const key_type& __k);
+    const mapped_type& at(const key_type& __k) const;
+
+    allocator_type get_allocator() const {return __tree_.__alloc();}
+    key_compare    key_comp()      const {return __tree_.value_comp().key_comp();}
+    value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
+
+#ifdef _LIBCPP_MOVE
+
+    pair<iterator, bool>
+        emplace() {return __tree_.__emplace_unique();}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        pair<iterator, bool>
+        emplace(_A0&& __a0)
+            {return __tree_.__emplace_unique(_STD::forward<_A0>(__a0));}
+
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        pair<iterator, bool>
+        emplace(_A0&& __a0, _Args&& ...__args);
+
+    iterator
+    emplace_hint(const_iterator __p)
+        {return __tree_.__emplace_hint_unique(__p.__i_);}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator
+        emplace_hint(const_iterator __p, _A0&& __a0)
+            {return __tree_.__emplace_hint_unique(__p.__i_, _STD::forward<_A0>(__a0));}
+
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator
+        emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
+
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        pair<iterator, bool> insert(_P&& __p)
+            {return __tree_.__insert_unique(_STD::forward<_P>(__p));}
+
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(const_iterator __pos, _P&& __p)
+            {return __tree_.__insert_unique(__pos.__i_, _STD::forward<_P>(__p));}
+
+#endif
+
+    pair<iterator, bool>
+        insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
+
+    iterator
+        insert(const_iterator __p, const value_type& __v)
+            {return __tree_.__insert_unique(__p.__i_, __v);}
+
+    template <class _InputIterator>
+        void insert(_InputIterator __f, _InputIterator __l)
+        {
+            for (const_iterator __e = cend(); __f != __l; ++__f)
+                insert(__e.__i_, *__f);
+        }
+
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
+    size_type erase(const key_type& __k)
+        {return __tree_.__erase_unique(__k);}
+    iterator  erase(const_iterator __f, const_iterator __l)
+        {return __tree_.erase(__f.__i_, __l.__i_);}
+    void clear() {__tree_.clear();}
+
+    void swap(map& __m) {__tree_.swap(__m.__tree_);}
+
+    iterator find(const key_type& __k)             {return __tree_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
+    size_type      count(const key_type& __k) const
+        {return __tree_.__count_unique(__k);}
+    iterator lower_bound(const key_type& __k)
+        {return __tree_.lower_bound(__k);}
+    const_iterator lower_bound(const key_type& __k) const
+        {return __tree_.lower_bound(__k);}
+    iterator upper_bound(const key_type& __k)
+        {return __tree_.upper_bound(__k);}
+    const_iterator upper_bound(const key_type& __k) const
+        {return __tree_.upper_bound(__k);}
+    pair<iterator,iterator> equal_range(const key_type& __k)
+        {return __tree_.__equal_range_unique(__k);}
+    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
+        {return __tree_.__equal_range_unique(__k);}
+
+private:
+    typedef typename __base::__node                    __node;
+    typedef typename __base::__node_allocator          __node_allocator;
+    typedef typename __base::__node_pointer            __node_pointer;
+    typedef typename __base::__node_const_pointer      __node_const_pointer;
+    typedef typename __base::__node_base_pointer       __node_base_pointer;
+    typedef typename __base::__node_base_const_pointer __node_base_const_pointer;
+    typedef __map_node_destructor<__node_allocator> _D;
+    typedef unique_ptr<__node, _D> __node_holder;
+
+#ifdef _LIBCPP_MOVE
+    __node_holder __construct_node();
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0);
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
+#else
+    __node_holder __construct_node(const key_type& __k);
+#endif
+
+    __node_base_pointer&
+        __find_equal_key(__node_base_pointer& __parent, const key_type& __k);
+    __node_base_pointer&
+        __find_equal_key(const_iterator __hint,
+                         __node_base_pointer& __parent, const key_type& __k);
+    __node_base_const_pointer
+        __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const;
+};
+
+// Find place to insert if __k doesn't exist
+// Set __parent to parent of null leaf
+// Return reference to null leaf
+// If __k exists, set parent to node of __k and return reference to node of __k
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
+map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __parent,
+                                                       const key_type& __k)
+{
+    __node_pointer __nd = __tree_.__root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = __nd;
+                    return __parent->__left_;
+                }
+            }
+            else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = __nd;
+                    return __parent->__right_;
+                }
+            }
+            else
+            {
+                __parent = __nd;
+                return __parent;
+            }
+        }
+    }
+    __parent = __tree_.__end_node();
+    return __parent->__left_;
+}
+
+// Find place to insert if __k 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 __k exists, set parent to node of __k and return reference to node of __k
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer&
+map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint,
+                                                       __node_base_pointer& __parent,
+                                                       const key_type& __k)
+{
+    if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first))  // check before
+    {
+        // __k < *__hint
+        const_iterator __prior = __hint;
+        if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k))
+        {
+            // *prev(__hint) < __k < *__hint
+            if (__hint.__ptr_->__left_ == nullptr)
+            {
+                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                return __parent->__left_;
+            }
+            else
+            {
+                __parent = const_cast<__node_pointer&>(__prior.__ptr_);
+                return __parent->__right_;
+            }
+        }
+        // __k <= *prev(__hint)
+        return __find_equal_key(__parent, __k);
+    }
+    else if (__tree_.value_comp().key_comp()(__hint->first, __k))  // check after
+    {
+        // *__hint < __k
+        const_iterator __next = next(__hint);
+        if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first))
+        {
+            // *__hint < __k < *next(__hint)
+            if (__hint.__ptr_->__right_ == nullptr)
+            {
+                __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+                return __parent->__right_;
+            }
+            else
+            {
+                __parent = const_cast<__node_pointer&>(__next.__ptr_);
+                return __parent->__left_;
+            }
+        }
+        // *next(__hint) <= __k
+        return __find_equal_key(__parent, __k);
+    }
+    // else __k == *__hint
+    __parent = const_cast<__node_pointer&>(__hint.__ptr_);
+    return __parent;
+}
+
+// Find __k
+// Set __parent to parent of null leaf and
+//    return reference to null leaf iv __k does not exist.
+// If __k exists, set parent to node of __k and return reference to node of __k
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_const_pointer
+map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer& __parent,
+                                                       const key_type& __k) const
+{
+    __node_const_pointer __nd = __tree_.__root();
+    if (__nd != nullptr)
+    {
+        while (true)
+        {
+            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first))
+            {
+                if (__nd->__left_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__left_);
+                else
+                {
+                    __parent = __nd;
+                    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+                }
+            }
+            else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k))
+            {
+                if (__nd->__right_ != nullptr)
+                    __nd = static_cast<__node_pointer>(__nd->__right_);
+                else
+                {
+                    __parent = __nd;
+                    return const_cast<const __node_base_const_pointer&>(__parent->__right_);
+                }
+            }
+            else
+            {
+                __parent = __nd;
+                return __parent;
+            }
+        }
+    }
+    __parent = __tree_.__end_node();
+    return const_cast<const __node_base_const_pointer&>(__parent->__left_);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
+    : __tree_(_STD::move(__m.__tree_), __a)
+{
+    if (__a != __m.get_allocator())
+    {
+        const_iterator __e = cend();
+        while (!__m.empty())
+            __tree_.__insert_unique(__e.__i_,
+                    _STD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
+    }
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node()
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0,
+          class>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first), _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second), _STD::forward<_Args>(__args)...);
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#else
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
+map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first), __k);
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second));
+    __h.get_deleter().__second_constructed = true;
+    return _STD::move(__h);
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+_Tp&
+map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal_key(__parent, __k);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __node_holder __h = __construct_node(__k);
+        __tree_.__insert_node_at(__parent, __child, __h.get());
+        __r = __h.release();
+    }
+    return __r->__value_.second;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+_Tp&
+map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal_key(__parent, __k);
+    __node_pointer __r = static_cast<__node_pointer>(__child);
+    if (__child == nullptr)
+    {
+        __node_holder __h = __construct_node(_STD::move(__k));
+        __tree_.__insert_node_at(__parent, __child, __h.get());
+        __r = __h.release();
+    }
+    return __r->__value_.second;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+_Tp&
+map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
+{
+    __node_base_pointer __parent;
+    __node_base_pointer& __child = __find_equal_key(__parent, __k);
+    if (__child == nullptr)
+        throw out_of_range("map::at:  key not found");
+    return static_cast<__node_pointer>(__child)->__value_.second;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+const _Tp&
+map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
+{
+    __node_base_const_pointer __parent;
+    __node_base_const_pointer __child = __find_equal_key(__parent, __k);
+    if (__child == nullptr)
+        throw out_of_range("map::at:  key not found");
+    return static_cast<__node_const_pointer>(__child)->__value_.second;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class //= typename enable_if<is_convertible<_A0, _Key>::value>::type
+         >
+pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool>
+map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class //= typename enable_if<is_convertible<_A0, _Key>::value>::type
+         >
+typename map<_Key, _Tp, _Compare, _Allocator>::iterator
+map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
+                                                   _A0&& __a0, _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get());
+    if (__r.__i_.__ptr_ == __h.get())
+        __h.release();
+    return __r;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
+           const map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+void
+swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
+     map<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Key, class _Tp, class _Compare = less<_Key>,
+          class _Allocator = allocator<pair<const _Key, _Tp> > >
+class multimap
+{
+public:
+    // types:
+    typedef _Key                                     key_type;
+    typedef _Tp                                      mapped_type;
+    typedef pair<const key_type, mapped_type>        value_type;
+    typedef _Compare                                 key_compare;
+    typedef _Allocator                               allocator_type;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+
+    class value_compare
+        : public binary_function<value_type, value_type, bool>
+    {
+        friend class multimap;
+    protected:
+        key_compare comp;
+
+        value_compare(key_compare c) : comp(c) {}
+    public:
+        bool operator()(const value_type& __x, const value_type& __y) const
+            {return comp(__x.first, __y.first);}
+    };
+
+private:
+    typedef pair<key_type, mapped_type>                             __value_type;
+    typedef __map_value_compare<key_type, mapped_type, key_compare> __vc;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                                    __allocator_type;
+    typedef __tree<__value_type, __vc, __allocator_type>            __base;
+    typedef typename __base::__node_traits                          __node_traits;
+    typedef allocator_traits<allocator_type>                        __alloc_traits;
+
+    __base __tree_;
+
+public:
+    typedef typename __alloc_traits::pointer               pointer;
+    typedef typename __alloc_traits::const_pointer         const_pointer;
+    typedef typename __alloc_traits::size_type             size_type;
+    typedef typename __alloc_traits::difference_type       difference_type;
+    typedef __map_iterator<typename __base::iterator>      iterator;
+    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
+    typedef _STD::reverse_iterator<iterator>               reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>         const_reverse_iterator;
+
+    explicit multimap(const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp)) {}
+
+    explicit multimap(const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a) {}
+
+    template <class _InputIterator>
+        multimap(_InputIterator __f, _InputIterator __l,
+            const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp))
+        {
+            insert(__f, __l);
+        }
+
+    template <class _InputIterator>
+        multimap(_InputIterator __f, _InputIterator __l,
+            const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a)
+        {
+            insert(__f, __l);
+        }
+
+    multimap(const multimap& __m)
+        : __tree_(__m.__tree_.value_comp(),
+          __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
+        {
+            insert(__m.begin(), __m.end());
+        }
+
+#ifdef _LIBCPP_MOVE
+
+    multimap(multimap&& __m)
+        : __tree_(_STD::move(__m.__tree_))
+        {
+        }
+
+    multimap(multimap&& __m, const allocator_type& __a);
+
+    multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
+        : __tree_(__vc(__comp))
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
+        : __tree_(__vc(__comp), __a)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    multimap& operator=(multimap&& __m)
+        {
+            __tree_ = _STD::move(__m.__tree_);
+            return *this;
+        }
+
+    multimap& operator=(initializer_list<value_type> __il)
+        {
+            __tree_.__assign_multi(__il.begin(), __il.end());
+            return *this;
+        }
+#endif
+
+    explicit multimap(const allocator_type& __a)
+        : __tree_(__a)
+        {
+        }
+
+    multimap(const multimap& __m, const allocator_type& __a)
+        : __tree_(__m.__tree_.value_comp(), __a)
+        {
+            insert(__m.begin(), __m.end());
+        }
+
+          iterator begin()       {return __tree_.begin();}
+    const_iterator begin() const {return __tree_.begin();}
+          iterator end()         {return __tree_.end();}
+    const_iterator end()   const {return __tree_.end();}
+
+          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+          reverse_iterator rend()         {return       reverse_iterator(begin());}
+    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+
+    const_iterator         cbegin()  const {return begin();}
+    const_iterator         cend()    const {return end();}
+    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crend()   const {return rend();}
+
+    bool      empty()    const {return __tree_.size() == 0;}
+    size_type size()     const {return __tree_.size();}
+    size_type max_size() const {return __tree_.max_size();}
+
+    allocator_type get_allocator() const {return __tree_.__alloc();}
+    key_compare    key_comp()      const {return __tree_.value_comp().key_comp();}
+    value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
+
+#ifdef _LIBCPP_MOVE
+
+    iterator emplace() {return __tree_.__emplace_multi();}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator
+        emplace(_A0&& __a0)
+            {return __tree_.__emplace_multi(_STD::forward<_A0>(__a0));}
+
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator
+        emplace(_A0&& __a0, _Args&& ...__args);
+
+    iterator emplace_hint(const_iterator __p)
+        {return __tree_.__emplace_hint_multi(__p.__i_);}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator
+        emplace_hint(const_iterator __p, _A0&& __a0)
+            {return __tree_.__emplace_hint_multi(__p.__i_, _STD::forward<_A0>(__a0));}
+
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator
+        emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args);
+
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(_P&& __p)
+            {return __tree_.__insert_multi(_STD::forward<_P>(__p));}
+
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(const_iterator __pos, _P&& __p)
+            {return __tree_.__insert_multi(__pos.__i_, _STD::forward<_P>(__p));}
+
+#endif
+
+    iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
+
+    iterator insert(const_iterator __p, const value_type& __v)
+            {return __tree_.__insert_multi(__p.__i_, __v);}
+
+    template <class _InputIterator>
+        void insert(_InputIterator __f, _InputIterator __l)
+        {
+            for (const_iterator __e = cend(); __f != __l; ++__f)
+                __tree_.__insert_multi(__e.__i_, *__f);
+        }
+
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
+    size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
+    iterator  erase(const_iterator __f, const_iterator __l)
+        {return __tree_.erase(__f.__i_, __l.__i_);}
+    void clear() {__tree_.clear();}
+
+    void swap(multimap& __m) {__tree_.swap(__m.__tree_);}
+
+    iterator find(const key_type& __k)             {return __tree_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
+    size_type      count(const key_type& __k) const
+        {return __tree_.__count_multi(__k);}
+    iterator lower_bound(const key_type& __k)
+        {return __tree_.lower_bound(__k);}
+    const_iterator lower_bound(const key_type& __k) const
+            {return __tree_.lower_bound(__k);}
+    iterator upper_bound(const key_type& __k)
+            {return __tree_.upper_bound(__k);}
+    const_iterator upper_bound(const key_type& __k) const
+            {return __tree_.upper_bound(__k);}
+    pair<iterator,iterator>             equal_range(const key_type& __k)
+            {return __tree_.__equal_range_multi(__k);}
+    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
+            {return __tree_.__equal_range_multi(__k);}
+
+private:
+    typedef typename __base::__node                    __node;
+    typedef typename __base::__node_allocator          __node_allocator;
+    typedef typename __base::__node_pointer            __node_pointer;
+    typedef typename __base::__node_const_pointer      __node_const_pointer;
+    typedef __map_node_destructor<__node_allocator> _D;
+    typedef unique_ptr<__node, _D> __node_holder;
+
+#ifdef _LIBCPP_MOVE
+    __node_holder __construct_node();
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0);
+    template <class _A0, class ..._Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0, _Args&& ...__args);
+#endif
+};
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
+    : __tree_(_STD::move(__m.__tree_), __a)
+{
+    if (__a != __m.get_allocator())
+    {
+        const_iterator __e = cend();
+        while (!__m.empty())
+            __tree_.__insert_multi(__e.__i_,
+                    _STD::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
+    }
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node()
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second));
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0,
+          class // = typename enable_if<is_convertible<_A0, value_type>::value>::type
+         >
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_), _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder
+multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args)
+{
+    __node_allocator& __na = __tree_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first), _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second), _STD::forward<_Args>(__args)...);
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+#endif
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class //= typename enable_if<is_convertible<_A0, _Key>::value>::type
+         >
+typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
+multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+template <class _A0, class ..._Args,
+          class //= typename enable_if<is_convertible<_A0, _Key>::value>::type
+         >
+typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator
+multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p,
+                                                        _A0&& __a0,
+                                                        _Args&& ...__args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+bool
+operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Allocator>
+inline
+void
+swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
+     multimap<_Key, _Tp, _Compare, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_MAP
diff --git a/include/memory b/include/memory
new file mode 100644
index 0000000..663c470
--- /dev/null
+++ b/include/memory
@@ -0,0 +1,3824 @@
+// -*- C++ -*-
+//===-------------------------- memory ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_MEMORY
+#define _LIBCPP_MEMORY
+
+/*
+    memory synopsis
+
+namespace std
+{
+
+struct allocator_arg_t { };
+constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+
+template <class T, class Alloc> struct uses_allocator;
+
+template <class Ptr>
+struct pointer_traits
+{
+    typedef Ptr pointer;
+    typedef <details> element_type;
+    typedef <details> difference_type;
+    
+    template <class U> using rebind = <details>;
+    
+    static pointer pointer_to(<details>);
+};
+
+template <class Alloc>
+struct allocator_traits
+{
+    typedef Alloc                        allocator_type;
+    typedef typename allocator_type::value_type
+                                         value_type;
+
+    typedef Alloc::pointer | value_type* pointer;
+    typedef Alloc::const_pointer
+          | pointer_traits<pointer>::rebind<const value_type>
+                                         const_pointer;
+    typedef Alloc::void_pointer
+          | pointer_traits<pointer>::rebind<void>
+                                         void_pointer;
+    typedef Alloc::const_void_pointer
+          | pointer_traits<pointer>::rebind<const void>
+                                         const_void_pointer;
+    typedef Alloc::difference_type
+          | ptrdiff_t                    difference_type;
+    typedef Alloc::size_type | size_t    size_type;
+    typedef Alloc::propagate_on_container_copy_assignment
+          | false_type                   propagate_on_container_copy_assignment;
+    typedef Alloc::propagate_on_container_move_assignment
+          | false_type                   propagate_on_container_move_assignment;
+    typedef Alloc::propagate_on_container_swap
+          | false_type                   propagate_on_container_swap;
+
+    template <class T> using rebind_alloc  = Alloc::rebind<U>::other | Alloc<T, Args...>;
+    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
+
+    static pointer allocate(allocator_type& a, size_type n);
+    static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
+
+    static void deallocate(allocator_type& a, pointer p, size_type n);
+
+    template <class T, class... Args>
+        static void construct(allocator_type& a, T* p, Args&&... args);
+
+    template <class T>
+        static void destroy(allocator_type& a, T* p);
+
+    static size_type max_size(const allocator_type& a);
+
+    static allocator_type
+        select_on_container_copy_construction(const allocator_type& a);
+};
+
+template <>
+class allocator<void>
+{
+public:
+    typedef void*                                 pointer;
+    typedef const void*                           const_pointer;
+    typedef void                                  value_type;
+
+    template <class _Up> struct rebind {typedef allocator<_Up> other;};
+};
+
+template <class T>
+class allocator
+{
+public:
+    typedef size_t                                size_type;
+    typedef ptrdiff_t                             difference_type;
+    typedef T*                                    pointer;
+    typedef const T*                              const_pointer;
+    typedef typename add_lvalue_reference<T>::type       reference;
+    typedef typename add_lvalue_reference<const T>::type const_reference;
+    typedef T                                     value_type;
+
+    template <class U> struct rebind {typedef allocator<U> other;};
+
+    allocator() throw();
+    allocator(const allocator&) throw();
+    template <class U> allocator(const allocator<U>&) throw();
+    ~allocator() throw();
+    pointer address(reference x) const;
+    const_pointer address(const_reference x) const;
+    pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
+    void deallocate(pointer p, size_type n);
+    size_type max_size() const throw();
+    void construct(pointer p, const T& val);
+    void destroy(pointer p);
+};
+
+template <class T, class U>
+bool operator==(const allocator<T>&, const allocator<U>&) throw();
+
+template <class T, class U>
+bool operator!=(const allocator<T>&, const allocator<U>&) throw();
+
+template <class OutputIterator, class T>
+class raw_storage_iterator
+    : public iterator<output_iterator_tag,
+                      T,                               // purposefully not C++03
+                      ptrdiff_t,                       // purposefully not C++03
+                      T*,                              // purposefully not C++03
+                      raw_storage_iterator&>           // purposefully not C++03
+{
+public:
+    explicit raw_storage_iterator(OutputIterator x);
+    raw_storage_iterator& operator*();
+    raw_storage_iterator& operator=(const T& element);
+    raw_storage_iterator& operator++();
+    raw_storage_iterator  operator++(int);
+};
+
+template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n);
+template <class T> void               return_temporary_buffer(T* p);
+
+template <class InputIterator, class ForwardIterator>
+ForwardIterator
+uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
+
+template <class ForwardIterator, class T>
+void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
+
+template <class ForwardIterator, class Size, class T>
+void uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
+
+template <class Y> struct auto_ptr_ref {};
+
+template<class X>
+class auto_ptr
+{
+public:
+    typedef X element_type;
+
+    explicit auto_ptr(X* p =0) throw();
+    auto_ptr(auto_ptr&) throw();
+    template<class Y> auto_ptr(auto_ptr<Y>&) throw();
+    auto_ptr& operator=(auto_ptr&) throw();
+    template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
+    auto_ptr& operator=(auto_ptr_ref<X> r) throw();
+    ~auto_ptr() throw();
+
+    typename add_lvalue_reference<X>::type operator*() const throw();
+    X* operator->() const throw();
+    X* get() const throw();
+    X* release() throw();
+    void reset(X* p =0) throw();
+
+    auto_ptr(auto_ptr_ref<X>) throw();
+    template<class Y> operator auto_ptr_ref<Y>() throw();
+    template<class Y> operator auto_ptr<Y>() throw();
+};
+
+void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <type_traits>
+#include <typeinfo>
+#include <cstddef>
+#include <cstdint>
+#include <new>
+#include <utility>
+#include <limits>
+#include <iterator>
+#include <__functional_base>
+#if defined(_LIBCPP_NO_EXCEPTIONS)
+    #include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// allocator_arg_t
+
+struct allocator_arg_t { }; 
+
+extern const allocator_arg_t allocator_arg;
+
+// addressof
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+addressof(_Tp& __x)
+{
+    return (_Tp*)&(char&)__x;
+}
+
+template <class _Tp> class allocator;
+
+template <>
+class allocator<void>
+{
+public:
+    typedef void*             pointer;
+    typedef const void*       const_pointer;
+    typedef void              value_type;
+
+    template <class _Up> struct rebind {typedef allocator<_Up> other;};
+};
+
+
+// pointer_traits
+
+template <class _Tp>
+struct __has_element_type
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::element_type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, bool = __has_element_type<_Ptr>::value>
+struct __pointer_traits_element_type;
+
+template <class _Ptr>
+struct __pointer_traits_element_type<_Ptr, true>
+{
+    typedef typename _Ptr::element_type type;
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args>
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
+{
+    typedef typename _Sp<_Tp, _Args...>::element_type type;
+};
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args>
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
+{
+    typedef _Tp type;
+};
+
+#else
+
+template <template <class> class _Sp, class _Tp>
+struct __pointer_traits_element_type<_Sp<_Tp>, true>
+{
+    typedef typename _Sp<_Tp>::element_type type;
+};
+
+template <template <class> class _Sp, class _Tp>
+struct __pointer_traits_element_type<_Sp<_Tp>, false>
+{
+    typedef _Tp type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
+{
+    typedef typename _Sp<_Tp, _A0>::element_type type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
+{
+    typedef _Tp type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
+{
+    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
+{
+    typedef _Tp type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+                                                           class _A1, class _A2>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
+{
+    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+                                                           class _A1, class _A2>
+struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
+{
+    typedef _Tp type;
+};
+
+#endif
+
+template <class _Tp>
+struct __has_difference_type
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::difference_type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
+struct __pointer_traits_difference_type
+{
+    typedef ptrdiff_t type;
+};
+
+template <class _Ptr>
+struct __pointer_traits_difference_type<_Ptr, true>
+{
+    typedef typename _Ptr::difference_type type;
+};
+
+template <class _Tp, class _Up>
+struct __has_rebind
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Xp> static __two __test(...);
+    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
+struct __pointer_traits_rebind
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Tp::template rebind<_Up> type;
+#else
+    typedef typename _Tp::template rebind<_Up>::other type;
+#endif
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
+#else
+    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
+{
+    typedef _Sp<_Up, _Args...> type;
+};
+
+#else
+
+template <template <class> class _Sp, class _Tp, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Sp<_Tp>::template rebind<_Up> type;
+#else
+    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class> class _Sp, class _Tp, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
+{
+    typedef _Sp<_Up> type;
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
+#else
+    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
+{
+    typedef _Sp<_Up, _A0> type;
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0,
+                                         class _A1, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
+#else
+    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class, class> class _Sp, class _Tp, class _A0,
+                                         class _A1, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
+{
+    typedef _Sp<_Up, _A0, _A1> type;
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+                                                class _A1, class _A2, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
+#else
+    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
+#endif
+};
+
+template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
+                                                class _A1, class _A2, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
+{
+    typedef _Sp<_Up, _A0, _A1, _A2> type;
+};
+
+#endif
+
+template <class _Ptr>
+struct pointer_traits
+{
+    typedef _Ptr                                                     pointer;
+    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
+    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    template <class _Up> using rebind = __pointer_traits_rebind<pointer, _Up>::type;
+#else
+    template <class _Up> struct rebind
+        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
+#endif
+
+private:
+    struct __nat {};
+public:
+    static pointer pointer_to(typename conditional<is_void<element_type>::value,
+                                           __nat, element_type>::type& __r)
+        {return pointer::pointer_to(__r);}
+};
+
+template <class _Tp>
+struct pointer_traits<_Tp*>
+{
+    typedef _Tp*      pointer;
+    typedef _Tp       element_type;
+    typedef ptrdiff_t difference_type;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    template <class _Up> using rebind = _Up*;
+#else
+    template <class _Up> struct rebind {typedef _Up* other;};
+#endif
+
+private:
+    struct __nat {};
+public:
+    static pointer pointer_to(typename conditional<is_void<element_type>::value,
+                                           __nat, element_type>::type& __r)
+        {return _STD::addressof(__r);}
+};
+
+// allocator_traits
+
+namespace __has_pointer_type_imp
+{
+    template <class _Up> static __two test(...);
+    template <class _Up> static char test(typename _Up::pointer* = 0);
+}
+
+template <class _Tp>
+struct __has_pointer_type
+    : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
+{
+};
+
+namespace __pointer_type_imp
+{
+
+template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
+struct __pointer_type
+{
+    typedef typename _Dp::pointer type;
+};
+
+template <class _Tp, class _Dp>
+struct __pointer_type<_Tp, _Dp, false>
+{
+    typedef _Tp* type;
+};
+
+}
+
+template <class _Tp, class _Dp>
+struct __pointer_type
+{
+    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
+};
+
+template <class _Tp>
+struct __has_const_pointer
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::const_pointer* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
+struct __const_pointer
+{
+    typedef typename _Alloc::const_pointer type;
+};
+
+template <class _Tp, class _Ptr, class _Alloc>
+struct __const_pointer<_Tp, _Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
+#else
+    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
+#endif
+};
+
+template <class _Tp>
+struct __has_void_pointer
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::void_pointer* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
+struct __void_pointer
+{
+    typedef typename _Alloc::void_pointer type;
+};
+
+template <class _Ptr, class _Alloc>
+struct __void_pointer<_Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
+#else
+    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
+#endif
+};
+
+template <class _Tp>
+struct __has_const_void_pointer
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
+struct __const_void_pointer
+{
+    typedef typename _Alloc::const_void_pointer type;
+};
+
+template <class _Ptr, class _Alloc>
+struct __const_void_pointer<_Ptr, _Alloc, false>
+{
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
+#else
+    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
+#endif
+};
+
+template <class _T>
+inline _LIBCPP_INLINE_VISIBILITY
+_T*
+__to_raw_pointer(_T* __p)
+{
+    return __p;
+}
+
+template <class _Pointer>
+inline _LIBCPP_INLINE_VISIBILITY
+typename pointer_traits<_Pointer>::element_type*
+__to_raw_pointer(_Pointer __p)
+{
+    return _STD::__to_raw_pointer(__p.operator->());
+}
+
+template <class _Tp>
+struct __has_size_type
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::size_type* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_size_type<_Alloc>::value>
+struct __size_type
+{
+    typedef size_t type;
+};
+
+template <class _Alloc>
+struct __size_type<_Alloc, true>
+{
+    typedef typename _Alloc::size_type type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_copy_assignment
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
+struct __propagate_on_container_copy_assignment
+{
+    typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_copy_assignment<_Alloc, true>
+{
+    typedef typename _Alloc::propagate_on_container_copy_assignment type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_move_assignment
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
+struct __propagate_on_container_move_assignment
+{
+    typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_move_assignment<_Alloc, true>
+{
+    typedef typename _Alloc::propagate_on_container_move_assignment type;
+};
+
+template <class _Tp>
+struct __has_propagate_on_container_swap
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Up> static __two __test(...);
+    template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
+struct __propagate_on_container_swap
+{
+    typedef false_type type;
+};
+
+template <class _Alloc>
+struct __propagate_on_container_swap<_Alloc, true>
+{
+    typedef typename _Alloc::propagate_on_container_swap type;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
+struct __has_rebind_other
+{
+private:
+    struct __two {char _; char __;};
+    template <class _Xp> static __two __test(...);
+    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
+public:
+    static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Tp, class _Up>
+struct __has_rebind_other<_Tp, _Up, false>
+{
+    static const bool value = false;
+};
+
+template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
+struct __allocator_traits_rebind
+{
+    typedef typename _Tp::template rebind<_Up>::other type;
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
+{
+    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
+};
+
+template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
+{
+    typedef _Alloc<_Up, _Args...> type;
+};
+
+#else
+
+template <template <class> class _Alloc, class _Tp, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
+{
+    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
+};
+
+template <template <class> class _Alloc, class _Tp, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
+{
+    typedef _Alloc<_Up> type;
+};
+
+
+template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
+{
+    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
+};
+
+template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
+{
+    typedef _Alloc<_Up, _A0> type;
+};
+
+
+template <template <class, class, class> class _Alloc, class _Tp, class _A0,
+                                         class _A1, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
+{
+    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
+};
+
+template <template <class, class, class> class _Alloc, class _Tp, class _A0,
+                                         class _A1, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
+{
+    typedef _Alloc<_Up, _A0, _A1> type;
+};
+
+
+template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
+                                                class _A1, class _A2, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
+{
+    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
+};
+
+template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
+                                                class _A1, class _A2, class _Up>
+struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
+{
+    typedef _Alloc<_Up, _A0, _A1, _A2> type;
+};
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+auto
+__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
+    -> decltype(__a.allocate(__sz, __p), true_type());
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+auto
+__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
+    -> false_type;
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+struct __has_allocate_hint
+    : integral_constant<bool,
+        is_same<
+            decltype(__has_allocate_hint_test(declval<_Alloc>(),
+                                          declval<_SizeType>(),
+                                          declval<_ConstVoidPtr>())),
+            true_type>::value>
+{
+};
+
+#else
+
+template <class _Alloc, class _SizeType, class _ConstVoidPtr>
+struct __has_allocate_hint
+    : true_type
+{
+};
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+template <class _Alloc, class _Tp, class ..._Args>
+decltype(_STD::declval<_Alloc>().construct(_STD::declval<_Tp*>(),
+                                           _STD::declval<_Args>()...),
+                                           true_type())
+__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
+
+template <class _Alloc, class _Pointer, class ..._Args>
+false_type
+__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
+
+template <class _Alloc, class _Pointer, class ..._Args>
+struct __has_construct
+    : integral_constant<bool,
+        is_same<
+            decltype(__has_construct_test(declval<_Alloc>(),
+                                          declval<_Pointer>(),
+                                          declval<_Args>()...)),
+            true_type>::value>
+{
+};
+
+template <class _Alloc, class _Pointer>
+auto
+__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
+    -> decltype(__a.destroy(__p), true_type());
+
+template <class _Alloc, class _Pointer>
+auto
+__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
+    -> false_type;
+
+template <class _Alloc, class _Pointer>
+struct __has_destroy
+    : integral_constant<bool,
+        is_same<
+            decltype(__has_destroy_test(declval<_Alloc>(),
+                                        declval<_Pointer>())),
+            true_type>::value>
+{
+};
+
+template <class _Alloc>
+auto
+__has_max_size_test(_Alloc&& __a)
+    -> decltype(__a.max_size(), true_type());
+
+template <class _Alloc>
+auto
+__has_max_size_test(const volatile _Alloc& __a)
+    -> false_type;
+
+template <class _Alloc>
+struct __has_max_size
+    : integral_constant<bool,
+        is_same<
+            decltype(__has_max_size_test(declval<_Alloc&>())),
+            true_type>::value>
+{
+};
+
+template <class _Alloc>
+auto
+__has_select_on_container_copy_construction_test(_Alloc&& __a)
+    -> decltype(__a.select_on_container_copy_construction(), true_type());
+
+template <class _Alloc>
+auto
+__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
+    -> false_type;
+
+template <class _Alloc>
+struct __has_select_on_container_copy_construction
+    : integral_constant<bool,
+        is_same<
+            decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
+            true_type>::value>
+{
+};
+
+#else
+
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Alloc, class _Pointer, class ..._Args>
+struct __has_construct
+    : false_type
+{
+};
+
+#endif
+
+template <class _Alloc, class _Pointer>
+struct __has_destroy
+    : false_type
+{
+};
+
+template <class _Alloc>
+struct __has_max_size
+    : true_type
+{
+};
+
+template <class _Alloc>
+struct __has_select_on_container_copy_construction
+    : false_type
+{
+};
+
+#endif
+
+template <class _Alloc>
+struct allocator_traits
+{
+    typedef _Alloc                              allocator_type;
+    typedef typename allocator_type::value_type value_type;
+
+    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
+    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
+    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
+    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
+
+    typedef typename __pointer_traits_difference_type<allocator_type>::type difference_type;
+    typedef typename __size_type<allocator_type>::type size_type;
+
+    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
+                     propagate_on_container_copy_assignment;
+    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
+                     propagate_on_container_move_assignment;
+    typedef typename __propagate_on_container_swap<allocator_type>::type
+                     propagate_on_container_swap;
+
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+    template <class _Tp> using rebind_alloc =
+                           __allocator_traits_rebind<allocator_type, _Tp>::type;
+    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
+#else
+    template <class _Tp> struct rebind_alloc
+        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
+    template <class _Tp> struct rebind_traits
+        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
+#endif
+
+    static pointer allocate(allocator_type& __a, size_type __n)
+        {return __a.allocate(__n);}
+    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
+        {return allocate(__a, __n, __hint,
+            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
+
+    static void deallocate(allocator_type& __a, pointer __p, size_type __n)
+        {__a.deallocate(__p, __n);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _Tp, class... _Args>
+        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
+            {__construct(__has_construct<allocator_type, pointer, _Args...>(),
+                         __a, __p, _STD::forward<_Args>(__args)...);}
+#else
+    template <class _Tp>
+        static void construct(allocator_type& __a, _Tp* __p)
+            {
+                ::new ((void*)__p) _Tp();
+            }
+    template <class _Tp, class _A0>
+        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
+            {
+                ::new ((void*)__p) _Tp(__a0);
+            }
+    template <class _Tp, class _A0, class _A1>
+        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
+                              const _A1& __a1)
+            {
+                ::new ((void*)__p) _Tp(__a0, __a1);
+            }
+    template <class _Tp, class _A0, class _A1, class _A2>
+        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
+                              const _A1& __a1, const _A2& __a2)
+            {
+                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
+            }
+#endif
+
+    template <class _Tp>
+        static void destroy(allocator_type& __a, _Tp* __p)
+            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
+
+    static size_type max_size(const allocator_type& __a)
+        {return __max_size(__has_max_size<const allocator_type>(), __a);}
+
+    static allocator_type
+        select_on_container_copy_construction(const allocator_type& __a)
+            {return select_on_container_copy_construction(
+                __has_select_on_container_copy_construction<const allocator_type>(),
+                __a);}
+
+private:
+
+    static pointer allocate(allocator_type& __a, size_type __n,
+        const_void_pointer __hint, true_type)
+        {return __a.allocate(__n, __hint);}
+    static pointer allocate(allocator_type& __a, size_type __n,
+        const_void_pointer __hint, false_type)
+        {return __a.allocate(__n);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _Tp, class... _Args>
+        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
+            {__a.construct(__p, _STD::forward<_Args>(__args)...);}
+    template <class _Tp, class... _Args>
+        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
+            {
+                ::new ((void*)__p) _Tp(_STD::forward<_Args>(__args)...);
+            }
+#endif
+
+    template <class _Tp>
+        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
+            {__a.destroy(__p);}
+    template <class _Tp>
+        static void __destroy(false_type, allocator_type&, _Tp* __p)
+            {
+                __p->~_Tp();
+            }
+
+    static size_type __max_size(true_type, const allocator_type& __a)
+            {return __a.max_size();}
+    static size_type __max_size(false_type, const allocator_type&)
+            {return numeric_limits<size_type>::max();}
+
+    static allocator_type
+        select_on_container_copy_construction(true_type, const allocator_type& __a)
+            {return __a.select_on_container_copy_construction();}
+    static allocator_type
+        select_on_container_copy_construction(false_type, const allocator_type& __a)
+            {return __a;}
+};
+
+// uses_allocator
+
+template <class _Tp>
+struct __has_allocator_type
+{
+private:
+    struct __two {char _; char __;};
+    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 uses_allocator
+    : public __uses_allocator<_Tp, _Alloc>
+{
+};
+
+#ifdef _LIBCPP_MOVE
+
+// uses-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>
+    {};
+
+// scoped_allocator_adaptor
+
+template <class ..._Allocs>
+class scoped_allocator_adaptor;
+
+template <class ..._Allocs> struct __get_poc_copy_assignment;
+
+template <class _A0>
+struct __get_poc_copy_assignment<_A0>
+{
+    static const bool value = allocator_traits<_A0>::
+                              propagate_on_container_copy_assignment::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_copy_assignment<_A0, _Allocs...>
+{
+    static const bool value =
+        allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
+        __get_poc_copy_assignment<_Allocs...>::value;
+};
+
+template <class ..._Allocs> struct __get_poc_move_assignment;
+
+template <class _A0>
+struct __get_poc_move_assignment<_A0>
+{
+    static const bool value = allocator_traits<_A0>::
+                              propagate_on_container_move_assignment::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_move_assignment<_A0, _Allocs...>
+{
+    static const bool value =
+        allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
+        __get_poc_move_assignment<_Allocs...>::value;
+};
+
+template <class ..._Allocs> struct __get_poc_swap;
+
+template <class _A0>
+struct __get_poc_swap<_A0>
+{
+    static const bool value = allocator_traits<_A0>::
+                              propagate_on_container_swap::value;
+};
+
+template <class _A0, class ..._Allocs>
+struct __get_poc_swap<_A0, _Allocs...>
+{
+    static const bool value =
+        allocator_traits<_A0>::propagate_on_container_swap::value ||
+        __get_poc_swap<_Allocs...>::value;
+};
+
+template <class ..._Allocs>
+class __scoped_allocator_storage;
+
+template <class _OuterAlloc, class... _InnerAllocs>
+class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
+    : public _OuterAlloc
+{
+    typedef _OuterAlloc outer_allocator_type;
+protected:
+    typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
+
+private:
+    inner_allocator_type __inner_;
+
+protected:
+    
+    __scoped_allocator_storage() {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        __scoped_allocator_storage(_OuterA2&& __outerAlloc,
+                                   const _InnerAllocs& ...__innerAllocs)
+            : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)),
+              __inner_(__innerAllocs...) {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, const _OuterA2&>::value
+                      >::type>
+        __scoped_allocator_storage(
+            const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other)
+            : outer_allocator_type(__other.outer_allocator()),
+              __inner_(__other.inner_allocator()) {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        __scoped_allocator_storage(
+            __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other)
+            : outer_allocator_type(_STD::move(__other.outer_allocator())),
+              __inner_(_STD::move(__other.inner_allocator())) {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+    __scoped_allocator_storage(_OuterA2&& __o,
+                               const inner_allocator_type& __i)
+        : outer_allocator_type(_STD::forward<_OuterA2>(__o)),
+          __inner_(__i)
+    {
+    }
+
+    inner_allocator_type& inner_allocator()             {return __inner_;}
+    const inner_allocator_type& inner_allocator() const {return __inner_;}
+
+    outer_allocator_type& outer_allocator()
+        {return static_cast<outer_allocator_type&>(*this);}
+    const outer_allocator_type& outer_allocator() const
+        {return static_cast<const outer_allocator_type&>(*this);}
+
+    scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
+    select_on_container_copy_construction() const
+        {
+            return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
+            (
+                allocator_traits<outer_allocator_type>::
+                    select_on_container_copy_construction(outer_allocator()),
+                allocator_traits<inner_allocator_type>::
+                    select_on_container_copy_construction(inner_allocator())
+            );
+        }
+
+    template <class...> friend class __scoped_allocator_storage;
+};
+
+template <class _OuterAlloc>
+class __scoped_allocator_storage<_OuterAlloc>
+    : public _OuterAlloc
+{
+    typedef _OuterAlloc outer_allocator_type;
+protected:
+    typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
+
+    __scoped_allocator_storage() {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        __scoped_allocator_storage(_OuterA2&& __outerAlloc)
+            : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)) {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, const _OuterA2&>::value
+                      >::type>
+        __scoped_allocator_storage(
+            const __scoped_allocator_storage<_OuterA2>& __other)
+            : outer_allocator_type(__other.outer_allocator()) {}
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        __scoped_allocator_storage(
+            __scoped_allocator_storage<_OuterA2>&& __other)
+            : outer_allocator_type(_STD::move(__other.outer_allocator())) {}
+
+    inner_allocator_type& inner_allocator()
+        {return static_cast<inner_allocator_type&>(*this);}
+    const inner_allocator_type& inner_allocator() const
+        {return static_cast<const inner_allocator_type&>(*this);}
+
+    outer_allocator_type& outer_allocator()
+        {return static_cast<outer_allocator_type&>(*this);}
+    const outer_allocator_type& outer_allocator() const
+        {return static_cast<const outer_allocator_type&>(*this);}
+
+    scoped_allocator_adaptor<outer_allocator_type>
+    select_on_container_copy_construction() const
+        {return scoped_allocator_adaptor<outer_allocator_type>(
+            allocator_traits<outer_allocator_type>::
+                select_on_container_copy_construction(outer_allocator())
+        );}
+
+    __scoped_allocator_storage(const outer_allocator_type& __o,
+                               const inner_allocator_type& __i);
+
+    template <class...> friend class __scoped_allocator_storage;
+};
+
+// __outermost
+
+template <class _Alloc>
+decltype(declval<_Alloc>().outer_allocator(), true_type())
+__has_outer_allocator_test(_Alloc&& __a);
+
+template <class _Alloc>
+false_type
+__has_outer_allocator_test(const volatile _Alloc& __a);
+
+template <class _Alloc>
+struct __has_outer_allocator
+    : public common_type
+             <
+                 decltype(__has_outer_allocator_test(declval<_Alloc&>()))
+             >::type
+{
+};
+
+template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
+struct __outermost
+{
+    typedef _Alloc type;
+    type& operator()(type& __a) const {return __a;}
+};
+
+template <class _Alloc>
+struct __outermost<_Alloc, true>
+{
+    typedef typename remove_reference
+                     <
+                        decltype(_STD::declval<_Alloc>().outer_allocator())
+                     >::type                                    _OuterAlloc;
+    typedef typename __outermost<_OuterAlloc>::type             type;
+    type& operator()(_Alloc& __a) const
+        {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
+};
+
+template <class _OuterAlloc, class... _InnerAllocs>
+class scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
+    : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
+{
+    typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
+    typedef allocator_traits<_OuterAlloc>             _OuterTraits;
+public:
+    typedef _OuterAlloc                               outer_allocator_type;
+    typedef typename base::inner_allocator_type       inner_allocator_type;
+    typedef typename _OuterTraits::size_type          size_type;
+    typedef typename _OuterTraits::difference_type    difference_type;
+    typedef typename _OuterTraits::pointer            pointer;
+    typedef typename _OuterTraits::const_pointer      const_pointer;
+    typedef typename _OuterTraits::void_pointer       void_pointer;
+    typedef typename _OuterTraits::const_void_pointer const_void_pointer;
+
+    typedef integral_constant
+            <
+                bool,
+                __get_poc_copy_assignment<outer_allocator_type,
+                                          _InnerAllocs...>::value
+            > propagate_on_container_copy_assignment;
+    typedef integral_constant
+            <
+                bool,
+                __get_poc_move_assignment<outer_allocator_type,
+                                          _InnerAllocs...>::value
+            > propagate_on_container_move_assignment;
+    typedef integral_constant
+            <
+                bool,
+                __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
+            > propagate_on_container_swap;
+
+    template <class _Tp>
+    struct rebind
+    {
+        typedef scoped_allocator_adaptor
+        <
+            typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
+        > other;
+    };
+
+    scoped_allocator_adaptor() {}
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
+                                 const _InnerAllocs& ...__innerAllocs)
+            : base(_STD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
+    // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, const _OuterA2&>::value
+                      >::type>
+        scoped_allocator_adaptor(
+            const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other)
+                : base(__other) {}
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+        scoped_allocator_adaptor(
+            scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other)
+                : base(_STD::move(__other)) {}
+
+    // ~scoped_allocator_adaptor() = default;
+
+    inner_allocator_type& inner_allocator()
+        {return base::inner_allocator();}
+    const inner_allocator_type& inner_allocator() const
+        {return base::inner_allocator();}
+
+    outer_allocator_type& outer_allocator()
+        {return base::outer_allocator();}
+    const outer_allocator_type& outer_allocator() const
+        {return base::outer_allocator();}
+
+    pointer allocate(size_type __n)
+        {return allocator_traits<outer_allocator_type>::
+            allocate(outer_allocator(), __n);}
+    pointer allocate(size_type __n, const_void_pointer __hint)
+        {return allocator_traits<outer_allocator_type>::
+            allocate(outer_allocator(), __n, __hint);}
+
+    void deallocate(pointer __p, size_type __n)
+        {allocator_traits<outer_allocator_type>::
+            deallocate(outer_allocator(), __p, __n);}
+
+    size_type max_size() const
+        {allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
+
+    template <class _Tp, class... _Args>
+        void construct(_Tp* __p, _Args&& ...__args)
+            {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(),
+                         __p, _STD::forward<_Args>(__args)...);}
+    template <class _Tp>
+        void destroy(_Tp* __p)
+            {
+                typedef __outermost<outer_allocator_type> _OM;
+                allocator_traits<typename _OM::type>::
+                                         destroy(_OM()(outer_allocator()), __p);
+            }
+
+    scoped_allocator_adaptor select_on_container_copy_construction() const
+        {return base::select_on_container_copy_construction();}
+
+private:
+
+    template <class _OuterA2,
+              class = typename enable_if<
+                        is_constructible<outer_allocator_type, _OuterA2>::value
+                      >::type>
+    scoped_allocator_adaptor(_OuterA2&& __o,
+                             const inner_allocator_type& __i)
+        : base(_STD::forward<_OuterA2>(__o), __i) {}
+
+    template <class _Tp, class... _Args>
+        void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
+            {
+                typedef __outermost<outer_allocator_type> _OM;
+                allocator_traits<typename _OM::type>::construct
+                (
+                    _OM()(outer_allocator()),
+                    __p,
+                    _STD::forward<_Args>(__args)...
+                );
+            }
+
+    template <class _Tp, class... _Args>
+        void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
+            {
+                typedef __outermost<outer_allocator_type> _OM;
+                allocator_traits<typename _OM::type>::construct
+                (
+                    _OM()(outer_allocator()),
+                    __p,
+                    allocator_arg,
+                    inner_allocator(),
+                    _STD::forward<_Args>(__args)...
+                );
+            }
+
+    template <class _Tp, class... _Args>
+        void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
+            {
+                typedef __outermost<outer_allocator_type> _OM;
+                allocator_traits<typename _OM::type>::construct
+                (
+                    _OM()(outer_allocator()),
+                    __p,
+                    _STD::forward<_Args>(__args)...,
+                    inner_allocator()
+                );
+            }
+
+    template <class...> friend class __scoped_allocator_storage;
+};
+
+template <class _OuterA1, class _OuterA2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
+           const scoped_allocator_adaptor<_OuterA2>& __b)
+{
+    return __a.outer_allocator() == __b.outer_allocator();
+}
+
+template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
+           const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b)
+{
+    return __a.outer_allocator() == __b.outer_allocator() &&
+           __a.inner_allocator() == __b.inner_allocator();
+}
+
+template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
+           const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b)
+{
+    return !(__a == __b);
+}
+
+#endif
+
+// allocator
+
+template <class _Tp>
+class allocator
+{
+public:
+    typedef size_t            size_type;
+    typedef ptrdiff_t         difference_type;
+    typedef _Tp*              pointer;
+    typedef const _Tp*        const_pointer;
+    typedef _Tp&              reference;
+    typedef const _Tp&        const_reference;
+    typedef _Tp               value_type;
+
+    template <class _Up> struct rebind {typedef allocator<_Up> other;};
+
+    _LIBCPP_INLINE_VISIBILITY allocator() throw() {}
+    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) throw() {}
+    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const             {return addressof(__x);}
+    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const {return addressof(__x);}
+    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
+        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
+    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) {::operator delete((void*)__p);}
+    _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
+#ifdef _LIBCPP_MOVE
+    template <class _Up, class... _Args>
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(_Up* __p, _Args&&... __args)
+        {
+            ::new((void*)__p) _Up(_STD::forward<_Args>(__args)...);
+        }
+#else
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(pointer __p)
+        {
+            ::new((void*)__p) _Tp();
+        }
+    template <class _A0>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            !is_convertible<_A0, __rv<_A0> >::value,
+            void
+        >::type
+        construct(pointer __p, _A0& __a0)
+        {
+            ::new((void*)__p) _Tp(__a0);
+        }
+    template <class _A0>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            !is_convertible<_A0, __rv<_A0> >::value,
+            void
+        >::type
+        construct(pointer __p, const _A0& __a0)
+        {
+            ::new((void*)__p) _Tp(__a0);
+        }
+    template <class _A0>
+        _LIBCPP_INLINE_VISIBILITY
+        typename enable_if
+        <
+            is_convertible<_A0, __rv<_A0> >::value,
+            void
+        >::type
+        construct(pointer __p, _A0 __a0)
+        {
+            ::new((void*)__p) _Tp(_STD::move(__a0));
+        }
+    template <class _A0, class _A1>
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(pointer __p, _A0& __a0, _A1& __a1)
+        {
+            ::new((void*)__p) _Tp(__a0, __a1);
+        }
+    template <class _A0, class _A1>
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(pointer __p, const _A0& __a0, _A1& __a1)
+        {
+            ::new((void*)__p) _Tp(__a0, __a1);
+        }
+    template <class _A0, class _A1>
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(pointer __p, _A0& __a0, const _A1& __a1)
+        {
+            ::new((void*)__p) _Tp(__a0, __a1);
+        }
+    template <class _A0, class _A1>
+        _LIBCPP_INLINE_VISIBILITY
+        void
+        construct(pointer __p, const _A0& __a0, const _A1& __a1)
+        {
+            ::new((void*)__p) _Tp(__a0, __a1);
+        }
+#endif
+    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
+};
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator==(const allocator<_Tp>&, const allocator<_Up>&) throw() {return true;}
+
+template <class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) throw() {return false;}
+
+template <class _OutputIterator, class _Tp>
+class raw_storage_iterator
+    : public iterator<output_iterator_tag,
+                      _Tp,                                         // purposefully not C++03
+                      ptrdiff_t,                                   // purposefully not C++03
+                      _Tp*,                                        // purposefully not C++03
+                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
+{
+private:
+    _OutputIterator __x_;
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
+        {::new(&*__x_) _Tp(__element); return *this;}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
+    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
+        {raw_storage_iterator __t(*this); ++__x_; return __t;}
+};
+
+template <class _Tp>
+pair<_Tp*, ptrdiff_t>
+get_temporary_buffer(ptrdiff_t __n)
+{
+    pair<_Tp*, ptrdiff_t> __r(0, 0);
+    const ptrdiff_t __m = (~ptrdiff_t(0) ^
+                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
+                           / sizeof(_Tp);
+    if (__n > __m)
+        __n = __m;
+    while (__n > 0)
+    {
+        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
+        if (__r.first)
+        {
+            __r.second = __n;
+            break;
+        }
+        __n /= 2;
+    }
+    return __r;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void return_temporary_buffer(_Tp* __p) {::operator delete(__p);}
+
+template <class _Tp>
+struct auto_ptr_ref
+{
+    _Tp* __ptr_;
+};
+
+template<class _Tp>
+class auto_ptr
+{
+private:
+    _Tp* __ptr_;
+public:
+    typedef _Tp element_type;
+
+    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
+    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
+    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
+        : __ptr_(__p.release()) {}
+    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
+        {reset(__p.release()); return *this;}
+    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
+        {reset(__p.release()); return *this;}
+    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
+        {reset(__p.__ptr_); return *this;}
+    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
+
+    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
+        {return *__ptr_;}
+    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
+    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
+    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
+    {
+        _Tp* __t = __ptr_;
+        __ptr_ = 0;
+        return __t;
+    }
+    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
+    {
+        if (__ptr_ != __p)
+            delete __ptr_;
+        __ptr_ = __p;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
+    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
+        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
+    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
+        {return auto_ptr<_Up>(release());}
+};
+
+template <>
+class auto_ptr<void>
+{
+public:
+    typedef void element_type;
+};
+
+
+template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
+                                                     typename remove_cv<_T2>::type>::value,
+                                bool = is_empty<_T1>::value,
+                                bool = is_empty<_T2>::value>
+struct __libcpp_compressed_pair_switch;
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
+
+template <class _T1, class _T2, bool IsSame>
+struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
+
+template <class _T1, class _T2>
+struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
+
+template <class _T1, class _T2>
+struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
+
+template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
+class __libcpp_compressed_pair_imp;
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 0>
+{
+private:
+    _T1 __first_;
+    _T2 __second_;
+public:
+    typedef _T1 _T1_param;
+    typedef _T2 _T2_param;
+
+    typedef typename remove_reference<_T1>::type& _T1_reference;
+    typedef typename remove_reference<_T2>::type& _T2_reference;
+
+    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
+    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+        : __first_(_STD::forward<_T1_param>(__t1)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+        : __second_(_STD::forward<_T2_param>(__t2)) {}
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+        : __first_(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+        : __first_(_STD::forward<_T1>(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {}
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY _T1_reference       first()       {return __first_;}
+    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;}
+
+    _LIBCPP_INLINE_VISIBILITY _T2_reference       second()       {return __second_;}
+    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;}
+
+    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+    {
+        using _STD::swap;
+        swap(__first_, __x.__first_);
+        swap(__second_, __x.__second_);
+    }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 1>
+    : private _T1
+{
+private:
+    _T2 __second_;
+public:
+    typedef _T1 _T1_param;
+    typedef _T2 _T2_param;
+
+    typedef _T1&                                        _T1_reference;
+    typedef typename remove_reference<_T2>::type& _T2_reference;
+
+    typedef const _T1&                                        _T1_const_reference;
+    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+        : _T1(_STD::forward<_T1_param>(__t1)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+        : __second_(_STD::forward<_T2_param>(__t2)) {}
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+        : _T1(_STD::forward<_T1_param>(__t1)), __second_(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+        : _T1(_STD::move(__p.first())), __second_(_STD::forward<_T2>(__p.second())) {}
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY _T1_reference       first()       {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY _T2_reference       second()       {return __second_;}
+    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return __second_;}
+
+    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+    {
+        using _STD::swap;
+        swap(__second_, __x.__second_);
+    }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 2>
+    : private _T2
+{
+private:
+    _T1 __first_;
+public:
+    typedef _T1 _T1_param;
+    typedef _T2 _T2_param;
+
+    typedef typename remove_reference<_T1>::type& _T1_reference;
+    typedef _T2&                                        _T2_reference;
+
+    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
+    typedef const _T2&                                        _T2_const_reference;
+
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
+        : __first_(_STD::forward<_T1_param>(__t1)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
+        : _T2(_STD::forward<_T2_param>(__t2)) {}
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+        : _T2(_STD::forward<_T2_param>(__t2)), __first_(_STD::forward<_T1_param>(__t1)) {}
+
+#ifdef _LIBCPP_MOVE
+    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+        : _T2(_STD::forward<_T2>(__p.second())), __first_(_STD::move(__p.first())) {}
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY _T1_reference       first()       {return __first_;}
+    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return __first_;}
+
+    _LIBCPP_INLINE_VISIBILITY _T2_reference       second()       {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+    {
+        using _STD::swap;
+        swap(__first_, __x.__first_);
+    }
+};
+
+template <class _T1, class _T2>
+class __libcpp_compressed_pair_imp<_T1, _T2, 3>
+    : private _T1,
+      private _T2
+{
+public:
+    typedef _T1 _T1_param;
+    typedef _T2 _T2_param;
+
+    typedef _T1& _T1_reference;
+    typedef _T2& _T2_reference;
+
+    typedef const _T1& _T1_const_reference;
+    typedef const _T2& _T2_const_reference;
+
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
+        : _T1(_STD::forward<_T1_param>(__t1)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
+        : _T2(_STD::forward<_T2_param>(__t2)) {}
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+        : _T1(_STD::forward<_T1_param>(__t1)), _T2(_STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
+        : _T1(_STD::move(__p.first())), _T2(_STD::move(__p.second())) {}
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY _T1_reference       first()       {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY _T2_reference       second()       {return *this;}
+    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return *this;}
+
+    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+    {
+    }
+};
+
+template <class _T1, class _T2>
+class __compressed_pair
+    : private __libcpp_compressed_pair_imp<_T1, _T2>
+{
+    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
+public:
+    typedef typename base::_T1_param _T1_param;
+    typedef typename base::_T2_param _T2_param;
+
+    typedef typename base::_T1_reference _T1_reference;
+    typedef typename base::_T2_reference _T2_reference;
+
+    typedef typename base::_T1_const_reference _T1_const_reference;
+    typedef typename base::_T2_const_reference _T2_const_reference;
+
+    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
+    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0)
+        : base(_STD::forward<_T1_param>(__t1)) {}
+    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0)
+        : base(_STD::forward<_T2_param>(__t2)) {}
+    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
+        : base(_STD::forward<_T1_param>(__t1), _STD::forward<_T2_param>(__t2)) {}
+
+#ifdef _LIBCPP_MOVE
+    __compressed_pair(__compressed_pair&& __p)
+        : base(_STD::move(__p)) {}
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY _T1_reference       first()       {return base::first();}
+    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const {return base::first();}
+
+    _LIBCPP_INLINE_VISIBILITY _T2_reference       second()       {return base::second();}
+    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const {return base::second();}
+
+    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x) {base::swap(__x);}
+};
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
+    {__x.swap(__y);}
+
+template <class _Tp>
+struct default_delete
+{
+    _LIBCPP_INLINE_VISIBILITY default_delete() {}
+    template <class _Up>
+        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
+                      typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) {}
+    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const
+        {
+            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+            delete __ptr;
+        }
+};
+
+template <class _Tp>
+struct default_delete<_Tp[]>
+{
+    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const
+        {
+            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
+            delete [] __ptr;
+        }
+private:
+    template <class _Up> void operator() (_Up*) const;
+};
+
+template <class _Tp, class _Dp = default_delete<_Tp> >
+class unique_ptr
+{
+public:
+    typedef _Tp element_type;
+    typedef _Dp deleter_type;
+    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
+private:
+    __compressed_pair<pointer, deleter_type> __ptr_;
+
+#ifdef _LIBCPP_MOVE
+    unique_ptr(const unique_ptr&);
+    unique_ptr& operator=(const unique_ptr&);
+    template <class _Up, class _Ep>
+        unique_ptr(const unique_ptr<_Up, _Ep>&);
+    template <class _Up, class _Ep>
+        unique_ptr& operator=(const unique_ptr<_Up, _Ep>&);
+#else
+    unique_ptr(unique_ptr&);
+    template <class _Up, class _Ep>
+        unique_ptr(unique_ptr<_Up, _Ep>&);
+    unique_ptr& operator=(unique_ptr&);
+    template <class _Up, class _Ep>
+        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
+#endif
+
+    struct __nat {int __for_bool_;};
+
+    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
+    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+public:
+    _LIBCPP_INLINE_VISIBILITY unique_ptr()
+        : __ptr_(pointer())
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t)
+        : __ptr_(pointer())
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
+        : __ptr_(_STD::move(__p))
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+
+    template <class _Up>
+        _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(auto_ptr<_Up>& __p,
+                typename enable_if<
+                                      is_convertible<_Up*, _Tp*>::value &&
+                                      is_same<_Dp, default_delete<_Tp> >::value,
+                                      __nat
+                                  >::type = __nat())
+            : __ptr_(__p.release())
+            {
+            }
+
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
+                                        is_reference<deleter_type>::value,
+                                        deleter_type,
+                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
+        : __ptr_(__p, __d) {}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
+        : __ptr_(__p, _STD::move(__d))
+        {
+            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+        }
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u)
+        : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {}
+    template <class _Up, class _Ep>
+        _LIBCPP_INLINE_VISIBILITY
+        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
+                   typename enable_if
+                      <
+                        !is_array<_Up>::value &&
+                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
+                         is_convertible<_Ep, deleter_type>::value &&
+                         (
+                            !is_reference<deleter_type>::value ||
+                            is_same<deleter_type, _Ep>::value
+                         ),
+                         __nat
+                      >::type = __nat())
+            : __ptr_(__u.release(), _STD::forward<_Ep>(__u.get_deleter())) {}
+
+    template <class _Up>
+        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
+                typename enable_if<
+                                      is_convertible<_Up*, _Tp*>::value &&
+                                      is_same<_Dp, default_delete<_Tp> >::value,
+                                      __nat
+                                  >::type = __nat())
+            : __ptr_(__p.release())
+            {
+            }
+
+        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u)
+            {
+                reset(__u.release());
+                __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+                return *this;
+            }
+
+        template <class _Up, class _Ep>
+            _LIBCPP_INLINE_VISIBILITY
+            typename enable_if
+            <
+                !is_array<_Up>::value,
+                unique_ptr&
+            >::type
+            operator=(unique_ptr<_Up, _Ep>&& __u)
+            {
+                reset(__u.release());
+                __ptr_.second() = _STD::forward<_Ep>(__u.get_deleter());
+                return *this;
+            }
+#else
+
+    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
+    {
+        return __rv<unique_ptr>(*this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
+        : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {}
+
+    template <class _Up, class _Ep>
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
+    {
+        reset(__u.release());
+        __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
+        : __ptr_(_STD::move(__p), _STD::move(__d)) {}
+
+    template <class _Up>
+        _LIBCPP_INLINE_VISIBILITY
+                typename enable_if<
+                                      is_convertible<_Up*, _Tp*>::value &&
+                                      is_same<_Dp, default_delete<_Tp> >::value,
+                                      unique_ptr&
+                                  >::type
+        operator=(auto_ptr<_Up> __p)
+            {reset(__p.release()); return *this;}
+
+#endif
+    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t)
+    {
+        reset();
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
+        {return *__ptr_.first();}
+    _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_.first();}
+    _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();}
+    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter()       {return __ptr_.second();}
+    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();}
+    _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+
+    _LIBCPP_INLINE_VISIBILITY pointer release()
+    {
+        pointer __t = __ptr_.first();
+        __ptr_.first() = pointer();
+        return __t;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = __p;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
+};
+
+template <class _Tp, class _Dp>
+class unique_ptr<_Tp[], _Dp>
+{
+public:
+    typedef _Tp element_type;
+    typedef _Dp deleter_type;
+    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
+private:
+    __compressed_pair<pointer, deleter_type> __ptr_;
+
+#ifdef _LIBCPP_MOVE
+    unique_ptr(const unique_ptr&);
+    unique_ptr& operator=(const unique_ptr&);
+#else
+    unique_ptr(unique_ptr&);
+    template <class _Up>
+        unique_ptr(unique_ptr<_Up>&);
+    unique_ptr& operator=(unique_ptr&);
+    template <class _Up>
+        unique_ptr& operator=(unique_ptr<_Up>&);
+#endif
+
+    struct __nat {int __for_bool_;};
+
+    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
+    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+public:
+    _LIBCPP_INLINE_VISIBILITY unique_ptr()
+        : __ptr_(pointer())
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t)
+        : __ptr_(pointer())
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_same<_P, pointer>::value>::type
+             >
+    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p)
+        : __ptr_(__p)
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+
+    template <class _P,
+              class = typename enable_if<is_same<_P, pointer>::value>::type
+             >
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional<
+                                       is_reference<deleter_type>::value,
+                                       deleter_type,
+                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
+        : __ptr_(__p, __d) {}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
+                                       is_reference<deleter_type>::value,
+                                       deleter_type,
+                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
+        : __ptr_(pointer(), __d) {}
+
+    template <class _P,
+              class = typename enable_if<is_same<_P, pointer>::value ||
+                                         is_same<_P, nullptr_t>::value>::type
+             >
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename remove_reference<deleter_type>::type&& __d)
+        : __ptr_(__p, _STD::move(__d))
+        {
+            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+        }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
+        : __ptr_(pointer(), _STD::move(__d))
+        {
+            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
+        }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u)
+        : __ptr_(__u.release(), _STD::forward<deleter_type>(__u.get_deleter())) {}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u)
+        {
+            reset(__u.release());
+            __ptr_.second() = _STD::forward<deleter_type>(__u.get_deleter());
+            return *this;
+        }
+#else
+
+    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
+        : __ptr_(__p)
+        {
+            static_assert(!is_pointer<deleter_type>::value,
+                "unique_ptr constructed with null function pointer deleter");
+        }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
+        : __ptr_(__p, _STD::forward<deleter_type>(__d)) {}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
+        : __ptr_(pointer(), _STD::forward<deleter_type>(__d)) {}
+
+    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
+    {
+        return __rv<unique_ptr>(*this);
+    }
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
+        : __ptr_(__u->release(), _STD::forward<deleter_type>(__u->get_deleter())) {}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
+    {
+        reset(__u->release());
+        __ptr_.second() = _STD::forward<deleter_type>(__u->get_deleter());
+        return *this;
+    }
+
+#endif
+    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
+
+    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t)
+    {
+        reset();
+        return *this;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
+        {return __ptr_.first()[__i];}
+    _LIBCPP_INLINE_VISIBILITY pointer get() const {return __ptr_.first();}
+    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter()       {return __ptr_.second();}
+    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const {return __ptr_.second();}
+    _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+
+    _LIBCPP_INLINE_VISIBILITY pointer release()
+    {
+        pointer __t = __ptr_.first();
+        __ptr_.first() = pointer();
+        return __t;
+    }
+
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_same<_P, pointer>::value>::type
+             >
+    _LIBCPP_INLINE_VISIBILITY void reset(_P __p)
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = __p;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t)
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = nullptr;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+    _LIBCPP_INLINE_VISIBILITY void reset()
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = nullptr;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+#else
+    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
+    {
+        pointer __tmp = __ptr_.first();
+        __ptr_.first() = __p;
+        if (__tmp)
+            __ptr_.second()(__tmp);
+    }
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
+private:
+    
+#ifndef _LIBCPP_MOVE
+    template <class _Up>
+        explicit unique_ptr(_Up);
+    template <class _Up>
+        unique_ptr(_Up __u,
+                   typename conditional<
+                                       is_reference<deleter_type>::value,
+                                       deleter_type,
+                                       typename add_lvalue_reference<const deleter_type>::type>::type,
+                   typename enable_if
+                      <
+                         is_convertible<_Up, pointer>::value,
+                         __nat
+                      >::type = __nat());
+#endif
+};
+
+template <class _Tp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) {__x.swap(__y);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
+
+template <class _T1, class _D1, class _T2, class _D2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
+
+struct __destruct_n
+{
+private:
+    size_t size;
+
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type)
+        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
+
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type)
+        {}
+
+    _LIBCPP_INLINE_VISIBILITY void __incr(false_type)
+        {++size;}
+    _LIBCPP_INLINE_VISIBILITY void __incr(true_type)
+        {}
+
+    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type)
+        {size = __s;}
+    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type)
+        {}
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) : size(__s) {}
+
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*)
+        {__incr(integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*)
+        {__set(__s, integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+
+    template <class _Tp>
+    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p)
+        {__process(__p, integral_constant<bool, has_trivial_destructor<_Tp>::value>());}
+};
+
+template <class _Alloc>
+class __allocator_destructor
+{
+    typedef allocator_traits<_Alloc> __alloc_traits;
+public:
+    typedef typename __alloc_traits::pointer pointer;
+    typedef typename __alloc_traits::size_type size_type;
+private:
+    _Alloc& __alloc_;
+    size_type __s_;
+public:
+    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
+        : __alloc_(__a), __s_(__s) {}
+    void operator()(pointer __p) {__alloc_traits::deallocate(__alloc_, __p, __s_);}
+};
+
+template <class _InputIterator, class _ForwardIterator>
+_ForwardIterator
+uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
+{
+    __destruct_n __d(0);
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
+    for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0))
+        ::new(&*__r) value_type(*__f);
+    __h.release();
+    return __r;
+}
+
+template <class _InputIterator, class _Size, class _ForwardIterator>
+_ForwardIterator
+uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
+{
+    __destruct_n __d(0);
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
+    for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n)
+        ::new(&*__r) value_type(*__f);
+    __h.release();
+    return __r;
+}
+
+template <class _ForwardIterator, class _Tp>
+void
+uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
+{
+    __destruct_n __d(0);
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
+    for (; __f != __l; ++__f, __d.__incr((value_type*)0))
+        ::new(&*__f) value_type(__x);
+    __h.release();
+}
+
+template <class _ForwardIterator, class _Size, class _Tp>
+void
+uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
+{
+    __destruct_n __d(0);
+    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+    unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
+    for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0))
+        ::new(&*__f) value_type(__x);
+    __h.release();
+}
+
+class bad_weak_ptr
+    : public std::exception
+{
+public:
+    virtual ~bad_weak_ptr() throw();
+    virtual const char* what() const throw();
+};
+
+template<class _Tp> class weak_ptr;
+
+class __shared_count
+{
+    __shared_count(const __shared_count&);
+    __shared_count& operator=(const __shared_count&);
+
+protected:
+    long __shared_owners_;
+    virtual ~__shared_count();
+private:
+    virtual void __on_zero_shared() = 0;
+
+public:
+    explicit __shared_count(long __refs = 0)
+        : __shared_owners_(__refs) {}
+
+    void __add_shared();
+    void __release_shared();
+    long use_count() const {return __shared_owners_ + 1;}
+};
+
+class __shared_weak_count
+    : private __shared_count
+{
+    long __shared_weak_owners_;
+
+public:
+    explicit __shared_weak_count(long __refs = 0)
+        : __shared_count(__refs),
+          __shared_weak_owners_(__refs) {}
+protected:
+    virtual ~__shared_weak_count();
+
+public:
+    void __add_shared();
+    void __add_weak();
+    void __release_shared();
+    void __release_weak();
+    long use_count() const {return __shared_count::use_count();}
+    __shared_weak_count* lock();
+
+    virtual const void* __get_deleter(const type_info&) const;
+private:
+    virtual void __on_zero_shared_weak() = 0;
+};
+
+template <class _Tp, class _Dp, class _Alloc>
+class __shared_ptr_pointer
+    : public __shared_weak_count
+{
+    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
+public:
+    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
+        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _STD::move(__d)), _STD::move(__a)) {}
+
+    virtual const void* __get_deleter(const type_info&) const;
+
+private:
+    virtual void __on_zero_shared();
+    virtual void __on_zero_shared_weak();
+};
+
+template <class _Tp, class _Dp, class _Alloc>
+const void*
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const
+{
+    return __t == typeid(_Dp) ? &__data_.first().second() : 0;
+}
+
+template <class _Tp, class _Dp, class _Alloc>
+void
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared()
+{
+    __data_.first().second()(__data_.first().first());
+    __data_.first().second().~_Dp();
+}
+
+template <class _Tp, class _Dp, class _Alloc>
+void
+__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak()
+{
+    typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
+    __data_.second().~_Alloc();
+    __a.deallocate(this, 1);
+}
+
+template <class _Tp, class _Alloc>
+class __shared_ptr_emplace
+    : public __shared_weak_count
+{
+    __compressed_pair<_Alloc, _Tp> __data_;
+public:
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+    __shared_ptr_emplace(_Alloc __a)
+        :  __data_(_STD::move(__a)) {}
+
+    template <class ..._Args>
+        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
+            :  __data_(_STD::move(__a), _Tp(_STD::forward<_Args>(__args)...)) {}
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+    __shared_ptr_emplace(_Alloc __a)
+        :  __data_(__a) {}
+
+    template <class _A0>
+        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
+            :  __data_(__a, _Tp(__a0)) {}
+
+    template <class _A0, class _A1>
+        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
+            :  __data_(__a, _Tp(__a0, __a1)) {}
+
+    template <class _A0, class _A1, class _A2>
+        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
+            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+private:
+    virtual void __on_zero_shared();
+    virtual void __on_zero_shared_weak();
+public:
+    _Tp* get() {return &__data_.second();}
+};
+
+template <class _Tp, class _Alloc>
+void
+__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared()
+{
+    __data_.second().~_Tp();
+}
+
+template <class _Tp, class _Alloc>
+void
+__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak()
+{
+    typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
+    __data_.first().~_Alloc();
+    __a.deallocate(this, 1);
+}
+
+template<class _Tp> class enable_shared_from_this;
+
+template<class _Tp>
+class shared_ptr
+{
+public: 
+    typedef _Tp element_type; 
+private:
+    element_type*      __ptr_;
+    __shared_weak_count* __cntrl_;
+
+    struct __nat {int __for_bool_;};
+public:
+    shared_ptr();
+    shared_ptr(nullptr_t);
+    template<class _Yp> explicit shared_ptr(_Yp* __p);
+    template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d); 
+    template<class _Yp, class _Dp, class _Alloc> shared_ptr(_Yp* __p, _Dp __d, _Alloc __a); 
+    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
+    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
+    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p); 
+    shared_ptr(const shared_ptr& __r);
+    template<class _Yp>
+        shared_ptr(const shared_ptr<_Yp>& __r,
+                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+#ifdef _LIBCPP_MOVE    
+    shared_ptr(shared_ptr&& __r);
+    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
+                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); 
+#endif
+    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
+                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat()); 
+#ifdef _LIBCPP_MOVE    
+    template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r); 
+#else
+    template<class _Yp> shared_ptr(auto_ptr<_Yp>& __r); 
+#endif
+#ifdef _LIBCPP_MOVE    
+private:
+    template <class _Yp, class _Dp> shared_ptr(const unique_ptr<_Yp, _Dp>& __r);// = delete; 
+public:
+    template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+    template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+#else
+    template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+    template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
+#endif
+
+    ~shared_ptr();
+
+    shared_ptr& operator=(const shared_ptr& __r); 
+    template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r); 
+#ifdef _LIBCPP_MOVE    
+    shared_ptr& operator=(shared_ptr&& __r); 
+    template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r); 
+    template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r); 
+#else
+    template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>& __r); 
+#endif
+#ifdef _LIBCPP_MOVE    
+private:
+    template <class _Yp, class _Dp> shared_ptr& operator=(const unique_ptr<_Yp, _Dp>& __r);// = delete; 
+public:
+    template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp>&& __r); 
+#else
+    template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp> __r); 
+#endif
+
+    void swap(shared_ptr& __r);
+    void reset();
+    template<class _Yp> void reset(_Yp* __p);
+    template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d);
+    template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a);
+
+    element_type* get() const {return __ptr_;}
+    typename add_lvalue_reference<element_type>::type operator*() const {return *__ptr_;}
+    element_type* operator->() const {return __ptr_;}
+    long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;}
+    bool unique() const {return use_count() == 1;}
+    bool empty() const {return __cntrl_ == 0;}
+    /*explicit*/ operator bool() const {return get() != 0;}
+    template <class _U> bool owner_before(shared_ptr<_U> const& __p) const
+        {return __cntrl_ < __p.__cntrl_;}
+    template <class _U> bool owner_before(weak_ptr<_U> const& __p) const
+        {return __cntrl_ < __p.__cntrl_;}
+
+    template <class _Dp>
+        _Dp* __get_deleter() const
+            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+    template<class ..._Args>
+        static
+        shared_ptr<_Tp>
+        make_shared(_Args&& ...__args);
+
+    template<class _Alloc, class ..._Args>
+        static
+        shared_ptr<_Tp>
+        allocate_shared(const _Alloc& __a, _Args&& ...__args);
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+    static shared_ptr<_Tp> make_shared();
+
+    template<class _A0>
+        static shared_ptr<_Tp> make_shared(_A0&);
+
+    template<class _A0, class _A1>
+        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
+
+    template<class _A0, class _A1, class _A2>
+        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
+
+    template<class _Alloc>
+        static shared_ptr<_Tp>
+        allocate_shared(const _Alloc& __a);
+
+    template<class _Alloc, class _A0>
+        static shared_ptr<_Tp>
+        allocate_shared(const _Alloc& __a, _A0& __a0);
+
+    template<class _Alloc, class _A0, class _A1>
+        static shared_ptr<_Tp>
+        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
+
+    template<class _Alloc, class _A0, class _A1, class _A2>
+        static shared_ptr<_Tp>
+        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+private:
+
+    template <class _Yp>
+        void
+        __enable_weak_this(const enable_shared_from_this<_Yp>* __e)
+        {
+            if (__e)
+                __e->__weak_this_ = *this;
+        }
+
+    void __enable_weak_this(const void*) {}
+
+    template <class _Up> friend class shared_ptr;
+    template <class _Up> friend class weak_ptr;
+};
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr()
+    : __ptr_(0),
+      __cntrl_(0)
+{
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(nullptr_t)
+    : __ptr_(0),
+      __cntrl_(0)
+{
+}
+
+template<class _Tp>
+template<class _Yp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p)
+    : __ptr_(__p)
+{
+    unique_ptr<_Yp> __hold(__p);
+    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
+    __hold.release();
+    __enable_weak_this(__p);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
+    : __ptr_(__p)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
+        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
+        __enable_weak_this(__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __d(__p);
+        throw;
+    }
+#endif
+}
+
+template<class _Tp>
+template<class _Dp>
+shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
+    : __ptr_(0)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
+        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __d(__p);
+        throw;
+    }
+#endif
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp, class _Alloc>
+shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
+    : __ptr_(__p)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
+        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+        typedef __allocator_destructor<_A2> _D2;
+        _A2 __a2(__a);
+        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
+        __cntrl_ = __hold2.release();
+        __enable_weak_this(__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __d(__p);
+        throw;
+    }
+#endif
+}
+
+template<class _Tp>
+template<class _Dp, class _Alloc>
+shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
+    : __ptr_(0)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
+        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+        typedef __allocator_destructor<_A2> _D2;
+        _A2 __a2(__a);
+        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
+        __cntrl_ = __hold2.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __d(__p);
+        throw;
+    }
+#endif
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p)
+    : __ptr_(__p),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_shared();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_shared();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
+                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_shared();
+}
+
+#ifdef _LIBCPP_MOVE
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    __r.__ptr_ = 0;
+    __r.__cntrl_ = 0;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
+                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    __r.__ptr_ = 0;
+    __r.__cntrl_ = 0;
+}
+
+#endif
+
+template<class _Tp>
+template<class _Yp>
+#ifdef _LIBCPP_MOVE    
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
+#else
+shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>& __r)
+#endif
+    : __ptr_(__r.get())
+{
+    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
+    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
+    __enable_weak_this(__r.get());
+    __r.release();
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+#ifdef _LIBCPP_MOVE    
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
+#else
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
+#endif
+           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
+    : __ptr_(__r.get())
+{
+    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
+    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
+    __enable_weak_this(__r.get());
+    __r.release();
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+#ifdef _LIBCPP_MOVE    
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
+#else
+shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
+#endif
+           typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
+    : __ptr_(__r.get())
+{
+    typedef __shared_ptr_pointer<_Yp*,
+                                 reference_wrapper<typename remove_reference<_Dp>::type>,
+                                 allocator<_Yp> > _CntrlBlk;
+    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
+    __enable_weak_this(__r.get());
+    __r.release();
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+template<class ..._Args>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_Args&& ...__args)
+{
+    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+    typedef allocator<_CntrlBlk> _A2;
+    typedef __allocator_destructor<_A2> _D2;
+    _A2 __a2;
+    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class ..._Args>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
+{
+    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+    typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
+    typedef __allocator_destructor<_A2> _D2;
+    _A2 __a2(__a);
+    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a, _STD::forward<_Args>(__args)...);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared()
+{
+    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+    typedef allocator<_CntrlBlk> _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2;
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__alloc2);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _A0>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0)
+{
+    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+    typedef allocator<_CntrlBlk> _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2;
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _A0, class _A1>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
+{
+    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+    typedef allocator<_CntrlBlk> _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2;
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _A0, class _A1, class _A2>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
+{
+    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
+    typedef allocator<_CntrlBlk> _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2;
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _Alloc>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
+{
+    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2(__a);
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
+{
+    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2(__a);
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a, __a0);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0, class _A1>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
+{
+    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2(__a);
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+template<class _Tp>
+template<class _Alloc, class _A0, class _A1, class _A2>
+shared_ptr<_Tp>
+shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
+    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
+    typedef __allocator_destructor<_Alloc2> _D2;
+    _Alloc2 __alloc2(__a);
+    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
+    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
+    shared_ptr<_Tp> __r;
+    __r.__ptr_ = __hold2.get()->get();
+    __r.__cntrl_ = __hold2.release();
+    __r.__enable_weak_this(__r.__ptr_);
+    return __r;
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+shared_ptr<_Tp>::~shared_ptr()
+{
+    if (__cntrl_)
+        __cntrl_->__release_shared();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(const shared_ptr& __r)
+{
+    shared_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r)
+{
+    shared_ptr(__r).swap(*this);
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE    
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(shared_ptr&& __r)
+{
+    shared_ptr(_STD::move(__r)).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
+{
+    shared_ptr(_STD::move(__r)).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
+{
+    shared_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
+{
+    shared_ptr(_STD::move(__r)).swap(*this);
+    return *this;
+}
+
+#else
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(auto_ptr<_Yp>& __r)
+{
+    shared_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template <class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>&
+shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
+{
+    shared_ptr(_STD::move(__r)).swap(*this);
+    return *this;
+}
+
+#endif
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::swap(shared_ptr& __r)
+{
+    _STD::swap(__ptr_, __r.__ptr_);
+    _STD::swap(__cntrl_, __r.__cntrl_);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset()
+{
+    shared_ptr().swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p)
+{
+    shared_ptr(__p).swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
+{
+    shared_ptr(__p, __d).swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp, class _Dp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
+{
+    shared_ptr(__p, __d, __a).swap(*this);
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp, class ..._Args> 
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_Args&& ...__args)
+{
+    return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...);
+}
+
+template<class _Tp, class _Alloc, class ..._Args> 
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _Args&& ...__args)
+{
+    return shared_ptr<_Tp>::allocate_shared(__a, _STD::forward<_Args>(__args)...);
+}
+
+#else  // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared()
+{
+    return shared_ptr<_Tp>::make_shared();
+}
+
+template<class _Tp, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0)
+{
+    return shared_ptr<_Tp>::make_shared(__a0);
+}
+
+template<class _Tp, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0, _A1& __a1)
+{
+    return shared_ptr<_Tp>::make_shared(__a0, __a1);
+}
+
+template<class _Tp, class _A0, class _A1, class _A2> 
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
+}
+
+template<class _Tp, class _Alloc>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a)
+{
+    return shared_ptr<_Tp>::allocate_shared(__a);
+}
+
+template<class _Tp, class _Alloc, class _A0>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0)
+{
+    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
+}
+
+template<class _Tp, class _Alloc, class _A0, class _A1>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
+{
+    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
+}
+
+template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
+{
+    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
+}
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+    return __x.get() == __y.get();
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+    return !(__x == __y);
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y)
+{
+    return __x.get() < __y.get();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y)
+{
+    __x.swap(__y);
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+static_pointer_cast(const shared_ptr<_Up>& __r)
+{
+    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+dynamic_pointer_cast(const shared_ptr<_Up>& __r)
+{
+    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
+    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
+}
+
+template<class _Tp, class _Up>
+shared_ptr<_Tp>
+const_pointer_cast(const shared_ptr<_Up>& __r)
+{
+    return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get()));
+}
+
+template<class _Dp, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Dp*
+get_deleter(const shared_ptr<_Tp>& __p)
+{
+    return __p.template __get_deleter<_Dp>();
+}
+
+template<class _Tp>
+class weak_ptr
+{
+public: 
+    typedef _Tp element_type; 
+private:
+    element_type*        __ptr_;
+    __shared_weak_count* __cntrl_;
+
+public: 
+    weak_ptr(); 
+    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
+                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat());
+    weak_ptr(weak_ptr const& __r); 
+    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
+                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat()); 
+    
+    ~weak_ptr(); 
+    
+    weak_ptr& operator=(weak_ptr const& __r); 
+    template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r); 
+    template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r); 
+    
+    void swap(weak_ptr& __r); 
+    void reset(); 
+    
+    long use_count() const {return __cntrl_ ? __cntrl_->use_count() : 0;}
+    bool expired() const {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
+    shared_ptr<_Tp> lock() const; 
+    template<class _Up> bool owner_before(const shared_ptr<_Up>& __r) const 
+        {return __cntrl_ < __r.__cntrl_;}
+    template<class _Up> bool owner_before(const weak_ptr<_Up>& __r) const
+        {return __cntrl_ < __r.__cntrl_;}
+
+    template <class _Up> friend class weak_ptr;
+    template <class _Up> friend class shared_ptr;
+};
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr()
+    : __ptr_(0),
+      __cntrl_(0)
+{
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
+                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
+                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_)
+{
+    if (__cntrl_)
+        __cntrl_->__add_weak();
+}
+
+template<class _Tp>
+weak_ptr<_Tp>::~weak_ptr()
+{
+    if (__cntrl_)
+        __cntrl_->__release_weak();
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(weak_ptr const& __r)
+{
+    weak_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template<class _Yp> 
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r)
+{
+    weak_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+template<class _Yp> 
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r)
+{
+    weak_ptr(__r).swap(*this);
+    return *this;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+weak_ptr<_Tp>::swap(weak_ptr& __r)
+{
+    _STD::swap(__ptr_, __r.__ptr_);
+    _STD::swap(__cntrl_, __r.__cntrl_);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y)
+{
+    __x.swap(__y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+weak_ptr<_Tp>::reset()
+{
+    weak_ptr().swap(*this);
+}
+
+template<class _Tp>
+template<class _Yp>
+shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
+                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
+    : __ptr_(__r.__ptr_),
+      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
+{
+    if (__cntrl_ == 0)
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw bad_weak_ptr();
+#else
+        assert(!"bad_weak_ptr");
+#endif
+}
+
+template<class _Tp>
+shared_ptr<_Tp>
+weak_ptr<_Tp>::lock() const
+{
+    shared_ptr<_Tp> __r;
+    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
+    if (__r.__cntrl_)
+        __r.__ptr_ = __ptr_;
+    return __r;
+}
+
+template <class _Tp> struct owner_less; 
+
+template <class _Tp>
+struct owner_less<shared_ptr<_Tp> > 
+    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
+{ 
+    typedef bool result_type; 
+    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+}; 
+
+template <class _Tp>
+struct owner_less<weak_ptr<_Tp> > 
+    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
+{
+    typedef bool result_type; 
+    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
+        {return __x.owner_before(__y);}
+};
+
+template<class _Tp>
+class enable_shared_from_this
+{
+    mutable weak_ptr<_Tp> __weak_this_;
+protected: 
+    enable_shared_from_this() {}
+    enable_shared_from_this(enable_shared_from_this const&) {}
+    enable_shared_from_this& operator=(enable_shared_from_this const&) {return *this;}
+    ~enable_shared_from_this() {}
+public: 
+    shared_ptr<_Tp> shared_from_this() {return shared_ptr<_Tp>(__weak_this_);}
+    shared_ptr<_Tp const> shared_from_this() const {return shared_ptr<const _Tp>(__weak_this_);}
+
+    template <class _Up> friend class shared_ptr;
+};
+
+//enum class 
+struct pointer_safety
+{
+    enum _
+    {
+        relaxed,
+        preferred,
+        strict
+    };
+
+    _ __v_;
+
+    pointer_safety(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+};
+
+void declare_reachable(void* __p);
+void declare_no_pointers(char* __p, size_t __n);
+void undeclare_no_pointers(char* __p, size_t __n);
+pointer_safety get_pointer_safety();
+void* __undeclare_reachable(void*);
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp* 
+undeclare_reachable(_Tp* __p)
+{
+    return static_cast<_Tp*>(__undeclare_reachable(__p));
+}
+
+void* align(size_t, size_t, void*&, size_t&);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_MEMORY
+
+// hh 060228 Created
diff --git a/include/mutex b/include/mutex
new file mode 100644
index 0000000..ffa08b4
--- /dev/null
+++ b/include/mutex
@@ -0,0 +1,516 @@
+// -*- C++ -*-
+//===--------------------------- mutex ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_MUTEX
+#define _LIBCPP_MUTEX
+
+/*
+    mutex synopsis
+
+namespace std
+{
+
+class mutex
+{
+public:
+     mutex();
+     ~mutex();
+
+    mutex(const mutex&) = delete;
+    mutex& operator=(const mutex&) = delete;
+
+    void lock();
+    bool try_lock();
+    void unlock();
+
+    typedef pthread_mutex_t* native_handle_type;
+    native_handle_type native_handle();
+};
+
+class recursive_mutex
+{
+public:
+     recursive_mutex();
+     ~recursive_mutex();
+
+    recursive_mutex(const recursive_mutex&) = delete;
+    recursive_mutex& operator=(const recursive_mutex&) = delete;
+
+    void lock();
+    bool try_lock();
+    void unlock();
+
+    typedef pthread_mutex_t* native_handle_type;
+    native_handle_type native_handle();
+};
+
+class timed_mutex
+{
+public:
+     timed_mutex();
+     ~timed_mutex();
+
+    timed_mutex(const timed_mutex&) = delete;
+    timed_mutex& operator=(const timed_mutex&) = delete;
+
+    void lock();
+    bool try_lock();
+    template <class Rep, class Period>
+        bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+    template <class Clock, class Duration>
+        bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+    void unlock();
+};
+
+class recursive_timed_mutex
+{
+public:
+     recursive_timed_mutex();
+     ~recursive_timed_mutex();
+
+    recursive_timed_mutex(const recursive_timed_mutex&) = delete;
+    recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
+
+    void lock();
+    bool try_lock();
+    template <class Rep, class Period>
+        bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+    template <class Clock, class Duration>
+        bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+    void unlock();
+};
+
+struct defer_lock_t {};
+struct try_to_lock_t {};
+struct adopt_lock_t {};
+
+constexpr defer_lock_t  defer_lock{};
+constexpr try_to_lock_t try_to_lock{};
+constexpr adopt_lock_t  adopt_lock{};
+
+template <class Mutex>
+class lock_guard
+{
+public:
+    typedef Mutex mutex_type;
+
+    explicit lock_guard(mutex_type& m);
+    lock_guard(mutex_type& m, adopt_lock_t);
+    ~lock_guard();
+
+    lock_guard(lock_guard const&) = delete;
+    lock_guard& operator=(lock_guard const&) = delete;
+};
+
+template <class Mutex>
+class unique_lock
+{
+public:
+    typedef Mutex mutex_type;
+    unique_lock();
+    explicit unique_lock(mutex_type& m);
+    unique_lock(mutex_type& m, defer_lock_t);
+    unique_lock(mutex_type& m, try_to_lock_t);
+    unique_lock(mutex_type& m, adopt_lock_t);
+    template <class Clock, class Duration>
+        unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
+    template <class Rep, class Period>
+        unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
+    ~unique_lock();
+
+    unique_lock(unique_lock const&) = delete;
+    unique_lock& operator=(unique_lock const&) = delete;
+
+    unique_lock(unique_lock&& u);
+    unique_lock& operator=(unique_lock&& u);
+
+    void lock();
+    bool try_lock();
+
+    template <class Rep, class Period>
+        bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+    template <class Clock, class Duration>
+        bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+    void unlock();
+
+    void swap(unique_lock& u);
+    mutex_type* release();
+
+    bool owns_lock() const;
+    explicit operator bool () const;
+    mutex_type* mutex() const;
+};
+
+template <class Mutex>
+  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);
+
+template <class L1, class L2, class... L3>
+  int try_lock(L1&, L2&, L3&...);
+template <class L1, class L2, class... L3>
+  void lock(L1&, L2&, L3&...);
+
+struct once_flag
+{
+    constexpr once_flag();
+
+    once_flag(const once_flag&) = delete;
+    once_flag& operator=(const once_flag&) = delete;
+};
+
+template<class Callable, class ...Args>
+  void call_once(once_flag& flag, Callable&& func, Args&&... args);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__mutex_base>
+#include <functional>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class recursive_mutex
+{
+    pthread_mutex_t __m_;
+
+public:
+     recursive_mutex();
+     ~recursive_mutex();
+
+private:
+    recursive_mutex(const recursive_mutex&); // = delete;
+    recursive_mutex& operator=(const recursive_mutex&); // = delete;
+
+public:
+    void lock();
+    bool try_lock();
+    void unlock();
+
+    typedef pthread_mutex_t* native_handle_type;
+    native_handle_type native_handle() {return &__m_;}
+};
+
+class timed_mutex
+{
+    mutex              __m_;
+    condition_variable __cv_;
+    bool               __locked_;
+public:
+     timed_mutex();
+     ~timed_mutex();
+
+private:
+    timed_mutex(const timed_mutex&); // = delete;
+    timed_mutex& operator=(const timed_mutex&); // = delete;
+
+public:
+    void lock();
+    bool try_lock();
+    template <class _Rep, class _Period>
+        bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
+            {return try_lock_until(chrono::monotonic_clock::now() + __d);}
+    template <class _Clock, class _Duration>
+        bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+    void unlock();
+};
+
+template <class _Clock, class _Duration>
+bool
+timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
+{
+    using namespace chrono;
+    unique_lock<mutex> __lk(__m_);
+    bool no_timeout = _Clock::now() < __t;
+    while (no_timeout && __locked_)
+        no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
+    if (!__locked_)
+    {
+        __locked_ = true;
+        return true;
+    }
+    return false;
+}
+
+class recursive_timed_mutex
+{
+    mutex              __m_;
+    condition_variable __cv_;
+    size_t             __count_;
+    pthread_t          __id_;
+public:
+     recursive_timed_mutex();
+     ~recursive_timed_mutex();
+
+private:
+    recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
+    recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
+
+public:
+    void lock();
+    bool try_lock();
+    template <class _Rep, class _Period>
+        bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
+            {return try_lock_until(chrono::monotonic_clock::now() + __d);}
+    template <class _Clock, class _Duration>
+        bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+    void unlock();
+};
+
+template <class _Clock, class _Duration>
+bool
+recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
+{
+    using namespace chrono;
+    pthread_t __id = pthread_self();
+    unique_lock<mutex> lk(__m_);
+    if (pthread_equal(__id, __id_))
+    {
+        if (__count_ == numeric_limits<size_t>::max())
+            return false;
+        ++__count_;
+        return true;
+    }
+    bool no_timeout = _Clock::now() < __t;
+    while (no_timeout && __count_ != 0)
+        no_timeout = __cv_.wait_until(lk, __t) == cv_status::no_timeout;
+    if (__count_ == 0)
+    {
+        __count_ = 1;
+        __id_ = __id;
+        return true;
+    }
+    return false;
+}
+
+template <class _L0, class _L1>
+int
+try_lock(_L0& __l0, _L1& __l1)
+{
+    unique_lock<_L0> __u0(__l0, try_to_lock);
+    if (__u0.owns_lock())
+    {
+        if (__l1.try_lock())
+        {
+            __u0.release();
+            return -1;
+        }
+        else
+            return 1;
+    }
+    return 0;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _L0, class _L1, class _L2, class... _L3>
+int
+try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3)
+{
+    int __r = 0;
+    unique_lock<_L0> __u0(__l0, try_to_lock);
+    if (__u0.owns_lock())
+    {
+        __r = try_lock(__l1, __l2, __l3...);
+        if (__r == -1)
+            __u0.release();
+        else
+            ++__r;
+    }
+    return __r;
+}
+
+#endif
+
+template <class _L0, class _L1>
+void
+lock(_L0& __l0, _L1& __l1)
+{
+    while (true)
+    {
+        {
+            unique_lock<_L0> __u0(__l0);
+            if (__l1.try_lock())
+            {
+                __u0.release();
+                break;
+            }
+        }
+        sched_yield();
+        {
+            unique_lock<_L1> __u1(__l1);
+            if (__l0.try_lock())
+            {
+                __u1.release();
+                break;
+            }
+        }
+        sched_yield();
+    }
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _L0, class _L1, class ..._L2>
+void
+__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& ...__l2)
+{
+    while (true)
+    {
+        switch (__i)
+        {
+        case 0:
+            {
+                unique_lock<_L0> __u0(__l0);
+                __i = try_lock(__l1, __l2...);
+                if (__i == -1)
+                {
+                    __u0.release();
+                    return;
+                }
+            }
+            ++__i;
+            sched_yield();
+            break;
+        case 1:
+            {
+                unique_lock<_L1> __u1(__l1);
+                __i = try_lock(__l2..., __l0);
+                if (__i == -1)
+                {
+                    __u1.release();
+                    return;
+                }
+            }
+            if (__i == sizeof...(_L2))
+                __i = 0;
+            else
+                __i += 2;
+            sched_yield();
+            break;
+        default:
+            __lock_first(__i - 2, __l2..., __l0, __l1);
+            return;
+        }
+    }
+}
+
+template <class _L0, class _L1, class ..._L2>
+inline
+void
+lock(_L0& __l0, _L1& __l1, _L2& ...__l2)
+{
+    __lock_first(0, __l0, __l1, __l2...);
+}
+
+#endif
+
+struct once_flag;
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Callable, class... _Args>
+  void call_once(once_flag&, _Callable&&, _Args&&...);
+
+#else
+
+template<class _Callable>
+  void call_once(once_flag&, _Callable);
+
+#endif
+
+struct once_flag
+{
+    // constexpr
+        once_flag() {}
+
+private:
+    once_flag(const once_flag&); // = delete;
+    once_flag& operator=(const once_flag&); // = delete;
+
+    unsigned long __state_;
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template<class _Callable, class... _Args>
+    friend
+    void call_once(once_flag&, _Callable&&, _Args&&...);
+#else
+    template<class _Callable>
+    friend
+    void call_once(once_flag&, _Callable);
+#endif
+};
+
+template <class _F>
+class __call_once_param
+{
+    _F __f_;
+public:
+#ifdef _LIBCPP_MOVE
+    explicit __call_once_param(_F&& __f) : __f_(_STD::move(__f)) {}
+#else
+    explicit __call_once_param(const _F& __f) : __f_(__f) {}
+#endif
+
+    void operator()()
+    {
+        __f_();
+    }
+};
+
+template <class _F>
+void
+__call_once_proxy(void* __vp)
+{
+    __call_once_param<_F>* __p = static_cast<__call_once_param<_F>*>(__vp);
+    (*__p)();
+}
+
+void __call_once(volatile unsigned long&, void*, void(*)(void*));
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template<class _Callable, class... _Args>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
+{
+    if (__builtin_expect(__flag.__state_ , ~0ul) != ~0ul)
+    {
+        typedef decltype(std::bind(std::forward<_Callable>(__func),
+                         std::forward<_Args>(__args)...)) _G;
+        __call_once_param<_G> __p(std::bind(std::forward<_Callable>(__func),
+                                 std::forward<_Args>(__args)...));
+        __call_once(__flag.__state_, &__p, &__call_once_proxy<_G>);
+    }
+}
+
+#else
+
+template<class _Callable>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+call_once(once_flag& __flag, _Callable __func)
+{
+    if (__flag.__state_ != ~0ul)
+    {
+        __call_once_param<_Callable> __p(__func);
+        __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
+    }
+}
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_MUTEX
diff --git a/include/new b/include/new
new file mode 100644
index 0000000..9d7ed45
--- /dev/null
+++ b/include/new
@@ -0,0 +1,106 @@
+// -*- C++ -*-
+//===----------------------------- new ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_NEW
+#define _LIBCPP_NEW
+
+/*
+    new synopsis
+
+namespace std
+{
+
+class bad_alloc
+    : public exception
+{
+public:
+    bad_alloc() throw();
+    bad_alloc(const bad_alloc&) throw();
+    bad_alloc& operator=(const bad_alloc&) throw();
+    virtual ~bad_alloc() throw();
+    virtual const char* what() const throw();
+};
+
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+typedef void (*new_handler)();
+new_handler set_new_handler(new_handler new_p) throw();
+
+}  // std
+
+void* operator new(std::size_t size) throw(std::bad_alloc);            // replaceable
+void* operator new(std::size_t size, const std::nothrow_t&) throw();   // replaceable
+void  operator delete(void* ptr) throw();                              // replaceable
+void  operator delete(void* ptr, const std::nothrow_t&) throw();       // replaceable
+
+void* operator new[](std::size_t size) throw(std::bad_alloc);          // replaceable
+void* operator new[](std::size_t size, const std::nothrow_t&) throw(); // replaceable
+void  operator delete[](void* ptr) throw();                            // replaceable
+void  operator delete[](void* ptr, const std::nothrow_t&) throw();     // replaceable
+
+void* operator new  (std::size_t size, void* ptr) throw();
+void* operator new[](std::size_t size, void* ptr) throw();
+void  operator delete  (void* ptr, void*) throw();
+void  operator delete[](void* ptr, void*) throw();
+
+*/
+
+#include <__config>
+#include <exception>
+#include <cstddef>
+
+#pragma GCC system_header
+
+namespace std  // purposefully not using versioning namespace
+{
+
+class _LIBCPP_EXCEPTION_ABI bad_alloc
+    : public exception
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY bad_alloc() throw() {}
+    virtual ~bad_alloc() throw();
+    virtual const char* what() const throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI bad_array_new_length
+    : public bad_alloc
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY bad_array_new_length() throw() {}
+    virtual ~bad_array_new_length() throw();
+    virtual const char* what() const throw();
+};
+
+void __throw_bad_alloc();
+
+struct nothrow_t {};
+extern _LIBCPP_VISIBLE const nothrow_t nothrow;
+typedef void (*new_handler)();
+_LIBCPP_VISIBLE new_handler set_new_handler(new_handler) throw();
+
+}  // std
+
+_LIBCPP_VISIBLE void* operator new(std::size_t) throw(std::bad_alloc);
+_LIBCPP_VISIBLE void* operator new(std::size_t, const std::nothrow_t&) throw();
+_LIBCPP_VISIBLE void  operator delete(void*) throw();
+_LIBCPP_VISIBLE void  operator delete(void*, const std::nothrow_t&) throw();
+
+_LIBCPP_VISIBLE void* operator new[](std::size_t) throw(std::bad_alloc);
+_LIBCPP_VISIBLE void* operator new[](std::size_t, const std::nothrow_t&) throw();
+_LIBCPP_VISIBLE void  operator delete[](void*) throw();
+_LIBCPP_VISIBLE void  operator delete[](void*, const std::nothrow_t&) throw();
+
+_LIBCPP_INLINE_VISIBILITY inline void* operator new  (std::size_t, void* __p) throw() {return __p;}
+_LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) throw() {return __p;}
+_LIBCPP_INLINE_VISIBILITY inline void  operator delete  (void*, void*) throw() {}
+_LIBCPP_INLINE_VISIBILITY inline void  operator delete[](void*, void*) throw() {}
+
+#endif  // _LIBCPP_NEW
diff --git a/include/numeric b/include/numeric
new file mode 100644
index 0000000..4600890
--- /dev/null
+++ b/include/numeric
@@ -0,0 +1,183 @@
+// -*- C++ -*-
+//===---------------------------- numeric ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_NUMERIC
+#define _LIBCPP_NUMERIC
+
+/*
+    numeric synopsis
+
+namespace std
+{
+
+template <class InputIterator, class T>
+    T
+    accumulate(InputIterator first, InputIterator last, T init);
+
+template <class InputIterator, class T, class BinaryOperation>
+    T
+    accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
+
+template <class InputIterator1, class InputIterator2, class T>
+    T
+    inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
+
+template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
+    T
+    inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
+                  T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
+
+template <class InputIterator, class OutputIterator>
+    OutputIterator
+    partial_sum(InputIterator first, InputIterator last, OutputIterator result);
+
+template <class InputIterator, class OutputIterator, class BinaryOperation>
+    OutputIterator
+    partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
+
+template <class InputIterator, class OutputIterator>
+    OutputIterator
+    adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
+
+template <class InputIterator, class OutputIterator, class BinaryOperation>
+    OutputIterator
+    adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <iterator>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _InputIterator, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
+{
+    for (; __first != __last; ++__first)
+        __init = __init + *__first;
+    return __init;
+}
+
+template <class _InputIterator, class _Tp, class _BinaryOperation>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
+{
+    for (; __first != __last; ++__first)
+        __init = __binary_op(__init, *__first);
+    return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
+{
+    for (; __first1 != __last1; ++__first1, ++__first2)
+        __init = __init + *__first1 * *__first2;
+    return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp
+inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
+              _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
+{
+    for (; __first1 != __last1; ++__first1, ++__first2)
+        __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
+    return __init;
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t(*__first);
+        *__result = __t;
+        for (++__first, ++__result; __first != __last; ++__first, ++__result)
+        {
+            __t = __t + *__first;
+            *__result = __t;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+              _BinaryOperation __binary_op)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t(*__first);
+        *__result = __t;
+        for (++__first, ++__result; __first != __last; ++__first, ++__result)
+        {
+            __t = __binary_op(__t, *__first);
+            *__result = __t;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t1(*__first);
+        *__result = __t1;
+        for (++__first, ++__result; __first != __last; ++__first, ++__result)
+        {
+            typename iterator_traits<_InputIterator>::value_type __t2(*__first);
+            *__result = __t2 - __t1;
+            __t1 = __t2;
+        }
+    }
+    return __result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+inline _LIBCPP_INLINE_VISIBILITY
+_OutputIterator
+adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
+                      _BinaryOperation __binary_op)
+{
+    if (__first != __last)
+    {
+        typename iterator_traits<_InputIterator>::value_type __t1(*__first);
+        *__result = __t1;
+        for (++__first, ++__result; __first != __last; ++__first, ++__result)
+        {
+            typename iterator_traits<_InputIterator>::value_type __t2(*__first);
+            *__result = __binary_op(__t2, __t1);
+            __t1 = __t2;
+        }
+    }
+    return __result;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_NUMERIC
diff --git a/include/ostream b/include/ostream
new file mode 100644
index 0000000..46a3aa5
--- /dev/null
+++ b/include/ostream
@@ -0,0 +1,1291 @@
+// -*- C++ -*-
+//===-------------------------- ostream -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_OSTREAM
+#define _LIBCPP_OSTREAM
+
+/*
+    ostream synopsis
+
+template <class charT, class traits = char_traits<charT> >
+class basic_ostream
+    : virtual public basic_ios<charT,traits>
+{
+public:
+    // types (inherited from basic_ios (27.5.4)):
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // 27.7.2.2 Constructor/destructor:
+    explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
+    basic_ostream(basic_ostream&& rhs);
+    virtual ~basic_ostream();
+
+    // 27.7.2.3 Assign/swap
+    basic_ostream& operator=(basic_ostream&& rhs);
+    void swap(basic_ostream& rhs);
+
+    // 27.7.2.4 Prefix/suffix:
+    class sentry;
+
+    // 27.7.2.6 Formatted output:
+    basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
+    basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
+    basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
+    basic_ostream& operator<<(bool n);
+    basic_ostream& operator<<(short n);
+    basic_ostream& operator<<(unsigned short n);
+    basic_ostream& operator<<(int n);
+    basic_ostream& operator<<(unsigned int n);
+    basic_ostream& operator<<(long n);
+    basic_ostream& operator<<(unsigned long n);
+    basic_ostream& operator<<(long long n);
+    basic_ostream& operator<<(unsigned long long n);
+    basic_ostream& operator<<(float f);
+    basic_ostream& operator<<(double f);
+    basic_ostream& operator<<(long double f);
+    basic_ostream& operator<<(const void* p);
+    basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
+
+    // 27.7.2.7 Unformatted output:
+    basic_ostream& put(char_type c);
+    basic_ostream& write(const char_type* s, streamsize n);
+    basic_ostream& flush();
+
+    // 27.7.2.5 seeks:
+    pos_type tellp();
+    basic_ostream& seekp(pos_type);
+    basic_ostream& seekp(off_type, ios_base::seekdir);
+};
+
+// 27.7.2.6.4 character inserters
+
+template<class charT, class traits>
+  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
+
+template<class charT, class traits>
+  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
+
+template<class traits>
+  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
+
+// signed and unsigned
+
+template<class traits>
+  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
+
+template<class traits>
+  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
+
+// NTBS
+template<class charT, class traits>
+  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
+
+template<class charT, class traits>
+  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
+
+template<class traits>
+  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
+
+// signed and unsigned
+template<class traits>
+basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
+
+template<class traits>
+  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
+
+// swap:
+template <class charT, class traits>
+  void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
+
+template <class charT, class traits>
+  basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
+
+template <class charT, class traits>
+  basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
+
+template <class charT, class traits>
+  basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
+
+// rvalue stream insertion
+template <class charT, class traits, class T>
+  basic_ostream<charT, traits>&
+  operator<<(basic_ostream<charT, traits>&& os, const T& x);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ios>
+#include <streambuf>
+#include <locale>
+#include <iterator>
+#include <bitset>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _CharT, class _Traits>
+class basic_ostream
+    : virtual public basic_ios<_CharT, _Traits>
+{
+public:
+    // types (inherited from basic_ios (27.5.4)):
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    // 27.7.2.2 Constructor/destructor:
+    explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
+    virtual ~basic_ostream();
+protected:
+#ifdef _LIBCPP_MOVE
+    basic_ostream(basic_ostream&& __rhs);
+#endif
+
+    // 27.7.2.3 Assign/swap
+#ifdef _LIBCPP_MOVE
+    basic_ostream& operator=(basic_ostream&& __rhs);
+#endif
+    void swap(basic_ostream& __rhs);
+public:
+
+    // 27.7.2.4 Prefix/suffix:
+    class sentry;
+
+    // 27.7.2.6 Formatted output:
+    basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
+    basic_ostream& operator<<(basic_ios<char_type, traits_type>&
+                              (*__pf)(basic_ios<char_type,traits_type>&));
+    basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
+    basic_ostream& operator<<(bool __n);
+    basic_ostream& operator<<(short __n);
+    basic_ostream& operator<<(unsigned short __n);
+    basic_ostream& operator<<(int __n);
+    basic_ostream& operator<<(unsigned int __n);
+    basic_ostream& operator<<(long __n);
+    basic_ostream& operator<<(unsigned long __n);
+    basic_ostream& operator<<(long long __n);
+    basic_ostream& operator<<(unsigned long long __n);
+    basic_ostream& operator<<(float __f);
+    basic_ostream& operator<<(double __f);
+    basic_ostream& operator<<(long double __f);
+    basic_ostream& operator<<(const void* __p);
+    basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
+
+    // 27.7.2.7 Unformatted output:
+    basic_ostream& put(char_type __c);
+    basic_ostream& write(const char_type* __s, streamsize __n);
+    basic_ostream& flush();
+
+    // 27.7.2.5 seeks:
+    pos_type tellp();
+    basic_ostream& seekp(pos_type __pos);
+    basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
+
+protected:
+    _LIBCPP_ALWAYS_INLINE
+    basic_ostream() {}  // extension, intentially does not initialize
+};
+
+template <class _CharT, class _Traits>
+class basic_ostream<_CharT, _Traits>::sentry
+{
+    bool __ok_;
+    basic_ostream<_CharT, _Traits>& __os_;
+
+    sentry(const sentry&); // = delete;
+    sentry& operator=(const sentry&); // = delete;
+
+public:
+    explicit sentry(basic_ostream<_CharT, _Traits>& __os);
+    ~sentry();
+
+    _LIBCPP_ALWAYS_INLINE
+    // explicit
+        operator bool() const {return __ok_;}
+};
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
+    : __ok_(false),
+      __os_(__os)
+{
+    if (__os.good())
+    {
+        if (__os.tie())
+            __os.tie()->flush();
+        __ok_ = true;
+    }
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>::sentry::~sentry()
+{
+    if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
+                      && !uncaught_exception())
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            if (__os_.rdbuf()->pubsync() == -1)
+                __os_.setstate(ios_base::badbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+        }
+#endif
+    }
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
+{
+    this->init(__sb);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
+{
+    this->move(__rhs);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
+{
+    swap(__rhs);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>::~basic_ostream()
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
+{
+    basic_ios<char_type, traits_type>::swap(__rhs);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
+{
+    return __pf(*this);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
+                                           (*__pf)(basic_ios<char_type,traits_type>&))
+{
+    __pf(*this);
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
+{
+    __pf(*this);
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            if (__sb)
+            {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                try
+                {
+#endif
+                    typedef istreambuf_iterator<_CharT, _Traits> _I;
+                    typedef ostreambuf_iterator<_CharT, _Traits> _O;
+                    _I __i(__sb);
+                    _I __eof;
+                    _O __o(*this);
+                    size_t __c = 0;
+                    for (; __i != __eof; ++__i, ++__o, ++__c)
+                    {
+                        *__o = *__i;
+                        if (__o.failed())
+                            break;
+                    }
+                    if (__c == 0)
+                        this->setstate(ios_base::failbit);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+                }
+                catch (...)
+                {
+                    this->__set_failbit_and_consider_rethrow();
+                }
+#endif
+            }
+            else
+                this->setstate(ios_base::badbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(bool __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(short __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(),
+                        __flags == ios_base::oct || __flags == ios_base::hex ?
+                        static_cast<long>(static_cast<unsigned short>(__n))  :
+                        static_cast<long>(__n)).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(int __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(),
+                        __flags == ios_base::oct || __flags == ios_base::hex ?
+                        static_cast<long>(static_cast<unsigned int>(__n))  :
+                        static_cast<long>(__n)).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(long __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(long long __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(float __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(double __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(long double __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
+            const _F& __f = use_facet<_F>(this->getloc());
+            if (__f.put(*this, *this, this->fill(), __n).failed())
+                this->setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _I;
+            if (__pad_and_output(_I(__os),
+                                 &__c,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     &__c + 1 :
+                                     &__c,
+                                 &__c + 1,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            _CharT __c = __os.widen(__cn);
+            typedef ostreambuf_iterator<_CharT, _Traits> _I;
+            if (__pad_and_output(_I(__os),
+                                 &__c,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     &__c + 1 :
+                                     &__c,
+                                 &__c + 1,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, char __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            if (__pad_and_output(_I(__os),
+                                 &__c,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     &__c + 1 :
+                                     &__c,
+                                 &__c + 1,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            if (__pad_and_output(_I(__os),
+                                 (char*)&__c,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     (char*)&__c + 1 :
+                                     (char*)&__c,
+                                 (char*)&__c + 1,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            if (__pad_and_output(_I(__os),
+                                 (char*)&__c,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     (char*)&__c + 1 :
+                                     (char*)&__c,
+                                 (char*)&__c + 1,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _I;
+            size_t __len = _Traits::length(__str);
+            if (__pad_and_output(_I(__os),
+                                 __str,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     __str + __len :
+                                     __str,
+                                 __str + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _I;
+            size_t __len = char_traits<char>::length(__strn);
+            const int __bs = 100;
+            _CharT __wbb[__bs];
+            _CharT* __wb = __wbb;
+            unique_ptr<_CharT, void(*)(void*)> __h(0, free);
+            if (__len > __bs)
+            {
+                __wb = (_CharT*)malloc(__len*sizeof(_CharT));
+                if (__wb == 0)
+                    __throw_bad_alloc();
+                __h.reset(__wb);
+            }
+            for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
+                *__p = __os.widen(*__strn);
+            if (__pad_and_output(_I(__os),
+                                 __wb,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     __wb + __len :
+                                     __wb,
+                                 __wb + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            size_t __len = _Traits::length(__str);
+            if (__pad_and_output(_I(__os),
+                                 __str,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     __str + __len :
+                                     __str,
+                                 __str + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            size_t __len = _Traits::length((const char*)__str);
+            if (__pad_and_output(_I(__os),
+                                 (const char*)__str,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     (const char*)__str + __len :
+                                     (const char*)__str,
+                                 (const char*)__str + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template<class _Traits>
+basic_ostream<char, _Traits>&
+operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<char, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<char, _Traits> _I;
+            size_t __len = _Traits::length((const char*)__str);
+            if (__pad_and_output(_I(__os),
+                                 (const char*)__str,
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     (const char*)__str + __len :
+                                     (const char*)__str,
+                                 (const char*)__str + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::put(char_type __c)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __s(*this);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _O;
+            _O __o(*this);
+            *__o = __c;
+            if (__o.failed())
+                this->setstate(ios_base::badbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        sentry __sen(*this);
+        if (__sen && __n)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _O;
+            _O __o(*this);
+            for (; __n; --__n, ++__o, ++__s)
+            {
+                *__o = *__s;
+                if (__o.failed())
+                {
+                    this->setstate(ios_base::badbit);
+                    break;
+                }
+            }
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::flush()
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        if (this->rdbuf())
+        {
+            sentry __s(*this);
+            if (__s)
+            {
+                if (this->rdbuf()->pubsync() == -1)
+                    this->setstate(ios_base::badbit);
+            }
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        this->__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_ostream<_CharT, _Traits>::pos_type
+basic_ostream<_CharT, _Traits>::tellp()
+{
+    if (this->fail())
+        return pos_type(-1);
+    return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
+{
+    if (!this->fail())
+    {
+        if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
+            this->setstate(ios_base::failbit);
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
+{
+    if (!this->fail())
+        this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+endl(basic_ostream<_CharT, _Traits>& __os)
+{
+    __os.put(__os.widen('\n'));
+    __os.flush();
+    return __os;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+ends(basic_ostream<_CharT, _Traits>& __os)
+{
+    __os.put(_CharT());
+    return __os;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+flush(basic_ostream<_CharT, _Traits>& __os)
+{
+    __os.flush();
+    return __os;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Stream, class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+    !is_lvalue_reference<_Stream>::value &&
+    is_base_of<ios_base, _Stream>::value,
+    _Stream&
+>::type
+operator<<(_Stream&& __os, const _Tp& __x)
+{
+    __os << __x;
+    return __os;
+}
+
+#endif
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const basic_string<_CharT, _Traits, _Allocator>& __str)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
+        if (__s)
+        {
+            typedef ostreambuf_iterator<_CharT, _Traits> _I;
+            size_t __len = __str.size();
+            if (__pad_and_output(_I(__os),
+                                 __str.data(),
+                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
+                                     __str.data() + __len :
+                                     __str.data(),
+                                 __str.data() + __len,
+                                 __os,
+                                 __os.fill()).failed())
+                __os.setstate(ios_base::badbit | ios_base::failbit);
+        }
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        __os.__set_badbit_and_consider_rethrow();
+    }
+#endif
+    return __os;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
+{
+    return __os << __ec.category().name() << ':' << __ec.value();
+}
+
+template<class _CharT, class _Traits, class _Y>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Y> const& __p)
+{
+    return __os << __p.get();
+}
+
+template <class _CharT, class _Traits, size_t _Size>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, bitset<_Size>& __x)
+{
+    return __os << __x.template to_string<_CharT, _Traits>
+                        (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
+                         use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
+}
+
+extern template class basic_ostream<char>;
+extern template class basic_ostream<wchar_t>;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_OSTREAM
diff --git a/include/queue b/include/queue
new file mode 100644
index 0000000..217206d
--- /dev/null
+++ b/include/queue
@@ -0,0 +1,629 @@
+// -*- C++ -*-
+//===--------------------------- queue ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_QUEUE
+#define _LIBCPP_QUEUE
+
+/*
+    queue synopsis
+
+namespace std
+{
+
+template <class T, class Container = deque<T>>
+class queue
+{
+public:
+    typedef Container                                container_type;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+
+public:
+    queue();
+    explicit queue(const container_type& c);
+    explicit queue(container_type&& c);
+    queue(queue&& q);
+    template <class Alloc>
+        explicit queue(const Alloc& a);
+    template <class Alloc>
+        queue(const container_type& c, const Alloc& a);
+    template <class Alloc>
+        queue(container_type&& c, const Alloc& a);
+    template <class Alloc>
+        queue(queue&& q, const Alloc& a);
+
+    queue& operator=(queue&& q);
+
+    bool      empty() const;
+    size_type size() const;
+
+    reference       front();
+    const_reference front() const;
+    reference       back();
+    const_reference back() const;
+
+    void push(const value_type& v);
+    void push(value_type&& v);
+    template <class... Args> void emplace(Args&&... args);
+    void pop();
+
+    void swap(queue& q);
+};
+
+template <class T, class Container>
+  bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
+
+template <class T, class Container>
+  void swap(queue<T, Container>& x, queue<T, Container>& y);
+
+template <class T, class Container = vector<T>,
+          class Compare = less<typename Container::value_type>>
+class priority_queue
+{
+public:
+    typedef Container                                container_type;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+    Compare comp;
+
+public:
+    explicit priority_queue(const Compare& comp = Compare());
+    priority_queue(const Compare& comp, const container_type& c);
+    explicit priority_queue(const Compare& comp, container_type&& c);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp = Compare());
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp, const container_type& c);
+    template <class InputIterator>
+        priority_queue(InputIterator first, InputIterator last,
+                       const Compare& comp, container_type&& c);
+    priority_queue(priority_queue&& q);
+    priority_queue& operator=(priority_queue&& q);
+    template <class Alloc>
+        explicit priority_queue(const Alloc& a);
+    template <class Alloc>
+        priority_queue(const Compare& comp, const Alloc& a);
+    template <class Alloc>
+        priority_queue(const Compare& comp, const container_type& c,
+                       const Alloc& a);
+    template <class Alloc>
+        priority_queue(const Compare& comp, container_type&& c,
+                       const Alloc& a);
+    template <class Alloc>
+        priority_queue(priority_queue&& q, const Alloc& a);
+
+    bool            empty() const;
+    size_type       size() const;
+    const_reference top() const;
+
+    void push(const value_type& v);
+    void push(value_type&& v);
+    template <class... Args> void emplace(Args&&... args);
+    void pop();
+
+    void swap(priority_queue& q);
+};
+
+template <class T, class Container, class Compare>
+  void swap(priority_queue<T, Container, Compare>& x,
+            priority_queue<T, Container, Compare>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <deque>
+#include <vector>
+#include <functional>
+#include <algorithm>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Container> class queue;
+
+template <class _Tp, class _Container>
+bool
+operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
+
+template <class _Tp, class _Container>
+bool
+operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
+
+template <class _Tp, class _Container = deque<_Tp> >
+class queue
+{
+public:
+    typedef _Container                               container_type;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+
+public:
+    queue() : c() {}
+    explicit queue(const container_type& __c)  : c(__c) {}
+#ifdef _LIBCPP_MOVE
+    explicit queue(container_type&& __c) : c(_STD::move(__c)) {}
+    queue(queue&& __q) : c(_STD::move(__q.c)) {}
+#endif
+    template <class _Alloc>
+        explicit queue(const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(__a) {}
+    template <class _Alloc>
+        queue(const queue& __q, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(__q.c, __a) {}
+    template <class _Alloc>
+        queue(const container_type& __c, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(__c, __a) {}
+#ifdef _LIBCPP_MOVE
+    template <class _Alloc>
+        queue(container_type&& __c, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(_STD::move(__c), __a) {}
+    template <class _Alloc>
+        queue(queue&& __q, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(_STD::move(__q.c), __a) {}
+
+    queue& operator=(queue&& __q)
+    {
+        c = _STD::move(__q.c);
+        return *this;
+    }
+#endif
+
+    bool      empty() const {return c.empty();}
+    size_type size() const  {return c.size();}
+
+    reference       front()       {return c.front();}
+    const_reference front() const {return c.front();}
+    reference       back()        {return c.back();}
+    const_reference back() const  {return c.back();}
+
+    void push(const value_type& __v) {c.push_back(__v);}
+#ifdef _LIBCPP_MOVE
+    void push(value_type&& __v)      {c.push_back(_STD::move(__v));}
+    template <class... _Args>
+        void emplace(_Args&&... __args)
+            {c.emplace_back(_STD::forward<_Args>(__args)...);}
+#endif
+    void pop() {c.pop_front();}
+
+    void swap(queue& __q)
+    {
+        using _STD::swap;
+        swap(c, __q.c);
+    }
+
+    template <class _T1, class _C1>
+    friend
+    bool
+    operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
+    
+    template <class _T1, class _C1>
+    friend
+    bool
+    operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
+};
+
+template <class _Tp, class _Container>
+inline
+bool
+operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return __x.c == __y.c;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return __x.c < __y.c;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Container>
+inline
+void
+swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Tp, class _Container, class _Alloc>
+struct uses_allocator<queue<_Tp, _Container>, _Alloc>
+    : public uses_allocator<_Container, _Alloc>
+{
+};
+
+template <class _Tp, class _Container = vector<_Tp>,
+          class _Compare = less<typename _Container::value_type> >
+class priority_queue
+{
+public:
+    typedef _Container                               container_type;
+    typedef _Compare                                 value_compare;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+    value_compare comp;
+
+public:
+    explicit priority_queue(const value_compare& __comp = value_compare())
+        : c(), comp(__comp) {}
+    priority_queue(const value_compare& __comp, const container_type& __c);
+#ifdef _LIBCPP_MOVE
+    explicit priority_queue(const value_compare& __comp, container_type&& __c);
+#endif
+    template <class _InputIter>
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp = value_compare());
+    template <class _InputIter>
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp, const container_type& __c);
+#ifdef _LIBCPP_MOVE
+    template <class _InputIter>
+        priority_queue(_InputIter __f, _InputIter __l,
+                       const value_compare& __comp, container_type&& __c);
+    priority_queue(priority_queue&& __q);
+    priority_queue& operator=(priority_queue&& __q);
+#endif
+    template <class _Alloc>
+        explicit priority_queue(const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+    template <class _Alloc>
+        priority_queue(const value_compare& __comp, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+    template <class _Alloc>
+        priority_queue(const value_compare& __comp, const container_type& __c,
+                       const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+    template <class _Alloc>
+        priority_queue(const priority_queue& __q, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+#ifdef _LIBCPP_MOVE
+    template <class _Alloc>
+        priority_queue(const value_compare& __comp, container_type&& __c,
+                       const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+    template <class _Alloc>
+        priority_queue(priority_queue&& __q, const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0);
+#endif
+
+    bool            empty() const {return c.empty();}
+    size_type       size() const  {return c.size();}
+    const_reference top() const   {return c.front();}
+
+    void push(const value_type& __v);
+#ifdef _LIBCPP_MOVE
+    void push(value_type&& __v);
+    template <class... _Args> void emplace(_Args&&... __args);
+#endif
+    void pop();
+
+    void swap(priority_queue& __q);
+};
+
+template <class _Tp, class _Container, class _Compare>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
+                                                          const container_type& __c)
+    : c(__c),
+      comp(__comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Container, class _Compare>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
+                                                          container_type&& __c)
+    : c(_STD::move(__c)),
+      comp(__comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+#endif
+
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
+                                                          const value_compare& __comp)
+    : c(__f, __l),
+      comp(__comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
+                                                          const value_compare& __comp,
+                                                          const container_type& __c)
+    : c(__c),
+      comp(__comp)
+{
+    c.insert(c.end(), __f, __l);
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Container, class _Compare>
+template <class _InputIter>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
+                                                          const value_compare& __comp,
+                                                          container_type&& __c)
+    : c(_STD::move(__c)),
+      comp(__comp)
+{
+    c.insert(c.end(), __f, __l);
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q)
+    : c(_STD::move(__q.c)),
+      comp(_STD::move(__q.comp))
+{
+}
+
+template <class _Tp, class _Container, class _Compare>
+priority_queue<_Tp, _Container, _Compare>&
+priority_queue<_Tp, _Container, _Compare>::operator=(priority_queue&& __q)
+{
+    c = _STD::move(__q.c);
+    comp = _STD::move(__q.comp);
+    return *this;
+}
+
+#endif
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(__a)
+{
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
+                                                          const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(__a),
+      comp(__comp)
+{
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
+                                                          const container_type& __c,
+                                                          const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(__c, __a),
+      comp(__comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
+                                                          const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(__q.c, __a),
+      comp(__q.comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
+                                                          container_type&& __c,
+                                                          const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(_STD::move(__c), __a),
+      comp(__comp)
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+
+template <class _Tp, class _Container, class _Compare>
+template <class _Alloc>
+inline
+priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
+                                                          const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type*)
+    : c(_STD::move(__q.c), __a),
+      comp(_STD::move(__q.comp))
+{
+    _STD::make_heap(c.begin(), c.end(), comp);
+}
+
+#endif
+
+template <class _Tp, class _Container, class _Compare>
+inline
+void
+priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
+{
+    c.push_back(__v);
+    _STD::push_heap(c.begin(), c.end(), comp);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Container, class _Compare>
+inline
+void
+priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
+{
+    c.push_back(_STD::move(__v));
+    _STD::push_heap(c.begin(), c.end(), comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+template <class... _Args>
+inline
+void
+priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
+{
+    c.emplace_back(_STD::forward<_Args>(__args)...);
+    _STD::push_heap(c.begin(), c.end(), comp);
+}
+
+#endif
+
+template <class _Tp, class _Container, class _Compare>
+inline
+void
+priority_queue<_Tp, _Container, _Compare>::pop()
+{
+    _STD::pop_heap(c.begin(), c.end(), comp);
+    c.pop_back();
+}
+
+template <class _Tp, class _Container, class _Compare>
+inline
+void
+priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
+{
+    using _STD::swap;
+    swap(c, __q.c);
+    swap(comp, __q.comp);
+}
+
+template <class _Tp, class _Container, class _Compare>
+inline
+void
+swap(priority_queue<_Tp, _Container, _Compare>& __x,
+     priority_queue<_Tp, _Container, _Compare>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Tp, class _Container, class _Compare, class _Alloc>
+struct uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
+    : public uses_allocator<_Container, _Alloc>
+{
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_QUEUE
diff --git a/include/random b/include/random
new file mode 100644
index 0000000..f468020
--- /dev/null
+++ b/include/random
@@ -0,0 +1,2851 @@
+// -*- C++ -*-
+//===--------------------------- random -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_RANDOM
+#define _LIBCPP_RANDOM
+
+/*
+    random synopsis
+
+#include <initializer_list>
+
+namespace std
+{
+
+// Engines
+
+template <class UIntType, UIntType a, UIntType c, UIntType m>
+class linear_congruential_engine
+{
+public:
+    // types
+    typedef UIntType result_type;
+
+    // engine characteristics
+    static constexpr result_type multiplier = a;
+    static constexpr result_type increment = c;
+    static constexpr result_type modulus = m;
+    static constexpr result_type min() { return c == 0u ? 1u: 0u;}
+    static constexpr result_type max() { return m - 1u;}
+    static constexpr result_type default_seed = 1u;
+
+    // constructors and seeding functions
+    explicit linear_congruential_engine(result_type s = default_seed);
+    template<class Sseq> explicit linear_congruential_engine(Sseq& q);
+    void seed(result_type s = default_seed);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long z);
+};
+
+template <class UIntType, UIntType a, UIntType c, UIntType m>
+bool
+operator==(const linear_congruential_engine<UIntType, a, c, m>& x,
+           const linear_congruential_engine<UIntType, a, c, m>& y);
+
+template <class UIntType, UIntType a, UIntType c, UIntType m>
+bool
+operator!=(const linear_congruential_engine<UIntType, a, c, m>& x,
+           const linear_congruential_engine<UIntType, a, c, m>& y);
+
+template <class charT, class traits,
+          class UIntType, UIntType a, UIntType c, UIntType m>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const linear_congruential_engine<UIntType, a, c, m>& x);
+
+template <class charT, class traits,
+          class UIntType, UIntType a, UIntType c, UIntType m>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           linear_congruential_engine<UIntType, a, c, m>& x);
+
+template <class UIntType, size_t w, size_t n, size_t m, size_t r,
+          UIntType a, size_t u, UIntType d, size_t s,
+          UIntType b, size_t t, UIntType c, size_t l, UIntType f>
+class mersenne_twister_engine
+{
+public:
+    // types
+    typedef UIntType result_type;
+
+    // engine characteristics
+    static constexpr size_t word_size = w;
+    static constexpr size_t state_size = n;
+    static constexpr size_t shift_size = m;
+    static constexpr size_t mask_bits = r;
+    static constexpr result_type xor_mask = a;
+    static constexpr size_t tempering_u = u;
+    static constexpr result_type tempering_d = d;
+    static constexpr size_t tempering_s = s;
+    static constexpr result_type tempering_b = b;
+    static constexpr size_t tempering_t = t;
+    static constexpr result_type tempering_c = c;
+    static constexpr size_t tempering_l = l;
+    static constexpr result_type initialization_multiplier = f;
+    static constexpr result_type min () { return 0; }
+    static constexpr result_type max() { return 2^w - 1; }
+    static constexpr result_type default_seed = 5489u;
+
+    // constructors and seeding functions
+    explicit mersenne_twister_engine(result_type value = default_seed);
+    template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
+    void seed(result_type value = default_seed);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long z);
+};
+
+template <class UIntType, size_t w, size_t n, size_t m, size_t r,
+          UIntType a, size_t u, UIntType d, size_t s,
+          UIntType b, size_t t, UIntType c, size_t l, UIntType f>
+bool
+operator==(
+    const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
+    const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
+
+template <class UIntType, size_t w, size_t n, size_t m, size_t r,
+          UIntType a, size_t u, UIntType d, size_t s,
+          UIntType b, size_t t, UIntType c, size_t l, UIntType f>
+bool
+operator!=(
+    const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
+    const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
+
+template <class charT, class traits,
+          class UIntType, size_t w, size_t n, size_t m, size_t r,
+          UIntType a, size_t u, UIntType d, size_t s,
+          UIntType b, size_t t, UIntType c, size_t l, UIntType f>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
+
+template <class charT, class traits,
+          class UIntType, size_t w, size_t n, size_t m, size_t r,
+          UIntType a, size_t u, UIntType d, size_t s,
+          UIntType b, size_t t, UIntType c, size_t l, UIntType f>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
+
+template<class UIntType, size_t w, size_t s, size_t r>
+class subtract_with_carry_engine
+{
+public:
+    // types
+    typedef UIntType result_type;
+
+    // engine characteristics
+    static constexpr size_t word_size = w;
+    static constexpr size_t short_lag = s;
+    static constexpr size_t long_lag = r;
+    static constexpr result_type min() { return 0; }
+    static constexpr result_type max() { return m-1; }
+    static constexpr result_type default_seed = 19780503u;
+
+    // constructors and seeding functions
+    explicit subtract_with_carry_engine(result_type value = default_seed);
+    template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
+    void seed(result_type value = default_seed);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long z);
+};
+
+template<class UIntType, size_t w, size_t s, size_t r>
+bool
+operator==(
+    const subtract_with_carry_engine<UIntType, w, s, r>& x,
+    const subtract_with_carry_engine<UIntType, w, s, r>& y);
+
+template<class UIntType, size_t w, size_t s, size_t r>
+bool
+operator!=(
+    const subtract_with_carry_engine<UIntType, w, s, r>& x,
+    const subtract_with_carry_engine<UIntType, w, s, r>& y);
+
+template <class charT, class traits,
+          class UIntType, size_t w, size_t s, size_t r>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const subtract_with_carry_engine<UIntType, w, s, r>& x);
+
+template <class charT, class traits,
+          class UIntType, size_t w, size_t s, size_t r>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           subtract_with_carry_engine<UIntType, w, s, r>& x);
+
+template<class Engine, size_t p, size_t r>
+class discard_block_engine
+{
+public:
+    // types
+    typedef typename Engine::result_type result_type;
+
+    // engine characteristics
+    static constexpr size_t block_size = p;
+    static constexpr size_t used_block = r;
+    static constexpr result_type min() { return Engine::min(); }
+    static constexpr result_type max() { return Engine::max(); }
+
+    // constructors and seeding functions
+    discard_block_engine();
+    explicit discard_block_engine(const Engine& e);
+    explicit discard_block_engine(Engine&& e);
+    explicit discard_block_engine(result_type s);
+    template<class Sseq> explicit discard_block_engine(Sseq& q);
+    void seed();
+    void seed(result_type s);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long z);
+
+    // property functions
+    const Engine& base() const;
+};
+
+template<class Engine, size_t p, size_t r>
+bool
+operator==(
+    const discard_block_engine<Engine, p, r>& x,
+    const discard_block_engine<Engine, p, r>& y);
+
+template<class Engine, size_t p, size_t r>
+bool
+operator!=(
+    const discard_block_engine<Engine, p, r>& x,
+    const discard_block_engine<Engine, p, r>& y);
+
+template <class charT, class traits,
+          class Engine, size_t p, size_t r>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const discard_block_engine<Engine, p, r>& x);
+
+template <class charT, class traits,
+          class Engine, size_t p, size_t r>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           discard_block_engine<Engine, p, r>& x);
+
+template<class Engine, size_t w, class UIntType>
+class independent_bits_engine
+{
+public:
+    // types
+    typedef UIntType result_type;
+
+    // engine characteristics
+    static constexpr result_type min() { return 0; }
+    static constexpr result_type max() { return 2^w - 1; }
+
+    // constructors and seeding functions
+    independent_bits_engine();
+    explicit independent_bits_engine(const Engine& e);
+    explicit independent_bits_engine(Engine&& e);
+    explicit independent_bits_engine(result_type s);
+    template<class Sseq> explicit independent_bits_engine(Sseq& q);
+    void seed();
+    void seed(result_type s);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()(); void discard(unsigned long long z);
+
+    // property functions
+    const Engine& base() const;
+};
+
+template<class Engine, size_t w, class UIntType>
+bool
+operator==(
+    const independent_bits_engine<Engine, w, UIntType>& x,
+    const independent_bits_engine<Engine, w, UIntType>& y);
+
+template<class Engine, size_t w, class UIntType>
+bool
+operator!=(
+    const independent_bits_engine<Engine, w, UIntType>& x,
+    const independent_bits_engine<Engine, w, UIntType>& y);
+
+template <class charT, class traits,
+          class Engine, size_t w, class UIntType>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const independent_bits_engine<Engine, w, UIntType>& x);
+
+template <class charT, class traits,
+          class Engine, size_t w, class UIntType>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           independent_bits_engine<Engine, w, UIntType>& x);
+
+template<class Engine, size_t k>
+class shuffle_order_engine
+{
+public:
+    // types
+    typedef typename Engine::result_type result_type;
+
+    // engine characteristics
+    static constexpr size_t table_size = k;
+    static constexpr result_type min() { return Engine::min; }
+    static constexpr result_type max() { return Engine::max; }
+
+    // constructors and seeding functions
+    shuffle_order_engine();
+    explicit shuffle_order_engine(const Engine& e);
+    explicit shuffle_order_engine(Engine&& e);
+    explicit shuffle_order_engine(result_type s);
+    template<class Sseq> explicit shuffle_order_engine(Sseq& q);
+    void seed();
+    void seed(result_type s);
+    template<class Sseq> void seed(Sseq& q);
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long z);
+
+    // property functions
+    const Engine& base() const;
+};
+
+template<class Engine, size_t k>
+bool
+operator==(
+    const shuffle_order_engine<Engine, k>& x,
+    const shuffle_order_engine<Engine, k>& y);
+
+template<class Engine, size_t k>
+bool
+operator!=(
+    const shuffle_order_engine<Engine, k>& x,
+    const shuffle_order_engine<Engine, k>& y);
+
+template <class charT, class traits,
+          class Engine, size_t k>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os,
+           const shuffle_order_engine<Engine, k>& x);
+
+template <class charT, class traits,
+          class Engine, size_t k>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is,
+           shuffle_order_engine<Engine, k>& x);
+
+typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
+                                                                   minstd_rand0;
+typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
+                                                                    minstd_rand;
+typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
+                                0x9908b0df,
+                                11, 0xffffffff,
+                                7,  0x9d2c5680,
+                                15, 0xefc60000,
+                                18, 1812433253>                         mt19937;
+typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
+                                0xb5026f5aa96619e9,
+                                29, 0x5555555555555555,
+                                17, 0x71d67fffeda60000,
+                                37, 0xfff7eee000000000,
+                                43, 6364136223846793005>             mt19937_64;
+typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base;
+typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base;
+typedef discard_block_engine<ranlux24_base, 223, 23>                   ranlux24;
+typedef discard_block_engine<ranlux48_base, 389, 11>                   ranlux48;
+typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b;
+typedef minstd_rand0                                      default_random_engine;
+
+// Generators
+
+class random_device
+{
+public:
+    // types
+    typedef unsigned int result_type;
+
+    // generator characteristics
+    static constexpr result_type min() { return numeric_limits<result_type>::min(); }
+    static constexpr result_type max() { return numeric_limits<result_type>::max(); }
+
+    // constructors
+    explicit random_device(const string& token = "/dev/urandom");
+
+    // generating functions
+    result_type operator()();
+
+    // property functions
+    double entropy() const;
+
+    // no copy functions
+    random_device(const random_device& ) = delete;
+    void operator=(const random_device& ) = delete;
+};
+
+// Utilities
+
+class seed_seq
+{
+public:
+    // types
+    typedef uint_least32_t result_type;
+
+    // constructors
+    seed_seq();
+    template<class T>
+        seed_seq(initializer_list<T> il);
+    template<class InputIterator>
+        seed_seq(InputIterator begin, InputIterator end);
+
+    // generating functions
+    template<class RandomAccessIterator>
+        void generate(RandomAccessIterator begin, RandomAccessIterator end);
+
+    // property functions
+    size_t size() const;
+    template<class OutputIterator>
+        void param(OutputIterator dest) const;
+
+    // no copy functions
+    seed_seq(const seed_seq&) = delete;
+    void operator=(const seed_seq& ) = delete;
+};
+
+template<class RealType, size_t bits, class URNG>
+    RealType generate_canonical(URNG& g);
+
+// Distributions
+
+template<class IntType = int>
+class uniform_int_distribution
+{
+public:
+    // types
+    typedef IntType result_type;
+
+    class param_type
+    {
+    public:
+        typedef uniform_int_distribution distribution_type;
+
+        explicit param_type(IntType a = 0,
+                                    IntType b = numeric_limits<IntType>::max());
+
+        result_type a() const;
+        result_type b() const;
+
+        friend bool operator==(const param_type& x, const param_type& y);
+        friend bool operator!=(const param_type& x, const param_type& y);
+    };
+
+    // constructors and reset functions
+    explicit uniform_int_distribution(IntType a = 0,
+                                    IntType b = numeric_limits<IntType>::max());
+    explicit uniform_int_distribution(const param_type& parm);
+    void reset();
+
+    // generating functions
+    template<class URNG> result_type operator()(URNG& g);
+    template<class URNG> result_type operator()(URNG& g, const param_type& parm);
+
+    // property functions
+    result_type a() const;
+    result_type b() const;
+
+    param_type param() const;
+    void param(const param_type& parm);
+
+    result_type min() const;
+    result_type max() const;
+
+    friend bool operator==(const uniform_int_distribution& x,
+                           const uniform_int_distribution& y);
+    friend bool operator!=(const uniform_int_distribution& x,
+                           const uniform_int_distribution& y);
+
+    template <class charT, class traits>
+    friend
+    basic_ostream<charT, traits>&
+    operator<<(basic_ostream<charT, traits>& os,
+               const uniform_int_distribution& x);
+    
+    template <class charT, class traits>
+    friend
+    basic_istream<charT, traits>&
+    operator>>(basic_istream<charT, traits>& is,
+               uniform_int_distribution& x);
+};
+
+template<class RealType = double>
+class uniform_real_distribution
+{
+public:
+    // types
+    typedef RealType result_type;
+
+    class param_type
+    {
+    public:
+        typedef uniform_real_distribution distribution_type;
+
+        explicit param_type(RealType a = 0,
+                            RealType b = 1);
+
+        result_type a() const;
+        result_type b() const;
+
+        friend bool operator==(const param_type& x, const param_type& y);
+        friend bool operator!=(const param_type& x, const param_type& y);
+    };
+
+    // constructors and reset functions
+    explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
+    explicit uniform_real_distribution(const param_type& parm);
+    void reset();
+
+    // generating functions
+    template<class URNG> result_type operator()(URNG& g);
+    template<class URNG> result_type operator()(URNG& g, const param_type& parm);
+
+    // property functions
+    result_type a() const;
+    result_type b() const;
+
+    param_type param() const;
+    void param(const param_type& parm);
+
+    result_type min() const;
+    result_type max() const;
+
+    friend bool operator==(const uniform_real_distribution& x,
+                           const uniform_real_distribution& y);
+    friend bool operator!=(const uniform_real_distribution& x,
+                           const uniform_real_distribution& y);
+
+    template <class charT, class traits>
+    friend
+    basic_ostream<charT, traits>&
+    operator<<(basic_ostream<charT, traits>& os,
+               const uniform_real_distribution& x);
+    
+    template <class charT, class traits>
+    friend
+    basic_istream<charT, traits>&
+    operator>>(basic_istream<charT, traits>& is,
+               uniform_real_distribution& x);
+};
+
+class bernoulli_distribution
+{
+public:
+    // types
+    typedef bool result_type;
+
+    class param_type
+    {
+    public:
+        typedef bernoulli_distribution distribution_type;
+
+        explicit param_type(double p = 0.5);
+
+        double p() const;
+
+        friend bool operator==(const param_type& x, const param_type& y);
+        friend bool operator!=(const param_type& x, const param_type& y);
+    };
+
+    // constructors and reset functions
+    explicit bernoulli_distribution(double p = 0.5);
+    explicit bernoulli_distribution(const param_type& parm);
+    void reset();
+
+    // generating functions
+    template<class URNG> result_type operator()(URNG& g);
+    template<class URNG> result_type operator()(URNG& g, const param_type& parm);
+
+    // property functions
+    double p() const;
+
+    param_type param() const;
+    void param(const param_type& parm);
+
+    result_type min() const;
+    result_type max() const;
+
+    friend bool operator==(const bernoulli_distribution& x,
+                           const bernoulli_distribution& y);
+    friend bool operator!=(const bernoulli_distribution& x,
+                           const bernoulli_distribution& y);
+
+    template <class charT, class traits>
+    friend
+    basic_ostream<charT, traits>&
+    operator<<(basic_ostream<charT, traits>& os,
+               const bernoulli_distribution& x);
+    
+    template <class charT, class traits>
+    friend
+    basic_istream<charT, traits>&
+    operator>>(basic_istream<charT, traits>& is,
+               bernoulli_distribution& x);
+};
+
+template<class IntType = int>
+    class binomial_distribution;
+
+template<class IntType = int>
+    class geometric_distribution;
+
+template<class IntType = int>
+    class negative_binomial_distribution;
+
+template<class IntType = int>
+    class poisson_distribution;
+
+template<class RealType = double>
+    class exponential_distribution;
+
+template<class RealType = double>
+    class gamma_distribution;
+
+template<class RealType = double>
+    class weibull_distribution;
+
+template<class RealType = double>
+    class extreme_value_distribution;
+
+template<class RealType = double>
+    class normal_distribution;
+
+template<class RealType = double>
+    class lognormal_distribution;
+
+template<class RealType = double>
+    class chi_squared_distribution;
+
+template<class RealType = double>
+    class cauchy_distribution;
+
+template<class RealType = double>
+    class fisher_f_distribution;
+
+template<class RealType = double>
+    class student_t_distribution;
+
+template<class IntType = int>
+    class discrete_distribution;
+
+template<class RealType = double>
+    class piecewise_constant_distribution;
+
+template<class RealType = double>
+    class piecewise_linear_distribution;
+
+} // std
+*/
+
+#include <__config>
+#include <cstddef>
+#include <type_traits>
+#include <initializer_list>
+#include <cstdint>
+#include <limits>
+#include <algorithm>
+#include <vector>
+#include <string>
+#include <istream>
+#include <ostream>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// linear_congruential_engine
+
+template <unsigned long long __a, unsigned long long __c,
+          unsigned long long __m, unsigned long long _M,
+          bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_M-__c)/__a)>
+struct __lce_ta;
+
+// 64
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
+struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true>
+{
+    typedef unsigned long long result_type;
+    static result_type next(result_type __x)
+    {
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        __x += __c - (__x >= __m - __c) * __m;
+        return __x;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __m>
+struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true>
+{
+    typedef unsigned long long result_type;
+    static result_type next(result_type __x)
+    {
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        return __x;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m>
+struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false>
+{
+    typedef unsigned long long result_type;
+    static result_type next(result_type __x)
+    {
+        return (__a * __x + __c) % __m;
+    }
+};
+
+template <unsigned long long __a, unsigned long long __c>
+struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false>
+{
+    typedef unsigned long long result_type;
+    static result_type next(result_type __x)
+    {
+        return __a * __x + __c;
+    }
+};
+
+// 32
+
+template <unsigned long long _A, unsigned long long _C, unsigned long long _M>
+struct __lce_ta<_A, _C, _M, unsigned(~0), true>
+{
+    typedef unsigned result_type;
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_A);
+        const result_type __c = static_cast<result_type>(_C);
+        const result_type __m = static_cast<result_type>(_M);
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        __x += __c - (__x >= __m - __c) * __m;
+        return __x;
+    }
+};
+
+template <unsigned long long _A, unsigned long long _M>
+struct __lce_ta<_A, 0, _M, unsigned(~0), true>
+{
+    typedef unsigned result_type;
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_A);
+        const result_type __m = static_cast<result_type>(_M);
+        // Schrage's algorithm
+        const result_type __q = __m / __a;
+        const result_type __r = __m % __a;
+        const result_type __t0 = __a * (__x % __q);
+        const result_type __t1 = __r * (__x / __q);
+        __x = __t0 + (__t0 < __t1) * __m - __t1;
+        return __x;
+    }
+};
+
+template <unsigned long long _A, unsigned long long _C, unsigned long long _M>
+struct __lce_ta<_A, _C, _M, unsigned(~0), false>
+{
+    typedef unsigned result_type;
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_A);
+        const result_type __c = static_cast<result_type>(_C);
+        const result_type __m = static_cast<result_type>(_M);
+        return (__a * __x + __c) % __m;
+    }
+};
+
+template <unsigned long long _A, unsigned long long _C>
+struct __lce_ta<_A, _C, 0, unsigned(~0), false>
+{
+    typedef unsigned result_type;
+    static result_type next(result_type __x)
+    {
+        const result_type __a = static_cast<result_type>(_A);
+        const result_type __c = static_cast<result_type>(_C);
+        return __a * __x + __c;
+    }
+};
+
+// 16
+
+template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b>
+struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b>
+{
+    typedef unsigned short result_type;
+    static result_type next(result_type __x)
+    {
+        return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x));
+    }
+};
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+class linear_congruential_engine;
+
+template <class _CharT, class _Traits,
+          class _U, _U _A, _U _C, _U _N>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const linear_congruential_engine<_U, _A, _C, _N>&);
+
+template <class _CharT, class _Traits,
+          class _U, _U _A, _U _C, _U _N>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           linear_congruential_engine<_U, _A, _C, _N>& __x);
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+class linear_congruential_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_;
+
+    static const result_type _M = result_type(~0);
+
+    static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters");
+    static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters");
+public:
+    static const result_type _Min = __c == 0u ? 1u: 0u;
+    static const result_type _Max = __m - 1u;
+    static_assert(_Min < _Max,           "linear_congruential_engine invalid parameters");
+
+    // engine characteristics
+    static const/*expr*/ result_type multiplier = __a;
+    static const/*expr*/ result_type increment = __c;
+    static const/*expr*/ result_type modulus = __m;
+    static const/*expr*/ result_type min() {return _Min;}
+    static const/*expr*/ result_type max() {return _Max;}
+    static const/*expr*/ result_type default_seed = 1u;
+
+    // constructors and seeding functions
+    explicit linear_congruential_engine(result_type __s = default_seed)
+        {seed(__s);}
+    template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q)
+        {seed(__q);}
+    void seed(result_type __s = default_seed)
+        {seed(integral_constant<bool, __m == 0>(),
+              integral_constant<bool, __c == 0>(), __s);}
+    template<class _Sseq>
+        typename enable_if
+        <
+            !is_convertible<_Sseq, result_type>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned,
+                1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32
+                             :  (__m-1) / 0x100000000ull)>());}
+
+    // generating functions
+    result_type operator()()
+        {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _M>::next(__x_));}
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    friend bool operator==(const linear_congruential_engine& __x,
+                           const linear_congruential_engine& __y)
+        {return __x.__x_ == __y.__x_;}
+    friend bool operator!=(const linear_congruential_engine& __x,
+                           const linear_congruential_engine& __y)
+        {return !(__x == __y);}
+
+private:
+
+    void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;}
+    void seed(true_type, false_type, result_type __s) {__x_ = __s;}
+    void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ?
+                                                                 1 : __s % __m;}
+    void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;}
+
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+
+    template <class _CharT, class _Traits,
+              class _U, _U _A, _U _C, _U _N>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const linear_congruential_engine<_U, _A, _C, _N>&);
+    
+    template <class _CharT, class _Traits,
+              class _U, _U _A, _U _C, _U _N>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               linear_congruential_engine<_U, _A, _C, _N>& __x);
+};
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+template<class _Sseq>
+void
+linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
+                                                 integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__k+3];
+    __q.generate(__ar, __ar + __k + 3);
+    result_type __s = static_cast<result_type>(__ar[3] % __m);
+    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
+}
+
+template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+template<class _Sseq>
+void
+linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q,
+                                                 integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__k+3];
+    __q.generate(__ar, __ar + __k + 3);
+    result_type __s = static_cast<result_type>((__ar[3] +
+                                                (uint64_t)__ar[4] << 32) % __m);
+    __x_ = __c == 0 && __s == 0 ? result_type(1) : __s;
+}
+
+template <class _CharT, class _Traits>
+class __save_flags
+{
+    typedef basic_ios<_CharT, _Traits> __stream_type;
+    typedef typename __stream_type::fmtflags fmtflags;
+
+    __stream_type& __stream_;
+    fmtflags       __fmtflags_;
+    _CharT         __fill_;
+
+    __save_flags(const __save_flags&);
+    __save_flags& operator=(const __save_flags&);
+public:
+    explicit __save_flags(__stream_type& __stream)
+        : __stream_(__stream),
+          __fmtflags_(__stream.flags()),
+          __fill_(__stream.fill())
+        {}
+    ~__save_flags()
+    {
+        __stream_.flags(__fmtflags_);
+        __stream_.fill(__fill_);
+    }
+};
+
+template <class _CharT, class _Traits,
+          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+inline
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    __os.fill(__os.widen(' '));
+    return __os << __x.__x_;
+}
+
+template <class _CharT, class _Traits,
+          class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    _UIntType __t;
+    __is >> __t;
+    if (!__is.fail())
+        __x.__x_ = __t;
+    return __is;
+}
+
+typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
+                                                                   minstd_rand0;
+typedef minstd_rand0                                      default_random_engine;
+typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
+                                                                    minstd_rand;
+// mersenne_twister_engine
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+class mersenne_twister_engine;
+
+template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+bool
+operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __y);
+
+template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+bool
+operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __y);
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x);
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                   _B, _T, _C, _L, _F>& __x);
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+class mersenne_twister_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_[__n];
+    size_t      __i_;
+
+    static_assert(  0 <  __m, "mersenne_twister_engine invalid parameters");
+    static_assert(__m <= __n, "mersenne_twister_engine invalid parameters");
+    static const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters");
+    static_assert(  2 <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__r <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__u <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__s <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__t <= __w, "mersenne_twister_engine invalid parameters");
+    static_assert(__l <= __w, "mersenne_twister_engine invalid parameters");
+public:
+    static const result_type _Min = 0;
+    static const result_type _Max = __w == _Dt ? result_type(~0) :
+                                   (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters");
+    static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
+
+    // engine characteristics
+    static const/*expr*/ size_t word_size = __w;
+    static const/*expr*/ size_t state_size = __n;
+    static const/*expr*/ size_t shift_size = __m;
+    static const/*expr*/ size_t mask_bits = __r;
+    static const/*expr*/ result_type xor_mask = __a;
+    static const/*expr*/ size_t tempering_u = __u;
+    static const/*expr*/ result_type tempering_d = __d;
+    static const/*expr*/ size_t tempering_s = __s;
+    static const/*expr*/ result_type tempering_b = __b;
+    static const/*expr*/ size_t tempering_t = __t;
+    static const/*expr*/ result_type tempering_c = __c;
+    static const/*expr*/ size_t tempering_l = __l;
+    static const/*expr*/ result_type initialization_multiplier = __f;
+    static const/*expr*/ result_type min() { return _Min; }
+    static const/*expr*/ result_type max() { return _Max; }
+    static const/*expr*/ result_type default_seed = 5489u;
+
+    // constructors and seeding functions
+    explicit mersenne_twister_engine(result_type __sd = default_seed)
+        {seed(__sd);}
+    template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q)
+        {seed(__q);}
+    void seed(result_type __sd = default_seed);
+    template<class _Sseq>
+        typename enable_if
+        <
+            !is_convertible<_Sseq, result_type>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+              _UI _A, size_t _U, _UI _D, size_t _S,
+              _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+    friend
+    bool
+    operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                             _B, _T, _C, _L, _F>& __x,
+               const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                             _B, _T, _C, _L, _F>& __y);
+    
+    template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+              _UI _A, size_t _U, _UI _D, size_t _S,
+              _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+    friend
+    bool
+    operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                             _B, _T, _C, _L, _F>& __x,
+               const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                             _B, _T, _C, _L, _F>& __y);
+
+    template <class _CharT, class _Traits,
+              class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+              _UI _A, size_t _U, _UI _D, size_t _S,
+              _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                             _B, _T, _C, _L, _F>& __x);
+
+    template <class _CharT, class _Traits,
+              class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+              _UI _A, size_t _U, _UI _D, size_t _S,
+              _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                       _B, _T, _C, _L, _F>& __x);
+private:
+
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            __count < __w,
+            result_type
+        >::type
+        __lshift(result_type __x) {return (__x << __count) & _Max;}
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            (__count >= __w),
+            result_type
+        >::type
+        __lshift(result_type __x) {return result_type(0);}
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            __count < _Dt,
+            result_type
+        >::type
+        __rshift(result_type __x) {return __x >> __count;}
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            (__count >= _Dt),
+            result_type
+        >::type
+        __rshift(result_type __x) {return result_type(0);}
+};
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::seed(result_type __sd)
+{   // __w >= 2
+    __x_[0] = __sd & _Max;
+    for (size_t __i = 1; __i < __n; ++__i)
+        __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max;
+    __i_ = 0;
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+template<class _Sseq>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__n * __k];
+    __q.generate(__ar, __ar + __n * __k);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    __i_ = 0;
+    if ((__x_[0] & ~__mask) == 0)
+    {
+        for (size_t __i = 1; __i < __n; ++__i)
+            if (__x_[__i] != 0)
+                return;
+        __x_[0] = _Max;
+    }
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+template<class _Sseq>
+void
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__n * __k];
+    __q.generate(__ar, __ar + __n * __k);
+    for (size_t __i = 0; __i < __n; ++__i)
+        __x_[__i] = static_cast<result_type>(
+            (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    __i_ = 0;
+    if ((__x_[0] & ~__mask) == 0)
+    {
+        for (size_t __i = 1; __i < __n; ++__i)
+            if (__x_[__i] != 0)
+                return;
+        __x_[0] = _Max;
+    }
+}
+
+template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r,
+          _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+          _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f>
+_UIntType
+mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b,
+    __t, __c, __l, __f>::operator()()
+{
+    const size_t __j = (__i_ + 1) % __n;
+    const result_type __mask = __r == _Dt ? result_type(~0) :
+                                       (result_type(1) << __r) - result_type(1);
+    const result_type _Y = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask);
+    const size_t __k = (__i_ + __m) % __n;
+    __x_[__i_] = __x_[__k] ^ __rshift<1>(_Y) ^ (__a * (_Y & 1));
+    result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d);
+    __i_ = __j;
+    __z ^= __lshift<__s>(__z) & __b;
+    __z ^= __lshift<__t>(__z) & __c;
+    return __z ^ __rshift<__l>(__z);
+}
+
+template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+bool
+operator==(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __y)
+{
+    if (__x.__i_ == __y.__i_)
+        return _STD::equal(__x.__x_, __x.__x_ + _N, __y.__x_);
+    if (__x.__i_ == 0 || __y.__i_ == 0)
+    {
+        size_t __j = _STD::min(_N - __x.__i_, _N - __y.__i_);
+        if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (__x.__i_ == 0)
+            return _STD::equal(__x.__x_ + __j, __x.__x_ + _N, __y.__x_);
+        return _STD::equal(__x.__x_, __x.__x_ + (_N - __j), __y.__x_ + __j);
+    }
+    if (__x.__i_ < __y.__i_)
+    {
+        size_t __j = _N - __y.__i_;
+        if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (!_STD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _N,
+                         __y.__x_))
+            return false;
+        return _STD::equal(__x.__x_, __x.__x_ + __x.__i_,
+                           __y.__x_ + (_N - (__x.__i_ + __j)));
+    }
+    size_t __j = _N - __x.__i_;
+    if (!_STD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
+                     __x.__x_ + __x.__i_))
+        return false;
+    if (!_STD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _N,
+                     __x.__x_))
+        return false;
+    return _STD::equal(__y.__x_, __y.__x_ + __y.__i_,
+                       __x.__x_ + (_N - (__y.__i_ + __j)));
+}
+
+template <class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+inline
+bool
+operator!=(const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                         _B, _T, _C, _L, _F>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__x_[__x.__i_];
+    for (size_t __j = __x.__i_ + 1; __j < _N; ++__j)
+        __os << __sp << __x.__x_[__j];
+    for (size_t __j = 0; __j < __x.__i_; ++__j)
+        __os << __sp << __x.__x_[__j];
+    return __os;
+}
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _N, size_t _M, size_t _R,
+          _UI _A, size_t _U, _UI _D, size_t _S,
+          _UI _B, size_t _T, _UI _C, size_t _L, _UI _F>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           mersenne_twister_engine<_UI, _W, _N, _M, _R, _A, _U, _D, _S,
+                                   _B, _T, _C, _L, _F>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    _UI __t[_N];
+    for (size_t __i = 0; __i < _N; ++__i)
+        __is >> __t[__i];
+    if (!__is.fail())
+    {
+        for (size_t __i = 0; __i < _N; ++__i)
+            __x.__x_[__i] = __t[__i];
+        __x.__i_ = 0;
+    }
+    return __is;
+}
+
+typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31,
+                                0x9908b0df, 11, 0xffffffff,
+                                7,  0x9d2c5680,
+                                15, 0xefc60000,
+                                18, 1812433253>                         mt19937;
+typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31,
+                                0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL,
+                                17, 0x71d67fffeda60000ULL,
+                                37, 0xfff7eee000000000ULL,
+                                43, 6364136223846793005ULL>          mt19937_64;
+
+// subtract_with_carry_engine
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+class subtract_with_carry_engine;
+
+template<class _UI, size_t _W, size_t _S, size_t _R>
+bool
+operator==(
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __y);
+
+template<class _UI, size_t _W, size_t _S, size_t _R>
+bool
+operator!=(
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __y);
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _S, size_t _R>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const subtract_with_carry_engine<_UI, _W, _S, _R>& __x);
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _S, size_t _R>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           subtract_with_carry_engine<_UI, _W, _S, _R>& __x);
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+class subtract_with_carry_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    result_type __x_[__r];
+    result_type  __c_;
+    size_t      __i_;
+
+    static const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(  0 <  __w, "subtract_with_carry_engine invalid parameters");
+    static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters");
+    static_assert(  0 <  __s, "subtract_with_carry_engine invalid parameters");
+    static_assert(__s <  __r, "subtract_with_carry_engine invalid parameters");
+public:
+    static const result_type _Min = 0;
+    static const result_type _Max = __w == _Dt ? result_type(~0) :
+                                   (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
+
+    // engine characteristics
+    static const/*expr*/ size_t word_size = __w;
+    static const/*expr*/ size_t short_lag = __s;
+    static const/*expr*/ size_t long_lag = __r;
+    static const/*expr*/ result_type min() { return _Min; }
+    static const/*expr*/ result_type max() { return _Max; }
+    static const/*expr*/ result_type default_seed = 19780503u;
+
+    // constructors and seeding functions
+    explicit subtract_with_carry_engine(result_type __sd = default_seed)
+        {seed(__sd);}
+    template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q)
+        {seed(__q);}
+    void seed(result_type __sd = default_seed)
+        {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+    template<class _Sseq>
+        typename enable_if
+        <
+            !is_convertible<_Sseq, result_type>::value,
+            void
+        >::type
+        seed(_Sseq& __q)
+            {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    template<class _UI, size_t _W, size_t _S, size_t _R>
+    friend
+    bool
+    operator==(
+        const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+        const subtract_with_carry_engine<_UI, _W, _S, _R>& __y);
+    
+    template<class _UI, size_t _W, size_t _S, size_t _R>
+    friend
+    bool
+    operator!=(
+        const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+        const subtract_with_carry_engine<_UI, _W, _S, _R>& __y);
+    
+    template <class _CharT, class _Traits,
+              class _UI, size_t _W, size_t _S, size_t _R>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const subtract_with_carry_engine<_UI, _W, _S, _R>& __x);
+    
+    template <class _CharT, class _Traits,
+              class _UI, size_t _W, size_t _S, size_t _R>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               subtract_with_carry_engine<_UI, _W, _S, _R>& __x);
+
+private:
+
+    void seed(result_type __sd, integral_constant<unsigned, 1>);
+    void seed(result_type __sd, integral_constant<unsigned, 2>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 1>);
+    template<class _Sseq>
+        void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
+};
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
+        integral_constant<unsigned, 1>)
+{
+    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
+        __e(__sd == 0u ? default_seed : __sd);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(__e() & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd,
+        integral_constant<unsigned, 2>)
+{
+    linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
+        __e(__sd == 0u ? default_seed : __sd);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(
+                                    (__e() + ((uint64_t)__e() << 32)) & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+template<class _Sseq>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
+        integral_constant<unsigned, 1>)
+{
+    const unsigned __k = 1;
+    uint32_t __ar[__r * __k];
+    __q.generate(__ar, __ar + __r * __k);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(__ar[__i] & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+template<class _Sseq>
+void
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q,
+        integral_constant<unsigned, 2>)
+{
+    const unsigned __k = 2;
+    uint32_t __ar[__r * __k];
+    __q.generate(__ar, __ar + __r * __k);
+    for (size_t __i = 0; __i < __r; ++__i)
+        __x_[__i] = static_cast<result_type>(
+                  (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max);
+    __c_ = __x_[__r-1] == 0;
+    __i_ = 0;
+}
+
+template<class _UIntType, size_t __w, size_t __s, size_t __r>
+_UIntType
+subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()()
+{
+    const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r];
+    result_type& __xr = __x_[__i_];
+    result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1;
+    __xr = (__xs - __xr - __c_) & _Max;
+    __c_ = __new_c;
+    __i_ = (__i_ + 1) % __r;
+    return __xr;
+}
+
+template<class _UI, size_t _W, size_t _S, size_t _R>
+bool
+operator==(
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __y)
+{
+    if (__x.__c_ != __y.__c_)
+        return false;
+    if (__x.__i_ == __y.__i_)
+        return _STD::equal(__x.__x_, __x.__x_ + _R, __y.__x_);
+    if (__x.__i_ == 0 || __y.__i_ == 0)
+    {
+        size_t __j = _STD::min(_R - __x.__i_, _R - __y.__i_);
+        if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j,
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (__x.__i_ == 0)
+            return _STD::equal(__x.__x_ + __j, __x.__x_ + _R, __y.__x_);
+        return _STD::equal(__x.__x_, __x.__x_ + (_R - __j), __y.__x_ + __j);
+    }
+    if (__x.__i_ < __y.__i_)
+    {
+        size_t __j = _R - __y.__i_;
+        if (!_STD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j),
+                         __y.__x_ + __y.__i_))
+            return false;
+        if (!_STD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _R,
+                         __y.__x_))
+            return false;
+        return _STD::equal(__x.__x_, __x.__x_ + __x.__i_,
+                           __y.__x_ + (_R - (__x.__i_ + __j)));
+    }
+    size_t __j = _R - __x.__i_;
+    if (!_STD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j),
+                     __x.__x_ + __x.__i_))
+        return false;
+    if (!_STD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _R,
+                     __x.__x_))
+        return false;
+    return _STD::equal(__y.__x_, __y.__x_ + __y.__i_,
+                       __x.__x_ + (_R - (__y.__i_ + __j)));
+}
+
+template<class _UI, size_t _W, size_t _S, size_t _R>
+inline
+bool
+operator!=(
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __x,
+    const subtract_with_carry_engine<_UI, _W, _S, _R>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _S, size_t _R>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const subtract_with_carry_engine<_UI, _W, _S, _R>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__x_[__x.__i_];
+    for (size_t __j = __x.__i_ + 1; __j < _R; ++__j)
+        __os << __sp << __x.__x_[__j];
+    for (size_t __j = 0; __j < __x.__i_; ++__j)
+        __os << __sp << __x.__x_[__j];
+    __os << __sp << __x.__c_;
+    return __os;
+}
+
+template <class _CharT, class _Traits,
+          class _UI, size_t _W, size_t _S, size_t _R>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           subtract_with_carry_engine<_UI, _W, _S, _R>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    _UI __t[_R+1];
+    for (size_t __i = 0; __i < _R+1; ++__i)
+        __is >> __t[__i];
+    if (!__is.fail())
+    {
+        for (size_t __i = 0; __i < _R; ++__i)
+            __x.__x_[__i] = __t[__i];
+        __x.__c_ = __t[_R];
+        __x.__i_ = 0;
+    }
+    return __is;
+}
+
+typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>     ranlux24_base;
+typedef subtract_with_carry_engine<uint_fast64_t, 48,  5, 12>     ranlux48_base;
+
+// discard_block_engine
+
+template<class _Engine, size_t __p, size_t __r>
+class discard_block_engine
+{
+    _Engine __e_;
+    int     __n_;
+
+    static_assert(  0 <  __r, "discard_block_engine invalid parameters");
+    static_assert(__r <= __p, "discard_block_engine invalid parameters");
+public:
+    // types
+    typedef typename _Engine::result_type result_type;
+
+    // engine characteristics
+    static const/*expr*/ size_t block_size = __p;
+    static const/*expr*/ size_t used_block = __r;
+
+    // Temporary work around for lack of constexpr
+    static const result_type _Min = _Engine::_Min;
+    static const result_type _Max = _Engine::_Max;
+
+    static const/*expr*/ result_type min() { return _Engine::min(); }
+    static const/*expr*/ result_type max() { return _Engine::max(); }
+
+    // constructors and seeding functions
+    discard_block_engine() : __n_(0) {}
+//     explicit discard_block_engine(const _Engine& __e);
+//     explicit discard_block_engine(_Engine&& __e);
+    explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
+    template<class _Sseq> explicit discard_block_engine(_Sseq& __q)
+        : __e_(__q), __n_(0) {}
+    void seed() {__e_.seed(); __n_ = 0;}
+    void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
+    template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
+
+    // generating functions
+    result_type operator()();
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    const _Engine& base() const {return __e_;}
+
+    template<class _Eng, size_t _P, size_t _R>
+    friend
+    bool
+    operator==(
+        const discard_block_engine<_Eng, _P, _R>& __x,
+        const discard_block_engine<_Eng, _P, _R>& __y);
+    
+    template<class _Eng, size_t _P, size_t _R>
+    friend
+    bool
+    operator!=(
+        const discard_block_engine<_Eng, _P, _R>& __x,
+        const discard_block_engine<_Eng, _P, _R>& __y);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _P, size_t _R>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const discard_block_engine<_Eng, _P, _R>& __x);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _P, size_t _R>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               discard_block_engine<_Eng, _P, _R>& __x);
+};
+
+template<class _Engine, size_t __p, size_t __r>
+typename discard_block_engine<_Engine, __p, __r>::result_type
+discard_block_engine<_Engine, __p, __r>::operator()()
+{
+    if (__n_ >= __r)
+    {
+        __e_.discard(__p - __r);
+        __n_ = 0;
+    }
+    ++__n_;
+    return __e_();
+}
+
+template<class _Eng, size_t _P, size_t _R>
+inline
+bool
+operator==(const discard_block_engine<_Eng, _P, _R>& __x,
+           const discard_block_engine<_Eng, _P, _R>& __y)
+{
+    return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_;
+}
+
+template<class _Eng, size_t _P, size_t _R>
+inline
+bool
+operator!=(const discard_block_engine<_Eng, _P, _R>& __x,
+           const discard_block_engine<_Eng, _P, _R>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _P, size_t _R>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const discard_block_engine<_Eng, _P, _R>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.__e_ << __sp << __x.__n_;
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _P, size_t _R>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           discard_block_engine<_Eng, _P, _R>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    _Eng __e;
+    int __n;
+    __is >> __e >> __n;
+    if (!__is.fail())
+    {
+        __x.__e_ = __e;
+        __x.__n_ = __n;
+    }
+    return __is;
+}
+
+typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
+typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
+
+// independent_bits_engine
+
+template <unsigned long long _X, size_t _R>
+struct __log2_imp
+{
+    static const size_t value = _X & ((unsigned long long)(1) << _R) ? _R
+                                           : __log2_imp<_X, _R - 1>::value;
+};
+
+template <unsigned long long _X>
+struct __log2_imp<_X, 0>
+{
+    static const size_t value = 0;
+};
+
+template <size_t _R>
+struct __log2_imp<0, _R>
+{
+    static const size_t value = _R + 1;
+};
+
+template <class _UI, _UI _X>
+struct __log2
+{
+    static const size_t value = __log2_imp<_X,
+                                         sizeof(_UI) * __CHAR_BIT__ - 1>::value;
+};
+
+template<class _Engine, size_t __w, class _UIntType>
+class independent_bits_engine
+{
+    template <class _UI, _UI _R0, size_t _W, size_t _M>
+    class __get_n
+    {
+        static const size_t _Dt = numeric_limits<_UI>::digits;
+        static const size_t _N = _W / _M + (_W % _M != 0);
+        static const size_t _W0 = _W / _N;
+        static const _UI _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0;
+    public:
+        static const size_t value = _R0 - _Y0 > _Y0 / _N ? _N + 1 : _N;
+    };
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    _Engine __e_;
+
+    static const result_type _Dt = numeric_limits<result_type>::digits;
+    static_assert(  0 <  __w, "independent_bits_engine invalid parameters");
+    static_assert(__w <= _Dt, "independent_bits_engine invalid parameters");
+
+    typedef typename _Engine::result_type _Engine_result_type;
+    typedef typename conditional
+        <
+            sizeof(_Engine_result_type) <= sizeof(result_type),
+                result_type,
+                _Engine_result_type
+        >::type _Working_result_type;
+    // Temporary work around for lack of constexpr
+    static const _Working_result_type _R = _Engine::_Max - _Engine::_Min
+                                                         + _Working_result_type(1);
+    static const size_t __m = __log2<_Working_result_type, _R>::value;
+    static const size_t __n = __get_n<_Working_result_type, _R, __w, __m>::value;
+    static const size_t __w0 = __w / __n;
+    static const size_t __n0 = __n - __w % __n;
+    static const size_t _WDt = numeric_limits<_Working_result_type>::digits;
+    static const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
+    static const _Working_result_type __y0 = __w0 >= _WDt ? 0 :
+                                                   (_R >> __w0) << __w0;
+    static const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 :
+                                                   (_R >> (__w0+1)) << (__w0+1);
+    static const _Engine_result_type __mask0 = __w0 > 0 ?
+                                _Engine_result_type(~0) >> (_EDt - __w0) :
+                                _Engine_result_type(0);
+    static const _Engine_result_type __mask1 = __w0 < _EDt - 1 ?
+                                _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) :
+                                _Engine_result_type(~0);
+public:
+    static const result_type _Min = 0;
+    static const result_type _Max = __w == _Dt ? result_type(~0) :
+                                   (result_type(1) << __w) - result_type(1);
+    static_assert(_Min < _Max, "independent_bits_engine invalid parameters");
+
+    // engine characteristics
+    static const/*expr*/ result_type min() { return _Min; }
+    static const/*expr*/ result_type max() { return _Max; }
+
+    // constructors and seeding functions
+    independent_bits_engine() {}
+//    explicit independent_bits_engine(const _Engine& __e);
+//    explicit independent_bits_engine(_Engine&& __e);
+    explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
+    template<class _Sseq> explicit independent_bits_engine(_Sseq& __q)
+         : __e_(__q) {}
+    void seed() {__e_.seed();}
+    void seed(result_type __sd) {__e_.seed(__sd);}
+    template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q);}
+
+    // generating functions
+    result_type operator()() {return __eval(integral_constant<bool, _R != 0>());}
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    const _Engine& base() const {return __e_;}
+
+    template<class _Eng, size_t _W, class _UI>
+    friend
+    bool
+    operator==(
+        const independent_bits_engine<_Eng, _W, _UI>& __x,
+        const independent_bits_engine<_Eng, _W, _UI>& __y);
+    
+    template<class _Eng, size_t _W, class _UI>
+    friend
+    bool
+    operator!=(
+        const independent_bits_engine<_Eng, _W, _UI>& __x,
+        const independent_bits_engine<_Eng, _W, _UI>& __y);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _W, class _UI>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const independent_bits_engine<_Eng, _W, _UI>& __x);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _W, class _UI>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               independent_bits_engine<_Eng, _W, _UI>& __x);
+
+private:
+    result_type __eval(false_type);
+    result_type __eval(true_type);
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            __count < _Dt,
+            result_type
+        >::type
+        __lshift(result_type __x) {return __x << __count;}
+
+    template <size_t __count>
+        static
+        typename enable_if
+        <
+            (__count >= _Dt),
+            result_type
+        >::type
+        __lshift(result_type __x) {return result_type(0);}
+};
+
+template<class _Engine, size_t __w, class _UIntType>
+inline
+_UIntType
+independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type)
+{
+    return static_cast<result_type>(__e_() & __mask0);
+}
+
+template<class _Engine, size_t __w, class _UIntType>
+_UIntType
+independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type)
+{
+    result_type _S = 0;
+    for (size_t __k = 0; __k < __n0; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y0);
+        _S = static_cast<result_type>(__lshift<__w0>(_S) + (__u & __mask0));
+    }
+    for (size_t __k = __n0; __k < __n; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y1);
+        _S = static_cast<result_type>(__lshift<__w0+1>(_S) + (__u & __mask1));
+    }
+    return _S;
+}
+
+template<class _Eng, size_t _W, class _UI>
+inline
+bool
+operator==(
+    const independent_bits_engine<_Eng, _W, _UI>& __x,
+    const independent_bits_engine<_Eng, _W, _UI>& __y)
+{
+    return __x.base() == __y.base();
+}
+
+template<class _Eng, size_t _W, class _UI>
+inline
+bool
+operator!=(
+    const independent_bits_engine<_Eng, _W, _UI>& __x,
+    const independent_bits_engine<_Eng, _W, _UI>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _W, class _UI>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const independent_bits_engine<_Eng, _W, _UI>& __x)
+{
+    return __os << __x.base();
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _W, class _UI>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           independent_bits_engine<_Eng, _W, _UI>& __x)
+{
+    _Eng __e;
+    __is >> __e;
+    if (!__is.fail())
+        __x.__e_ = __e;
+    return __is;
+}
+
+// shuffle_order_engine
+
+template <uint64_t _Xp, uint64_t _Yp>
+struct __ugcd
+{
+    static const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value;
+};
+
+template <uint64_t _Xp>
+struct __ugcd<_Xp, 0>
+{
+    static const uint64_t value = _Xp;
+};
+
+template <uint64_t _N, uint64_t _D>
+class __uratio
+{
+    static_assert(_D != 0, "__uratio divide by 0");
+    static const uint64_t __gcd = __ugcd<_N, _D>::value;
+public:
+    static const uint64_t num = _N / __gcd;
+    static const uint64_t den = _D / __gcd;
+
+    typedef __uratio<num, den> type;
+};
+
+template<class _Engine, size_t __k>
+class shuffle_order_engine
+{
+    static_assert(0 < __k, "shuffle_order_engine invalid parameters");
+public:
+    // types
+    typedef typename _Engine::result_type result_type;
+
+private:
+    _Engine __e_;
+    result_type _V_[__k];
+    result_type _Y_;
+
+public:
+    // engine characteristics
+    static const/*expr*/ size_t table_size = __k;
+    
+    static const result_type _Min = _Engine::_Min;
+    static const result_type _Max = _Engine::_Max;
+    static_assert(_Min < _Max, "shuffle_order_engine invalid parameters");
+    static const/*expr*/ result_type min() { return _Min; }
+    static const/*expr*/ result_type max() { return _Max; }
+
+    static const unsigned long long _R = _Max - _Min + 1ull;
+
+    // constructors and seeding functions
+    shuffle_order_engine() {__init();}
+//    explicit shuffle_order_engine(const _Engine& __e);
+//    explicit shuffle_order_engine(_Engine&& e);
+    explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
+    template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q)
+         : __e_(__q) {__init();}
+    void seed() {__e_.seed(); __init();}
+    void seed(result_type __sd) {__e_.seed(__sd); __init();}
+    template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q); __init();}
+
+    // generating functions
+    result_type operator()() {return __eval(integral_constant<bool, _R != 0>());}
+    void discard(unsigned long long __z) {for (; __z; --__z) operator()();}
+
+    // property functions
+    const _Engine& base() const {return __e_;}
+
+private:
+    template<class _Eng, size_t _K>
+    friend
+    bool
+    operator==(
+        const shuffle_order_engine<_Eng, _K>& __x,
+        const shuffle_order_engine<_Eng, _K>& __y);
+    
+    template<class _Eng, size_t _K>
+    friend
+    bool
+    operator!=(
+        const shuffle_order_engine<_Eng, _K>& __x,
+        const shuffle_order_engine<_Eng, _K>& __y);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _K>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os,
+               const shuffle_order_engine<_Eng, _K>& __x);
+    
+    template <class _CharT, class _Traits,
+              class _Eng, size_t _K>
+    friend
+    basic_istream<_CharT, _Traits>&
+    operator>>(basic_istream<_CharT, _Traits>& __is,
+               shuffle_order_engine<_Eng, _K>& __x);
+
+    void __init()
+    {
+        for (size_t __i = 0; __i < __k; ++__i)
+            _V_[__i] = __e_();
+        _Y_ = __e_();
+    }
+
+    result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());}
+    result_type __eval(true_type) {return __eval(__uratio<__k, _R>());}
+
+    result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());}
+    result_type __eval2(true_type) {return __evalf<__k, 0>();}
+
+    template <uint64_t _N, uint64_t _D>
+        typename enable_if
+        <
+            (__uratio<_N, _D>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)),
+            result_type
+        >::type
+        __eval(__uratio<_N, _D>)
+            {return __evalf<__uratio<_N, _D>::num, __uratio<_N, _D>::den>();}
+
+    template <uint64_t _N, uint64_t _D>
+        typename enable_if
+        <
+            __uratio<_N, _D>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min),
+            result_type
+        >::type
+        __eval(__uratio<_N, _D>)
+        {
+            const size_t __j = static_cast<size_t>(__uratio<_N, _D>::num * (_Y_ - _Min)
+                                                   / __uratio<_N, _D>::den);
+            _Y_ = _V_[__j];
+            _V_[__j] = __e_();
+            return _Y_;
+        }
+
+    template <uint64_t __n, uint64_t __d>
+        result_type __evalf()
+        {
+            const double _F = __d == 0 ?
+                __n / (2. * 0x8000000000000000ull) :
+                __n / (double)__d;
+            const size_t __j = static_cast<size_t>(_F * (_Y_ - _Min));
+            _Y_ = _V_[__j];
+            _V_[__j] = __e_();
+            return _Y_;
+        }
+};
+
+template<class _Eng, size_t _K>
+bool
+operator==(
+    const shuffle_order_engine<_Eng, _K>& __x,
+    const shuffle_order_engine<_Eng, _K>& __y)
+{
+    return __x._Y_ == __y._Y_ && _STD::equal(__x._V_, __x._V_ + _K, __y._V_) &&
+           __x.__e_ == __y.__e_;
+}
+
+template<class _Eng, size_t _K>
+inline
+bool
+operator!=(
+    const shuffle_order_engine<_Eng, _K>& __x,
+    const shuffle_order_engine<_Eng, _K>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _K>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const shuffle_order_engine<_Eng, _K>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    __os << __x.__e_ << __sp << __x._V_[0];
+    for (size_t __i = 1; __i < _K; ++__i)
+        __os << __sp << __x._V_[__i];
+    return __os << __sp << __x._Y_;
+}
+
+template <class _CharT, class _Traits,
+          class _Eng, size_t _K>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           shuffle_order_engine<_Eng, _K>& __x)
+{
+    typedef typename shuffle_order_engine<_Eng, _K>::result_type result_type;
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    _Eng __e;
+    result_type _V[_K+1];
+    __is >> __e;
+    for (size_t __i = 0; __i < _K+1; ++__i)
+        __is >> _V[__i];
+    if (!__is.fail())
+    {
+        __x.__e_ = __e;
+        for (size_t __i = 0; __i < _K; ++__i)
+            __x._V_[__i] = _V[__i];
+        __x._Y_ = _V[_K];
+    }
+    return __is;
+}
+
+typedef shuffle_order_engine<minstd_rand0, 256>                         knuth_b;
+
+// random_device
+
+class random_device
+{
+    int __f_;
+public:
+    // types
+    typedef unsigned result_type;
+
+    // generator characteristics
+    static const result_type _Min = 0;
+    static const result_type _Max = 0xFFFFFFFFu;
+
+    static const/*expr*/ result_type min() { return _Min;}
+    static const/*expr*/ result_type max() { return _Max;}
+
+    // constructors
+    explicit random_device(const string& __token = "/dev/urandom");
+    ~random_device();
+
+    // generating functions
+    result_type operator()();
+
+    // property functions
+    double entropy() const;
+
+private:
+    // no copy functions
+    random_device(const random_device&); // = delete;
+    random_device& operator=(const random_device&); // = delete;
+};
+
+// seed_seq
+
+class seed_seq
+{
+public:
+    // types
+    typedef uint32_t result_type;
+
+private:
+    vector<result_type> __v_;
+
+    template<class _InputIterator>
+        void init(_InputIterator __first, _InputIterator __last);
+public:
+    // constructors
+    seed_seq() {}
+    template<class _Tp>
+        seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());}
+            
+    template<class _InputIterator>
+        seed_seq(_InputIterator __first, _InputIterator __last)
+             {init(__first, __last);}
+
+    // generating functions
+    template<class _RandomAccessIterator>
+        void generate(_RandomAccessIterator __first, _RandomAccessIterator __last);
+
+    // property functions
+    size_t size() const {return __v_.size();}
+    template<class _OutputIterator>
+        void param(_OutputIterator __dest) const
+            {_STD::copy(__v_.begin(), __v_.end(), __dest);}
+
+private:
+    // no copy functions
+    seed_seq(const seed_seq&); // = delete;
+    void operator=(const seed_seq&); // = delete;
+
+    static result_type _T(result_type __x) {return __x ^ (__x >> 27);}
+};
+
+template<class _InputIterator>
+void
+seed_seq::init(_InputIterator __first, _InputIterator __last)
+{
+    for (_InputIterator __s = __first; __s != __last; ++__s)
+        __v_.push_back(*__s & 0xFFFFFFFF);
+}
+
+template<class _RandomAccessIterator>
+void
+seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+    if (__first != __last)
+    {
+        _STD::fill(__first, __last, 0x8b8b8b8b);
+        const size_t __n = static_cast<size_t>(__last - __first);
+        const size_t __s = __v_.size();
+        const size_t __t = (__n >= 623) ? 11
+                         : (__n >= 68) ? 7
+                         : (__n >= 39) ? 5
+                         : (__n >= 7)  ? 3
+                         : (__n - 1) / 2;
+        const size_t __p = (__n - __t) / 2;
+        const size_t __q = __p + __t;
+        const size_t __m = _STD::max(__s + 1, __n);
+        // __k = 0;
+        {
+            result_type __r = 1664525 * _T(__first[0] ^ __first[__p]
+                                                      ^  __first[__n - 1]);
+            __first[__p] += __r;
+            __r += __s;
+            __first[__q] += __r;
+            __first[0] = __r;
+        }
+        for (size_t __k = 1; __k <= __s; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn]
+                                           ^ __first[(__k - 1) % __n]);
+            __first[__kpmodn] += __r;
+            __r +=  __kmodn + __v_[__k-1];
+            __first[(__k + __q) % __n] += __r;
+            __first[__kmodn] = __r;
+        }
+        for (size_t __k = __s + 1; __k < __m; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1664525 * _T(__first[__kmodn] ^ __first[__kpmodn]
+                                           ^ __first[(__k - 1) % __n]);
+            __first[__kpmodn] += __r;
+            __r +=  __kmodn;
+            __first[(__k + __q) % __n] += __r;
+            __first[__kmodn] = __r;
+        }
+        for (size_t __k = __m; __k < __m + __n; ++__k)
+        {
+            const size_t __kmodn = __k % __n;
+            const size_t __kpmodn = (__k + __p) % __n;
+            result_type __r = 1566083941 * _T(__first[__kmodn] +
+                                              __first[__kpmodn] +
+                                              __first[(__k - 1) % __n]);
+            __first[__kpmodn] ^= __r;
+            __r -= __kmodn;
+            __first[(__k + __q) % __n] ^= __r;
+            __first[__kmodn] = __r;
+        }
+    }
+}
+
+template<class _RealType, size_t __bits, class _URNG>
+_RealType
+generate_canonical(_URNG& __g)
+{
+    const size_t _Dt = numeric_limits<_RealType>::digits;
+    const size_t __b = _Dt < __bits ? _Dt : __bits;
+    const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value;
+    const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0);
+    const _RealType _R = _URNG::_Max - _URNG::_Min + _RealType(1);
+    _RealType __base = _R;
+    _RealType _S = __g() - _URNG::_Min;
+    for (size_t __i = 1; __i < __k; ++__i, __base *= _R)
+        _S += (__g() - _URNG::_Min) * __base;
+    return _S / __base;
+}
+
+// __independent_bits_engine
+
+template<class _Engine, class _UIntType>
+class __independent_bits_engine
+{
+public:
+    // types
+    typedef _UIntType result_type;
+
+private:
+    typedef typename _Engine::result_type _Engine_result_type;
+    typedef typename conditional
+        <
+            sizeof(_Engine_result_type) <= sizeof(result_type),
+                result_type,
+                _Engine_result_type
+        >::type _Working_result_type;
+
+    _Engine& __e_;
+    size_t __w_;
+    size_t __w0_;
+    size_t __n_;
+    size_t __n0_;
+    _Working_result_type __y0_;
+    _Working_result_type __y1_;
+    _Engine_result_type __mask0_;
+    _Engine_result_type __mask1_;
+
+    static const _Working_result_type _R = _Engine::_Max - _Engine::_Min
+                                                         + _Working_result_type(1);
+    static const size_t __m = __log2<_Working_result_type, _R>::value;
+    static const size_t _WDt = numeric_limits<_Working_result_type>::digits;
+    static const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
+
+public:
+    // constructors and seeding functions
+    __independent_bits_engine(_Engine& __e, size_t __w);
+
+    // generating functions
+    result_type operator()() {return __eval(integral_constant<bool, _R != 0>());}
+
+private:
+    result_type __eval(false_type);
+    result_type __eval(true_type);
+};
+
+template<class _Engine, class _UIntType>
+__independent_bits_engine<_Engine, _UIntType>
+    ::__independent_bits_engine(_Engine& __e, size_t __w)
+        : __e_(__e),
+          __w_(__w)
+{
+    __n_ = __w_ / __m + (__w_ % __m != 0);
+    __w0_ = __w_ / __n_;
+    if (_R == 0)
+        __y0_ = _R;
+    else if (__w0_ < _WDt)
+        __y0_ = (_R >> __w0_) << __w0_;
+    else
+        __y0_ = 0;
+    if (_R - __y0_ > __y0_ / __n_)
+    {
+        ++__n_;
+        __w0_ = __w_ / __n_;
+        if (__w0_ < _WDt)
+            __y0_ = (_R >> __w0_) << __w0_;
+        else
+            __y0_ = 0;
+    }
+    __n0_ = __n_ - __w_ % __n_;
+    if (__w0_ < _WDt - 1)
+        __y1_ = (_R >> (__w0_ + 1)) << (__w0_ + 1);
+    else
+        __y1_ = 0;
+    __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) :
+                          _Engine_result_type(0);
+    __mask1_ = __w0_ < _EDt - 1 ?
+                               _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) :
+                               _Engine_result_type(~0);
+}
+
+template<class _Engine, class _UIntType>
+inline
+_UIntType
+__independent_bits_engine<_Engine, _UIntType>::__eval(false_type)
+{
+    return static_cast<result_type>(__e_() & __mask0_);
+}
+
+template<class _Engine, class _UIntType>
+_UIntType
+__independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
+{
+    result_type _S = 0;
+    for (size_t __k = 0; __k < __n0_; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y0_);
+        if (__w0_ < _EDt)
+            _S <<= __w0_;
+        else
+            _S = 0;
+        _S += __u & __mask0_;
+    }
+    for (size_t __k = __n0_; __k < __n_; ++__k)
+    {
+        _Engine_result_type __u;
+        do
+        {
+            __u = __e_() - _Engine::min();
+        } while (__u >= __y1_);
+        if (__w0_ < _EDt - 1)
+            _S <<= __w0_ + 1;
+        else
+            _S = 0;
+        _S += __u & __mask1_;
+    }
+    return _S;
+}
+
+template<class _IntType = int>
+class uniform_int_distribution
+{
+public:
+    // types
+    typedef _IntType result_type;
+
+    class param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef uniform_int_distribution distribution_type;
+
+        explicit param_type(result_type __a = 0,
+                            result_type __b = numeric_limits<result_type>::max())
+            : __a_(__a), __b_(__b) {}
+
+        result_type a() const {return __a_;}
+        result_type b() const {return __b_;}
+
+        friend bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+    explicit uniform_int_distribution(result_type __a = 0,
+                                      result_type __b = numeric_limits<result_type>::max())
+        : __p_(param_type(__a, __b)) {}
+    explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {}
+    void reset() {}
+
+    // generating functions
+    template<class _URNG> result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    result_type a() const {return __p_.a();}
+    result_type b() const {return __p_.b();}
+
+    param_type param() const {return __p_;}
+    void param(const param_type& __p) {__p_ = __p;}
+
+    result_type min() const {return a();}
+    result_type max() const {return b();}
+
+    friend bool operator==(const uniform_int_distribution& __x,
+                           const uniform_int_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend bool operator!=(const uniform_int_distribution& __x,
+                           const uniform_int_distribution& __y)
+            {return !(__x == __y);}
+};
+
+template<class _IntType>
+template<class _URNG>
+typename uniform_int_distribution<_IntType>::result_type
+uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
+{
+    typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t),
+                                            uint32_t, uint64_t>::type _UIntType;
+    const _UIntType _R = __p.b() - __p.a() + _UIntType(1);
+    if (_R == 1)
+        return __p.a();
+    const size_t _Dt = numeric_limits<_UIntType>::digits;
+    typedef __independent_bits_engine<_URNG, _UIntType> _Eng;
+    if (_R == 0)
+        return static_cast<result_type>(_Eng(__g, _Dt)());
+    size_t __w = _Dt - __clz(_R) - 1;
+    if ((_R & (_UIntType(~0) >> (_Dt - __w))) != 0)
+        ++__w;
+    _Eng __e(__g, __w);
+    _UIntType __u;
+    do
+    {
+        __u = __e();
+    } while (__u >= _R);
+    return static_cast<result_type>(__u + __p.a());
+}
+
+template <class _CharT, class _Traits, class _IT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const uniform_int_distribution<_IT>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.a() << __sp << __x.b();
+}
+
+template <class _CharT, class _Traits, class _IT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           uniform_int_distribution<_IT>& __x)
+{
+    typedef uniform_int_distribution<_IT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+template<class _RealType = double>
+class uniform_real_distribution
+{
+public:
+    // types
+    typedef _RealType result_type;
+
+    class param_type
+    {
+        result_type __a_;
+        result_type __b_;
+    public:
+        typedef uniform_real_distribution distribution_type;
+
+        explicit param_type(result_type __a = 0,
+                            result_type __b = 1)
+            : __a_(__a), __b_(__b) {}
+
+        result_type a() const {return __a_;}
+        result_type b() const {return __b_;}
+
+        friend bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
+        friend bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+    explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
+        : __p_(param_type(__a, __b)) {}
+    explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {}
+    void reset() {}
+
+    // generating functions
+    template<class _URNG> result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+
+    // property functions
+    result_type a() const {return __p_.a();}
+    result_type b() const {return __p_.b();}
+
+    param_type param() const {return __p_;}
+    void param(const param_type& __p) {__p_ = __p;}
+
+    result_type min() const {return a();}
+    result_type max() const {return b();}
+
+    friend bool operator==(const uniform_real_distribution& __x,
+                           const uniform_real_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend bool operator!=(const uniform_real_distribution& __x,
+                           const uniform_real_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template<class _RealType>
+template<class _URNG>
+inline
+typename uniform_real_distribution<_RealType>::result_type
+uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
+{
+    return (__p.b() - __p.a())
+        * _STD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
+        + __p.a();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+           const uniform_real_distribution<_RT>& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.a() << __sp << __x.b();
+}
+
+template <class _CharT, class _Traits, class _RT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is,
+           uniform_real_distribution<_RT>& __x)
+{
+    typedef uniform_real_distribution<_RT> _Eng;
+    typedef typename _Eng::result_type result_type;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    result_type __a;
+    result_type __b;
+    __is >> __a >> __b;
+    if (!__is.fail())
+        __x.param(param_type(__a, __b));
+    return __is;
+}
+
+class bernoulli_distribution
+{
+public:
+    // types
+    typedef bool result_type;
+
+    class param_type
+    {
+        double __p_;
+    public:
+        typedef bernoulli_distribution distribution_type;
+
+        explicit param_type(double __p = 0.5) : __p_(__p) {}
+
+        double p() const {return __p_;}
+
+        friend bool operator==(const param_type& __x, const param_type& __y)
+            {return __x.__p_ == __y.__p_;}
+        friend bool operator!=(const param_type& __x, const param_type& __y)
+            {return !(__x == __y);}
+    };
+
+private:
+    param_type __p_;
+
+public:
+    // constructors and reset functions
+    explicit bernoulli_distribution(double __p = 0.5)
+        : __p_(param_type(__p)) {}
+    explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {}
+    void reset() {}
+
+    // generating functions
+    template<class _URNG> result_type operator()(_URNG& __g)
+        {return (*this)(__g, __p_);}
+    template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p)
+        {
+            return _STD::generate_canonical<double, numeric_limits<double>::digits>(__g)
+                   < __p.p();
+        }
+
+    // property functions
+    double p() const {return __p_.p();}
+
+    param_type param() const {return __p_;}
+    void param(const param_type& __p) {__p_ = __p;}
+
+    result_type min() const {return false;}
+    result_type max() const {return true;}
+
+    friend bool operator==(const bernoulli_distribution& __x,
+                          const bernoulli_distribution& __y)
+        {return __x.__p_ == __y.__p_;}
+    friend bool operator!=(const bernoulli_distribution& __x,
+                          const bernoulli_distribution& __y)
+        {return !(__x == __y);}
+};
+
+template <class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
+{
+    __save_flags<_CharT, _Traits> _(__os);
+    __os.flags(ios_base::dec | ios_base::left);
+    _CharT __sp = __os.widen(' ');
+    __os.fill(__sp);
+    return __os << __x.p();
+}
+
+template <class _CharT, class _Traits>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x)
+{
+    typedef bernoulli_distribution _Eng;
+    typedef typename _Eng::param_type param_type;
+    __save_flags<_CharT, _Traits> _(__is);
+    __is.flags(ios_base::dec | ios_base::skipws);
+    double __p;
+    __is >> __p;
+    if (!__is.fail())
+        __x.param(param_type(__p));
+    return __is;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_RANDOM
diff --git a/include/ratio b/include/ratio
new file mode 100644
index 0000000..8a6cb6c
--- /dev/null
+++ b/include/ratio
@@ -0,0 +1,424 @@
+// -*- C++ -*-
+//===---------------------------- ratio -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_RATIO
+#define _LIBCPP_RATIO
+
+/*
+    ratio synopsis
+
+namespace std
+{
+
+template <intmax_t N, intmax_t D = 1>
+class ratio
+{
+public:
+    static const intmax_t num;
+    static const intmax_t den;
+};
+
+// ratio arithmetic
+template <class R1, class R2> struct ratio_add;
+template <class R1, class R2> struct ratio_subtract;
+template <class R1, class R2> struct ratio_multiply;
+template <class R1, class R2> struct ratio_divide;
+
+// ratio comparison
+template <class R1, class R2> struct ratio_equal;
+template <class R1, class R2> struct ratio_not_equal;
+template <class R1, class R2> struct ratio_less;
+template <class R1, class R2> struct ratio_less_equal;
+template <class R1, class R2> struct ratio_greater;
+template <class R1, class R2> struct ratio_greater_equal;
+
+// convenience SI typedefs
+typedef ratio<1, 1000000000000000000000000> yocto;  // not supported
+typedef ratio<1,    1000000000000000000000> zepto;  // not supported
+typedef ratio<1,       1000000000000000000> atto;
+typedef ratio<1,          1000000000000000> femto;
+typedef ratio<1,             1000000000000> pico;
+typedef ratio<1,                1000000000> nano;
+typedef ratio<1,                   1000000> micro;
+typedef ratio<1,                      1000> milli;
+typedef ratio<1,                       100> centi;
+typedef ratio<1,                        10> deci;
+typedef ratio<                       10, 1> deca;
+typedef ratio<                      100, 1> hecto;
+typedef ratio<                     1000, 1> kilo;
+typedef ratio<                  1000000, 1> mega;
+typedef ratio<               1000000000, 1> giga;
+typedef ratio<            1000000000000, 1> tera;
+typedef ratio<         1000000000000000, 1> peta;
+typedef ratio<      1000000000000000000, 1> exa;
+typedef ratio<   1000000000000000000000, 1> zetta;  // not supported
+typedef ratio<1000000000000000000000000, 1> yotta;  // not supported
+
+}
+*/
+
+#include <__config>
+#include <cstdint>
+#include <climits>
+#include <type_traits>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// __static_gcd
+
+template <intmax_t _Xp, intmax_t _Yp>
+struct __static_gcd
+{
+    static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value;
+};
+
+template <intmax_t _Xp>
+struct __static_gcd<_Xp, 0>
+{
+    static const intmax_t value = _Xp;
+};
+
+// __static_lcm
+
+template <intmax_t _Xp, intmax_t _Yp>
+struct __static_lcm
+{
+    static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp;
+};
+
+template <intmax_t _Xp>
+struct __static_abs
+{
+    static const intmax_t value = _Xp < 0 ? -_Xp : _Xp;
+};
+
+template <intmax_t _Xp>
+struct __static_sign
+{
+    static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1);
+};
+
+template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
+class __ll_add;
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_add<_Xp, _Yp, 1>
+{
+    static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
+    static const intmax_t max = -min;
+
+    static_assert(_Xp <= max - _Yp, "overflow in __ll_add");
+public:
+    static const intmax_t value = _Xp + _Yp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_add<_Xp, _Yp, 0>
+{
+public:
+    static const intmax_t value = _Xp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_add<_Xp, _Yp, -1>
+{
+    static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
+    static const intmax_t max = -min;
+
+    static_assert(min - _Yp <= _Xp, "overflow in __ll_add");
+public:
+    static const intmax_t value = _Xp + _Yp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
+class __ll_sub;
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_sub<_Xp, _Yp, 1>
+{
+    static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
+    static const intmax_t max = -min;
+
+    static_assert(min + _Yp <= _Xp, "overflow in __ll_sub");
+public:
+    static const intmax_t value = _Xp - _Yp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_sub<_Xp, _Yp, 0>
+{
+public:
+    static const intmax_t value = _Xp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_sub<_Xp, _Yp, -1>
+{
+    static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
+    static const intmax_t max = -min;
+
+    static_assert(_Xp <= max + _Yp, "overflow in __ll_sub");
+public:
+    static const intmax_t value = _Xp - _Yp;
+};
+
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_mul
+{
+    static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
+    static const intmax_t min = nan + 1;
+    static const intmax_t max = -min;
+    static const intmax_t __a_x = __static_abs<_Xp>::value;
+    static const intmax_t __a_y = __static_abs<_Yp>::value;
+
+    static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul");
+public:
+    static const intmax_t value = _Xp * _Yp;
+};
+
+template <intmax_t _Yp>
+class __ll_mul<0, _Yp>
+{
+public:
+    static const intmax_t value = 0;
+};
+
+template <intmax_t _Xp>
+class __ll_mul<_Xp, 0>
+{
+public:
+    static const intmax_t value = 0;
+};
+
+template <>
+class __ll_mul<0, 0>
+{
+public:
+    static const intmax_t value = 0;
+};
+
+// Not actually used but left here in case needed in future maintenance
+template <intmax_t _Xp, intmax_t _Yp>
+class __ll_div
+{
+    static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
+    static const intmax_t min = nan + 1;
+    static const intmax_t max = -min;
+
+    static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div");
+public:
+    static const intmax_t value = _Xp / _Yp;
+};
+
+template <intmax_t _Num, intmax_t _Den = 1>
+class ratio
+{
+    static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
+    static_assert(_Den != 0, "ratio divide by 0");
+    static_assert(__static_abs<_Den>::value >  0, "ratio denominator is out of range");
+    static const intmax_t __na = __static_abs<_Num>::value;
+    static const intmax_t __da = __static_abs<_Den>::value;
+    static const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
+    static const intmax_t __gcd = __static_gcd<__na, __da>::value;
+public:
+    static const intmax_t num = __s * __na / __gcd;
+    static const intmax_t den = __da / __gcd;
+
+    typedef ratio<num, den> type;
+};
+
+template <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::num;
+template <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::den;
+
+template <class T>                      struct __is_ratio                     : false_type {};
+template <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type  {};
+
+typedef ratio<1LL, 1000000000000000000LL> atto;
+typedef ratio<1LL,    1000000000000000LL> femto;
+typedef ratio<1LL,       1000000000000LL> pico;
+typedef ratio<1LL,          1000000000LL> nano;
+typedef ratio<1LL,             1000000LL> micro;
+typedef ratio<1LL,                1000LL> milli;
+typedef ratio<1LL,                 100LL> centi;
+typedef ratio<1LL,                  10LL> deci;
+typedef ratio<                 10LL, 1LL> deca;
+typedef ratio<                100LL, 1LL> hecto;
+typedef ratio<               1000LL, 1LL> kilo;
+typedef ratio<            1000000LL, 1LL> mega;
+typedef ratio<         1000000000LL, 1LL> giga;
+typedef ratio<      1000000000000LL, 1LL> tera;
+typedef ratio<   1000000000000000LL, 1LL> peta;
+typedef ratio<1000000000000000000LL, 1LL> exa;
+
+template <class _R1, class _R2>
+struct ratio_multiply
+{
+private:
+    static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value;
+    static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value;
+public:
+    typedef typename ratio
+        <
+            __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value,
+            __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value
+        >::type type;
+};
+
+template <class _R1, class _R2>
+struct ratio_divide
+{
+private:
+    static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
+    static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
+public:
+    typedef typename ratio
+        <
+            __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
+            __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
+        >::type type;
+};
+
+template <class _R1, class _R2>
+struct ratio_add
+{
+private:
+    static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
+    static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
+public:
+    typedef typename ratio_multiply
+        <
+            ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
+            ratio
+            <
+                __ll_add
+                <
+                    __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
+                    __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
+                >::value,
+                _R2::den
+            >
+        >::type type;
+};
+
+template <class _R1, class _R2>
+struct ratio_subtract
+{
+private:
+    static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
+    static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
+public:
+    typedef typename ratio_multiply
+        <
+            ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
+            ratio
+            <
+                __ll_sub
+                <
+                    __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
+                    __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
+                >::value,
+                _R2::den
+            >
+        >::type type;
+};
+
+// ratio_equal
+
+template <class _R1, class _R2>
+struct ratio_equal
+    : public integral_constant<bool, _R1::num == _R2::num && _R1::den == _R2::den> {}; 
+
+template <class _R1, class _R2>
+struct ratio_not_equal
+    : public integral_constant<bool, !ratio_equal<_R1, _R2>::value> {}; 
+
+// ratio_less
+
+template <class _R1, class _R2, bool _Odd = false,
+          intmax_t _Q1 = _R1::num / _R1::den, intmax_t _M1 = _R1::num % _R1::den,
+          intmax_t _Q2 = _R2::num / _R2::den, intmax_t _M2 = _R2::num % _R2::den>
+struct __ratio_less1
+{
+    static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2;
+};
+
+template <class _R1, class _R2, bool _Odd, intmax_t _Q>
+struct __ratio_less1<_R1, _R2, _Odd, _Q, 0, _Q, 0>
+{
+    static const bool value = false;
+};
+
+template <class _R1, class _R2, bool _Odd, intmax_t _Q, intmax_t _M2>
+struct __ratio_less1<_R1, _R2, _Odd, _Q, 0, _Q, _M2>
+{
+    static const bool value = !_Odd;
+};
+
+template <class _R1, class _R2, bool _Odd, intmax_t _Q, intmax_t _M1>
+struct __ratio_less1<_R1, _R2, _Odd, _Q, _M1, _Q, 0>
+{
+    static const bool value = _Odd;
+};
+
+template <class _R1, class _R2, bool _Odd, intmax_t _Q, intmax_t _M1,
+                                                        intmax_t _M2>
+struct __ratio_less1<_R1, _R2, _Odd, _Q, _M1, _Q, _M2>
+{
+    static const bool value = __ratio_less1<ratio<_R1::den, _M1>,
+                                            ratio<_R2::den, _M2>, !_Odd>::value;
+};
+
+template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>::value,
+                                intmax_t _S2 = __static_sign<_R2::num>::value>
+struct __ratio_less
+{
+    static const bool value = _S1 < _S2;
+};
+
+template <class _R1, class _R2>
+struct __ratio_less<_R1, _R2, 1LL, 1LL>
+{
+    static const bool value = __ratio_less1<_R1, _R2>::value;
+};
+
+template <class _R1, class _R2>
+struct __ratio_less<_R1, _R2, -1LL, -1LL>
+{
+    static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value;
+};
+
+template <class _R1, class _R2>
+struct ratio_less
+    : public integral_constant<bool, __ratio_less<_R1, _R2>::value> {};
+
+template <class _R1, class _R2>
+struct ratio_less_equal
+    : public integral_constant<bool, !ratio_less<_R2, _R1>::value> {};
+
+template <class _R1, class _R2>
+struct ratio_greater
+    : public integral_constant<bool, ratio_less<_R2, _R1>::value> {};
+
+template <class _R1, class _R2>
+struct ratio_greater_equal
+    : public integral_constant<bool, !ratio_less<_R1, _R2>::value> {};
+
+template <class _R1, class _R2>
+struct __ratio_gcd
+{
+    typedef ratio<__static_gcd<_R1::num, _R2::num>::value,
+                  __static_lcm<_R1::den, _R2::den>::value> type;
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_RATIO
diff --git a/include/set b/include/set
new file mode 100644
index 0000000..38e5ac1
--- /dev/null
+++ b/include/set
@@ -0,0 +1,841 @@
+// -*- C++ -*-
+//===---------------------------- set -------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SET
+#define _LIBCPP_SET
+
+/*
+
+    set synopsis
+
+namespace std
+{
+
+template <class Key, class Compare = less<Key>,
+          class Allocator = allocator<Key>>
+class set
+{
+public:
+    // types:
+    typedef Key                                      key_type;
+    typedef key_type                                 value_type;
+    typedef Compare                                  key_compare;
+    typedef key_compare                              value_compare;
+    typedef Allocator                                allocator_type;
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    // construct/copy/destroy:
+    explicit set(const value_compare& comp = value_compare());
+    set(const value_compare& comp, const allocator_type& a);
+    template <class InputIterator>
+        set(InputIterator first, InputIterator last,
+            const value_compare& comp = value_compare());
+    template <class InputIterator>
+        set(InputIterator first, InputIterator last, const value_compare& comp,
+            const allocator_type& a);
+    set(const set& s);
+    set(set&& s);
+    explicit set(const allocator_type& a);
+    set(const set& s, const allocator_type& a);
+    set(set&& s, const allocator_type& a);
+    set(initializer_list<value_type> il, const value_compare& comp = value_compare());
+    set(initializer_list<value_type> il, const value_compare& comp,
+        const allocator_type& a);
+    ~set();
+
+    set& operator=(const set& s);
+    set& operator=(set&& s);
+    set& operator=(initializer_list<value_type> il);
+
+    // iterators:
+          iterator begin();
+    const_iterator begin() const;
+          iterator end();
+    const_iterator end()   const;
+
+          reverse_iterator rbegin();
+    const_reverse_iterator rbegin() const;
+          reverse_iterator rend();
+    const_reverse_iterator rend()   const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    // capacity:
+    bool      empty()    const;
+    size_type size()     const;
+    size_type max_size() const;
+
+    // modifiers:
+    template <class... Args>
+        pair<iterator, bool> emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    pair<iterator,bool> insert(const value_type& v);
+    pair<iterator,bool> insert(value_type&& v);
+    iterator insert(const_iterator position, const value_type& v);
+    iterator insert(const_iterator position, value_type&& v);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type> il);
+
+    iterator  erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator  erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(set& s);
+
+    // observers:
+    allocator_type get_allocator() const;
+    key_compare    key_comp()      const;
+    value_compare  value_comp()    const;
+
+    // set operations:
+          iterator find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type      count(const key_type& k) const;
+          iterator lower_bound(const key_type& k);
+    const_iterator lower_bound(const key_type& k) const;
+          iterator upper_bound(const key_type& k);
+    const_iterator upper_bound(const key_type& k) const;
+    pair<iterator,iterator>             equal_range(const key_type& k);
+    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
+};
+
+template <class Key, class Compare, class Allocator>
+bool
+operator==(const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator< (const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator!=(const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator> (const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator>=(const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator<=(const set<Key, Compare, Allocator>& x,
+           const set<Key, Compare, Allocator>& y);
+
+// specialized algorithms:
+template <class Key, class Compare, class Allocator>
+void
+swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y);
+
+
+template <class Key, class Compare = less<Key>,
+          class Allocator = allocator<Key>>
+class multiset
+{
+public:
+    // types:
+    typedef Key                                      key_type;
+    typedef key_type                                 value_type;
+    typedef Compare                                  key_compare;
+    typedef key_compare                              value_compare;
+    typedef Allocator                                allocator_type;
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    // construct/copy/destroy:
+    explicit multiset(const value_compare& comp = value_compare());
+    multiset(const value_compare& comp, const allocator_type& a);
+    template <class InputIterator>
+        multiset(InputIterator first, InputIterator last,
+                 const value_compare& comp = value_compare());
+    template <class InputIterator>
+        multiset(InputIterator first, InputIterator last,
+                 const value_compare& comp, const allocator_type& a);
+    multiset(const multiset& s);
+    multiset(multiset&& s);
+    explicit multiset(const allocator_type& a);
+    multiset(const multiset& s, const allocator_type& a);
+    multiset(multiset&& s, const allocator_type& a);
+    multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
+    multiset(initializer_list<value_type> il, const value_compare& comp,
+             const allocator_type& a);
+    ~multiset();
+
+    multiset& operator=(const multiset& s);
+    multiset& operator=(multiset&& s);
+    multiset& operator=(initializer_list<value_type> il);
+
+    // iterators:
+          iterator begin();
+    const_iterator begin() const;
+          iterator end();
+    const_iterator end()   const;
+
+          reverse_iterator rbegin();
+    const_reverse_iterator rbegin() const;
+          reverse_iterator rend();
+    const_reverse_iterator rend()   const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    // capacity:
+    bool      empty()    const;
+    size_type size()     const;
+    size_type max_size() const;
+
+    // modifiers:
+    template <class... Args>
+        iterator emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    iterator insert(const value_type& v);
+    iterator insert(value_type&& v);
+    iterator insert(const_iterator position, const value_type& v);
+    iterator insert(const_iterator position, value_type&& v);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type> il);
+
+    iterator  erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator  erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(multiset& s);
+
+    // observers:
+    allocator_type get_allocator() const;
+    key_compare    key_comp()      const;
+    value_compare  value_comp()    const;
+
+    // set operations:
+          iterator find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type      count(const key_type& k) const;
+          iterator lower_bound(const key_type& k);
+    const_iterator lower_bound(const key_type& k) const;
+          iterator upper_bound(const key_type& k);
+    const_iterator upper_bound(const key_type& k) const;
+    pair<iterator,iterator>             equal_range(const key_type& k);
+    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
+};
+
+template <class Key, class Compare, class Allocator>
+bool
+operator==(const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator< (const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator!=(const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator> (const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator>=(const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+template <class Key, class Compare, class Allocator>
+bool
+operator<=(const multiset<Key, Compare, Allocator>& x,
+           const multiset<Key, Compare, Allocator>& y);
+
+// specialized algorithms:
+template <class Key, class Compare, class Allocator>
+void
+swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__tree>
+#include <functional>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Key, class _Compare = less<_Key>,
+          class _Allocator = allocator<_Key> >
+class set
+{
+public:
+    // types:
+    typedef _Key                                     key_type;
+    typedef key_type                                 value_type;
+    typedef _Compare                                 key_compare;
+    typedef key_compare                              value_compare;
+    typedef _Allocator                               allocator_type;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+
+private:
+    typedef __tree<value_type, value_compare, allocator_type> __base;
+    typedef allocator_traits<allocator_type>                  __alloc_traits;
+    typedef typename __base::__node_holder                    __node_holder;
+
+    __base __tree_;
+
+public:
+    typedef typename __base::pointer               pointer;
+    typedef typename __base::const_pointer         const_pointer;
+    typedef typename __base::size_type             size_type;
+    typedef typename __base::difference_type       difference_type;
+    typedef typename __base::const_iterator        iterator;
+    typedef typename __base::const_iterator        const_iterator;
+    typedef _STD::reverse_iterator<iterator>       reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
+
+    explicit set(const value_compare& __comp = value_compare())
+        : __tree_(__comp) {}
+    set(const value_compare& __comp, const allocator_type& __a)
+        : __tree_(__comp, __a) {}
+    template <class _InputIterator>
+        set(_InputIterator __f, _InputIterator __l,
+            const value_compare& __comp = value_compare())
+        : __tree_(__comp)
+        {
+            insert(__f, __l);
+        }
+
+    template <class _InputIterator>
+        set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
+            const allocator_type& __a)
+        : __tree_(__comp, __a)
+        {
+            insert(__f, __l);
+        }
+
+    set(const set& __s)
+        : __tree_(__s.__tree_)
+        {
+            insert(__s.begin(), __s.end());
+        }
+
+#ifdef _LIBCPP_MOVE
+    set(set&& __s)
+        : __tree_(_STD::move(__s.__tree_)) {}
+#endif
+
+    explicit set(const allocator_type& __a)
+        : __tree_(__a) {}
+
+    set(const set& __s, const allocator_type& __a)
+        : __tree_(__s.__tree_.value_comp(), __a)
+        {
+            insert(__s.begin(), __s.end());
+        }
+
+#ifdef _LIBCPP_MOVE
+    set(set&& __s, const allocator_type& __a);
+#endif
+
+    set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
+        : __tree_(__comp)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    set(initializer_list<value_type> __il, const value_compare& __comp,
+        const allocator_type& __a)
+        : __tree_(__comp, __a)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    set& operator=(initializer_list<value_type> __il)
+        {
+            __tree_.__assign_unique(__il.begin(), __il.end());
+            return *this;
+        }
+
+#ifdef _LIBCPP_MOVE
+    set& operator=(set&& __s)
+        {
+            __tree_ = _STD::move(__s.__tree_);
+            return *this;
+        }
+#endif
+
+          iterator begin()       {return __tree_.begin();}
+    const_iterator begin() const {return __tree_.begin();}
+          iterator end()         {return __tree_.end();}
+    const_iterator end()   const {return __tree_.end();}
+
+          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+          reverse_iterator rend()         {return       reverse_iterator(begin());}
+    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+
+    const_iterator         cbegin()  const {return begin();}
+    const_iterator         cend()    const {return end();}
+    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crend()   const {return rend();}
+
+    bool      empty()    const {return __tree_.size() == 0;}
+    size_type size()     const {return __tree_.size();}
+    size_type max_size() const {return __tree_.max_size();}
+
+    // modifiers:
+#ifdef _LIBCPP_MOVE
+    template <class... _Args>
+        pair<iterator, bool> emplace(_Args&&... __args)
+            {return __tree_.__emplace_unique(_STD::forward<_Args>(__args)...);}
+    template <class... _Args>
+        iterator emplace_hint(const_iterator __p, _Args&&... __args)
+            {return __tree_.__emplace_hint_unique(__p, _STD::forward<_Args>(__args)...);}
+#endif
+    pair<iterator,bool> insert(const value_type& __v)
+        {return __tree_.__insert_unique(__v);}
+#ifdef _LIBCPP_MOVE
+    pair<iterator,bool> insert(value_type&& __v)
+        {return __tree_.__insert_unique(_STD::move(__v));}
+#endif
+    iterator insert(const_iterator __p, const value_type& __v)
+        {return __tree_.__insert_unique(__p, __v);}
+#ifdef _LIBCPP_MOVE
+    iterator insert(const_iterator __p, value_type&& __v)
+        {return __tree_.__insert_unique(__p, _STD::move(__v));}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __f, _InputIterator __l)
+        {
+            for (const_iterator __e = cend(); __f != __l; ++__f)
+                __tree_.__insert_unique(__e, *__f);
+        }
+
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator  erase(const_iterator __p) {return __tree_.erase(__p);}
+    size_type erase(const key_type& __k)
+        {return __tree_.__erase_unique(__k);}
+    iterator  erase(const_iterator __f, const_iterator __l)
+        {return __tree_.erase(__f, __l);}
+    void clear() {__tree_.clear();}
+
+    void swap(set& __s) {__tree_.swap(__s.__tree_);}
+
+    allocator_type get_allocator() const {return __tree_.__alloc();}
+    key_compare    key_comp()      const {return __tree_.value_comp();}
+    value_compare  value_comp()    const {return __tree_.value_comp();}
+
+    // set operations:
+    iterator find(const key_type& __k)             {return __tree_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
+    size_type      count(const key_type& __k) const
+        {return __tree_.__count_unique(__k);}
+    iterator lower_bound(const key_type& __k)
+        {return __tree_.lower_bound(__k);}
+    const_iterator lower_bound(const key_type& __k) const
+        {return __tree_.lower_bound(__k);}
+    iterator upper_bound(const key_type& __k)
+        {return __tree_.upper_bound(__k);}
+    const_iterator upper_bound(const key_type& __k) const
+        {return __tree_.upper_bound(__k);}
+    pair<iterator,iterator> equal_range(const key_type& __k)
+        {return __tree_.__equal_range_unique(__k);}
+    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
+        {return __tree_.__equal_range_unique(__k);}
+};
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Compare, class _Allocator>
+set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
+    : __tree_(_STD::move(__s.__tree_), __a)
+{
+    if (__a != __s.get_allocator())
+    {
+        const_iterator __e = cend();
+        while (!__s.empty())
+            insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
+    }
+}
+
+#endif
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator==(const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator< (const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator!=(const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator> (const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator>=(const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator<=(const set<_Key, _Compare, _Allocator>& __x,
+           const set<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+// specialized algorithms:
+template <class _Key, class _Compare, class _Allocator>
+inline
+void
+swap(set<_Key, _Compare, _Allocator>& __x,
+     set<_Key, _Compare, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+
+template <class _Key, class _Compare = less<_Key>,
+          class _Allocator = allocator<_Key> >
+class multiset
+{
+public:
+    // types:
+    typedef _Key                                      key_type;
+    typedef key_type                                 value_type;
+    typedef _Compare                                  key_compare;
+    typedef key_compare                              value_compare;
+    typedef _Allocator                                allocator_type;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+
+private:
+    typedef __tree<value_type, value_compare, allocator_type> __base;
+    typedef allocator_traits<allocator_type>                  __alloc_traits;
+    typedef typename __base::__node_holder                    __node_holder;
+
+    __base __tree_;
+
+public:
+    typedef typename __base::pointer               pointer;
+    typedef typename __base::const_pointer         const_pointer;
+    typedef typename __base::size_type             size_type;
+    typedef typename __base::difference_type       difference_type;
+    typedef typename __base::const_iterator        iterator;
+    typedef typename __base::const_iterator        const_iterator;
+    typedef _STD::reverse_iterator<iterator>       reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
+
+    // construct/copy/destroy:
+    explicit multiset(const value_compare& __comp = value_compare())
+        : __tree_(__comp) {}
+    multiset(const value_compare& __comp, const allocator_type& __a)
+        : __tree_(__comp, __a) {}
+    template <class _InputIterator>
+        multiset(_InputIterator __f, _InputIterator __l,
+                 const value_compare& __comp = value_compare())
+        : __tree_(__comp)
+        {
+            insert(__f, __l);
+        }
+
+    template <class _InputIterator>
+        multiset(_InputIterator __f, _InputIterator __l,
+                 const value_compare& __comp, const allocator_type& __a)
+        : __tree_(__comp, __a)
+        {
+            insert(__f, __l);
+        }
+
+    multiset(const multiset& __s)
+        : __tree_(__s.__tree_.value_comp(),
+          __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
+        {
+            insert(__s.begin(), __s.end());
+        }
+
+#ifdef _LIBCPP_MOVE
+    multiset(multiset&& __s)
+        : __tree_(_STD::move(__s.__tree_)) {}
+#endif
+    explicit multiset(const allocator_type& __a)
+        : __tree_(__a) {}
+    multiset(const multiset& __s, const allocator_type& __a)
+        : __tree_(__s.__tree_.value_comp(), __a)
+        {
+            insert(__s.begin(), __s.end());
+        }
+#ifdef _LIBCPP_MOVE
+    multiset(multiset&& __s, const allocator_type& __a);
+#endif
+
+    multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
+        : __tree_(__comp)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    multiset(initializer_list<value_type> __il, const value_compare& __comp,
+        const allocator_type& __a)
+        : __tree_(__comp, __a)
+        {
+            insert(__il.begin(), __il.end());
+        }
+
+    multiset& operator=(initializer_list<value_type> __il)
+        {
+            __tree_.__assign_multi(__il.begin(), __il.end());
+            return *this;
+        }
+
+#ifdef _LIBCPP_MOVE
+    multiset& operator=(multiset&& __s)
+        {
+            __tree_ = _STD::move(__s.__tree_);
+            return *this;
+        }
+#endif
+
+          iterator begin()       {return __tree_.begin();}
+    const_iterator begin() const {return __tree_.begin();}
+          iterator end()         {return __tree_.end();}
+    const_iterator end()   const {return __tree_.end();}
+
+          reverse_iterator rbegin()       {return       reverse_iterator(end());}
+    const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+          reverse_iterator rend()         {return       reverse_iterator(begin());}
+    const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+
+    const_iterator         cbegin()  const {return begin();}
+    const_iterator         cend()    const {return end();}
+    const_reverse_iterator crbegin() const {return rbegin();}
+    const_reverse_iterator crend()   const {return rend();}
+
+    bool      empty()    const {return __tree_.size() == 0;}
+    size_type size()     const {return __tree_.size();}
+    size_type max_size() const {return __tree_.max_size();}
+
+    // modifiers:
+#ifdef _LIBCPP_MOVE
+    template <class... _Args>
+        iterator emplace(_Args&&... __args)
+            {return __tree_.__emplace_multi(_STD::forward<_Args>(__args)...);}
+    template <class... _Args>
+        iterator emplace_hint(const_iterator __p, _Args&&... __args)
+            {return __tree_.__emplace_hint_multi(__p, _STD::forward<_Args>(__args)...);}
+#endif
+    iterator insert(const value_type& __v)
+        {return __tree_.__insert_multi(__v);}
+#ifdef _LIBCPP_MOVE
+    iterator insert(value_type&& __v)
+        {return __tree_.__insert_multi(_STD::move(__v));}
+#endif
+    iterator insert(const_iterator __p, const value_type& __v)
+        {return __tree_.__insert_multi(__p, __v);}
+#ifdef _LIBCPP_MOVE
+    iterator insert(const_iterator __p, value_type&& __v)
+        {return __tree_.__insert_multi(_STD::move(__v));}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __f, _InputIterator __l)
+        {
+            for (const_iterator __e = cend(); __f != __l; ++__f)
+                __tree_.__insert_multi(__e, *__f);
+        }
+
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator  erase(const_iterator __p) {return __tree_.erase(__p);}
+    size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
+    iterator  erase(const_iterator __f, const_iterator __l)
+        {return __tree_.erase(__f, __l);}
+    void clear() {__tree_.clear();}
+
+    void swap(multiset& __s) {__tree_.swap(__s.__tree_);}
+
+    allocator_type get_allocator() const {return __tree_.__alloc();}
+    key_compare    key_comp()      const {return __tree_.value_comp();}
+    value_compare  value_comp()    const {return __tree_.value_comp();}
+
+    // set operations:
+    iterator find(const key_type& __k)             {return __tree_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
+    size_type      count(const key_type& __k) const
+        {return __tree_.__count_multi(__k);}
+    iterator lower_bound(const key_type& __k)
+        {return __tree_.lower_bound(__k);}
+    const_iterator lower_bound(const key_type& __k) const
+            {return __tree_.lower_bound(__k);}
+    iterator upper_bound(const key_type& __k)
+            {return __tree_.upper_bound(__k);}
+    const_iterator upper_bound(const key_type& __k) const
+            {return __tree_.upper_bound(__k);}
+    pair<iterator,iterator>             equal_range(const key_type& __k)
+            {return __tree_.__equal_range_multi(__k);}
+    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
+            {return __tree_.__equal_range_multi(__k);}
+};
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Compare, class _Allocator>
+multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
+    : __tree_(_STD::move(__s.__tree_), __a)
+{
+    if (__a != __s.get_allocator())
+    {
+        const_iterator __e = cend();
+        while (!__s.empty())
+            insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
+    }
+}
+
+#endif
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator==(const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator< (const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator> (const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+bool
+operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
+           const multiset<_Key, _Compare, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Key, class _Compare, class _Allocator>
+inline
+void
+swap(multiset<_Key, _Compare, _Allocator>& __x,
+     multiset<_Key, _Compare, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_SET
diff --git a/include/sstream b/include/sstream
new file mode 100644
index 0000000..55154c4
--- /dev/null
+++ b/include/sstream
@@ -0,0 +1,884 @@
+// -*- C++ -*-
+//===--------------------------- sstream ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SSTREAM
+#define _LIBCPP_SSTREAM
+
+/*
+    sstream synopsis
+
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+class basic_stringbuf
+    : public basic_streambuf<charT, traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef Allocator                      allocator_type;
+
+    // 27.8.1.1 Constructors:
+    explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out);
+    explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    basic_stringbuf(basic_stringbuf&& rhs);
+
+    // 27.8.1.2 Assign and swap:
+    basic_stringbuf& operator=(basic_stringbuf&& rhs);
+    void swap(basic_stringbuf& rhs);
+
+    // 27.8.1.3 Get and set:
+    basic_string<char_type, traits_type, allocator_type> str() const;
+    void str(const basic_string<char_type, traits_type, allocator_type>& s);
+
+protected:
+    // 27.8.1.4 Overridden virtual functions:
+    virtual int_type underflow();
+    virtual int_type pbackfail(int_type c = traits_type::eof());
+    virtual int_type overflow (int_type c = traits_type::eof());
+    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
+    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type sp,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+};
+
+template <class charT, class traits, class Allocator>
+  void swap(basic_stringbuf<charT, traits, Allocator>& x,
+            basic_stringbuf<charT, traits, Allocator>& y);
+
+typedef basic_stringbuf<char>    stringbuf;
+typedef basic_stringbuf<wchar_t> wstringbuf;
+
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+class basic_istringstream
+    : public basic_istream<charT, traits>
+{
+public:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef Allocator                      allocator_type;
+
+    // 27.8.2.1 Constructors:
+    explicit basic_istringstream(ios_base::openmode which = ios_base::in);
+    explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str,
+                                 ios_base::openmode which = ios_base::in);
+    basic_istringstream(basic_istringstream&& rhs);
+
+    // 27.8.2.2 Assign and swap:
+    basic_istringstream& operator=(basic_istringstream&& rhs);
+    void swap(basic_istringstream& rhs);
+
+    // 27.8.2.3 Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    basic_string<char_type, traits_type, allocator_type> str() const;
+    void str(const basic_string<char_type, traits_type, allocator_type>& s);
+};
+
+template <class charT, class traits, class Allocator>
+  void swap(basic_istringstream<charT, traits, Allocator>& x,
+            basic_istringstream<charT, traits, Allocator>& y);
+
+typedef basic_istringstream<char>    istringstream;
+typedef basic_istringstream<wchar_t> wistringstream;
+
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+class basic_ostringstream
+    : public basic_ostream<charT, traits>
+{
+public:
+    // types:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef Allocator                      allocator_type;
+
+    // 27.8.3.1 Constructors/destructor:
+    explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
+    explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str,
+                                 ios_base::openmode which = ios_base::out);
+    basic_ostringstream(basic_ostringstream&& rhs);
+
+    // 27.8.3.2 Assign/swap:
+    basic_ostringstream& operator=(basic_ostringstream&& rhs);
+    void swap(basic_ostringstream& rhs);
+
+    // 27.8.3.3 Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    basic_string<char_type, traits_type, allocator_type> str() const;
+    void str(const basic_string<char_type, traits_type, allocator_type>& s);
+};
+
+template <class charT, class traits, class Allocator>
+  void swap(basic_ostringstream<charT, traits, Allocator>& x,
+            basic_ostringstream<charT, traits, Allocator>& y);
+
+typedef basic_ostringstream<char>    ostringstream;
+typedef basic_ostringstream<wchar_t> wostringstream;
+
+template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+class basic_stringstream
+    : public basic_iostream<charT, traits>
+{
+public:
+    // types:
+    typedef charT                          char_type;
+    typedef traits                         traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef Allocator                      allocator_type;
+
+    // constructors/destructor
+    explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in);
+    explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str,
+                                ios_base::openmode which = ios_base::out|ios_base::in);
+    basic_stringstream(basic_stringstream&& rhs);
+
+    // 27.8.5.1 Assign/swap:
+    basic_stringstream& operator=(basic_stringstream&& rhs);
+    void swap(basic_stringstream& rhs);
+
+    // Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    basic_string<char_type, traits_type, allocator_type> str() const;
+    void str(const basic_string<char_type, traits_type, allocator_type>& str);
+};
+
+template <class charT, class traits, class Allocator>
+  void swap(basic_stringstream<charT, traits, Allocator>& x,
+            basic_stringstream<charT, traits, Allocator>& y);
+
+typedef basic_stringstream<char>    stringstream;
+typedef basic_stringstream<wchar_t> wstringstream;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ostream>
+#include <istream>
+#include <string>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// basic_stringbuf
+
+template <class _CharT, class _Traits, class _Allocator>
+class basic_stringbuf
+    : public basic_streambuf<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef _Allocator                     allocator_type;
+
+    typedef basic_string<char_type, traits_type, allocator_type> string_type;
+
+private:
+
+    string_type __str_;
+    mutable char_type* __hm_;
+    ios_base::openmode __mode_;
+
+public:
+    // 27.8.1.1 Constructors:
+    explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out);
+    explicit basic_stringbuf(const string_type& __s,
+                             ios_base::openmode __wch = ios_base::in | ios_base::out);
+#ifdef _LIBCPP_MOVE
+    basic_stringbuf(basic_stringbuf&& __rhs);
+#endif
+
+    // 27.8.1.2 Assign and swap:
+#ifdef _LIBCPP_MOVE
+    basic_stringbuf& operator=(basic_stringbuf&& __rhs);
+#endif
+    void swap(basic_stringbuf& __rhs);
+
+    // 27.8.1.3 Get and set:
+    string_type str() const;
+    void str(const string_type& __s);
+
+protected:
+    // 27.8.1.4 Overridden virtual functions:
+    virtual int_type underflow();
+    virtual int_type pbackfail(int_type __c = traits_type::eof());
+    virtual int_type overflow (int_type __c = traits_type::eof());
+    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
+                             ios_base::openmode __wch = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type __sp,
+                             ios_base::openmode __wch = ios_base::in | ios_base::out);
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch)
+    : __hm_(0),
+      __mode_(__wch)
+{
+    str(string_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s,
+                             ios_base::openmode __wch)
+    : __hm_(0),
+      __mode_(__wch)
+{
+    str(__s);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs)
+    : __mode_(__rhs.__mode_)
+{
+    ptrdiff_t __ninp = __rhs.gptr()  - __rhs.eback();
+    ptrdiff_t __einp = __rhs.egptr() - __rhs.eback();
+    ptrdiff_t __nout = __rhs.pptr()  - __rhs.pbase();
+    ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase();
+    ptrdiff_t __hm   = __rhs.__hm_   - __rhs.pbase();
+    __str_ = _STD::move(__rhs.__str_);
+    char_type* __p = const_cast<char_type*>(__str_.data());
+    this->setg(__p, __p + __ninp, __p + __einp);
+    this->setp(__p, __p + __eout);
+    this->pbump(__nout);
+    __hm_ = __p + __hm;
+    __p = const_cast<char_type*>(__rhs.__str_.data());
+    __rhs.setg(__p, __p, __p);
+    __rhs.setp(__p, __p);
+    __rhs.__hm_ = __p;
+    this->pubimbue(__rhs.getloc());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_stringbuf<_CharT, _Traits, _Allocator>&
+basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
+{
+    ptrdiff_t __ninp = __rhs.gptr()  - __rhs.eback();
+    ptrdiff_t __einp = __rhs.egptr() - __rhs.eback();
+    ptrdiff_t __nout = __rhs.pptr()  - __rhs.pbase();
+    ptrdiff_t __eout = __rhs.epptr() - __rhs.pbase();
+    ptrdiff_t __hm   = __rhs.__hm_   - __rhs.pbase();
+    __mode_ = __rhs.__mode_;
+    __str_ = _STD::move(__rhs.__str_);
+    char_type* __p = const_cast<char_type*>(__str_.data());
+    this->setg(__p, __p + __ninp, __p + __einp);
+    this->setp(__p, __p + __eout);
+    this->pbump(__nout);
+    __hm_ = __p + __hm;
+    __p = const_cast<char_type*>(__rhs.__str_.data());
+    __rhs.setg(__p, __p, __p);
+    __rhs.setp(__p, __p);
+    __rhs.__hm_ = __p;
+    this->pubimbue(__rhs.getloc());
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
+{
+    ptrdiff_t __rninp = __rhs.gptr()  - __rhs.eback();
+    ptrdiff_t __reinp = __rhs.egptr() - __rhs.eback();
+    ptrdiff_t __rnout = __rhs.pptr()  - __rhs.pbase();
+    ptrdiff_t __reout = __rhs.epptr() - __rhs.pbase();
+    ptrdiff_t __rhm   = __rhs.__hm_   - __rhs.pbase();
+    ptrdiff_t __lninp = this->gptr()  - this->eback();
+    ptrdiff_t __leinp = this->egptr() - this->eback();
+    ptrdiff_t __lnout = this->pptr()  - this->pbase();
+    ptrdiff_t __leout = this->epptr() - this->pbase();
+    ptrdiff_t __lhm   = this->__hm_   - this->pbase();
+    _STD::swap(__mode_, __rhs.__mode_);
+    __str_.swap(__rhs.__str_);
+    char_type* __p = const_cast<char_type*>(__str_.data());
+    this->setg(__p, __p + __rninp, __p + __reinp);
+    this->setp(__p, __p + __reout);
+    this->pbump(__rnout);
+    __hm_ = __p + __rhm;
+    __p = const_cast<char_type*>(__rhs.__str_.data());
+    __rhs.setg(__p, __p + __lninp, __p + __leinp);
+    __rhs.setp(__p, __p + __leout);
+    __rhs.pbump(__lnout);
+    __rhs.__hm_ = __p + __lhm;
+    locale __tl = __rhs.getloc();
+    __rhs.pubimbue(this->getloc());
+    this->pubimbue(__tl);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
+     basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+basic_stringbuf<_CharT, _Traits, _Allocator>::str() const
+{
+    if (__mode_ & ios_base::out)
+    {
+        if (__hm_ < this->pptr())
+            __hm_ = this->pptr();
+        return string_type(this->pbase(), __hm_, __str_.get_allocator());
+    }
+    else if (__mode_ & ios_base::in)
+        return string_type(this->eback(), this->egptr(), __str_.get_allocator());
+    return string_type(__str_.get_allocator());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s)
+{
+    __str_ = __s;
+    __hm_ = 0;
+    if (__mode_ & ios_base::in)
+    {
+        __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size();
+        this->setg(const_cast<char_type*>(__str_.data()),
+                   const_cast<char_type*>(__str_.data()),
+                   __hm_);
+    }
+    if (__mode_ & ios_base::out)
+    {
+        typename string_type::size_type __sz = __str_.size();
+        __hm_ = const_cast<char_type*>(__str_.data()) + __sz;
+        __str_.resize(__str_.capacity());
+        this->setp(const_cast<char_type*>(__str_.data()),
+                   const_cast<char_type*>(__str_.data()) + __str_.size());
+        if (__mode_ & (ios_base::app | ios_base::ate))
+            this->pbump(__sz);
+    }
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::underflow()
+{
+    if (__hm_ < this->pptr())
+        __hm_ = this->pptr();
+    if (__mode_ & ios_base::in)
+    {
+        if (this->egptr() < __hm_)
+            this->setg(this->eback(), this->gptr(), __hm_);
+        if (this->gptr() < this->egptr())
+            return traits_type::to_int_type(*this->gptr());
+    }
+    return traits_type::eof();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c)
+{
+    if (__hm_ < this->pptr())
+        __hm_ = this->pptr();
+    if (this->eback() < this->gptr())
+    {
+        if (traits_type::eq_int_type(__c, traits_type::eof()))
+        {
+            this->setg(this->eback(), this->gptr()-1, __hm_);
+            return traits_type::not_eof(__c);
+        }
+        if ((__mode_ & ios_base::out) ||
+            traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
+        {
+            this->setg(this->eback(), this->gptr()-1, __hm_);
+            *this->gptr() = traits_type::to_char_type(__c);
+            return __c;
+        }
+    }
+    return traits_type::eof();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c)
+{
+    if (!traits_type::eq_int_type(__c, traits_type::eof()))
+    {
+        ptrdiff_t __ninp = this->gptr()  - this->eback();
+        if (this->pptr() == this->epptr())
+        {
+            if (!(__mode_ & ios_base::out))
+                return traits_type::eof();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            try
+            {
+#endif
+                ptrdiff_t __nout = this->pptr()  - this->pbase();
+                ptrdiff_t __hm = __hm_ - this->pbase();
+                __str_.push_back(char_type());
+                __str_.resize(__str_.capacity());
+                char_type* __p = const_cast<char_type*>(__str_.data());
+                this->setp(__p, __p + __str_.size());
+                this->pbump(__nout);
+                __hm_ = this->pbase() + __hm;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+            }
+            catch (...)
+            {
+                return traits_type::eof();
+            }
+#endif
+        }
+        __hm_ = max(this->pptr() + 1, __hm_);
+        if (__mode_ & ios_base::in)
+        {
+            char_type* __p = const_cast<char_type*>(__str_.data());
+            this->setg(__p, __p + __ninp, __hm_);
+        }
+        return this->sputc(__c);
+    }
+    return traits_type::not_eof(__c);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
+                                                      ios_base::seekdir __way,
+                                                      ios_base::openmode __wch)
+{
+    if (__hm_ < this->pptr())
+        __hm_ = this->pptr();
+    if ((__wch & (ios_base::in | ios_base::out)) == 0)
+        return pos_type(-1);
+    if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
+        && __way == ios_base::cur)
+        return pos_type(-1);
+    off_type __noff;
+    switch (__way)
+    {
+    case ios_base::beg:
+        __noff = 0;
+        break;
+    case ios_base::cur:
+        if (__wch & ios_base::in)
+            __noff = this->gptr() - this->eback();
+        else
+            __noff = this->pptr() - this->pbase();
+        break;
+    case ios_base::end:
+        __noff = __hm_ - __str_.data();
+        break;
+    default:
+        return pos_type(-1);
+    }
+    __noff += __off;
+    if (__noff < 0 || __hm_ - __str_.data() < __noff)
+        return pos_type(-1);
+    if (__noff != 0)
+    {
+        if ((__wch & ios_base::in) && this->gptr() == 0)
+            return pos_type(-1);
+        if ((__wch & ios_base::out) && this->pptr() == 0)
+            return pos_type(-1);
+    }
+    if (__wch & ios_base::in)
+        this->setg(this->eback(), this->eback() + __noff, __hm_);
+    if (__wch & ios_base::out)
+    {
+        this->setp(this->pbase(), this->epptr());
+        this->pbump(__noff);
+    }
+    return pos_type(__noff);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
+basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp,
+                                                      ios_base::openmode __wch)
+{
+    return seekoff(__sp, ios_base::beg, __wch);
+}
+
+// basic_istringstream
+
+template <class _CharT, class _Traits, class _Allocator>
+class basic_istringstream
+    : public basic_istream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef _Allocator                     allocator_type;
+
+    typedef basic_string<char_type, traits_type, allocator_type> string_type;
+
+private:
+    basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
+
+public:
+    // 27.8.2.1 Constructors:
+    explicit basic_istringstream(ios_base::openmode __wch = ios_base::in);
+    explicit basic_istringstream(const string_type& __s,
+                                 ios_base::openmode __wch = ios_base::in);
+#ifdef _LIBCPP_MOVE
+    basic_istringstream(basic_istringstream&& __rhs);
+
+    // 27.8.2.2 Assign and swap:
+    basic_istringstream& operator=(basic_istringstream&& __rhs);
+#endif
+    void swap(basic_istringstream& __rhs);
+
+    // 27.8.2.3 Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    string_type str() const;
+    void str(const string_type& __s);
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch)
+    : basic_istream<_CharT, _Traits>(&__sb_),
+      __sb_(__wch | ios_base::in)
+{
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s,
+                                                                      ios_base::openmode __wch)
+    : basic_istream<_CharT, _Traits>(&__sb_),
+      __sb_(__s, __wch | ios_base::in)
+{
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs)
+    : basic_istream<_CharT, _Traits>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_istringstream<_CharT, _Traits, _Allocator>&
+basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs)
+{
+    basic_istream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs)
+{
+    basic_istream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
+     basic_istringstream<_CharT, _Traits, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringbuf<_CharT, _Traits, _Allocator>*
+basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const
+{
+    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, _Traits, _Allocator>
+basic_istringstream<_CharT, _Traits, _Allocator>::str() const
+{
+    return __sb_.str();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
+{
+    __sb_.str(__s);
+}
+
+// basic_ostringstream
+
+template <class _CharT, class _Traits, class _Allocator>
+class basic_ostringstream
+    : public basic_ostream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef _Allocator                     allocator_type;
+
+    typedef basic_string<char_type, traits_type, allocator_type> string_type;
+
+private:
+    basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
+
+public:
+    // 27.8.2.1 Constructors:
+    explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out);
+    explicit basic_ostringstream(const string_type& __s,
+                                 ios_base::openmode __wch = ios_base::out);
+#ifdef _LIBCPP_MOVE
+    basic_ostringstream(basic_ostringstream&& __rhs);
+
+    // 27.8.2.2 Assign and swap:
+    basic_ostringstream& operator=(basic_ostringstream&& __rhs);
+#endif
+    void swap(basic_ostringstream& __rhs);
+
+    // 27.8.2.3 Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    string_type str() const;
+    void str(const string_type& __s);
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch)
+    : basic_ostream<_CharT, _Traits>(&__sb_),
+      __sb_(__wch | ios_base::out)
+{
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s,
+                                                                      ios_base::openmode __wch)
+    : basic_ostream<_CharT, _Traits>(&__sb_),
+      __sb_(__s, __wch | ios_base::out)
+{
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs)
+    : basic_ostream<_CharT, _Traits>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_ostringstream<_CharT, _Traits, _Allocator>&
+basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs)
+{
+    basic_ostream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs)
+{
+    basic_ostream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
+     basic_ostringstream<_CharT, _Traits, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringbuf<_CharT, _Traits, _Allocator>*
+basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const
+{
+    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, _Traits, _Allocator>
+basic_ostringstream<_CharT, _Traits, _Allocator>::str() const
+{
+    return __sb_.str();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
+{
+    __sb_.str(__s);
+}
+
+// basic_stringstream
+
+template <class _CharT, class _Traits, class _Allocator>
+class basic_stringstream
+    : public basic_iostream<_CharT, _Traits>
+{
+public:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+    typedef _Allocator                     allocator_type;
+
+    typedef basic_string<char_type, traits_type, allocator_type> string_type;
+
+private:
+    basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
+
+public:
+    // 27.8.2.1 Constructors:
+    explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out);
+    explicit basic_stringstream(const string_type& __s,
+                                ios_base::openmode __wch = ios_base::in | ios_base::out);
+#ifdef _LIBCPP_MOVE
+    basic_stringstream(basic_stringstream&& __rhs);
+
+    // 27.8.2.2 Assign and swap:
+    basic_stringstream& operator=(basic_stringstream&& __rhs);
+#endif
+    void swap(basic_stringstream& __rhs);
+
+    // 27.8.2.3 Members:
+    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
+    string_type str() const;
+    void str(const string_type& __s);
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch)
+    : basic_iostream<_CharT, _Traits>(&__sb_),
+      __sb_(__wch)
+{
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s,
+                                                                    ios_base::openmode __wch)
+    : basic_iostream<_CharT, _Traits>(&__sb_),
+      __sb_(__s, __wch)
+{
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs)
+    : basic_iostream<_CharT, _Traits>(_STD::move(__rhs)),
+      __sb_(_STD::move(__rhs.__sb_))
+{
+    basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_stringstream<_CharT, _Traits, _Allocator>&
+basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs)
+{
+    basic_iostream<char_type, traits_type>::operator=(_STD::move(__rhs));
+    __sb_ = _STD::move(__rhs.__sb_);
+    return *this;
+}
+
+#endif
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs)
+{
+    basic_iostream<char_type, traits_type>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
+     basic_stringstream<_CharT, _Traits, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_stringbuf<_CharT, _Traits, _Allocator>*
+basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const
+{
+    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_string<_CharT, _Traits, _Allocator>
+basic_stringstream<_CharT, _Traits, _Allocator>::str() const
+{
+    return __sb_.str();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
+{
+    __sb_.str(__s);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_SSTREAM
diff --git a/include/stack b/include/stack
new file mode 100644
index 0000000..d5ac100
--- /dev/null
+++ b/include/stack
@@ -0,0 +1,237 @@
+// -*- C++ -*-
+//===---------------------------- stack -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STACK
+#define _LIBCPP_STACK
+
+/*
+    stack synopsis
+
+namespace std
+{
+
+template <class T, class Container = deque<T>>
+class stack
+{
+public:
+    typedef Container                                container_type;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+
+public:
+    explicit stack();
+    explicit stack(const container_type& c);
+    explicit stack(container_type&& c);
+    stack(stack&& s);
+    stack& operator=(stack&& s);
+    template <class Alloc> explicit stack(const Alloc& a);
+    template <class Alloc> stack(const container_type& c, const Alloc& a);
+    template <class Alloc> stack(container_type&& c, const Alloc& a);
+    template <class Alloc> stack(stack&& c, const Alloc& a);
+
+    bool empty() const;
+    size_type size() const;
+    reference top();
+    const_reference top() const;
+
+    void push(const value_type& x);
+    void push(value_type&& x);
+    template <class... Args> void emplace(Args&&... args);
+    void pop();
+
+    void swap(stack& c);
+};
+
+template <class T, class Container>
+  bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
+template <class T, class Container>
+  bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
+template <class T, class Container>
+  bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
+template <class T, class Container>
+  bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
+template <class T, class Container>
+  bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
+template <class T, class Container>
+  bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
+
+template <class T, class Container>
+  void swap(stack<T, Container>& x, stack<T, Container>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <deque>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Container> class stack;
+
+template <class _Tp, class _Container>
+bool
+operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
+
+template <class _Tp, class _Container>
+bool
+operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
+
+template <class _Tp, class _Container = deque<_Tp> >
+class stack
+{
+public:
+    typedef _Container                               container_type;
+    typedef typename container_type::value_type      value_type;
+    typedef typename container_type::reference       reference;
+    typedef typename container_type::const_reference const_reference;
+    typedef typename container_type::size_type       size_type;
+
+protected:
+    container_type c;
+
+public:
+    stack() : c() {}
+    explicit stack(const container_type& __c) : c(__c) {}
+#ifdef _LIBCPP_MOVE
+    explicit stack(container_type&& __c) : c(_STD::move(__c)) {}
+    stack(stack&& __s) : c(_STD::move(__s.c)) {}
+    stack& operator=(stack&& __s) {c = _STD::move(__s.c); return *this;}
+#endif
+    template <class _Alloc>
+        explicit stack(const _Alloc& __a,
+                       typename enable_if<uses_allocator<container_type,
+                                                         _Alloc>::value>::type* = 0)
+            : c(__a) {}
+    template <class _Alloc>
+        stack(const container_type& __c, const _Alloc& __a,
+              typename enable_if<uses_allocator<container_type,
+                                                _Alloc>::value>::type* = 0)
+            : c(__c, __a) {}
+    template <class _Alloc>
+        stack(const stack& __s, const _Alloc& __a,
+              typename enable_if<uses_allocator<container_type,
+                                                _Alloc>::value>::type* = 0)
+            : c(__s.c, __a) {}
+#ifdef _LIBCPP_MOVE
+    template <class _Alloc>
+        stack(container_type&& __c, const _Alloc& __a,
+              typename enable_if<uses_allocator<container_type,
+                                                _Alloc>::value>::type* = 0)
+            : c(_STD::move(__c), __a) {}
+    template <class _Alloc>
+        stack(stack&& __s, const _Alloc& __a,
+              typename enable_if<uses_allocator<container_type,
+                                                _Alloc>::value>::type* = 0)
+            : c(_STD::move(__s.c), __a) {}
+#endif
+
+    bool empty()     const      {return c.empty();}
+    size_type size() const      {return c.size();}
+    reference top()             {return c.back();}
+    const_reference top() const {return c.back();}
+
+    void push(const value_type& __v) {c.push_back(__v);}
+#ifdef _LIBCPP_MOVE
+    void push(value_type&& __v) {c.push_back(_STD::move(__v));}
+    template <class... _Args> void emplace(_Args&&... __args)
+        {c.emplace_back(_STD::forward<_Args>(__args)...);}
+#endif
+    void pop() {c.pop_back();}
+
+    void swap(stack& __s)
+    {
+        using _STD::swap;
+        swap(c, __s.c);
+    }
+
+    template <class T1, class _C1>
+    friend
+    bool
+    operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
+    
+    template <class T1, class _C1>
+    friend
+    bool
+    operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
+};
+
+template <class _Tp, class _Container>
+inline
+bool
+operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return __x.c == __y.c;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return __x.c < __y.c;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Container>
+inline
+bool
+operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Container>
+inline
+void
+swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Tp, class _Container, class _Alloc>
+struct uses_allocator<stack<_Tp, _Container>, _Alloc>
+    : public uses_allocator<_Container, _Alloc>
+{
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_STACK
diff --git a/include/stdbool.h b/include/stdbool.h
new file mode 100644
index 0000000..3263659
--- /dev/null
+++ b/include/stdbool.h
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===--------------------------- stdbool.h --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STDBOOL_H
+#define _LIBCPP_STDBOOL_H
+
+/*
+    stdbool.h synopsis
+
+Macros:
+
+    __bool_true_false_are_defined
+
+*/
+
+#ifdef __cplusplus
+#include <__config>
+#endif
+
+#pragma GCC system_header
+
+#undef __bool_true_false_are_defined
+#define __bool_true_false_are_defined 1
+
+#ifndef __cplusplus
+
+#define	bool	_Bool
+#if __STDC_VERSION__ < 199901L && __GNUC__ < 3
+typedef	int	_Bool;
+#endif
+
+#define	false	(bool)0
+#define	true	(bool)1
+
+#endif /* !__cplusplus */
+
+#endif  // _LIBCPP_STDBOOL_H
diff --git a/include/stdexcept b/include/stdexcept
new file mode 100644
index 0000000..73025f8
--- /dev/null
+++ b/include/stdexcept
@@ -0,0 +1,161 @@
+// -*- C++ -*-
+//===--------------------------- stdexcept --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STDEXCEPT
+#define _LIBCPP_STDEXCEPT
+
+/*
+    stdexcept synopsis
+
+namespace std
+{
+
+class logic_error;
+    class domain_error;
+    class invalid_argument;
+    class length_error;
+    class out_of_range;
+class runtime_error;
+    class range_error;
+    class overflow_error;
+    class underflow_error;
+
+for each class xxx_error:
+
+class xxx_error : public exception // at least indirectly
+{
+public:
+    explicit xxx_error(const string& what_arg);
+    explicit xxx_error(const char*   what_arg);  // extension
+
+    virtual const char* what() const // returns what_arg
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <exception>
+#include <iosfwd>  // for string forward decl
+
+#pragma GCC system_header
+
+namespace std  // purposefully not using versioning namespace
+{
+
+class _LIBCPP_EXCEPTION_ABI logic_error
+    : public exception
+{
+private:
+    void* __imp_;
+public:
+    explicit logic_error(const string&);
+    explicit logic_error(const char*);
+
+    logic_error(const logic_error&) throw();
+    logic_error& operator=(const logic_error&) throw();
+
+    virtual ~logic_error() throw();
+
+    virtual const char* what() const throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI runtime_error
+    : public exception
+{
+private:
+    void* __imp_;
+public:
+    explicit runtime_error(const string&);
+    explicit runtime_error(const char*);
+
+    runtime_error(const runtime_error&) throw();
+    runtime_error& operator=(const runtime_error&) throw();
+
+    virtual ~runtime_error() throw();
+
+    virtual const char* what() const throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI domain_error
+    : public logic_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
+
+    virtual ~domain_error() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI invalid_argument
+    : public logic_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s)   : logic_error(__s) {}
+
+    virtual ~invalid_argument() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI length_error
+    : public logic_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s)   : logic_error(__s) {}
+
+    virtual ~length_error() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI out_of_range
+    : public logic_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
+
+    virtual ~out_of_range() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI range_error
+    : public runtime_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
+
+    virtual ~range_error() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI overflow_error
+    : public runtime_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
+
+    virtual ~overflow_error() throw();
+};
+
+class _LIBCPP_EXCEPTION_ABI underflow_error
+    : public runtime_error
+{
+public:
+    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
+    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
+
+    virtual ~underflow_error() throw();
+};
+
+
+}  // std
+
+#endif  // _LIBCPP_STDEXCEPT
diff --git a/include/streambuf b/include/streambuf
new file mode 100644
index 0000000..d14e5e2
--- /dev/null
+++ b/include/streambuf
@@ -0,0 +1,563 @@
+// -*- C++ -*-
+//===------------------------- streambuf ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STEAMBUF
+#define _LIBCPP_STEAMBUF
+
+/*
+    streambuf synopsis
+
+namespace std
+{
+
+template <class charT, class traits = char_traits<charT> >
+class basic_streambuf
+{
+public:
+    // types:
+    typedef charT char_type;
+    typedef traits traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    virtual ~basic_streambuf();
+
+    // 27.6.2.2.1 locales:
+    locale pubimbue(const locale& loc);
+    locale getloc() const;
+
+    // 27.6.2.2.2 buffer and positioning:
+    basic_streambuf* pubsetbuf(char_type* s, streamsize n);
+    pos_type pubseekoff(off_type off, ios_base::seekdir way,
+                        ios_base::openmode which = ios_base::in | ios_base::out);
+    pos_type pubseekpos(pos_type sp,
+                        ios_base::openmode which = ios_base::in | ios_base::out);
+    int pubsync();
+
+    // Get and put areas:
+    // 27.6.2.2.3 Get area:
+    streamsize in_avail();
+    int_type snextc();
+    int_type sbumpc();
+    int_type sgetc();
+    streamsize sgetn(char_type* s, streamsize n);
+
+    // 27.6.2.2.4 Putback:
+    int_type sputbackc(char_type c);
+    int_type sungetc();
+
+    // 27.6.2.2.5 Put area:
+    int_type sputc(char_type c);
+    streamsize sputn(const char_type* s, streamsize n);
+
+protected:
+    basic_streambuf();
+    basic_streambuf(const basic_streambuf& rhs);
+    basic_streambuf& operator=(const basic_streambuf& rhs);
+    void swap(basic_streambuf& rhs);
+
+    // 27.6.2.3.2 Get area:
+    char_type* eback() const;
+    char_type* gptr() const;
+    char_type* egptr() const;
+    void gbump(int n);
+    void setg(char_type* gbeg, char_type* gnext, char_type* gend);
+
+    // 27.6.2.3.3 Put area:
+    char_type* pbase() const;
+    char_type* pptr() const;
+    char_type* epptr() const;
+    void pbump(int n);
+    void setp(char_type* pbeg, char_type* pend);
+
+    // 27.6.2.4 virtual functions:
+    // 27.6.2.4.1 Locales:
+    virtual void imbue(const locale& loc);
+
+    // 27.6.2.4.2 Buffer management and positioning:
+    virtual basic_streambuf* setbuf(char_type* s, streamsize n);
+    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type sp,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual int sync();
+
+    // 27.6.2.4.3 Get area:
+    virtual streamsize showmanyc();
+    virtual streamsize xsgetn(char_type* s, streamsize n);
+    virtual int_type underflow();
+    virtual int_type uflow();
+
+    // 27.6.2.4.4 Putback:
+    virtual int_type pbackfail(int_type c = traits_type::eof());
+
+    // 27.6.2.4.5 Put area:
+    virtual streamsize xsputn(const char_type* s, streamsize n);
+    virtual int_type overflow (int_type c = traits_type::eof());
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <iosfwd>
+#include <ios>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _CharT, class _Traits>
+class basic_streambuf
+{
+public:
+    // types:
+    typedef _CharT                         char_type;
+    typedef _Traits                        traits_type;
+    typedef typename traits_type::int_type int_type;
+    typedef typename traits_type::pos_type pos_type;
+    typedef typename traits_type::off_type off_type;
+
+    virtual ~basic_streambuf();
+
+    // 27.6.2.2.1 locales:
+    locale pubimbue(const locale& __loc);
+    locale getloc() const;
+
+    // 27.6.2.2.2 buffer and positioning:
+    basic_streambuf* pubsetbuf(char_type* __s, streamsize __n);
+    pos_type pubseekoff(off_type __off, ios_base::seekdir __way,
+                        ios_base::openmode __which = ios_base::in | ios_base::out);
+    pos_type pubseekpos(pos_type __sp,
+                        ios_base::openmode __which = ios_base::in | ios_base::out);
+    int pubsync();
+
+    // Get and put areas:
+    // 27.6.2.2.3 Get area:
+    streamsize in_avail();
+    int_type snextc();
+    int_type sbumpc();
+    int_type sgetc();
+    streamsize sgetn(char_type* __s, streamsize __n);
+
+    // 27.6.2.2.4 Putback:
+    int_type sputbackc(char_type __c);
+    int_type sungetc();
+
+    // 27.6.2.2.5 Put area:
+    int_type sputc(char_type __c);
+    streamsize sputn(const char_type* __s, streamsize __n);
+
+protected:
+    basic_streambuf();
+    basic_streambuf(const basic_streambuf& __rhs);
+    basic_streambuf& operator=(const basic_streambuf& __rhs);
+    void swap(basic_streambuf& __rhs);
+
+    // 27.6.2.3.2 Get area:
+    _LIBCPP_ALWAYS_INLINE char_type* eback() const {return __binp_;}
+    _LIBCPP_ALWAYS_INLINE char_type* gptr()  const {return __ninp_;}
+    _LIBCPP_ALWAYS_INLINE char_type* egptr() const {return __einp_;}
+    void gbump(int __n);
+    void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend);
+
+    // 27.6.2.3.3 Put area:
+    _LIBCPP_ALWAYS_INLINE char_type* pbase() const {return __bout_;}
+    _LIBCPP_ALWAYS_INLINE char_type* pptr()  const {return __nout_;}
+    _LIBCPP_ALWAYS_INLINE char_type* epptr() const {return __eout_;}
+    void pbump(int __n);
+    void setp(char_type* __pbeg, char_type* __pend);
+
+    // 27.6.2.4 virtual functions:
+    // 27.6.2.4.1 Locales:
+    virtual void imbue(const locale& __loc);
+
+    // 27.6.2.4.2 Buffer management and positioning:
+    virtual basic_streambuf* setbuf(char_type* __s, streamsize __n);
+    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
+                             ios_base::openmode __which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type __sp,
+                             ios_base::openmode __which = ios_base::in | ios_base::out);
+    virtual int sync();
+
+    // 27.6.2.4.3 Get area:
+    virtual streamsize showmanyc();
+    virtual streamsize xsgetn(char_type* __s, streamsize __n);
+    virtual int_type underflow();
+    virtual int_type uflow();
+
+    // 27.6.2.4.4 Putback:
+    virtual int_type pbackfail(int_type __c = traits_type::eof());
+
+    // 27.6.2.4.5 Put area:
+    virtual streamsize xsputn(const char_type* __s, streamsize __n);
+    virtual int_type overflow(int_type __c = traits_type::eof());
+
+private:
+    locale __loc_;
+    char_type* __binp_;
+    char_type* __ninp_;
+    char_type* __einp_;
+    char_type* __bout_;
+    char_type* __nout_;
+    char_type* __eout_;
+};
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>::~basic_streambuf()
+{
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+locale
+basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc)
+{
+    imbue(__loc);
+    locale __r = __loc_;
+    __loc_ = __loc;
+    return __r;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+locale
+basic_streambuf<_CharT, _Traits>::getloc() const
+{
+    return __loc_;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+basic_streambuf<_CharT, _Traits>*
+basic_streambuf<_CharT, _Traits>::pubsetbuf(char_type* __s, streamsize __n)
+{
+    return setbuf(__s, __n);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::pos_type
+basic_streambuf<_CharT, _Traits>::pubseekoff(off_type __off,
+                                             ios_base::seekdir __way,
+                                             ios_base::openmode __which)
+{
+    return seekoff(__off, __way, __which);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::pos_type
+basic_streambuf<_CharT, _Traits>::pubseekpos(pos_type __sp,
+                                             ios_base::openmode __which)
+{
+    return seekpos(__sp, __which);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+int
+basic_streambuf<_CharT, _Traits>::pubsync()
+{
+    return sync();
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+basic_streambuf<_CharT, _Traits>::in_avail()
+{
+    if (__ninp_ < __einp_)
+        return static_cast<streamsize>(__einp_ - __ninp_);
+    return showmanyc();
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::snextc()
+{
+    if (sbumpc() == traits_type::eof())
+        return traits_type::eof();
+    return sgetc();
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::sbumpc()
+{
+    if (__ninp_ == __einp_)
+        return uflow();
+    return traits_type::to_int_type(*__ninp_++);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::sgetc()
+{
+    if (__ninp_ == __einp_)
+        return underflow();
+    return traits_type::to_int_type(*__ninp_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+basic_streambuf<_CharT, _Traits>::sgetn(char_type* __s, streamsize __n)
+{
+    return xsgetn(__s, __n);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::sputbackc(char_type __c)
+{
+    if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
+        return pbackfail(traits_type::to_int_type(__c));
+    return traits_type::to_int_type(*--__ninp_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::sungetc()
+{
+    if (__binp_ == __ninp_)
+        return pbackfail();
+    return traits_type::to_int_type(*--__ninp_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::sputc(char_type __c)
+{
+    if (__nout_ == __eout_)
+        return overflow(traits_type::to_int_type(__c));
+    *__nout_++ = __c;
+    return traits_type::to_int_type(__c);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+streamsize
+basic_streambuf<_CharT, _Traits>::sputn(const char_type* __s, streamsize __n)
+{
+    return xsputn(__s, __n);
+}
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>::basic_streambuf()
+    : __binp_(0),
+      __ninp_(0),
+      __einp_(0),
+      __bout_(0),
+      __nout_(0),
+      __eout_(0)
+{
+}
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb)
+    : __loc_(__sb.__loc_),
+      __binp_(__sb.__binp_),
+      __ninp_(__sb.__ninp_),
+      __einp_(__sb.__einp_),
+      __bout_(__sb.__bout_),
+      __nout_(__sb.__nout_),
+      __eout_(__sb.__eout_)
+{
+}
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>&
+basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb)
+{
+    __loc_ = __sb.__loc_;
+    __binp_ = __sb.__binp_;
+    __ninp_ = __sb.__ninp_;
+    __einp_ = __sb.__einp_;
+    __bout_ = __sb.__bout_;
+    __nout_ = __sb.__nout_;
+    __eout_ = __sb.__eout_;
+    return *this;
+}
+
+template <class _CharT, class _Traits>
+void
+basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb)
+{
+    _STD::swap(__loc_, __sb.__loc_);
+    _STD::swap(__binp_, __sb.__binp_);
+    _STD::swap(__ninp_, __sb.__ninp_);
+    _STD::swap(__einp_, __sb.__einp_);
+    _STD::swap(__bout_, __sb.__bout_);
+    _STD::swap(__nout_, __sb.__nout_);
+    _STD::swap(__eout_, __sb.__eout_);
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_streambuf<_CharT, _Traits>::gbump(int __n)
+{
+    __ninp_ += __n;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_streambuf<_CharT, _Traits>::setg(char_type* __gbeg, char_type* __gnext,
+                                                          char_type* __gend)
+{
+    __binp_ = __gbeg;
+    __ninp_ = __gnext;
+    __einp_ = __gend;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_streambuf<_CharT, _Traits>::pbump(int __n)
+{
+    __nout_ += __n;
+}
+
+template <class _CharT, class _Traits>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+basic_streambuf<_CharT, _Traits>::setp(char_type* __pbeg, char_type* __pend)
+{
+    __bout_ = __nout_ = __pbeg;
+    __eout_ = __pend;
+}
+
+template <class _CharT, class _Traits>
+void
+basic_streambuf<_CharT, _Traits>::imbue(const locale&)
+{
+}
+
+template <class _CharT, class _Traits>
+basic_streambuf<_CharT, _Traits>*
+basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize)
+{
+    return this;
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::pos_type
+basic_streambuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
+                                          ios_base::openmode __which)
+{
+    return pos_type(off_type(-1));
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::pos_type
+basic_streambuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode __which)
+{
+    return pos_type(off_type(-1));
+}
+
+template <class _CharT, class _Traits>
+int
+basic_streambuf<_CharT, _Traits>::sync()
+{
+    return 0;
+}
+
+template <class _CharT, class _Traits>
+streamsize
+basic_streambuf<_CharT, _Traits>::showmanyc()
+{
+    return 0;
+}
+
+template <class _CharT, class _Traits>
+streamsize
+basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n)
+{
+    const int_type __eof = traits_type::eof();
+    int_type __c;
+    streamsize __i = 0;
+    for (;__i < __n; ++__i, ++__s)
+    {
+        if (__ninp_ < __einp_)
+            *__s = *__ninp_++;
+        else if ((__c = uflow()) != __eof)
+            *__s = traits_type::to_char_type(__c);
+        else
+            break;
+    }
+    return __i;
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::underflow()
+{
+    return traits_type::eof();
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::uflow()
+{
+    if (underflow() == traits_type::eof())
+        return traits_type::eof();
+    return traits_type::to_int_type(*__ninp_++);
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::pbackfail(int_type)
+{
+    return traits_type::eof();
+}
+
+template <class _CharT, class _Traits>
+streamsize
+basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n)
+{
+    streamsize __i = 0;
+    int_type __eof = traits_type::eof();
+    for (; __i < __n; ++__s, ++__i)
+    {
+        if (__nout_ < __eout_)
+            *__nout_++ = *__s;
+        else if (overflow(*__s) == __eof)
+            break;
+    }
+    return __i;
+}
+
+template <class _CharT, class _Traits>
+typename basic_streambuf<_CharT, _Traits>::int_type
+basic_streambuf<_CharT, _Traits>::overflow(int_type __c)
+{
+    return traits_type::eof();
+}
+
+extern template class basic_streambuf<char>;
+extern template class basic_streambuf<wchar_t>;
+
+extern template class basic_ios<char>;
+extern template class basic_ios<wchar_t>;
+
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_STEAMBUF
diff --git a/include/string b/include/string
new file mode 100644
index 0000000..6839f49
--- /dev/null
+++ b/include/string
@@ -0,0 +1,3543 @@
+// -*- C++ -*-
+//===--------------------------- string -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STRING
+#define _LIBCPP_STRING
+
+/*
+    string synopsis
+
+namespace std
+{
+
+template <class stateT>
+class fpos
+{
+private:
+    stateT st;
+public:
+    fpos(streamoff = streamoff());
+
+    operator streamoff() const;
+
+    stateT state() const;
+    void state(stateT);
+
+    fpos& operator+=(streamoff);
+    fpos  operator+ (streamoff) const;
+    fpos& operator-=(streamoff);
+    fpos  operator- (streamoff) const;
+};
+
+template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
+
+template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
+template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
+
+template <class charT>
+struct char_traits
+{
+    typedef charT     char_type;
+    typedef ...       int_type;
+    typedef streamoff off_type;
+    typedef streampos pos_type;
+    typedef mbstate_t state_type;
+
+    static void assign(char_type& c1, const char_type& c2);
+    static bool eq(char_type c1, char_type c2);
+    static bool lt(char_type c1, char_type c2);
+
+    static int              compare(const char_type* s1, const char_type* s2, size_t n);
+    static size_t           length(const char_type* s);
+    static const char_type* find(const char_type* s, size_t n, const char_type& a);
+    static char_type*       move(char_type* s1, const char_type* s2, size_t n);
+    static char_type*       copy(char_type* s1, const char_type* s2, size_t n);
+    static char_type*       assign(char_type* s, size_t n, char_type a);
+
+    static int_type  not_eof(int_type c);
+    static char_type to_char_type(int_type c);
+    static int_type  to_int_type(char_type c);
+    static bool      eq_int_type(int_type c1, int_type c2);
+    static int_type  eof();
+};
+
+template <> struct char_traits<char>;
+template <> struct char_traits<wchar_t>;
+
+template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 
+class basic_string
+{
+public: 
+// types: 
+    typedef traits traits_type;
+    typedef typename traits_type::char_type value_type;
+    typedef Allocator allocator_type;
+    typedef typename allocator_type::size_type size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef typename allocator_type::reference reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef typename allocator_type::pointer pointer;
+    typedef typename allocator_type::const_pointer const_pointer;
+    typedef implementation-defined iterator;
+    typedef implementation-defined const_iterator;
+    typedef std::reverse_iterator<iterator> reverse_iterator;
+    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+    static const size_type npos = -1;
+
+    explicit basic_string(const allocator_type& a = allocator_type());
+    basic_string(const basic_string& str);
+    basic_string(basic_string&& str);
+    basic_string(const basic_string& str, size_type pos, size_type n = npos, const allocator_type& a = allocator_type());
+    basic_string(const_pointer s, const allocator_type& a = allocator_type());
+    basic_string(const_pointer s, size_type n, const allocator_type& a = allocator_type());
+    basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
+    template<class InputIterator>
+        basic_string(InputIterator begin, InputIterator end, const allocator_type& a = allocator_type());
+    basic_string(initializer_list<value_type>, const Allocator& = Allocator());
+    basic_string(const basic_string&, const Allocator&);
+    basic_string(basic_string&&, const Allocator&);
+
+    ~basic_string();
+
+    basic_string& operator=(const basic_string& str);
+    basic_string& operator=(const_pointer s);
+    basic_string& operator=(value_type c);
+    basic_string& operator=(initializer_list<value_type>);
+
+    iterator       begin();
+    const_iterator begin() const;
+    iterator       end();
+    const_iterator end() const;
+
+    reverse_iterator       rbegin();
+    const_reverse_iterator rbegin() const;
+    reverse_iterator       rend();
+    const_reverse_iterator rend() const;
+
+    const_iterator         cbegin() const;
+    const_iterator         cend() const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend() const;
+
+    size_type size() const;
+    size_type length() const;
+    size_type max_size() const;
+    size_type capacity() const;
+
+    void resize(size_type n, value_type c);
+    void resize(size_type n);
+
+    void reserve(size_type res_arg = 0);
+    void shrink_to_fit();
+    void clear();
+    bool empty() const;
+
+    const_reference operator[](size_type pos) const;
+    reference       operator[](size_type pos);
+
+    const_reference at(size_type n) const;
+    reference       at(size_type n);
+
+    basic_string& operator+=(const basic_string& str);
+    basic_string& operator+=(const_pointer s);
+    basic_string& operator+=(value_type c);
+    basic_string& operator+=(initializer_list<value_type>);
+
+    basic_string& append(const basic_string& str);
+    basic_string& append(const basic_string& str, size_type pos, size_type n);
+    basic_string& append(const_pointer s, size_type n);
+    basic_string& append(const_pointer s);
+    basic_string& append(size_type n, value_type c);
+    template<class InputIterator> basic_string& append(InputIterator first, InputIterator last);
+    basic_string& append(initializer_list<value_type>);
+
+    void push_back(value_type c);
+    void pop_back();
+    reference       front();
+    const_reference front() const;
+    reference       back();
+    const_reference back() const;
+
+    basic_string& assign(const basic_string& str);
+    basic_string& assign(const basic_string& str, size_type pos, size_type n);
+    basic_string& assign(const_pointer s, size_type n);
+    basic_string& assign(const_pointer s);
+    basic_string& assign(size_type n, value_type c);
+    template<class InputIterator> basic_string& assign(InputIterator first, InputIterator last);
+    basic_string& assign(initializer_list<value_type>);
+
+    basic_string& insert(size_type pos1, const basic_string& str);
+    basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n);
+    basic_string& insert(size_type pos, const_pointer s, size_type n);
+    basic_string& insert(size_type pos, const_pointer s);
+    basic_string& insert(size_type pos, size_type n, value_type c);
+    iterator      insert(const_iterator p, value_type c);
+    iterator      insert(const_iterator p, size_type n, value_type c);
+    template<class InputIterator> iterator insert(const_iterator p, InputIterator first, InputIterator last);
+    iterator      insert(const_iterator p, initializer_list<value_type>);
+
+    basic_string& erase(size_type pos = 0, size_type n = npos);
+    iterator      erase(const_iterator position);
+    iterator      erase(const_iterator first, const_iterator last);
+
+    basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
+    basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2);
+    basic_string& replace(size_type pos, size_type n1, const_pointer s, size_type n2);
+    basic_string& replace(size_type pos, size_type n1, const_pointer s);
+    basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
+    basic_string& replace(iterator i1, iterator i2, const basic_string& str);
+    basic_string& replace(iterator i1, iterator i2, const_pointer s, size_type n);
+    basic_string& replace(iterator i1, iterator i2, const_pointer s);
+    basic_string& replace(iterator i1, iterator i2, size_type n, value_type c);
+    template<class InputIterator> basic_string& replace(iterator i1, iterator i2, InputIterator j1, InputIterator j2);
+    basic_string& replace(iterator i1, iterator i2, initializer_list<value_type>);
+
+    size_type copy(pointer s, size_type n, size_type pos = 0) const;
+    basic_string substr(size_type pos = 0, size_type n = npos) const;
+
+    void swap(basic_string& str);
+
+    const_pointer c_str() const;
+    const_pointer data() const;
+
+    allocator_type get_allocator() const;
+
+    size_type find(const basic_string& str, size_type pos = 0) const;
+    size_type find(const_pointer s, size_type pos, size_type n) const;
+    size_type find(const_pointer s, size_type pos = 0) const;
+    size_type find(value_type c, size_type pos = 0) const;
+
+    size_type rfind(const basic_string& str, size_type pos = npos) const;
+    size_type rfind(const_pointer s, size_type pos, size_type n) const;
+    size_type rfind(const_pointer s, size_type pos = npos) const;
+    size_type rfind(value_type c, size_type pos = npos) const;
+
+    size_type find_first_of(const basic_string& str, size_type pos = 0) const;
+    size_type find_first_of(const_pointer s, size_type pos, size_type n) const;
+    size_type find_first_of(const_pointer s, size_type pos = 0) const;
+    size_type find_first_of(value_type c, size_type pos = 0) const;
+
+    size_type find_last_of(const basic_string& str, size_type pos = npos) const;
+    size_type find_last_of(const_pointer s, size_type pos, size_type n) const;
+    size_type find_last_of(const_pointer s, size_type pos = npos) const;
+    size_type find_last_of(value_type c, size_type pos = npos) const;
+
+    size_type find_first_not_of(const basic_string& str, size_type pos = 0) const;
+    size_type find_first_not_of(const_pointer s, size_type pos, size_type n) const;
+    size_type find_first_not_of(const_pointer s, size_type pos = 0) const;
+    size_type find_first_not_of(value_type c, size_type pos = 0) const;
+
+    size_type find_last_not_of(const basic_string& str, size_type pos = npos) const;
+    size_type find_last_not_of(const_pointer s, size_type pos, size_type n) const;
+    size_type find_last_not_of(const_pointer s, size_type pos = npos) const;
+    size_type find_last_not_of(value_type c, size_type pos = npos) const;
+
+    int compare(const basic_string& str) const;
+    int compare(size_type pos1, size_type n1, const basic_string& str) const;
+    int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2) const;
+    int compare(const_pointer s) const;
+    int compare(size_type pos1, size_type n1, const_pointer s) const;
+    int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const;
+
+    bool __invariants() const;
+};
+
+template<class charT, class traits, class Allocator>
+basic_string<charT, traits, Allocator>
+operator+(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+basic_string<charT, traits, Allocator>
+operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
+
+template<class charT, class traits, class Allocator>
+basic_string<charT, traits, Allocator>
+operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+basic_string<charT, traits, Allocator>
+operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+basic_string<charT, traits, Allocator>
+operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator==(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator> 
+bool operator!=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator< (const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator> (const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+void swap(basic_string<charT, traits, Allocator>& lhs, basic_string<charT, traits, Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+basic_istream<charT, traits>&
+operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
+
+template<class charT, class traits, class Allocator>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
+
+template<class charT, class traits, class Allocator>
+basic_istream<charT, traits>& 
+getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, charT delim);
+
+template<class charT, class traits, class Allocator>
+basic_istream<charT, traits>&
+getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
+
+typedef basic_string<char>    string;
+typedef basic_string<wchar_t> wstring;
+
+template <> struct hash<string>;
+template <> struct hash<u16string>;
+template <> struct hash<u32string>;
+template <> struct hash<wstring>;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <iosfwd>
+#include <cstring>
+#include <cwchar>
+#include <algorithm>
+#include <iterator>
+#include <utility>
+#include <memory>
+#include <stdexcept>
+#include <type_traits>
+#include <initializer_list>
+#include <__functional_base>
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+#include <cstdint>
+#endif
+#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
+#include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// fpos
+
+template <class _StateT>
+class fpos
+{
+private:
+    _StateT __st_;
+    streamoff __off_;
+public:
+    _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
+
+    _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
+
+    _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
+    _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
+
+    _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
+    _LIBCPP_INLINE_VISIBILITY fpos  operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
+    _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
+    _LIBCPP_INLINE_VISIBILITY fpos  operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
+};
+
+template <class _StateT>
+inline _LIBCPP_INLINE_VISIBILITY
+streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
+    {return streamoff(__x) - streamoff(__y);}
+
+template <class _StateT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
+    {return streamoff(__x) == streamoff(__y);}
+
+template <class _StateT>
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
+    {return streamoff(__x) != streamoff(__y);}
+
+// char_traits
+
+template <class _CharT>
+struct char_traits
+{
+    typedef _CharT    char_type;
+    typedef int       int_type;
+    typedef streamoff off_type;
+    typedef streampos pos_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_INLINE_VISIBILITY static void assign(char_type& __c1, const char_type& __c2) {__c1 = __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool eq(char_type __c1, char_type __c2) {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool lt(char_type __c1, char_type __c2) {return __c1 < __c2;}
+
+    static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
+    static size_t           length(const char_type* __s);
+    static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
+    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       assign(char_type* __s, size_t __n, char_type __a);
+
+    _LIBCPP_INLINE_VISIBILITY static int_type  not_eof(int_type __c)
+        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
+    _LIBCPP_INLINE_VISIBILITY static char_type to_char_type(int_type __c) {return char_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static int_type  to_int_type(char_type __c) {return int_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static bool      eq_int_type(int_type __c1, int_type __c2)
+        {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static int_type  eof() {return int_type(EOF);}
+};
+
+template <class _CharT>
+int
+char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
+{
+    for (; __n; --__n, ++__s1, ++__s2)
+    {
+        if (lt(*__s1, *__s2))
+            return -1;
+        if (lt(*__s2, *__s1))
+            return 1;
+    }
+    return 0;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+char_traits<_CharT>::length(const char_type* __s)
+{
+    size_t __len = 0;
+    for (; !eq(*__s, char_type(0)); ++__s)
+        ++__len;
+    return __len;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+const _CharT*
+char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
+{
+    for (; __n; --__n)
+    {
+        if (eq(*__s, __a))
+            return __s;
+        ++__s;
+    }
+    return 0;
+}
+
+template <class _CharT>
+_CharT*
+char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    if (__s1 < __s2)
+    {
+        for (; __n; --__n, ++__s1, ++__s2)
+            assign(*__s1, *__s2);
+    }
+    else if (__s2 < __s1)
+    {
+        __s1 += __n;
+        __s2 += __n;
+        for (; __n; --__n)
+            assign(*--__s1, *--__s2);
+    }
+    return __r;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT*
+char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    for (; __n; --__n, ++__s1, ++__s2)
+        assign(*__s1, *__s2);
+    return __r;
+}
+
+template <class _CharT>
+inline _LIBCPP_INLINE_VISIBILITY
+_CharT*
+char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
+{
+    char_type* __r = __s;
+    for (; __n; --__n, ++__s)
+        assign(*__s, __a);
+    return __r;
+}
+
+// char_traits<char>
+
+template <>
+struct char_traits<char>
+{
+    typedef char      char_type;
+    typedef int       int_type;
+    typedef streamoff off_type;
+    typedef streampos pos_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_INLINE_VISIBILITY static void assign(char_type& __c1, const char_type& __c2) {__c1 = __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool eq(char_type __c1, char_type __c2) {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool lt(char_type __c1, char_type __c2)
+        {return (unsigned char)__c1 < (unsigned char)__c2;}
+
+    _LIBCPP_INLINE_VISIBILITY static int              compare(const char_type* __s1, const char_type* __s2, size_t __n)
+        {return memcmp(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static size_t           length(const char_type* __s) {return strlen(__s);}
+    _LIBCPP_INLINE_VISIBILITY static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
+        {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n)
+        {return (char_type*)memmove(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n)
+        {return (char_type*)memcpy(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       assign(char_type* __s, size_t __n, char_type __a)
+        {return (char_type*)memset(__s, to_int_type(__a), __n);}
+
+    _LIBCPP_INLINE_VISIBILITY static int_type  not_eof(int_type __c)
+        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
+    _LIBCPP_INLINE_VISIBILITY static char_type to_char_type(int_type __c) {return char_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static int_type  to_int_type(char_type __c) {return int_type((unsigned char)__c);}
+    _LIBCPP_INLINE_VISIBILITY static bool      eq_int_type(int_type __c1, int_type __c2)
+        {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static int_type  eof() {return int_type(EOF);}
+};
+
+// char_traits<wchar_t>
+
+template <>
+struct char_traits<wchar_t>
+{
+    typedef wchar_t   char_type;
+    typedef wint_t    int_type;
+    typedef streamoff off_type;
+    typedef streampos pos_type;
+    typedef mbstate_t state_type;
+
+    _LIBCPP_INLINE_VISIBILITY static void assign(char_type& __c1, const char_type& __c2) {__c1 = __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool eq(char_type __c1, char_type __c2) {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool lt(char_type __c1, char_type __c2)
+        {return __c1 < __c2;}
+
+    _LIBCPP_INLINE_VISIBILITY static int              compare(const char_type* __s1, const char_type* __s2, size_t __n)
+        {return wmemcmp(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static size_t           length(const char_type* __s) {return wcslen(__s);}
+    _LIBCPP_INLINE_VISIBILITY static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
+        {return (const char_type*)wmemchr(__s, __a, __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n)
+        {return (char_type*)wmemmove(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n)
+        {return (char_type*)wmemcpy(__s1, __s2, __n);}
+    _LIBCPP_INLINE_VISIBILITY static char_type*       assign(char_type* __s, size_t __n, char_type __a)
+        {return (char_type*)wmemset(__s, __a, __n);}
+
+    _LIBCPP_INLINE_VISIBILITY static int_type  not_eof(int_type __c)
+        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
+    _LIBCPP_INLINE_VISIBILITY static char_type to_char_type(int_type __c) {return char_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static int_type  to_int_type(char_type __c) {return int_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static bool      eq_int_type(int_type __c1, int_type __c2)
+        {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static int_type  eof() {return int_type(WEOF);}
+};
+
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+
+template <>
+struct char_traits<char16_t>
+{
+    typedef char16_t       char_type;
+    typedef uint_least16_t int_type;
+    typedef streamoff      off_type;
+    typedef u16streampos   pos_type;
+    typedef mbstate_t      state_type;
+
+    _LIBCPP_INLINE_VISIBILITY static void assign(char_type& __c1, const char_type& __c2) {__c1 = __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool eq(char_type __c1, char_type __c2) {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool lt(char_type __c1, char_type __c2) {return __c1 < __c2;}
+
+    static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
+    static size_t           length(const char_type* __s);
+    static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
+    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       assign(char_type* __s, size_t __n, char_type __a);
+
+    _LIBCPP_INLINE_VISIBILITY static int_type  not_eof(int_type __c)
+        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
+    _LIBCPP_INLINE_VISIBILITY static char_type to_char_type(int_type __c) {return char_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static int_type  to_int_type(char_type __c) {return int_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static bool      eq_int_type(int_type __c1, int_type __c2)
+        {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static int_type  eof() {return int_type(0xDFFF);}
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+int
+char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
+{
+    for (; __n; --__n, ++__s1, ++__s2)
+    {
+        if (lt(*__s1, *__s2))
+            return -1;
+        if (lt(*__s2, *__s1))
+            return 1;
+    }
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+char_traits<char16_t>::length(const char_type* __s)
+{
+    size_t __len = 0;
+    for (; !eq(*__s, char_type(0)); ++__s)
+        ++__len;
+    return __len;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+const char16_t*
+char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
+{
+    for (; __n; --__n)
+    {
+        if (eq(*__s, __a))
+            return __s;
+        ++__s;
+    }
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char16_t*
+char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    if (__s1 < __s2)
+    {
+        for (; __n; --__n, ++__s1, ++__s2)
+            assign(*__s1, *__s2);
+    }
+    else if (__s2 < __s1)
+    {
+        __s1 += __n;
+        __s2 += __n;
+        for (; __n; --__n)
+            assign(*--__s1, *--__s2);
+    }
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char16_t*
+char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    for (; __n; --__n, ++__s1, ++__s2)
+        assign(*__s1, *__s2);
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char16_t*
+char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
+{
+    char_type* __r = __s;
+    for (; __n; --__n, ++__s)
+        assign(*__s, __a);
+    return __r;
+}
+
+template <>
+struct char_traits<char32_t>
+{
+    typedef char32_t       char_type;
+    typedef uint_least32_t int_type;
+    typedef streamoff      off_type;
+    typedef u32streampos   pos_type;
+    typedef mbstate_t      state_type;
+
+    _LIBCPP_INLINE_VISIBILITY static void assign(char_type& __c1, const char_type& __c2) {__c1 = __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool eq(char_type __c1, char_type __c2) {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static bool lt(char_type __c1, char_type __c2) {return __c1 < __c2;}
+
+    static int              compare(const char_type* __s1, const char_type* __s2, size_t __n);
+    static size_t           length(const char_type* __s);
+    static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
+    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);
+    static char_type*       assign(char_type* __s, size_t __n, char_type __a);
+
+    _LIBCPP_INLINE_VISIBILITY static int_type  not_eof(int_type __c)
+        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
+    _LIBCPP_INLINE_VISIBILITY static char_type to_char_type(int_type __c) {return char_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static int_type  to_int_type(char_type __c) {return int_type(__c);}
+    _LIBCPP_INLINE_VISIBILITY static bool      eq_int_type(int_type __c1, int_type __c2)
+        {return __c1 == __c2;}
+    _LIBCPP_INLINE_VISIBILITY static int_type  eof() {return int_type(0xFFFFFFFF);}
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+int
+char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
+{
+    for (; __n; --__n, ++__s1, ++__s2)
+    {
+        if (lt(*__s1, *__s2))
+            return -1;
+        if (lt(*__s2, *__s1))
+            return 1;
+    }
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+size_t
+char_traits<char32_t>::length(const char_type* __s)
+{
+    size_t __len = 0;
+    for (; !eq(*__s, char_type(0)); ++__s)
+        ++__len;
+    return __len;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+const char32_t*
+char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
+{
+    for (; __n; --__n)
+    {
+        if (eq(*__s, __a))
+            return __s;
+        ++__s;
+    }
+    return 0;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char32_t*
+char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    if (__s1 < __s2)
+    {
+        for (; __n; --__n, ++__s1, ++__s2)
+            assign(*__s1, *__s2);
+    }
+    else if (__s2 < __s1)
+    {
+        __s1 += __n;
+        __s2 += __n;
+        for (; __n; --__n)
+            assign(*--__s1, *--__s2);
+    }
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char32_t*
+char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
+{
+    char_type* __r = __s1;
+    for (; __n; --__n, ++__s1, ++__s2)
+        assign(*__s1, *__s2);
+    return __r;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+char32_t*
+char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
+{
+    char_type* __r = __s;
+    for (; __n; --__n, ++__s)
+        assign(*__s, __a);
+    return __r;
+}
+
+#endif
+
+// basic_string
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&);
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const _CharT*, const basic_string<_CharT,_Traits,_Allocator>&);
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(_CharT, const basic_string<_CharT,_Traits,_Allocator>&);
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>&, const _CharT*);
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>&, _CharT);
+
+template <bool>
+class __basic_string_common
+{
+protected:
+    void __throw_length_error() const;
+    void __throw_out_of_range() const;
+};
+
+template <bool __b>
+void
+__basic_string_common<__b>::__throw_length_error() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw length_error("basic_string");
+#else
+    assert(!"basic_string length_error");
+#endif
+}
+
+template <bool __b>
+void
+__basic_string_common<__b>::__throw_out_of_range() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw out_of_range("basic_string");
+#else
+    assert(!"basic_string out_of_range");
+#endif
+}
+
+extern template class __basic_string_common<true>;
+
+template<class _CharT, class _Traits, class _Allocator> 
+class basic_string
+    : private __basic_string_common<true>
+{
+public:
+    typedef basic_string                                 __self;
+    typedef _Traits                                      traits_type;
+    typedef typename traits_type::char_type              value_type;
+    typedef _Allocator                                   allocator_type;
+    typedef typename allocator_type::size_type           size_type;
+    typedef typename allocator_type::difference_type     difference_type;
+    typedef typename allocator_type::reference           reference;
+    typedef typename allocator_type::const_reference     const_reference;
+    typedef typename allocator_type::pointer             pointer;
+    typedef typename allocator_type::const_pointer       const_pointer;
+#ifdef _LIBCPP_DEBUG
+    typedef __debug_iter<basic_string, pointer>          iterator;
+    typedef __debug_iter<basic_string, const_pointer>    const_iterator;
+
+    friend class __debug_iter<basic_string, pointer>;
+    friend class __debug_iter<basic_string, const_pointer>;
+#elif defined(_LIBCPP_RAW_ITERATORS)
+    typedef pointer                                      iterator;
+    typedef const_pointer                                const_iterator;
+#else
+    typedef __wrap_iter<pointer>                         iterator;
+    typedef __wrap_iter<const_pointer>                   const_iterator;
+#endif
+    typedef _STD::reverse_iterator<iterator>             reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>       const_reverse_iterator;
+
+private:
+    struct __long
+    {
+        size_type __cap_;
+        size_type __size_;
+        pointer   __data_;
+    };
+
+#if _LIBCPP_BIG_ENDIAN
+    enum {__short_mask = 0x80};
+    enum {__long_mask  = ~(size_type(~0) >> 1)};
+#else
+    enum {__short_mask = 0x01};
+    enum {__long_mask  = 0x1};
+#endif
+
+    enum {__mask = size_type(~0) >> 1};
+
+    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
+                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
+
+    struct __short
+    {
+        union
+        {
+            unsigned char __size_;
+            value_type _;
+        };
+        value_type __data_[__min_cap];
+    };
+
+    union _{__long _; __short __;};
+
+    enum {__n_words = sizeof(_) / sizeof(size_type)};
+
+    struct __raw
+    {
+        size_type __words[__n_words];
+    };
+
+    struct __rep
+    {
+        union
+        {
+            __long  __l;
+            __short __s;
+            __raw   __r;
+        };
+    };
+
+    __compressed_pair<__rep, allocator_type> __r_;
+
+#ifdef _LIBCPP_DEBUG
+
+    pair<iterator*, const_iterator*> __iterator_list_;
+
+    _LIBCPP_INLINE_VISIBILITY iterator*&       __get_iterator_list(iterator*)       {return __iterator_list_.first;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
+
+#endif  // _LIBCPP_DEBUG
+
+public:
+    static const size_type npos = -1;
+
+    basic_string();
+    explicit basic_string(const allocator_type& __a);
+    basic_string(const basic_string& __str);
+    basic_string(const basic_string& __str, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    basic_string(basic_string&& __str);
+    basic_string(basic_string&& __str, const allocator_type& __a);
+#endif
+    basic_string(const_pointer __s);
+    basic_string(const_pointer __s, const allocator_type& __a);
+    basic_string(const_pointer __s, size_type __n);
+    basic_string(const_pointer __s, size_type __n, const allocator_type& __a);
+    basic_string(size_type __n, value_type __c);
+    basic_string(size_type __n, value_type __c, const allocator_type& __a);
+    basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
+                 const allocator_type& __a = allocator_type());
+    template<class _InputIterator>
+        basic_string(_InputIterator __first, _InputIterator __last);
+    template<class _InputIterator>
+        basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
+    basic_string(initializer_list<value_type> __il);
+    basic_string(initializer_list<value_type> __il, const allocator_type& __a);
+
+    ~basic_string();
+
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const basic_string& __str) {return assign(__str);}
+#ifdef _LIBCPP_MOVE
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(basic_string&& __str) {swap(__str); return *this;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s)         {return assign(__s);}
+    basic_string& operator=(value_type __c);
+    basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
+
+#ifndef _LIBCPP_DEBUG
+    _LIBCPP_INLINE_VISIBILITY iterator       begin()       {return iterator(__get_pointer());}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(data());}
+    _LIBCPP_INLINE_VISIBILITY iterator       end()         {return iterator(__get_pointer() + size());}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end() const   {return const_iterator(data() + size());}
+#else  // _LIBCPP_DEBUG
+    _LIBCPP_INLINE_VISIBILITY iterator       begin()       {return iterator(this, __get_pointer());}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
+    _LIBCPP_INLINE_VISIBILITY iterator       end()         {return iterator(this, __get_pointer() + size());}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end() const   {return const_iterator(this, data() + size());}
+#endif  // _LIBCPP_DEBUG
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator       rbegin()       {return reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator       rend()         {return reverse_iterator(begin());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const   {return const_reverse_iterator(begin());}
+
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cbegin() const {return begin();}
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cend() const   {return end();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const {return rbegin();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const   {return rend();}
+
+    _LIBCPP_INLINE_VISIBILITY size_type size() const
+        {return __is_long() ? __get_long_size() : __get_short_size();}
+    _LIBCPP_INLINE_VISIBILITY size_type length() const {return size();}
+    size_type max_size() const;
+    _LIBCPP_INLINE_VISIBILITY size_type capacity() const
+        {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
+
+    void resize(size_type __n, value_type __c);
+    _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
+
+    void reserve(size_type res_arg = 0);
+    void shrink_to_fit() {reserve();}
+    void clear();
+    _LIBCPP_INLINE_VISIBILITY bool empty() const {return size() == 0;}
+
+    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
+    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __pos);
+
+    const_reference at(size_type __n) const;
+    reference       at(size_type __n);
+
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s)         {return append(__s);}
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c)            {push_back(__c); return *this;}
+    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
+
+    basic_string& append(const basic_string& __str);
+    basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
+    basic_string& append(const_pointer __s, size_type __n);
+    basic_string& append(const_pointer __s);
+    basic_string& append(size_type __n, value_type __c);
+    template<class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            basic_string&
+        >::type
+        append(_InputIterator __first, _InputIterator __last);
+    template<class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            basic_string&
+        >::type
+        append(_ForwardIterator __first, _ForwardIterator __last);
+    basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
+
+    void push_back(value_type __c);
+    void pop_back();
+    reference       front();
+    const_reference front() const;
+    reference       back();
+    const_reference back() const;
+
+    basic_string& assign(const basic_string& __str);
+    basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
+    basic_string& assign(const_pointer __s, size_type __n);
+    basic_string& assign(const_pointer __s);
+    basic_string& assign(size_type __n, value_type __c);
+    template<class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            basic_string&
+        >::type
+        assign(_InputIterator __first, _InputIterator __last);
+    template<class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            basic_string&
+        >::type
+        assign(_ForwardIterator __first, _ForwardIterator __last);
+    basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
+
+    basic_string& insert(size_type __pos1, const basic_string& __str);
+    basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
+    basic_string& insert(size_type __pos, const_pointer __s, size_type __n);
+    basic_string& insert(size_type __pos, const_pointer __s);
+    basic_string& insert(size_type __pos, size_type __n, value_type __c);
+    iterator      insert(const_iterator __pos, value_type __c);
+    iterator      insert(const_iterator __pos, size_type __n, value_type __c);
+    template<class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
+    template<class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
+    iterator insert(const_iterator __pos, initializer_list<value_type> __il)
+                    {return insert(__pos, __il.begin(), __il.end());}
+
+    basic_string& erase(size_type __pos = 0, size_type __n = npos);
+    iterator      erase(const_iterator __pos);
+    iterator      erase(const_iterator __first, const_iterator __last);
+
+    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
+    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
+    basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2);
+    basic_string& replace(size_type __pos, size_type __n1, const_pointer __s);
+    basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
+    basic_string& replace(iterator __i1, iterator __i2, const basic_string& __str);
+    basic_string& replace(iterator __i1, iterator __i2, const_pointer __s, size_type __n);
+    basic_string& replace(iterator __i1, iterator __i2, const_pointer __s);
+    basic_string& replace(iterator __i1, iterator __i2, size_type __n, value_type __c);
+    template<class _InputIterator>
+        typename enable_if
+        <
+            __is_input_iterator<_InputIterator>::value,
+            basic_string&
+        >::type
+        replace(iterator __i1, iterator __i2, _InputIterator __j1, _InputIterator __j2);
+    basic_string& replace(iterator __i1, iterator __i2, initializer_list<value_type> __il)
+        {return replace(__i1, __i2, __il.begin(), __il.end());}
+
+    size_type copy(pointer __s, size_type __n, size_type __pos = 0) const;
+    basic_string substr(size_type __pos = 0, size_type __n = npos) const;
+
+    void swap(basic_string& __str);
+
+    _LIBCPP_INLINE_VISIBILITY const_pointer c_str() const {return data();}
+    _LIBCPP_INLINE_VISIBILITY const_pointer data() const  {return __get_pointer();}
+
+    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const {return __alloc();}
+
+    size_type find(const basic_string& __str, size_type __pos = 0) const;
+    size_type find(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type find(const_pointer __s, size_type __pos = 0) const;
+    size_type find(value_type __c, size_type __pos = 0) const;
+
+    size_type rfind(const basic_string& __str, size_type __pos = npos) const;
+    size_type rfind(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type rfind(const_pointer __s, size_type __pos = npos) const;
+    size_type rfind(value_type __c, size_type __pos = npos) const;
+
+    size_type find_first_of(const basic_string& __str, size_type __pos = 0) const;
+    size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type find_first_of(const_pointer __s, size_type __pos = 0) const;
+    size_type find_first_of(value_type __c, size_type __pos = 0) const;
+
+    size_type find_last_of(const basic_string& __str, size_type __pos = npos) const;
+    size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type find_last_of(const_pointer __s, size_type __pos = npos) const;
+    size_type find_last_of(value_type __c, size_type __pos = npos) const;
+
+    size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const;
+    size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const;
+    size_type find_first_not_of(value_type __c, size_type __pos = 0) const;
+
+    size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const;
+    size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const;
+    size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const;
+    size_type find_last_not_of(value_type __c, size_type __pos = npos) const;
+
+    int compare(const basic_string& __str) const;
+    int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
+    int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
+    int compare(const_pointer __s) const;
+    int compare(size_type __pos1, size_type __n1, const_pointer __s) const;
+    int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const;
+
+    bool __invariants() const;
+private:
+    _LIBCPP_INLINE_VISIBILITY allocator_type&       __alloc()       {return __r_.second();}
+    _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const {return __r_.second();}
+
+    _LIBCPP_INLINE_VISIBILITY bool __is_long() const {return bool(__r_.first().__s.__size_ & __short_mask);}
+    _LIBCPP_INLINE_VISIBILITY void __set_long()  {__r_.first().__s.__size_ &= __short_mask;}
+    _LIBCPP_INLINE_VISIBILITY void __set_short() {__r_.first().__s.__size_ |= ~__short_mask;}
+
+    _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s)
+#if _LIBCPP_BIG_ENDIAN
+        {__r_.first().__s.__size_ = (unsigned char)(__s);}
+#else
+        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
+#endif
+    _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const
+#if _LIBCPP_BIG_ENDIAN
+        {return __r_.first().__s.__size_;}
+#else
+        {return __r_.first().__s.__size_ >> 1;}
+#endif
+    _LIBCPP_INLINE_VISIBILITY void __set_long_size(size_type __s)  {__r_.first().__l.__size_ = __s;}
+    _LIBCPP_INLINE_VISIBILITY size_type __get_long_size() const {return __r_.first().__l.__size_;}
+    _LIBCPP_INLINE_VISIBILITY void __set_size(size_type __s)
+        {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
+
+    _LIBCPP_INLINE_VISIBILITY void __set_long_cap(size_type __s)   {__r_.first().__l.__cap_  = __long_mask | __s;}
+    _LIBCPP_INLINE_VISIBILITY size_type __get_long_cap() const {return __r_.first().__l.__cap_ & ~__long_mask;}
+
+    _LIBCPP_INLINE_VISIBILITY void __set_long_pointer(pointer __p) {__r_.first().__l.__data_ = __p;}
+    _LIBCPP_INLINE_VISIBILITY pointer       __get_long_pointer()       {return __r_.first().__l.__data_;}
+    _LIBCPP_INLINE_VISIBILITY const_pointer __get_long_pointer() const {return __r_.first().__l.__data_;}
+    _LIBCPP_INLINE_VISIBILITY pointer       __get_short_pointer()       {return __r_.first().__s.__data_;}
+    _LIBCPP_INLINE_VISIBILITY const_pointer __get_short_pointer() const {return __r_.first().__s.__data_;}
+    _LIBCPP_INLINE_VISIBILITY pointer       __get_pointer()
+        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
+    _LIBCPP_INLINE_VISIBILITY const_pointer __get_pointer() const
+        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
+
+    _LIBCPP_INLINE_VISIBILITY void __zero()
+        {
+            size_type (&__a)[__n_words] = __r_.first().__r.__words;
+            for (unsigned __i = 0; __i < __n_words; ++__i)
+                __a[__i] = 0;
+        }
+
+    template <size_type __a> static
+        _LIBCPP_INLINE_VISIBILITY size_type __align(size_type __s) {return __s + (__a-1) & ~(__a-1);}
+    enum {__alignment = 16};
+    static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s)
+        {return (__s < __min_cap ? __min_cap :
+                 __align<sizeof(value_type) < __alignment ? __alignment/sizeof(value_type) : 1>(__s+1)) - 1;}
+
+    void __init(const_pointer __s, size_type __sz, size_type __reserve);
+    void __init(const_pointer __s, size_type __sz);
+    void __init(size_type __n, value_type __c);
+ 
+    template <class _InputIterator>
+    typename enable_if
+    <
+         __is_input_iterator  <_InputIterator>::value &&
+        !__is_forward_iterator<_InputIterator>::value,
+        void
+    >::type
+    __init(_InputIterator __first, _InputIterator __last);
+
+    template <class _ForwardIterator>
+    typename enable_if
+    <
+        __is_forward_iterator<_ForwardIterator>::value,
+        void
+    >::type
+    __init(_ForwardIterator __first, _ForwardIterator __last);
+
+    void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
+                   size_type __n_copy,  size_type __n_del,     size_type __n_add = 0); 
+    void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
+                               size_type __n_copy,  size_type __n_del,
+                               size_type __n_add, const_pointer __p_new_stuff);
+
+    void __erase_to_end(size_type __pos);
+
+    void __invalidate_all_iterators();
+    void __invalidate_iterators_past(size_type);
+
+    friend basic_string operator+<>(const basic_string&, const basic_string&);
+    friend basic_string operator+<>(const value_type*, const basic_string&);
+    friend basic_string operator+<>(value_type, const basic_string&);
+    friend basic_string operator+<>(const basic_string&, const value_type*);
+    friend basic_string operator+<>(const basic_string&, value_type);
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+#ifndef _LIBCPP_DEBUG
+_LIBCPP_INLINE_VISIBILITY inline
+#endif
+void
+basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
+{
+#ifdef _LIBCPP_DEBUG
+    iterator::__remove_all(this);
+    const_iterator::__remove_all(this);
+#endif
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+#ifndef _LIBCPP_DEBUG
+_LIBCPP_INLINE_VISIBILITY inline
+#endif
+void
+basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
+{
+#ifdef _LIBCPP_DEBUG
+    const_iterator __beg = begin();
+    if (__iterator_list_.first)
+    {
+        for (iterator* __p = __iterator_list_.first; __p;)
+        {
+            if (*__p - __beg > static_cast<difference_type>(__pos))
+            {
+                iterator* __n = __p;
+                __p = __p->__next;
+                __n->__remove_owner();
+            }
+            else
+                __p = __p->__next;
+        }
+    }
+    if (__iterator_list_.second)
+    {
+        for (const_iterator* __p = __iterator_list_.second; __p;)
+        {
+            if (*__p - __beg > static_cast<difference_type>(__pos))
+            {
+                const_iterator* __n = __p;
+                __p = __p->__next;
+                __n->__remove_owner();
+            }
+            else
+                __p = __p->__next;
+        }
+    }
+#endif
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string()
+{
+    __zero();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
+    : __r_(__a)
+{
+    __zero();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve)
+{
+    if (__reserve > max_size())
+        this->__throw_length_error();
+    pointer __p;
+    if (__reserve < __min_cap)
+    {
+        __set_short_size(__sz);
+        __p = __get_short_pointer();
+    }
+    else
+    {
+        size_type __cap = __recommend(__reserve);
+        __p = __alloc().allocate(__cap+1);
+        __set_long_pointer(__p);
+        __set_long_cap(__cap+1);
+        __set_long_size(__sz);
+    }
+    traits_type::copy(__p, __s, __sz);
+    traits_type::assign(__p[__sz], value_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz)
+{
+    if (__sz > max_size())
+        this->__throw_length_error();
+    pointer __p;
+    if (__sz < __min_cap)
+    {
+        __set_short_size(__sz);
+        __p = __get_short_pointer();
+    }
+    else
+    {
+        size_type __cap = __recommend(__sz);
+        __p = __alloc().allocate(__cap+1);
+        __set_long_pointer(__p);
+        __set_long_cap(__cap+1);
+        __set_long_size(__sz);
+    }
+    traits_type::copy(__p, __s, __sz);
+    traits_type::assign(__p[__sz], value_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    __init(__s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a)
+    : __r_(__a)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    __init(__s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    __init(__s, __n);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a)
+    : __r_(__a)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    __init(__s, __n);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
+    : __r_(__str.__alloc())
+{
+    if (!__str.__is_long())
+        __r_.first().__r = __str.__r_.first().__r;
+    else
+        __init(__str.__get_long_pointer(), __str.__get_long_size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
+    : __r_(__a)
+{
+    if (!__str.__is_long())
+        __r_.first().__r = __str.__r_.first().__r;
+    else
+        __init(__str.__get_long_pointer(), __str.__get_long_size());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
+    : __r_(_STD::move(__str.__r_))
+{
+    __str.__zero();
+#ifdef _LIBCPP_DEBUG
+    __str.__invalidate_all_iterators();
+#endif
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
+    : __r_(__str.__r_.first(), __a)
+{
+    __str.__zero();
+#ifdef _LIBCPP_DEBUG
+    __str.__invalidate_all_iterators();
+#endif
+}
+
+#endif  // _LIBCPP_MOVE
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
+{
+    if (__n > max_size())
+        this->__throw_length_error();
+    pointer __p;
+    if (__n < __min_cap)
+    {
+        __set_short_size(__n);
+        __p = __get_short_pointer();
+    }
+    else
+    {
+        size_type __cap = __recommend(__n);
+        __p = __alloc().allocate(__cap+1);
+        __set_long_pointer(__p);
+        __set_long_cap(__cap+1);
+        __set_long_size(__n);
+    }
+    traits_type::assign(__p, __n, __c);
+    traits_type::assign(__p[__n], value_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
+{
+    __init(__n, __c);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
+    : __r_(__a)
+{
+    __init(__n, __c);
+}
+
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
+                                                        const allocator_type& __a)
+    : __r_(__a)
+{
+    size_type __str_sz = __str.size();
+    if (__pos > __str_sz)
+        this->__throw_out_of_range();
+    __init(__str.data() + __pos, _STD::min(__n, __str_sz - __pos));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template <class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    void
+>::type
+basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
+{
+    __zero();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        if (__is_long())
+            __alloc().deallocate(__get_long_pointer(), __get_long_cap());
+        throw;
+    }
+#endif
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    void
+>::type
+basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
+{
+    size_type __sz = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__sz > max_size())
+        this->__throw_length_error();
+    pointer __p;
+    if (__sz < __min_cap)
+    {
+        __set_short_size(__sz);
+        __p = __get_short_pointer();
+    }
+    else
+    {
+        size_type __cap = __recommend(__sz);
+        __p = __alloc().allocate(__cap+1);
+        __set_long_pointer(__p);
+        __set_long_cap(__cap+1);
+        __set_long_size(__sz);
+    }
+    for (; __first != __last; ++__first, ++__p)
+        traits_type::assign(*__p, *__first);
+    traits_type::assign(*__p, value_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
+{
+    __init(__first, __last);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
+                                                        const allocator_type& __a)
+    : __r_(__a)
+{
+    __init(__first, __last);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
+{
+    __init(__il.begin(), __il.end());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
+    : __r_(__a)
+{
+    __init(__il.begin(), __il.end());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>::~basic_string()
+{
+    __invalidate_all_iterators();
+    if (__is_long())
+        __alloc().deallocate(__get_long_pointer(), __get_long_cap());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
+    (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
+     size_type __n_copy,  size_type __n_del,     size_type __n_add, const_pointer __p_new_stuff)
+{
+    size_type __ms = max_size();
+    if (__delta_cap > __ms - __old_cap - 1)
+        this->__throw_length_error();
+    pointer __old_p = __get_pointer();
+    size_type __cap = __old_cap < __ms / 2 - __alignment ?
+                          __recommend(_STD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
+                          __ms - 1;
+    pointer __p = __alloc().allocate(__cap+1);
+    __invalidate_all_iterators();
+    if (__n_copy != 0)
+        traits_type::copy(__p, __old_p, __n_copy);
+    if (__n_add != 0)
+        traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add);
+    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
+    if (__sec_cp_sz != 0)
+        traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
+    if (__old_cap+1 != __min_cap)
+        __alloc().deallocate(__old_p, __old_cap+1);
+    __set_long_pointer(__p);
+    __set_long_cap(__cap+1);
+    __old_sz = __n_copy + __n_add + __sec_cp_sz;
+    __set_long_size(__old_sz);
+    traits_type::assign(__p[__old_sz], value_type());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
+                                                     size_type __n_copy,  size_type __n_del,     size_type __n_add)
+{
+    size_type __ms = max_size();
+    if (__delta_cap > __ms - __old_cap - 1)
+        this->__throw_length_error();
+    pointer __old_p = __get_pointer();
+    size_type __cap = __old_cap < __ms / 2 - __alignment ?
+                          __recommend(_STD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
+                          __ms - 1;
+    pointer __p = __alloc().allocate(__cap+1);
+    __invalidate_all_iterators();
+    if (__n_copy != 0)
+        traits_type::copy(__p, __old_p, __n_copy);
+    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
+    if (__sec_cp_sz != 0)
+        traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
+    if (__old_cap+1 != __min_cap)
+        __alloc().deallocate(__old_p, __old_cap+1);
+    __set_long_pointer(__p);
+    __set_long_cap(__cap+1);
+}
+
+// assign
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __cap = capacity();
+    if (__cap >= __n)
+    {
+        pointer __p = __get_pointer();
+        traits_type::move(__p, __s, __n);
+        traits_type::assign(__p[__n], value_type());
+        __set_size(__n);
+        __invalidate_iterators_past(__n);
+    }
+    else
+    {
+        size_type __sz = size();
+        __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
+{
+    size_type __cap = capacity();
+    if (__cap < __n)
+    {
+        size_type __sz = size();
+        __grow_by(__cap, __n - __cap, __sz, 0, __sz);
+    }
+    else
+        __invalidate_iterators_past(__n);
+    pointer __p = __get_pointer();
+    traits_type::assign(__p, __n, __c);
+    traits_type::assign(__p[__n], value_type());
+    __set_size(__n);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
+{
+    pointer __p;
+    if (__is_long())
+    {
+        __p = __get_long_pointer();
+        __set_long_size(1);
+    }
+    else
+    {
+        __p = __get_short_pointer();
+        __set_short_size(1);
+    }
+    traits_type::assign(*__p, __c);
+    traits_type::assign(*++__p, value_type());
+    __invalidate_iterators_past(1);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    basic_string<_CharT, _Traits, _Allocator>&
+>::type
+basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
+{
+    clear();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    basic_string<_CharT, _Traits, _Allocator>&
+>::type
+basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
+{
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    size_type __cap = capacity();
+    if (__cap < __n)
+    {
+        size_type __sz = size();
+        __grow_by(__cap, __n - __cap, __sz, 0, __sz);
+    }
+    else
+        __invalidate_iterators_past(__n);
+    pointer __p = __get_pointer();
+    for (; __first != __last; ++__first, ++__p)
+        traits_type::assign(*__p, *__first);
+    traits_type::assign(*__p, value_type());
+    __set_size(__n);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
+{
+    return assign(__str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
+{
+    size_type __sz = __str.size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    return assign(__str.data() + __pos, _STD::min(__n, __sz - __pos));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return assign(__s, traits_type::length(__s));
+}
+
+// append
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __cap = capacity();
+    size_type __sz = size();
+    if (__cap - __sz >= __n)
+    {
+        if (__n)
+        {
+            pointer __p = __get_pointer();
+            traits_type::copy(__p + __sz, __s, __n);
+            __sz += __n;
+            __set_size(__sz);
+            traits_type::assign(__p[__sz], value_type());
+        }
+    }
+    else
+        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
+{
+    if (__n)
+    {
+        size_type __cap = capacity();
+        size_type __sz = size();
+        if (__cap - __sz < __n)
+            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
+        pointer __p = __get_pointer();
+        traits_type::assign(__p + __sz, __n, __c);
+        __sz += __n;
+        __set_size(__sz);
+        traits_type::assign(__p[__sz], value_type());
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
+{
+    size_type __cap = capacity();
+    size_type __sz = size();
+    if (__sz == __cap)
+        __grow_by(__cap, 1, __sz, __sz, 0);
+    pointer __p = __get_pointer() + __sz;
+    traits_type::assign(*__p, __c);
+    traits_type::assign(*++__p, value_type());
+    __set_size(__sz+1);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    basic_string<_CharT, _Traits, _Allocator>&
+>::type
+basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    basic_string<_CharT, _Traits, _Allocator>&
+>::type
+basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
+{
+    size_type __sz = size();
+    size_type __cap = capacity();
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n)
+    {
+        if (__cap - __sz < __n)
+            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
+        pointer __p = __get_pointer() + __sz;
+        for (; __first != __last; ++__p, ++__first)
+            traits_type::assign(*__p, *__first);
+        traits_type::assign(*__p, value_type());
+        __set_size(__sz + __n);
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
+{
+    return append(__str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
+{
+    size_type __sz = __str.size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    return append(__str.data() + __pos, _STD::min(__n, __sz - __pos));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return append(__s, traits_type::length(__s));
+}
+
+// insert
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    size_type __cap = capacity();
+    if (__cap - __sz >= __n)
+    {
+        if (__n)
+        {
+            pointer __p = __get_pointer();
+            size_type __n_move = __sz - __pos;
+            if (__n_move != 0)
+            {
+                if (__p + __pos <= __s && __s < __p + __sz)
+                    __s += __n;
+                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
+            }
+            traits_type::move(__p + __pos, __s, __n);
+            __sz += __n;
+            __set_size(__sz);
+            traits_type::assign(__p[__sz], value_type());
+        }
+    }
+    else
+        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
+{
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    if (__n)
+    {
+        size_type __cap = capacity();
+        pointer __p;
+        if (__cap - __sz >= __n)
+        {
+            __p = __get_pointer();
+            size_type __n_move = __sz - __pos;
+            if (__n_move != 0)
+                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
+        }
+        else
+        {
+            __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
+            __p = __get_long_pointer();
+        }
+        traits_type::assign(__p + __pos, __n, __c);
+        __sz += __n;
+        __set_size(__sz);
+        traits_type::assign(__p[__sz], value_type());
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    typename basic_string<_CharT, _Traits, _Allocator>::iterator
+>::type
+basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
+{
+    size_type __old_sz = size();
+    difference_type __ip = __pos - begin();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+    pointer __p = __get_pointer();
+    _STD::rotate(__p + __ip, __p + __old_sz, __p + size());
+    return iterator(__p + __ip);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    typename basic_string<_CharT, _Traits, _Allocator>::iterator
+>::type
+basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
+{
+    size_type __ip = static_cast<size_type>(__pos - begin());
+    size_type __sz = size();
+    size_type __cap = capacity();
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n)
+    {
+        pointer __p;
+        if (__cap - __sz >= __n)
+        {
+            __p = __get_pointer();
+            size_type __n_move = __sz - __ip;
+            if (__n_move != 0)
+                traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
+        }
+        else
+        {
+            __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
+            __p = __get_long_pointer();
+        }
+        __sz += __n;
+        __set_size(__sz);
+        traits_type::assign(__p[__sz], value_type());
+        for (__p += __ip; __first != __last; ++__p, ++__first)
+            traits_type::assign(*__p, *__first);
+    }
+    return begin() + __ip;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
+{
+    return insert(__pos1, __str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
+                                                  size_type __pos2, size_type __n)
+{
+    size_type __str_sz = __str.size();
+    if (__pos2 > __str_sz)
+        this->__throw_out_of_range();
+    return insert(__pos1, __str.data() + __pos2, _STD::min(__n, __str_sz - __pos2));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return insert(__pos, __s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::iterator
+basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
+{
+    size_type __ip = static_cast<size_type>(__pos - begin());
+    size_type __sz = size();
+    size_type __cap = capacity();
+    pointer __p;
+    if (__cap == __sz)
+    {
+        __grow_by(__cap, 1, __sz, __ip, 0, 1);
+        __p = __get_long_pointer();
+    }
+    else
+    {
+        __p = __get_pointer();
+        size_type __n_move = __sz - __ip;
+        if (__n_move != 0)
+            traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
+    }
+    traits_type::assign(__p[__ip], __c);
+    traits_type::assign(__p[++__sz], value_type());
+    __set_size(__sz);
+    return begin() + static_cast<difference_type>(__ip);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::iterator
+basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
+{
+    difference_type __p = __pos - begin();
+    insert(static_cast<size_type>(__p), __n, __c);
+    return begin() + __p;
+}
+
+// replace
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    __n1 = _STD::min(__n1, __sz - __pos);
+    size_type __cap = capacity();
+    if (__cap - __sz + __n1 >= __n2)
+    {
+        pointer __p = __get_pointer();
+        if (__n1 != __n2)
+        {
+            size_type __n_move = __sz - __pos - __n1;
+            if (__n_move != 0)
+            {
+                if (__n1 > __n2)
+                {
+                    traits_type::move(__p + __pos, __s, __n2);
+                    traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
+                    goto __finish;
+                }
+                if (__p + __pos < __s && __s < __p + __sz)
+                {
+                    if (__p + __pos + __n1 <= __s)
+                        __s += __n2 - __n1;
+                    else // __p + __pos < __s < __p + __pos + __n1
+                    {
+                        traits_type::move(__p + __pos, __s, __n1);
+                        __pos += __n1;
+                        __s += __n2;
+                        __n2 -= __n1;
+                        __n1 = 0;
+                    }
+                }
+                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
+            }
+        }
+        traits_type::move(__p + __pos, __s, __n2);
+__finish:
+        __sz += __n2 - __n1;
+        __set_size(__sz);
+        __invalidate_iterators_past(__sz);
+        traits_type::assign(__p[__sz], value_type());
+    }
+    else
+        __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
+{
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    __n1 = _STD::min(__n1, __sz - __pos);
+    size_type __cap = capacity();
+    pointer __p;
+    if (__cap - __sz + __n1 >= __n2)
+    {
+        __p = __get_pointer();
+        if (__n1 != __n2)
+        {
+            size_type __n_move = __sz - __pos - __n1;
+            if (__n_move != 0)
+                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
+        }
+    }
+    else
+    {
+        __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
+        __p = __get_long_pointer();
+    }
+    traits_type::assign(__p + __pos, __n2, __c);
+    __sz += __n2 - __n1;
+    __set_size(__sz);
+    __invalidate_iterators_past(__sz);
+    traits_type::assign(__p[__sz], value_type());
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+template<class _InputIterator>
+typename enable_if
+<
+    __is_input_iterator<_InputIterator>::value,
+    basic_string<_CharT, _Traits, _Allocator>&
+>::type
+basic_string<_CharT, _Traits, _Allocator>::replace(iterator __i1, iterator __i2,
+                                                   _InputIterator __j1, _InputIterator __j2)
+{
+    for (; true; ++__i1, ++__j1)
+    {
+        if (__i1 == __i2)
+        {
+            if (__j1 != __j2)
+                insert(__i1, __j1, __j2);
+            break;
+        }
+        if (__j1 == __j2)
+        {
+            erase(__i1, __i2);
+            break;
+        }
+        traits_type::assign(*__i1, *__j1);
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
+{
+    return replace(__pos1, __n1, __str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
+                                                   size_type __pos2, size_type __n2)
+{
+    size_type __str_sz = __str.size();
+    if (__pos2 > __str_sz)
+        this->__throw_out_of_range();
+    return replace(__pos1, __n1, __str.data() + __pos2, _STD::min(__n2, __str_sz - __pos2));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return replace(__pos, __n1, __s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(iterator __i1, iterator __i2, const basic_string& __str)
+{
+    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
+                   __str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(iterator __i1, iterator __i2, const_pointer __s, size_type __n)
+{
+    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(iterator __i1, iterator __i2, const_pointer __s)
+{
+    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::replace(iterator __i1, iterator __i2, size_type __n, value_type __c)
+{
+    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
+}
+
+// erase
+
+template <class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>&
+basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
+{
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    if (__n)
+    {
+        pointer __p = __get_pointer();
+        __n = _STD::min(__n, __sz - __pos);
+        size_type __n_move = __sz - __pos - __n;
+        if (__n_move != 0)
+            traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
+        __sz -= __n;
+        __set_size(__sz);
+        __invalidate_iterators_past(__sz);
+        traits_type::assign(__p[__sz], value_type());
+    }
+    return *this;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::iterator
+basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
+{
+    iterator __b = begin();
+    size_type __r = static_cast<size_type>(__pos - __b);
+    erase(__r, 1);
+    return __b + __r;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::iterator
+basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
+{
+    iterator __b = begin();
+    size_type __r = static_cast<size_type>(__first - __b);
+    erase(__r, static_cast<size_type>(__last - __first));
+    return __b + __r;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+basic_string<_CharT, _Traits, _Allocator>::pop_back()
+{
+#ifdef _LIBCPP_DEBUG
+    assert(!empty());
+#endif
+    size_type __sz;
+    if (__is_long())
+    {
+        __sz = __get_long_size() - 1;
+        __set_long_size(__sz);
+        traits_type::assign(*(__get_long_pointer() + __sz), value_type());
+    }
+    else
+    {
+        __sz = __get_short_size() - 1;
+        __set_short_size(__sz);
+        traits_type::assign(*(__get_short_pointer() + __sz), value_type());
+    }
+    __invalidate_iterators_past(__sz);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+basic_string<_CharT, _Traits, _Allocator>::clear()
+{
+    __invalidate_all_iterators();
+    if (__is_long())
+    {
+        traits_type::assign(*__get_long_pointer(), value_type());
+        __set_long_size(0);
+    }
+    else
+    {
+        traits_type::assign(*__get_short_pointer(), value_type());
+        __set_short_size(0);
+    }
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
+{
+    if (__is_long())
+    {
+        traits_type::assign(*(__get_long_pointer() + __pos), value_type());
+        __set_long_size(__pos);
+    }
+    else
+    {
+        traits_type::assign(*(__get_short_pointer() + __pos), value_type());
+        __set_short_size(__pos);
+    }
+    __invalidate_iterators_past(__pos);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
+{
+    size_type __sz = size();
+    if (__n > __sz)
+        append(__n - __sz, __c);
+    else
+        __erase_to_end(__n);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::max_size() const
+{
+    size_type __m = __alloc().max_size();
+#if _LIBCPP_BIG_ENDIAN
+    return (__m <= ~__long_mask ? __m : __m/2) - 1;
+#else
+    return __m - 1;
+#endif
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+void
+basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
+{
+    if (__res_arg > max_size())
+        this->__throw_length_error();
+    size_type __cap = capacity();
+    size_type __sz = size();
+    __res_arg = _STD::max(__res_arg, __sz);
+    __res_arg = __recommend(__res_arg);
+    if (__res_arg != __cap)
+    {
+        pointer __new_data, __p;
+        bool __was_long, __now_long;
+        if (__res_arg == __min_cap - 1)
+        {
+            __was_long = true;
+            __now_long = false;
+            __new_data = __get_short_pointer();
+            __p = __get_long_pointer();
+        }
+        else
+        {
+            if (__res_arg > __cap)
+                __new_data = __alloc().allocate(__res_arg+1);
+            else
+            {
+            #ifndef _LIBCPP_NO_EXCEPTIONS
+                try
+                {
+            #endif
+                    __new_data = __alloc().allocate(__res_arg+1);
+            #ifndef _LIBCPP_NO_EXCEPTIONS
+                }
+                catch (...)
+                {
+                    return;
+                }
+            #else
+                if (__new_data == 0)
+                    return;
+            #endif
+            }
+            __now_long = true;
+            __was_long = __is_long();
+            __p = __get_pointer();
+        }
+        traits_type::copy(__new_data, __p, size()+1);
+        if (__was_long)
+            __alloc().deallocate(__p, __cap+1);
+        if (__now_long)
+        {
+            __set_long_cap(__res_arg+1);
+            __set_long_size(__sz);
+            __set_long_pointer(__new_data);
+        }
+        else
+            __set_short_size(__sz);
+        __invalidate_all_iterators();
+    }
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::const_reference
+basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
+{
+#ifdef __LIBCPP_DEBUG
+    assert(__pos <= size());
+#endif
+    return *(data() + __pos);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::reference
+basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
+{
+#ifdef __LIBCPP_DEBUG
+    assert(__pos < size());
+#endif
+    return *(__get_pointer() + __pos);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::const_reference
+basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return (*this)[__n];
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::reference
+basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return (*this)[__n];
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::reference
+basic_string<_CharT, _Traits, _Allocator>::front()
+{
+#ifdef _LIBCPP_DEBUG
+    assert(!empty());
+#endif
+    return *__get_pointer();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::const_reference
+basic_string<_CharT, _Traits, _Allocator>::front() const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(!empty());
+#endif
+    return *data();
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::reference
+basic_string<_CharT, _Traits, _Allocator>::back()
+{
+#ifdef _LIBCPP_DEBUG
+    assert(!empty());
+#endif
+    return *(__get_pointer() + size() - 1);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::const_reference
+basic_string<_CharT, _Traits, _Allocator>::back() const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(!empty());
+#endif
+    return *(data() + size() - 1);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const
+{
+    size_type __sz = size();
+    if (__pos > __sz)
+        this->__throw_out_of_range();
+    size_type __rlen = _STD::min(__n, __sz - __pos);
+    traits_type::copy(__s, data() + __pos, __rlen);
+    return __rlen;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
+{
+    return basic_string(*this, __pos, __n, __alloc());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
+{
+    __r_.swap(__str.__r_);
+#ifdef _LIBCPP_DEBUG
+    __invalidate_all_iterators();
+    __str.__invalidate_all_iterators();
+#endif
+}
+
+// find
+
+template <class _Traits>
+struct _LIBCPP_HIDDEN __traits_eq
+{
+    typedef typename _Traits::char_type char_type;
+    _LIBCPP_INLINE_VISIBILITY bool operator()(const char_type& __x, const char_type& __y) {return _Traits::eq(__x, __y);}
+};
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos > __sz || __sz - __pos < __n)
+        return npos;
+    if (__n == 0)
+        return __pos;
+    const_pointer __p = data();
+    const_pointer __r = _STD::search(__p + __pos, __p + __sz, __s, __s + __n, __traits_eq<traits_type>());
+    if (__r == __p + __sz)
+        return npos;
+    return static_cast<size_type>(__r - __p);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, size_type __pos) const
+{
+    return find(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return find(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __pos) const
+{
+    size_type __sz = size();
+    if (__pos >= __sz)
+        return npos;
+    const_pointer __p = data();
+    const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c);
+    if (__r == 0)
+        return npos;
+    return static_cast<size_type>(__r - __p);
+}
+
+// rfind
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    __pos = _STD::min(__pos, __sz);
+    if (__n < __sz - __pos)
+        __pos += __n;
+    else
+        __pos = __sz;
+    const_pointer __p = data();
+    const_pointer __r = _STD::find_end(__p, __p + __pos, __s, __s + __n, __traits_eq<traits_type>());
+    if (__n > 0 && __r == __p + __pos)
+        return npos;
+    return static_cast<size_type>(__r - __p);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, size_type __pos) const
+{
+    return rfind(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return rfind(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, size_type __pos) const
+{
+    size_type __sz = size();
+    if (__sz)
+    {
+        if (__pos < __sz)
+            ++__pos;
+        else
+            __pos = __sz;
+        const_pointer __p = data();
+        for (const_pointer __ps = __p + __pos; __ps != __p;)
+        {
+            if (traits_type::eq(*--__ps, __c))
+                return static_cast<size_type>(__ps - __p);
+        }
+    }
+    return npos;
+}
+
+// find_first_of
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos >= __sz || __n == 0)
+        return npos;
+    const_pointer __p = data();
+    const_pointer __r = _STD::find_first_of(__p + __pos, __p + __sz, __s, __s + __n, __traits_eq<traits_type>());
+    if (__r == __p + __sz)
+        return npos;
+    return static_cast<size_type>(__r - __p);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, size_type __pos) const
+{
+    return find_first_of(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return find_first_of(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, size_type __pos) const
+{
+    return find(__c, __pos);
+}
+
+// find_last_of
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    if (__n != 0)
+    {
+        size_type __sz = size();
+        if (__pos < __sz)
+            ++__pos;
+        else
+            __pos = __sz;
+        const_pointer __p = data();
+        for (const_pointer __ps = __p + __pos; __ps != __p;)
+        {
+            const_pointer __r = traits_type::find(__s, __n, *--__ps);
+            if (__r)
+                return static_cast<size_type>(__ps - __p);
+        }
+    }
+    return npos;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, size_type __pos) const
+{
+    return find_last_of(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return find_last_of(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, size_type __pos) const
+{
+    return rfind(__c, __pos);
+}
+
+// find_first_not_of
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos < __sz)
+    {
+        const_pointer __p = data();
+        const_pointer __pe = __p + __sz;
+        for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
+            if (traits_type::find(__s, __n, *__ps) == 0)
+                return static_cast<size_type>(__ps - __p);
+    }
+    return npos;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, size_type __pos) const
+{
+    return find_first_not_of(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return find_first_not_of(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __pos) const
+{
+    size_type __sz = size();
+    if (__pos < __sz)
+    {
+        const_pointer __p = data();
+        const_pointer __pe = __p + __sz;
+        for (const_pointer __ps = __p + __pos; __p != __pe; ++__ps)
+            if (!traits_type::eq(*__ps, __c))
+                return static_cast<size_type>(__ps - __p);
+    }
+    return npos;
+}
+
+// find_last_not_of
+
+template<class _CharT, class _Traits, class _Allocator>
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos < __sz)
+        ++__pos;
+    else
+        __pos = __sz;
+    const_pointer __p = data();
+    for (const_pointer __ps = __p + __pos; __ps != __p;)
+        if (traits_type::find(__s, __n, *--__ps) == 0)
+            return static_cast<size_type>(__ps - __p);
+    return npos;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, size_type __pos) const
+{
+    return find_last_not_of(__str.data(), __pos, __str.size());
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, size_type __pos) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return find_last_not_of(__s, __pos, traits_type::length(__s));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename basic_string<_CharT, _Traits, _Allocator>::size_type
+basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, size_type __pos) const
+{
+    size_type __sz = size();
+    if (__pos < __sz)
+        ++__pos;
+    else
+        __pos = __sz;
+    const_pointer __p = data();
+    for (const_pointer __ps = __p + __pos; __ps != __p;)
+        if (!traits_type::eq(*--__ps, __c))
+            return static_cast<size_type>(__ps - __p);
+    return npos;
+}
+
+// compare
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const
+{
+    return compare(0, npos, __str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str) const
+{
+    return compare(__pos1, __n1, __str.data(), __str.size());
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str,
+                                                   size_type __pos2, size_type __n2) const
+{
+    size_type __sz = __str.size();
+    if (__pos2 > __sz)
+        this->__throw_out_of_range();
+    return compare(__pos1, __n1, __str.data() + __pos2, _STD::min(__n2, __sz - __pos2));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return compare(0, npos, __s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const_pointer __s) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    return compare(__pos1, __n1, __s, traits_type::length(__s));
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+int
+basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1,
+                                                   const_pointer __s, size_type __n2) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__s != 0);
+#endif
+    size_type __sz = size();
+    if (__pos1 > __sz || __n2 == npos)
+        this->__throw_out_of_range();
+    size_type __rlen = _STD::min(__n1, __sz - __pos1);
+    int __r = traits_type::compare(data() + __pos1, __s, _STD::min(__rlen, __n2));
+    if (__r == 0)
+    {
+        if (__rlen < __n2)
+            __r = -1;
+        else if (__rlen > __n2)
+            __r = 1;
+    }
+    return __r;
+}
+
+// __invariants
+
+template<class _CharT, class _Traits, class _Allocator>
+bool
+basic_string<_CharT, _Traits, _Allocator>::__invariants() const
+{
+    if (size() > capacity())
+        return false;
+    if (capacity() < __min_cap - 1)
+        return false;
+    if (data() == 0)
+        return false;
+    if (data()[size()] != value_type(0))
+        return false;
+    return true;
+}
+
+// operator==
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __lhs.size() == __rhs.size() && _Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()) == 0;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __rhs.compare(__lhs) == 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const char* __lhs, const basic_string<char, char_traits<char>, _Allocator>& __rhs)
+{
+    return strcmp(__lhs, __rhs.data()) == 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const wchar_t* __lhs, const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs)
+{
+    return wcscmp(__lhs, __rhs.data()) == 0;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const _CharT* __rhs)
+{
+    return __lhs.compare(__rhs) == 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, const char* __rhs)
+{
+    return strcmp(__lhs.data(), __rhs) == 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs, const wchar_t* __rhs)
+{
+    return wcscmp(__lhs.data(), __rhs) == 0;
+}
+
+// operator!=
+
+template<class _CharT, class _Traits, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    return !(__lhs == __rhs);
+}
+
+// operator<
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __lhs.cmpare(__rhs) < 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<char, char_traits<char>, _Allocator>& __lhs,
+           const basic_string<char, char_traits<char>, _Allocator>& __rhs)
+{
+    return strcmp(__lhs.data(), __rhs.data()) < 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs,
+           const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs)
+{
+    return wcscmp(__lhs.data(), __rhs.data()) < 0;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    return __lhs.compare(__rhs);
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<char, char_traits<char>, _Allocator>& __lhs, const char* __rhs)
+{
+    return strcmp(__lhs.data(), __rhs) < 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __lhs, const wchar_t* __rhs)
+{
+    return wcscmp(__lhs.data(), __rhs) < 0;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __rhs.compare(__lhs) > 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const char* __lhs, const basic_string<char, char_traits<char>, _Allocator>& __rhs)
+{
+    return strcmp(__lhs, __rhs.data()) < 0;
+}
+
+template<class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const wchar_t* __lhs, const basic_string<wchar_t, char_traits<wchar_t>, _Allocator>& __rhs)
+{
+    return wcscmp(__lhs, __rhs.data()) < 0;
+}
+
+// operator>
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    return __rhs < __lhs;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator> (const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return __rhs < __lhs;
+}
+
+// operator<=
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__rhs < __lhs);
+}
+
+// operator>=
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+           const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return !(__lhs < __rhs);
+}
+
+// operator +
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+          const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
+    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
+    __r.append(__rhs.data(), __rhs_sz);
+    return __r;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
+    __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
+    __r.append(__rhs.data(), __rhs_sz);
+    return __r;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
+    __r.__init(&__lhs, 1, 1 + __rhs_sz);
+    __r.append(__rhs.data(), __rhs_sz);
+    return __r;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
+    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
+    __r.append(__rhs, __rhs_sz);
+    return __r;
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
+{
+    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
+    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
+    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
+    __r.push_back(__rhs);
+    return __r;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    return _STD::move(__lhs.append(__rhs));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
+{
+    return _STD::move(__rhs.insert(0, __lhs));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
+{
+    return _STD::move(__lhs.append(__rhs));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
+{
+    return _STD::move(__rhs.insert(0, __lhs));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
+{
+    __rhs.insert(__rhs.begin(), __lhs);
+    return _STD::move(__rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
+{
+    return _STD::move(__lhs.append(__rhs));
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+basic_string<_CharT, _Traits, _Allocator>
+operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
+{
+    __lhs.push_back(__rhs);
+    return _STD::move(__lhs);
+}
+
+#endif  // _LIBCPP_MOVE
+
+// swap
+
+template<class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>& __rhs)
+{
+    __lhs.swap(__rhs);
+}
+
+template<class _CharT, class _Traits, class _Allocator>
+struct __is_zero_default_constructible<basic_string<_CharT, _Traits, _Allocator> >
+    : public integral_constant<bool, __is_zero_default_constructible<_Allocator>::value> {};
+
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+
+typedef basic_string<char16_t> u16string;
+typedef basic_string<char32_t> u32string;
+
+#endif
+
+template<class _CharT, class _Traits, class _Allocator>
+    const typename basic_string<_CharT, _Traits, _Allocator>::size_type
+                   basic_string<_CharT, _Traits, _Allocator>::npos;
+
+template<class _CharT, class _Traits, class _Allocator>
+struct hash<basic_string<_CharT, _Traits, _Allocator> >
+    : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
+{
+    size_t
+        operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const;
+};
+
+template<class _CharT, class _Traits, class _Allocator>
+size_t
+hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
+        const basic_string<_CharT, _Traits, _Allocator>& __val) const
+{
+    typedef basic_string<_CharT, _Traits, _Allocator> S;
+    typedef typename S::const_pointer const_pointer;
+    size_t __r = 0;
+    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
+    const size_t __m = size_t(0xF) << (__sr + 4);
+    const_pointer __p = __val.data();
+    const_pointer __e = __p + __val.size();
+    for (; __p != __e; ++__p)
+    {
+        __r = (__r << 4) + *__p;
+        size_t __g = __r & __m;
+        __r ^= __g | (__g >> __sr);
+    }
+    return __r;
+}
+
+extern template class basic_string<char>;
+extern template class basic_string<wchar_t>;
+
+extern template
+    enable_if<__is_forward_iterator<char const*>::value, void>::type
+    basic_string<char, char_traits<char>, allocator<char> >::
+    __init<char const*>(char const*, char const*);
+
+extern template
+    enable_if<__is_forward_iterator<wchar_t const*>::value, void>::type
+    basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >::
+    __init<wchar_t const*>(wchar_t const*, wchar_t const*);
+
+extern template
+    enable_if<__is_forward_iterator<char*>::value,
+    basic_string<char, char_traits<char>, allocator<char> >&>::type
+    basic_string<char, char_traits<char>, allocator<char> >::
+    append<char*>(char*, char*);
+
+extern template
+    enable_if<__is_forward_iterator<wchar_t*>::value,
+    basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&>::type
+    basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >::
+    append<wchar_t*>(wchar_t*, wchar_t*);
+
+extern template
+    enable_if<__is_forward_iterator<char const*>::value,
+    string::iterator>::type
+    string::
+    insert<char const*>(string::const_iterator, char const*, char const*);
+
+extern template
+    enable_if<__is_forward_iterator<wchar_t const*>::value,
+    wstring::iterator>::type
+    wstring::
+    insert<wchar_t const*>(wstring::const_iterator, wchar_t const*, wchar_t const*);
+
+extern template
+    enable_if<__is_input_iterator<char const*>::value, string&>::type
+    string::
+    replace<char const*>(string::iterator, string::iterator, char const*, char const*);
+
+extern template
+    enable_if<__is_input_iterator<wchar_t const*>::value, wstring&>::type
+    wstring::
+    replace<wchar_t const*>(wstring::iterator, wstring::iterator, wchar_t const*, wchar_t const*);
+
+extern template
+    enable_if<__is_forward_iterator<wchar_t*>::value, wstring&>::type
+    wstring::assign<wchar_t*>(wchar_t*, wchar_t*);
+
+extern template
+    string
+    operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_STRING
+
+// hh 060525 Created
diff --git a/include/strstream b/include/strstream
new file mode 100644
index 0000000..50f639f
--- /dev/null
+++ b/include/strstream
@@ -0,0 +1,332 @@
+// -*- C++ -*-
+//===--------------------------- strstream --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STRSTREAM
+#define _LIBCPP_STRSTREAM
+
+/*
+    strstream synopsis
+
+class strstreambuf
+    : public basic_streambuf<char>
+{
+public:
+    explicit strstreambuf(streamsize alsize_arg = 0);
+    strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
+    strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0);
+    strstreambuf(const char* gnext_arg, streamsize n);
+
+    strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0);
+    strstreambuf(const signed char* gnext_arg, streamsize n);
+    strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0);
+    strstreambuf(const unsigned char* gnext_arg, streamsize n);
+
+    strstreambuf(strstreambuf&& rhs);
+    strstreambuf& operator=(strstreambuf&& rhs);
+
+    virtual ~strstreambuf();
+
+    void swap(strstreambuf& rhs);
+
+    void freeze(bool freezefl = true);
+    char* str();
+    int	pcount() const;
+
+protected:
+    virtual int_type overflow (int_type c = EOF);
+    virtual int_type pbackfail(int_type c = EOF);
+    virtual int_type underflow();
+    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type sp,
+                             ios_base::openmode which = ios_base::in | ios_base::out);
+    virtual streambuf* setbuf(char* s, streamsize n);
+
+private:
+    typedef T1 strstate;                // exposition only
+    static const strstate allocated;    // exposition only
+    static const strstate constant;     // exposition only
+    static const strstate dynamic;      // exposition only
+    static const strstate frozen;       // exposition only
+    strstate strmode;                   // exposition only
+    streamsize alsize;                  // exposition only
+    void* (*palloc)(size_t);            // exposition only
+    void (*pfree)(void*);               // exposition only
+};
+
+class istrstream
+    : public basic_istream<char>
+{
+public:
+    explicit istrstream(const char* s);
+    explicit istrstream(char* s);
+    istrstream(const char* s, streamsize n);
+    istrstream(char* s, streamsize n);
+
+    virtual ~istrstream();
+
+    strstreambuf* rdbuf() const;
+    char *str();
+
+private:
+    strstreambuf sb;	// exposition only
+};
+
+class ostrstream
+    : public basic_ostream<char>
+{
+public:
+    ostrstream();
+    ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
+
+    virtual ~ostrstream();
+
+    strstreambuf* rdbuf() const;
+    void freeze(bool freezefl = true);
+    char* str();
+    int pcount() const;
+
+private:
+    strstreambuf sb;	// exposition only
+};
+
+class strstream
+    : public basic_iostream<char>
+{
+public:
+    // Types
+    typedef char                        char_type;
+    typedef char_traits<char>::int_type int_type;
+    typedef char_traits<char>::pos_type pos_type;
+    typedef char_traits<char>::off_type off_type;
+
+    // constructors/destructor
+    strstream();
+    strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
+
+    virtual ~strstream();
+
+    // Members:
+    strstreambuf* rdbuf() const;
+    void freeze(bool freezefl = true);
+    int pcount() const;
+    char* str();
+
+private:
+    strstreambuf sb;	// exposition only
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <ostream>
+#include <istream>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class strstreambuf
+    : public streambuf
+{
+public:
+    explicit strstreambuf(streamsize __alsize = 0);
+    strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
+    strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0);
+    strstreambuf(const char* __gnext, streamsize __n);
+
+    strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0);
+    strstreambuf(const signed char* __gnext, streamsize __n);
+    strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0);
+    strstreambuf(const unsigned char* __gnext, streamsize __n);
+
+#ifdef _LIBCPP_MOVE
+    strstreambuf(strstreambuf&& __rhs);
+    strstreambuf& operator=(strstreambuf&& __rhs);
+#endif
+
+    virtual ~strstreambuf();
+
+    void swap(strstreambuf& __rhs);
+
+    void freeze(bool __freezefl = true);
+    char* str();
+    int	pcount() const;
+
+protected:
+    virtual int_type overflow (int_type __c = EOF);
+    virtual int_type pbackfail(int_type __c = EOF);
+    virtual int_type underflow();
+    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
+                             ios_base::openmode __which = ios_base::in | ios_base::out);
+    virtual pos_type seekpos(pos_type __sp,
+                             ios_base::openmode __which = ios_base::in | ios_base::out);
+
+private:
+    typedef unsigned __mode_type;
+    static const __mode_type __allocated = 0x01;
+    static const __mode_type __constant  = 0x02;
+    static const __mode_type __dynamic   = 0x04;
+    static const __mode_type __frozen    = 0x08;
+    static const streamsize    __default_alsize = 4096;
+
+    __mode_type __strmode_;
+    streamsize __alsize_;
+    void* (*__palloc_)(size_t);
+    void (*__pfree_)(void*);
+
+    void __init(char* __gnext, streamsize __n, char* __pbeg);
+};
+
+class istrstream
+    : public istream
+{
+public:
+    explicit istrstream(const char* __s)
+        : istream(&__sb_), __sb_(__s, 0) {}
+    explicit istrstream(char* __s)
+        : istream(&__sb_), __sb_(__s, 0) {}
+    istrstream(const char* __s, streamsize __n)
+        : istream(&__sb_), __sb_(__s, __n) {}
+    istrstream(char* __s, streamsize __n)
+        : istream(&__sb_), __sb_(__s, __n) {}
+
+#ifdef _LIBCPP_MOVE
+    istrstream(istrstream&& __rhs)
+        : istream(_STD::move(__rhs)),
+          __sb_(_STD::move(__rhs.__sb_))
+    {
+        istream::set_rdbuf(&__sb_);
+    }
+
+    istrstream& operator=(istrstream&& __rhs)
+    {
+        istream::operator=(_STD::move(__rhs));
+        __sb_ = _STD::move(__rhs.__sb_);
+        return *this;
+    }
+#endif
+
+    virtual ~istrstream();
+
+    void swap(istrstream& __rhs)
+    {
+        istream::swap(__rhs);
+        __sb_.swap(__rhs.__sb_);
+    }
+
+    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
+    char *str() {return __sb_.str();}
+
+private:
+    strstreambuf __sb_;
+};
+
+class ostrstream
+    : public ostream
+{
+public:
+    ostrstream()
+        : ostream(&__sb_) {}
+    ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
+        : ostream(&__sb_),
+          __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
+        {}
+
+#ifdef _LIBCPP_MOVE
+    ostrstream(ostrstream&& __rhs)
+        : ostream(_STD::move(__rhs)),
+          __sb_(_STD::move(__rhs.__sb_))
+    {
+        ostream::set_rdbuf(&__sb_);
+    }
+
+    ostrstream& operator=(ostrstream&& __rhs)
+    {
+        ostream::operator=(_STD::move(__rhs));
+        __sb_ = _STD::move(__rhs.__sb_);
+        return *this;
+    }
+#endif
+
+    virtual ~ostrstream();
+
+    void swap(ostrstream& __rhs)
+    {
+        ostream::swap(__rhs);
+        __sb_.swap(__rhs.__sb_);
+    }
+
+    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
+    void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
+    char* str()         {return __sb_.str();}
+    int pcount() const  {return __sb_.pcount();}
+
+private:
+    strstreambuf __sb_;	// exposition only
+};
+
+class strstream
+    : public iostream
+{
+public:
+    // Types
+    typedef char                        char_type;
+    typedef char_traits<char>::int_type int_type;
+    typedef char_traits<char>::pos_type pos_type;
+    typedef char_traits<char>::off_type off_type;
+
+    // constructors/destructor
+    strstream()
+        : iostream(&__sb_) {}
+    strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
+        : iostream(&__sb_),
+          __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
+        {}
+
+#ifdef _LIBCPP_MOVE
+    strstream(strstream&& __rhs)
+        : iostream(_STD::move(__rhs)),
+          __sb_(_STD::move(__rhs.__sb_))
+    {
+        iostream::set_rdbuf(&__sb_);
+    }
+
+    strstream& operator=(strstream&& __rhs)
+    {
+        iostream::operator=(_STD::move(__rhs));
+        __sb_ = _STD::move(__rhs.__sb_);
+        return *this;
+    }
+#endif
+
+    virtual ~strstream();
+
+    void swap(strstream& __rhs)
+    {
+        iostream::swap(__rhs);
+        __sb_.swap(__rhs.__sb_);
+    }
+
+    // Members:
+    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
+    void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
+    int pcount() const {return __sb_.pcount();}
+    char* str()        {return __sb_.str();}
+
+private:
+    strstreambuf __sb_;	// exposition only
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_STRSTREAM
diff --git a/include/system_error b/include/system_error
new file mode 100644
index 0000000..bc82dd1
--- /dev/null
+++ b/include/system_error
@@ -0,0 +1,607 @@
+// -*- C++ -*-
+//===---------------------------- system_error ----------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SYSTEM_ERROR
+#define _LIBCPP_SYSTEM_ERROR
+
+/*
+    system_error synopsis
+
+namespace std
+{
+
+class error_category
+{
+public:
+    virtual ~error_category();
+
+    error_category(const error_category&) = delete;
+    error_category& operator=(const error_category&) = delete;
+
+    virtual const char* name() const = 0;
+    virtual error_condition default_error_condition(int ev) const;
+    virtual bool equivalent(int code, const error_condition& condition) const;
+    virtual bool equivalent(const error_code& code, int condition) const;
+    virtual string message(int ev) const = 0;
+
+    bool operator==(const error_category& rhs) const;
+    bool operator!=(const error_category& rhs) const;
+    bool operator<(const error_category& rhs) const;
+};
+
+const error_category& generic_category();
+const error_category& system_category();
+
+template <class T> struct is_error_code_enum
+    : public false_type {};
+
+template <class T> struct is_error_condition_enum
+    : public false_type {};
+
+class error_code
+{
+public:
+    // constructors:
+    error_code();
+    error_code(int val, const error_category& cat);
+    template <class ErrorCodeEnum>
+        error_code(ErrorCodeEnum e);
+
+    // modifiers:
+    void assign(int val, const error_category& cat);
+    template <class ErrorCodeEnum>
+        error_code& operator=(ErrorCodeEnum e);
+    void clear();
+
+    // observers:
+    int value() const;
+    const error_category& category() const;
+    error_condition default_error_condition() const;
+    string message() const;
+    explicit operator bool() const;
+};
+
+// non-member functions:
+bool operator<(const error_code& lhs, const error_code& rhs);
+template <class charT, class traits>
+    basic_ostream<charT,traits>&
+    operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
+
+class error_condition
+{
+public:
+    // constructors:
+    error_condition();
+    error_condition(int val, const error_category& cat);
+    template <class ErrorConditionEnum>
+        error_condition(ErrorConditionEnum e);
+
+    // modifiers:
+    void assign(int val, const error_category& cat);
+    template <class ErrorConditionEnum>
+        error_condition& operator=(ErrorConditionEnum e);
+    void clear();
+
+    // observers:
+    int value() const;
+    const error_category& category() const;
+    string message() const;
+    explicit operator bool() const;
+};
+
+bool operator<(const error_condition& lhs, const error_condition& rhs);
+
+class system_error
+    : public runtime_error
+{
+public:
+    system_error(error_code ec, const string& what_arg);
+    system_error(error_code ec, const char* what_arg);
+    system_error(error_code ec);
+    system_error(int ev, const error_category& ecat, const string& what_arg);
+    system_error(int ev, const error_category& ecat, const char* what_arg);
+    system_error(int ev, const error_category& ecat);
+
+    const error_code& code() const throw();
+    const char* what() const throw();
+};
+
+enum class errc
+{
+    address_family_not_supported,       // EAFNOSUPPORT
+    address_in_use,                     // EADDRINUSE
+    address_not_available,              // EADDRNOTAVAIL
+    already_connected,                  // EISCONN
+    argument_list_too_long,             // E2BIG
+    argument_out_of_domain,             // EDOM
+    bad_address,                        // EFAULT
+    bad_file_descriptor,                // EBADF
+    bad_message,                        // EBADMSG
+    broken_pipe,                        // EPIPE
+    connection_aborted,                 // ECONNABORTED
+    connection_already_in_progress,     // EALREADY
+    connection_refused,                 // ECONNREFUSED
+    connection_reset,                   // ECONNRESET
+    cross_device_link,                  // EXDEV
+    destination_address_required,       // EDESTADDRREQ
+    device_or_resource_busy,            // EBUSY
+    directory_not_empty,                // ENOTEMPTY
+    executable_format_error,            // ENOEXEC
+    file_exists,                        // EEXIST
+    file_too_large,                     // EFBIG
+    filename_too_long,                  // ENAMETOOLONG
+    function_not_supported,             // ENOSYS
+    host_unreachable,                   // EHOSTUNREACH
+    identifier_removed,                 // EIDRM
+    illegal_byte_sequence,              // EILSEQ
+    inappropriate_io_control_operation, // ENOTTY
+    interrupted,                        // EINTR
+    invalid_argument,                   // EINVAL
+    invalid_seek,                       // ESPIPE
+    io_error,                           // EIO
+    is_a_directory,                     // EISDIR
+    message_size,                       // EMSGSIZE
+    network_down,                       // ENETDOWN
+    network_reset,                      // ENETRESET
+    network_unreachable,                // ENETUNREACH
+    no_buffer_space,                    // ENOBUFS
+    no_child_process,                   // ECHILD
+    no_link,                            // ENOLINK
+    no_lock_available,                  // ENOLCK
+    no_message_available,               // ENODATA
+    no_message,                         // ENOMSG
+    no_protocol_option,                 // ENOPROTOOPT
+    no_space_on_device,                 // ENOSPC
+    no_stream_resources,                // ENOSR
+    no_such_device_or_address,          // ENXIO
+    no_such_device,                     // ENODEV
+    no_such_file_or_directory,          // ENOENT
+    no_such_process,                    // ESRCH
+    not_a_directory,                    // ENOTDIR
+    not_a_socket,                       // ENOTSOCK
+    not_a_stream,                       // ENOSTR
+    not_connected,                      // ENOTCONN
+    not_enough_memory,                  // ENOMEM
+    not_supported,                      // ENOTSUP
+    operation_canceled,                 // ECANCELED
+    operation_in_progress,              // EINPROGRESS
+    operation_not_permitted,            // EPERM
+    operation_not_supported,            // EOPNOTSUPP
+    operation_would_block,              // EWOULDBLOCK
+    owner_dead,                         // EOWNERDEAD
+    permission_denied,                  // EACCES
+    protocol_error,                     // EPROTO
+    protocol_not_supported,             // EPROTONOSUPPORT
+    read_only_file_system,              // EROFS
+    resource_deadlock_would_occur,      // EDEADLK
+    resource_unavailable_try_again,     // EAGAIN
+    result_out_of_range,                // ERANGE
+    state_not_recoverable,              // ENOTRECOVERABLE
+    stream_timeout,                     // ETIME
+    text_file_busy,                     // ETXTBSY
+    timed_out,                          // ETIMEDOUT
+    too_many_files_open_in_system,      // ENFILE
+    too_many_files_open,                // EMFILE
+    too_many_links,                     // EMLINK
+    too_many_symbolic_link_levels,      // ELOOP
+    value_too_large,                    // EOVERFLOW
+    wrong_protocol_type                 // EPROTOTYPE
+};
+
+template <> struct is_error_condition_enum<errc>
+    : true_type { }
+
+error_code make_error_code(errc e);
+error_condition make_error_condition(errc e);
+
+// Comparison operators:
+bool operator==(const error_code& lhs, const error_code& rhs);
+bool operator==(const error_code& lhs, const error_condition& rhs);
+bool operator==(const error_condition& lhs, const error_code& rhs);
+bool operator==(const error_condition& lhs, const error_condition& rhs);
+bool operator!=(const error_code& lhs, const error_code& rhs);
+bool operator!=(const error_code& lhs, const error_condition& rhs);
+bool operator!=(const error_condition& lhs, const error_code& rhs);
+bool operator!=(const error_condition& lhs, const error_condition& rhs);
+
+template <> struct hash<std::error_code>;
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cerrno>
+#include <type_traits>
+#include <stdexcept>
+#include <__functional_base>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// is_error_code_enum
+
+template <class _Tp> struct is_error_code_enum
+    : public false_type {};
+
+// is_error_condition_enum
+
+template <class _Tp> struct is_error_condition_enum
+    : public false_type {};
+
+//enum class errc
+struct errc
+{
+enum _ {
+    address_family_not_supported        = EAFNOSUPPORT,
+    address_in_use                      = EADDRINUSE,
+    address_not_available               = EADDRNOTAVAIL,
+    already_connected                   = EISCONN,
+    argument_list_too_long              = E2BIG,
+    argument_out_of_domain              = EDOM,
+    bad_address                         = EFAULT,
+    bad_file_descriptor                 = EBADF,
+    bad_message                         = EBADMSG,
+    broken_pipe                         = EPIPE,
+    connection_aborted                  = ECONNABORTED,
+    connection_already_in_progress      = EALREADY,
+    connection_refused                  = ECONNREFUSED,
+    connection_reset                    = ECONNRESET,
+    cross_device_link                   = EXDEV,
+    destination_address_required        = EDESTADDRREQ,
+    device_or_resource_busy             = EBUSY,
+    directory_not_empty                 = ENOTEMPTY,
+    executable_format_error             = ENOEXEC,
+    file_exists                         = EEXIST,
+    file_too_large                      = EFBIG,
+    filename_too_long                   = ENAMETOOLONG,
+    function_not_supported              = ENOSYS,
+    host_unreachable                    = EHOSTUNREACH,
+    identifier_removed                  = EIDRM,
+    illegal_byte_sequence               = EILSEQ,
+    inappropriate_io_control_operation  = ENOTTY,
+    interrupted                         = EINTR,
+    invalid_argument                    = EINVAL,
+    invalid_seek                        = ESPIPE,
+    io_error                            = EIO,
+    is_a_directory                      = EISDIR,
+    message_size                        = EMSGSIZE,
+    network_down                        = ENETDOWN,
+    network_reset                       = ENETRESET,
+    network_unreachable                 = ENETUNREACH,
+    no_buffer_space                     = ENOBUFS,
+    no_child_process                    = ECHILD,
+    no_link                             = ENOLINK,
+    no_lock_available                   = ENOLCK,
+    no_message_available                = ENODATA,
+    no_message                          = ENOMSG,
+    no_protocol_option                  = ENOPROTOOPT,
+    no_space_on_device                  = ENOSPC,
+    no_stream_resources                 = ENOSR,
+    no_such_device_or_address           = ENXIO,
+    no_such_device                      = ENODEV,
+    no_such_file_or_directory           = ENOENT,
+    no_such_process                     = ESRCH,
+    not_a_directory                     = ENOTDIR,
+    not_a_socket                        = ENOTSOCK,
+    not_a_stream                        = ENOSTR,
+    not_connected                       = ENOTCONN,
+    not_enough_memory                   = ENOMEM,
+    not_supported                       = ENOTSUP,
+    operation_canceled                  = ECANCELED,
+    operation_in_progress               = EINPROGRESS,
+    operation_not_permitted             = EPERM,
+    operation_not_supported             = EOPNOTSUPP,
+    operation_would_block               = EWOULDBLOCK,
+    owner_dead                          = EOWNERDEAD,
+    permission_denied                   = EACCES,
+    protocol_error                      = EPROTO,
+    protocol_not_supported              = EPROTONOSUPPORT,
+    read_only_file_system               = EROFS,
+    resource_deadlock_would_occur       = EDEADLK,
+    resource_unavailable_try_again      = EAGAIN,
+    result_out_of_range                 = ERANGE,
+    state_not_recoverable               = ENOTRECOVERABLE,
+    stream_timeout                      = ETIME,
+    text_file_busy                      = ETXTBSY,
+    timed_out                           = ETIMEDOUT,
+    too_many_files_open_in_system       = ENFILE,
+    too_many_files_open                 = EMFILE,
+    too_many_links                      = EMLINK,
+    too_many_symbolic_link_levels       = ELOOP,
+    value_too_large                     = EOVERFLOW,
+    wrong_protocol_type                 = EPROTOTYPE
+};
+
+    _ __v_;
+
+    errc(_ __v) : __v_(__v) {}
+    operator int() const {return __v_;}
+
+};
+
+template <> struct is_error_condition_enum<errc>
+    : true_type { };
+
+template <> struct is_error_condition_enum<errc::_>
+    : true_type { };
+
+class error_condition;
+class error_code;
+
+// class error_category
+
+class __do_message;
+
+class error_category
+{
+public:
+    virtual ~error_category();
+
+private:
+    error_category();
+    error_category(const error_category&);// = delete;
+    error_category& operator=(const error_category&);// = delete;
+
+public:
+    virtual const char* name() const = 0;
+    virtual error_condition default_error_condition(int __ev) const;
+    virtual bool equivalent(int __code, const error_condition& __condition) const;
+    virtual bool equivalent(const error_code& __code, int __condition) const;
+    virtual string message(int __ev) const = 0;
+
+    _LIBCPP_ALWAYS_INLINE
+    bool operator==(const error_category& __rhs) const {return this == &__rhs;}
+
+    _LIBCPP_ALWAYS_INLINE
+    bool operator!=(const error_category& __rhs) const {return !(*this == __rhs);}
+
+    _LIBCPP_ALWAYS_INLINE
+    bool operator< (const error_category& __rhs) const {return this < &__rhs;}
+
+    friend class __do_message;
+};
+
+class _LIBCPP_HIDDEN __do_message
+    : public error_category
+{
+public:
+    virtual string message(int ev) const;
+};
+
+const error_category& generic_category();
+const error_category& system_category();
+
+class error_condition
+{
+    int __val_;
+    const error_category* __cat_;
+public:
+    _LIBCPP_ALWAYS_INLINE
+    error_condition() : __val_(0), __cat_(&generic_category()) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    error_condition(int __val, const error_category& __cat)
+        : __val_(__val), __cat_(&__cat) {}
+
+    template <class _E>
+        _LIBCPP_ALWAYS_INLINE
+        error_condition(_E __e, typename enable_if<is_error_condition_enum<_E>::value>::type* = 0)
+            {*this = make_error_condition(__e);}
+
+    _LIBCPP_ALWAYS_INLINE
+    void assign(int __val, const error_category& __cat)
+    {
+        __val_ = __val;
+        __cat_ = &__cat;
+    }
+
+    template <class _E>
+        _LIBCPP_ALWAYS_INLINE
+        typename enable_if
+        <
+            is_error_condition_enum<_E>::value,
+            error_condition&
+        >::type
+        operator=(_E __e)
+            {*this = make_error_condition(__e); return *this;}
+
+    _LIBCPP_ALWAYS_INLINE
+    void clear()
+    {
+        __val_ = 0;
+        __cat_ = &generic_category();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int value() const {return __val_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    const error_category& category() const {return *__cat_;}
+    string message() const;
+
+    _LIBCPP_ALWAYS_INLINE
+    //explicit
+        operator bool() const {return __val_ != 0;}
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+error_condition
+make_error_condition(errc __e)
+{
+    return error_condition(static_cast<int>(__e), generic_category());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const error_condition& __x, const error_condition& __y)
+{
+    return __x.category() < __y.category()
+        || __x.category() == __y.category() && __x.value() < __y.value();
+}
+
+// error_code
+
+class error_code
+{
+    int __val_;
+    const error_category* __cat_;
+public:
+    _LIBCPP_ALWAYS_INLINE
+    error_code() : __val_(0), __cat_(&system_category()) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    error_code(int __val, const error_category& __cat)
+        : __val_(__val), __cat_(&__cat) {}
+
+    template <class _E>
+        _LIBCPP_ALWAYS_INLINE
+        error_code(_E __e, typename enable_if<is_error_code_enum<_E>::value>::type* = 0)
+            {*this = make_error_code(__e);}
+
+    _LIBCPP_ALWAYS_INLINE
+    void assign(int __val, const error_category& __cat)
+    {
+        __val_ = __val;
+        __cat_ = &__cat;
+    }
+
+    template <class _E>
+        _LIBCPP_ALWAYS_INLINE
+        typename enable_if
+        <
+            is_error_code_enum<_E>::value,
+            error_code&
+        >::type
+        operator=(_E __e)
+            {*this = make_error_code(__e); return *this;}
+
+    _LIBCPP_ALWAYS_INLINE
+    void clear()
+    {
+        __val_ = 0;
+        __cat_ = &system_category();
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    int value() const {return __val_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    const error_category& category() const {return *__cat_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    error_condition default_error_condition() const
+        {return __cat_->default_error_condition(__val_);}
+
+    string message() const;
+
+    _LIBCPP_ALWAYS_INLINE
+    //explicit
+        operator bool() const {return __val_ != 0;}
+};
+
+inline _LIBCPP_INLINE_VISIBILITY
+error_code
+make_error_code(errc __e)
+{
+    return error_code(static_cast<int>(__e), generic_category());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const error_code& __x, const error_code& __y)
+{
+    return __x.category() < __y.category()
+        || __x.category() == __y.category() && __x.value() < __y.value();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const error_code& __x, const error_code& __y)
+{
+    return __x.category() == __y.category() && __x.value() == __y.value();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const error_code& __x, const error_condition& __y)
+{
+    return __x.category().equivalent(__x.value(), __y)
+        || __y.category().equivalent(__x, __y.value());
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const error_condition& __x, const error_code& __y)
+{
+    return __y == __x;
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const error_condition& __x, const error_condition& __y)
+{
+    return __x.category() == __y.category() && __x.value() == __y.value();
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const error_code& __x, const error_code& __y) {return !(__x == __y);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const error_code& __x, const error_condition& __y) {return !(__x == __y);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const error_condition& __x, const error_code& __y) {return !(__x == __y);}
+
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const error_condition& __x, const error_condition& __y) {return !(__x == __y);}
+
+template <>
+struct hash<error_code>
+    : public unary_function<error_code, size_t>
+{
+    size_t operator()(const error_code& __ec) const
+    {
+        return static_cast<size_t>(__ec.value());
+    }
+};
+
+// system_error
+
+class system_error
+    : public runtime_error
+{
+    error_code __ec_;
+public:
+    system_error(error_code __ec, const string& __what_arg);
+    system_error(error_code __ec, const char* __what_arg);
+    system_error(error_code __ec);
+    system_error(int __ev, const error_category& __ecat, const string& __what_arg);
+    system_error(int __ev, const error_category& __ecat, const char* __what_arg);
+    system_error(int __ev, const error_category& __ecat);
+    ~system_error() throw();
+
+    _LIBCPP_ALWAYS_INLINE
+    const error_code& code() const throw() {return __ec_;}
+
+private:
+    static string __init(const error_code&, string);
+};
+
+void __throw_system_error(int ev, const char* what_arg);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_SYSTEM_ERROR
diff --git a/include/tgmath.h b/include/tgmath.h
new file mode 100644
index 0000000..893bca2
--- /dev/null
+++ b/include/tgmath.h
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===-------------------------- tgmath.h ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_TGMATH_H
+#define _LIBCPP_TGMATH_H
+
+/*
+    tgmath.h synopsis
+
+#include <complex.h>
+#include <math.h>
+
+*/
+
+#include <complex.h>
+#include <math.h>
+
+#pragma GCC system_header
+
+#endif  // _LIBCPP_TGMATH_H
diff --git a/include/thread b/include/thread
new file mode 100644
index 0000000..f9ec4e1
--- /dev/null
+++ b/include/thread
@@ -0,0 +1,322 @@
+// -*- C++ -*-
+//===--------------------------- thread -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_THREAD
+#define _LIBCPP_THREAD
+
+/*
+
+    thread synopsis
+
+#define __STDCPP_THREADS __cplusplus
+
+namespace std
+{
+
+class thread
+{
+public:
+    class id;
+    typedef pthread_t native_handle_type;
+
+    thread();
+    template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
+    ~thread();
+
+    thread(const thread&) = delete;
+    thread(thread&& t);
+
+    thread& operator=(const thread&) = delete;
+    thread& operator=(thread&& t);
+
+    void swap(thread& t);
+
+    bool joinable() const;
+    void join();
+    void detach();
+    id get_id() const;
+    native_handle_type native_handle();
+
+    static unsigned hardware_concurrency();
+};
+
+void swap(thread& x, thread& y);
+
+class thread::id
+{
+public:
+    id();
+};
+
+bool operator==(thread::id x, thread::id y);
+bool operator!=(thread::id x, thread::id y);
+bool operator< (thread::id x, thread::id y);
+bool operator<=(thread::id x, thread::id y);
+bool operator> (thread::id x, thread::id y);
+bool operator>=(thread::id x, thread::id y);
+
+template<class charT, class traits>
+basic_ostream<charT, traits>&
+operator<<(basic_ostream<charT, traits>& out, thread::id id);
+
+namespace this_thread
+{
+
+thread::id get_id();
+
+void yield();
+
+template <class Clock, class Duration>
+void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+template <class Rep, class Period>
+void sleep_for(const chrono::duration<Rep, Period>& rel_time);
+
+}  // this_thread
+
+}  // std
+
+*/
+
+#include <__config>
+#include <iosfwd>
+#include <__functional_base>
+#include <type_traits>
+#include <cstddef>
+#include <functional>
+#include <memory>
+#include <system_error>
+#include <chrono>
+#include <__mutex_base>
+#include <pthread.h>
+
+#pragma GCC system_header
+
+#define __STDCPP_THREADS __cplusplus
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class thread;
+class __thread_id;
+
+namespace this_thread
+{
+
+__thread_id get_id();
+
+}  // this_thread
+
+class __thread_id
+{
+    pthread_t __id_;
+
+public:
+    __thread_id() : __id_(0) {}
+
+    friend bool operator==(__thread_id __x, __thread_id __y)
+        {return __x.__id_ == __y.__id_;}
+    friend bool operator!=(__thread_id __x, __thread_id __y)
+        {return !(__x == __y);}
+    friend bool operator< (__thread_id __x, __thread_id __y)
+        {return __x.__id_ < __y.__id_;}
+    friend bool operator<=(__thread_id __x, __thread_id __y)
+        {return !(__y < __x);}
+    friend bool operator> (__thread_id __x, __thread_id __y)
+        {return   __y < __x ;}
+    friend bool operator>=(__thread_id __x, __thread_id __y)
+        {return !(__x < __y);}
+
+    template<class _CharT, class _Traits>
+    friend
+    basic_ostream<_CharT, _Traits>&
+    operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id)
+        {return __os << __id.__id_;}
+
+private:
+    __thread_id(pthread_t __id) : __id_(__id) {}
+
+    friend __thread_id this_thread::get_id();
+    friend class thread;
+};
+
+template<class _Tp> struct hash;
+
+template<>
+struct hash<__thread_id>
+    : public unary_function<__thread_id, size_t>
+{
+    size_t operator()(__thread_id __v) const
+    {
+        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
+        return *__p;
+    }
+};
+
+namespace this_thread
+{
+
+inline
+__thread_id
+get_id()
+{
+    return pthread_self();
+}
+
+}  // this_thread
+
+class thread
+{
+    pthread_t __t_;
+
+#ifndef _LIBCPP_MOVE
+    thread(const thread&); // = delete;
+    thread& operator=(const thread&); // = delete;
+#endif
+public:
+    typedef __thread_id id;
+    typedef pthread_t native_handle_type;
+
+    thread() : __t_(0) {}
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class _F, class ..._Args,
+              class = typename enable_if
+              <
+                   !is_same<typename decay<_F>::type, thread>::value
+              >::type
+             >
+        explicit thread(_F&& __f, _Args&&... __args);
+#else
+    template <class _F> explicit thread(_F __f);
+#endif
+    ~thread();
+
+#ifdef _LIBCPP_MOVE
+    thread(const thread&) = delete;
+    thread(thread&& __t) : __t_(__t.__t_) {__t.__t_ = 0;}
+    thread& operator=(const thread&) = delete;
+    thread& operator=(thread&& __t);
+#endif
+
+    void swap(thread& __t) {_STD::swap(__t_, __t.__t_);}
+
+    bool joinable() const {return __t_ != nullptr;}
+    void join();
+    void detach();
+    id get_id() const {return __t_;}
+    native_handle_type native_handle() {return __t_;}
+
+    static unsigned hardware_concurrency();
+};
+
+template <class _F>
+void*
+__thread_proxy(void* __vp)
+{
+    std::unique_ptr<_F> __p(static_cast<_F*>(__vp));
+    (*__p)();
+    return nullptr;
+}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _F, class ..._Args,
+          class
+         >
+thread::thread(_F&& __f, _Args&&... __args)
+{
+    typedef decltype(bind(std::forward<_F>(__f), std::forward<_Args>(__args)...)) _G;
+    std::unique_ptr<_G> __p(new _G(bind(std::forward<_F>(__f),
+                              std::forward<_Args>(__args)...)));
+    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_G>, __p.get());
+    if (__ec == 0)
+        __p.release();
+    else
+        __throw_system_error(__ec, "thread constructor failed");
+}
+
+#else
+
+template <class _F>
+thread::thread(_F __f)
+{
+    std::unique_ptr<_F> __p(new _F(__f));
+    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_F>, __p.get());
+    if (__ec == 0)
+        __p.release();
+    else
+        __throw_system_error(__ec, "thread constructor failed");
+}
+
+#endif
+
+#ifdef _LIBCPP_MOVE
+
+inline
+thread&
+thread::operator=(thread&& __t)
+{
+    if (__t_ != nullptr)
+        terminate();
+    __t_ = __t.__t_;
+    __t.__t_ = nullptr;
+    return *this;
+}
+
+#endif
+
+inline
+void swap(thread& __x, thread& __y) {__x.swap(__y);}
+
+
+namespace this_thread
+{
+
+void sleep_for(const chrono::nanoseconds& ns);
+
+template <class _Rep, class _Period>
+void
+sleep_for(const chrono::duration<_Rep, _Period>& __d)
+{
+    using namespace chrono;
+    nanoseconds __ns = duration_cast<nanoseconds>(__d);
+    if (__ns < __d)
+        ++__ns;
+    sleep_for(__ns);
+}
+
+template <class _Clock, class _Duration>
+void
+sleep_until(const chrono::time_point<_Clock, _Duration>& __t)
+{
+    using namespace chrono;
+    mutex __mut;
+    condition_variable __cv;
+    unique_lock<mutex> __lk(__mut);
+    while (_Clock::now() < __t)
+        __cv.wait_until(__lk, __t);
+}
+
+template <class _Duration>
+inline
+void
+sleep_until(const chrono::time_point<chrono::monotonic_clock, _Duration>& __t)
+{
+    using namespace chrono;
+    sleep_for(__t - monotonic_clock::now());
+}
+
+inline
+void yield() {sched_yield();}
+
+}  // this_thread
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_THREAD
diff --git a/include/tuple b/include/tuple
new file mode 100644
index 0000000..ad673ec
--- /dev/null
+++ b/include/tuple
@@ -0,0 +1,818 @@
+// -*- C++ -*-
+//===--------------------------- tuple ------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_TUPLE
+#define _LIBCPP_TUPLE
+
+/*
+    tuple synopsis
+
+namespace std
+{
+
+template <class... T>
+class tuple {
+public:
+    constexpr tuple();
+    explicit tuple(const T&...);
+    template <class... U>
+        explicit tuple(U&&...);
+    tuple(const tuple&) = default;
+    tuple(tuple&&);
+    template <class... U>
+        tuple(const tuple<U...>&);
+    template <class... U>
+        tuple(tuple<U...>&&);
+    template <class U1, class U2>
+        tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2
+    template <class U1, class U2>
+        tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2
+
+    // allocator-extended constructors
+    template <class Alloc>
+        tuple(allocator_arg_t, const Alloc& a);
+    template <class Alloc>
+        tuple(allocator_arg_t, const Alloc& a, const T&...);
+    template <class Alloc, class... U>
+        tuple(allocator_arg_t, const Alloc& a, U&&...);
+    template <class Alloc>
+        tuple(allocator_arg_t, const Alloc& a, const tuple&);
+    template <class Alloc>
+        tuple(allocator_arg_t, const Alloc& a, tuple&&);
+    template <class Alloc, class... U>
+        tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
+    template <class Alloc, class... U>
+        tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
+    template <class Alloc, class U1, class U2>
+        tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
+    template <class Alloc, class U1, class U2>
+        tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
+
+    tuple& operator=(const tuple&);
+    tuple& operator=(tuple&&);
+    template <class... U>
+        tuple& operator=(const tuple<U...>&);
+    template <class... U>
+        tuple& operator=(tuple<U...>&&);
+    template <class U1, class U2>
+        tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
+    template <class U1, class U2>
+        tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
+
+    void swap(tuple&);
+};
+
+const unspecified ignore;
+
+template <class... T> tuple<V...>  make_tuple(T&&...);
+template <class... T> tuple<T&...> tie(T&...);
+template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, const tuple<U...>&);
+template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, const tuple<U...>&);
+template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, tuple<U...>&&);
+template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, tuple<U...>&&);
+
+// 20.4.1.4, tuple helper classes:
+template <class T> class tuple_size; // undefined
+template <class... T> class tuple_size<tuple<T...>>;
+template <intsize_t I, class T> class tuple_element; // undefined
+template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
+
+// 20.4.1.5, element access:
+template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& get(tuple<T...>&);
+template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& get(const tuple<T...>&);
+
+// 20.4.1.6, relational operators:
+template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&);
+
+template <class... Types, class Alloc>
+  struct uses_allocator<tuple<Types...>, Alloc>;
+
+template <class... Types>
+  void swap(tuple<Types...>& x, tuple<Types...>& y);
+
+template <class InputIterator>
+  InputIterator begin(const std::tuple<InputIterator, InputIterator>& t);
+
+template <class InputIterator>
+  InputIterator end(const std::tuple<InputIterator, InputIterator>& t);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__tuple>
+#include <cstddef>
+#include <memory>
+#include <type_traits>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+// tuple_size
+
+template <class ..._Tp>
+class tuple_size<tuple<_Tp...>>
+    : public integral_constant<size_t, sizeof...(_Tp)>
+{
+};
+
+template <class ..._Tp>
+class tuple_size<const tuple<_Tp...>>
+    : public integral_constant<size_t, sizeof...(_Tp)>
+{
+};
+
+// tuple_element
+
+template <size_t _Ip, class ..._Tp>
+class tuple_element<_Ip, tuple<_Tp...>>
+{
+public:
+    typedef typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
+};
+
+template <size_t _Ip, class ..._Tp>
+class tuple_element<_Ip, const tuple<_Tp...>>
+{
+public:
+    typedef const typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
+};
+
+// __tuple_leaf
+
+template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value>
+class __tuple_leaf;
+
+template <size_t _Ip, class _Hp, bool _Ep>
+inline
+void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
+{
+    swap(__x.get(), __y.get());
+}
+
+template <size_t _Ip, class _Hp, bool>
+class __tuple_leaf
+{
+    _Hp value;
+
+    __tuple_leaf& operator=(const __tuple_leaf&);
+public:
+    _LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value()
+       {static_assert(!is_reference<_Hp>::value,
+              "Attempted to default construct a reference element in a tuple");}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 0>, const _Alloc&)
+            : value()
+        {static_assert(!is_reference<_Hp>::value,
+              "Attempted to default construct a reference element in a tuple");}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
+            : value(allocator_arg_t(), __a)
+        {static_assert(!is_reference<_Hp>::value,
+              "Attempted to default construct a reference element in a tuple");}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
+            : value(__a)
+        {static_assert(!is_reference<_Hp>::value,
+              "Attempted to default construct a reference element in a tuple");}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(_Tp&& __t)
+            : value(_STD::forward<_Tp>(__t))
+        {static_assert(!is_lvalue_reference<_Hp>::value ||
+                        is_lvalue_reference<_Hp>::value &&
+                        (is_lvalue_reference<_Tp>::value ||
+                         is_same<typename remove_reference<_Tp>::type,
+                                 reference_wrapper<
+                                    typename remove_reference<_Hp>::type
+                                 >
+                                >::value),
+       "Attempted to construct a reference element in a tuple with an rvalue");}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
+            : value(_STD::forward<_Tp>(__t))
+        {static_assert(!is_lvalue_reference<_Hp>::value ||
+                        is_lvalue_reference<_Hp>::value &&
+                        (is_lvalue_reference<_Tp>::value ||
+                         is_same<typename remove_reference<_Tp>::type,
+                                 reference_wrapper<
+                                    typename remove_reference<_Hp>::type
+                                 >
+                                >::value),
+       "Attempted to construct a reference element in a tuple with an rvalue");}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
+            : value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t))
+        {static_assert(!is_lvalue_reference<_Hp>::value ||
+                        is_lvalue_reference<_Hp>::value &&
+                        (is_lvalue_reference<_Tp>::value ||
+                         is_same<typename remove_reference<_Tp>::type,
+                                 reference_wrapper<
+                                    typename remove_reference<_Hp>::type
+                                 >
+                                >::value),
+       "Attempted to construct a reference element in a tuple with an rvalue");}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
+            : value(_STD::forward<_Tp>(__t), __a)
+        {static_assert(!is_lvalue_reference<_Hp>::value ||
+                        is_lvalue_reference<_Hp>::value &&
+                        (is_lvalue_reference<_Tp>::value ||
+                         is_same<typename remove_reference<_Tp>::type,
+                                 reference_wrapper<
+                                    typename remove_reference<_Hp>::type
+                                 >
+                                >::value),
+       "Attempted to construct a reference element in a tuple with an rvalue");}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
+            : value(__t.get()) {}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf&
+        operator=(_Tp&& __t)
+        {
+            value = _STD::forward<_Tp>(__t);
+            return *this;
+        }
+
+    _LIBCPP_INLINE_VISIBILITY
+    int swap(__tuple_leaf& __t)
+    {
+        _STD::swap(*this, __t);
+        return 0;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       {return value;}
+    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;}
+};
+
+template <size_t _Ip, class _Hp>
+class __tuple_leaf<_Ip, _Hp, true>
+    : private _Hp
+{
+
+    __tuple_leaf& operator=(const __tuple_leaf&);
+public:
+    _LIBCPP_INLINE_VISIBILITY __tuple_leaf() {}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
+            : _Hp(allocator_arg_t(), __a) {}
+
+    template <class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
+            : _Hp(__a) {}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(_Tp&& __t)
+            : _Hp(_STD::forward<_Tp>(__t)) {}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
+            : _Hp(_STD::forward<_Tp>(__t)) {}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
+            : _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {}
+
+    template <class _Tp, class _Alloc>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
+            : _Hp(_STD::forward<_Tp>(__t), __a) {}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
+            : _Hp(__t.get()) {}
+
+    template <class _Tp>
+        _LIBCPP_INLINE_VISIBILITY
+        __tuple_leaf&
+        operator=(_Tp&& __t)
+        {
+            _Hp::operator=(_STD::forward<_Tp>(__t));
+            return *this;
+        }
+
+    _LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t)
+    {
+        _STD::swap(*this, __t);
+        return 0;
+    }
+
+    _LIBCPP_INLINE_VISIBILITY       _Hp& get()       {return static_cast<_Hp&>(*this);}
+    _LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);}
+};
+
+template <class ..._Tp> void __swallow(_Tp&&...) {}
+
+// __tuple_impl
+
+template<class _Indx, class ..._Tp> struct __tuple_impl;
+
+template<size_t ..._Indx, class ..._Tp>
+struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
+    : public __tuple_leaf<_Indx, _Tp>...
+{
+    template <size_t ..._Uf, class ..._Tf,
+              size_t ..._Ul, class ..._Tl, class ..._Up>
+        explicit
+        __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
+                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
+                     _Up&&... __u) :
+            __tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))...,
+            __tuple_leaf<_Ul, _Tl>()...
+            {}
+
+    template <class _Alloc, size_t ..._Uf, class ..._Tf,
+              size_t ..._Ul, class ..._Tl, class ..._Up>
+        explicit
+        __tuple_impl(allocator_arg_t, const _Alloc& __a,
+                     __tuple_indices<_Uf...>, __tuple_types<_Tf...>,
+                     __tuple_indices<_Ul...>, __tuple_types<_Tl...>,
+                     _Up&&... __u) :
+            __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
+            _STD::forward<_Up>(__u))...,
+            __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
+            {}
+
+    template <class _Tuple,
+              class = typename enable_if
+                      <
+                         __tuple_convertible<_Tuple, tuple<_Tp...>>::value
+                      >::type
+             >
+        __tuple_impl(_Tuple&& __t)
+            : __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
+            {}
+
+    template <class _Alloc, class _Tuple,
+              class = typename enable_if
+                      <
+                         __tuple_convertible<_Tuple, tuple<_Tp...>>::value
+                      >::type
+             >
+        __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
+            : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>(), __a, 
+                                       _STD::forward<typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
+            {}
+
+    template <class _Tuple>
+        typename enable_if
+        <
+            __tuple_assignable<_Tuple, tuple<_Tp...>>::value,
+            __tuple_impl&
+        >::type
+        operator=(_Tuple&& __t)
+        {
+            __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx,
+                                       typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...);
+            return *this;
+        }
+
+    void swap(__tuple_impl& __t)
+    {
+        __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
+    }
+};
+
+template <class ..._Tp>
+class tuple
+{
+    typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
+
+    base base_;
+
+    template <size_t _Jp, class ..._Up> friend
+        typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&);
+    template <size_t _Jp, class ..._Up> friend
+        const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&);
+public:
+
+    explicit tuple(const _Tp& ... __t)
+        : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
+                typename __make_tuple_indices<0>::type(),
+                typename __make_tuple_types<tuple, 0>::type(),
+                __t...
+               ) {}
+
+    template <class _Alloc>
+      tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
+        : base_(allocator_arg_t(), __a,
+                typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
+                typename __make_tuple_indices<0>::type(),
+                typename __make_tuple_types<tuple, 0>::type(),
+                __t...
+               ) {}
+
+    template <class ..._Up,
+              class = typename enable_if
+                      <
+                         sizeof...(_Up) <= sizeof...(_Tp) &&
+                         __tuple_convertible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value
+                      >::type
+             >
+        explicit
+        tuple(_Up&&... __u)
+            : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
+                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
+                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
+                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
+                    _STD::forward<_Up>(__u)...) {}
+
+    template <class _Alloc, class ..._Up,
+              class = typename enable_if
+                      <
+                         sizeof...(_Up) <= sizeof...(_Tp) &&
+                         __tuple_convertible
+                         <
+                            tuple<_Up...>,
+                            typename __make_tuple_types<tuple,
+                                     sizeof...(_Up) < sizeof...(_Tp) ?
+                                        sizeof...(_Up) :
+                                        sizeof...(_Tp)>::type
+                         >::value
+                      >::type
+             >
+        tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
+            : base_(allocator_arg_t(), __a,
+                    typename __make_tuple_indices<sizeof...(_Up)>::type(),
+                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
+                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
+                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
+                    _STD::forward<_Up>(__u)...) {}
+
+    template <class _Tuple,
+              class = typename enable_if
+                      <
+                         __tuple_convertible<_Tuple, tuple>::value
+                      >::type
+             >
+        tuple(_Tuple&& __t)
+            : base_(_STD::forward<_Tuple>(__t)) {}
+
+    template <class _Alloc, class _Tuple,
+              class = typename enable_if
+                      <
+                         __tuple_convertible<_Tuple, tuple>::value
+                      >::type
+             >
+        tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
+            : base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {}
+
+    template <class _Tuple,
+              class = typename enable_if
+                      <
+                         __tuple_assignable<_Tuple, tuple>::value
+                      >::type
+             >
+        tuple&
+        operator=(_Tuple&& __t)
+        {
+            base_.operator=(_STD::forward<_Tuple>(__t));
+            return *this;
+        }
+
+    void swap(tuple& __t) {base_.swap(__t.base_);}
+};
+
+template <>
+class tuple<>
+{
+public:
+    tuple() {}
+    template <class _Alloc>
+        tuple(allocator_arg_t, const _Alloc&) {}
+    template <class _Alloc>
+        tuple(allocator_arg_t, const _Alloc&, const tuple&) {}
+    template <class _U>
+        tuple(array<_U, 0>) {}
+    template <class _Alloc, class _U>
+        tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {}
+    void swap(tuple&) {}
+};
+
+template <class ..._Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);}
+
+// get
+
+template <size_t _Ip, class ..._Tp>
+inline
+typename tuple_element<_Ip, tuple<_Tp...>>::type&
+get(tuple<_Tp...>& __t)
+{
+    typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
+    return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
+}
+
+template <size_t _Ip, class ..._Tp>
+inline
+const typename tuple_element<_Ip, tuple<_Tp...>>::type&
+get(const tuple<_Tp...>& __t)
+{
+    typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
+    return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
+}
+
+// tie
+
+template <class ..._Tp>
+inline
+tuple<_Tp&...>
+tie(_Tp&... __t)
+{
+    return tuple<_Tp&...>(__t...);
+}
+
+template <class _Up>
+struct __ignore_t
+{
+    __ignore_t() {}
+    template <class _Tp>
+        __ignore_t(_Tp&&) {}
+    template <class _Tp>
+        const __ignore_t& operator=(_Tp&&) const {return *this;}
+};
+
+namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
+
+template <class _Tp> class reference_wrapper;
+
+template <class _Tp>
+struct ___make_tuple_return
+{
+    typedef _Tp type;
+};
+
+template <class _Tp>
+struct ___make_tuple_return<reference_wrapper<_Tp>>
+{
+    typedef _Tp& type;
+};
+
+template <class _Tp>
+struct __make_tuple_return
+{
+    typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
+};
+
+template <class... _Tp>
+inline
+tuple<typename __make_tuple_return<_Tp>::type...>
+make_tuple(_Tp&&... __t)
+{
+    return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...);
+}
+
+template <size_t _I>
+struct __tuple_equal
+{
+    template <class _Tp, class _Up>
+    bool operator()(const _Tp& __x, const _Up& __y)
+    {
+        return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y);
+    }
+};
+
+template <>
+struct __tuple_equal<0>
+{
+    template <class _Tp, class _Up>
+    bool operator()(const _Tp&, const _Up&)
+    {
+        return true;
+    }
+};
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
+}
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return !(__x == __y);
+}
+
+template <size_t _I>
+struct __tuple_less
+{
+    template <class _Tp, class _Up>
+    bool operator()(const _Tp& __x, const _Up& __y)
+    {
+        return __tuple_less<_I-1>()(__x, __y) ||
+             (!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y));
+    }
+};
+
+template <>
+struct __tuple_less<0>
+{
+    template <class _Tp, class _Up>
+    bool operator()(const _Tp&, const _Up&)
+    {
+        return false;
+    }
+};
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return __tuple_less<sizeof...(_Tp)>()(__x, __y);
+}
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return __y < __x;
+}
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class ..._Tp, class ..._Up>
+inline
+bool
+operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return !(__y < __x);
+}
+
+// tuple_cat
+
+template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
+inline
+tuple<_Tp..., _Up...>
+__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
+{
+    return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...);
+}
+
+template <class... _Tp, class... _Up>
+inline
+tuple<_Tp..., _Up...>
+tuple_cat(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
+{
+    return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                       __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
+}
+
+template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
+inline
+tuple<_Tp..., _Up...>
+__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
+{
+    return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...);
+}
+
+template <class... _Tp, class... _Up>
+inline
+tuple<_Tp..., _Up...>
+tuple_cat(tuple<_Tp...>&& __x, const tuple<_Up...>& __y)
+{
+    return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                       __y, typename __make_tuple_indices<sizeof...(_Up)>::type());
+}
+
+template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
+inline
+tuple<_Tp..., _Up...>
+__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
+{
+    return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...);
+}
+
+template <class... _Tp, class... _Up>
+inline
+tuple<_Tp..., _Up...>
+tuple_cat(const tuple<_Tp...>& __x, tuple<_Up...>&& __y)
+{
+    return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                       _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
+}
+
+template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
+inline
+tuple<_Tp..., _Up...>
+__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
+{
+    return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...);
+}
+
+template <class... _Tp, class... _Up>
+inline
+tuple<_Tp..., _Up...>
+tuple_cat(tuple<_Tp...>&& __x, tuple<_Up...>&& __y)
+{
+    return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
+                       _STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
+}
+
+template <class ..._Tp, class _Alloc>
+struct uses_allocator<tuple<_Tp...>, _Alloc>
+    : true_type {};
+
+template <class _InputIterator>
+inline
+_InputIterator
+begin(const std::tuple<_InputIterator, _InputIterator>& __t)
+{
+    return get<0>(__t);
+}
+
+template <class _InputIterator>
+inline
+_InputIterator
+end(const std::tuple<_InputIterator, _InputIterator>& __t)
+{
+    return get<1>(__t);
+}
+
+template <class _T1, class _T2>
+template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_T1, _T2>::pair(piecewise_construct_t,
+                     tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
+                     __tuple_indices<_I1...>, __tuple_indices<_I2...>)
+    :  first(_STD::forward<_Args1>(get<_I1>( __first_args))...),
+      second(_STD::forward<_Args2>(get<_I2>(__second_args))...)
+{
+}
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_TUPLE
diff --git a/include/type_traits b/include/type_traits
new file mode 100644
index 0000000..dd02aa4
--- /dev/null
+++ b/include/type_traits
@@ -0,0 +1,1525 @@
+// -*- C++ -*-
+//===------------------------ type_traits ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_TYPE_TRAITS
+#define _LIBCPP_TYPE_TRAITS
+
+/*
+    type_traits synopsis
+
+namespace std
+{
+
+    // helper class:
+    template <class T, T v> struct integral_constant;
+    typedef integral_constant<bool, true>  true_type;
+    typedef integral_constant<bool, false> false_type;
+
+    // helper traits
+    template <bool, class T = void> struct enable_if;
+    template <bool, class T, class F> struct conditional;
+
+    // Primary classification traits:
+    template <class T> struct is_void;
+    template <class T> struct is_integral;
+    template <class T> struct is_floating_point;
+    template <class T> struct is_array;
+    template <class T> struct is_pointer;
+    template <class T> struct is_lvalue_reference;
+    template <class T> struct is_rvalue_reference;
+    template <class T> struct is_reference;
+    template <class T> struct is_member_object_pointer;
+    template <class T> struct is_member_function_pointer;
+    template <class T> struct is_enum;
+    template <class T> struct is_union;
+    template <class T> struct is_class;
+    template <class T> struct is_function;
+    
+    // Secondary classification traits:
+    template <class T> struct is_reference;
+    template <class T> struct is_arithmetic;
+    template <class T> struct is_fundamental;
+    template <class T> struct is_member_pointer;
+    template <class T> struct is_scalar;
+    template <class T> struct is_object;
+    template <class T> struct is_compound;
+    
+    // Const-volatile properties and transformations:
+    template <class T> struct is_const;
+    template <class T> struct is_volatile;
+    template <class T> struct remove_const;
+    template <class T> struct remove_volatile;
+    template <class T> struct remove_cv;
+    template <class T> struct add_const;
+    template <class T> struct add_volatile;
+    template <class T> struct add_cv;
+    
+    // Reference transformations:
+    template <class T> struct remove_reference;
+    template <class T> struct add_lvalue_reference;
+    template <class T> struct add_rvalue_reference;
+    
+    // Pointer transformations:
+    template <class T> struct remove_pointer;
+    template <class T> struct add_pointer;
+    
+    // Integral properties:
+    template <class T> struct is_signed;
+    template <class T> struct is_unsigned;
+    template <class T> struct make_signed;
+    template <class T> struct make_unsigned;
+    
+    // Array properties and transformations:
+    template <class T> struct rank;
+    template <class T, unsigned I = 0> struct extent;
+    template <class T> struct remove_extent;
+    template <class T> struct remove_all_extents;
+    
+    // Member introspection:
+    template <class T> struct is_pod;
+    template <class T> struct is_trivial;
+    template <class T> struct is_trivially_copyable;
+    template <class T> struct is_standard_layout;
+    template <class T> struct is_literal_type;
+    template <class T> struct is_empty;
+    template <class T> struct is_polymorphic;
+    template <class T> struct is_abstract;
+    template <class T, class... Args> struct is_constructible;
+    template <class T, class... Args> struct is_nothrow_constructible;
+    template <class T> struct has_default_constructor;
+    template <class T> struct has_copy_constructor;
+    template <class T> struct has_move_constructor;
+    template <class T> struct has_copy_assign;
+    template <class T> struct has_move_assign;
+    template <class T> struct has_trivial_default_constructor
+    template <class T> struct has_trivial_copy_constructor;
+    template <class T> struct has_trivial_move_constructor;
+    template <class T> struct has_trivial_copy_assign;
+    template <class T> struct has_trivial_move_assign;
+    template <class T> struct has_trivial_destructor;
+    template <class T> struct has_nothrow_default_constructor;
+    template <class T> struct has_nothrow_copy_constructor;
+    template <class T> struct has_nothrow_move_constructor;
+    template <class T> struct has_nothrow_copy_assign;
+    template <class T> struct has_nothrow_move_assign;
+    template <class T> struct has_virtual_destructor;
+    
+    // Relationships between types:
+    template <class T, class U> struct is_same;
+    template <class Base, class Derived> struct is_base_of;
+    template <class From, class To> struct is_convertible;
+    template <class From, class To> struct is_explicitly_convertible;
+    template <classÊT> struct underlying_type;
+    
+    // Alignment properties and transformations:
+    template <class T> struct alignment_of;
+    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
+        struct aligned_storage;
+    template <std::size_t Len, class... Types> struct aligned_union;
+
+    template <class T> struct decay;
+    template <class... T> struct common_type;
+    template <class T> struct underlying_type;
+    template <class> class result_of; // undefined
+    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
+
+}  // std
+
+*/
+#include <__config>
+#include <cstddef>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <bool _B, class _If, class _Then> struct conditional           {typedef _If type;};
+template <class _If, class _Then> struct conditional<false, _If, _Then> {typedef _Then type;};
+
+template <bool, class _Tp = void> struct enable_if {};
+template <class _Tp> struct enable_if<true, _Tp> {typedef _Tp type;};
+
+struct __two {char _[2];};
+
+// helper class:
+
+template <class _Tp, _Tp __v>
+struct integral_constant
+{
+    static const _Tp          value = __v;
+    typedef _Tp               value_type;
+    typedef integral_constant type;
+};
+
+template <class _Tp, _Tp __v>
+const _Tp integral_constant<_Tp, __v>::value;
+
+typedef integral_constant<bool, true>  true_type;
+typedef integral_constant<bool, false> false_type;
+
+// is_const
+
+template <class _Tp> struct is_const            : public false_type {};
+template <class _Tp> struct is_const<_Tp const> : public true_type {};
+
+// is_volatile
+
+template <class _Tp> struct is_volatile               : public false_type {};
+template <class _Tp> struct is_volatile<_Tp volatile> : public true_type {};
+
+// remove_const
+
+template <class _Tp> struct remove_const            {typedef _Tp type;};
+template <class _Tp> struct remove_const<const _Tp> {typedef _Tp type;};
+
+// remove_volatile
+
+template <class _Tp> struct remove_volatile               {typedef _Tp type;};
+template <class _Tp> struct remove_volatile<volatile _Tp> {typedef _Tp type;};
+
+// remove_cv
+
+template <class _Tp> struct remove_cv
+{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
+
+// is_void
+
+template <class _Tp> struct __is_void       : public false_type {};
+template <>          struct __is_void<void> : public true_type {};
+
+template <class _Tp> struct is_void : public __is_void<typename remove_cv<_Tp>::type> {};
+
+// is_integral
+
+template <class _Tp> struct __is_integral                     : public false_type {};
+template <>          struct __is_integral<bool>               : public true_type {};
+template <>          struct __is_integral<char>               : public true_type {};
+template <>          struct __is_integral<signed char>        : public true_type {};
+template <>          struct __is_integral<unsigned char>      : public true_type {};
+template <>          struct __is_integral<wchar_t>            : public true_type {};
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+template <>          struct __is_integral<char16_t>           : public true_type {};
+template <>          struct __is_integral<char32_t>           : public true_type {};
+#endif
+template <>          struct __is_integral<short>              : public true_type {};
+template <>          struct __is_integral<unsigned short>     : public true_type {};
+template <>          struct __is_integral<int>                : public true_type {};
+template <>          struct __is_integral<unsigned int>       : public true_type {};
+template <>          struct __is_integral<long>               : public true_type {};
+template <>          struct __is_integral<unsigned long>      : public true_type {};
+template <>          struct __is_integral<long long>          : public true_type {};
+template <>          struct __is_integral<unsigned long long> : public true_type {};
+
+template <class _Tp> struct is_integral : public __is_integral<typename remove_cv<_Tp>::type> {};
+
+// is_floating_point
+
+template <class _Tp> struct __is_floating_point              : public false_type {};
+template <>          struct __is_floating_point<float>       : public true_type {};
+template <>          struct __is_floating_point<double>      : public true_type {};
+template <>          struct __is_floating_point<long double> : public true_type {};
+
+template <class _Tp> struct is_floating_point : public __is_floating_point<typename remove_cv<_Tp>::type> {};
+
+// is_array
+
+template <class _Tp> struct            is_array            : public false_type {};
+template <class _Tp> struct            is_array<_Tp[]>     : public true_type {};
+template <class _Tp, size_t _Np> struct is_array<_Tp[_Np]> : public true_type {};
+
+// is_pointer
+
+template <class _Tp> struct __is_pointer       : public false_type {};
+template <class _Tp> struct __is_pointer<_Tp*> : public true_type {};
+
+template <class _Tp> struct is_pointer : public __is_pointer<typename remove_cv<_Tp>::type> {};
+
+// is_reference
+
+template <class _Tp> struct is_lvalue_reference       : public false_type {};
+template <class _Tp> struct is_lvalue_reference<_Tp&> : public true_type {};
+
+template <class _Tp> struct is_rvalue_reference        : public false_type {};
+#ifdef _LIBCPP_MOVE
+template <class _Tp> struct is_rvalue_reference<_Tp&&> : public true_type {};
+#endif
+
+template <class _Tp> struct is_reference        : public false_type {};
+template <class _Tp> struct is_reference<_Tp&>  : public true_type {};
+#ifdef _LIBCPP_MOVE
+template <class _Tp> struct is_reference<_Tp&&> : public true_type {};
+#endif
+
+// is_union
+
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
+
+template <class _Tp> struct is_union : public integral_constant<bool, __is_union(_Tp)> {};
+
+#else
+
+template <class _Tp> struct __libcpp_union : public false_type {};
+template <class _Tp> struct is_union : public __libcpp_union<typename remove_cv<_Tp>::type> {};
+
+#endif
+
+// is_class
+
+namespace __is_class_imp
+{
+template <class _Tp> char  __test(int _Tp::*);
+template <class _Tp> __two __test(...);
+}
+
+template <class _Tp> struct is_class
+    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
+
+// is_function
+
+namespace __is_function_imp
+{
+template <class _Tp> char  __test(_Tp*);
+template <class _Tp> __two __test(...);
+template <class _Tp> _Tp&  __source();
+}
+
+template <class _Tp, bool = is_class<_Tp>::value ||
+                            is_union<_Tp>::value ||
+                            is_void<_Tp>::value  ||
+                            is_reference<_Tp>::value>
+struct __is_function
+    : public integral_constant<bool, sizeof(__is_function_imp::__test<_Tp>(__is_function_imp::__source<_Tp>())) == 1>
+    {};
+template <class _Tp> struct __is_function<_Tp, true> : public false_type {};
+
+template <class _Tp> struct is_function : public __is_function<_Tp> {};
+
+// is_member_function_pointer
+
+template <class _Tp> struct            __is_member_function_pointer             : public false_type {};
+template <class _Tp, class _Up> struct __is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
+
+template <class _Tp> struct is_member_function_pointer
+    : public __is_member_function_pointer<typename remove_cv<_Tp>::type> {};
+
+// is_member_pointer
+
+template <class _Tp>            struct __is_member_pointer             : public false_type {};
+template <class _Tp, class _Up> struct __is_member_pointer<_Tp _Up::*> : public true_type {};
+
+template <class _Tp> struct is_member_pointer
+    : public __is_member_pointer<typename remove_cv<_Tp>::type> {};
+
+// is_member_object_pointer
+
+template <class _Tp> struct is_member_object_pointer
+    : public integral_constant<bool, is_member_pointer<_Tp>::value &&
+                                    !is_member_function_pointer<_Tp>::value> {};
+
+// is_enum
+
+template <class _Tp> struct is_enum
+    : public integral_constant<bool, !is_void<_Tp>::value             &&
+                                     !is_integral<_Tp>::value         &&
+                                     !is_floating_point<_Tp>::value   &&
+                                     !is_array<_Tp>::value            &&
+                                     !is_pointer<_Tp>::value          &&
+                                     !is_reference<_Tp>::value        &&
+                                     !is_member_pointer<_Tp>::value   &&
+                                     !is_union<_Tp>::value            &&
+                                     !is_class<_Tp>::value            &&
+                                     !is_function<_Tp>::value         > {};
+
+// is_arithmetic
+
+template <class _Tp> struct is_arithmetic
+    : public integral_constant<bool, is_integral<_Tp>::value      ||
+                                     is_floating_point<_Tp>::value> {};
+
+// is_fundamental
+
+template <class _Tp> struct is_fundamental
+    : public integral_constant<bool, is_void<_Tp>::value      ||
+                                     is_arithmetic<_Tp>::value> {};
+
+// is_scalar
+
+template <class _Tp> struct is_scalar
+    : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
+                                     is_member_pointer<_Tp>::value ||
+                                     is_pointer<_Tp>::value        ||
+                                     is_enum<_Tp>::value           > {};
+
+// is_object
+
+template <class _Tp> struct is_object
+    : public integral_constant<bool, is_scalar<_Tp>::value ||
+                                     is_array<_Tp>::value  ||
+                                     is_union<_Tp>::value  ||
+                                     is_class<_Tp>::value  > {};
+
+// is_compound
+
+template <class _Tp> struct is_compound : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
+
+// add_const
+
+template <class _Tp, bool = is_reference<_Tp>::value ||
+                            is_function<_Tp>::value  ||
+                            is_const<_Tp>::value     >
+struct __add_const             {typedef _Tp type;};
+
+template <class _Tp>
+struct __add_const<_Tp, false> {typedef const _Tp type;};
+
+template <class _Tp> struct add_const {typedef typename __add_const<_Tp>::type type;};
+
+// add_volatile
+
+template <class _Tp, bool = is_reference<_Tp>::value ||
+                            is_function<_Tp>::value  ||
+                            is_volatile<_Tp>::value  >
+struct __add_volatile             {typedef _Tp type;};
+
+template <class _Tp>
+struct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
+
+template <class _Tp> struct add_volatile {typedef typename __add_volatile<_Tp>::type type;};
+
+// add_cv
+
+template <class T> struct add_cv {typedef typename add_const<typename add_volatile<T>::type>::type type;};
+
+// remove_reference
+
+template <class _Tp> struct remove_reference        {typedef _Tp type;};
+template <class _Tp> struct remove_reference<_Tp&>  {typedef _Tp type;};
+#ifdef _LIBCPP_MOVE
+template <class _Tp> struct remove_reference<_Tp&&> {typedef _Tp type;};
+#endif
+
+// add_lvalue_reference
+
+template <class _Tp> struct add_lvalue_reference                      {typedef _Tp& type;};
+template <class _Tp> struct add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
+template <>          struct add_lvalue_reference<void>                {typedef void type;};
+template <>          struct add_lvalue_reference<const void>          {typedef const void type;};
+template <>          struct add_lvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct add_lvalue_reference<const volatile void> {typedef const volatile void type;};
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp> struct add_rvalue_reference                      {typedef _Tp&& type;};
+template <>          struct add_rvalue_reference<void>                {typedef void type;};
+template <>          struct add_rvalue_reference<const void>          {typedef const void type;};
+template <>          struct add_rvalue_reference<volatile void>       {typedef volatile void type;};
+template <>          struct add_rvalue_reference<const volatile void> {typedef const volatile void type;};
+
+#endif
+
+// remove_pointer
+
+template <class _Tp> struct remove_pointer                      {typedef _Tp type;};
+template <class _Tp> struct remove_pointer<_Tp*>                {typedef _Tp type;};
+template <class _Tp> struct remove_pointer<_Tp* const>          {typedef _Tp type;};
+template <class _Tp> struct remove_pointer<_Tp* volatile>       {typedef _Tp type;};
+template <class _Tp> struct remove_pointer<_Tp* const volatile> {typedef _Tp type;};
+
+// add_pointer
+
+template <class _Tp> struct add_pointer {typedef typename remove_reference<_Tp>::type* type;};
+
+// is_signed
+
+template <class _Tp, bool = is_integral<_Tp>::value>
+struct ___is_signed : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
+
+template <class _Tp>
+struct ___is_signed<_Tp, false> : public true_type {};  // floating point
+
+template <class _Tp, bool = is_arithmetic<_Tp>::value>
+struct __is_signed : public ___is_signed<_Tp> {};
+
+template <class _Tp> struct __is_signed<_Tp, false> : public false_type {};
+
+template <class _Tp> struct is_signed : public __is_signed<_Tp> {};
+
+// is_unsigned
+
+template <class _Tp, bool = is_integral<_Tp>::value>
+struct ___is_unsigned : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
+
+template <class _Tp>
+struct ___is_unsigned<_Tp, false> : public false_type {};  // floating point
+
+template <class _Tp, bool = is_arithmetic<_Tp>::value>
+struct __is_unsigned : public ___is_unsigned<_Tp> {};
+
+template <class _Tp> struct __is_unsigned<_Tp, false> : public false_type {};
+
+template <class _Tp> struct is_unsigned : public __is_unsigned<_Tp> {};
+
+// rank
+
+template <class _Tp> struct rank                       : public integral_constant<size_t, 0> {};
+template <class _Tp> struct rank<_Tp[]>                : public integral_constant<size_t, rank<_Tp>::value + 1> {};
+template <class _Tp, size_t _Np> struct rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
+
+// extent
+
+template <class _Tp, unsigned _Ip = 0>         struct extent                : public integral_constant<size_t, 0> {};
+template <class _Tp>                           struct extent<_Tp[], 0>      : public integral_constant<size_t, 0> {};
+template <class _Tp, unsigned _Ip>             struct extent<_Tp[], _Ip>    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
+template <class _Tp, size_t _Np>               struct extent<_Tp[_Np], 0>   : public integral_constant<size_t, _Np> {};
+template <class _Tp, size_t _Np, unsigned _Ip> struct extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
+
+// remove_extent
+
+template <class _Tp>             struct remove_extent           {typedef _Tp type;};
+template <class _Tp>             struct remove_extent<_Tp[]>    {typedef _Tp type;};
+template <class _Tp, size_t _Np> struct remove_extent<_Tp[_Np]> {typedef _Tp type;};
+
+// remove_all_extents
+
+template <class _Tp>             struct remove_all_extents           {typedef _Tp type;};
+template <class _Tp>             struct remove_all_extents<_Tp[]>    {typedef typename remove_all_extents<_Tp>::type type;};
+template <class _Tp, size_t _Np> struct remove_all_extents<_Tp[_Np]> {typedef typename remove_all_extents<_Tp>::type type;};
+
+// is_same
+
+template <class _Tp, class _Up> struct is_same           : public false_type {};
+template <class _Tp>            struct is_same<_Tp, _Tp> : public true_type {};
+
+// is_abstract
+
+namespace __is_abstract_imp
+{
+template <class _Tp> char  __test(_Tp (*)[1]);
+template <class _Tp> __two __test(...);
+}
+
+template <class _Tp, bool = is_class<_Tp>::value>
+struct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
+
+template <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
+
+template <class _Tp> struct is_abstract : public __libcpp_abstract<_Tp> {};
+
+// is_convertible
+
+namespace __is_convertible_imp
+{
+#ifdef _LIBCPP_MOVE
+template <class _Tp> char  __test(const volatile typename remove_reference<_Tp>::type&&);
+#else
+template <class _Tp> char  __test(_Tp);
+#endif
+template <class _Tp> __two __test(...);
+#ifdef _LIBCPP_MOVE
+template <class _Tp> _Tp&& __source();
+#else
+template <class _Tp> typename remove_reference<_Tp>::type& __source();
+#endif
+
+template <class _Tp, bool _IsArray =    is_array<_Tp>::value,
+                     bool _IsFunction = is_function<_Tp>::value,
+                     bool _IsVoid =     is_void<_Tp>::value>
+                     struct __is_array_function_or_void                          {enum {value = 0};};
+template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
+template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
+template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
+}
+
+template <class _Tp,
+    unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
+struct __is_convertible_check
+{
+    static const size_t __v = 0;
+};
+
+template <class _Tp>
+struct __is_convertible_check<_Tp, 0>
+{
+    static const size_t __v = sizeof(_Tp);
+};
+
+template <class _T1, class _T2,
+    unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
+    unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
+struct __is_convertible
+    : public integral_constant<bool,
+        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
+    >
+{};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
+
+template <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
+#ifdef _LIBCPP_MOVE
+template <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
+template <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
+#endif
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
+    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
+
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
+#ifdef _LIBCPP_MOVE
+template <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
+#endif
+template <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
+template <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
+
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
+template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
+
+template <class _T1, class _T2> struct is_convertible : public __is_convertible<_T1, _T2>
+{
+    static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
+    static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
+};
+
+// is_base_of
+
+//  (C) Copyright Rani Sharoni 2003.
+//  Use, modification and distribution are subject to the Boost Software License,
+//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+//  http://www.boost.org/LICENSE_1_0.txt).
+//
+//  See http://www.boost.org/libs/type_traits for most recent version including documentation.
+
+template <class _Bp, class _Dp>
+struct __is_base_of_tests
+{
+    template <class _Tp>
+    static char  __test(const volatile _Dp*, _Tp);
+    static __two __test(const volatile _Bp*, int);
+};
+
+template <class _Bp, class _Dp>
+struct __is_base_of_imp
+{
+    struct __host
+    {
+        operator const volatile _Bp*() const;
+        operator const volatile _Dp*();
+    };
+
+    static const size_t __complete_check = sizeof(_Dp);
+    static const bool value = sizeof(__is_base_of_tests<_Bp, _Dp>::__test(__host(), 0)) == 1;
+};
+
+template <class _Bp, class _Dp, bool = is_class<_Bp>::value,
+                                bool = is_class<_Dp>::value,
+                                bool = is_same<_Bp, _Dp>::value>
+struct __libcpp_base_of : public false_type {};
+
+template <class _Bp, class _Dp>
+struct __libcpp_base_of<_Bp, _Dp, true, true, true> : public true_type {};
+
+template <class _Bp, class _Dp>
+struct __libcpp_base_of<_Bp, _Dp, true, true, false>
+    : public integral_constant<bool, __is_base_of_imp<_Bp, _Dp>::value> {};
+
+template <class _Bp, class _Dp>
+struct is_base_of
+    : public __libcpp_base_of<typename remove_cv<_Bp>::type, typename remove_cv<_Dp>::type>
+{
+};
+
+// is_empty
+
+template <class _Tp>
+struct __is_empty1
+    : public _Tp
+{
+    double _;
+};
+
+struct __is_empty2
+{
+    double _;
+};
+
+template <class _Tp, bool = is_class<_Tp>::value>
+struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
+
+template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
+
+template <class _Tp> struct is_empty : public __libcpp_empty<_Tp> {};
+
+// is_polymorphic
+
+template <class _Tp> struct __is_polymorphic1 : public _Tp {};
+template <class _Tp> struct __is_polymorphic2 : public _Tp {virtual ~__is_polymorphic2() throw();};
+
+template <class _Tp, bool = is_class<_Tp>::value>
+struct __libcpp_polymorphic
+    : public integral_constant<bool, sizeof(__is_polymorphic1<_Tp>) == sizeof(__is_polymorphic2<_Tp>)> {};
+
+template <class _Tp> struct __libcpp_polymorphic<_Tp, false> : public false_type {};
+
+template <class _Tp> struct is_polymorphic : public __libcpp_polymorphic<_Tp> {};
+
+// has_trivial_default_constructor
+
+template <class _Tp> struct __has_trivial_default_constructor : public integral_constant<bool, is_scalar<_Tp>::value> {};
+
+template <class _Tp> struct has_trivial_default_constructor
+    : public __has_trivial_default_constructor<typename remove_all_extents<_Tp>::type> {};
+
+// has_nothrow_default_constructor
+
+template <class _Tp> struct has_nothrow_default_constructor : public has_trivial_default_constructor<_Tp> {};
+
+// has_trivial_copy_constructor
+
+template <class _Tp> struct __has_trivial_copy_constructor : public integral_constant<bool, is_scalar<_Tp>::value ||
+                                                                                is_reference<_Tp>::value> {};
+
+template <class _Tp> struct has_trivial_copy_constructor
+    : public __has_trivial_copy_constructor<typename remove_all_extents<_Tp>::type> {};
+
+// has_nothrow_copy_constructor
+
+template <class _Tp> struct has_nothrow_copy_constructor : public has_trivial_copy_constructor<_Tp> {};
+
+// has_nothrow_move_constructor
+
+template <class _Tp> struct has_nothrow_move_constructor : public has_nothrow_copy_constructor<_Tp> {};
+
+// has_copy_constructor
+
+template <class _Tp> struct has_copy_constructor : public true_type {};
+
+// has_trivial_copy_assign
+
+template <class _Tp> struct __libcpp_trivial_copy_assign : public integral_constant<bool, !is_const<_Tp>::value &&
+                                                                                   is_scalar<_Tp>::value> {};
+
+template <class _Tp> struct has_trivial_copy_assign
+    : public __libcpp_trivial_copy_assign<typename remove_all_extents<_Tp>::type> {};
+
+// has_nothrow_copy_assign
+
+template <class _Tp> struct has_nothrow_copy_assign: public has_trivial_copy_assign<_Tp> {};
+
+// has_trivial_destructor
+
+template <class _Tp> struct __libcpp_trivial_destructor : public integral_constant<bool, is_scalar<_Tp>::value ||
+                                                                                      is_reference<_Tp>::value> {};
+
+template <class _Tp> struct has_trivial_destructor
+    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
+
+// has_virtual_destructor
+
+template <class _Tp> struct has_virtual_destructor : public false_type {};
+
+// is_pod
+
+template <class _Tp> struct is_pod : public integral_constant<bool, has_trivial_default_constructor<_Tp>::value   &&
+                                                                    has_trivial_copy_constructor<_Tp>::value      &&
+                                                                    has_trivial_copy_assign<_Tp>::value    &&
+                                                                    has_trivial_destructor<_Tp>::value> {};
+
+// alignment_of
+
+template <class _Tp> struct __alignment_of {_Tp _;};
+
+template <class _Tp> struct alignment_of
+    : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};
+
+// aligned_storage
+
+template <class _Hp, class _Tp>
+struct __type_list
+{
+    typedef _Hp _Head;
+    typedef _Tp _Tail;
+};
+
+struct __nat {};
+
+template <class _Tp>
+struct __align_type
+{
+    static const size_t value = alignment_of<_Tp>::value;
+    typedef _Tp type;
+};
+
+struct __struct_double {long double _;};
+struct __struct_double4 {double _[4];};
+
+typedef
+    __type_list<__align_type<unsigned char>,
+    __type_list<__align_type<unsigned short>,
+    __type_list<__align_type<unsigned int>,
+    __type_list<__align_type<unsigned long>,
+    __type_list<__align_type<unsigned long long>,
+    __type_list<__align_type<double>,
+    __type_list<__align_type<long double>,
+    __type_list<__align_type<__struct_double>,
+    __type_list<__align_type<__struct_double4>,
+    __type_list<__align_type<int*>,
+    __nat
+    > > > > > > > > > > __all_types;
+
+template <class _TL, size_t _Align> struct __find_pod;
+
+template <class _Hp, size_t _Align>
+struct __find_pod<__type_list<_Hp, __nat>, _Align>
+{
+    typedef typename conditional<
+                             _Align == _Hp::value,
+                             typename _Hp::type,
+                             void
+                         >::type type;
+};
+
+template <class _Hp, class _Tp, size_t _Align>
+struct __find_pod<__type_list<_Hp, _Tp>, _Align>
+{
+    typedef typename conditional<
+                             _Align == _Hp::value,
+                             typename _Hp::type,
+                             typename __find_pod<_Tp, _Align>::type
+                         >::type type;
+};
+
+template <class _TL, size_t _Len> struct __find_max_align;
+
+template <class _Hp, size_t _Len>
+struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
+
+template <size_t _Len, size_t _A1, size_t _A2>
+struct __select_align
+{
+private:
+    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
+    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
+public:
+    static const size_t value = _Len < __max ? __min : __max;
+};
+
+template <class _Hp, class _Tp, size_t _Len>
+struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
+    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
+
+template <size_t _Len, const size_t _Align = __find_max_align<__all_types, _Len>::value>
+struct aligned_storage
+{
+    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
+    static_assert(!is_void<_Aligner>::value, "");
+    union type
+    {
+        _Aligner __align;
+        unsigned char __data[_Len];
+    };
+};
+
+#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
+template <size_t _Len>\
+struct aligned_storage<_Len, n>\
+{\
+    struct type\
+    {\
+        unsigned char _[_Len];\
+    } __attribute__((__aligned__(n)));\
+}
+
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
+_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
+
+#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
+
+// __promote
+
+template <class _A1, class _A2 = void, class _A3 = void,
+          bool = (is_arithmetic<_A1>::value || is_void<_A1>::value) &&
+                 (is_arithmetic<_A2>::value || is_void<_A2>::value) &&
+                 (is_arithmetic<_A3>::value || is_void<_A3>::value)>
+class __promote {};
+
+
+template <class _A1, class _A2, class _A3>
+class __promote<_A1, _A2, _A3, true>
+{
+private:
+    typedef typename __promote<_A1>::type __type1;
+    typedef typename __promote<_A2>::type __type2;
+    typedef typename __promote<_A3>::type __type3;
+public:
+    typedef __typeof__(__type1() + __type2() + __type3()) type;
+};
+
+template <class _A1, class _A2>
+class __promote<_A1, _A2, void, true>
+{
+private:
+    typedef typename __promote<_A1>::type __type1;
+    typedef typename __promote<_A2>::type __type2;
+public:
+    typedef __typeof__(__type1() + __type2()) type;
+};
+
+template <class _A1>
+class __promote<_A1, void, void, true>
+{
+public:
+    typedef typename conditional<is_arithmetic<_A1>::value,
+                     typename conditional<is_integral<_A1>::value, double, _A1>::type,
+                     void
+            >::type type;
+};
+
+#ifdef _LIBCPP_STORE_AS_OPTIMIZATION
+
+// __transform
+
+template <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
+template <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
+template <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
+template <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
+template <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
+
+#endif  // _LIBCPP_STORE_AS_OPTIMIZATION
+
+// make_signed / make_unsigned
+
+typedef
+    __type_list<signed char,
+    __type_list<signed short,
+    __type_list<signed int,
+    __type_list<signed long,
+    __type_list<signed long long,
+    __nat
+    > > > > > __signed_types;
+
+typedef
+    __type_list<unsigned char,
+    __type_list<unsigned short,
+    __type_list<unsigned int,
+    __type_list<unsigned long,
+    __type_list<unsigned long long,
+    __nat
+    > > > > > __unsigned_types;
+
+template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
+
+template <class _Hp, class _Tp, size_t _Size>
+struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
+{
+    typedef _Hp type;
+};
+
+template <class _Hp, class _Tp, size_t _Size>
+struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
+{
+    typedef typename __find_first<_Tp, _Size>::type type;
+};
+
+template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
+                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
+struct __apply_cv
+{
+    typedef _Up type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp, _Up, true, false>
+{
+    typedef const _Up type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp, _Up, false, true>
+{
+    typedef volatile _Up type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp, _Up, true, true>
+{
+    typedef const volatile _Up type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp&, _Up, false, false>
+{
+    typedef _Up& type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp&, _Up, true, false>
+{
+    typedef const _Up& type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp&, _Up, false, true>
+{
+    typedef volatile _Up& type;
+};
+
+template <class _Tp, class _Up>
+struct __apply_cv<_Tp&, _Up, true, true>
+{
+    typedef const volatile _Up& type;
+};
+
+template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
+struct __make_signed {};
+
+template <class _Tp>
+struct __make_signed<_Tp, true>
+{
+    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
+};
+
+template <> struct __make_signed<bool,               true> {};
+template <> struct __make_signed<  signed short,     true> {typedef short     type;};
+template <> struct __make_signed<unsigned short,     true> {typedef short     type;};
+template <> struct __make_signed<  signed int,       true> {typedef int       type;};
+template <> struct __make_signed<unsigned int,       true> {typedef int       type;};
+template <> struct __make_signed<  signed long,      true> {typedef long      type;};
+template <> struct __make_signed<unsigned long,      true> {typedef long      type;};
+template <> struct __make_signed<  signed long long, true> {typedef long long type;};
+template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
+
+template <class _Tp>
+struct make_signed
+{
+    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
+};
+
+template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
+struct __make_unsigned {};
+
+template <class _Tp>
+struct __make_unsigned<_Tp, true>
+{
+    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
+};
+
+template <> struct __make_unsigned<bool,               true> {};
+template <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
+template <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
+template <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
+template <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
+template <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
+template <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
+template <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
+template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
+
+template <class _Tp>
+struct make_unsigned
+{
+    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
+};
+
+#ifdef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Tp, class _Up = void, class V = void>
+struct common_type
+{
+public:
+    typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
+};
+
+
+template <class _Tp>
+struct common_type<_Tp, void, void>
+{
+public:
+    typedef _Tp type;
+};
+
+template <class _Tp, class _Up>
+struct common_type<_Tp, _Up, void>
+{
+private:
+#ifdef _LIBCPP_MOVE
+    static _Tp&& __t();
+    static _Up&& __u();
+#else
+    static _Tp __t();
+    static _Up __u();
+    static bool __f();
+#endif
+public:
+    typedef __typeof__(__f() ? __t() : __u()) type;
+};
+
+#else
+
+template <class ..._Tp> struct common_type;
+
+template <class _Tp>
+struct common_type<_Tp>
+{
+    typedef _Tp type;
+};
+
+template <class _Tp, class _Up>
+struct common_type<_Tp, _Up>
+{
+private:
+    static _Tp&& __t();
+    static _Up&& __u();
+    static bool __f();
+public:
+    typedef decltype(__f() ? __t() : __u()) type;
+};
+
+template <class _Tp, class _Up, class ..._Vp>
+struct common_type<_Tp, _Up, _Vp...>
+{
+    typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
+};
+
+#endif
+
+// move
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename remove_reference<_Tp>::type&&
+move(_Tp&& __t) {return __t;}
+
+template <class _Tp, class _Up,
+    class = typename _STD::enable_if<
+         is_lvalue_reference<_Tp>::value ? is_lvalue_reference<_Up>::value : true
+                     >::type,
+    class = typename _STD::enable_if<
+         is_convertible<typename remove_reference<_Up>::type*,
+                        typename remove_reference<_Tp>::type*>::value>::type>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp&&
+forward(_Up&& __t)
+{
+    return __t;  // to quiet spurious warning
+//    return static_cast<_Tp&&>(__t);
+}
+
+#else  // _LIBCPP_MOVE
+
+template <class T>
+class __rv
+{
+    typedef typename remove_reference<T>::type Trr;
+    Trr& t_;
+public:
+    Trr* operator->() {return &t_;}
+    explicit __rv(Trr& t) : t_(t) {}
+};
+
+template <class T>
+inline
+typename enable_if
+<
+    !is_convertible<T, __rv<T> >::value,
+    T&
+>::type
+move(T& t)
+{
+    return t;
+}
+
+template <class T>
+inline
+typename enable_if
+<
+    is_convertible<T, __rv<T> >::value,
+    T
+>::type
+move(T& t)
+{
+    return T(__rv<T>(t));
+}
+
+template <class T, class U>
+inline
+typename enable_if
+<
+    !is_convertible<T, __rv<T> >::value,
+    typename add_lvalue_reference<T>::type
+>::type
+forward(U& t)
+{
+    return t;
+}
+
+template <class T, class U>
+inline
+typename enable_if
+<
+    !is_convertible<T, __rv<T> >::value,
+    typename add_lvalue_reference<T>::type
+>::type
+forward(const U& t)
+{
+    return t;
+}
+
+template <class T, class U>
+inline
+typename enable_if
+<
+    is_convertible<T, __rv<T> >::value,
+    T
+>::type
+forward(U& t)
+{
+    return T(__rv<T>(t));
+}
+
+template <class T, class U>
+inline
+typename enable_if
+<
+    is_convertible<T, __rv<T> >::value,
+    T
+>::type
+forward(const U& t)
+{
+    return T(__rv<T>(t));
+}
+
+#endif  // _LIBCPP_MOVE
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+typename add_rvalue_reference<_Tp>::type
+declval();
+
+#else
+
+template <class _Tp>
+typename add_lvalue_reference<_Tp>::type
+declval();
+
+#endif
+
+template <class _Tp>
+struct decay
+{
+private:
+    typedef typename remove_reference<_Tp>::type _Up;
+public:
+    typedef typename conditional
+                     <
+                         is_array<_Up>::value,
+                         typename remove_extent<_Up>::type*,
+                         typename conditional
+                         <
+                              is_function<_Up>::value,
+                              typename add_pointer<_Up>::type,
+                              typename remove_cv<_Up>::type
+                         >::type
+                     >::type type;
+};
+
+// result_of
+
+template <class> class result_of;
+
+template <class _Fn, bool>
+class __result_of
+{
+};
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Fn, class ..._ArgTypes>
+class __result_of<_Fn(_ArgTypes...), true>
+{
+public:
+    typedef decltype(declval<_Fn>()(declval<_ArgTypes>()...)) type;
+};
+
+template <class _Fn, class ..._ArgTypes>
+class result_of<_Fn(_ArgTypes...)>
+    : public __result_of<_Fn(_ArgTypes...),
+                         is_class<typename remove_reference<_Fn>::type>::value ||
+                         is_function<typename remove_pointer<
+                                        typename remove_reference<_Fn>::type
+                                                            >::type
+                                    >::value
+                        >
+{
+};
+
+#else
+
+template <class _Fn>
+class __result_of<_Fn(), true>
+{
+public:
+    typedef decltype(declval<_Fn>()()) type;
+};
+
+template <class _Fn, class _A0>
+class __result_of<_Fn(_A0), true>
+{
+public:
+    typedef decltype(declval<_Fn>()(declval<_A0>())) type;
+};
+
+template <class _Fn, class _A0, class _A1>
+class __result_of<_Fn(_A0, _A1), true>
+{
+public:
+    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
+};
+
+template <class _Fn, class _A0, class _A1, class _A2>
+class __result_of<_Fn(_A0, _A1, _A2), true>
+{
+public:
+    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
+};
+
+template <class _Fn>
+class result_of<_Fn()>
+    : public __result_of<_Fn(),
+                         is_class<typename remove_reference<_Fn>::type>::value ||
+                         is_function<typename remove_pointer<
+                                        typename remove_reference<_Fn>::type
+                                                            >::type
+                                    >::value
+                        >
+{
+};
+
+template <class _Fn, class _A0>
+class result_of<_Fn(_A0)>
+    : public __result_of<_Fn(_A0),
+                         is_class<typename remove_reference<_Fn>::type>::value ||
+                         is_function<typename remove_pointer<
+                                        typename remove_reference<_Fn>::type
+                                                            >::type
+                                    >::value
+                        >
+{
+};
+
+template <class _Fn, class _A0, class _A1>
+class result_of<_Fn(_A0, _A1)>
+    : public __result_of<_Fn(_A0, _A1),
+                         is_class<typename remove_reference<_Fn>::type>::value ||
+                         is_function<typename remove_pointer<
+                                        typename remove_reference<_Fn>::type
+                                                            >::type
+                                    >::value
+                        >
+{
+};
+
+template <class _Fn, class _A0, class _A1, class _A2>
+class result_of<_Fn(_A0, _A1, _A2)>
+    : public __result_of<_Fn(_A0, _A1, _A2),
+                         is_class<typename remove_reference<_Fn>::type>::value ||
+                         is_function<typename remove_pointer<
+                                        typename remove_reference<_Fn>::type
+                                                            >::type
+                                    >::value
+                        >
+{
+};
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
+
+// template <class T, class... Args> struct is_constructible;
+
+//      main is_constructible test
+
+template <class _Tp, class ..._Args>
+decltype(_STD::move(_Tp(_STD::declval<_Args>()...)), true_type())
+__is_constructible_test(_Tp&&, _Args&& ...);
+
+struct __any
+{
+    __any(...);
+};
+
+template <class ..._Args>
+false_type
+__is_constructible_test(__any, _Args&& ...);
+
+template <bool, class _Tp, class... _Args>
+struct __is_constructible // false, _Tp is not a scalar
+    : public common_type
+             <
+                 decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
+             >::type
+    {};
+
+//      function types are not constructible
+
+template <class _R, class... _A1, class... _A2>
+struct __is_constructible<false, _R(_A1...), _A2...>
+    : public false_type
+    {};
+
+//      handle scalars and reference types
+
+//      Scalars are default constructible, references are not
+
+template <class _Tp>
+struct __is_constructible<true, _Tp> 
+    : public is_scalar<_Tp>
+    {};
+
+//      Scalars and references are constructible from one arg if that arg is
+//          implicitly convertible to the scalar or reference.
+
+template <class _Tp>
+struct __is_constructible_ref
+{
+    true_type static __(_Tp);
+    false_type static __(...);
+};
+
+template <class _Tp, class _A0>
+struct __is_constructible<true, _Tp, _A0> 
+    : public common_type
+             <
+                 decltype(__is_constructible_ref<_Tp>::__(declval<_A0>()))
+             >::type
+    {};
+
+//      Scalars and references are not constructible from multiple args.
+
+template <class _Tp, class _A0, class ..._Args>
+struct __is_constructible<true, _Tp, _A0, _Args...> 
+    : public false_type
+    {};
+
+//      Treat scalars and reference types separately
+
+template <bool, class _Tp, class... _Args>
+struct __is_constructible_void_check
+    : public __is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
+                                _Tp, _Args...>
+    {};
+
+//      If any of T or Args is void, is_constructible should be false
+
+template <class _Tp, class... _Args>
+struct __is_constructible_void_check<true, _Tp, _Args...>
+    : public false_type
+    {};
+
+template <class ..._Args> struct __constains_void;
+
+template <> struct __constains_void<> : false_type {};
+
+template <class _A0, class ..._Args>
+struct __constains_void<_A0, _Args...>
+{
+    static const bool value = is_void<_A0>::value ||
+                              __constains_void<_Args...>::value;
+};
+
+//      is_constructible entry point
+
+template <class _Tp, class... _Args>
+struct is_constructible
+    : public __is_constructible_void_check<__constains_void<_Tp, _Args...>::value,
+                                           _Tp, _Args...>
+    {};
+
+//      Array types are default constructible if their element type
+//      is default constructible
+
+template <class _A, size_t _N>
+struct __is_constructible<false, _A[_N]>
+    : public is_constructible<typename remove_all_extents<_A>::type>
+    {};
+
+//      Otherwise array types are not constructible by this syntax
+
+template <class _A, size_t _N, class ..._Args>
+struct __is_constructible<false, _A[_N], _Args...>
+    : public false_type
+    {};
+
+//      Incomplete array types are not constructible
+
+template <class _A, class ..._Args>
+struct __is_constructible<false, _A[], _Args...>
+    : public false_type
+    {};
+
+#endif
+
+template <class _Tp> struct __is_zero_default_constructible
+    : public integral_constant<bool, is_scalar<_Tp>::value || is_empty<_Tp>::value> {};
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(_Tp& __x, _Tp& __y)
+{
+    _Tp __t(_STD::move(__x));
+    __x = _STD::move(__y);
+    __y = _STD::move(__t);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_TYPE_TRAITS
diff --git a/include/typeindex b/include/typeindex
new file mode 100644
index 0000000..6ce2d7b
--- /dev/null
+++ b/include/typeindex
@@ -0,0 +1,84 @@
+// -*- C++ -*-
+//===-------------------------- typeindex ---------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_TYPEINDEX
+#define _LIBCPP_TYPEINDEX
+
+/*
+
+    typeindex synopsis
+
+namespace std
+{
+
+class type_index
+{
+public:
+    type_index(const type_info& rhs);
+
+    bool operator==(const type_index& rhs) const;
+    bool operator!=(const type_index& rhs) const;
+    bool operator< (const type_index& rhs) const;
+    bool operator<=(const type_index& rhs) const;
+    bool operator> (const type_index& rhs) const;
+    bool operator>=(const type_index& rhs) const;
+
+    size_t hash_code() const;
+    const char* name() const;
+};
+
+template <>
+struct hash<type_index>
+    : public unary_function<type_index, size_t>
+{
+    size_t operator()(type_index index) const;
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <typeinfo>
+#include <__functional_base>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class type_index
+{
+    const type_info* __t_;
+public:
+    type_index(const type_info& __y) : __t_(&__y) {}
+
+    bool operator==(const type_index& __y) const {return *__t_ == *__y.__t_;}
+    bool operator!=(const type_index& __y) const {return *__t_ != *__y.__t_;}
+    bool operator< (const type_index& __y) const {return  __t_->before(*__y.__t_);}
+    bool operator<=(const type_index& __y) const {return !__y.__t_->before(*__t_);}
+    bool operator> (const type_index& __y) const {return  __y.__t_->before(*__t_);}
+    bool operator>=(const type_index& __y) const {return !__t_->before(*__y.__t_);}
+
+    size_t hash_code() const {return __t_->hash_code();}
+    const char* name() const {return __t_->name();}
+};
+
+template <class _Tp> struct hash;
+
+template <>
+struct hash<type_index>
+    : public unary_function<type_index, size_t>
+{
+    size_t operator()(type_index __index) const {return __index.hash_code();}
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_TYPEINDEX
diff --git a/include/typeinfo b/include/typeinfo
new file mode 100644
index 0000000..c45e512
--- /dev/null
+++ b/include/typeinfo
@@ -0,0 +1,129 @@
+// -*- C++ -*-
+//===-------------------------- typeinfo ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LIBCPP_TYPEINFO
+#define __LIBCPP_TYPEINFO
+
+/*
+
+    typeinfo synopsis
+
+namespace std {
+
+class type_info
+{
+public:
+    virtual ~type_info();
+    
+    bool operator==(const type_info& rhs) const;
+    bool operator!=(const type_info& rhs) const;
+    
+    bool before(const type_info& rhs) const;
+    size_t hash_code() const throw();
+    const char* name() const;
+    
+    type_info(const type_info& rhs) = delete;
+    type_info& operator=(const type_info& rhs) = delete;
+};
+
+class bad_cast
+    : public exception
+{
+public:
+    bad_cast() throw();
+    bad_cast(const bad_cast&) throw();
+    bad_cast& operator=(const bad_cast&) throw();
+    virtual const char* what() const throw();
+};
+
+class bad_typeid
+    : public exception
+{
+public:
+    bad_typeid() throw();
+    bad_typeid(const bad_typeid&) throw();
+    bad_typeid& operator=(const bad_typeid&) throw();
+    virtual const char* what() const throw();
+};
+
+}  // std
+
+*/
+
+#include <__config>
+#include <exception>
+#include <cstddef>
+
+#pragma GCC system_header
+
+#pragma GCC visibility push(default)
+
+namespace __cxxabiv1
+{
+    class __class_type_info;
+}
+
+namespace std  // purposefully not using versioning namespace
+{
+
+class type_info 
+{
+    type_info& operator=(const type_info&);
+    type_info(const type_info&);
+protected:
+    const char* __type_name;
+
+    explicit type_info(const char* __n)
+        : __type_name(__n) {}
+
+public:
+    virtual ~type_info();
+
+    const char* name() const {return __type_name;}
+
+    bool before(const type_info& __arg) const
+        {return __type_name < __arg.__type_name;}
+    size_t hash_code() const throw()
+        {return *reinterpret_cast<const size_t*>(&__type_name);}
+
+    bool operator==(const type_info& __arg) const
+        {return __type_name == __arg.__type_name;}
+    bool operator!=(const type_info& __arg) const
+        {return !operator==(__arg);}
+
+    virtual bool __is_pointer_p() const;
+    virtual bool __is_function_p() const;
+    virtual bool __do_catch(const type_info*, void**, unsigned) const;
+    virtual bool __do_upcast(const __cxxabiv1::__class_type_info*, void**) const;
+};
+
+class bad_cast
+    : public exception 
+{
+public:
+    bad_cast() throw() {}
+    virtual ~bad_cast() throw();
+    virtual const char* what() const throw();
+};
+
+class bad_typeid
+    : public exception 
+{
+public:
+    bad_typeid () throw() { }
+    virtual ~bad_typeid() throw();
+    virtual const char* what() const throw();
+};
+
+}  // std
+
+#pragma GCC visibility pop
+
+#endif  // __LIBCPP_TYPEINFO
diff --git a/include/unordered_map b/include/unordered_map
new file mode 100644
index 0000000..55d5a9d
--- /dev/null
+++ b/include/unordered_map
@@ -0,0 +1,1511 @@
+// -*- C++ -*-
+//===-------------------------- unordered_map -----------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_UNORDERED_MAP
+#define _LIBCPP_UNORDERED_MAP
+
+/*
+
+    unordered_map synopsis
+
+#include <initializer_list>
+
+namespace std
+{
+
+template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+          class Alloc = allocator<pair<const Key, T>>>
+class unordered_map
+{
+public:
+    // types
+    typedef Key                                                        key_type;
+    typedef T                                                          mapped_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef pair<const key_type, mapped_type>                          value_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+    typedef /unspecified/ local_iterator;
+    typedef /unspecified/ const_local_iterator;
+
+    explicit unordered_map(size_type n = 0, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        unordered_map(InputIterator f, InputIterator l,
+                      size_type n = 0, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    explicit unordered_map(const allocator_type&);
+    unordered_map(const unordered_map&);
+    unordered_map(const unordered_map&, const Allocator&);
+    unordered_map(unordered_map&&);
+    unordered_map(unordered_map&&, const Allocator&);
+    unordered_map(initializer_list<value_type>, size_type n = 0,
+                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
+                  const allocator_type& a = allocator_type());
+    ~unordered_map();
+    unordered_map& operator=(const unordered_map&);
+    unordered_map& operator=(unordered_map&&);
+    unordered_map& operator=(initializer_list<value_type>);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+    const_iterator cbegin() const;
+    const_iterator cend()   const;
+
+    template <class... Args>
+        pair<iterator, bool> emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    pair<iterator, bool> insert(const value_type& obj);
+    template <class P>
+        pair<iterator, bool> insert(P&& obj);
+    iterator insert(const_iterator hint, const value_type& obj);
+    template <class P>
+        iterator insert(const_iterator hint, P&& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type>);
+
+    iterator erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(unordered_map&);
+
+    hasher hash_function() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    mapped_type& operator[](const key_type& k);
+    mapped_type& operator[](key_type&& k);
+
+    mapped_type&       at(const key_type& k);
+    const mapped_type& at(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type bucket_size(size_type n) const;
+    size_type bucket(const key_type& k) const;
+
+    local_iterator       begin(size_type n);
+    local_iterator       end(size_type n);
+    const_local_iterator begin(size_type n) const;
+    const_local_iterator end(size_type n) const;
+    const_local_iterator cbegin(size_type n) const;
+    const_local_iterator cend(size_type n) const;
+
+    float load_factor() const;
+    float max_load_factor() const;
+    void max_load_factor(float z);
+    void rehash(size_type n);
+    void reserve(size_type n);
+};
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
+              unordered_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
+               const unordered_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
+               const unordered_map<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+          class Alloc = allocator<pair<const Key, T>>>
+class unordered_multimap
+{
+public:
+    // types
+    typedef Key                                                        key_type;
+    typedef T                                                          mapped_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef pair<const key_type, mapped_type>                          value_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+    typedef /unspecified/ local_iterator;
+    typedef /unspecified/ const_local_iterator;
+
+    explicit unordered_multimap(size_type n = 0, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        unordered_multimap(InputIterator f, InputIterator l,
+                      size_type n = 0, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    explicit unordered_multimap(const allocator_type&);
+    unordered_multimap(const unordered_multimap&);
+    unordered_multimap(const unordered_multimap&, const Allocator&);
+    unordered_multimap(unordered_multimap&&);
+    unordered_multimap(unordered_multimap&&, const Allocator&);
+    unordered_multimap(initializer_list<value_type>, size_type n = 0,
+                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
+                  const allocator_type& a = allocator_type());
+    ~unordered_multimap();
+    unordered_multimap& operator=(const unordered_multimap&);
+    unordered_multimap& operator=(unordered_multimap&&);
+    unordered_multimap& operator=(initializer_list<value_type>);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+    const_iterator cbegin() const;
+    const_iterator cend()   const;
+
+    template <class... Args>
+        iterator emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    iterator insert(const value_type& obj);
+    template <class P>
+        iterator insert(P&& obj);
+    iterator insert(const_iterator hint, const value_type& obj);
+    template <class P>
+        iterator insert(const_iterator hint, P&& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type>);
+
+    iterator erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(unordered_multimap&);
+
+    hasher hash_function() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type bucket_size(size_type n) const;
+    size_type bucket(const key_type& k) const;
+
+    local_iterator       begin(size_type n);
+    local_iterator       end(size_type n);
+    const_local_iterator begin(size_type n) const;
+    const_local_iterator end(size_type n) const;
+    const_local_iterator cbegin(size_type n) const;
+    const_local_iterator cend(size_type n) const;
+
+    float load_factor() const;
+    float max_load_factor() const;
+    void max_load_factor(float z);
+    void rehash(size_type n);
+    void reserve(size_type n);
+};
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
+              unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
+               const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+template <class Key, class T, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
+               const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__hash_table>
+#include <functional>
+#include <stdexcept>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Hash, bool = is_empty<_Hash>::value>
+class __unordered_map_hasher
+    : private _Hash
+{
+public:
+    __unordered_map_hasher() : _Hash() {}
+    __unordered_map_hasher(const _Hash& __h) : _Hash(__h) {}
+    const _Hash& hash_function() const {return *this;}
+    size_t operator()(const _Tp& __x) const
+        {return static_cast<const _Hash&>(*this)(__x.first);}
+    size_t operator()(const typename _Tp::first_type& __x) const
+        {return static_cast<const _Hash&>(*this)(__x);}
+};
+
+template <class _Tp, class _Hash>
+class __unordered_map_hasher<_Tp, _Hash, false>
+{
+    _Hash __hash_;
+public:
+    __unordered_map_hasher() : __hash_() {}
+    __unordered_map_hasher(const _Hash& __h) : __hash_(__h) {}
+    const _Hash& hash_function() const {return __hash_;}
+    size_t operator()(const _Tp& __x) const
+        {return __hash_(__x.first);}
+    size_t operator()(const typename _Tp::first_type& __x) const
+        {return __hash_(__x);}
+};
+
+template <class _Tp, class _Pred, bool = is_empty<_Pred>::value>
+class __unordered_map_equal
+    : private _Pred
+{
+public:
+    __unordered_map_equal() : _Pred() {}
+    __unordered_map_equal(const _Pred& __p) : _Pred(__p) {}
+    const _Pred& key_eq() const {return *this;}
+    bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
+    bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+        {return static_cast<const _Pred&>(*this)(__x, __y.first);}
+    bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+        {return static_cast<const _Pred&>(*this)(__x.first, __y);}
+    bool operator()(const typename _Tp::first_type& __x, 
+                    const typename _Tp::first_type& __y) const
+        {return static_cast<const _Pred&>(*this)(__x, __y);}
+};
+
+template <class _Tp, class _Pred>
+class __unordered_map_equal<_Tp, _Pred, false>
+{
+    _Pred __pred_;
+public:
+    __unordered_map_equal() : __pred_() {}
+    __unordered_map_equal(const _Pred& __p) : __pred_(__p) {}
+    const _Pred& key_eq() const {return __pred_;}
+    bool operator()(const _Tp& __x, const _Tp& __y) const
+        {return __pred_(__x.first, __y.first);}
+    bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
+        {return __pred_(__x, __y.first);}
+    bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
+        {return __pred_(__x.first, __y);}
+    bool operator()(const typename _Tp::first_type& __x,
+                    const typename _Tp::first_type& __y) const
+        {return __pred_(__x, __y);}
+};
+
+template <class _Alloc>
+class __hash_map_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:
+    typedef typename value_type::first_type     first_type;
+    typedef typename value_type::second_type    second_type;
+
+    allocator_type& __na_;
+
+    __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
+
+public:
+    bool __first_constructed;
+    bool __second_constructed;
+
+    explicit __hash_map_node_destructor(allocator_type& __na)
+        : __na_(__na),
+          __first_constructed(false),
+          __second_constructed(false)
+        {}
+
+#ifdef _LIBCPP_MOVE
+    __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
+        : __na_(__x.__na_),
+          __first_constructed(__x.__value_constructed),
+          __second_constructed(__x.__value_constructed)
+        {
+            __x.__value_constructed = false;
+        }
+#else
+    __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
+        : __na_(__x.__na_),
+          __first_constructed(__x.__value_constructed),
+          __second_constructed(__x.__value_constructed)
+        {
+            const_cast<bool&>(__x.__value_constructed) = false;
+        }
+#endif
+
+    void operator()(pointer __p)
+    {
+        if (__second_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.second));
+        if (__first_constructed)
+            __alloc_traits::destroy(__na_, addressof(__p->__value_.first));
+        if (__p)
+            __alloc_traits::deallocate(__na_, __p, 1);
+    }
+};
+
+template <class _HashIterator>
+class __hash_map_iterator
+{
+    _HashIterator __i_;
+
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::second_type      mapped_type;
+public:
+    typedef forward_iterator_tag                                 iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::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;
+
+    __hash_map_iterator() {}
+
+    __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __hash_map_iterator& operator++() {++__i_; return *this;}
+    __hash_map_iterator operator++(int)
+    {
+        __hash_map_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class, class> friend class unordered_map;
+    template <class, class, class, class, class> friend class unordered_multimap;
+    template <class> friend class __hash_const_iterator;
+    template <class> friend class __hash_const_local_iterator;
+    template <class> friend class __hash_map_const_iterator;
+};
+
+template <class _HashIterator>
+class __hash_map_const_iterator
+{
+    _HashIterator __i_;
+
+    typedef pointer_traits<typename _HashIterator::pointer>      __pointer_traits;
+    typedef const typename _HashIterator::value_type::first_type key_type;
+    typedef typename _HashIterator::value_type::second_type      mapped_type;
+public:
+    typedef forward_iterator_tag                                 iterator_category;
+    typedef pair<key_type, mapped_type>                          value_type;
+    typedef typename _HashIterator::difference_type              difference_type;
+    typedef const value_type&                                    reference;
+    typedef typename __pointer_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind<value_type>
+#else
+            rebind<value_type>::other
+#endif
+                                                                 pointer;
+
+    __hash_map_const_iterator() {}
+
+    __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
+    __hash_map_const_iterator(
+            __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
+                : __i_(__i.__i_) {}
+
+    reference operator*() const {return *operator->();}
+    pointer operator->() const {return (pointer)__i_.operator->();}
+
+    __hash_map_const_iterator& operator++() {++__i_; return *this;}
+    __hash_map_const_iterator operator++(int)
+    {
+        __hash_map_const_iterator __t(*this);
+        ++(*this);
+        return __t;
+    }
+
+    friend bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
+        {return __x.__i_ == __y.__i_;}
+    friend bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
+        {return __x.__i_ != __y.__i_;}
+
+    template <class, class, class, class, class> friend class unordered_map;
+    template <class, class, class, class, class> friend class unordered_multimap;
+    template <class> friend class __hash_const_iterator;
+    template <class> friend class __hash_const_local_iterator;
+};
+
+template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
+          class _Alloc = allocator<pair<const _Key, _Tp> > >
+class unordered_map
+{
+public:
+    // types
+    typedef _Key                                           key_type;
+    typedef _Tp                                            mapped_type;
+    typedef _Hash                                          hasher;
+    typedef _Pred                                          key_equal;
+    typedef _Alloc                                         allocator_type;
+    typedef pair<const key_type, mapped_type>              value_type;
+    typedef value_type&                                    reference;
+    typedef const value_type&                              const_reference;
+
+private:
+    typedef pair<key_type, mapped_type>                    __value_type;
+    typedef __unordered_map_hasher<__value_type, hasher>   __hasher;
+    typedef __unordered_map_equal<__value_type, key_equal> __key_equal;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                           __allocator_type;
+
+    typedef __hash_table<__value_type, __hasher,
+                         __key_equal,  __allocator_type>   __table;
+
+    __table __table_;
+
+    typedef typename __table::__node_pointer               __node_pointer;
+    typedef typename __table::__node_const_pointer         __node_const_pointer;
+    typedef typename __table::__node_traits                __node_traits;
+    typedef typename __table::__node_allocator             __node_allocator;
+    typedef typename __table::__node                       __node;
+    typedef __hash_map_node_destructor<__node_allocator>   _D;
+    typedef unique_ptr<__node, _D>                         __node_holder;
+    typedef allocator_traits<allocator_type>               __alloc_traits;
+public:
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+
+    typedef __hash_map_iterator<typename __table::iterator>       iterator;
+    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
+    typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
+    typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
+
+    unordered_map() {} // = default;
+    explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
+                           const key_equal& __eql = key_equal());
+    unordered_map(size_type __n, const hasher& __hf,
+                  const key_equal& __eql,
+                  const allocator_type& __a);
+    template <class _InputIterator>
+        unordered_map(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        unordered_map(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        unordered_map(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf,
+                      const key_equal& __eql,
+                      const allocator_type& __a);
+    explicit unordered_map(const allocator_type& __a);
+    unordered_map(const unordered_map& __u);
+    unordered_map(const unordered_map& __u, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    unordered_map(unordered_map&& __u);
+    unordered_map(unordered_map&& __u, const allocator_type& __a);
+#endif
+    unordered_map(initializer_list<value_type> __il);
+    unordered_map(initializer_list<value_type> __il, size_type __n,
+                  const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
+    unordered_map(initializer_list<value_type> __il, size_type __n,
+                  const hasher& __hf, const key_equal& __eql,
+                  const allocator_type& __a);
+    // ~unordered_map() = default;
+    // unordered_map& operator=(const unordered_map& __u) = default;
+#ifdef _LIBCPP_MOVE
+    unordered_map& operator=(unordered_map&& __u);
+#endif
+    unordered_map& operator=(initializer_list<value_type> __il);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+    const_iterator cbegin() const {return __table_.begin();}
+    const_iterator cend()   const {return __table_.end();}
+
+#ifdef _LIBCPP_MOVE
+    pair<iterator, bool> emplace()
+        {return __table_.__emplace_unique();}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        pair<iterator, bool> emplace(_A0&& __a0)
+            {return __table_.__emplace_unique(_STD::forward<_A0>(__a0));}
+
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        pair<iterator, bool> emplace(_A0&& __a0, _Args&&... __args);
+
+    iterator emplace_hint(const_iterator)
+        {return __table_.__emplace_unique().first;}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator emplace_hint(const_iterator, _A0&& __a0)
+            {return __table_.__emplace_unique(_STD::forward<_A0>(__a0)).first;}
+
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator emplace_hint(const_iterator, _A0&& __a0, _Args&&... __args)
+            {return emplace(_STD::forward<_A0>(__a0),
+                            _STD::forward<_Args>(__args)...).first;}
+#endif
+    pair<iterator, bool> insert(const value_type& __x)
+        {return __table_.__insert_unique(__x);}
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        pair<iterator, bool> insert(_P&& __x)
+            {return __table_.__insert_unique(_STD::forward<_P>(__x));}
+#endif
+    iterator insert(const_iterator, const value_type& __x)
+        {return insert(__x).first;}
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(const_iterator, _P&& __x)
+            {return insert(_STD::forward<_P>(__x)).first;}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
+    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
+    iterator erase(const_iterator __first, const_iterator __last)
+        {return __table_.erase(__first.__i_, __last.__i_);}
+    void clear() {__table_.clear();}
+
+    void swap(unordered_map& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_function() const
+        {return __table_.hash_function().hash_function();}
+    key_equal key_eq() const
+        {return __table_.key_eq().key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_unique(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_unique(__k);}
+
+    mapped_type& operator[](const key_type& __k);
+#ifdef _LIBCPP_MOVE
+    mapped_type& operator[](key_type&& __k);
+#endif
+
+    mapped_type&       at(const key_type& __k);
+    const mapped_type& at(const key_type& __k) const;
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type bucket_size(size_type __n) const
+        {return __table_.bucket_size(__n);}
+    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
+
+    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
+    local_iterator       end(size_type __n)          {return __table_.end(__n);}
+    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
+    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
+    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
+    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
+
+    float load_factor() const {return __table_.load_factor();}
+    float max_load_factor() const {return __table_.max_load_factor();}
+    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
+    void rehash(size_type __n) {__table_.rehash(__n);}
+    void reserve(size_type __n) {__table_.reserve(__n);}
+
+private:
+#ifdef _LIBCPP_MOVE
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0);
+#else
+    __node_holder __construct_node(const key_type& __k);
+#endif
+};
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        const allocator_type& __a)
+    : __table_(__a)
+{
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        _InputIterator __first, _InputIterator __last)
+{
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        const unordered_map& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        const unordered_map& __u, const allocator_type& __a)
+    : __table_(__u.__table_, __a)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        unordered_map&& __u)
+    : __table_(_STD::move(__u.__table_))
+{
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        unordered_map&& __u, const allocator_type& __a)
+    : __table_(_STD::move(__u.__table_), __a)
+{
+    if (__a != __u.get_allocator())
+    {
+        iterator __i = __u.begin();
+        while (__u.size() != 0)
+            __table_.__insert_unique(
+                _STD::move(__u.__table_.remove((__i++).__i_)->__value_)
+                                    );
+    }
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        initializer_list<value_type> __il)
+{
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
+{
+    __table_ = _STD::move(__u.__table_);
+    return *this;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
+        initializer_list<value_type> __il)
+{
+    __table_.__assign_unique(__il.begin(), __il.end());
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class... _Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
+                                                                 _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first),
+                             _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second),
+                             _STD::forward<_Args>(__args)...);
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0,
+          class // = typename enable_if<is_convertible<_A0, value_type>::value>::type
+         >
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_),
+                             _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class... _Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    if (__r.second)
+        __h.release();
+    return __r;
+}
+
+#else
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first), __k);
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second));
+    __h.get_deleter().__second_constructed = true;
+    return _STD::move(__h);
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                       _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_unique(*__first);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+_Tp&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
+{
+    iterator __i = find(__k);
+    if (__i != end())
+        return __i->second;
+    __node_holder __h = __construct_node(__k);
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    __h.release();
+    return __r.first->second;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+_Tp&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
+{
+    iterator __i = find(__k);
+    if (__i != end())
+        return __i->second;
+    __node_holder __h = __construct_node(_STD::move(__k));
+    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
+    __h.release();
+    return __r.first->second;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+_Tp&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
+{
+    iterator __i = find(__k);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__i == end())
+        throw out_of_range("unordered_map::at: key not found");
+#endif
+    return __i->second;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+const _Tp&
+unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
+{
+    const_iterator __i = find(__k);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    if (__i == end())
+        throw out_of_range("unordered_map::at: key not found");
+#endif
+    return __i->second;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+     unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
+            __i != __ex; ++__i)
+    {
+        const_iterator __j = __y.find(__i->first);
+        if (__j == __ey || !(*__i == *__j))
+            return false;
+    }
+    return true;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
+          class _Alloc = allocator<pair<const _Key, _Tp> > >
+class unordered_multimap
+{
+public:
+    // types
+    typedef _Key                                           key_type;
+    typedef _Tp                                            mapped_type;
+    typedef _Hash                                          hasher;
+    typedef _Pred                                          key_equal;
+    typedef _Alloc                                         allocator_type;
+    typedef pair<const key_type, mapped_type>              value_type;
+    typedef value_type&                                    reference;
+    typedef const value_type&                              const_reference;
+
+private:
+    typedef pair<key_type, mapped_type>                    __value_type;
+    typedef __unordered_map_hasher<__value_type, hasher>   __hasher;
+    typedef __unordered_map_equal<__value_type, key_equal> __key_equal;
+    typedef typename allocator_traits<allocator_type>::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+            rebind_alloc<__value_type>
+#else
+            rebind_alloc<__value_type>::other
+#endif
+                                                           __allocator_type;
+
+    typedef __hash_table<__value_type, __hasher,
+                         __key_equal,  __allocator_type>   __table;
+
+    __table __table_;
+
+    typedef typename __table::__node_traits                __node_traits;
+    typedef typename __table::__node_allocator             __node_allocator;
+    typedef typename __table::__node                       __node;
+    typedef __hash_map_node_destructor<__node_allocator>   _D;
+    typedef unique_ptr<__node, _D>                         __node_holder;
+    typedef allocator_traits<allocator_type>               __alloc_traits;
+public:
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+
+    typedef __hash_map_iterator<typename __table::iterator>       iterator;
+    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
+    typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
+    typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
+
+    unordered_multimap() {} // = default
+    explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
+                                const key_equal& __eql = key_equal());
+    unordered_multimap(size_type __n, const hasher& __hf,
+                                const key_equal& __eql,
+                                const allocator_type& __a);
+    template <class _InputIterator>
+        unordered_multimap(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        unordered_multimap(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        unordered_multimap(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf,
+                      const key_equal& __eql,
+                      const allocator_type& __a);
+    explicit unordered_multimap(const allocator_type& __a);
+    unordered_multimap(const unordered_multimap& __u);
+    unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    unordered_multimap(unordered_multimap&& __u);
+    unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
+#endif
+    unordered_multimap(initializer_list<value_type> __il);
+    unordered_multimap(initializer_list<value_type> __il, size_type __n,
+                       const hasher& __hf = hasher(),
+                       const key_equal& __eql = key_equal());
+    unordered_multimap(initializer_list<value_type> __il, size_type __n,
+                       const hasher& __hf, const key_equal& __eql,
+                       const allocator_type& __a);
+    // ~unordered_multimap() = default;
+    // unordered_multimap& operator=(const unordered_multimap& __u) = default;
+#ifdef _LIBCPP_MOVE
+    unordered_multimap& operator=(unordered_multimap&& __u);
+#endif
+    unordered_multimap& operator=(initializer_list<value_type> __il);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+    const_iterator cbegin() const {return __table_.begin();}
+    const_iterator cend()   const {return __table_.end();}
+
+#ifdef _LIBCPP_MOVE
+    iterator emplace()
+        {return __table_.__emplace_multi();}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator emplace(_A0&& __a0)
+            {return __table_.__emplace_multi(_STD::forward<_A0>(__a0));}
+
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator emplace(_A0&& __a0, _Args&&... __args);
+
+    iterator emplace_hint(const_iterator __p)
+        {return __table_.__emplace_hint_multi(__p.__i_);}
+
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        iterator emplace_hint(const_iterator __p, _A0&& __a0)
+            {return __table_.__emplace_hint_multi(__p.__i_, _STD::forward<_A0>(__a0));}
+
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        iterator emplace_hint(const_iterator __p, _A0&& __a0, _Args&&... __args);
+#endif
+    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(_P&& __x)
+            {return __table_.__insert_multi(_STD::forward<_P>(__x));}
+#endif
+    iterator insert(const_iterator __p, const value_type& __x)
+        {return __table_.__insert_multi(__p.__i_, __x);}
+#ifdef _LIBCPP_MOVE
+    template <class _P,
+              class = typename enable_if<is_convertible<_P, value_type>::value>::type>
+        iterator insert(const_iterator __p, _P&& __x)
+            {return __table_.__insert_multi(__p.__i_, _STD::forward<_P>(__x));}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
+    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
+    iterator erase(const_iterator __first, const_iterator __last)
+        {return __table_.erase(__first.__i_, __last.__i_);}
+    void clear() {__table_.clear();}
+
+    void swap(unordered_multimap& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_function() const
+        {return __table_.hash_function().hash_function();}
+    key_equal key_eq() const
+        {return __table_.key_eq().key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_multi(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_multi(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type bucket_size(size_type __n) const
+        {return __table_.bucket_size(__n);}
+    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
+
+    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
+    local_iterator       end(size_type __n)          {return __table_.end(__n);}
+    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
+    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
+    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
+    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
+
+    float load_factor() const {return __table_.load_factor();}
+    float max_load_factor() const {return __table_.max_load_factor();}
+    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
+    void rehash(size_type __n) {__table_.rehash(__n);}
+    void reserve(size_type __n) {__table_.reserve(__n);}
+
+private:
+#ifdef _LIBCPP_MOVE
+    template <class _A0, class... _Args,
+              class = typename enable_if<is_convertible<_A0, key_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
+    template <class _A0,
+              class = typename enable_if<is_convertible<_A0, value_type>::value>::type>
+        __node_holder __construct_node(_A0&& __a0);
+#endif
+};
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        _InputIterator __first, _InputIterator __last)
+{
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        const allocator_type& __a)
+    : __table_(__a)
+{
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        const unordered_multimap& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        const unordered_multimap& __u, const allocator_type& __a)
+    : __table_(__u.__table_, __a)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        unordered_multimap&& __u)
+    : __table_(_STD::move(__u.__table_))
+{
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        unordered_multimap&& __u, const allocator_type& __a)
+    : __table_(_STD::move(__u.__table_), __a)
+{
+    if (__a != __u.get_allocator())
+    {
+        iterator __i = __u.begin();
+        while (__u.size() != 0)
+{
+            __table_.__insert_multi(
+                _STD::move(__u.__table_.remove((__i++).__i_)->__value_)
+                                   );
+}
+    }
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        initializer_list<value_type> __il)
+{
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
+{
+    __table_ = _STD::move(__u.__table_);
+    return *this;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
+        initializer_list<value_type> __il)
+{
+    __table_.__assign_multi(__il.begin(), __il.end());
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class... _Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
+        _A0&& __a0, _Args&&... __args)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_.first),
+                             _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __node_traits::construct(__na, addressof(__h->__value_.second),
+                             _STD::forward<_Args>(__args)...);
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0,
+          class // = typename enable_if<is_convertible<_A0, value_type>::value>::type
+         >
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
+{
+    __node_allocator& __na = __table_.__node_alloc();
+    __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
+    __node_traits::construct(__na, addressof(__h->__value_),
+                             _STD::forward<_A0>(__a0));
+    __h.get_deleter().__first_constructed = true;
+    __h.get_deleter().__second_constructed = true;
+    return __h;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class... _Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    iterator __r = __table_.__node_insert_multi(__h.get());
+    __h.release();
+    return __r;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _A0, class... _Args,
+          class // = typename enable_if<is_convertible<_A0, key_type>::value>::type
+         >
+typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
+        const_iterator __p, _A0&& __a0, _Args&&... __args)
+{
+    __node_holder __h = __construct_node(_STD::forward<_A0>(__a0),
+                                         _STD::forward<_Args>(__args)...);
+    iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
+    __h.release();
+    return __r;
+}
+
+#endif
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                            _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_multi(*__first);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+     unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    typedef pair<const_iterator, const_iterator> _EqRng;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
+    {
+        _EqRng __xeq = __x.equal_range(__i->first);
+        _EqRng __yeq = __y.equal_range(__i->first);
+        if (_STD::distance(__xeq.first, __xeq.second) !=
+            _STD::distance(__yeq.first, __yeq.second) ||
+                  !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
+            return false;
+        __i = __xeq.second;
+    }
+    return true;
+}
+
+template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+           const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_UNORDERED_MAP
diff --git a/include/unordered_set b/include/unordered_set
new file mode 100644
index 0000000..968a048
--- /dev/null
+++ b/include/unordered_set
@@ -0,0 +1,956 @@
+// -*- C++ -*-
+//===-------------------------- unordered_set -----------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_UNORDERED_SET
+#define _LIBCPP_UNORDERED_SET
+
+/*
+
+    unordered_set synopsis
+
+#include <initializer_list>
+
+namespace std
+{
+
+template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
+          class Alloc = allocator<Value>>
+class unordered_set
+{
+public:
+    // types
+    typedef Value                                                      key_type;
+    typedef key_type                                                   value_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+    typedef /unspecified/ local_iterator;
+    typedef /unspecified/ const_local_iterator;
+
+    explicit unordered_set(size_type n = 0, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        unordered_set(InputIterator f, InputIterator l,
+                      size_type n = 0, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    explicit unordered_set(const allocator_type&);
+    unordered_set(const unordered_set&);
+    unordered_set(const unordered_set&, const Allocator&);
+    unordered_set(unordered_set&&);
+    unordered_set(unordered_set&&, const Allocator&);
+    unordered_set(initializer_list<value_type>, size_type n = 0,
+                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
+                  const allocator_type& a = allocator_type());
+    ~unordered_set();
+    unordered_set& operator=(const unordered_set&);
+    unordered_set& operator=(unordered_set&&);
+    unordered_set& operator=(initializer_list<value_type>);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+    const_iterator cbegin() const;
+    const_iterator cend()   const;
+
+    template <class... Args>
+        pair<iterator, bool> emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    pair<iterator, bool> insert(const value_type& obj);
+    pair<iterator, bool> insert(value_type&& obj);
+    iterator insert(const_iterator hint, const value_type& obj);
+    iterator insert(const_iterator hint, value_type&& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type>);
+
+    iterator erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(unordered_set&);
+
+    hasher hash_function() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type bucket_size(size_type n) const;
+    size_type bucket(const key_type& k) const;
+
+    local_iterator       begin(size_type n);
+    local_iterator       end(size_type n);
+    const_local_iterator begin(size_type n) const;
+    const_local_iterator end(size_type n) const;
+    const_local_iterator cbegin(size_type n) const;
+    const_local_iterator cend(size_type n) const;
+
+    float load_factor() const;
+    float max_load_factor() const;
+    void max_load_factor(float z);
+    void rehash(size_type n);
+    void reserve(size_type n);
+};
+
+template <class Value, class Hash, class Pred, class Alloc>
+    void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
+              unordered_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
+               const unordered_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
+               const unordered_set<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
+          class Alloc = allocator<Value>>
+class unordered_multiset
+{
+public:
+    // types
+    typedef Value                                                      key_type;
+    typedef key_type                                                   value_type;
+    typedef Hash                                                       hasher;
+    typedef Pred                                                       key_equal;
+    typedef Alloc                                                      allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+    typedef typename allocator_traits<allocator_type>::pointer         pointer;
+    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
+    typedef typename allocator_traits<allocator_type>::size_type       size_type;
+    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
+
+    typedef /unspecified/ iterator;
+    typedef /unspecified/ const_iterator;
+    typedef /unspecified/ local_iterator;
+    typedef /unspecified/ const_local_iterator;
+
+    explicit unordered_multiset(size_type n = 0, const hasher& hf = hasher(),
+                           const key_equal& eql = key_equal(),
+                           const allocator_type& a = allocator_type());
+    template <class InputIterator>
+        unordered_multiset(InputIterator f, InputIterator l,
+                      size_type n = 0, const hasher& hf = hasher(),
+                      const key_equal& eql = key_equal(),
+                      const allocator_type& a = allocator_type());
+    explicit unordered_multiset(const allocator_type&);
+    unordered_multiset(const unordered_multiset&);
+    unordered_multiset(const unordered_multiset&, const Allocator&);
+    unordered_multiset(unordered_multiset&&);
+    unordered_multiset(unordered_multiset&&, const Allocator&);
+    unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
+                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
+                  const allocator_type& a = allocator_type());
+    ~unordered_multiset();
+    unordered_multiset& operator=(const unordered_multiset&);
+    unordered_multiset& operator=(unordered_multiset&&);
+    unordered_multiset& operator=(initializer_list<value_type>);
+
+    allocator_type get_allocator() const;
+
+    bool      empty() const;
+    size_type size() const;
+    size_type max_size() const;
+
+    iterator       begin();
+    iterator       end();
+    const_iterator begin()  const;
+    const_iterator end()    const;
+    const_iterator cbegin() const;
+    const_iterator cend()   const;
+
+    template <class... Args>
+        iterator emplace(Args&&... args);
+    template <class... Args>
+        iterator emplace_hint(const_iterator position, Args&&... args);
+    iterator insert(const value_type& obj);
+    iterator insert(value_type&& obj);
+    iterator insert(const_iterator hint, const value_type& obj);
+    iterator insert(const_iterator hint, value_type&& obj);
+    template <class InputIterator>
+        void insert(InputIterator first, InputIterator last);
+    void insert(initializer_list<value_type>);
+
+    iterator erase(const_iterator position);
+    size_type erase(const key_type& k);
+    iterator erase(const_iterator first, const_iterator last);
+    void clear();
+
+    void swap(unordered_multiset&);
+
+    hasher hash_function() const;
+    key_equal key_eq() const;
+
+    iterator       find(const key_type& k);
+    const_iterator find(const key_type& k) const;
+    size_type count(const key_type& k) const;
+    pair<iterator, iterator>             equal_range(const key_type& k);
+    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+
+    size_type bucket_count() const;
+    size_type max_bucket_count() const;
+
+    size_type bucket_size(size_type n) const;
+    size_type bucket(const key_type& k) const;
+
+    local_iterator       begin(size_type n);
+    local_iterator       end(size_type n);
+    const_local_iterator begin(size_type n) const;
+    const_local_iterator end(size_type n) const;
+    const_local_iterator cbegin(size_type n) const;
+    const_local_iterator cend(size_type n) const;
+
+    float load_factor() const;
+    float max_load_factor() const;
+    void max_load_factor(float z);
+    void rehash(size_type n);
+    void reserve(size_type n);
+};
+
+template <class Value, class Hash, class Pred, class Alloc>
+    void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
+              unordered_multiset<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
+               const unordered_multiset<Value, Hash, Pred, Alloc>& y);
+
+template <class Value, class Hash, class Pred, class Alloc>
+    bool
+    operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
+               const unordered_multiset<Value, Hash, Pred, Alloc>& y);
+}  // std
+
+*/
+
+#include <__config>
+#include <__hash_table>
+#include <functional>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
+          class _Alloc = allocator<_Value> >
+class unordered_set
+{
+public:
+    // types
+    typedef _Value                                                     key_type;
+    typedef key_type                                                   value_type;
+    typedef _Hash                                                      hasher;
+    typedef _Pred                                                      key_equal;
+    typedef _Alloc                                                     allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+
+private:
+    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
+
+    __table __table_;
+
+public:
+    typedef typename __table::pointer         pointer;
+    typedef typename __table::const_pointer   const_pointer;
+    typedef typename __table::size_type       size_type;
+    typedef typename __table::difference_type difference_type;
+
+    typedef typename __table::const_iterator       iterator;
+    typedef typename __table::const_iterator       const_iterator;
+    typedef typename __table::const_local_iterator local_iterator;
+    typedef typename __table::const_local_iterator const_local_iterator;
+
+    unordered_set() {} // = default;
+    explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
+                           const key_equal& __eql = key_equal());
+    unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
+                  const allocator_type& __a);
+    template <class _InputIterator>
+        unordered_set(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        unordered_set(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        unordered_set(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf, const key_equal& __eql,
+                      const allocator_type& __a);
+    explicit unordered_set(const allocator_type& __a);
+    unordered_set(const unordered_set& __u);
+    unordered_set(const unordered_set& __u, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    unordered_set(unordered_set&& __u);
+    unordered_set(unordered_set&& __u, const allocator_type& __a);
+#endif
+    unordered_set(initializer_list<value_type> __il);
+    unordered_set(initializer_list<value_type> __il, size_type __n,
+                  const hasher& __hf = hasher(),
+                  const key_equal& __eql = key_equal());
+    unordered_set(initializer_list<value_type> __il, size_type __n,
+                  const hasher& __hf, const key_equal& __eql,
+                  const allocator_type& __a);
+    // ~unordered_set() = default;
+    // unordered_set& operator=(const unordered_set& __u) = default;
+#ifdef _LIBCPP_MOVE
+    unordered_set& operator=(unordered_set&& __u);
+#endif
+    unordered_set& operator=(initializer_list<value_type> __il);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+    const_iterator cbegin() const {return __table_.begin();}
+    const_iterator cend()   const {return __table_.end();}
+
+#ifdef _LIBCPP_MOVE
+    template <class... _Args>
+        pair<iterator, bool> emplace(_Args&&... __args)
+            {return __table_.__emplace_unique(_STD::forward<_Args>(__args)...);}
+    template <class... _Args>
+        iterator emplace_hint(const_iterator, _Args&&... __args)
+            {return __table_.__emplace_unique(_STD::forward<_Args>(__args)...).first;}
+#endif
+    pair<iterator, bool> insert(const value_type& __x)
+        {return __table_.__insert_unique(__x);}
+#ifdef _LIBCPP_MOVE
+    pair<iterator, bool> insert(value_type&& __x)
+        {return __table_.__insert_unique(_STD::move(__x));}
+#endif
+    iterator insert(const_iterator, const value_type& __x)
+        {return insert(__x).first;}
+#ifdef _LIBCPP_MOVE
+    iterator insert(const_iterator, value_type&& __x)
+        {return insert(_STD::move(__x)).first;}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __table_.erase(__p);}
+    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
+    iterator erase(const_iterator __first, const_iterator __last)
+        {return __table_.erase(__first, __last);}
+    void clear() {__table_.clear();}
+
+    void swap(unordered_set& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_function() const {return __table_.hash_function();}
+    key_equal key_eq() const {return __table_.key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_unique(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_unique(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
+    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
+
+    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
+    local_iterator       end(size_type __n)          {return __table_.end(__n);}
+    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
+    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
+    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
+    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
+
+    float load_factor() const {return __table_.load_factor();}
+    float max_load_factor() const {return __table_.max_load_factor();}
+    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
+    void rehash(size_type __n) {__table_.rehash(__n);}
+    void reserve(size_type __n) {__table_.reserve(__n);}
+};
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        _InputIterator __first, _InputIterator __last)
+{
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        const allocator_type& __a)
+    : __table_(__a)
+{
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        const unordered_set& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        const unordered_set& __u, const allocator_type& __a)
+    : __table_(__u.__table_, __a)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        unordered_set&& __u)
+    : __table_(_STD::move(__u.__table_))
+{
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        unordered_set&& __u, const allocator_type& __a)
+    : __table_(_STD::move(__u.__table_), __a)
+{
+    if (__a != __u.get_allocator())
+    {
+        iterator __i = __u.begin();
+        while (__u.size() != 0)
+            __table_.__insert_unique(_STD::move(__u.__table_.remove(__i++)->__value_));
+    }
+}
+
+#endif
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        initializer_list<value_type> __il)
+{
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_set<_Value, _Hash, _Pred, _Alloc>&
+unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
+{
+    __table_ = _STD::move(__u.__table_);
+    return *this;
+}
+
+#endif
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_set<_Value, _Hash, _Pred, _Alloc>&
+unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
+        initializer_list<value_type> __il)
+{
+    __table_.__assign_unique(__il.begin(), __il.end());
+    return *this;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                    _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_unique(*__first);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
+     unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
+           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
+            __i != __ex; ++__i)
+    {
+        const_iterator __j = __y.find(*__i);
+        if (__j == __ey || !(*__i == *__j))
+            return false;
+    }
+    return true;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
+           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
+          class _Alloc = allocator<_Value> >
+class unordered_multiset
+{
+public:
+    // types
+    typedef _Value                                                     key_type;
+    typedef key_type                                                   value_type;
+    typedef _Hash                                                      hasher;
+    typedef _Pred                                                      key_equal;
+    typedef _Alloc                                                     allocator_type;
+    typedef value_type&                                                reference;
+    typedef const value_type&                                          const_reference;
+
+private:
+    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
+
+    __table __table_;
+
+public:
+    typedef typename __table::pointer         pointer;
+    typedef typename __table::const_pointer   const_pointer;
+    typedef typename __table::size_type       size_type;
+    typedef typename __table::difference_type difference_type;
+
+    typedef typename __table::const_iterator       iterator;
+    typedef typename __table::const_iterator       const_iterator;
+    typedef typename __table::const_local_iterator local_iterator;
+    typedef typename __table::const_local_iterator const_local_iterator;
+
+    unordered_multiset() {} // = default
+    explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
+                                const key_equal& __eql = key_equal());
+    unordered_multiset(size_type __n, const hasher& __hf,
+                       const key_equal& __eql, const allocator_type& __a);
+    template <class _InputIterator>
+        unordered_multiset(_InputIterator __first, _InputIterator __last);
+    template <class _InputIterator>
+        unordered_multiset(_InputIterator __first, _InputIterator __last,
+                      size_type __n, const hasher& __hf = hasher(),
+                      const key_equal& __eql = key_equal());
+    template <class _InputIterator>
+        unordered_multiset(_InputIterator __first, _InputIterator __last,
+                      size_type __n , const hasher& __hf,
+                      const key_equal& __eql, const allocator_type& __a);
+    explicit unordered_multiset(const allocator_type& __a);
+    unordered_multiset(const unordered_multiset& __u);
+    unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
+#ifdef _LIBCPP_MOVE
+    unordered_multiset(unordered_multiset&& __u);
+    unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
+#endif
+    unordered_multiset(initializer_list<value_type> __il);
+    unordered_multiset(initializer_list<value_type> __il, size_type __n,
+                       const hasher& __hf = hasher(),
+                       const key_equal& __eql = key_equal());
+    unordered_multiset(initializer_list<value_type> __il, size_type __n,
+                       const hasher& __hf, const key_equal& __eql,
+                       const allocator_type& __a);
+    // ~unordered_multiset() = default;
+    // unordered_multiset& operator=(const unordered_multiset& __u) = default;
+#ifdef _LIBCPP_MOVE
+    unordered_multiset& operator=(unordered_multiset&& __u);
+#endif
+    unordered_multiset& operator=(initializer_list<value_type> __il);
+
+    allocator_type get_allocator() const
+        {return allocator_type(__table_.__node_alloc());}
+
+    bool      empty() const {return __table_.size() == 0;}
+    size_type size() const  {return __table_.size();}
+    size_type max_size() const {return __table_.max_size();}
+
+    iterator       begin()        {return __table_.begin();}
+    iterator       end()          {return __table_.end();}
+    const_iterator begin()  const {return __table_.begin();}
+    const_iterator end()    const {return __table_.end();}
+    const_iterator cbegin() const {return __table_.begin();}
+    const_iterator cend()   const {return __table_.end();}
+
+#ifdef _LIBCPP_MOVE
+    template <class... _Args>
+        iterator emplace(_Args&&... __args)
+            {return __table_.__emplace_multi(_STD::forward<_Args>(__args)...);}
+    template <class... _Args>
+        iterator emplace_hint(const_iterator __p, _Args&&... __args)
+            {return __table_.__emplace_hint_multi(__p, _STD::forward<_Args>(__args)...);}
+#endif
+    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
+#ifdef _LIBCPP_MOVE
+    iterator insert(value_type&& __x) {return __table_.__insert_multi(_STD::move(__x));}
+#endif
+    iterator insert(const_iterator __p, const value_type& __x)
+        {return __table_.__insert_multi(__p, __x);}
+#ifdef _LIBCPP_MOVE
+    iterator insert(const_iterator __p, value_type&& __x)
+        {return __table_.__insert_multi(__p, _STD::move(__x));}
+#endif
+    template <class _InputIterator>
+        void insert(_InputIterator __first, _InputIterator __last);
+    void insert(initializer_list<value_type> __il)
+        {insert(__il.begin(), __il.end());}
+
+    iterator erase(const_iterator __p) {return __table_.erase(__p);}
+    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
+    iterator erase(const_iterator __first, const_iterator __last)
+        {return __table_.erase(__first, __last);}
+    void clear() {__table_.clear();}
+
+    void swap(unordered_multiset& __u) {__table_.swap(__u.__table_);}
+
+    hasher hash_function() const {return __table_.hash_function();}
+    key_equal key_eq() const {return __table_.key_eq();}
+
+    iterator       find(const key_type& __k)       {return __table_.find(__k);}
+    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
+    pair<iterator, iterator>             equal_range(const key_type& __k)
+        {return __table_.__equal_range_multi(__k);}
+    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
+        {return __table_.__equal_range_multi(__k);}
+
+    size_type bucket_count() const {return __table_.bucket_count();}
+    size_type max_bucket_count() const {return __table_.max_bucket_count();}
+
+    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
+    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
+
+    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
+    local_iterator       end(size_type __n)          {return __table_.end(__n);}
+    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
+    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
+    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
+    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
+
+    float load_factor() const {return __table_.load_factor();}
+    float max_load_factor() const {return __table_.max_load_factor();}
+    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
+    void rehash(size_type __n) {__table_.rehash(__n);}
+    void reserve(size_type __n) {__table_.reserve(__n);}
+};
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        size_type __n, const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        size_type __n, const hasher& __hf, const key_equal& __eql,
+        const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        _InputIterator __first, _InputIterator __last)
+{
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        _InputIterator __first, _InputIterator __last, size_type __n,
+        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__first, __last);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        const allocator_type& __a)
+    : __table_(__a)
+{
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        const unordered_multiset& __u)
+    : __table_(__u.__table_)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        const unordered_multiset& __u, const allocator_type& __a)
+    : __table_(__u.__table_, __a)
+{
+    __table_.rehash(__u.bucket_count());
+    insert(__u.begin(), __u.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        unordered_multiset&& __u)
+    : __table_(_STD::move(__u.__table_))
+{
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        unordered_multiset&& __u, const allocator_type& __a)
+    : __table_(_STD::move(__u.__table_), __a)
+{
+    if (__a != __u.get_allocator())
+    {
+        iterator __i = __u.begin();
+        while (__u.size() != 0)
+            __table_.__insert_multi(_STD::move(__u.__table_.remove(__i++)->__value_));
+    }
+}
+
+#endif
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        initializer_list<value_type> __il)
+{
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql)
+    : __table_(__hf, __eql)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
+        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
+        const key_equal& __eql, const allocator_type& __a)
+    : __table_(__hf, __eql, __a)
+{
+    __table_.rehash(__n);
+    insert(__il.begin(), __il.end());
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
+        unordered_multiset&& __u)
+{
+    __table_ = _STD::move(__u.__table_);
+    return *this;
+}
+
+#endif
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
+        initializer_list<value_type> __il)
+{
+    __table_.__assign_multi(__il.begin(), __il.end());
+    return *this;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+template <class _InputIterator>
+inline
+void
+unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
+                                                         _InputIterator __last)
+{
+    for (; __first != __last; ++__first)
+        __table_.__insert_multi(*__first);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+void
+swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+     unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    __x.swap(__y);
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+bool
+operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    if (__x.size() != __y.size())
+        return false;
+    typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
+                                                                 const_iterator;
+    typedef pair<const_iterator, const_iterator> _EqRng;
+    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
+    {
+        _EqRng __xeq = __x.equal_range(*__i);
+        _EqRng __yeq = __y.equal_range(*__i);
+        if (_STD::distance(__xeq.first, __xeq.second) !=
+            _STD::distance(__yeq.first, __yeq.second) ||
+                  !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
+            return false;
+        __i = __xeq.second;
+    }
+    return true;
+}
+
+template <class _Value, class _Hash, class _Pred, class _Alloc>
+inline
+bool
+operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+{
+    return !(__x == __y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_UNORDERED_SET
diff --git a/include/utility b/include/utility
new file mode 100644
index 0000000..0319b19
--- /dev/null
+++ b/include/utility
@@ -0,0 +1,481 @@
+// -*- C++ -*-
+//===-------------------------- utility -----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_UTILITY
+#define _LIBCPP_UTILITY
+
+/*
+    utility synopsis
+
+namespace std
+{
+
+template <class T>
+    void
+    swap(T& a, T& b);
+
+namespace rel_ops
+{
+    template<class T> bool operator!=(const T&, const T&);
+    template<class T> bool operator> (const T&, const T&);
+    template<class T> bool operator<=(const T&, const T&);
+    template<class T> bool operator>=(const T&, const T&);
+}
+
+template<class T> void swap(T& a, T& b);
+template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]);
+
+template <class T, class U> T&& forward(U&&);
+template <class T> typename remove_reference<T>::type&& move(T&&);
+
+template <class T>
+    typename conditional
+    <
+        !has_nothrow_move_constructor<T>::value && has_copy_constructor<T>::value,
+        const T&,
+        T&&
+    >::type
+    move_if_noexcept(T& x);
+
+template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
+
+template <class T1, class T2>
+struct pair
+{
+    typedef T1 first_type;
+    typedef T2 second_type;
+
+    T1 first;
+    T2 second;
+
+    pair(const pair&) = default;
+    constexpr pair();
+    pair(const T1& x, const T2& y);
+    template <class U, class V> pair(U&& x, V&& y);
+    template <class U, class V> pair(const pair<U, V>& p);
+    template <class U, class V> pair(pair<U, V>&& p);
+    template <class... Args1, class... Args2>
+        pair(piecewise_construct_t, tuple<Args1...> first_args,
+             tuple<Args2...> second_args);
+
+    template <class U, class V> pair& operator=(const pair<U, V>& p);
+    pair& operator=(pair&& p);
+    template <class U, class V> pair& operator=(pair<U, V>&& p);
+
+    void swap(pair& p);
+};
+
+template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&);
+template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
+template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&);
+template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&);
+template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&);
+template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&);
+
+template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);
+template <class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y);
+
+struct piecewise_construct_t { };
+constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
+
+template <class T> class tuple_size;
+template <size_t I, class T> class tuple_element;
+
+template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >;
+template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >;
+template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >;
+
+template<size_t I, class T1, class T2>
+    typename tuple_element<I, std::pair<T1, T2> >::type&
+    get(std::pair<T1, T2>&);
+
+template<size_t I, class T1, class T2>
+    const typename const tuple_element<I, std::pair<T1, T2> >::type&
+    get(const std::pair<T1, T2>&);
+
+template <class InputIterator>
+    InputIterator begin(const std::pair<InputIterator, InputIterator>& p);
+template <class InputIterator>
+    InputIterator end(const std::pair<InputIterator, InputIterator>& p);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__tuple>
+#include <type_traits>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace rel_ops
+{
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const _Tp& __x, const _Tp& __y)
+{
+    return !(__x == __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator> (const _Tp& __x, const _Tp& __y)
+{
+    return __y < __x;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const _Tp& __x, const _Tp& __y)
+{
+    return !(__y < __x);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const _Tp& __x, const _Tp& __y)
+{
+    return !(__x < __y);
+}
+
+}  // rel_ops
+
+// swap_ranges
+
+template <class _ForwardIterator1, class _ForwardIterator2>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator2
+swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
+{
+    for(; __first1 != __last1; ++__first1, ++__first2)
+        swap(*__first1, *__first2);
+    return __first2;
+}
+
+template<class _Tp, size_t _N>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(_Tp (&__a)[_N], _Tp (&__b)[_N])
+{
+    _STD::swap_ranges(__a, __a + _N, __b);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+#ifdef _LIBCPP_MOVE
+typename conditional
+<
+    !has_nothrow_move_constructor<_Tp>::value && has_copy_constructor<_Tp>::value,
+    const _Tp&,
+    _Tp&&
+>::type
+#else
+const _Tp&
+#endif
+move_if_noexcept(_Tp& __x)
+{
+    return _STD::move(__x);
+}
+
+struct piecewise_construct_t { };
+//constexpr
+extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
+
+template <class _T1, class _T2> struct pair;
+template <class _T1, class _T2> void swap(pair<_T1, _T2>&, pair<_T1, _T2>&);
+
+template <class _T1, class _T2>
+struct pair
+{
+    typedef _T1 first_type;
+    typedef _T2 second_type;
+
+    _T1 first;
+    _T2 second;
+
+    _LIBCPP_INLINE_VISIBILITY pair() : first(), second() {}
+
+    _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y)
+        : first(__x), second(__y) {}
+
+#ifdef _LIBCPP_MOVE
+
+    template <class _U1, class _U2,
+              class = typename enable_if<is_convertible<_U1, first_type >::value &&
+                                         is_convertible<_U2, second_type>::value>::type>
+        _LIBCPP_INLINE_VISIBILITY
+        pair(_U1&& __u1, _U2&& __u2)
+            : first(_STD::forward<_U1>(__u1)),
+              second(_STD::forward<_U2>(__u2))
+            {}
+
+    template<class _Tuple,
+             class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type>
+        _LIBCPP_INLINE_VISIBILITY
+        pair(_Tuple&& __p)
+            : first(_STD::forward<typename tuple_element<0,
+                                  typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))),
+              second(_STD::forward<typename tuple_element<1,
+                                   typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p)))
+            {}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+        pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
+                                    tuple<_Args2...> __second_args)
+            : pair(__pc, __first_args, __second_args, 
+                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
+                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
+            {}
+#endif
+
+    template <class _Tuple,
+              class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type>
+        pair&
+        operator=(_Tuple&& __p)
+        {
+            typedef typename __make_tuple_types<_Tuple>::type _TupleRef;
+            typedef typename tuple_element<0, _TupleRef>::type _U0;
+            typedef typename tuple_element<1, _TupleRef>::type _U1;
+            first  = _STD::forward<_U0>(_STD::get<0>(__p));
+            second = _STD::forward<_U1>(_STD::get<1>(__p));
+            return *this;
+        }
+
+#else
+    template<class _U1, class _U2>
+        _LIBCPP_INLINE_VISIBILITY pair(const pair<_U1, _U2>& __p)
+            : first(__p.first), second(__p.second) {}
+#endif
+    void _LIBCPP_INLINE_VISIBILITY swap(pair& __p) {_STD::swap(*this, __p);}
+private:
+    
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+        pair(piecewise_construct_t,
+             tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
+             __tuple_indices<_I1...>, __tuple_indices<_I2...>);
+#endif
+};
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return __x.first == __y.first && __x.second == __y.second;
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return __y < __x;
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
+{
+    swap(__x.first, __y.first);
+    swap(__x.second, __y.second);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp> class reference_wrapper;
+
+template <class _Tp>
+struct ___make_pair_return
+{
+    typedef _Tp type;
+};
+
+template <class _Tp>
+struct ___make_pair_return<reference_wrapper<_Tp>>
+{
+    typedef _Tp& type;
+};
+
+template <class _Tp>
+struct __make_pair_return
+{
+    typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type;
+};
+
+template <class _T1, class _T2>
+inline
+pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
+make_pair(_T1&& __t1, _T2&& __t2)
+{
+    return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
+               (_STD::forward<_T1>(__t1), _STD::forward<_T2>(__t2));
+}
+
+#else
+
+template <class _T1, class _T2>
+inline _LIBCPP_INLINE_VISIBILITY
+pair<_T1,_T2>
+make_pair(_T1 __x, _T2 __y)
+{
+    return pair<_T1, _T2>(__x, __y);
+}
+
+#endif
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+template <class _T1, class _T2>
+  class tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};
+
+template <class _T1, class _T2>
+  class tuple_size<const pair<_T1, _T2> > : public integral_constant<size_t, 2> {};
+
+template <class _T1, class _T2>
+class tuple_element<0, pair<_T1, _T2> >
+{
+public:
+    typedef _T1 type;
+};
+
+template <class _T1, class _T2>
+class tuple_element<1, pair<_T1, _T2> >
+{
+public:
+    typedef _T2 type;
+};
+
+template <class _T1, class _T2>
+class tuple_element<0, const pair<_T1, _T2> >
+{
+public:
+    typedef const _T1 type;
+};
+
+template <class _T1, class _T2>
+class tuple_element<1, const pair<_T1, _T2> >
+{
+public:
+    typedef const _T2 type;
+};
+
+template <size_t _Ip> struct __get_pair;
+
+template <>
+struct __get_pair<0>
+{
+    template <class _T1, class _T2>
+    static
+    _LIBCPP_INLINE_VISIBILITY
+    _T1&
+    get(pair<_T1, _T2>& __p) {return __p.first;}
+
+    template <class _T1, class _T2>
+    static
+    _LIBCPP_INLINE_VISIBILITY
+    const _T1&
+    get(const pair<_T1, _T2>& __p) {return __p.first;}
+};
+
+template <>
+struct __get_pair<1>
+{
+    template <class _T1, class _T2>
+    static
+    _LIBCPP_INLINE_VISIBILITY
+    _T2&
+    get(pair<_T1, _T2>& __p) {return __p.second;}
+
+    template <class _T1, class _T2>
+    static
+    _LIBCPP_INLINE_VISIBILITY
+    const _T2&
+    get(const pair<_T1, _T2>& __p) {return __p.second;}
+};
+
+template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY inline
+typename tuple_element<_Ip, pair<_T1, _T2> >::type&
+get(pair<_T1, _T2>& __p)
+{
+    return __get_pair<_Ip>::get(__p);
+}
+
+template <size_t _Ip, class _T1, class _T2>
+_LIBCPP_INLINE_VISIBILITY inline
+const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
+get(const pair<_T1, _T2>& __p)
+{
+    return __get_pair<_Ip>::get(__p);
+}
+
+#endif
+
+template <class _InputIterator>
+_LIBCPP_INLINE_VISIBILITY inline
+_InputIterator
+begin(const pair<_InputIterator, _InputIterator>& __p)
+{
+    return __p.first;
+}
+
+template <class _InputIterator>
+_LIBCPP_INLINE_VISIBILITY inline
+_InputIterator
+end(const pair<_InputIterator, _InputIterator>& __p)
+{
+    return __p.second;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_UTILITY
diff --git a/include/valarray b/include/valarray
new file mode 100644
index 0000000..2d2199a
--- /dev/null
+++ b/include/valarray
@@ -0,0 +1,4738 @@
+// -*- C++ -*-
+//===-------------------------- valarray ----------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_VALARRAY
+#define _LIBCPP_VALARRAY
+
+/*
+    valarray synopsis
+
+namespace std
+{
+
+template<class T>
+class valarray
+{
+public:
+    typedef T value_type;
+
+    // construct/destroy:
+    valarray();
+    explicit valarray(size_t n);
+    valarray(const value_type& x, size_t n);
+    valarray(const value_type* px, size_t n);
+    valarray(const valarray& v);
+    valarray(valarray&& v);
+    valarray(const slice_array<value_type>& sa);
+    valarray(const gslice_array<value_type>& ga);
+    valarray(const mask_array<value_type>& ma);
+    valarray(const indirect_array<value_type>& ia);
+    valarray(initializer_list<value_type> il);
+    ~valarray();
+
+    // assignment:
+    valarray& operator=(const valarray& v);
+    valarray& operator=(valarray&& v);
+    valarray& operator=(initializer_list<value_type> il);
+    valarray& operator=(const value_type& x);
+    valarray& operator=(const slice_array<value_type>& sa);
+    valarray& operator=(const gslice_array<value_type>& ga);
+    valarray& operator=(const mask_array<value_type>& ma);
+    valarray& operator=(const indirect_array<value_type>& ia);
+
+    // element access:
+    const value_type& operator[](size_t i) const;
+    value_type&       operator[](size_t i);
+
+    // subset operations:
+    valarray                   operator[](slice s) const;
+    slice_array<value_type>    operator[](slice s);
+    valarray                   operator[](const gslice& gs) const;
+    gslice_array<value_type>   operator[](const gslice& gs);
+    valarray                   operator[](const valarray<bool>& vb) const;
+    mask_array<value_type>     operator[](const valarray<bool>& vb);
+    valarray                   operator[](const valarray<size_t>& vs) const;
+    indirect_array<value_type> operator[](const valarray<size_t>& vs);
+
+    // unary operators:
+    valarray       operator+() const;
+    valarray       operator-() const;
+    valarray       operator~() const;
+    valarray<bool> operator!() const;
+
+    // computed assignment:
+    valarray& operator*= (const value_type& x);
+    valarray& operator/= (const value_type& x);
+    valarray& operator%= (const value_type& x);
+    valarray& operator+= (const value_type& x);
+    valarray& operator-= (const value_type& x);
+    valarray& operator^= (const value_type& x);
+    valarray& operator&= (const value_type& x);
+    valarray& operator|= (const value_type& x);
+    valarray& operator<<=(const value_type& x);
+    valarray& operator>>=(const value_type& x);
+
+    valarray& operator*= (const valarray& v);
+    valarray& operator/= (const valarray& v);
+    valarray& operator%= (const valarray& v);
+    valarray& operator+= (const valarray& v);
+    valarray& operator-= (const valarray& v);
+    valarray& operator^= (const valarray& v);
+    valarray& operator|= (const valarray& v);
+    valarray& operator&= (const valarray& v);
+    valarray& operator<<=(const valarray& v);
+    valarray& operator>>=(const valarray& v);
+
+    // member functions:
+    void swap(valarray& v);
+
+    size_t size() const;
+
+    value_type sum() const;
+    value_type min() const;
+    value_type max() const;
+
+    valarray shift (int i) const;
+    valarray cshift(int i) const;
+    valarray apply(value_type f(value_type)) const;
+    valarray apply(value_type f(const value_type&)) const;
+    void resize(size_t n, value_type x = value_type());
+};
+
+class slice
+{
+public:
+    slice();
+    slice(size_t start, size_t size, size_t stride);
+
+    size_t start()  const;
+    size_t size()   const;
+    size_t stride() const;
+};
+
+template <class T>
+class slice_array
+{
+public:
+    typedef T value_type;
+
+    const slice_array& operator=(const slice_array& sa) const;
+    void operator=  (const valarray<value_type>& v) const;
+    void operator*= (const valarray<value_type>& v) const;
+    void operator/= (const valarray<value_type>& v) const;
+    void operator%= (const valarray<value_type>& v) const;
+    void operator+= (const valarray<value_type>& v) const;
+    void operator-= (const valarray<value_type>& v) const;
+    void operator^= (const valarray<value_type>& v) const;
+    void operator&= (const valarray<value_type>& v) const;
+    void operator|= (const valarray<value_type>& v) const;
+    void operator<<=(const valarray<value_type>& v) const;
+    void operator>>=(const valarray<value_type>& v) const;
+
+    void operator=(const value_type& x) const;
+
+    slice_array() = delete;
+};
+
+class gslice
+{
+public:
+    gslice();
+    gslice(size_t start, const valarray<size_t>& size,
+                         const valarray<size_t>& stride);
+
+    size_t           start()  const;
+    valarray<size_t> size()   const;
+    valarray<size_t> stride() const;
+};
+
+template <class T>
+class gslice_array
+{
+public:
+    typedef T value_type;
+
+    void operator=  (const valarray<value_type>& v) const;
+    void operator*= (const valarray<value_type>& v) const;
+    void operator/= (const valarray<value_type>& v) const;
+    void operator%= (const valarray<value_type>& v) const;
+    void operator+= (const valarray<value_type>& v) const;
+    void operator-= (const valarray<value_type>& v) const;
+    void operator^= (const valarray<value_type>& v) const;
+    void operator&= (const valarray<value_type>& v) const;
+    void operator|= (const valarray<value_type>& v) const;
+    void operator<<=(const valarray<value_type>& v) const;
+    void operator>>=(const valarray<value_type>& v) const;
+
+    gslice_array(const gslice_array& ga);
+    ~gslice_array();
+    const gslice_array& operator=(const gslice_array& ga) const;
+    void operator=(const value_type& x) const;
+
+    gslice_array() = delete;
+};
+
+template <class T>
+class mask_array
+{
+public:
+    typedef T value_type;
+
+    void operator=  (const valarray<value_type>& v) const;
+    void operator*= (const valarray<value_type>& v) const;
+    void operator/= (const valarray<value_type>& v) const;
+    void operator%= (const valarray<value_type>& v) const;
+    void operator+= (const valarray<value_type>& v) const;
+    void operator-= (const valarray<value_type>& v) const;
+    void operator^= (const valarray<value_type>& v) const;
+    void operator&= (const valarray<value_type>& v) const;
+    void operator|= (const valarray<value_type>& v) const;
+    void operator<<=(const valarray<value_type>& v) const;
+    void operator>>=(const valarray<value_type>& v) const;
+
+    mask_array(const mask_array& ma);
+    ~mask_array();
+    const mask_array& operator=(const mask_array& ma) const;
+    void operator=(const value_type& x) const;
+
+    mask_array() = delete;
+};
+
+template <class T>
+class indirect_array
+{
+public:
+    typedef T value_type;
+
+    void operator=  (const valarray<value_type>& v) const;
+    void operator*= (const valarray<value_type>& v) const;
+    void operator/= (const valarray<value_type>& v) const;
+    void operator%= (const valarray<value_type>& v) const;
+    void operator+= (const valarray<value_type>& v) const;
+    void operator-= (const valarray<value_type>& v) const;
+    void operator^= (const valarray<value_type>& v) const;
+    void operator&= (const valarray<value_type>& v) const;
+    void operator|= (const valarray<value_type>& v) const;
+    void operator<<=(const valarray<value_type>& v) const;
+    void operator>>=(const valarray<value_type>& v) const;
+
+    indirect_array(const indirect_array& ia);
+    ~indirect_array();
+    const indirect_array& operator=(const indirect_array& ia) const;
+    void operator=(const value_type& x) const;
+
+    indirect_array() = delete;
+};
+
+template<class T> void swap(valarray<T>& x, valarray<T>& y);
+
+template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
+template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
+
+template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
+template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> abs (const valarray<T>& x);
+template<class T> valarray<T> acos (const valarray<T>& x);
+template<class T> valarray<T> asin (const valarray<T>& x);
+template<class T> valarray<T> atan (const valarray<T>& x);
+
+template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
+template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> cos (const valarray<T>& x);
+template<class T> valarray<T> cosh (const valarray<T>& x);
+template<class T> valarray<T> exp (const valarray<T>& x);
+template<class T> valarray<T> log (const valarray<T>& x);
+template<class T> valarray<T> log10(const valarray<T>& x);
+
+template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
+template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
+template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
+
+template<class T> valarray<T> sin (const valarray<T>& x);
+template<class T> valarray<T> sinh (const valarray<T>& x);
+template<class T> valarray<T> sqrt (const valarray<T>& x);
+template<class T> valarray<T> tan (const valarray<T>& x);
+template<class T> valarray<T> tanh (const valarray<T>& x);
+
+template <class T> unspecified1 begin(valarray<T>& v);
+template <class T> unspecified2 begin(const valarray<T>& v);
+template <class T> unspecified1 end(valarray<T>& v);
+template <class T> unspecified2 end(const valarray<T>& v);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <cstddef>
+#include <cmath>
+#include <initializer_list>
+#include <algorithm>
+#include <functional>
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template<class _Tp> class valarray;
+
+class slice
+{
+    size_t __start_;
+    size_t __size_;
+    size_t __stride_;
+public:
+    _LIBCPP_ALWAYS_INLINE
+    slice()
+        : __start_(0),
+          __size_(0),
+          __stride_(0)
+          {}
+
+    _LIBCPP_ALWAYS_INLINE
+    slice(size_t __start, size_t __size, size_t __stride)
+        : __start_(__start),
+          __size_(__size),
+          __stride_(__stride)
+          {}
+
+    _LIBCPP_ALWAYS_INLINE size_t start()  const {return __start_;}
+    _LIBCPP_ALWAYS_INLINE size_t size()   const {return __size_;}
+    _LIBCPP_ALWAYS_INLINE size_t stride() const {return __stride_;}
+};
+
+template <class _Tp> class slice_array;
+class gslice;
+template <class _Tp> class gslice_array;
+template <class _Tp> class mask_array;
+template <class _Tp> class indirect_array;
+
+template <class _Tp>
+_Tp*
+begin(valarray<_Tp>& __v);
+
+template <class _Tp>
+const _Tp*
+begin(const valarray<_Tp>& __v);
+
+template <class _Tp>
+_Tp*
+end(valarray<_Tp>& __v);
+
+template <class _Tp>
+const _Tp*
+end(const valarray<_Tp>& __v);
+
+template <class _Op, class _A0>
+struct _UnaryOp
+{
+    typedef typename _Op::result_type result_type;
+    typedef typename _A0::value_type value_type;
+
+    _Op __op_;
+    _A0 __a0_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+template <class _Op, class _A0, class _A1>
+struct _BinaryOp
+{
+    typedef typename _Op::result_type result_type;
+    typedef typename _A0::value_type value_type;
+
+    _Op __op_;
+    _A0 __a0_;
+    _A1 __a1_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
+        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+template <class _Tp>
+class __scalar_expr
+{
+public:
+    typedef _Tp        value_type;
+    typedef const _Tp& result_type;
+private:
+    const value_type& __t_;
+    size_t __s_;
+public:
+    _LIBCPP_ALWAYS_INLINE
+    explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t) const {return __t_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __s_;}
+};
+
+template <class _Tp>
+struct __unary_plus : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return +__x;}
+};
+
+template <class _Tp>
+struct __bit_not  : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return ~__x;}
+};
+
+template <class _Tp>
+struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x << __y;}
+};
+
+template <class _Tp>
+struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return __x >> __y;}
+};
+
+template <class _Tp, class _F>
+struct __apply_expr   : unary_function<_Tp, _Tp>
+{
+private:
+    _F __f_;
+public:
+    _LIBCPP_ALWAYS_INLINE
+    explicit __apply_expr(_F __f) : __f_(__f) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return __f_(__x);}
+};
+
+template <class _Tp>
+struct __abs_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return abs(__x);}
+};
+
+template <class _Tp>
+struct __acos_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return acos(__x);}
+};
+
+template <class _Tp>
+struct __asin_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return asin(__x);}
+};
+
+template <class _Tp>
+struct __atan_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return atan(__x);}
+};
+
+template <class _Tp>
+struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return atan2(__x, __y);}
+};
+
+template <class _Tp>
+struct __cos_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return cos(__x);}
+};
+
+template <class _Tp>
+struct __cosh_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return cosh(__x);}
+};
+
+template <class _Tp>
+struct __exp_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return exp(__x);}
+};
+
+template <class _Tp>
+struct __log_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return log(__x);}
+};
+
+template <class _Tp>
+struct __log10_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return log10(__x);}
+};
+
+template <class _Tp>
+struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x, const _Tp& __y) const
+        {return pow(__x, __y);}
+};
+
+template <class _Tp>
+struct __sin_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return sin(__x);}
+};
+
+template <class _Tp>
+struct __sinh_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return sinh(__x);}
+};
+
+template <class _Tp>
+struct __sqrt_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return sqrt(__x);}
+};
+
+template <class _Tp>
+struct __tan_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return tan(__x);}
+};
+
+template <class _Tp>
+struct __tanh_expr : unary_function<_Tp, _Tp>
+{
+    _LIBCPP_ALWAYS_INLINE
+    _Tp operator()(const _Tp& __x) const
+        {return tanh(__x);}
+};
+
+template <class _ValExpr>
+class __slice_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef value_type result_type;
+
+private:
+    _ValExpr __expr_;
+    size_t __start_;
+    size_t __size_;
+    size_t __stride_;
+
+    _LIBCPP_ALWAYS_INLINE
+    __slice_expr(const slice& __sl, const _RmExpr& __e)
+        : __expr_(__e),
+          __start_(__sl.start()),
+          __size_(__sl.size()),
+          __stride_(__sl.stride())
+        {}
+public:
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const
+        {return __expr_[__start_ + __i * __stride_];}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __size_;}
+
+    template <class> friend class valarray;
+};
+
+template <class _ValExpr>
+class __mask_expr;
+
+template <class _ValExpr>
+class __indirect_expr;
+
+template <class _ValExpr>
+class __shift_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef value_type result_type;
+
+private:
+    _ValExpr __expr_;
+    size_t __size_;
+    ptrdiff_t __ul_;
+    ptrdiff_t __sn_;
+    ptrdiff_t __n_;
+    static const ptrdiff_t _N = static_cast<ptrdiff_t>(
+                                    sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
+
+    _LIBCPP_ALWAYS_INLINE
+    __shift_expr(int __n, const _RmExpr& __e)
+        : __expr_(__e),
+          __size_(__e.size()),
+          __n_(__n)
+        {
+            ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _N);
+            __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _N);
+            __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
+        }
+public:
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __j) const
+        {
+            ptrdiff_t __i = static_cast<size_t>(__j);
+            ptrdiff_t __m = (__sn_ * __i - __ul_) >> _N;
+            return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
+        }
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __size_;}
+
+    template <class> friend class __val_expr;
+};
+
+template <class _ValExpr>
+class __cshift_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef value_type result_type;
+
+private:
+    _ValExpr __expr_;
+    size_t __size_;
+    size_t __m_;
+    size_t __o1_;
+    size_t __o2_;
+
+    _LIBCPP_ALWAYS_INLINE
+    __cshift_expr(int __n, const _RmExpr& __e)
+        : __expr_(__e),
+          __size_(__e.size())
+        {
+            __n %= static_cast<int>(__size_);
+            if (__n >= 0)
+            {
+                __m_ = __size_ - __n;
+                __o1_ = __n;
+                __o2_ = __n - __size_;
+            }
+            else
+            {
+                __m_ = -__n;
+                __o1_ = __n + __size_;
+                __o2_ = __n;
+            }
+        }
+public:
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const
+        {
+            if (__i < __m_)
+                return __expr_[__i + __o1_];
+            return __expr_[__i + __o2_];
+        }
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __size_;}
+
+    template <class> friend class __val_expr;
+};
+
+template<class _ValExpr>
+class __val_expr;
+
+template<class _ValExpr>
+struct __is_val_expr : false_type {};
+
+template<class _ValExpr>
+struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
+
+template<class _Tp>
+struct __is_val_expr<valarray<_Tp> > : true_type {};
+
+template<class _Tp>
+class valarray
+{
+public:
+    typedef _Tp value_type;
+    typedef _Tp result_type;
+
+private:
+    value_type* __begin_;
+    value_type* __end_;
+
+public:
+    // construct/destroy:
+    valarray() : __begin_(0), __end_(0) {}
+    explicit valarray(size_t __n);
+    valarray(const value_type& __x, size_t __n);
+    valarray(const value_type* __p, size_t __n);
+    valarray(const valarray& __v);
+#ifdef _LIBCPP_MOVE
+    valarray(valarray&& __v);
+    valarray(initializer_list<value_type> __il);
+#endif
+    valarray(const slice_array<value_type>& __sa);
+    valarray(const gslice_array<value_type>& __ga);
+    valarray(const mask_array<value_type>& __ma);
+    valarray(const indirect_array<value_type>& __ia);
+    ~valarray();
+
+    // assignment:
+    valarray& operator=(const valarray& __v);
+#ifdef _LIBCPP_MOVE
+    valarray& operator=(valarray&& __v);
+    valarray& operator=(initializer_list<value_type>);
+#endif
+    valarray& operator=(const value_type& __x);
+    valarray& operator=(const slice_array<value_type>& __sa);
+    valarray& operator=(const gslice_array<value_type>& __ga);
+    valarray& operator=(const mask_array<value_type>& __ma);
+    valarray& operator=(const indirect_array<value_type>& __ia);
+
+    // element access:
+    _LIBCPP_ALWAYS_INLINE
+    const value_type& operator[](size_t __i) const {return __begin_[__i];}
+
+    _LIBCPP_ALWAYS_INLINE
+    value_type&       operator[](size_t __i)       {return __begin_[__i];}
+
+    // subset operations:
+    __val_expr<__slice_expr<const valarray&> >    operator[](slice __s) const;
+    slice_array<value_type>                       operator[](slice __s);
+    __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
+    gslice_array<value_type>   operator[](const gslice& __gs);
+#ifdef _LIBCPP_MOVE
+    __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
+    gslice_array<value_type>                      operator[](gslice&& __gs);
+#endif
+    __val_expr<__mask_expr<const valarray&> >     operator[](const valarray<bool>& __vb) const;
+    mask_array<value_type>                        operator[](const valarray<bool>& __vb);
+#ifdef _LIBCPP_MOVE
+    __val_expr<__mask_expr<const valarray&> >     operator[](valarray<bool>&& __vb) const;
+    mask_array<value_type>                        operator[](valarray<bool>&& __vb);
+#endif
+    __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
+    indirect_array<value_type>                    operator[](const valarray<size_t>& __vs);
+#ifdef _LIBCPP_MOVE
+    __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
+    indirect_array<value_type>                    operator[](valarray<size_t>&& __vs);
+#endif
+
+    // unary operators:
+    valarray       operator+() const;
+    valarray       operator-() const;
+    valarray       operator~() const;
+    valarray<bool> operator!() const;
+
+    // computed assignment:
+    valarray& operator*= (const value_type& __x);
+    valarray& operator/= (const value_type& __x);
+    valarray& operator%= (const value_type& __x);
+    valarray& operator+= (const value_type& __x);
+    valarray& operator-= (const value_type& __x);
+    valarray& operator^= (const value_type& __x);
+    valarray& operator&= (const value_type& __x);
+    valarray& operator|= (const value_type& __x);
+    valarray& operator<<=(const value_type& __x);
+    valarray& operator>>=(const value_type& __x);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator*= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator/= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator%= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator+= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator-= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator^= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator|= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator&= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator<<= (const _Expr& __v);
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        valarray&
+    >::type
+    operator>>= (const _Expr& __v);
+
+    // member functions:
+    void swap(valarray& __v);
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __end_ - __begin_;}
+
+    value_type sum() const;
+    value_type min() const;
+    value_type max() const;
+
+    valarray shift (int __i) const;
+    valarray cshift(int __i) const;
+    valarray apply(value_type __f(value_type)) const;
+    valarray apply(value_type __f(const value_type&)) const;
+    void     resize(size_t __n, value_type __x = value_type());
+
+private:
+    template <class> friend class valarray;
+    template <class> friend class slice_array;
+    template <class> friend class gslice_array;
+    template <class> friend class mask_array;
+    template <class> friend class __mask_expr;
+    template <class> friend class indirect_array;
+    template <class> friend class __indirect_expr;
+    template <class> friend class __val_expr;
+
+    template <class _Up>
+    friend
+    _Up*
+    begin(valarray<_Up>& __v);
+    
+    template <class _Up>
+    friend
+    const _Up*
+    begin(const valarray<_Up>& __v);
+    
+    template <class _Up>
+    friend
+    _Up*
+    end(valarray<_Up>& __v);
+    
+    template <class _Up>
+    friend
+    const _Up*
+    end(const valarray<_Up>& __v);
+};
+
+template <class _Op, class _Tp>
+struct _UnaryOp<_Op, valarray<_Tp> >
+{
+    typedef typename _Op::result_type result_type;
+    typedef _Tp value_type;
+
+    _Op __op_;
+    const valarray<_Tp>& __a0_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+template <class _Op, class _Tp, class _A1>
+struct _BinaryOp<_Op, valarray<_Tp>, _A1>
+{
+    typedef typename _Op::result_type result_type;
+    typedef _Tp value_type;
+
+    _Op __op_;
+    const valarray<_Tp>& __a0_;
+    _A1 __a1_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
+        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+template <class _Op, class _A0, class _Tp>
+struct _BinaryOp<_Op, _A0, valarray<_Tp> >
+{
+    typedef typename _Op::result_type result_type;
+    typedef _Tp value_type;
+
+    _Op __op_;
+    _A0 __a0_;
+    const valarray<_Tp>& __a1_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
+        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+template <class _Op, class _Tp>
+struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
+{
+    typedef typename _Op::result_type result_type;
+    typedef _Tp value_type;
+
+    _Op __op_;
+    const valarray<_Tp>& __a0_;
+    const valarray<_Tp>& __a1_;
+
+    _LIBCPP_ALWAYS_INLINE
+    _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
+        : __op_(__op), __a0_(__a0), __a1_(__a1) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __a0_.size();}
+};
+
+// slice_array
+
+template <class _Tp>
+class slice_array
+{
+public:
+    typedef _Tp value_type;
+
+private:
+    value_type* __vp_;
+    size_t __size_;
+    size_t __stride_;
+
+public:
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator*=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator/=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator%=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator+=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator-=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator^=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator&=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator|=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator<<=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator>>=(const _Expr& __v) const;
+
+    const slice_array& operator=(const slice_array& __sa) const;
+
+    void operator=(const value_type& __x) const;
+
+private:
+    slice_array(const slice& __sl, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
+          __size_(__sl.size()),
+          __stride_(__sl.stride())
+        {}
+
+    template <class> friend class valarray;
+    template <class> friend class sliceExpr;
+};
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const slice_array<_Tp>&
+slice_array<_Tp>::operator=(const slice_array& __sa) const
+{
+    value_type* __t = __vp_;
+    const value_type* __s = __sa.__vp_;
+    for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
+        *__t = *__s;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t = __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator*=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t *= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator/=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t /= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator%=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t %= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator+=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t += __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator-=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t -= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator^=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t ^= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator&=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t &= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator|=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t |= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator<<=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t <<= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+slice_array<_Tp>::operator>>=(const _Expr& __v) const
+{
+    value_type* __t = __vp_;
+    for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
+        *__t >>= __v[__i];
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+slice_array<_Tp>::operator=(const value_type& __x) const
+{
+    value_type* __t = __vp_;
+    for (size_t __n = __size_; __n; --__n, __t += __stride_)
+        *__t = __x;
+}
+
+// gslice
+
+class gslice
+{
+    valarray<size_t> __size_;
+    valarray<size_t> __stride_;
+    valarray<size_t> __1d_;
+    
+public:
+    _LIBCPP_ALWAYS_INLINE
+    gslice() {}
+
+    _LIBCPP_ALWAYS_INLINE
+    gslice(size_t __start, const valarray<size_t>& __size,
+                           const valarray<size_t>& __stride)
+        : __size_(__size),
+          __stride_(__stride)
+        {__init(__start);}
+
+#ifdef _LIBCPP_MOVE
+
+    _LIBCPP_ALWAYS_INLINE
+    gslice(size_t __start, const valarray<size_t>&  __size,
+                                 valarray<size_t>&& __stride)
+        : __size_(__size),
+          __stride_(move(__stride))
+        {__init(__start);}
+
+    _LIBCPP_ALWAYS_INLINE
+    gslice(size_t __start,       valarray<size_t>&& __size,
+                           const valarray<size_t>&  __stride)
+        : __size_(move(__size)),
+          __stride_(__stride)
+        {__init(__start);}
+
+    _LIBCPP_ALWAYS_INLINE
+    gslice(size_t __start,       valarray<size_t>&& __size,
+                                 valarray<size_t>&& __stride)
+        : __size_(move(__size)),
+          __stride_(move(__stride))
+        {__init(__start);}
+
+#endif
+
+//  gslice(const gslice&)            = default;
+//  gslice(gslice&&)                 = default;
+//  gslice& operator=(const gslice&) = default;
+//  gslice& operator=(gslice&&)      = default;
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t           start()  const {return __1d_.size() ? __1d_[0] : 0;}
+
+    _LIBCPP_ALWAYS_INLINE
+    valarray<size_t> size()   const {return __size_;}
+
+    _LIBCPP_ALWAYS_INLINE
+    valarray<size_t> stride() const {return __stride_;}
+
+private:
+    void __init(size_t __start);
+
+    template <class> friend class gslice_array;
+    template <class> friend class valarray;
+    template <class> friend class __val_expr;
+};
+
+// gslice_array
+
+template <class _Tp>
+class gslice_array
+{
+public:
+    typedef _Tp value_type;
+
+private:
+    value_type*      __vp_;
+    valarray<size_t> __1d_;
+
+public:
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator*=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator/=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator%=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator+=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator-=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator^=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator&=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator|=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator<<=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator>>=(const _Expr& __v) const;
+
+    const gslice_array& operator=(const gslice_array& __ga) const;
+
+    void operator=(const value_type& __x) const;
+
+//  gslice_array(const gslice_array&)            = default;
+//  gslice_array(gslice_array&&)                 = default;
+//  gslice_array& operator=(const gslice_array&) = default;
+//  gslice_array& operator=(gslice_array&&)      = default;
+
+private:
+    _LIBCPP_ALWAYS_INLINE
+    gslice_array(const gslice& __gs, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_)),
+          __1d_(__gs.__1d_)
+        {}
+
+#ifdef _LIBCPP_MOVE
+
+    _LIBCPP_ALWAYS_INLINE
+    gslice_array(gslice&& __gs, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_)),
+          __1d_(move(__gs.__1d_))
+        {}
+
+#endif
+
+    template <class> friend class valarray;
+};
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] = __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator*=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] *= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator/=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] /= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator%=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] %= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator+=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] += __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator-=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] -= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator^=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] ^= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator&=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] &= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator|=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] |= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator<<=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] <<= __v[__j];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+gslice_array<_Tp>::operator>>=(const _Expr& __v) const
+{
+    typedef const size_t* _Ip;
+    size_t __j = 0;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
+        __vp_[*__i] >>= __v[__j];
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const gslice_array<_Tp>&
+gslice_array<_Tp>::operator=(const gslice_array& __ga) const
+{
+    typedef const size_t* _Ip;
+    const value_type* __s = __ga.__vp_;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
+            __i != __e; ++__i, ++__j)
+        __vp_[*__i] = __s[*__j];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+gslice_array<_Tp>::operator=(const value_type& __x) const
+{
+    typedef const size_t* _Ip;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
+        __vp_[*__i] = __x;
+}
+
+// mask_array
+
+template <class _Tp>
+class mask_array
+{
+public:
+    typedef _Tp value_type;
+
+private:
+    value_type*      __vp_;
+    valarray<size_t> __1d_;
+
+public:
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator*=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator/=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator%=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator+=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator-=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator^=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator&=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator|=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator<<=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator>>=(const _Expr& __v) const;
+
+    const mask_array& operator=(const mask_array& __ma) const;
+
+    void operator=(const value_type& __x) const;
+
+//  mask_array(const mask_array&)            = default;
+//  mask_array(mask_array&&)                 = default;
+//  mask_array& operator=(const mask_array&) = default;
+//  mask_array& operator=(mask_array&&)      = default;
+
+private:
+    _LIBCPP_ALWAYS_INLINE
+    mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_)),
+          __1d_(count(__vb.__begin_, __vb.__end_, true))
+          {
+              size_t __j = 0;
+              for (size_t __i = 0; __i < __vb.size(); ++__i)
+                  if (__vb[__i])
+                      __1d_[__j++] = __i;
+          }
+
+    template <class> friend class valarray;
+};
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] = __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator*=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] *= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator/=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] /= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator%=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] %= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator+=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] += __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator-=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] -= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator^=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] ^= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator&=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] &= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator|=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] |= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator<<=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] <<= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+mask_array<_Tp>::operator>>=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] >>= __v[__i];
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const mask_array<_Tp>&
+mask_array<_Tp>::operator=(const mask_array& __ma) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+mask_array<_Tp>::operator=(const value_type& __x) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] = __x;
+}
+
+template <class _ValExpr>
+class __mask_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef value_type result_type;
+
+private:
+    _ValExpr __expr_;
+    valarray<size_t> __1d_;
+
+    _LIBCPP_ALWAYS_INLINE
+    __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
+        : __expr_(__e),
+          __1d_(count(__vb.__begin_, __vb.__end_, true))
+          {
+              size_t __j = 0;
+              for (size_t __i = 0; __i < __vb.size(); ++__i)
+                  if (__vb[__i])
+                      __1d_[__j++] = __i;
+          }
+
+public:
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const
+        {return __expr_[__1d_[__i]];}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __1d_.size();}
+
+    template <class> friend class valarray;
+};
+
+// indirect_array
+
+template <class _Tp>
+class indirect_array
+{
+public:
+    typedef _Tp value_type;
+
+private:
+    value_type*      __vp_;
+    valarray<size_t> __1d_;
+
+public:
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator*=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator/=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator%=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator+=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator-=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator^=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator&=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator|=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator<<=(const _Expr& __v) const;
+
+    template <class _Expr>
+    typename enable_if
+    <
+        __is_val_expr<_Expr>::value,
+        void
+    >::type
+    operator>>=(const _Expr& __v) const;
+
+    const indirect_array& operator=(const indirect_array& __ia) const;
+
+    void operator=(const value_type& __x) const;
+
+//  indirect_array(const indirect_array&)            = default;
+//  indirect_array(indirect_array&&)                 = default;
+//  indirect_array& operator=(const indirect_array&) = default;
+//  indirect_array& operator=(indirect_array&&)      = default;
+
+private:
+     _LIBCPP_ALWAYS_INLINE
+   indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_)),
+          __1d_(__ia)
+        {}
+
+#ifdef _LIBCPP_MOVE
+
+    _LIBCPP_ALWAYS_INLINE
+    indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
+        : __vp_(const_cast<value_type*>(__v.__begin_)),
+          __1d_(move(__ia))
+        {}
+
+#endif
+
+    template <class> friend class valarray;
+};
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] = __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator*=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] *= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator/=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] /= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator%=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] %= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator+=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] += __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator-=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] -= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator^=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] ^= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator&=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] &= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator|=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] |= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator<<=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] <<= __v[__i];
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    void
+>::type
+indirect_array<_Tp>::operator>>=(const _Expr& __v) const
+{
+    size_t __n = __1d_.size();
+    for (size_t __i = 0; __i < __n; ++__i)
+        __vp_[__1d_[__i]] >>= __v[__i];
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const indirect_array<_Tp>&
+indirect_array<_Tp>::operator=(const indirect_array& __ia) const
+{
+    typedef const size_t* _Ip;
+    const value_type* __s = __ia.__vp_;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
+            __i != __e; ++__i, ++__j)
+        __vp_[*__i] = __s[*__j];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+indirect_array<_Tp>::operator=(const value_type& __x) const
+{
+    typedef const size_t* _Ip;
+    for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
+        __vp_[*__i] = __x;
+}
+
+template <class _ValExpr>
+class __indirect_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef value_type result_type;
+
+private:
+    _ValExpr __expr_;
+    valarray<size_t> __1d_;
+
+    __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
+        : __expr_(__e),
+          __1d_(__ia)
+          {}
+
+#ifdef _LIBCPP_MOVE
+
+    __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
+        : __expr_(__e),
+          __1d_(move(__ia))
+          {}
+
+#endif
+
+public:
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const
+        {return __expr_[__1d_[__i]];}
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __1d_.size();}
+
+    template <class> friend class valarray;
+};
+
+template<class _ValExpr>
+class __val_expr
+{
+    typedef typename remove_reference<_ValExpr>::type  _RmExpr;
+
+    _ValExpr __expr_;
+public:
+    typedef typename _RmExpr::value_type value_type;
+    typedef typename _RmExpr::result_type result_type;
+
+    _LIBCPP_ALWAYS_INLINE
+    explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type operator[](size_t __i) const
+        {return __expr_[__i];}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
+        {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
+        {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
+        {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
+        {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
+    operator+() const
+    {
+        typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
+    operator-() const
+    {
+        typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
+    operator~() const
+    {
+        typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
+    operator!() const
+    {
+        typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
+    }
+
+    operator valarray<result_type>() const;
+
+    _LIBCPP_ALWAYS_INLINE
+    size_t size() const {return __expr_.size();}
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type sum() const
+    {
+        size_t __n = __expr_.size();
+        result_type __r = __n ? __expr_[0] : result_type();
+        for (size_t __i = 1; __i < __n; ++__i)
+            __r += __expr_[__i];
+        return __r;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type min() const
+    {
+        size_t __n = size();
+        result_type __r = __n ? (*this)[0] : result_type();
+        for (size_t __i = 1; __i < __n; ++__i)
+        {
+            result_type __x = __expr_[__i];
+            if (__x < __r)
+                __r = __x;
+        }
+        return __r;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    result_type max() const
+    {
+        size_t __n = size();
+        result_type __r = __n ? (*this)[0] : result_type();
+        for (size_t __i = 1; __i < __n; ++__i)
+        {
+            result_type __x = __expr_[__i];
+            if (__r < __x)
+                __r = __x;
+        }
+        return __r;
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__shift_expr<_ValExpr> > shift (int __i) const
+        {return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
+        {return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
+    apply(value_type __f(value_type)) const
+    {
+        typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
+        typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
+    }
+
+    _LIBCPP_ALWAYS_INLINE
+    __val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
+    apply(value_type __f(const value_type&)) const
+    {
+        typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
+        typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
+        return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
+    }
+};
+
+template<class _ValExpr>
+__val_expr<_ValExpr>::operator valarray<result_type>() const
+{
+    valarray<result_type> __r;
+    size_t __n = __expr_.size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
+        for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
+            ::new (__r.__end_) result_type(__expr_[__i]);
+    }
+    return __r;
+}
+
+// valarray
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>::valarray(size_t __n)
+    : __begin_(0),
+      __end_(0)
+{
+    resize(__n);
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>::valarray(const value_type& __x, size_t __n)
+    : __begin_(0),
+      __end_(0)
+{
+    resize(__n, __x);
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(const value_type* __p, size_t __n)
+    : __begin_(0),
+      __end_(0)
+{
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (; __n; ++__end_, ++__p, --__n)
+                ::new (__end_) value_type(*__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(const valarray& __v)
+    : __begin_(0),
+      __end_(0)
+{
+    if (__v.size())
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
+                ::new (__end_) value_type(*__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>::valarray(valarray&& __v)
+    : __begin_(__v.__begin_),
+      __end_(__v.__end_)
+{
+    __v.__begin_ = __v.__end_ = nullptr;
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(initializer_list<value_type> __il)
+    : __begin_(0),
+      __end_(0)
+{
+    size_t __n = __il.size();
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (const value_type* __p = __il.begin(); __n; ++__end_, ++__p, --__n)
+                ::new (__end_) value_type(*__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+#endif
+
+template <class _Tp>
+valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
+    : __begin_(0),
+      __end_(0)
+{
+    size_t __n = __sa.__size_;
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (const value_type* __p = __sa.__vp_; __n; ++__end_, __p += __sa.__stride_, --__n)
+                ::new (__end_) value_type(*__p);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
+    : __begin_(0),
+      __end_(0)
+{
+    size_t __n = __ga.__1d_.size();
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            typedef const size_t* _Ip;
+            const value_type* __s = __ga.__vp_;
+            for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
+                    __i != __e; ++__i, ++__end_)
+                ::new (__end_) value_type(__s[*__i]);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
+    : __begin_(0),
+      __end_(0)
+{
+    size_t __n = __ma.__1d_.size();
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            typedef const size_t* _Ip;
+            const value_type* __s = __ma.__vp_;
+            for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
+                    __i != __e; ++__i, ++__end_)
+                ::new (__end_) value_type(__s[*__i]);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template <class _Tp>
+valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
+    : __begin_(0),
+      __end_(0)
+{
+    size_t __n = __ia.__1d_.size();
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            typedef const size_t* _Ip;
+            const value_type* __s = __ia.__vp_;
+            for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
+                    __i != __e; ++__i, ++__end_)
+                ::new (__end_) value_type(__s[*__i]);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>::~valarray()
+{
+    resize(0);
+}
+
+template <class _Tp>
+valarray<_Tp>&
+valarray<_Tp>::operator=(const valarray& __v)
+{
+    if (this != &__v)
+    {
+        if (size() != __v.size())
+            resize(__v.size());
+        _STD::copy(__v.__begin_, __v.__end_, __begin_);
+    }
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(valarray&& __v)
+{
+    resize(0);
+    __begin_ = __v.__begin_;
+    __end_ = __v.__end_;
+    __v.__begin_ = nullptr;
+    __v.__end_ = nullptr;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(initializer_list<value_type> __il)
+{
+    if (size() != __il.size())
+        resize(__il.size());
+    _STD::copy(__il.begin(), __il.end(), __begin_);
+    return *this;
+}
+
+#endif
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(const value_type& __x)
+{
+    _STD::fill(__begin_, __end_, __x);
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
+{
+    value_type* __t = __begin_;
+    const value_type* __s = __sa.__vp_;
+    for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
+        *__t = *__s;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
+{
+    typedef const size_t* _Ip;
+    value_type* __t = __begin_;
+    const value_type* __s = __ga.__vp_;
+    for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
+                    __i != __e; ++__i, ++__t)
+        *__t = __s[*__i];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
+{
+    typedef const size_t* _Ip;
+    value_type* __t = __begin_;
+    const value_type* __s = __ma.__vp_;
+    for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
+                    __i != __e; ++__i, ++__t)
+        *__t = __s[*__i];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
+{
+    typedef const size_t* _Ip;
+    value_type* __t = __begin_;
+    const value_type* __s = __ia.__vp_;
+    for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
+                    __i != __e; ++__i, ++__t)
+        *__t = __s[*__i];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__slice_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](slice __s) const
+{
+    return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+slice_array<_Tp>
+valarray<_Tp>::operator[](slice __s)
+{
+    return slice_array<value_type>(__s, *this);
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__indirect_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](const gslice& __gs) const
+{
+    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+gslice_array<_Tp>
+valarray<_Tp>::operator[](const gslice& __gs)
+{
+    return gslice_array<value_type>(__gs, *this);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__indirect_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](gslice&& __gs) const
+{
+    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+gslice_array<_Tp>
+valarray<_Tp>::operator[](gslice&& __gs)
+{
+    return gslice_array<value_type>(move(__gs), *this);
+}
+
+#endif
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__mask_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](const valarray<bool>& __vb) const
+{
+    return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+mask_array<_Tp>
+valarray<_Tp>::operator[](const valarray<bool>& __vb)
+{
+    return mask_array<value_type>(__vb, *this);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__mask_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](valarray<bool>&& __vb) const
+{
+    return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+mask_array<_Tp>
+valarray<_Tp>::operator[](valarray<bool>&& __vb)
+{
+    return mask_array<value_type>(move(__vb), *this);
+}
+
+#endif
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__indirect_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
+{
+    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+indirect_array<_Tp>
+valarray<_Tp>::operator[](const valarray<size_t>& __vs)
+{
+    return indirect_array<value_type>(__vs, *this);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+__val_expr<__indirect_expr<const valarray<_Tp>&> >
+valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
+{
+    return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+indirect_array<_Tp>
+valarray<_Tp>::operator[](valarray<size_t>&& __vs)
+{
+    return indirect_array<value_type>(move(__vs), *this);
+}
+
+#endif
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::operator+() const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) value_type(+*__p);
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::operator-() const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) value_type(-*__p);
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::operator~() const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) value_type(~*__p);
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<bool>
+valarray<_Tp>::operator!() const
+{
+    valarray<bool> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<bool*>(::operator new(__n * sizeof(bool)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) bool(!*__p);
+    }
+    return __r;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator*=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p *= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator/=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p /= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator%=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p %= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator+=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p += __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator-=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p -= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator^=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p ^= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator&=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p &= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator|=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p |= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator<<=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p <<= __x;
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+valarray<_Tp>&
+valarray<_Tp>::operator>>=(const value_type& __x)
+{
+    for (value_type* __p = __begin_; __p != __end_; ++__p)
+        *__p >>= __x;
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator*=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t *= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator/=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t /= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator%=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t %= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator+=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t += __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator-=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t -= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator^=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t ^= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator|=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t |= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator&=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t &= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator<<=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t <<= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+template <class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    valarray<_Tp>&
+>::type
+valarray<_Tp>::operator>>=(const _Expr& __v)
+{
+    size_t __i = 0;
+    for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
+        *__t >>= __v[__i];
+    return *this;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+valarray<_Tp>::swap(valarray& __v)
+{
+    _STD::swap(__begin_, __v.__begin_);
+    _STD::swap(__end_, __v.__end_);
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+_Tp
+valarray<_Tp>::sum() const
+{
+    if (__begin_ == __end_)
+        return value_type();
+    const value_type* __p = __begin_;
+    _Tp __r = *__p;
+    for (++__p; __p != __end_; ++__p)
+        __r += *__p;
+    return __r;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+_Tp
+valarray<_Tp>::min() const
+{
+    if (__begin_ == __end_)
+        return value_type();
+    return *_STD::min_element(__begin_, __end_);
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+_Tp
+valarray<_Tp>::max() const
+{
+    if (__begin_ == __end_)
+        return value_type();
+    return *_STD::max_element(__begin_, __end_);
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::shift(int __i) const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        const value_type* __sb;
+        value_type* __tb;
+        value_type* __te;
+        if (__i >= 0)
+        {
+            __i = _STD::min(__i, static_cast<int>(__n));
+            __sb = __begin_ + __i;
+            __tb = __r.__begin_;
+            __te = __r.__begin_ + (__n - __i);
+        }
+        else
+        {
+            __i = _STD::min(-__i, static_cast<int>(__n));
+            __sb = __begin_;
+            __tb = __r.__begin_ + __i;
+            __te = __r.__begin_ + __n;
+        }
+        for (; __r.__end_ != __tb; ++__r.__end_)
+            ::new (__r.__end_) value_type();
+        for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
+            ::new (__r.__end_) value_type(*__sb);
+        for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
+            ::new (__r.__end_) value_type();
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::cshift(int __i) const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        __i %= static_cast<int>(__n);
+        const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
+        for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
+            ::new (__r.__end_) value_type(*__s);
+        for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
+            ::new (__r.__end_) value_type(*__s);
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::apply(value_type __f(value_type)) const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) value_type(__f(*__p));
+    }
+    return __r;
+}
+
+template <class _Tp>
+valarray<_Tp>
+valarray<_Tp>::apply(value_type __f(const value_type&)) const
+{
+    valarray<value_type> __r;
+    size_t __n = size();
+    if (__n)
+    {
+        __r.__begin_ =
+            __r.__end_ =
+                static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+        for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
+            ::new (__r.__end_) value_type(__f(*__p));
+    }
+    return __r;
+}
+
+template <class _Tp>
+void
+valarray<_Tp>::resize(size_t __n, value_type __x)
+{
+    if (__begin_ != nullptr)
+    {
+        while (__end_ != __begin_)
+            (--__end_)->~value_type();
+        ::operator delete(__begin_);
+        __begin_ = __end_ = nullptr;
+    }
+    if (__n)
+    {
+        __begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            for (; __n; --__n, ++__end_)
+                ::new (__end_) value_type(__x);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            resize(0);
+            throw;
+        }
+#endif
+    }
+}
+
+template<class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+void
+swap(valarray<_Tp>& __x, valarray<_Tp>& __y)
+{
+    __x.swap(__y);
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator*(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator*(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(multiplies<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator*(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(multiplies<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator/(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator/(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(divides<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<divides<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator/(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(divides<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator%(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator%(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(modulus<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator%(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(modulus<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator+(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator+(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(plus<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<plus<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator+(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(plus<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator-(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator-(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(minus<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<minus<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator-(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(minus<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator^(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator^(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(bit_xor<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator^(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(bit_xor<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator&(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator&(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(bit_and<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator&(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(bit_and<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator|(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator|(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(bit_or<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator|(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(bit_or<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator<<(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator>>(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator&&(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(logical_and<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(logical_and<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator||(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator||(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(logical_or<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator||(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(logical_or<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator==(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator==(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(equal_to<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator==(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(equal_to<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator!=(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator<(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<less<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator<(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(less<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<less<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator<(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(less<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator>(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator>(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(greater<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<greater<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator>(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(greater<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator<=(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(less_equal<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(less_equal<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+operator>=(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(greater_equal<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(greater_equal<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
+>::type
+abs(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
+>::type
+acos(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
+>::type
+asin(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
+>::type
+atan(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+atan2(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+atan2(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+atan2(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
+>::type
+cos(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
+>::type
+cosh(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
+>::type
+exp(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
+>::type
+log(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
+>::type
+log10(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
+}
+
+template<class _Expr1, class _Expr2>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
+    __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
+>::type
+pow(const _Expr1& __x, const _Expr2& __y)
+{
+    typedef typename _Expr1::value_type value_type;
+    typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
+    return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
+               _Expr, __scalar_expr<typename _Expr::value_type> > >
+>::type
+pow(const _Expr& __x, const typename _Expr::value_type& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
+    return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
+                           __x, __scalar_expr<value_type>(__y, __x.size())));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
+               __scalar_expr<typename _Expr::value_type>, _Expr> >
+>::type
+pow(const typename _Expr::value_type& __x, const _Expr& __y)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
+                           __scalar_expr<value_type>(__x, __y.size()), __y));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
+>::type
+sin(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
+>::type
+sinh(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
+>::type
+sqrt(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
+>::type
+tan(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
+}
+
+template<class _Expr>
+inline _LIBCPP_ALWAYS_INLINE
+typename enable_if
+<
+    __is_val_expr<_Expr>::value,
+    __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
+>::type
+tanh(const _Expr& __x)
+{
+    typedef typename _Expr::value_type value_type;
+    typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
+    return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+_Tp*
+begin(valarray<_Tp>& __v)
+{
+    return __v.__begin_;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const _Tp*
+begin(const valarray<_Tp>& __v)
+{
+    return __v.__begin_;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+_Tp*
+end(valarray<_Tp>& __v)
+{
+    return __v.__end_;
+}
+
+template <class _Tp>
+inline _LIBCPP_ALWAYS_INLINE
+const _Tp*
+end(const valarray<_Tp>& __v)
+{
+    return __v.__end_;
+}
+
+extern template valarray<size_t>::valarray(size_t);
+extern template valarray<size_t>::~valarray();
+extern template void valarray<size_t>::resize(size_t, size_t);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_VALARRAY
diff --git a/include/vector b/include/vector
new file mode 100644
index 0000000..8910987
--- /dev/null
+++ b/include/vector
@@ -0,0 +1,2783 @@
+// -*- C++ -*-
+//===------------------------------ vector --------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_VECTOR
+#define _LIBCPP_VECTOR
+
+/*
+    vector synopsis
+
+namespace std
+{
+
+template <class T, class Allocator = allocator<T> > 
+class vector
+{ 
+public: 
+    typedef T                                        value_type; 
+    typedef Allocator                                allocator_type;
+    typedef typename allocator_type::reference       reference;
+    typedef typename allocator_type::const_reference const_reference;
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef typename allocator_type::pointer         pointer;
+    typedef typename allocator_type::const_pointer   const_pointer;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    explicit vector(const allocator_type& = allocator_type());
+    explicit vector(size_type n);
+    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
+    template <class InputIterator>
+        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
+    vector(const vector& x);
+    vector(vector&& x);
+    vector(initializer_list<value_type> il);
+    vector(initializer_list<value_type> il, const allocator_type& a);
+    ~vector();
+    vector& operator=(const vector& x);
+    vector& operator=(vector&& x);
+    vector& operator=(initializer_list<value_type> il);
+    template <class InputIterator>
+        void assign(InputIterator first, InputIterator last);
+    void assign(size_type n, const value_type& u);
+    void assign(initializer_list<value_type> il);
+
+    allocator_type get_allocator() const;
+
+    iterator               begin();
+    const_iterator         begin()   const;
+    iterator               end();
+    const_iterator         end()     const;
+
+    reverse_iterator       rbegin();
+    const_reverse_iterator rbegin()  const;
+    reverse_iterator       rend();
+    const_reverse_iterator rend()    const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    size_type size() const;
+    size_type max_size() const;
+    size_type capacity() const;
+    bool empty() const;
+    void reserve(size_type n);
+    void shrink_to_fit();
+
+    reference       operator[](size_type n);
+    const_reference operator[](size_type n) const;
+    reference       at(size_type n);
+    const_reference at(size_type n) const;
+
+    reference       front();
+    const_reference front() const;
+    reference       back();
+    const_reference back() const;
+
+    value_type*       data();
+    const value_type* data() const;
+
+    void push_back(const value_type& x);
+    void push_back(value_type&& x);
+    template <class... Args>
+        void emplace_back(Args&&... args);
+    void pop_back();
+
+    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
+    iterator insert(const_iterator position, const value_type& x);
+    iterator insert(const_iterator position, value_type&& x);
+    iterator insert(const_iterator position, size_type n, const value_type& x);
+    template <class InputIterator>
+        iterator insert(const_iterator position, InputIterator first, InputIterator last);
+    iterator insert(const_iterator position, initializer_list<value_type> il);
+
+    iterator erase(const_iterator position);
+    iterator erase(const_iterator first, const_iterator last);
+
+    void clear();
+
+    void resize(size_type sz);
+    void resize(size_type sz, const value_type& c);
+
+    void swap(vector&);
+
+    bool __invariants() const;
+}; 
+
+template <class Allocator = allocator<T> > 
+class vector<bool, Allocator>
+{ 
+public: 
+    typedef bool                                     value_type; 
+    typedef Allocator                                allocator_type;
+    typedef implementation-defined                   iterator;
+    typedef implementation-defined                   const_iterator;
+    typedef typename allocator_type::size_type       size_type;
+    typedef typename allocator_type::difference_type difference_type;
+    typedef iterator                                 pointer;
+    typedef const_iterator                           const_pointer;
+    typedef std::reverse_iterator<iterator>          reverse_iterator;
+    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+
+    class reference
+    {
+    public:
+        reference(const reference&);
+        operator bool() const;
+        reference& operator=(const bool x);
+        reference& operator=(const reference& x);
+        iterator operator&() const;
+        void flip();
+    };
+
+    class const_reference
+    {
+    public:
+        const_reference(const reference&);
+        operator bool() const;
+        const_iterator operator&() const;
+    };
+
+    explicit vector(const allocator_type& = allocator_type());
+    explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type());
+    template <class InputIterator>
+        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
+    vector(const vector& x);
+    vector(vector&& x);
+    vector(initializer_list<value_type> il);
+    vector(initializer_list<value_type> il, const allocator_type& a);
+    ~vector();
+    vector& operator=(const vector& x);
+    vector& operator=(vector&& x);
+    vector& operator=(initializer_list<value_type> il);
+    template <class InputIterator>
+        void assign(InputIterator first, InputIterator last);
+    void assign(size_type n, const value_type& u);
+    void assign(initializer_list<value_type> il);
+
+    allocator_type get_allocator() const;
+
+    iterator               begin();
+    const_iterator         begin()   const;
+    iterator               end();
+    const_iterator         end()     const;
+
+    reverse_iterator       rbegin();
+    const_reverse_iterator rbegin()  const;
+    reverse_iterator       rend();
+    const_reverse_iterator rend()    const;
+
+    const_iterator         cbegin()  const;
+    const_iterator         cend()    const;
+    const_reverse_iterator crbegin() const;
+    const_reverse_iterator crend()   const;
+
+    size_type size() const;
+    size_type max_size() const;
+    size_type capacity() const;
+    bool empty() const;
+    void reserve(size_type n);
+    void shrink_to_fit();
+
+    reference       operator[](size_type n);
+    const_reference operator[](size_type n) const;
+    reference       at(size_type n);
+    const_reference at(size_type n) const;
+
+    reference       front();
+    const_reference front() const;
+    reference       back();
+    const_reference back() const;
+
+    void push_back(const value_type& x);
+    void pop_back();
+
+    iterator insert(const_iterator position, const value_type& x);
+    iterator insert(const_iterator position, size_type n, const value_type& x);
+    template <class InputIterator>
+        iterator insert(const_iterator position, InputIterator first, InputIterator last);
+    iterator insert(const_iterator position, initializer_list<value_type> il);
+
+    iterator erase(const_iterator position);
+    iterator erase(const_iterator first, const_iterator last);
+
+    void clear();
+
+    void resize(size_type sz);
+    void resize(size_type sz, value_type x);
+
+    void swap(vector&);
+    void flip();
+
+    bool __invariants() const;
+}; 
+
+template <class Allocator> struct hash<std::vector<bool, Allocator>>;
+
+template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
+
+template <class T, class Allocator> void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);
+
+}  // std
+
+*/
+
+#include <__config>
+#include <__bit_reference>
+#include <type_traits>
+#include <climits>
+#include <limits>
+#include <initializer_list>
+#include <memory>
+#include <stdexcept>
+#include <algorithm>
+#include <cstring>
+#include <__split_buffer>
+#include <__functional_base>
+#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_NO_EXCEPTIONS)
+    #include <cassert>
+#endif
+
+#pragma GCC system_header
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <bool>
+class __vector_base_common
+{
+protected:
+    _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
+    void __throw_length_error() const;
+    void __throw_out_of_range() const;
+};
+
+template <bool __b>
+void
+__vector_base_common<__b>::__throw_length_error() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw length_error("vector");
+#else
+    assert(!"vector length_error");
+#endif
+}
+
+template <bool __b>
+void
+__vector_base_common<__b>::__throw_out_of_range() const
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    throw out_of_range("vector");
+#else
+    assert(!"vector out_of_range");
+#endif
+}
+
+extern template class __vector_base_common<true>;
+
+template <class _Tp, class _Allocator>
+class __vector_base
+    : protected __vector_base_common<true>
+{
+protected:
+    typedef _Tp                                      value_type; 
+    typedef _Allocator                               allocator_type;
+    typedef allocator_traits<allocator_type>         __alloc_traits;
+    typedef value_type&                              reference;
+    typedef const value_type&                        const_reference;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+    typedef typename __alloc_traits::pointer         pointer;
+    typedef typename __alloc_traits::const_pointer   const_pointer;
+    typedef pointer                                  iterator;
+    typedef const_pointer                            const_iterator;
+
+    pointer                                         __begin_;
+    pointer                                         __end_;
+    __compressed_pair<pointer, allocator_type> __end_cap_;
+
+    _LIBCPP_INLINE_VISIBILITY allocator_type&       __alloc()         {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const   {return __end_cap_.second();}
+    _LIBCPP_INLINE_VISIBILITY pointer&              __end_cap()       {return __end_cap_.first();}
+    _LIBCPP_INLINE_VISIBILITY const pointer&        __end_cap() const {return __end_cap_.first();}
+
+    __vector_base();
+    __vector_base(const allocator_type& __a);
+    ~__vector_base();
+
+    _LIBCPP_INLINE_VISIBILITY void clear() {__destruct_at_end(__begin_);}
+    _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __begin_);}
+
+    _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(const_pointer __new_last)
+        {__destruct_at_end(__new_last, has_trivial_destructor<value_type>());}
+        void __destruct_at_end(const_pointer __new_last, false_type);
+        void __destruct_at_end(const_pointer __new_last, true_type);
+
+    void __copy_assign_alloc(const __vector_base& __c)
+        {__copy_assign_alloc(__c, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
+
+    void __move_assign_alloc(__vector_base& __c)
+        {__move_assign_alloc(__c, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_move_assignment::value>());}
+
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __alloc_traits::propagate_on_container_swap::value>());}
+private:
+    void __copy_assign_alloc(const __vector_base& __c, true_type)
+        {
+            if (__alloc() != __c.__alloc())
+            {
+                clear();
+                __alloc_traits::deallocate(__alloc(), __begin_, capacity());
+                __begin_ = __end_ = __end_cap() = nullptr;
+            }
+            __alloc() = __c.__alloc();
+        }
+
+    void __copy_assign_alloc(const __vector_base& __c, false_type)
+        {}
+
+    void __move_assign_alloc(const __vector_base& __c, true_type)
+        {
+            __alloc() = _STD::move(__c.__alloc());
+        }
+
+    void __move_assign_alloc(const __vector_base& __c, false_type)
+        {}
+
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
+        {}
+};
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type)
+{
+    while (__new_last < __end_)
+        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type)
+{
+    __end_ = const_cast<pointer>(__new_last);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+__vector_base<_Tp, _Allocator>::__vector_base()
+    : __begin_(0),
+      __end_(0),
+      __end_cap_(0)
+{
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
+    : __begin_(0),
+      __end_(0),
+      __end_cap_(0, __a)
+{
+}
+
+template <class _Tp, class _Allocator>
+__vector_base<_Tp, _Allocator>::~__vector_base()
+{
+    if (__begin_ != 0)
+    {
+        clear();
+        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
+    }
+}
+
+template <class _Tp, class _Allocator = allocator<_Tp> >
+class vector
+    : private __vector_base<_Tp, _Allocator>
+{
+private:
+    typedef __vector_base<_Tp, _Allocator>           __base;
+public: 
+    typedef vector                                   __self;
+    typedef _Tp                                      value_type; 
+    typedef _Allocator                               allocator_type;
+    typedef typename __base::__alloc_traits          __alloc_traits;
+    typedef typename __base::reference               reference;
+    typedef typename __base::const_reference         const_reference;
+    typedef typename __base::size_type               size_type;
+    typedef typename __base::difference_type         difference_type;
+    typedef typename __base::pointer                 pointer;
+    typedef typename __base::const_pointer           const_pointer;
+#ifdef _LIBCPP_DEBUG
+    typedef __debug_iter<vector, pointer>            iterator;
+    typedef __debug_iter<vector, const_pointer>      const_iterator;
+
+    friend class __debug_iter<vector, pointer>;
+    friend class __debug_iter<vector, const_pointer>;
+
+    pair<iterator*, const_iterator*> __iterator_list_;
+
+    _LIBCPP_INLINE_VISIBILITY iterator*&       __get_iterator_list(iterator*)       {return __iterator_list_.first;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
+#elif defined(_LIBCPP_RAW_ITERATORS)
+    typedef pointer                                  iterator;
+    typedef const_pointer                            const_iterator;
+#else
+    typedef __wrap_iter<pointer>                     iterator;
+    typedef __wrap_iter<const_pointer>               const_iterator;
+#endif
+    typedef _STD::reverse_iterator<iterator>         reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>   const_reverse_iterator;
+
+    _LIBCPP_INLINE_VISIBILITY vector() {}
+    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) : __base(__a) {}
+    explicit vector(size_type __n);
+    vector(size_type __n, const_reference __x);
+    vector(size_type __n, const_reference __x, const allocator_type& __a);
+    template <class _InputIterator>
+        vector(_InputIterator __first, _InputIterator __last,
+               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+    template <class _InputIterator>
+        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
+               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+    template <class _ForwardIterator>
+        vector(_ForwardIterator __first, _ForwardIterator __last,
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+    template <class _ForwardIterator>
+        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+    vector(initializer_list<value_type> __il);
+    vector(initializer_list<value_type> __il, const allocator_type& __a);
+#ifdef _LIBCPP_DEBUG
+    ~vector() {__invalidate_all_iterators();}
+#endif
+
+    vector(const vector& __x);
+    vector(const vector& __x, const allocator_type& __a);
+    vector& operator=(const vector& __x);
+#ifdef _LIBCPP_MOVE
+    vector(vector&& __x);
+    vector(vector&& __x, const allocator_type& __a);
+    vector& operator=(vector&& __x);
+#endif
+    vector& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+
+    template <class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            void
+        >::type
+        assign(_InputIterator __first, _InputIterator __last);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            void
+        >::type
+        assign(_ForwardIterator __first, _ForwardIterator __last);
+
+    void assign(size_type __n, const_reference __u);
+    void assign(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end());}
+
+    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const {return this->__alloc();}
+
+    iterator               begin();
+    const_iterator         begin()   const;
+    iterator               end();
+    const_iterator         end()     const;
+
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator       rbegin()         {return       reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin()  const  {return const_reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY reverse_iterator       rend()           {return       reverse_iterator(begin());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend()    const  {return const_reverse_iterator(begin());}
+
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cbegin()  const  {return begin();}
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cend()    const  {return end();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const  {return rbegin();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend()   const  {return rend();}
+
+    _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(this->__end_ - this->__begin_);}
+    _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return __base::capacity();}
+    _LIBCPP_INLINE_VISIBILITY bool empty() const {return this->__begin_ == this->__end_;}
+    size_type max_size() const;
+    void reserve(size_type __n);
+    void shrink_to_fit();
+
+    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n);
+    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
+    reference       at(size_type __n);
+    const_reference at(size_type __n) const;
+
+    _LIBCPP_INLINE_VISIBILITY reference       front()       {return *this->__begin_;}
+    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *this->__begin_;}
+    _LIBCPP_INLINE_VISIBILITY reference       back()        {return *(this->__end_ - 1);}
+    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return *(this->__end_ - 1);}
+
+    _LIBCPP_INLINE_VISIBILITY value_type*       data()
+        {return _STD::__to_raw_pointer(this->__begin_);}
+    _LIBCPP_INLINE_VISIBILITY const value_type* data() const
+        {return _STD::__to_raw_pointer(this->__begin_);}
+
+    void push_back(const_reference __x);
+#ifdef _LIBCPP_MOVE
+    void push_back(value_type&& __x);
+    template <class... _Args>
+        void emplace_back(_Args&&... __args);
+#endif
+    void pop_back();
+
+    iterator insert(const_iterator __position, const_reference __x);
+#ifdef _LIBCPP_MOVE
+    iterator insert(const_iterator __position, value_type&& __x);
+    template <class... _Args>
+        iterator emplace(const_iterator __position, _Args&&... __args);
+#endif
+    iterator insert(const_iterator __position, size_type __n, const_reference __x);
+    template <class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
+    iterator insert(const_iterator __position, initializer_list<value_type> __il)
+        {return insert(__position, __il.begin(), __il.end());}
+
+    iterator erase(const_iterator __position);
+    iterator erase(const_iterator __first, const_iterator __last);
+
+    _LIBCPP_INLINE_VISIBILITY void clear() {__base::clear();}
+
+    void resize(size_type __sz);
+    void resize(size_type __sz, const_reference __x);
+
+    void swap(vector&);
+
+    bool __invariants() const;
+
+private:
+    void __invalidate_all_iterators();
+    void allocate(size_type __n);
+    void deallocate();
+    size_type __recommend(size_type __new_size) const;
+    void __construct_at_end(size_type __n);
+        void __construct_at_end(size_type __n, false_type);
+        void __construct_at_end(size_type __n, true_type);
+    void __construct_at_end(size_type __n, const_reference __x);
+        void __construct_at_end(size_type __n, const_reference __x, false_type);
+        void __construct_at_end(size_type __n, const_reference __x, true_type);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            void
+        >::type
+        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
+    void __move_construct_at_end(pointer __first, pointer __last);
+    void __append(size_type __n);
+    void __append(size_type __n, const_reference __x);
+    iterator       __make_iter(pointer __p);
+    const_iterator __make_iter(const_pointer __p) const;
+    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
+    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
+    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
+    void __move_assign(vector& __c, true_type);
+    void __move_assign(vector& __c, false_type);
+};
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
+{
+    for (pointer __p = this->__end_; this->__begin_ < __p;)
+        __v.push_front(_STD::move(*--__p));
+    _STD::swap(this->__begin_, __v.__begin_);
+    _STD::swap(this->__end_, __v.__end_);
+    _STD::swap(this->__end_cap(), __v.__end_cap());
+    __v.__first_ = __v.__begin_;
+    __invalidate_all_iterators();
+}
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::pointer
+vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
+{
+    pointer __r = __v.__begin_;
+    for (pointer __i = __p; this->__begin_ < __i;)
+        __v.push_front(_STD::move(*--__i));
+    for (pointer __i = __p; __i < this->__end_; ++__i)
+        __v.push_back(_STD::move(*__i));
+    _STD::swap(this->__begin_, __v.__begin_);
+    _STD::swap(this->__end_, __v.__end_);
+    _STD::swap(this->__end_cap(), __v.__end_cap());
+    __v.__first_ = __v.__begin_;
+    __invalidate_all_iterators();
+    return __r;
+}
+
+//  Allocate space for __n objects
+//  throws length_error if __n > max_size()
+//  throws (probably bad_alloc) if memory run out
+//  Precondition:  __begin_ == __end_ == __end_cap() == 0
+//  Precondition:  __n > 0
+//  Postcondition:  capacity() == __n
+//  Postcondition:  size() == 0
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::allocate(size_type __n)
+{
+    if (__n > max_size())
+        this->__throw_length_error();
+    this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
+    this->__end_cap() = this->__begin_ + __n;
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::deallocate()
+{
+    if (this->__begin_ != 0)
+    {
+        clear();
+        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
+        __invalidate_all_iterators();
+        this->__begin_ = this->__end_ = this->__end_cap() = 0;
+    }
+}
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::size_type
+vector<_Tp, _Allocator>::max_size() const
+{
+    return _STD::min(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2);  // end() >= begin(), always
+}
+
+//  Precondition:  __new_size > capacity()
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::size_type
+vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
+{
+    const size_type __ms = max_size();
+    if (__new_size > __ms)
+        this->__throw_length_error();
+    const size_type __cap = capacity();
+    if (__cap >= __ms / 2)
+        return __ms;
+    return _STD::max(2*__cap, __new_size);
+}
+
+//  Default constructs __n objects starting at __end_
+//  throws if construction throws
+//  Precondition:  __n > 0
+//  Precondition:  size() + __n <= capacity()
+//  Postcondition:  size() == size() + __n
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
+{
+    __construct_at_end(__n, __is_zero_default_constructible<value_type>());
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n, false_type)
+{
+    allocator_type& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_));
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n, true_type)
+{
+    _STD::memset(this->__end_, 0, __n*sizeof(value_type));
+    this->__end_ += __n;
+}
+
+//  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>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
+{
+    __construct_at_end(__n, __x, integral_constant<bool, has_trivial_copy_constructor<value_type>::value &&
+                                                         has_trivial_copy_assign<value_type>::value>());
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, false_type)
+{
+    allocator_type& __a = this->__alloc();
+    do
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), __x);
+        ++this->__end_;
+        --__n;
+    } while (__n > 0);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, true_type)
+{
+    _STD::fill_n(this->__end_, __n, __x);
+    this->__end_ += __n;
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    void
+>::type
+vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
+{
+    allocator_type& __a = this->__alloc();
+    for (; __first != __last; ++__first)
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), *__first);
+        ++this->__end_;
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
+{
+    allocator_type& __a = this->__alloc();
+    for (; __first != __last; ++__first)
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_),
+                                  _STD::move(*__first));
+        ++this->__end_;
+    }
+}
+
+//  Default constructs __n objects starting at __end_
+//  throws if construction throws
+//  Postcondition:  size() == size() + __n
+//  Exception safety: strong but assumes move ctor doesn't throw (copy ctor can)
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__append(size_type __n)
+{
+    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
+        this->__construct_at_end(__n);
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
+        __v.__construct_at_end(__n);
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+//  Default constructs __n objects starting at __end_
+//  throws if construction throws
+//  Postcondition:  size() == size() + __n
+//  Exception safety: strong but assumes move ctor doesn't throw (copy ctor can)
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
+{
+    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
+        this->__construct_at_end(__n, __x);
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
+        __v.__construct_at_end(__n, __x);
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+template <class _Tp, class _Allocator>
+vector<_Tp, _Allocator>::vector(size_type __n)
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n);
+    }
+}
+
+template <class _Tp, class _Allocator>
+vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n, __x);
+    }
+}
+
+template <class _Tp, class _Allocator>
+vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
+    : __base(__a)
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n, __x);
+    }
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIterator>
+vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
+       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                         !__is_forward_iterator<_InputIterator>::value>::type*)
+{
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIterator>
+vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
+       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                         !__is_forward_iterator<_InputIterator>::value>::type*)
+    : __base(__a)
+{
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+{
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+    : __base(__a)
+{
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Tp, class _Allocator>
+vector<_Tp, _Allocator>::vector(const vector& __x)
+    : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
+{
+    size_type __n = __x.size();
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__x.__begin_, __x.__end_);
+    }
+}
+
+template <class _Tp, class _Allocator>
+vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
+    : __base(__a)
+{
+    size_type __n = __x.size();
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__x.__begin_, __x.__end_);
+    }
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>::vector(vector&& __x)
+    : __base(_STD::move(__x.__alloc()))
+{
+    this->__begin_ = __x.__begin_;
+    this->__end_ = __x.__end_;
+    this->__end_cap() = __x.__end_cap();
+    __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
+    __x.__invalidate_all_iterators();
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
+    : __base(__a)
+{
+    if (__a == __x.__alloc())
+    {
+        this->__begin_ = __x.__begin_;
+        this->__end_ = __x.__end_;
+        this->__end_cap() = __x.__end_cap();
+        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
+        __x.__invalidate_all_iterators();
+    }
+    else
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__x.begin()), _I(__x.end()));
+    }
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
+{
+    if (__il.size() > 0)
+    {
+        allocate(__il.size());
+        __construct_at_end(__il.begin(), __il.end());
+    }
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
+    : __base(__a)
+{
+    if (__il.size() > 0)
+    {
+        allocate(__il.size());
+        __construct_at_end(__il.begin(), __il.end());
+    }
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>&
+vector<_Tp, _Allocator>::operator=(vector&& __x)
+{
+    __move_assign(__x, integral_constant<bool,
+          __alloc_traits::propagate_on_container_move_assignment::value>());
+    return *this;
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
+{
+    if (__base::__alloc() != __c.__alloc())
+    {
+        typedef move_iterator<iterator> _I;
+        assign(_I(__c.begin()), _I(__c.end()));
+    }
+    else
+        __move_assign(__c, true_type());
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
+{
+    deallocate();
+    this->__begin_ = __c.__begin_;
+    this->__end_ = __c.__end_;
+    this->__end_cap() = __c.__end_cap();
+    __base::__move_assign_alloc(__c);
+    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<_Tp, _Allocator>&
+vector<_Tp, _Allocator>::operator=(const vector& __x)
+{
+    if (this != &__x)
+    {
+        __base::__copy_assign_alloc(__x);
+        assign(__x.__begin_, __x.__end_);
+    }
+    return *this;
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    void
+>::type
+vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
+{
+    clear();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    void
+>::type
+vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
+{
+    typename iterator_traits<_ForwardIterator>::difference_type __new_size = _STD::distance(__first, __last);
+    if (static_cast<size_type>(__new_size) <= capacity())
+    {
+        _ForwardIterator __mid = __last;
+        bool __growing = false;
+        if (static_cast<size_type>(__new_size) > size())
+        {
+            __growing = true;
+            __mid =  __first;
+            _STD::advance(__mid, size());
+        }
+        pointer __m = _STD::copy(__first, __mid, this->__begin_);
+        if (__growing)
+            __construct_at_end(__mid, __last);
+        else
+            this->__destruct_at_end(__m);
+    }
+    else
+    {
+        deallocate();
+        allocate(__recommend(static_cast<size_type>(__new_size)));
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
+{
+    if (__n <= capacity())
+    {
+        size_type __s = size();
+        _STD::fill_n(this->__begin_, min(__n, __s), __u);
+        if (__n > __s)
+            __construct_at_end(__n - __s, __u);
+        else
+            __destruct_at_end(this->__begin_ + __n);
+    }
+    else
+    {
+        deallocate();
+        allocate(__recommend(static_cast<size_type>(__n)));
+        __construct_at_end(__n, __u);
+    }
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::__make_iter(pointer __p)
+{
+#ifdef _LIBCPP_DEBUG
+    return iterator(this, __p);
+#else
+    return iterator(__p);
+#endif
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::const_iterator
+vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const
+{
+#ifdef _LIBCPP_DEBUG
+    return const_iterator(this, __p);
+#else
+    return const_iterator(__p);
+#endif
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::begin()
+{
+    return __make_iter(this->__begin_);
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::const_iterator
+vector<_Tp, _Allocator>::begin() const
+{
+    return __make_iter(this->__begin_);
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::end()
+{
+    return __make_iter(this->__end_);
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::const_iterator
+vector<_Tp, _Allocator>::end() const
+{
+    return __make_iter(this->__end_);
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::reference
+vector<_Tp, _Allocator>::operator[](size_type __n)
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__n < size());
+#endif
+    return this->__begin_[__n];
+}
+
+template <class _Tp, class _Allocator> 
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::const_reference
+vector<_Tp, _Allocator>::operator[](size_type __n) const
+{
+#ifdef _LIBCPP_DEBUG
+    assert(__n < size());
+#endif
+    return this->__begin_[__n];
+}
+
+template <class _Tp, class _Allocator> 
+typename vector<_Tp, _Allocator>::reference
+vector<_Tp, _Allocator>::at(size_type __n)
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return this->__begin_[__n];
+}
+
+template <class _Tp, class _Allocator> 
+typename vector<_Tp, _Allocator>::const_reference
+vector<_Tp, _Allocator>::at(size_type __n) const
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return this->__begin_[__n];
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::reserve(size_type __n)
+{
+    if (__n > capacity())
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__n, 0, __a);
+        __v.__construct_at_end(move_iterator<pointer>(this->__begin_),
+                               move_iterator<pointer>(this->__end_));
+        clear();
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::shrink_to_fit()
+{
+    if (capacity() > size())
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            allocator_type& __a = this->__alloc();
+            __split_buffer<value_type, allocator_type&> __v(size(), 0, __a);
+            __v.__construct_at_end(move_iterator<pointer>(this->__begin_),
+                                   move_iterator<pointer>(this->__end_));
+            clear();
+            __swap_out_circular_buffer(__v);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+        }
+#endif
+    }
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::push_back(const_reference __x)
+{
+    if (this->__end_ < this->__end_cap())
+    {
+        __alloc_traits::construct(this->__alloc(),
+                                  _STD::__to_raw_pointer(this->__end_), __x);
+        ++this->__end_;
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
+        __v.push_back(__x);
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::push_back(value_type&& __x)
+{
+    if (this->__end_ < this->__end_cap())
+    {
+        __alloc_traits::construct(this->__alloc(),
+                                  _STD::__to_raw_pointer(this->__end_),
+                                  _STD::move(__x));
+        ++this->__end_;
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
+        __v.push_back(_STD::move(__x));
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+void
+vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
+{
+    if (this->__end_ < this->__end_cap())
+    {
+        __alloc_traits::construct(this->__alloc(),
+                                  _STD::__to_raw_pointer(this->__end_),
+                                  _STD::forward<_Args>(__args)...);
+        ++this->__end_;
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
+        __v.emplace_back(_STD::forward<_Args>(__args)...);
+        __swap_out_circular_buffer(__v);
+    }
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<_Tp, _Allocator>::pop_back()
+{
+    this->__destruct_at_end(this->__end_ - 1);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::erase(const_iterator __position)
+{
+    pointer __p = const_cast<pointer>(&*__position);
+    iterator __r = __make_iter(__p);
+    this->__destruct_at_end(_STD::move(__p + 1, this->__end_, __p));
+    return __r;
+}
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
+{
+    pointer __p = this->__begin_ + (__first - begin());
+    iterator __r = __make_iter(__p);
+    this->__destruct_at_end(_STD::move(__p + (__last - __first), this->__end_, __p));
+    return __r;
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
+{
+    pointer __old_last = this->__end_;
+    difference_type __n = __old_last - __to;
+    for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
+        __alloc_traits::construct(this->__alloc(),
+                                  _STD::__to_raw_pointer(this->__end_),
+                                  _STD::move(*__i));
+    _STD::move_backward(__from_s, __from_s + __n, __old_last);
+}
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
+{
+    pointer __p = this->__begin_ + (__position - begin());
+    if (this->__end_ < this->__end_cap())
+    {
+        if (__p == this->__end_)
+        {
+            __alloc_traits::construct(this->__alloc(),
+                                      _STD::__to_raw_pointer(this->__end_), __x);
+            ++this->__end_;
+        }
+        else
+        {
+            __move_range(__p, this->__end_, __p + 1);
+            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
+            if (__p <= __xr && __xr < this->__end_)
+                ++__xr;
+            *__p = *__xr;
+        }
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
+        __v.push_back(__x);
+        __p = __swap_out_circular_buffer(__v, __p);
+    }
+    return __make_iter(__p);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
+{
+    pointer __p = this->__begin_ + (__position - begin());
+    if (this->__end_ < this->__end_cap())
+    {
+        if (__p == this->__end_)
+        {
+            __alloc_traits::construct(this->__alloc(),
+                                      _STD::__to_raw_pointer(this->__end_),
+                                      _STD::move(__x));
+            ++this->__end_;
+        }
+        else
+        {
+            __move_range(__p, this->__end_, __p + 1);
+            *__p = _STD::move(__x);
+        }
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
+        __v.push_back(_STD::move(__x));
+        __p = __swap_out_circular_buffer(__v, __p);
+    }
+    return __make_iter(__p);
+}
+
+template <class _Tp, class _Allocator>
+template <class... _Args>
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
+{
+    pointer __p = this->__begin_ + (__position - begin());
+    if (this->__end_ < this->__end_cap())
+    {
+        if (__p == this->__end_)
+        {
+            __alloc_traits::construct(this->__alloc(),
+                                      _STD::__to_raw_pointer(this->__end_),
+                                      _STD::forward<_Args>(__args)...);
+            ++this->__end_;
+        }
+        else
+        {
+            __move_range(__p, this->__end_, __p + 1);
+            *__p = value_type(_STD::forward<_Args>(__args)...);
+        }
+    }
+    else
+    {
+        allocator_type& __a = this->__alloc();
+        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
+        __v.emplace_back(_STD::forward<_Args>(__args)...);
+        __p = __swap_out_circular_buffer(__v, __p);
+    }
+    return __make_iter(__p);
+}
+
+#endif
+
+template <class _Tp, class _Allocator>
+typename vector<_Tp, _Allocator>::iterator
+vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
+{
+    pointer __p = this->__begin_ + (__position - begin());
+    if (__n > 0)
+    {
+        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
+        {
+            size_type __old_n = __n;
+            pointer __old_last = this->__end_;
+            if (__n > static_cast<size_type>(this->__end_ - __p))
+            {
+                size_type __cx = __n - (this->__end_ - __p);
+                __construct_at_end(__cx, __x);
+                __n -= __cx;
+            }
+            if (__n > 0)
+            {
+                __move_range(__p, __old_last, __p + __old_n);
+                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
+                if (__p <= __xr && __xr < this->__end_)
+                    __xr += __old_n;
+                _STD::fill_n(__p, __n, *__xr);
+            }
+        }
+        else
+        {
+            allocator_type& __a = this->__alloc();
+            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
+            __v.__construct_at_end(__n, __x);
+            __p = __swap_out_circular_buffer(__v, __p);
+        }
+    }
+    return __make_iter(__p);
+}
+
+template <class _Tp, class _Allocator>
+template <class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    typename vector<_Tp, _Allocator>::iterator
+>::type
+vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
+{
+    difference_type __off = __position - begin();
+    pointer __p = this->__begin_ + __off;
+    allocator_type& __a = this->__alloc();
+    pointer __old_last = this->__end_;
+    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
+    {
+        __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_),
+                                  *__first);
+        ++this->__end_;
+    }
+    __split_buffer<value_type, allocator_type&> __v(__a);
+    if (__first != __last)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            __v.__construct_at_end(__first, __last);
+            difference_type __old_size = __old_last - this->__begin_;
+            difference_type __old_p = __p - this->__begin_;
+            reserve(__recommend(size() + __v.size()));
+            __p = this->__begin_ + __old_p;
+            __old_last = this->__begin_ + __old_size;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            erase(__make_iter(__old_last), end());
+            throw;
+        }
+#endif
+    }
+    __p = _STD::rotate(__p, __old_last, this->__end_);
+    insert(__make_iter(__p), move_iterator<iterator>(__v.begin()),
+                                    move_iterator<iterator>(__v.end()));
+    return begin() + __off;
+}
+
+template <class _Tp, class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    typename vector<_Tp, _Allocator>::iterator
+>::type
+vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
+{
+    pointer __p = this->__begin_ + (__position - begin());
+    difference_type __n = _STD::distance(__first, __last);
+    if (__n > 0)
+    {
+        if (__n <= this->__end_cap() - this->__end_)
+        {
+            size_type __old_n = __n;
+            pointer __old_last = this->__end_;
+            _ForwardIterator __m = __last;
+            difference_type __dx = this->__end_ - __p;
+            if (__n > __dx)
+            {
+                __m = __first;
+                _STD::advance(__m, this->__end_ - __p);
+                __construct_at_end(__m, __last);
+                __n = __dx;
+            }
+            if (__n > 0)
+            {
+                __move_range(__p, __old_last, __p + __old_n);
+                _STD::copy(__first, __m, __p);
+            }
+        }
+        else
+        {
+            allocator_type& __a = this->__alloc();
+            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
+            __v.__construct_at_end(__first, __last);
+            __p = __swap_out_circular_buffer(__v, __p);
+        }
+    }
+    return __make_iter(__p);
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::resize(size_type __sz)
+{
+    size_type __cs = size();
+    if (__cs < __sz)
+        this->__append(__sz - __cs);
+    else if (__cs > __sz)
+        this->__destruct_at_end(this->__begin_ + __sz);
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
+{
+    size_type __cs = size();
+    if (__cs < __sz)
+        this->__append(__sz - __cs, __x);
+    else if (__cs > __sz)
+        this->__destruct_at_end(this->__begin_ + __sz);
+}
+
+template <class _Tp, class _Allocator>
+void
+vector<_Tp, _Allocator>::swap(vector& __x)
+{
+    _STD::swap(this->__begin_, __x.__begin_);
+    _STD::swap(this->__end_, __x.__end_);
+    _STD::swap(this->__end_cap(), __x.__end_cap());
+    __base::__swap_alloc(this->__alloc(), __x.__alloc());
+#ifdef _LIBCPP_DEBUG
+    iterator::swap(this, &__x);
+    const_iterator::swap(this, &__x);
+#endif
+}
+
+template <class _Tp, class _Allocator> 
+bool
+vector<_Tp, _Allocator>::__invariants() const
+{
+    if (this->__begin_ == 0)
+    {
+        if (this->__end_ != 0 || this->__end_cap() != 0)
+            return false;
+    }
+    else
+    {
+        if (this->__begin_ > this->__end_)
+            return false;
+        if (this->__begin_ == this->__end_cap())
+            return false;
+        if (this->__end_ > this->__end_cap())
+            return false;
+    }
+    return true;
+}
+
+template <class _Tp, class _Allocator>
+#ifndef _LIBCPP_DEBUG
+_LIBCPP_INLINE_VISIBILITY inline
+#endif
+void
+vector<_Tp, _Allocator>::__invalidate_all_iterators()
+{
+#ifdef _LIBCPP_DEBUG
+    iterator::__remove_all(this);
+    const_iterator::__remove_all(this);
+#endif
+}
+
+// vector<bool>
+
+template <class _Allocator> class vector<bool, _Allocator>;
+
+template <class _Allocator> struct hash<vector<bool, _Allocator> >;
+
+template <class _Allocator>
+class vector<bool, _Allocator>
+    : private __vector_base_common<true>
+{
+public:
+    typedef vector                                   __self;
+    typedef bool                                     value_type; 
+    typedef _Allocator                               allocator_type;
+    typedef allocator_traits<allocator_type>         __alloc_traits;
+    typedef __bit_reference<vector>                  reference;
+    typedef __bit_const_reference<vector>            const_reference;
+    typedef typename __alloc_traits::size_type       size_type;
+    typedef typename __alloc_traits::difference_type difference_type;
+    typedef __bit_iterator<vector, false>            pointer;
+    typedef __bit_iterator<vector, true>             const_pointer;
+#ifdef _LIBCPP_DEBUG
+    typedef __debug_iter<vector, pointer>            iterator;
+    typedef __debug_iter<vector, const_pointer>      const_iterator;
+
+    friend class __debug_iter<vector, pointer>;
+    friend class __debug_iter<vector, const_pointer>;
+
+    pair<iterator*, const_iterator*> __iterator_list_;
+
+    _LIBCPP_INLINE_VISIBILITY iterator*&       __get_iterator_list(iterator*)       {return __iterator_list_.first;}
+    _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
+#else
+    typedef pointer                                  iterator;
+    typedef const_pointer                            const_iterator;
+#endif
+    typedef _STD::reverse_iterator<iterator>         reverse_iterator;
+    typedef _STD::reverse_iterator<const_iterator>   const_reverse_iterator;
+
+private:
+    typedef size_type __storage_type;
+    typedef typename __alloc_traits::template
+#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
+                rebind_alloc<__storage_type>
+#else
+                rebind_alloc<__storage_type>::other
+#endif
+                                                     __storage_allocator;
+    typedef allocator_traits<__storage_allocator>    __storage_traits;
+    typedef typename __storage_traits::pointer       __storage_pointer;
+    typedef typename __storage_traits::const_pointer __const_storage_pointer;
+
+    __storage_pointer                                      __begin_;
+    size_type                                              __size_;
+    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
+
+    _LIBCPP_INLINE_VISIBILITY       size_type&           __cap()         {return __cap_alloc_.first();}
+    _LIBCPP_INLINE_VISIBILITY const size_type&           __cap()   const {return __cap_alloc_.first();}
+    _LIBCPP_INLINE_VISIBILITY       __storage_allocator& __alloc()       {return __cap_alloc_.second();}
+    _LIBCPP_INLINE_VISIBILITY const __storage_allocator& __alloc() const {return __cap_alloc_.second();}
+
+    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
+
+    _LIBCPP_INLINE_VISIBILITY static size_type __internal_cap_to_external(size_type __n)
+        {return __n * __bits_per_word;}
+    _LIBCPP_INLINE_VISIBILITY static size_type __external_cap_to_internal(size_type __n)
+        {return (__n - 1) / __bits_per_word + 1;}
+
+public:
+    vector();
+    explicit vector(const allocator_type& __a);
+    ~vector();
+    explicit vector(size_type __n);
+    vector(size_type __n, const value_type& __v);
+    vector(size_type __n, const value_type& __v, const allocator_type& __a);
+    template <class _InputIterator>
+        vector(_InputIterator __first, _InputIterator __last,
+               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+    template <class _InputIterator>
+        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
+               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
+    template <class _ForwardIterator>
+        vector(_ForwardIterator __first, _ForwardIterator __last,
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+    template <class _ForwardIterator>
+        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
+               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
+
+    vector(const vector& __v);
+    vector(const vector& __v, const allocator_type& __a);
+    vector& operator=(const vector& __v);
+    vector(initializer_list<value_type> __il);
+    vector(initializer_list<value_type> __il, const allocator_type& __a);
+
+#ifdef _LIBCPP_MOVE
+    vector(vector&& __v);
+    vector(vector&& __v, const allocator_type& __a);
+    vector& operator=(vector&& __v);
+#endif
+    vector& operator=(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end()); return *this;}
+
+    template <class _InputIterator>
+        typename enable_if
+        <
+            __is_input_iterator<_InputIterator>::value &&
+           !__is_forward_iterator<_InputIterator>::value,
+           void
+        >::type
+        assign(_InputIterator __first, _InputIterator __last);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+           void
+        >::type
+        assign(_ForwardIterator __first, _ForwardIterator __last);
+
+    void assign(size_type __n, const value_type& __x);
+    void assign(initializer_list<value_type> __il)
+        {assign(__il.begin(), __il.end());}
+
+    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const
+        {return allocator_type(this->__alloc());}
+
+    size_type max_size() const;
+    _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return __internal_cap_to_external(__cap());}
+    _LIBCPP_INLINE_VISIBILITY size_type size() const {return __size_;}
+    _LIBCPP_INLINE_VISIBILITY bool empty() const {return __size_ == 0;}
+    void reserve(size_type __n);
+    void shrink_to_fit();
+
+    _LIBCPP_INLINE_VISIBILITY       iterator begin()       {return __make_iter(0);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __make_iter(0);}
+    _LIBCPP_INLINE_VISIBILITY       iterator end()         {return __make_iter(__size_);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator end()   const {return __make_iter(__size_);}
+
+    _LIBCPP_INLINE_VISIBILITY       reverse_iterator rbegin()       {return       reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
+    _LIBCPP_INLINE_VISIBILITY       reverse_iterator rend()         {return       reverse_iterator(begin());}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend()   const {return const_reverse_iterator(begin());}
+
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cbegin()  const {return __make_iter(0);}
+    _LIBCPP_INLINE_VISIBILITY const_iterator         cend()    const {return __make_iter(__size_);}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const {return rbegin();}
+    _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend()   const {return rend();}
+
+    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
+    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
+    reference       at(size_type __n);
+    const_reference at(size_type __n) const;
+
+    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
+    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
+    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
+    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
+
+    void push_back(const value_type& __x);
+    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
+
+    iterator insert(const_iterator __position, const value_type& __x);
+    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
+    iterator insert(const_iterator __position, size_type __n, const_reference __x);
+    template <class _InputIterator>
+        typename enable_if
+        <
+             __is_input_iterator  <_InputIterator>::value &&
+            !__is_forward_iterator<_InputIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            iterator
+        >::type
+        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
+    iterator insert(const_iterator __position, initializer_list<value_type> __il)
+        {return insert(__position, __il.begin(), __il.end());}
+
+    iterator erase(const_iterator __position);
+    iterator erase(const_iterator __first, const_iterator __last);
+
+    _LIBCPP_INLINE_VISIBILITY void clear() {__size_ = 0;}
+
+    void swap(vector&);
+
+    void resize(size_type __sz, value_type __x = false);
+    void flip();
+
+    bool __invariants() const;
+
+private:
+    void __invalidate_all_iterators();
+    void allocate(size_type __n);
+    void deallocate();
+    _LIBCPP_INLINE_VISIBILITY static size_type __align(size_type __new_size)
+        {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
+    size_type __recommend(size_type __new_size) const;
+    void __construct_at_end(size_type __n, bool __x);
+    template <class _ForwardIterator>
+        typename enable_if
+        <
+            __is_forward_iterator<_ForwardIterator>::value,
+            void
+        >::type
+        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
+    void __append(size_type __n, const_reference __x);
+    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_type __pos)
+        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
+    _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_type __pos) const
+        {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
+#ifdef _LIBCPP_DEBUG
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
+        {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
+        {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
+    _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
+        {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
+#else
+    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
+        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
+    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
+        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
+    _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
+        {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
+#endif
+
+    void __copy_assign_alloc(const vector& __v)
+        {__copy_assign_alloc(__v, integral_constant<bool,
+                      __storage_traits::propagate_on_container_copy_assignment::value>());}
+    void __copy_assign_alloc(const vector& __c, true_type)
+        {
+            if (__alloc() != __c.__alloc())
+                deallocate();
+            __alloc() = __c.__alloc();
+        }
+
+    void __copy_assign_alloc(const vector& __c, false_type)
+        {}
+
+    void __move_assign(vector& __c, false_type);
+    void __move_assign(vector& __c, true_type);
+    void __move_assign_alloc(vector& __c)
+        {__move_assign_alloc(__c, integral_constant<bool,
+                      __storage_traits::propagate_on_container_move_assignment::value>());}
+    void __move_assign_alloc(const vector& __c, true_type)
+        {
+            __alloc() = _STD::move(__c.__alloc());
+        }
+
+    void __move_assign_alloc(const vector& __c, false_type)
+        {}
+
+    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
+        {__swap_alloc(__x, __y, integral_constant<bool,
+                      __storage_traits::propagate_on_container_swap::value>());}
+
+    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
+        {
+            using _STD::swap;
+            swap(__x, __y);
+        }
+    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
+        {}
+
+    size_t __hash_code() const;
+
+    friend class __bit_reference<vector>;
+    friend class __bit_const_reference<vector>;
+    friend class __bit_iterator<vector, false>;
+    friend class __bit_iterator<vector, true>;
+    friend class __bit_array<vector>;
+    friend struct hash<vector>;
+};
+
+template <class _Allocator>
+#ifndef _LIBCPP_DEBUG
+_LIBCPP_INLINE_VISIBILITY inline
+#endif
+void
+vector<bool, _Allocator>::__invalidate_all_iterators()
+{
+#ifdef _LIBCPP_DEBUG
+    iterator::__remove_all(this);
+    const_iterator::__remove_all(this);
+#endif
+}
+
+//  Allocate space for __n objects
+//  throws length_error if __n > max_size()
+//  throws (probably bad_alloc) if memory run out
+//  Precondition:  __begin_ == __end_ == __cap() == 0
+//  Precondition:  __n > 0
+//  Postcondition:  capacity() == __n
+//  Postcondition:  size() == 0
+template <class _Allocator>
+void
+vector<bool, _Allocator>::allocate(size_type __n)
+{
+    if (__n > max_size())
+        this->__throw_length_error();
+    __n = __external_cap_to_internal(__n);
+    this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
+    this->__size_ = 0;
+    this->__cap() = __n;
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::deallocate()
+{
+    if (this->__begin_ != 0)
+    {
+        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
+        __invalidate_all_iterators();
+        this->__begin_ = 0;
+        this->__size_ = this->__cap() = 0;
+    }
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::size_type
+vector<bool, _Allocator>::max_size() const
+{
+    size_type __amax = __storage_traits::max_size(__alloc());
+    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
+    if (__nmax / __bits_per_word <= __amax)
+        return __nmax;
+    return __internal_cap_to_external(__amax);
+}
+
+//  Precondition:  __new_size > capacity()
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<bool, _Allocator>::size_type
+vector<bool, _Allocator>::__recommend(size_type __new_size) const
+{
+    const size_type __ms = max_size();
+    if (__new_size > __ms)
+        this->__throw_length_error();
+    const size_type __cap = capacity();
+    if (__cap >= __ms / 2)
+        return __ms;
+    return _STD::max(2*__cap, __align(__new_size));
+}
+
+//  Default constructs __n objects starting at __end_
+//  Precondition:  __n > 0
+//  Precondition:  size() + __n <= capacity()
+//  Postcondition:  size() == size() + __n
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
+{
+    size_type __old_size = this->__size_;
+    this->__size_ += __n;
+    _STD::fill_n(__make_iter(__old_size), __n, __x);
+}
+
+template <class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    void
+>::type
+vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
+{
+    size_type __old_size = this->__size_;
+    this->__size_ += _STD::distance(__first, __last);
+    _STD::copy(__first, __last, __make_iter(__old_size));
+}
+
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<bool, _Allocator>::vector()
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+}
+
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<bool, _Allocator>::vector(const allocator_type& __a)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
+{
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(size_type __n)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n, false);
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n, __x);
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
+{
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__n, __x);
+    }
+}
+
+template <class _Allocator>
+template <class _InputIterator>
+vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
+       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                         !__is_forward_iterator<_InputIterator>::value>::type*)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        for (; __first != __last; ++__first)
+            push_back(*__first);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        if (__begin_ != 0)
+            __storage_traits::deallocate(__alloc(), __begin_, __cap());
+        __invalidate_all_iterators();
+        throw;
+    }
+#endif
+}
+
+template <class _Allocator>
+template <class _InputIterator>
+vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
+       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
+                         !__is_forward_iterator<_InputIterator>::value>::type*)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    try
+    {
+#endif
+        for (; __first != __last; ++__first)
+            push_back(*__first);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+    }
+    catch (...)
+    {
+        if (__begin_ != 0)
+            __storage_traits::deallocate(__alloc(), __begin_, __cap());
+        __invalidate_all_iterators();
+        throw;
+    }
+#endif
+}
+
+template <class _Allocator>
+template <class _ForwardIterator>
+vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Allocator>
+template <class _ForwardIterator>
+vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
+                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
+{
+    size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0)
+{
+    size_type __n = static_cast<size_type>(__il.size());
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__il.begin(), __il.end());
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
+{
+    size_type __n = static_cast<size_type>(__il.size());
+    if (__n > 0)
+    {
+        allocate(__n);
+        __construct_at_end(__il.begin(), __il.end());
+    }
+}
+
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<bool, _Allocator>::~vector()
+{
+    if (__begin_ != 0)
+        __storage_traits::deallocate(__alloc(), __begin_, __cap());
+#ifdef _LIBCPP_DEBUG
+    __invalidate_all_iterators();
+#endif
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(const vector& __v)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
+{
+    if (__v.size() > 0)
+    {
+        allocate(__v.size());
+        __construct_at_end(__v.begin(), __v.end());
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, __a)
+{
+    if (__v.size() > 0)
+    {
+        allocate(__v.size());
+        __construct_at_end(__v.begin(), __v.end());
+    }
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>&
+vector<bool, _Allocator>::operator=(const vector& __v)
+{
+    if (this != &__v)
+    {
+        __copy_assign_alloc(__v);
+        if (__v.__size_)
+        {
+            if (__v.__size_ > capacity())
+            {
+                deallocate();
+                allocate(__v.__size_);
+            }
+            _STD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
+        }
+        __size_ = __v.__size_;
+    }
+    return *this;
+}
+
+#ifdef _LIBCPP_MOVE
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<bool, _Allocator>::vector(vector&& __v)
+    : __begin_(__v.__begin_),
+      __size_(__v.__size_),
+      __cap_alloc_(__v.__cap_alloc_)
+{
+    __v.__begin_ = 0;
+    __v.__size_ = 0;
+    __v.__cap() = 0;
+}
+
+template <class _Allocator>
+vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
+    : __begin_(0),
+      __size_(0),
+      __cap_alloc_(0, __a)
+{
+    if (__a == allocator_type(__v.__alloc()))
+    {
+        this->__begin_ = __v.__begin_;
+        this->__size_ = __v.__size_;
+        this->__cap() = __v.__cap();
+        __v.__begin_ = nullptr;
+        __v.__cap() = __v.__size_ = 0;
+    }
+    else if (__v.size() > 0)
+    {
+        allocate(__v.size());
+        __construct_at_end(__v.begin(), __v.end());
+    }
+}
+
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+vector<bool, _Allocator>&
+vector<bool, _Allocator>::operator=(vector&& __v)
+{
+    __move_assign(__v, integral_constant<bool,
+          __storage_traits::propagate_on_container_move_assignment::value>());
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
+{
+    if (__alloc() != __c.__alloc())
+        assign(__c.begin(), __c.end());
+    else
+        __move_assign(__c, true_type());
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
+{
+    deallocate();
+    this->__begin_ = __c.__begin_;
+    this->__size_ = __c.__size_;
+    this->__cap() = __c.__cap();
+    __move_assign_alloc(__c);
+    __c.__begin_ = nullptr;
+    __c.__cap() = __c.__size_ = 0;
+}
+#endif
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
+{
+    __size_ = 0;
+    if (__n > 0)
+    {
+        size_type __c = capacity();
+        if (__n <= __c)
+            __size_ = __n;
+        else
+        {
+            vector __v(__alloc());
+            __v.reserve(__recommend(__n));
+            __v.__size_ = __n;
+            swap(__v);
+        }
+        _STD::fill_n(begin(), __n, __x);
+    }
+}
+
+template <class _Allocator>
+template <class _InputIterator>
+typename enable_if
+<
+    __is_input_iterator<_InputIterator>::value &&
+   !__is_forward_iterator<_InputIterator>::value,
+   void
+>::type
+vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
+{
+    clear();
+    for (; __first != __last; ++__first)
+        push_back(*__first);
+}
+
+template <class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+   void
+>::type
+vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
+{
+    clear();
+    difference_type __n = _STD::distance(__first, __last);
+    if (__n)
+    {
+        if (__n > capacity())
+        {
+            deallocate();
+            allocate(__n);
+        }
+        __construct_at_end(__first, __last);
+    }
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::reserve(size_type __n)
+{
+    if (__n > capacity())
+    {
+        vector __v(this->__alloc());
+        __v.allocate(__n);
+        __v.__construct_at_end(this->begin(), this->end());
+        swap(__v);
+        __invalidate_all_iterators();
+    }
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::shrink_to_fit()
+{
+    if (__external_cap_to_internal(size()) > __cap())
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            vector(*this, allocator_type(__alloc())).swap(*this);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+        }
+#endif
+    }
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::reference
+vector<bool, _Allocator>::at(size_type __n)
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return (*this)[__n];
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::const_reference
+vector<bool, _Allocator>::at(size_type __n) const
+{
+    if (__n >= size())
+        this->__throw_out_of_range();
+    return (*this)[__n];
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::push_back(const value_type& __x)
+{
+    if (this->__size_ == this->capacity())
+        reserve(__recommend(this->__size_ + 1));
+    ++this->__size_;
+    back() = __x;
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::iterator
+vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
+{
+    iterator __r;
+    if (size() < capacity())
+    {
+        const_iterator __old_end = end();
+        ++__size_;
+        _STD::copy_backward(__position, __old_end, end());
+        __r = __const_iterator_cast(__position);
+    }
+    else
+    {
+        vector __v(__alloc());
+        __v.reserve(__recommend(__size_ + 1));
+        __v.__size_ = __size_ + 1;
+        __r = _STD::copy(cbegin(), __position, __v.begin());
+        _STD::copy_backward(__position, cend(), __v.end());
+        swap(__v);
+    }
+    *__r = __x;
+    return __r;
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::iterator
+vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
+{
+    iterator __r;
+    size_type __c = capacity();
+    if (__n <= __c && size() <= __c - __n)
+    {
+        const_iterator __old_end = end();
+        __size_ += __n;
+        _STD::copy_backward(__position, __old_end, end());
+        __r = __const_iterator_cast(__position);
+    }
+    else
+    {
+        vector __v(__alloc());
+        __v.reserve(__recommend(__size_ + __n));
+        __v.__size_ = __size_ + __n;
+        __r = _STD::copy(cbegin(), __position, __v.begin());
+        _STD::copy_backward(__position, cend(), __v.end());
+        swap(__v);
+    }
+    _STD::fill_n(__r, __n, __x);
+    return __r;
+}
+
+template <class _Allocator>
+template <class _InputIterator>
+typename enable_if
+<
+     __is_input_iterator  <_InputIterator>::value &&
+    !__is_forward_iterator<_InputIterator>::value,
+    typename vector<bool, _Allocator>::iterator
+>::type
+vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
+{
+    difference_type __off = __position - begin();
+    iterator __p = __const_iterator_cast(__position);
+    iterator __old_end = end();
+    for (; size() != capacity() && __first != __last; ++__first)
+    {
+        ++this->__size_;
+        back() = *__first;
+    }
+    vector __v(__alloc());
+    if (__first != __last)
+    {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        try
+        {
+#endif
+            __v.assign(__first, __last);
+            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
+            difference_type __old_p = __p - begin();
+            reserve(__recommend(size() + __v.size()));
+            __p = begin() + __old_p;
+            __old_end = begin() + __old_size;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        }
+        catch (...)
+        {
+            erase(__old_end, end());
+            throw;
+        }
+#endif
+    }
+    __p = _STD::rotate(__p, __old_end, end());
+    insert(__p, __v.begin(), __v.end());
+    return begin() + __off;
+}
+
+template <class _Allocator>
+template <class _ForwardIterator>
+typename enable_if
+<
+    __is_forward_iterator<_ForwardIterator>::value,
+    typename vector<bool, _Allocator>::iterator
+>::type
+vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
+{
+    difference_type __n = _STD::distance(__first, __last);
+    iterator __r;
+    size_type __c = capacity();
+    if (__n <= __c && size() <= __c - __n)
+    {
+        const_iterator __old_end = end();
+        __size_ += __n;
+        _STD::copy_backward(__position, __old_end, end());
+        __r = __const_iterator_cast(__position);
+    }
+    else
+    {
+        vector __v(__alloc());
+        __v.reserve(__recommend(__size_ + __n));
+        __v.__size_ = __size_ + __n;
+        __r = _STD::copy(cbegin(), __position, __v.begin());
+        _STD::copy_backward(__position, cend(), __v.end());
+        swap(__v);
+    }
+    _STD::copy(__first, __last, __r);
+    return __r;
+}
+
+template <class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+typename vector<bool, _Allocator>::iterator
+vector<bool, _Allocator>::erase(const_iterator __position)
+{
+    iterator __r = __const_iterator_cast(__position);
+    _STD::copy(__position + 1, this->cend(), __r);
+    --__size_;
+    return __r;
+}
+
+template <class _Allocator>
+typename vector<bool, _Allocator>::iterator
+vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
+{
+    iterator __r = __const_iterator_cast(__first);
+    difference_type __d = __last - __first;
+    _STD::copy(__last, this->cend(), __r);
+    __size_ -= __d;
+    return __r;
+}
+
+template <class _Allocator>
+void
+vector<bool, _Allocator>::swap(vector& __x)
+{
+    _STD::swap(this->__begin_, __x.__begin_);
+    _STD::swap(this->__size_, __x.__size_);
+    _STD::swap(this->__cap(), __x.__cap());
+    __swap_alloc(this->__alloc(), __x.__alloc());
+#ifdef _LIBCPP_DEBUG
+    iterator::swap(this, &__x);
+    const_iterator::swap(this, &__x);
+#endif
+}
+
+template <class _Allocator> 
+void
+vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
+{
+    size_type __cs = size();
+    if (__cs < __sz)
+    {
+        iterator __r;
+        size_type __c = capacity();
+        size_type __n = __sz - __cs;
+        if (__n <= __c && __cs <= __c - __n)
+        {
+            __r = end();
+            __size_ += __n;
+        }
+        else
+        {
+            vector __v(__alloc());
+            __v.reserve(__recommend(__size_ + __n));
+            __v.__size_ = __size_ + __n;
+            __r = _STD::copy(cbegin(), cend(), __v.begin());
+            swap(__v);
+        }
+        _STD::fill_n(__r, __n, __x);
+    }
+    else
+        __size_ = __sz;
+}
+
+template <class _Allocator> 
+void
+vector<bool, _Allocator>::flip()
+{
+    // do middle whole words
+    size_type __n = __size_;
+    __storage_pointer __p = __begin_;
+    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
+        *__p = ~*__p;
+    // do last partial word
+    if (__n > 0)
+    {
+        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __storage_type __b = *__p & __m;
+        *__p &= ~__m;
+        *__p |= ~__b & __m;
+    }
+}
+
+template <class _Allocator> 
+bool
+vector<bool, _Allocator>::__invariants() const
+{
+    if (this->__begin_ == 0)
+    {
+        if (this->__size_ != 0 || this->__cap() != 0)
+            return false;
+    }
+    else
+    {
+        if (this->__cap() == 0)
+            return false;
+        if (this->__size_ > this->capacity())
+            return false;
+    }
+    return true;
+}
+
+template <class _Allocator> 
+size_t
+vector<bool, _Allocator>::__hash_code() const
+{
+    size_t __h = 0;
+    // do middle whole words
+    size_type __n = __size_;
+    __storage_pointer __p = __begin_;
+    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
+        __h ^= *__p;
+    // do last partial word
+    if (__n > 0)
+    {
+        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
+        __h ^= *__p & __m;
+    }
+    return __h;
+}
+
+template <class _Allocator>
+struct hash<vector<bool, _Allocator> >
+    : public unary_function<vector<bool, _Allocator>, size_t>
+{
+    size_t operator()(const vector<bool, _Allocator>& __vec) const
+        {return __vec.__hash_code();}
+};
+
+template <class _Tp, class _Allocator>
+struct __is_zero_default_constructible<vector<_Tp, _Allocator> >
+    : public integral_constant<bool, __is_zero_default_constructible<_Allocator>::value> {};
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
+    return __sz == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    return !(__x == __y);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    return __y < __x;
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    return !(__x < __y);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+bool
+operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
+{
+    return !(__y < __x);
+}
+
+template <class _Tp, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY inline
+void
+swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
+{
+    __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif  // _LIBCPP_VECTOR